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"))
35 mode:value("", translate("Modem default"))
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 mode = section:taboption("general", Value, "pdptype", translate("IP Protocol"))
46 mode:value("IP", translate("IPv4"))
47 mode:value("IPV4V6", translate("IPv4+IPv6"))
48 mode:value("IPV6", translate("IPv6"))
51 apn = section:taboption("general", Value, "apn", translate("APN"))
54 pincode = section:taboption("general", Value, "pincode", translate("PIN"))
57 username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
60 password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
61 password.password = true
63 dialnumber = section:taboption("general", Value, "dialnumber", translate("Dial number"))
64 dialnumber.placeholder = "*99***1#"
66 if luci.model.network:has_ipv6() then
68 ipv6 = section:taboption("advanced", ListValue, "ipv6")
69 ipv6:value("auto", translate("Automatic"))
70 ipv6:value("0", translate("Disabled"))
71 ipv6:value("1", translate("Manual"))
77 maxwait = section:taboption("advanced", Value, "maxwait",
78 translate("Modem init timeout"),
79 translate("Maximum amount of seconds to wait for the modem to become ready"))
81 maxwait.placeholder = "20"
82 maxwait.datatype = "min(1)"
85 defaultroute = section:taboption("advanced", Flag, "defaultroute",
86 translate("Use default gateway"),
87 translate("If unchecked, no default route is configured"))
89 defaultroute.default = defaultroute.enabled
91 metric = section:taboption("advanced", Value, "metric",
92 translate("Use gateway metric"))
94 metric.placeholder = "0"
95 metric.datatype = "uinteger"
96 metric:depends("defaultroute", defaultroute.enabled)
99 peerdns = section:taboption("advanced", Flag, "peerdns",
100 translate("Use DNS servers advertised by peer"),
101 translate("If unchecked, the advertised DNS server addresses are ignored"))
103 peerdns.default = peerdns.enabled
106 dns = section:taboption("advanced", DynamicList, "dns",
107 translate("Use custom DNS servers"))
109 dns:depends("peerdns", "")
110 dns.datatype = "ipaddr"
114 keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
115 translate("LCP echo failure threshold"),
116 translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
118 function keepalive_failure.cfgvalue(self, section)
119 local v = m:get(section, "keepalive")
121 return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
125 function keepalive_failure.write() end
126 function keepalive_failure.remove() end
128 keepalive_failure.placeholder = "0"
129 keepalive_failure.datatype = "uinteger"
132 keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
133 translate("LCP echo interval"),
134 translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
136 function keepalive_interval.cfgvalue(self, section)
137 local v = m:get(section, "keepalive")
139 return tonumber(v:match("^%d+[ ,]+(%d+)"))
143 function keepalive_interval.write(self, section, value)
144 local f = tonumber(keepalive_failure:formvalue(section)) or 0
145 local i = tonumber(value) or 5
146 if i < 1 then i = 1 end
148 m:set(section, "keepalive", "%d %d" %{ f, i })
150 m:del(section, "keepalive")
154 keepalive_interval.remove = keepalive_interval.write
155 keepalive_interval.placeholder = "5"
156 keepalive_interval.datatype = "min(1)"
159 demand = section:taboption("advanced", Value, "demand",
160 translate("Inactivity timeout"),
161 translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
163 demand.placeholder = "0"
164 demand.datatype = "uinteger"