1 -- Copyright 2017-2018 Dirk Brenken (dev@brenken.org)
2 -- This is free software, licensed under the Apache License, Version 2.0
4 local fs = require("nixio.fs")
5 local uci = require("luci.model.uci").cursor()
6 local util = require("luci.util")
7 local nw = require("luci.model.network").init()
8 local fw = require("luci.model.firewall").init()
9 local dump = util.ubus("network.interface", "dump", {})
10 local trmiface = uci:get("travelmate", "global", "trm_iface") or "trm_wwan"
11 local uplink = uci:get("network", trmiface) or ""
13 m = Map("travelmate", translate("Travelmate"),
14 translate("Configuration of the travelmate package to to enable travel router functionality. ")
15 .. translatef("For further information "
16 .. "<a href=\"%s\" target=\"_blank\">"
17 .. "see online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md"))
20 m.apply_on_parse = true
22 function m.on_apply(self)
23 luci.sys.call("/etc/init.d/travelmate restart >/dev/null 2>&1")
29 ds = m:section(NamedSection, "global", "travelmate", translate("Interface Wizard"))
30 o = ds:option(Value, "trm_iface", translate("Create Uplink interface"),
31 translate("Create a new wireless wan uplink interface, configure it to use dhcp and ")
32 .. translate("add it to the wan zone of the firewall. ")
33 .. translate("This step has only to be done once."))
34 o.datatype = "and(uciname,rangelength(3,15))"
38 function o.validate(self, value)
40 local nwnet = nw:get_network(value)
41 local zone = fw:get_zone("wan")
42 local fwnet = fw:get_zone_by_network(value)
44 nwnet = nw:add_network(value, { proto = "dhcp" })
46 if zone and not fwnet then
47 fwnet = zone:add_network(value)
55 -- Main travelmate options
57 s = m:section(NamedSection, "global", "travelmate")
59 o1 = s:option(Flag, "trm_enabled", translate("Enable Travelmate"))
60 o1.default = o1.disabled
63 o2 = s:option(Flag, "trm_captive", translate("Captive Portal Detection"),
64 translate("Check the internet availability, log captive portal redirections and keep the uplink connection 'alive'."))
65 o2.default = o2.enabled
68 o3 = s:option(Flag, "trm_proactive", translate("ProActive Uplink Switch"),
69 translate("Proactively scan and switch to a higher prioritized uplink, despite of an already existing connection."))
70 o3.default = o3.enabled
73 o4 = s:option(ListValue, "trm_iface", translate("Uplink / Trigger interface"),
74 translate("Name of the used uplink interface."))
77 for i, v in ipairs(dump.interface) do
78 if v.interface ~= "loopback" and v.interface ~= "lan" then
79 local device = v.l3_device or v.device or "-"
80 o4:value(v.interface, v.interface.. " (" ..device.. ")")
87 -- Runtime information
89 ds = s:option(DummyValue, "_dummy")
90 ds.template = "travelmate/runtime"
94 e = m:section(NamedSection, "global", "travelmate", translate("Extra Options"),
95 translate("Options for further tweaking in case the defaults are not suitable for you."))
97 e1 = e:option(Flag, "trm_debug", translate("Enable Verbose Debug Logging"))
98 e1.default = e1.disabled
101 e2 = e:option(Value, "trm_radio", translate("Radio Selection / Order"),
102 translate("Restrict travelmate to a single radio (e.g. 'radio1') or change the overall scanning order (e.g. 'radio1 radio2 radio0')."))
105 e3 = e:option(Value, "trm_triggerdelay", translate("Trigger Delay"),
106 translate("Additional trigger delay in seconds before travelmate processing begins."))
107 e3.datatype = "range(1,60)"
111 e4 = e:option(Value, "trm_maxretry", translate("Connection Limit"),
112 translate("Retry limit to connect to an uplink."))
114 e4.datatype = "range(1,10)"
117 e5 = e:option(Value, "trm_minquality", translate("Signal Quality Threshold"),
118 translate("Minimum signal quality threshold as percent for conditional uplink (dis-) connections."))
120 e5.datatype = "range(20,80)"
123 e6 = e:option(Value, "trm_maxwait", translate("Interface Timeout"),
124 translate("How long should travelmate wait for a successful wlan uplink connection."))
126 e6.datatype = "range(20,40)"
129 e7 = e:option(Value, "trm_timeout", translate("Overall Timeout"),
130 translate("Overall retry timeout in seconds."))
132 e7.datatype = "range(30,300)"