From 256d7b7901e409c4cb5e88087871585c85a0d16a Mon Sep 17 00:00:00 2001 From: Simon Lerpard Date: Wed, 3 Jun 2020 13:41:16 +0200 Subject: [PATCH 1/3] Fix keeping the server interface state when stop The server interface wasn't updated in the database when it got stopped. Which led to 'is_running' was always set to true, if the server has been started once. Also fixed a copy-paste issue, which didn't affect the code --- wg_dashboard_backend/routers/v1/server.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/wg_dashboard_backend/routers/v1/server.py b/wg_dashboard_backend/routers/v1/server.py index 1f9be45..bed6eb1 100644 --- a/wg_dashboard_backend/routers/v1/server.py +++ b/wg_dashboard_backend/routers/v1/server.py @@ -73,12 +73,14 @@ def add_interface( @router.post("/stop", response_model=schemas.WGServer) -def start_server( - form_data: schemas.WGServer +def stop_server( + server: schemas.WGServer, + sess: Session = Depends(middleware.get_db) ): - script.wireguard.stop_interface(form_data) - form_data.is_running = script.wireguard.is_running(form_data) - return form_data + script.wireguard.stop_interface(server) + server.is_running = script.wireguard.is_running(server) + server.sync(sess) + return server @router.post("/start", response_model=schemas.WGServer) From 665167aa3ffeddd32a75ea257a5efbd0e3911427 Mon Sep 17 00:00:00 2001 From: Simon Lerpard Date: Wed, 3 Jun 2020 13:44:56 +0200 Subject: [PATCH 2/3] Fix detection of 'wg show interface' not running When main.py initializes the subprocess returns an output of 'No such device' but it doesn't throw any exception, for some reason...? So, the output was of course returned to the is_running process and since it wasn't "None" it though the interface was in the 'running' state. --- wg_dashboard_backend/script/wireguard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wg_dashboard_backend/script/wireguard.py b/wg_dashboard_backend/script/wireguard.py index dcce036..2aa3e84 100644 --- a/wg_dashboard_backend/script/wireguard.py +++ b/wg_dashboard_backend/script/wireguard.py @@ -108,7 +108,7 @@ def restart_interface(server: schemas.WGServer): def is_running(server: schemas.WGServer): try: output = _run_wg(server, ["show", server.interface]) - if output is None: + if output is None or b'Unable to access interface: No such device' in output: return False except Exception as e: if b'No such device' in e.output: From 66e68ee9ea7f2455a229d9da90a08f9518e92e8b Mon Sep 17 00:00:00 2001 From: Simon Lerpard Date: Wed, 3 Jun 2020 14:02:16 +0200 Subject: [PATCH 3/3] Fix incorrect port mapping in docker-compose Fixed an incorrect port mapping the the docker-compose example as well as added a restart attribute, since it's most likely a good use case to always keep the server up and running, even if it fails or the host is updated/restarted. Also added a missing end parenthesis in the table of env variables. --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 21b2087..6865297 100644 --- a/README.md +++ b/README.md @@ -33,11 +33,12 @@ The features of wg-manager includes: wireguard: container_name: wg-manager image: perara/wg-manager + restart: always cap_add: - NET_ADMIN #network_mode: host # Alternatively ports: - - 51800:51900/udp + - 51800-51900:51800-51900/udp - 8888:8888 volumes: - ./wg-manager:/config @@ -62,16 +63,16 @@ When docker container/server has started, go to http://localhost:8888 # Environment variables -| Environment | Description | Recommended | -|------------------|--------------------------------------------------------------------------|-------------| -| GUNICORN_CONF | Location of custom gunicorn configuration | default | -| WORKERS_PER_CORE | How many concurrent workers should there be per available core (Gunicorn | default | -| WEB_CONCURRENCY | The number of worker processes for handling requests. (Gunicorn) | 1 | -| HOST | 0.0.0.0 or unix:/tmp/gunicorn.sock if reverse proxy. Remember to mount | 0.0.0.0 | -| PORT | The port to use if running with IP host bind | 80 | -| LOG_LEVEL | Logging level of gunicorn/python | info | -| ADMIN_USERNAME | Default admin username on database creation | admin | -| ADMIN_PASSWORD | Default admin password on database creation | admin | +| Environment | Description | Recommended | +|------------------|---------------------------------------------------------------------------|-------------| +| GUNICORN_CONF | Location of custom gunicorn configuration | default | +| WORKERS_PER_CORE | How many concurrent workers should there be per available core (Gunicorn) | default | +| WEB_CONCURRENCY | The number of worker processes for handling requests. (Gunicorn) | 1 | +| HOST | 0.0.0.0 or unix:/tmp/gunicorn.sock if reverse proxy. Remember to mount | 0.0.0.0 | +| PORT | The port to use if running with IP host bind | 80 | +| LOG_LEVEL | Logging level of gunicorn/python | info | +| ADMIN_USERNAME | Default admin username on database creation | admin | +| ADMIN_PASSWORD | Default admin password on database creation | admin | # Showcase ![Illustration](docs/images/0.png)