luci-proto-ppp: add support for pppossh
[project/luci.git] / protocols / luci-proto-ppp / luasrc / model / cbi / admin_network / proto_pppossh.lua
1 -- Copyright (C) 2015 Yousong Zhou <yszhou4tech@gmail.com>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local map, section, net = ...
5
6 local sshuser, server, port, ssh_options, identity, ipaddr, peeraddr
7
8 sshuser = section:taboption("general", Value, "sshuser", translate("SSH username"))
9
10 server = section:taboption("general", Value, "server", translate("SSH server address"))
11 server.datatype = "host"
12
13 port = section:taboption("general", Value, "port", translate("SSH server port"))
14 port.datatype = "port"
15 port.optional = true
16 port.default = 22
17
18 ssh_options = section:taboption("general", Value, "ssh_options", translate("Extra SSH command options"))
19 ssh_options.optional = true
20
21 identity = section:taboption("general", DynamicList, "identity", translate("List of SSH key files for auth"))
22 identity.optional = true
23 identity.datatype = "file"
24
25 ipaddr = section:taboption("general", Value, "ipaddr", translate("Local IP address to assign"))
26 ipaddr.datatype = "ipaddr"
27
28 peeraddr = section:taboption("general", Value, "peeraddr", translate("Peer IP address to assign"))
29 peeraddr.datatype = "ipaddr"
30
31
32 local ipv6, defaultroute, metric, peerdns, dns,
33       keepalive_failure, keepalive_interval, demand
34
35 if luci.model.network:has_ipv6() then
36         ipv6 = section:taboption("advanced", Flag, "ipv6",
37                 translate("Enable IPv6 negotiation on the PPP link"))
38         ipv6.default = ipv6.disabled
39 end
40
41
42 defaultroute = section:taboption("advanced", Flag, "defaultroute",
43         translate("Use default gateway"),
44         translate("If unchecked, no default route is configured"))
45
46 defaultroute.default = defaultroute.enabled
47
48
49 metric = section:taboption("advanced", Value, "metric",
50         translate("Use gateway metric"))
51
52 metric.placeholder = "0"
53 metric.datatype    = "uinteger"
54 metric:depends("defaultroute", defaultroute.enabled)
55
56
57 peerdns = section:taboption("advanced", Flag, "peerdns",
58         translate("Use DNS servers advertised by peer"),
59         translate("If unchecked, the advertised DNS server addresses are ignored"))
60
61 peerdns.default = peerdns.enabled
62
63
64 dns = section:taboption("advanced", DynamicList, "dns",
65         translate("Use custom DNS servers"))
66
67 dns:depends("peerdns", "")
68 dns.datatype = "ipaddr"
69 dns.cast     = "string"
70
71
72 keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
73         translate("LCP echo failure threshold"),
74         translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
75
76 function keepalive_failure.cfgvalue(self, section)
77         local v = m:get(section, "keepalive")
78         if v and #v > 0 then
79                 return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
80         end
81 end
82
83 function keepalive_failure.write() end
84 function keepalive_failure.remove() end
85
86 keepalive_failure.placeholder = "0"
87 keepalive_failure.datatype    = "uinteger"
88
89
90 keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
91         translate("LCP echo interval"),
92         translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
93
94 function keepalive_interval.cfgvalue(self, section)
95         local v = m:get(section, "keepalive")
96         if v and #v > 0 then
97                 return tonumber(v:match("^%d+[ ,]+(%d+)"))
98         end
99 end
100
101 function keepalive_interval.write(self, section, value)
102         local f = tonumber(keepalive_failure:formvalue(section)) or 0
103         local i = tonumber(value) or 5
104         if i < 1 then i = 1 end
105         if f > 0 then
106                 m:set(section, "keepalive", "%d %d" %{ f, i })
107         else
108                 m:del(section, "keepalive")
109         end
110 end
111
112 keepalive_interval.remove      = keepalive_interval.write
113 keepalive_interval.placeholder = "5"
114 keepalive_interval.datatype    = "min(1)"
115
116
117 demand = section:taboption("advanced", Value, "demand",
118         translate("Inactivity timeout"),
119         translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
120
121 demand.placeholder = "0"
122 demand.datatype    = "uinteger"