1 -- Copyright 2017-2019 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"))
24 ds = m:section(NamedSection, "global", "travelmate", translate("Interface Wizard"))
25 o = ds:option(Value, "trm_iface", translate("Create Uplink interface"),
26 translate("Create a new wireless wan uplink interface, configure it to use dhcp and ")
27 .. translate("add it to the wan zone of the firewall. ")
28 .. translate("This step has only to be done once."))
29 o.datatype = "and(uciname,rangelength(3,15))"
33 function o.validate(self, value)
35 local nwnet = nw:get_network(value)
36 local zone = fw:get_zone("wan")
37 local fwnet = fw:get_zone_by_network(value)
39 nwnet = nw:add_network(value, { proto = "dhcp" })
41 if zone and not fwnet then
42 fwnet = zone:add_network(value)
50 -- Main travelmate options
52 s = m:section(NamedSection, "global", "travelmate")
54 o1 = s:option(Flag, "trm_enabled", translate("Enable Travelmate"))
55 o1.default = o1.disabled
58 o2 = s:option(Flag, "trm_captive", translate("Captive Portal Detection"),
59 translate("Check the internet availability, log captive portal redirections and keep the uplink connection 'alive'."))
60 o2.default = o2.enabled
63 o3 = s:option(Flag, "trm_netcheck", translate("Net Error Check"),
64 translate("Treat missing internet availability as an error."))
65 o3:depends("trm_captive", 1)
66 o3.default = o3.disabled
69 o4 = s:option(Flag, "trm_proactive", translate("ProActive Uplink Switch"),
70 translate("Proactively scan and switch to a higher prioritized uplink, despite of an already existing connection."))
71 o4.default = o4.enabled
74 o5 = s:option(Flag, "trm_autoadd", translate("Add Open Uplinks"),
75 translate("Automatically add open uplinks like hotel captive portals to your wireless config."))
76 o5.default = o5.disabled
79 o6 = s:option(ListValue, "trm_iface", translate("Uplink / Trigger interface"),
80 translate("Name of the used uplink interface."))
83 for i, v in ipairs(dump.interface) do
84 if v.interface ~= "loopback" and v.interface ~= "lan" then
85 local device = v.l3_device or v.device or "-"
86 o6:value(v.interface, v.interface.. " (" ..device.. ")")
93 -- Runtime information
95 ds = s:option(DummyValue, "_dummy")
96 ds.template = "travelmate/runtime"
100 e = m:section(NamedSection, "global", "travelmate", translate("Extra Options"),
101 translate("Options for further tweaking in case the defaults are not suitable for you."))
103 e1 = e:option(Flag, "trm_debug", translate("Enable Verbose Debug Logging"))
104 e1.default = e1.disabled
107 e2 = e:option(Value, "trm_radio", translate("Radio Selection / Order"),
108 translate("Restrict travelmate to a single radio (e.g. 'radio1') or change the overall scanning order (e.g. 'radio1 radio2 radio0')."))
111 e3 = e:option(Value, "trm_listexpiry", translate("List Auto Expiry"),
112 translate("Automatically resets the 'Faulty Stations' list after n minutes. Default is '0' which means no expiry."))
113 e3.datatype = "range(0,300)"
117 e4 = e:option(Value, "trm_triggerdelay", translate("Trigger Delay"),
118 translate("Additional trigger delay in seconds before travelmate processing begins."))
119 e4.datatype = "range(1,60)"
123 e5 = e:option(Value, "trm_maxretry", translate("Connection Limit"),
124 translate("Retry limit to connect to an uplink."))
126 e5.datatype = "range(1,10)"
129 e6 = e:option(Value, "trm_minquality", translate("Signal Quality Threshold"),
130 translate("Minimum signal quality threshold as percent for conditional uplink (dis-) connections."))
132 e6.datatype = "range(20,80)"
135 e7 = e:option(Value, "trm_maxwait", translate("Interface Timeout"),
136 translate("How long should travelmate wait for a successful wlan uplink connection."))
138 e7.datatype = "range(20,40)"
141 e8 = e:option(Value, "trm_timeout", translate("Overall Timeout"),
142 translate("Overall retry timeout in seconds."))
144 e8.datatype = "range(30,300)"
147 e10 = e:option(Value, "trm_scanbuffer", translate("Scan Buffer Size"),
148 translate("Buffer size in bytes to prepare nearby scan results."))
150 e10.datatype = "range(512,4096)"