Parametrize wg.conf template

This commit is contained in:
Timotej Lazar 2023-09-15 13:59:04 +02:00
parent f5af9eeb59
commit d704202e6e
3 changed files with 10 additions and 7 deletions

View file

@ -24,6 +24,8 @@ def create_app(test_config=None):
'admin_mail': '', 'admin_mail': '',
'wg_endpoint': '', 'wg_endpoint': '',
'wg_port': '51820', 'wg_port': '51820',
'wg_allowed_nets': '',
'wg_dns': False,
'wg_key': '', 'wg_key': '',
'wg_net': '', 'wg_net': '',
'version': 0, 'version': 0,

View file

@ -3,17 +3,17 @@
# PublicKey = {{ pubkey }} # PublicKey = {{ pubkey }}
PrivateKey = # paste private key here PrivateKey = # paste private key here
Address = {{ ip }} Address = {{ ip }}
{% if use_dns %}DNS = 212.235.188.28,212.235.188.29,fri1.uni-lj.si{% endif %} {%- if dns %}
DNS = {{ dns }}
{%- endif %}
[Peer] [Peer]
Endpoint = {{ server }}:{{ port }} Endpoint = {{ server }}:{{ port }}
PublicKey = {{ server_key }} PublicKey = {{ server_key }}
PersistentKeepalive = 25 PersistentKeepalive = 25
AllowedIPs = 10.32.0.0/14 {%- for net in allowed_nets.split() %}
AllowedIPs = 212.235.188.16/28 AllowedIPs = {{ net }}
AllowedIPs = 212.235.188.32/27 {%- endfor %}
AllowedIPs = 212.235.188.64/26
{% if add_default -%} {% if add_default -%}
AllowedIPs = 0.0.0.0/0 AllowedIPs = 0.0.0.0/0
{%- endif %} {%- endif %}

View file

@ -67,8 +67,9 @@ def new():
'ip': str(ip), 'ip': str(ip),
'timestamp': now, 'timestamp': now,
'name': name, 'name': name,
'dns': settings.get('wg_dns') if flask.request.json.get('use_dns', True) else False,
'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),
'use_dns': flask.request.json.get('use_dns', True),
} }
return flask.render_template('vpn/wg-fri.conf', **args) return flask.render_template('vpn/wg-fri.conf', **args)