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 json = require("luci.jsonc")
7 local util = require("luci.util")
8 local nw = require("luci.model.network").init()
9 local fw = require("luci.model.firewall").init()
10 local dump = util.ubus("network.interface", "dump", {})
11 local trmiface = uci:get("travelmate", "global", "trm_iface") or "trm_wwan"
12 local trminput = uci:get("travelmate", "global", "trm_rtfile") or "/tmp/trm_runtime.json"
13 local uplink = uci:get("network", trmiface) or ""
14 local parse = json.parse(fs.readfile(trminput) or "")
16 m = Map("travelmate", translate("Travelmate"),
17 translate("Configuration of the travelmate package to to enable travel router functionality. ")
18 .. translatef("For further information "
19 .. "<a href=\"%s\" target=\"_blank\">"
20 .. "see online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md"))
23 m.apply_on_parse = true
25 function m.on_apply(self)
26 luci.sys.call("env -i /etc/init.d/travelmate restart >/dev/null 2>&1")
27 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "travelmate"))
33 ds = m:section(NamedSection, "global", "travelmate", translate("Interface Wizard"))
34 o = ds:option(Value, "trm_iface", translate("Create Uplink interface"),
35 translate("Create a new wireless wan uplink interface, configure it to use dhcp and ")
36 .. translate("add it to the wan zone of the firewall.<br />")
37 .. translate("This step has only to be done once."))
38 o.datatype = "and(uciname,rangelength(3,15))"
42 function o.validate(self, value)
44 local net = nw:add_network(value, { proto = "dhcp" })
46 local zone = fw:get_zone_by_network("wan")
48 zone:add_network(value)
57 -- Main travelmate options
59 s = m:section(NamedSection, "global", "travelmate")
61 o1 = s:option(Flag, "trm_enabled", translate("Enable travelmate"))
62 o1.default = o1.disabled
65 o2 = s:option(Flag, "trm_captive", translate("Captive Portal Detection"),
66 translate("Check the internet availability, log captive portal redirections and keep the uplink connection 'alive'."))
67 o2.default = o2.enabled
70 o3 = s:option(ListValue, "trm_iface", translate("Uplink / Trigger interface"),
71 translate("Name of the used uplink interface."))
74 for i, v in ipairs(dump.interface) do
75 if v.interface ~= "loopback" and v.interface ~= "lan" then
83 if fs.access("/usr/bin/qrencode") then
84 btn = s:option(Button, "btn", translate("View AP QR-Codes"),
85 translate("Connect your Android or iOS devices to your router's WiFi using the shown QR code."))
86 btn.inputtitle = translate("QR-Codes")
87 btn.inputstyle = "apply"
91 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "travelmate", "apqr"))
95 -- Runtime information
97 ds = m:section(NamedSection, "global", "travelmate", translate("Runtime Information"))
99 dv1 = ds:option(DummyValue, "status", translate("Travelmate Status (Quality)"))
100 dv1.template = "travelmate/runtime"
102 dv1.value = parse.data.travelmate_status or translate("n/a")
104 dv1.value = translate("n/a")
107 dv2 = ds:option(DummyValue, "travelmate_version", translate("Travelmate Version"))
108 dv2.template = "travelmate/runtime"
110 dv2.value = parse.data.travelmate_version or translate("n/a")
112 dv2.value = translate("n/a")
115 dv3 = ds:option(DummyValue, "station_id", translate("Station ID (SSID/BSSID)"))
116 dv3.template = "travelmate/runtime"
118 dv3.value = parse.data.station_id or translate("n/a")
120 dv3.value = translate("n/a")
123 dv4 = ds:option(DummyValue, "station_interface", translate("Station Interface"))
124 dv4.template = "travelmate/runtime"
126 dv4.value = parse.data.station_interface or translate("n/a")
128 dv4.value = translate("n/a")
131 dv5 = ds:option(DummyValue, "station_radio", translate("Station Radio"))
132 dv5.template = "travelmate/runtime"
134 dv5.value = parse.data.station_radio or translate("n/a")
136 dv5.value = translate("n/a")
139 dv6 = ds:option(DummyValue, "last_rundate", translate("Last rundate"))
140 dv6.template = "travelmate/runtime"
142 dv6.value = parse.data.last_rundate or translate("n/a")
144 dv6.value = translate("n/a")
149 e = m:section(NamedSection, "global", "travelmate", translate("Extra options"),
150 translate("Options for further tweaking in case the defaults are not suitable for you."))
152 e1 = e:option(Flag, "trm_debug", translate("Enable verbose debug logging"))
153 e1.default = e1.disabled
156 e2 = e:option(Value, "trm_radio", translate("Radio selection"),
157 translate("Restrict travelmate to a dedicated radio, e.g. 'radio0'."))
158 e2.datatype = "and(uciname,rangelength(6,6))"
161 e3 = e:option(Value, "trm_triggerdelay", translate("Trigger Delay"),
162 translate("Additional trigger delay in seconds before travelmate processing begins."))
163 e3.datatype = "range(1,60)"
167 e4 = e:option(Value, "trm_maxretry", translate("Connection Limit"),
168 translate("Retry limit to connect to an uplink."))
170 e4.datatype = "range(1,10)"
173 e5 = e:option(Value, "trm_minquality", translate("Signal Quality Threshold"),
174 translate("Minimum signal quality threshold as percent for conditional uplink (dis-) connections."))
176 e5.datatype = "range(20,80)"
179 e6 = e:option(Value, "trm_maxwait", translate("Interface Timeout"),
180 translate("How long should travelmate wait for a successful wlan uplink connection."))
182 e6.datatype = "range(20,40)"
185 e7 = e:option(Value, "trm_timeout", translate("Overall Timeout"),
186 translate("Overall retry timeout in seconds."))
188 e7.datatype = "range(30,300)"