root/luci/trunk/protocols/ppp/luasrc/model/cbi/admin_network/proto_ppp.lua @ 8869

Revision 8869, 3.7 KB (checked in by jow, 11 months ago)

protocols/ppp: add mtu options to all ppp protocols, add lcp options to pptp

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, username, password
16local ipv6, defaultroute, metric, peerdns, dns,
17      keepalive_failure, keepalive_interval, demand, mtu
18
19
20device = section:taboption("general", Value, "device", translate("Modem device"))
21device.rmempty = false
22
23local device_suggestions = nixio.fs.glob("/dev/tty*S*")
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
34username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
35
36
37password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
38password.password = true
39
40
41if luci.model.network:has_ipv6() then
42
43    ipv6 = section:taboption("advanced", Flag, "ipv6",
44        translate("Enable IPv6 negotiation on the PPP link"))
45
46    ipv6.default = ipv6.disabled
47
48end
49
50
51defaultroute = section:taboption("advanced", Flag, "defaultroute",
52    translate("Use default gateway"),
53    translate("If unchecked, no default route is configured"))
54
55defaultroute.default = defaultroute.enabled
56
57
58metric = section:taboption("advanced", Value, "metric",
59    translate("Use gateway metric"))
60
61metric.placeholder = "0"
62metric.datatype    = "uinteger"
63metric:depends("defaultroute", defaultroute.enabled)
64
65
66peerdns = section:taboption("advanced", Flag, "peerdns",
67    translate("Use DNS servers advertised by peer"),
68    translate("If unchecked, the advertised DNS server addresses are ignored"))
69
70peerdns.default = peerdns.enabled
71
72
73dns = section:taboption("advanced", DynamicList, "dns",
74    translate("Use custom DNS servers"))
75
76dns:depends("peerdns", "")
77dns.datatype = "ipaddr"
78dns.cast     = "string"
79
80
81keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
82    translate("LCP echo failure threshold"),
83    translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
84
85function keepalive_failure.cfgvalue(self, section)
86    local v = m:get(section, "keepalive")
87    if v and #v > 0 then
88        return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
89    end
90end
91
92function keepalive_failure.write() end
93function keepalive_failure.remove() end
94
95keepalive_failure.placeholder = "0"
96keepalive_failure.datatype    = "uinteger"
97
98
99keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
100    translate("LCP echo interval"),
101    translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
102
103function keepalive_interval.cfgvalue(self, section)
104    local v = m:get(section, "keepalive")
105    if v and #v > 0 then
106        return tonumber(v:match("^%d+[ ,]+(%d+)"))
107    end
108end
109
110function keepalive_interval.write(self, section, value)
111    local f = tonumber(keepalive_failure:formvalue(section)) or 0
112    local i = tonumber(value) or 5
113    if i < 1 then i = 1 end
114    if f > 0 then
115        m:set(section, "keepalive", "%d %d" %{ f, i })
116    else
117        m:del(section, "keepalive")
118    end
119end
120
121keepalive_interval.remove      = keepalive_interval.write
122keepalive_interval.placeholder = "5"
123keepalive_interval.datatype    = "min(1)"
124
125
126demand = section:taboption("advanced", Value, "demand",
127    translate("Inactivity timeout"),
128    translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
129
130demand.placeholder = "0"
131demand.datatype    = "uinteger"
132
133
134mtu = section:taboption("advanced", Value, "mtu", translate("Override MTU"))
135mtu.placeholder = "1500"
136mtu.datatype    = "max(1500)"
Note: See TracBrowser for help on using the browser.