Update luci
[librecmc/librecmc.git] / package / luci / protocols / luci-proto-ncm / luasrc / model / cbi / admin_network / proto_ncm.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2015 Cezary Jackiewicz <cezary.jackiewicz@gmail.com>
5
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
9
10         http://www.apache.org/licenses/LICENSE-2.0
11 ]]--
12
13 local map, section, net = ...
14
15 local device, apn, service, pincode, username, password, dialnumber
16 local ipv6, maxwait, defaultroute, metric, peerdns, dns,
17       keepalive_failure, keepalive_interval, demand
18
19
20 device = section:taboption("general", Value, "device", translate("Modem device"))
21 device.rmempty = false
22
23 local device_suggestions = nixio.fs.glob("/dev/cdc-wdm*")
24         or nixio.fs.glob("/dev/ttyUSB*")
25
26 if device_suggestions then
27         local node
28         for node in device_suggestions do
29                 device:value(node)
30         end
31 end
32
33
34 mode = section:taboption("general", Value, "mode", translate("Service Type"))
35 mode.default = "auto"
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"))
42
43
44 apn = section:taboption("general", Value, "apn", translate("APN"))
45
46
47 pincode = section:taboption("general", Value, "pincode", translate("PIN"))
48
49
50 username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
51
52
53 password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
54 password.password = true
55
56 dialnumber = section:taboption("general", Value, "dialnumber", translate("Dial number"))
57 dialnumber.placeholder = "*99***1#"
58
59 if luci.model.network:has_ipv6() then
60
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"))
65         ipv6.default = "auto"
66
67 end
68
69
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"))
73
74 maxwait.placeholder = "20"
75 maxwait.datatype    = "min(1)"
76
77
78 defaultroute = section:taboption("advanced", Flag, "defaultroute",
79         translate("Use default gateway"),
80         translate("If unchecked, no default route is configured"))
81
82 defaultroute.default = defaultroute.enabled
83
84 metric = section:taboption("advanced", Value, "metric",
85         translate("Use gateway metric"))
86
87 metric.placeholder = "0"
88 metric.datatype    = "uinteger"
89 metric:depends("defaultroute", defaultroute.enabled)
90
91
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"))
95
96 peerdns.default = peerdns.enabled
97
98
99 dns = section:taboption("advanced", DynamicList, "dns",
100         translate("Use custom DNS servers"))
101
102 dns:depends("peerdns", "")
103 dns.datatype = "ipaddr"
104 dns.cast     = "string"
105
106
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"))
110
111 function keepalive_failure.cfgvalue(self, section)
112         local v = m:get(section, "keepalive")
113         if v and #v > 0 then
114                 return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
115         end
116 end
117
118 function keepalive_failure.write() end
119 function keepalive_failure.remove() end
120
121 keepalive_failure.placeholder = "0"
122 keepalive_failure.datatype    = "uinteger"
123
124
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"))
128
129 function keepalive_interval.cfgvalue(self, section)
130         local v = m:get(section, "keepalive")
131         if v and #v > 0 then
132                 return tonumber(v:match("^%d+[ ,]+(%d+)"))
133         end
134 end
135
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
140         if f > 0 then
141                 m:set(section, "keepalive", "%d %d" %{ f, i })
142         else
143                 m:del(section, "keepalive")
144         end
145 end
146
147 keepalive_interval.remove      = keepalive_interval.write
148 keepalive_interval.placeholder = "5"
149 keepalive_interval.datatype    = "min(1)"
150
151
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"))
155
156 demand.placeholder = "0"
157 demand.datatype    = "uinteger"