8f463e5d76a2cc203dce32ef4493de18576d5fd6
[project/luci.git] / protocols / luci-proto-ppp / luasrc / model / cbi / admin_network / proto_pppoa.lua
1 -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local map, section, net = ...
5
6 local encaps, atmdev, vci, vpi, username, password
7 local ipv6, defaultroute, metric, peerdns, dns,
8       keepalive_failure, keepalive_interval, demand, mtu
9
10
11 encaps = section:taboption("general", ListValue, "encaps", translate("PPPoA Encapsulation"))
12 encaps:value("vc", "VC-Mux")
13 encaps:value("llc", "LLC")
14
15
16 atmdev = section:taboption("general", Value, "atmdev", translate("ATM device number"))
17 atmdev.default  = "0"
18 atmdev.datatype = "uinteger"
19
20
21 vci = section:taboption("general", Value, "vci", translate("ATM Virtual Channel Identifier (VCI)"))
22 vci.default  = "35"
23 vci.datatype = "uinteger"
24
25
26 vpi = section:taboption("general", Value, "vpi", translate("ATM Virtual Path Identifier (VPI)"))
27 vpi.default  = "8"
28 vpi.datatype = "uinteger"
29
30
31 username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
32
33
34 password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
35 password.password = true
36
37
38 if luci.model.network:has_ipv6() then
39
40         ipv6 = section:taboption("advanced", ListValue, "ipv6")
41         ipv6:value("auto", translate("Automatic"))
42         ipv6:value("0", translate("Disabled"))
43         ipv6:value("1", translate("Manual"))
44         ipv6.default = "auto"
45
46 end
47
48
49 defaultroute = section:taboption("advanced", Flag, "defaultroute",
50         translate("Use default gateway"),
51         translate("If unchecked, no default route is configured"))
52
53 defaultroute.default = defaultroute.enabled
54
55
56 metric = section:taboption("advanced", Value, "metric",
57         translate("Use gateway metric"))
58
59 metric.placeholder = "0"
60 metric.datatype    = "uinteger"
61 metric:depends("defaultroute", defaultroute.enabled)
62
63
64 peerdns = section:taboption("advanced", Flag, "peerdns",
65         translate("Use DNS servers advertised by peer"),
66         translate("If unchecked, the advertised DNS server addresses are ignored"))
67
68 peerdns.default = peerdns.enabled
69
70
71 dns = section:taboption("advanced", DynamicList, "dns",
72         translate("Use custom DNS servers"))
73
74 dns:depends("peerdns", "")
75 dns.datatype = "ipaddr"
76 dns.cast     = "string"
77
78
79 keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
80         translate("LCP echo failure threshold"),
81         translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
82
83 function keepalive_failure.cfgvalue(self, section)
84         local v = m:get(section, "keepalive")
85         if v and #v > 0 then
86                 return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
87         end
88 end
89
90 keepalive_failure.placeholder = "0"
91 keepalive_failure.datatype    = "uinteger"
92
93
94 keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
95         translate("LCP echo interval"),
96         translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
97
98 function keepalive_interval.cfgvalue(self, section)
99         local v = m:get(section, "keepalive")
100         if v and #v > 0 then
101                 return tonumber(v:match("^%d+[ ,]+(%d+)"))
102         end
103 end
104
105 function keepalive_interval.write(self, section, value)
106         local f = tonumber(keepalive_failure:formvalue(section)) or 0
107         local i = tonumber(value) or 5
108         if i < 1 then i = 1 end
109         if f > 0 then
110                 m:set(section, "keepalive", "%d %d" %{ f, i })
111         else
112                 m:del(section, "keepalive")
113         end
114 end
115
116 keepalive_interval.remove      = keepalive_interval.write
117 keepalive_failure.write        = keepalive_interval.write
118 keepalive_failure.remove       = keepalive_interval.write
119 keepalive_interval.placeholder = "5"
120 keepalive_interval.datatype    = "min(1)"
121
122
123 demand = section:taboption("advanced", Value, "demand",
124         translate("Inactivity timeout"),
125         translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
126
127 demand.placeholder = "0"
128 demand.datatype    = "uinteger"
129
130
131 mtu = section:taboption("advanced", Value, "mtu", translate("Override MTU"))
132 mtu.placeholder = "1500"
133 mtu.datatype    = "max(9200)"