Always combine IP set data with static network definitions from NetBox

Before we relied on the combined data being present in ipsets.json
when generating a new config, but ipsets.json is only updated through
the form at /ipsets. So submitting any other form after changing
NetBox definitions might crash when trying to find an entry from
networks.json in ipsets.json.

Now we introduce a helper functon to always read both files and
combine the prefixes fron networks.json with ipsets.json. This way it
is not necessary to save a new ipsets.json before other changes.

Also don’t crash when enumerating networks for each VPN group.
This commit is contained in:
Timotej Lazar 2024-08-14 11:25:07 +02:00
parent b6c191e2ce
commit 048195c45c
5 changed files with 41 additions and 26 deletions

View file

@ -8,6 +8,7 @@ import flask
import flask_login
from . import db
from . import ipsets
from . import system
blueprint = flask.Blueprint('vpn', __name__)
@ -25,8 +26,7 @@ def custom():
return flask.Response('forbidden', status=403, mimetype='text/plain')
with db.locked():
keys = {ip: data for ip, data in db.read('wireguard').items() if data.get('networks') and not data.get('user')}
ipsets = db.read('networks') | db.read('ipsets')
return flask.render_template('vpn/custom.html', keys=keys, ipsets=ipsets.keys())
return flask.render_template('vpn/custom.html', keys=keys, ipsets=ipsets.read().keys())
@blueprint.route('/list')
@flask_login.login_required