Fix handling default settings
If a setting has ben set to empty string, dict.get will return it and not default argument. This is wrong when default is something else.
This commit is contained in:
parent
f8d71b7b06
commit
cac7658566
|
@ -90,7 +90,7 @@ def save_config():
|
||||||
# config files, then increment version before unlocking.
|
# config files, then increment version before unlocking.
|
||||||
with db.locked():
|
with db.locked():
|
||||||
settings = db.read('settings')
|
settings = db.read('settings')
|
||||||
version = settings['version'] = int(settings.get('version', 0)) + 1
|
version = settings['version'] = int(settings.get('version') or '0') + 1
|
||||||
|
|
||||||
# Populate IP sets.
|
# Populate IP sets.
|
||||||
ipsets = collections.defaultdict(set)
|
ipsets = collections.defaultdict(set)
|
||||||
|
@ -155,7 +155,7 @@ def save_config():
|
||||||
# Print wireguard config.
|
# Print wireguard config.
|
||||||
with open(output / 'etc/wireguard/wg.conf', 'w', encoding='utf-8') as f:
|
with open(output / 'etc/wireguard/wg.conf', 'w', encoding='utf-8') as f:
|
||||||
f.write(wg_intf.format(
|
f.write(wg_intf.format(
|
||||||
port=settings.get('wg_port', 51820),
|
port=settings.get('wg_port') or 51820,
|
||||||
key=settings.get('wg_key')))
|
key=settings.get('wg_key')))
|
||||||
for ip, data in wireguard.items():
|
for ip, data in wireguard.items():
|
||||||
f.write(wg_peer.format(
|
f.write(wg_peer.format(
|
||||||
|
|
|
@ -50,7 +50,7 @@ def new():
|
||||||
server_pubkey = subprocess.run([f'wg pubkey'], input=settings.get('wg_key'),
|
server_pubkey = subprocess.run([f'wg pubkey'], input=settings.get('wg_key'),
|
||||||
text=True, capture_output=True, shell=True).stdout.strip()
|
text=True, capture_output=True, shell=True).stdout.strip()
|
||||||
|
|
||||||
host = ipaddress.ip_interface(settings.get('wg_net', '10.0.0.1/24'))
|
host = ipaddress.ip_interface(settings.get('wg_net') or '10.0.0.1/24')
|
||||||
ip6 = None
|
ip6 = None
|
||||||
with db.locked():
|
with db.locked():
|
||||||
# Find a free address for the new key.
|
# Find a free address for the new key.
|
||||||
|
@ -80,7 +80,7 @@ def new():
|
||||||
# Template arguments.
|
# Template arguments.
|
||||||
args = {
|
args = {
|
||||||
'server': settings.get('wg_endpoint'),
|
'server': settings.get('wg_endpoint'),
|
||||||
'port': settings.get('wg_port', '51820'),
|
'port': settings.get('wg_port') or '51820',
|
||||||
'server_key': server_pubkey,
|
'server_key': server_pubkey,
|
||||||
'pubkey': pubkey,
|
'pubkey': pubkey,
|
||||||
'ip': str(ip),
|
'ip': str(ip),
|
||||||
|
@ -88,7 +88,7 @@ def new():
|
||||||
'timestamp': now,
|
'timestamp': now,
|
||||||
'name': name,
|
'name': name,
|
||||||
'dns': settings.get('wg_dns') if flask.request.json.get('use_dns', True) else False,
|
'dns': settings.get('wg_dns') if flask.request.json.get('use_dns', True) else False,
|
||||||
'allowed_nets': settings.get('wg_allowed_nets', []),
|
'allowed_nets': settings.get('wg_allowed_nets', ''),
|
||||||
'add_default': flask.request.json.get('add_default', False),
|
'add_default': flask.request.json.get('add_default', False),
|
||||||
}
|
}
|
||||||
return flask.render_template('vpn/wg-fri.conf', **args)
|
return flask.render_template('vpn/wg-fri.conf', **args)
|
||||||
|
|
Loading…
Reference in a new issue