Merge pull request #2534 from dibdot/travelmate
[oweals/luci.git] / applications / luci-app-travelmate / luasrc / model / cbi / travelmate / overview_tab.lua
1 -- Copyright 2017-2019 Dirk Brenken (dev@brenken.org)
2 -- This is free software, licensed under the Apache License, Version 2.0
3
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 ""
12
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"))
18 m:chain("network")
19 m:chain("firewall")
20
21 -- Interface Wizard
22
23 if uplink == "" then
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))"
30         o.default = trmiface
31         o.rmempty = false
32
33         function o.validate(self, value)
34                 if value then
35                         local nwnet = nw:get_network(value)
36                         local zone  = fw:get_zone("wan")
37                         local fwnet = fw:get_zone_by_network(value)
38                         if not nwnet then
39                                 nwnet = nw:add_network(value, { proto = "dhcp" })
40                         end
41                         if zone and not fwnet then
42                                 fwnet = zone:add_network(value)
43                         end
44                 end
45                 return value
46         end
47         return m
48 end
49
50 -- Main travelmate options
51
52 s = m:section(NamedSection, "global", "travelmate")
53
54 o1 = s:option(Flag, "trm_enabled", translate("Enable Travelmate"))
55 o1.default = o1.disabled
56 o1.rmempty = false
57
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
61 o2.rmempty = false
62
63 o3 = s:option(Flag, "trm_proactive", translate("ProActive Uplink Switch"),
64         translate("Proactively scan and switch to a higher prioritized uplink, despite of an already existing connection."))
65 o3.default = o3.enabled
66 o3.rmempty = false
67
68 o4 = s:option(ListValue, "trm_iface", translate("Uplink / Trigger interface"),
69         translate("Name of the used uplink interface."))
70 if dump then
71         local i, v
72         for i, v in ipairs(dump.interface) do
73                 if v.interface ~= "loopback" and v.interface ~= "lan" then
74                         local device = v.l3_device or v.device or "-"
75                         o4:value(v.interface, v.interface.. " (" ..device.. ")")
76                 end
77         end
78 end
79 o4.default = trmiface
80 o4.rmempty = false
81
82 -- Runtime information
83
84 ds = s:option(DummyValue, "_dummy")
85 ds.template = "travelmate/runtime"
86
87 -- Extra options
88
89 e = m:section(NamedSection, "global", "travelmate", translate("Extra Options"),
90 translate("Options for further tweaking in case the defaults are not suitable for you."))
91
92 e1 = e:option(Flag, "trm_debug", translate("Enable Verbose Debug Logging"))
93 e1.default = e1.disabled
94 e1.rmempty = false
95
96 e2 = e:option(Value, "trm_radio", translate("Radio Selection / Order"),
97         translate("Restrict travelmate to a single radio (e.g. 'radio1') or change the overall scanning order (e.g. 'radio1 radio2 radio0')."))
98 e2.rmempty = true
99
100 e3 = e:option(Value, "trm_triggerdelay", translate("Trigger Delay"),
101         translate("Additional trigger delay in seconds before travelmate processing begins."))
102 e3.datatype = "range(1,60)"
103 e3.default = 2
104 e3.rmempty = false
105
106 e4 = e:option(Value, "trm_maxretry", translate("Connection Limit"),
107         translate("Retry limit to connect to an uplink."))
108 e4.default = 3
109 e4.datatype = "range(1,10)"
110 e4.rmempty = false
111
112 e5 = e:option(Value, "trm_minquality", translate("Signal Quality Threshold"),
113         translate("Minimum signal quality threshold as percent for conditional uplink (dis-) connections."))
114 e5.default = 35
115 e5.datatype = "range(20,80)"
116 e5.rmempty = false
117
118 e6 = e:option(Value, "trm_maxwait", translate("Interface Timeout"),
119         translate("How long should travelmate wait for a successful wlan uplink connection."))
120 e6.default = 30
121 e6.datatype = "range(20,40)"
122 e6.rmempty = false
123
124 e7 = e:option(Value, "trm_timeout", translate("Overall Timeout"),
125         translate("Overall retry timeout in seconds."))
126 e7.default = 60
127 e7.datatype = "range(30,300)"
128 e7.rmempty = false
129
130 return m