Browse Source

Added import support

pull/4/head
Per-Arne 5 years ago
parent
commit
07e973784a
  1. 6
      README.md
  2. 28
      wg_dashboard_backend/routers/v1/server.py

6
README.md

@ -1,5 +1,5 @@
# wireguard-manager # wg-manager
The wireguard-manager provides a easy-to-use graphical interface to setup and manage wireguard server(s). The wg-manager provides a easy-to-use graphical interface to setup and manage WireGuard server(s).
The following features is implemented: The following features is implemented:
* Create/Delete/Modify Server * Create/Delete/Modify Server
* Create/Delete/Modify Users * Create/Delete/Modify Users
@ -26,7 +26,7 @@ docker run -d \
-v wireguard-manager:/config \ -v wireguard-manager:/config \
-e PORT="8888" \ -e PORT="8888" \
-e ADMIN_USERNAME="admin" \ -e ADMIN_USERNAME="admin" \
-e ADMIN_PASSWORD="admin \ -e ADMIN_PASSWORD="admin" \
perara/wireguard-manager perara/wireguard-manager
``` ```

28
wg_dashboard_backend/routers/v1/server.py

@ -6,6 +6,7 @@ from sqlalchemy.orm import Session
from starlette.responses import JSONResponse from starlette.responses import JSONResponse
import const import const
import models
import schemas import schemas
import middleware import middleware
import db.wireguard import db.wireguard
@ -33,6 +34,7 @@ def add_interface(
): ):
server.post_up = server.post_up if server.post_up != "" else const.DEFAULT_POST_UP server.post_up = server.post_up if server.post_up != "" else const.DEFAULT_POST_UP
server.post_down = server.post_up if server.post_up != "" else const.DEFAULT_POST_DOWN server.post_down = server.post_up if server.post_up != "" else const.DEFAULT_POST_DOWN
peers = server.peers if server.peers else []
# Public/Private key # Public/Private key
try: try:
@ -40,12 +42,30 @@ def add_interface(
if server.filter_query(sess).count() != 0: if server.filter_query(sess).count() != 0:
raise HTTPException(status_code=400, detail="The server interface %s already exists in the database" % server.interface) raise HTTPException(status_code=400, detail="The server interface %s already exists in the database" % server.interface)
keys = script.wireguard.generate_keys() if not server.private_key:
server.private_key = keys["private_key"] keys = script.wireguard.generate_keys()
server.public_key = keys["public_key"] server.private_key = keys["private_key"]
server.configuration = script.wireguard.generate_config(server) server.public_key = keys["public_key"]
server.configuration = script.wireguard.generate_config(server)
server.peers = []
server.sync(sess) server.sync(sess)
if len(peers) > 0:
server.from_db(sess)
for schemaPeer in peers:
schemaPeer.server_id = server.id
schemaPeer.configuration = script.wireguard.generate_config(dict(
peer=schemaPeer,
server=server
))
dbPeer = models.WGPeer(**schemaPeer.dict())
sess.add(dbPeer)
sess.commit()
server.from_db(sess)
except ValueError as e: except ValueError as e:
raise HTTPException(status_code=400, detail=str(e)) raise HTTPException(status_code=400, detail=str(e))

Loading…
Cancel
Save