Updated some documentation

This commit is contained in:
Donald Zou 2024-08-15 22:47:44 -04:00
parent c98d851cd2
commit 5d4a8136c5
3 changed files with 187 additions and 16 deletions

View file

@ -113,10 +113,12 @@
# make any changes with the dashboard, you can set it to false.
[Peer]
#Name# = Donald's iPhone
PublicKey = abcd1234
AllowedIPs = 1.2.3.4/32
# Must have for each peer
```
> With `v4`, WGDashboard will look for entry with `#Name# = abc...` in each peer and use that for the name.
- **Python 3.10** for v4.0+, **Python 3.7 - 3.9** for v2.0 - v3.0.6.2

View file

@ -110,11 +110,12 @@ This endpoint is dedicated for non-cross-server access. It is used to authentica
}
```
**`username`** string
| Parameter | Type |
|------------|--------|
| `username` | string |
| `password` | string |
| `totp` | string |
**`password`** string
**`totp`** string
#### Response
@ -140,7 +141,185 @@ If username, password or TOTP is not match
}
```
### Sign Out
To remove the current session on server side
#### Request
`GET /api/signout`
#### Response
`200 - OK`
```json
{
"data": null,
"message": null,
"status": true
}
```
### Get WireGuard Configurations
To get all WireGuard configurations in `/etc/wireguard`
#### Request
`GET /api/getWireguardConfigurations`
#### Response
`200 - OK`
```json
{
"data": [
{
"Address": "10.200.200.1/24",
"ConnectedPeers": 0,
"DataUsage": {
"Receive": 0.1582,
"Sent": 2.1012999999999997,
"Total": 2.2595
},
"ListenPort": "51820",
"Name": "wg0",
"PostDown": "iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o enp0s1 -j MASQUERADE;",
"PostUp": "iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o enp0s1 -j MASQUERADE;",
"PreDown": "",
"PreUp": "",
"PrivateKey": "8DsSMli3okgUx5frKbFQ0fMW5ZMyqyxOdOW7+g21L18=",
"PublicKey": "GQlGi8QJ93hWY7L2xlJyh+7S6+ekER9xP11T92T0O0Q=",
"SaveConfig": true,
"Status": false
}
],
"message": null,
"status": true
}
```
### Add WireGuard Configuration
Add a new WireGuard Configuration
#### Request
`POST /api/addWireguardConfiguration`
##### Body Parameters
```json
{
"ConfigurationName": "wg0",
"Address": "10.0.0.1/24",
"ListenPort": 51820,
"PrivateKey": "eJuuamCgakVs2xUZGHh/g7C6Oy89JGh7eE2jjEGbbFc=",
"PublicKey": "3Ruirgw9qNRwNpBepkiVjjSe82tY+lDZr6WaFC4wO2g=",
"PresharedKey": "GMMLKWdJlgsKVoR26BJPsNbDXyfILL+x1Nd6Ecmn4lg=",
"PreUp": "",
"PreDown": "iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o enp0s1 -j MASQUERADE;",
"PostUp": "iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o enp0s1 -j MASQUERADE;",
"PostDown": ""
}
```
| Parameter | Type |
|---------------------|--------|
| `ConfigurationName` | string |
| `Address` | string |
| `ListenPort` | int |
| `PrivateKey` | string |
| `PublicKey` | string |
| `PresharedKey` | string |
| `PreUp` | string |
| `PreDown` | string |
| `PostUp` | string |
| `PostDown` | string |
#### Response
`200 - OK`
If everything is good
```json
{
"data": null,
"message": null,
"status": true
}
```
If the new configuration's `ConfigurationName` is already existed
```json
{
"data": null,
"message": "Already have a configuration with the name \"wg0\"",
"status": false
}
```
If the new configuration's `ListenPort` is used by another configuration
```json
{
"data": null,
"message": "Already have a configuration with the port \"51820\"",
"status": false
}
```
If the new configuration's `Address` is used by another configuration
```json
{
"data": null,
"message": "Already have a configuration with the address \"10.0.0.1/24\"",
"status": false
}
```
### Toggle WireGuard Configuration
To turn on/off of a WireGuard Configuration
#### Request
`GET /api/toggleWireguardConfiguration/?configurationName=`
##### Query String Parameter
| Parameter | Type |
|---------------------|--------|
| `configurationName` | string |
#### Response
`200 - OK`
If toggle is successful, server will return the current status in `status`: `true` or `false` indicating if the configuration is up or not.
```json
{
"data": true,
"message": null,
"status": true
}
```
If the `configurationName` provided does not exist
```json
{
"data": null,
"message": "Please provide a valid configuration name",
"status": false
}
```

View file

@ -21,7 +21,7 @@ import bcrypt
import ifcfg
import psutil
import pyotp
from flask import Flask, request, render_template, session, g, Blueprint
from flask import Flask, request, render_template, session, g
from json import JSONEncoder
from flask_cors import CORS
@ -601,7 +601,6 @@ class WireguardConfiguration:
checkIfExist = sqldb.cursor().execute("SELECT * FROM '%s' WHERE id = ?" % self.Name,
((i['PublicKey']),)).fetchone()
if checkIfExist is None:
print(i)
newPeer = {
"id": i['PublicKey'],
"private_key": "",
@ -625,7 +624,6 @@ class WireguardConfiguration:
"remote_endpoint": DashboardConfig.GetConfig("Peers", "remote_endpoint")[1],
"preshared_key": i["PresharedKey"] if "PresharedKey" in i.keys() else ""
}
print(newPeer)
sqldb.cursor().execute(
"""
INSERT INTO '%s'
@ -823,7 +821,6 @@ class WireguardConfiguration:
sqldb.commit()
total_sent = 0
total_receive = 0
print(data_usage[i][0])
_, p = self.searchPeer(data_usage[i][0])
if p.total_receive != total_receive or p.total_sent != total_sent:
sqldb.cursor().execute(
@ -832,7 +829,6 @@ class WireguardConfiguration:
total_receive + total_sent, data_usage[i][0],))
sqldb.commit()
except Exception as e:
traceback.print_exc()
print(f"[WGDashboard] {self.Name} Error: {str(e)} {str(e.__traceback__)}")
def getPeersEndpoint(self):
@ -1339,7 +1335,6 @@ def _getWireguardConfigurationAvailableIP(configName: str) -> tuple[bool, list[s
configuration = WireguardConfigurations[configName]
if len(configuration.Address) > 0:
address = configuration.Address.split(',')
print(address)
existedAddress = []
availableAddress = []
for p in configuration.Peers:
@ -1426,8 +1421,6 @@ def auth_req():
and "sharePeer/get" not in request.path
and "isTotpEnabled" not in request.path
):
print(request.path)
print(f"{(APP_PREFIX if len(APP_PREFIX) > 0 else '')}")
response = Flask.make_response(app, {
"status": False,
"message": "Unauthorized access.",
@ -1693,8 +1686,6 @@ def API_sharePeer_update():
data: dict[str, str] = request.get_json()
ShareID: str = data.get("ShareID")
ExpireDate: str = data.get("ExpireDate")
print(ShareID)
print(ExpireDate)
if ShareID is None:
return ResponseObject(False, "Please specify ShareID")
@ -2077,7 +2068,6 @@ def index():
Index page related
@return: Template
"""
print(APP_PREFIX)
return render_template('index.html', APP_PREFIX=APP_PREFIX)