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"))
22 function m.on_after_commit(self)
23 luci.sys.call("env -i /etc/init.d/travelmate restart >/dev/null 2>&1")
24 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "travelmate"))
30 ds = m:section(NamedSection, "global", "travelmate", translate("Interface Wizard"))
32 o = ds:option(Value, "", translate("Uplink interface"))
33 o.datatype = "and(uciname,rangelength(3,15))"
37 btn = ds:option(Button, "trm_iface", translate("Create Uplink Interface"),
38 translate("Create a new wireless wan uplink interface, configure it to use dhcp and ")
39 .. translate("add it to the wan zone of the firewall. This step has only to be done once."))
40 btn.inputtitle = translate("Add Interface")
41 btn.inputstyle = "apply"
44 function btn.write(self, section)
45 local iface = o:formvalue(section)
47 uci:set("travelmate", section, "trm_iface", iface)
48 uci:save("travelmate")
49 uci:commit("travelmate")
50 local net = nw:add_network(iface, { proto = "dhcp" })
54 local zone = fw:get_zone_by_network("wan")
56 zone:add_network(iface)
61 luci.sys.call("env -i /bin/ubus call network reload >/dev/null 2>&1")
63 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "travelmate"))
68 -- Main travelmate options
70 s = m:section(NamedSection, "global", "travelmate")
72 o1 = s:option(Flag, "trm_enabled", translate("Enable travelmate"))
73 o1.default = o1.disabled
76 o2 = s:option(Flag, "trm_automatic", translate("Enable 'automatic' mode"),
77 translate("Keep travelmate in an active state. Check every n seconds the connection status, i.e. the uplink availability."))
78 o2.default = o2.enabled
81 o3 = s:option(ListValue, "trm_iface", translate("Uplink / Trigger interface"),
82 translate("Name of the used uplink interface."))
85 for i, v in ipairs(dump.interface) do
86 if v.interface ~= "loopback" and v.interface ~= "lan" then
94 o4 = s:option(Value, "trm_triggerdelay", translate("Trigger delay"),
95 translate("Additional trigger delay in seconds before travelmate processing begins."))
97 o4.datatype = "range(1,90)"
100 btn = s:option(Button, "", translate("Manual Rescan"),
101 translate("Force a manual uplink rescan / reconnect in 'trigger' mode."))
102 btn:depends("trm_automatic", "")
103 btn.inputtitle = translate("Rescan")
104 btn.inputstyle = "find"
108 luci.sys.call("env -i /etc/init.d/travelmate start >/dev/null 2>&1")
109 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "travelmate"))
112 -- Runtime information
114 ds = m:section(NamedSection, "global", "travelmate", translate("Runtime Information"))
116 dv1 = ds:option(DummyValue, "status", translate("Travelmate Status"))
117 dv1.template = "travelmate/runtime"
119 dv1.value = translate("n/a")
120 elseif parse.data.travelmate_status == "connected" then
121 dv1.value = translate("connected")
122 elseif parse.data.travelmate_status == "not connected" then
123 dv1.value = translate("not connected")
124 elseif parse.data.travelmate_status == "running" then
125 dv1.value = translate("running")
126 elseif parse.data.travelmate_status == "error" then
127 dv1.value = translate("error")
130 dv2 = ds:option(DummyValue, "travelmate_version", translate("Travelmate Version"))
131 dv2.template = "travelmate/runtime"
133 dv2.value = parse.data.travelmate_version or translate("n/a")
135 dv2.value = translate("n/a")
138 dv3 = ds:option(DummyValue, "station_id", translate("Station ID (SSID/BSSID)"))
139 dv3.template = "travelmate/runtime"
141 dv3.value = parse.data.station_id or translate("n/a")
143 dv3.value = translate("n/a")
146 dv4 = ds:option(DummyValue, "station_interface", translate("Station Interface"))
147 dv4.template = "travelmate/runtime"
149 dv4.value = parse.data.station_interface or translate("n/a")
151 dv4.value = translate("n/a")
154 dv5 = ds:option(DummyValue, "station_radio", translate("Station Radio"))
155 dv5.template = "travelmate/runtime"
157 dv5.value = parse.data.station_radio or translate("n/a")
159 dv5.value = translate("n/a")
162 dv6 = ds:option(DummyValue, "last_rundate", translate("Last rundate"))
163 dv6.template = "travelmate/runtime"
165 dv6.value = parse.data.last_rundate or translate("n/a")
167 dv6.value = translate("n/a")
172 e = m:section(NamedSection, "global", "travelmate", translate("Extra options"),
173 translate("Options for further tweaking in case the defaults are not suitable for you."))
175 e1 = e:option(Flag, "trm_debug", translate("Enable verbose debug logging"))
176 e1.default = e1.disabled
179 e2 = e:option(Value, "trm_radio", translate("Radio selection"),
180 translate("Restrict travelmate to a dedicated radio, e.g. 'radio0'."))
181 e2.datatype = "and(uciname,rangelength(6,6))"
184 e3 = e:option(Value, "trm_maxretry", translate("Connection Limit"),
185 translate("How many times should travelmate try to connect to an Uplink. ")
186 .. translate("To disable this feature set it to '0' which means unlimited retries."))
188 e3.datatype = "range(0,30)"
191 e4 = e:option(Value, "trm_maxwait", translate("Interface Timeout"),
192 translate("How long should travelmate wait for a successful wlan interface reload."))
194 e4.datatype = "range(5,60)"
197 e5 = e:option(Value, "trm_timeout", translate("Overall Timeout"),
198 translate("Timeout in seconds between retries in 'automatic' mode."))
200 e5.datatype = "range(60,300)"