2 LuCI - Lua Configuration Interface
4 Copyright 2015 Cezary Jackiewicz <cezary.jackiewicz@gmail.com>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
13 local map, section, net = ...
15 local device, apn, service, pincode, username, password, dialnumber
16 local ipv6, maxwait, defaultroute, metric, peerdns, dns,
17 keepalive_failure, keepalive_interval, demand
20 device = section:taboption("general", Value, "device", translate("Modem device"))
21 device.rmempty = false
23 local device_suggestions = nixio.fs.glob("/dev/cdc-wdm*")
24 or nixio.fs.glob("/dev/ttyUSB*")
26 if device_suggestions then
28 for node in device_suggestions do
34 mode = section:taboption("general", Value, "mode", translate("Service Type"))
36 mode:value("preferlte", translate("Prefer LTE"))
37 mode:value("preferumts", translate("Prefer UMTS"))
38 mode:value("lte", "LTE")
39 mode:value("umts", "UMTS/GPRS")
40 mode:value("gsm", translate("GPRS only"))
41 mode:value("auto", translate("auto"))
44 apn = section:taboption("general", Value, "apn", translate("APN"))
47 pincode = section:taboption("general", Value, "pincode", translate("PIN"))
50 username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
53 password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
54 password.password = true
56 dialnumber = section:taboption("general", Value, "dialnumber", translate("Dial number"))
57 dialnumber.placeholder = "*99***1#"
59 if luci.model.network:has_ipv6() then
61 ipv6 = section:taboption("advanced", ListValue, "ipv6")
62 ipv6:value("auto", translate("Automatic"))
63 ipv6:value("0", translate("Disabled"))
64 ipv6:value("1", translate("Manual"))
70 maxwait = section:taboption("advanced", Value, "maxwait",
71 translate("Modem init timeout"),
72 translate("Maximum amount of seconds to wait for the modem to become ready"))
74 maxwait.placeholder = "20"
75 maxwait.datatype = "min(1)"
78 defaultroute = section:taboption("advanced", Flag, "defaultroute",
79 translate("Use default gateway"),
80 translate("If unchecked, no default route is configured"))
82 defaultroute.default = defaultroute.enabled
84 metric = section:taboption("advanced", Value, "metric",
85 translate("Use gateway metric"))
87 metric.placeholder = "0"
88 metric.datatype = "uinteger"
89 metric:depends("defaultroute", defaultroute.enabled)
92 peerdns = section:taboption("advanced", Flag, "peerdns",
93 translate("Use DNS servers advertised by peer"),
94 translate("If unchecked, the advertised DNS server addresses are ignored"))
96 peerdns.default = peerdns.enabled
99 dns = section:taboption("advanced", DynamicList, "dns",
100 translate("Use custom DNS servers"))
102 dns:depends("peerdns", "")
103 dns.datatype = "ipaddr"
107 keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
108 translate("LCP echo failure threshold"),
109 translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
111 function keepalive_failure.cfgvalue(self, section)
112 local v = m:get(section, "keepalive")
114 return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
118 function keepalive_failure.write() end
119 function keepalive_failure.remove() end
121 keepalive_failure.placeholder = "0"
122 keepalive_failure.datatype = "uinteger"
125 keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
126 translate("LCP echo interval"),
127 translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
129 function keepalive_interval.cfgvalue(self, section)
130 local v = m:get(section, "keepalive")
132 return tonumber(v:match("^%d+[ ,]+(%d+)"))
136 function keepalive_interval.write(self, section, value)
137 local f = tonumber(keepalive_failure:formvalue(section)) or 0
138 local i = tonumber(value) or 5
139 if i < 1 then i = 1 end
141 m:set(section, "keepalive", "%d %d" %{ f, i })
143 m:del(section, "keepalive")
147 keepalive_interval.remove = keepalive_interval.write
148 keepalive_interval.placeholder = "5"
149 keepalive_interval.datatype = "min(1)"
152 demand = section:taboption("advanced", Value, "demand",
153 translate("Inactivity timeout"),
154 translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
156 demand.placeholder = "0"
157 demand.datatype = "uinteger"