root/luci/trunk/protocols/3g/luasrc/model/cbi/admin_network/proto_3g.lua @ 9121

Revision 9121, 4.2 KB (checked in by jow, 9 months ago)

protocols/3g: rework service type choices

Line 
1--[[
2LuCI - Lua Configuration Interface
3
4Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11]]--
12
13local map, section, net = ...
14
15local device, apn, service, pincode, username, password
16local ipv6, maxwait, defaultroute, metric, peerdns, dns,
17      keepalive_failure, keepalive_interval, demand
18
19
20device = section:taboption("general", Value, "device", translate("Modem device"))
21device.rmempty = false
22
23local device_suggestions = nixio.fs.glob("/dev/tty[A-Z]*")
24    or nixio.fs.glob("/dev/tts/*")
25
26if device_suggestions then
27    local node
28    for node in device_suggestions do
29        device:value(node)
30    end
31end
32
33
34service = section:taboption("general", Value, "service", translate("Service Type"))
35service:value("", translate("-- Please choose --"))
36service:value("umts", "UMTS/GPRS")
37service:value("umts_only", translate("UMTS only"))
38service:value("gprs_only", translate("GPRS only"))
39service:value("evdo", "CDMA/EV-DO")
40
41
42apn = section:taboption("general", Value, "apn", translate("APN"))
43
44
45pincode = section:taboption("general", Value, "pincode", translate("PIN"))
46
47
48username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
49
50
51password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
52password.password = true
53
54
55if luci.model.network:has_ipv6() then
56
57    ipv6 = section:taboption("advanced", Flag, "ipv6",
58        translate("Enable IPv6 negotiation on the PPP link"))
59
60    ipv6.default = ipv6.disabled
61
62end
63
64
65maxwait = section:taboption("advanced", Value, "maxwait",
66    translate("Modem init timeout"),
67    translate("Maximum amount of seconds to wait for the modem to become ready"))
68
69maxwait.placeholder = "20"
70maxwait.datatype    = "min(1)"
71
72
73defaultroute = section:taboption("advanced", Flag, "defaultroute",
74    translate("Use default gateway"),
75    translate("If unchecked, no default route is configured"))
76
77defaultroute.default = defaultroute.enabled
78
79
80metric = section:taboption("advanced", Value, "metric",
81    translate("Use gateway metric"))
82
83metric.placeholder = "0"
84metric.datatype    = "uinteger"
85metric:depends("defaultroute", defaultroute.enabled)
86
87
88peerdns = section:taboption("advanced", Flag, "peerdns",
89    translate("Use DNS servers advertised by peer"),
90    translate("If unchecked, the advertised DNS server addresses are ignored"))
91
92peerdns.default = peerdns.enabled
93
94
95dns = section:taboption("advanced", DynamicList, "dns",
96    translate("Use custom DNS servers"))
97
98dns:depends("peerdns", "")
99dns.datatype = "ipaddr"
100dns.cast     = "string"
101
102
103keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
104    translate("LCP echo failure threshold"),
105    translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
106
107function keepalive_failure.cfgvalue(self, section)
108    local v = m:get(section, "keepalive")
109    if v and #v > 0 then
110        return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
111    end
112end
113
114function keepalive_failure.write() end
115function keepalive_failure.remove() end
116
117keepalive_failure.placeholder = "0"
118keepalive_failure.datatype    = "uinteger"
119
120
121keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
122    translate("LCP echo interval"),
123    translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
124
125function keepalive_interval.cfgvalue(self, section)
126    local v = m:get(section, "keepalive")
127    if v and #v > 0 then
128        return tonumber(v:match("^%d+[ ,]+(%d+)"))
129    end
130end
131
132function keepalive_interval.write(self, section, value)
133    local f = tonumber(keepalive_failure:formvalue(section)) or 0
134    local i = tonumber(value) or 5
135    if i < 1 then i = 1 end
136    if f > 0 then
137        m:set(section, "keepalive", "%d %d" %{ f, i })
138    else
139        m:del(section, "keepalive")
140    end
141end
142
143keepalive_interval.remove      = keepalive_interval.write
144keepalive_interval.placeholder = "5"
145keepalive_interval.datatype    = "min(1)"
146
147
148demand = section:taboption("advanced", Value, "demand",
149    translate("Inactivity timeout"),
150    translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
151
152demand.placeholder = "0"
153demand.datatype    = "uinteger"
Note: See TracBrowser for help on using the browser.