mirror of
https://github.com/Ysurac/openmptcprouter-vps-admin.git
synced 2025-02-12 18:41:52 +00:00
Fix wireguard peer
This commit is contained in:
parent
2770e0db99
commit
2e752ad783
1 changed files with 3 additions and 1 deletions
|
@ -2094,6 +2094,8 @@ class WireGuard(BaseModel):
|
||||||
|
|
||||||
@app.post('/wireguard', summary="Modify Wireguard configuration")
|
@app.post('/wireguard', summary="Modify Wireguard configuration")
|
||||||
def wireguard(*, params: WireGuard, current_user: User = Depends(get_current_user)):
|
def wireguard(*, params: WireGuard, current_user: User = Depends(get_current_user)):
|
||||||
|
if not os.path.isfile('/etc/wireguard/wg0.conf'):
|
||||||
|
return {'result': 'error', 'reason': 'Wireguard config not found', 'route': 'wireguard'}
|
||||||
wg_config = configparser.ConfigParser(strict=False)
|
wg_config = configparser.ConfigParser(strict=False)
|
||||||
wg_config.read_file(open(r'/etc/wireguard/wg0.conf'))
|
wg_config.read_file(open(r'/etc/wireguard/wg0.conf'))
|
||||||
wg_port = wg_config.get('Interface', 'ListenPort')
|
wg_port = wg_config.get('Interface', 'ListenPort')
|
||||||
|
@ -2107,7 +2109,7 @@ def wireguard(*, params: WireGuard, current_user: User = Depends(get_current_use
|
||||||
n.write('PrivateKey = ' + wg_key + '\n')
|
n.write('PrivateKey = ' + wg_key + '\n')
|
||||||
for peer in params.peers:
|
for peer in params.peers:
|
||||||
n.write('\n')
|
n.write('\n')
|
||||||
n.write('[Peer]')
|
n.write('[Peer]\n')
|
||||||
n.write('PublicKey = ' + peer.key + '\n')
|
n.write('PublicKey = ' + peer.key + '\n')
|
||||||
n.write('AllowedIPs = ' + peer.ip + '\n')
|
n.write('AllowedIPs = ' + peer.ip + '\n')
|
||||||
move(tmpfile, '/etc/wireguard/wg0.conf')
|
move(tmpfile, '/etc/wireguard/wg0.conf')
|
||||||
|
|
Loading…
Reference in a new issue