luci-proto-ppp: l2tp: allow specifying port in "server" option
[project/luci.git] / protocols / luci-proto-ppp / luasrc / model / network / proto_ppp.lua
1 -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local netmod = luci.model.network
5
6 local _, p
7 for _, p in ipairs({"ppp", "pptp", "pppoe", "pppoa", "3g", "l2tp", "pppossh"}) do
8
9         local proto = netmod:register_protocol(p)
10
11         function proto.get_i18n(self)
12                 if p == "ppp" then
13                         return luci.i18n.translate("PPP")
14                 elseif p == "pptp" then
15                         return luci.i18n.translate("PPtP")
16                 elseif p == "3g" then
17                         return luci.i18n.translate("UMTS/GPRS/EV-DO")
18                 elseif p == "pppoe" then
19                         return luci.i18n.translate("PPPoE")
20                 elseif p == "pppoa" then
21                         return luci.i18n.translate("PPPoATM")
22                 elseif p == "l2tp" then
23                         return luci.i18n.translate("L2TP")
24                 elseif p == "pppossh" then
25                         return luci.i18n.translate("PPPoSSH")
26                 end
27         end
28
29         function proto.ifname(self)
30                 return p .. "-" .. self.sid
31         end
32
33         function proto.opkg_package(self)
34                 if p == "ppp" then
35                         return p
36                 elseif p == "3g" then
37                         return "comgt"
38                 elseif p == "pptp" then
39                         return "ppp-mod-pptp"
40                 elseif p == "pppoe" then
41                         return "ppp-mod-pppoe"
42                 elseif p == "pppoa" then
43                         return "ppp-mod-pppoa"
44                 elseif p == "l2tp" then
45                         return "xl2tpd"
46                 elseif p == "pppossh" then
47                         return "pppossh"
48                 end
49         end
50
51         function proto.is_installed(self)
52                 if p == "pppoa" then
53                         return (nixio.fs.glob("/usr/lib/pppd/*/pppoatm.so")() ~= nil)
54                 elseif p == "pppoe" then
55                         return (nixio.fs.glob("/usr/lib/pppd/*/rp-pppoe.so")() ~= nil)
56                 elseif p == "pptp" then
57                         return (nixio.fs.glob("/usr/lib/pppd/*/pptp.so")() ~= nil)
58                 elseif p == "3g" then
59                         return nixio.fs.access("/lib/netifd/proto/3g.sh")
60                 elseif p == "l2tp" then
61                         return nixio.fs.access("/lib/netifd/proto/l2tp.sh")
62                 elseif p == "pppossh" then
63                         return nixio.fs.access("/lib/netifd/proto/pppossh.sh")
64                 else
65                         return nixio.fs.access("/lib/netifd/proto/ppp.sh")
66                 end
67         end
68
69         function proto.is_floating(self)
70                 return (p ~= "pppoe")
71         end
72
73         function proto.is_virtual(self)
74                 return true
75         end
76
77         function proto.get_interfaces(self)
78                 if self:is_floating() then
79                         return nil
80                 else
81                         return netmod.protocol.get_interfaces(self)
82                 end
83         end
84
85         function proto.contains_interface(self, ifc)
86                 if self:is_floating() then
87                         return (netmod:ifnameof(ifc) == self:ifname())
88                 else
89                         return netmod.protocol.contains_interface(self, ifc)
90                 end
91         end
92
93         netmod:register_pattern_virtual("^%s-%%w" % p)
94 end