Rename a variable

This commit is contained in:
Timotej Lazar 2023-09-15 13:58:21 +02:00
parent c64489c163
commit f5af9eeb59

View file

@ -38,22 +38,22 @@ def new():
host = ipaddress.ip_interface(settings.get('wg_net', '10.0.0.1/24')) host = ipaddress.ip_interface(settings.get('wg_net', '10.0.0.1/24'))
with db.locked(): with db.locked():
# Find a free address for the new key. # Find a free address for the new key.
ips = db.read('wireguard') keys = db.read('wireguard')
for ip in host.network.hosts(): for ip in host.network.hosts():
if ip != host.ip and str(ip) not in ips: if ip != host.ip and str(ip) not in keys:
break break
else: else:
return flask.Response('no more available IP addresses', status=500, mimetype='text/plain') return flask.Response('no more available IP addresses', status=500, mimetype='text/plain')
now = datetime.datetime.utcnow() now = datetime.datetime.utcnow()
name = re.sub('[^\w ]', '', flask.request.json.get('name', '')) name = re.sub('[^\w ]', '', flask.request.json.get('name', ''))
ips[str(ip)] = { keys[str(ip)] = {
'key': pubkey, 'key': pubkey,
'time': now.timestamp(), 'time': now.timestamp(),
'user': flask_login.current_user.get_id(), 'user': flask_login.current_user.get_id(),
'name': name, 'name': name,
} }
db.write('wireguard', ips) db.write('wireguard', keys)
# Generate a new config archive for firewall nodes. # Generate a new config archive for firewall nodes.
system.run(system.save_config) system.run(system.save_config)
@ -81,8 +81,8 @@ def delete():
with db.locked(): with db.locked():
user = flask_login.current_user.get_id() user = flask_login.current_user.get_id()
ips = {k: v for k, v in db.read('wireguard').items() if v.get('user') != user or v.get('key') != pubkey} keys = {k: v for k, v in db.read('wireguard').items() if v.get('user') != user or v.get('key') != pubkey}
db.write('wireguard', ips) db.write('wireguard', keys)
system.run(system.save_config) system.run(system.save_config)