049525d34730402fc301464be2a18c7fc00328e9
[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                 else
73                         return nixio.fs.access("/lib/netifd/proto/ppp.sh")
74                 end
75         end
76
77         function proto.is_floating(self)
78                 return (p ~= "pppoe")
79         end
80
81         function proto.is_virtual(self)
82                 return true
83         end
84
85         function proto.get_interfaces(self)
86                 if self:is_floating() then
87                         return nil
88                 else
89                         return netmod.protocol.get_interfaces(self)
90                 end
91         end
92
93         function proto.contains_interface(self, ifc)
94                 if self:is_floating() then
95                         return (netmod:ifnameof(ifc) == self:ifname())
96                 else
97                         return netmod.protocol.contains_interface(self, ifc)
98                 end
99         end
100
101         netmod:register_pattern_virtual("^%s-%%w" % p)
102 end