1 -- Copyright 2017 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("uci")
6 local json = require("luci.jsonc")
7 local nw = require("luci.model.network").init()
8 local fw = require("luci.model.firewall").init()
9 local uplink = uci.get("network", "trm_wwan") or ""
10 local trminput = uci.get("travelmate", "global", "trm_rtfile") or "/tmp/trm_runtime.json"
11 local parse = json.parse(fs.readfile(trminput) 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"))
19 function m.on_after_commit(self)
20 luci.sys.call("/etc/init.d/travelmate restart >/dev/null 2>&1")
21 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "travelmate"))
24 -- Main travelmate options
26 s = m:section(NamedSection, "global", "travelmate")
28 o1 = s:option(Flag, "trm_enabled", translate("Enable travelmate"))
29 o1.default = o1.disabled
32 o2 = s:option(Flag, "trm_automatic", translate("Enable 'automatic' mode"),
33 translate("Keep travelmate in an active state."))
34 o2.default = o2.enabled
37 o3 = s:option(Value, "trm_iface", translate("Restrict interface trigger to certain interface(s)"),
38 translate("Space separated list of interfaces that trigger travelmate processing. "..
39 "To disable event driven (re-)starts remove all entries."))
42 o4 = s:option(Value, "trm_triggerdelay", translate("Trigger delay"),
43 translate("Additional trigger delay in seconds before travelmate processing begins."))
45 o4.datatype = "range(1,90)"
48 o5 = s:option(Flag, "trm_debug", translate("Enable verbose debug logging"))
49 o5.default = o5.disabled
55 dv = s:option(DummyValue, "_dummy", translate("Interface Setup"))
56 dv.template = "cbi/nullsection"
57 btn = s:option(Button, "", translate("Create Uplink Interface"),
58 translate("Automatically create a new wireless wan uplink interface 'trm_wwan', configure it to use dhcp and ")
59 .. translate("add it to the wan zone of the firewall. This step has only to be done once."))
60 btn.inputtitle = translate("Add Interface")
61 btn.inputstyle = "apply"
64 local name = "trm_wwan"
65 local net = nw:add_network(name, { proto = "dhcp" })
69 local zone = fw:get_zone_by_network("wan")
71 zone:add_network(name)
75 luci.sys.call("env -i /bin/ubus call network reload >/dev/null 2>&1")
76 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "travelmate"))
80 dv = s:option(DummyValue, "_dummy", translate("Interface Setup"),
81 translate("<br /> Network Interface 'trm_wwan' created successfully. ")
82 .. translatef("Scan & Add new wireless stations via standard "
84 .. "Wireless Setup</a>", luci.dispatcher.build_url("admin/network/wireless")))
85 dv.template = "cbi/nullsection"
88 -- Runtime information
90 ds = s:option(DummyValue, "_dummy", translate("Runtime information"))
91 ds.template = "cbi/nullsection"
93 dv1 = s:option(DummyValue, "status", translate("Online Status"))
94 dv1.template = "travelmate/runtime"
96 dv1.value = translate("n/a")
97 elseif parse.data.station_connection == "true" then
98 dv1.value = translate("connected")
100 dv1.value = translate("not connected")
103 dv2 = s:option(DummyValue, "travelmate_version", translate("Travelmate version"))
104 dv2.template = "travelmate/runtime"
106 dv2.value = parse.data.travelmate_version or translate("n/a")
108 dv2.value = translate("n/a")
111 dv3 = s:option(DummyValue, "station_ssid", translate("Station SSID"))
112 dv3.template = "travelmate/runtime"
114 dv3.value = parse.data.station_ssid or translate("n/a")
116 dv3.value = translate("n/a")
119 dv4 = s:option(DummyValue, "station_interface", translate("Station Interface"))
120 dv4.template = "travelmate/runtime"
122 dv4.value = parse.data.station_interface or translate("n/a")
124 dv4.value = translate("n/a")
127 dv5 = s:option(DummyValue, "station_radio", translate("Station Radio"))
128 dv5.template = "travelmate/runtime"
130 dv5.value = parse.data.station_radio or translate("n/a")
132 dv5.value = translate("n/a")
135 dv6 = s:option(DummyValue, "last_rundate", translate("Last rundate"))
136 dv6.template = "travelmate/runtime"
138 dv6.value = parse.data.last_rundate or translate("n/a")
140 dv6.value = translate("n/a")
145 e = m:section(NamedSection, "global", "travelmate", translate("Extra options"),
146 translate("Options for further tweaking in case the defaults are not suitable for you."))
148 e1 = e:option(Value, "trm_radio", translate("Radio selection"),
149 translate("Restrict travelmate to a dedicated radio, e.g. 'radio0'"))
152 e2 = e:option(Value, "trm_maxretry", translate("Connection Limit"),
153 translate("How many times should travelmate try to connect to an Uplink"))
155 e2.datatype = "range(1,10)"
158 e3 = e:option(Value, "trm_maxwait", translate("Interface Timeout"),
159 translate("How long should travelmate wait for a successful wlan interface reload"))
161 e3.datatype = "range(5,60)"
164 e4 = e:option(Value, "trm_timeout", translate("Overall Timeout"),
165 translate("Timeout in seconds between retries in 'automatic' mode"))
167 e4.datatype = "range(5,300)"