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 -- Main travelmate options
21 s = m:section(NamedSection, "global", "travelmate")
23 o1 = s:option(Flag, "trm_enabled", translate("Enable travelmate"))
24 o1.default = o1.disabled
27 o2 = s:option(Flag, "trm_automatic", translate("Enable 'automatic' mode"),
28 translate("Keep travelmate in an active state."))
29 o2.default = o2.enabled
32 o3 = s:option(Value, "trm_iface", translate("Restrict interface trigger to certain interface(s)"),
33 translate("Space separated list of interfaces that trigger travelmate processing. "..
34 "To disable event driven (re-)starts remove all entries."))
37 o4 = s:option(Value, "trm_triggerdelay", translate("Trigger delay"),
38 translate("Additional trigger delay in seconds before travelmate processing begins."))
40 o4.datatype = "range(1,90)"
43 o5 = s:option(Flag, "trm_debug", translate("Enable verbose debug logging"))
44 o5.default = o5.disabled
50 dv = s:option(DummyValue, "_dummy", translate("Interface Setup"))
51 dv.template = "cbi/nullsection"
52 btn = s:option(Button, "", translate("Create Uplink Interface"),
53 translate("Automatically create a new wireless wan uplink interface 'trm_wwan', configure it to use dhcp and ")
54 .. translate("add it to the wan zone of the firewall. This step has only to be done once."))
55 btn.inputtitle = translate("Add Interface")
56 btn.inputstyle = "apply"
59 local name = "trm_wwan"
60 local net = nw:add_network(name, { proto = "dhcp" })
64 local zone = fw:get_zone_by_network("wan")
66 zone:add_network(name)
70 luci.sys.call("env -i /bin/ubus call network reload >/dev/null 2>&1")
71 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "travelmate"))
75 dv = s:option(DummyValue, "_dummy", translate("Interface Setup"),
76 translate("<br /> Network Interface 'trm_wwan' created successfully. ")
77 .. translatef("Scan & Add new wireless stations via standard "
79 .. "Wireless Setup</a>", luci.dispatcher.build_url("admin/network/wireless")))
80 dv.template = "cbi/nullsection"
83 -- Runtime information
85 ds = s:option(DummyValue, "_dummy", translate("Runtime information"))
86 ds.template = "cbi/nullsection"
88 dv1 = s:option(DummyValue, "status", translate("Online Status"))
89 dv1.template = "travelmate/runtime"
91 dv1.value = translate("n/a")
92 elseif parse.data.station_connection == "true" then
93 dv1.value = translate("connected")
95 dv1.value = translate("not connected")
98 dv2 = s:option(DummyValue, "travelmate_version", translate("Travelmate version"))
99 dv2.template = "travelmate/runtime"
101 dv2.value = parse.data.travelmate_version or translate("n/a")
103 dv2.value = translate("n/a")
106 dv3 = s:option(DummyValue, "station_ssid", translate("Station SSID"))
107 dv3.template = "travelmate/runtime"
109 dv3.value = parse.data.station_ssid or translate("n/a")
111 dv3.value = translate("n/a")
114 dv4 = s:option(DummyValue, "station_interface", translate("Station Interface"))
115 dv4.template = "travelmate/runtime"
117 dv4.value = parse.data.station_interface or translate("n/a")
119 dv4.value = translate("n/a")
122 dv5 = s:option(DummyValue, "station_radio", translate("Station Radio"))
123 dv5.template = "travelmate/runtime"
125 dv5.value = parse.data.station_radio or translate("n/a")
127 dv5.value = translate("n/a")
130 dv6 = s:option(DummyValue, "last_rundate", translate("Last rundate"))
131 dv6.template = "travelmate/runtime"
133 dv6.value = parse.data.last_rundate or translate("n/a")
135 dv6.value = translate("n/a")
140 e = m:section(NamedSection, "global", "travelmate", translate("Extra options"),
141 translate("Options for further tweaking in case the defaults are not suitable for you."))
143 e1 = e:option(Value, "trm_radio", translate("Radio selection"),
144 translate("Restrict travelmate to a dedicated radio, e.g. 'radio0'"))
147 e2 = e:option(Value, "trm_maxretry", translate("Connection Limit"),
148 translate("How many times should travelmate try to connect to an Uplink"))
150 e2.datatype = "range(1,10)"
153 e3 = e:option(Value, "trm_maxwait", translate("Interface Timeout"),
154 translate("How long should travelmate wait for a successful wlan interface reload"))
156 e3.datatype = "range(5,60)"
159 e4 = e:option(Value, "trm_timeout", translate("Overall Timeout"),
160 translate("Timeout in seconds between retries in 'automatic' mode"))
162 e4.datatype = "range(5,300)"