wireguard_peer_manager/README.md

77 lines
1.9 KiB
Markdown
Raw Permalink Normal View History

# Wireguard Peer Manager
This is simple CURD for managing wireguard peer notations on a wireguard server config.
## Requirements
- Python 3.x
- `requests` library (for the client)
- WireGuard (`wg-quick` and `wg` commands must be available on the server)
## Server: wpm.py
### How to Run the Server
`python wpm.py`
### Endpoints
GET /peers: List all peers.
POST /peers: Add a new peer.
PUT /peers/<PublicKey>: Update an existing peer.
DELETE /peers/<PublicKey>: Delete an existing peer.
POST /restore: Restore the WireGuard configuration from a backup.
## Client: wpm_client.py
The client script allows interaction with the WireGuard Peer Management API.
### Usage
python wpm_client.py <action> [options]
### Available Actions
create: Create a new peer.
Required options: --public-key, --allowed-ips
update: Update an existing peer.
Required options: --public-key, --allowed-ips
delete: Delete a peer by its public key.
Required options: --public-key
list: List all peers.
restore: Restore the WireGuard configuration from the most recent backup.
### Example Usage
2024-10-19 23:51:28 +03:00
List Peers:
2024-10-19 23:51:28 +03:00
python wpm_client.py list
2024-10-19 23:51:28 +03:00
Create a New Peer:
2024-10-19 23:51:28 +03:00
python wpm_client.py create --public-key "<peer-public-key>" --allowed-ips "10.0.0.2/32"
2024-10-19 23:51:28 +03:00
Update an Existing Peer:
2024-10-19 23:51:28 +03:00
python wpm_client.py update --public-key "<peer-public-key>" --allowed-ips "10.0.0.3/32"
2024-10-19 23:51:28 +03:00
Delete a Peer:
2024-10-19 23:51:28 +03:00
python wpm_client.py delete --public-key "<peer-public-key>"
2024-10-19 23:51:28 +03:00
Restore Configuration:
2024-10-19 23:51:28 +03:00
python wpm_client.py restore
### Backup and Restore
The server automatically creates a backup before making any changes to the WireGuard configuration. The backups are stored in the same directory as the configuration file, inside a backups/ folder.
You can restore the latest backup by sending a POST /restore request, which can be done using the client or via curl:
2024-10-19 23:51:28 +03:00
curl -X POST http://localhost:8000/restore