diff --git a/actions/wireguard b/actions/wireguard index 871dd98a9..19085de33 100755 --- a/actions/wireguard +++ b/actions/wireguard @@ -135,6 +135,9 @@ def _get_info(): lines = output.split('\n') interfaces = {} for line in lines: + if not line: + continue + fields = line.split() interface_name = fields[0] if interface_name in interfaces: @@ -247,7 +250,7 @@ def subcommand_add_server(arguments): def subcommand_modify_server(arguments): """Modify a server.""" interfaces = _get_info() - interfaces.pop(SERVER_INTERFACE) + interfaces.pop(SERVER_INTERFACE, None) interface_to_modify = None for interface in interfaces.values(): if interface['peers']: @@ -280,7 +283,7 @@ def subcommand_modify_server(arguments): def subcommand_remove_server(arguments): """Remove a server.""" interfaces = _get_info() - interfaces.pop(SERVER_INTERFACE) + interfaces.pop(SERVER_INTERFACE, None) interface_to_remove = None for interface in interfaces.values(): if interface['peers']: diff --git a/plinth/modules/wireguard/__init__.py b/plinth/modules/wireguard/__init__.py index 3fcff2b85..21f24aa80 100644 --- a/plinth/modules/wireguard/__init__.py +++ b/plinth/modules/wireguard/__init__.py @@ -120,7 +120,7 @@ def get_info(): """Return server and clients info.""" output = actions.superuser_run('wireguard', ['get-info']) info = json.loads(output) - my_server_info = info.pop(SERVER_INTERFACE) + my_server_info = info.pop(SERVER_INTERFACE, {}) my_client_servers = [] for interface in info.values(): if interface['peers']: @@ -128,8 +128,8 @@ def get_info(): return { 'my_server': { - 'public_key': my_server_info['public_key'], - 'clients': my_server_info['peers'], + 'public_key': my_server_info.get('public_key'), + 'clients': my_server_info.get('peers'), }, 'my_client': { 'servers': my_client_servers,