WIP: keep certain push options unchanged

Keep certain push options in uci config untouched by settings update.
i.e. change only toggled settings (use DNS, route all, ...)

Useful when you want to keep manually added routes intact.
parent 96c0797c
Pipeline #60436 passed with stage
in 1 minute and 17 seconds
......@@ -283,7 +283,23 @@ class OpenvpnUci(object):
backend.set_option("openvpn", "server_turris", "status", "/tmp/openvpn-status.log")
backend.set_option("openvpn", "server_turris", "verb", "3")
backend.set_option("openvpn", "server_turris", "mute", "20")
push = [
# filter out unnecessary options
openvpn_data = backend.read("openvpn")
current_push_options = get_option_named(openvpn_data, "openvpn", "server_turris", "push", [])
# TODO: rewrite to something nicer
filtered = []
for opt in current_push_options:
if not route_all and opt.startswith("redirect-gateway"):
continue
if not use_dns and opt.startswith("dhcp-option DNS"):
continue
filtered.append(opt)
new_push_options = [
"route %s %s"
% (
ipaddress.ip_network(f"{lan_ip}/{lan_netmask}", False).network_address,
......@@ -291,14 +307,18 @@ class OpenvpnUci(object):
)
]
if route_all:
push.append("redirect-gateway def1")
new_push_options.append("redirect-gateway def1")
if use_dns:
# 10.111.111.0 -> 10.111.111.1
# TODO this won't work when router ip is set to a different address
push.append(
new_push_options.append(
f"dhcp-option DNS {ipaddress.ip_network(network, False).network_address + 1}"
)
backend.replace_list("openvpn", "server_turris", "push", push)
# merge current and new options instead of simple overwrite with new
push_options = list(set(filtered).union(new_push_options))
backend.replace_list("openvpn", "server_turris", "push", push_options)
else:
backend.add_section("network", "interface", "vpn_turris")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment