6a5d3c3622d7c45f273f69641949e75c68f59cd9
[project/luci.git] / protocols / ppp / luasrc / model / cbi / admin_network / proto_pppoe.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
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 username, password, ac, service
16 local ipv6, defaultroute, metric, peerdns, dns,
17       keepalive_failure, keepalive_interval, demand
18
19
20 username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
21
22
23 password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
24 password.password = true
25
26
27 ac = section:taboption("general", Value, "ac",
28         translate("Access Concentrator"),
29         translate("Leave empty to autodetect"))
30
31 ac.placeholder = translate("auto")
32
33
34 service = section:taboption("general", Value, "service",
35         translate("Service Name"),
36         translate("Leave empty to autodetect"))
37
38 service.placeholder = translate("auto")
39
40
41 if 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
48 end
49
50
51 defaultroute = section:taboption("advanced", Flag, "defaultroute",
52         translate("Use default gateway"),
53         translate("If unchecked, no default route is configured"))
54
55 defaultroute.default = defaultroute.enabled
56
57
58 metric = section:taboption("advanced", Value, "metric",
59         translate("Use gateway metric"))
60
61 metric.placeholder = "0"
62 metric.datatype    = "uinteger"
63 metric:depends("defaultroute", defaultroute.enabled)
64
65
66 peerdns = 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
70 peerdns.default = peerdns.enabled
71
72
73 dns = section:taboption("advanced", DynamicList, "dns",
74         translate("Use custom DNS servers"))
75
76 dns:depends("peerdns", "")
77 dns.datatype = "ipaddr"
78
79
80 keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
81         translate("LCP echo failure threshold"),
82         translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
83
84 function keepalive_failure.cfgvalue(self, section)
85         local v = m:get(section, "keepalive")
86         if v and #v > 0 then
87                 return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
88         end
89 end
90
91 function keepalive_failure.write() end
92 function keepalive_failure.remove() end
93
94 keepalive_failure.placeholder = "0"
95 keepalive_failure.datatype    = "uinteger"
96
97
98 keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
99         translate("LCP echo interval"),
100         translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
101
102 function keepalive_interval.cfgvalue(self, section)
103         local v = m:get(section, "keepalive")
104         if v and #v > 0 then
105                 return tonumber(v:match("^%d+[ ,]+(%d+)"))
106         end
107 end
108
109 function keepalive_interval.write(self, section, value)
110         local f = tonumber(keepalive_failure:formvalue(section)) or 0
111         local i = tonumber(value) or 5
112         if i < 1 then i = 1 end
113         if f > 0 then
114                 m:set(section, "keepalive", "%d %d" %{ f, i })
115         else
116                 m:del(section, "keepalive")
117         end
118 end
119
120 keepalive_interval.remove      = keepalive_interval.write
121 keepalive_interval.placeholder = "5"
122 keepalive_interval.datatype    = "min(1)"
123
124
125 demand = section:taboption("advanced", Value, "demand",
126         translate("Inactivity timeout"),
127         translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
128
129 demand.placeholder = "0"
130 demand.datatype    = "uinteger"