diff --git a/web/vpn.py b/web/vpn.py index 0b77e45..9d6f4c3 100644 --- a/web/vpn.py +++ b/web/vpn.py @@ -33,8 +33,9 @@ def custom(): def list(): # Return logged-in user’s keys, marking the key used for current connection (if any). user = flask_login.current_user.get_id() + remote_addr = ipaddress.ip_address(flask.request.remote_addr) return flask.jsonify([ - data | {'ip': ip, 'active': flask.request.remote_addr in (ip, data.get('ip6'))} + data | {'ip': ip, 'active': any(remote_addr in ipaddress.ip_network(addr) for addr in (ip, data.get('ip6')))} for ip, data in db.load('wireguard').items() if data.get('user') == user ]) @@ -45,7 +46,7 @@ def list_custom(): if not flask_login.current_user.is_admin: return flask.Response('forbidden', status=403, mimetype='text/plain') return flask.jsonify([ - data | {'ip': ip, 'active': flask.request.remote_addr in (ip, data.get('ip6'))} + data | {'ip': ip} for ip, data in db.load('wireguard').items() if data.get('networks') and not data.get('user') ])