From 6d944bcd99aaef1f9b45f3a788618391fd415353 Mon Sep 17 00:00:00 2001 From: Simon Lerpard Date: Wed, 3 Jun 2020 13:41:16 +0200 Subject: [PATCH] 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)