diff --git a/wg_dashboard_backend/routers/v1/server.py b/wg_dashboard_backend/routers/v1/server.py index 185c501..1a44ee3 100644 --- a/wg_dashboard_backend/routers/v1/server.py +++ b/wg_dashboard_backend/routers/v1/server.py @@ -122,7 +122,11 @@ def delete_server( @router.post("/stats", dependencies=[Depends(middleware.auth)]) def stats_server(server: schemas.WGServer): - stats = script.wireguard.get_stats(server) + if script.wireguard.is_running(server): + stats = script.wireguard.get_stats(server) + else: + stats = [] + return JSONResponse(content=stats) diff --git a/wg_dashboard_backend/script/wireguard.py b/wg_dashboard_backend/script/wireguard.py index 668d8f7..7459217 100644 --- a/wg_dashboard_backend/script/wireguard.py +++ b/wg_dashboard_backend/script/wireguard.py @@ -108,10 +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 or b'Unable to access interface: No such device' in output: - _LOGGER.warning("Unable to access interface: No such device. (%s)" - "This may indicate that there is a bug somewhere, " - "or that you have manually deleted parts of the database", server.interface) + if output is None: return False except Exception as e: if b'No such device' in e.output: