fix is_installed() check for l2tp
[project/luci.git] / protocols / ppp / luasrc / model / network / proto_ppp.lua
1 --[[
2 LuCI - Network model - 3G, PPP, PPtP, PPPoE and PPPoA protocol extension
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 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17
18 ]]--
19
20 local netmod = luci.model.network
21
22 local _, p
23 for _, p in ipairs({"ppp", "pptp", "pppoe", "pppoa", "3g", "l2tp"}) do
24
25         local proto = netmod:register_protocol(p)
26
27         function proto.get_i18n(self)
28                 if p == "ppp" then
29                         return luci.i18n.translate("PPP")
30                 elseif p == "pptp" then
31                         return luci.i18n.translate("PPtP")
32                 elseif p == "3g" then
33                         return luci.i18n.translate("UMTS/GPRS/EV-DO")
34                 elseif p == "pppoe" then
35                         return luci.i18n.translate("PPPoE")
36                 elseif p == "pppoa" then
37                         return luci.i18n.translate("PPPoATM")
38                 elseif p == "l2tp" then
39                         return luci.i18n.translate("L2TP")
40                 end
41         end
42
43         function proto.ifname(self)
44                 return p .. "-" .. self.sid
45         end
46
47         function proto.opkg_package(self)
48                 if p == "ppp" then
49                         return p
50                 elseif p == "3g" then
51                         return "comgt"
52                 elseif p == "pptp" then
53                         return "ppp-mod-pptp"
54                 elseif p == "pppoe" then
55                         return "ppp-mod-pppoe"
56                 elseif p == "pppoa" then
57                         return "ppp-mod-pppoa"
58                 elseif p == "l2tp" then
59                         return "xl2tpd"
60                 end
61         end
62
63         function proto.is_installed(self)
64                 if p == "pppoa" then
65                         return (nixio.fs.glob("/usr/lib/pppd/*/pppoatm.so")() ~= nil)
66                 elseif p == "pppoe" then
67                         return (nixio.fs.glob("/usr/lib/pppd/*/rp-pppoe.so")() ~= nil)
68                 elseif p == "pptp" then
69                         return (nixio.fs.glob("/usr/lib/pppd/*/pptp.so")() ~= nil)
70                 elseif p == "3g" then
71                         return nixio.fs.access("/lib/netifd/proto/3g.sh")
72                 elseif p == "l2tp" then
73                         return nixio.fs.access("/lib/netifd/proto/l2tp.sh")
74                 else
75                         return nixio.fs.access("/lib/netifd/proto/ppp.sh")
76                 end
77         end
78
79         function proto.is_floating(self)
80                 return (p ~= "pppoe")
81         end
82
83         function proto.is_virtual(self)
84                 return true
85         end
86
87         function proto.get_interfaces(self)
88                 if self:is_floating() then
89                         return nil
90                 else
91                         return netmod.protocol.get_interfaces(self)
92                 end
93         end
94
95         function proto.contains_interface(self, ifc)
96                 if self:is_floating() then
97                         return (netmod:ifnameof(ifc) == self:ifname())
98                 else
99                         return netmod.protocol.contains_interface(self, ifc)
100                 end
101         end
102
103         netmod:register_pattern_virtual("^%s-%%w" % p)
104 end