11104099cc06d55c5fc6fed14bb3321e942ec6d8
[project/luci.git] / protocols / luci-proto-ppp / luasrc / model / cbi / admin_network / proto_pptp.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2011-2012 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 server, username, password
16 local defaultroute, metric, peerdns, dns,
17         keepalive_failure, keepalive_interval, demand, mtu
18
19
20 server = section:taboption("general", Value, "server", translate("VPN Server"))
21 server.datatype = "host"
22
23
24 username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
25
26
27 password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
28 password.password = true
29
30
31 defaultroute = section:taboption("advanced", Flag, "defaultroute",
32         translate("Use default gateway"),
33         translate("If unchecked, no default route is configured"))
34
35 defaultroute.default = defaultroute.enabled
36
37
38 metric = section:taboption("advanced", Value, "metric",
39         translate("Use gateway metric"))
40
41 metric.placeholder = "0"
42 metric.datatype    = "uinteger"
43 metric:depends("defaultroute", defaultroute.enabled)
44
45
46 peerdns = section:taboption("advanced", Flag, "peerdns",
47         translate("Use DNS servers advertised by peer"),
48         translate("If unchecked, the advertised DNS server addresses are ignored"))
49
50 peerdns.default = peerdns.enabled
51
52
53 dns = section:taboption("advanced", DynamicList, "dns",
54         translate("Use custom DNS servers"))
55
56 dns:depends("peerdns", "")
57 dns.datatype = "ipaddr"
58 dns.cast     = "string"
59
60
61 keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
62         translate("LCP echo failure threshold"),
63         translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
64
65 function keepalive_failure.cfgvalue(self, section)
66         local v = m:get(section, "keepalive")
67         if v and #v > 0 then
68                 return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
69         end
70 end
71
72 keepalive_failure.placeholder = "0"
73 keepalive_failure.datatype    = "uinteger"
74
75
76 keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
77         translate("LCP echo interval"),
78         translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
79
80 function keepalive_interval.cfgvalue(self, section)
81         local v = m:get(section, "keepalive")
82         if v and #v > 0 then
83                 return tonumber(v:match("^%d+[ ,]+(%d+)"))
84         end
85 end
86
87 function keepalive_interval.write(self, section, value)
88         local f = tonumber(keepalive_failure:formvalue(section)) or 0
89         local i = tonumber(value) or 5
90         if i < 1 then i = 1 end
91         if f > 0 then
92                 m:set(section, "keepalive", "%d %d" %{ f, i })
93         else
94                 m:del(section, "keepalive")
95         end
96 end
97
98 keepalive_interval.remove      = keepalive_interval.write
99 keepalive_failure.write        = keepalive_interval.write
100 keepalive_failure.remove       = keepalive_interval.write
101 keepalive_interval.placeholder = "5"
102 keepalive_interval.datatype    = "min(1)"
103
104
105 demand = section:taboption("advanced", Value, "demand",
106         translate("Inactivity timeout"),
107         translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
108
109 demand.placeholder = "0"
110 demand.datatype    = "uinteger"
111
112
113 mtu = section:taboption("advanced", Value, "mtu", translate("Override MTU"))
114 mtu.placeholder = "1500"
115 mtu.datatype    = "max(9200)"