af6f39402504bcf18a4c7c754d92cacbb72459cc
[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"}) 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 end
39 end
40
41 function proto.ifname(self)
42 return p .. "-" .. self.sid
43 end
44
45 function proto.opkg_package(self)
46 if p == "ppp" or p == "pptp" then
47 return p
48 elseif p == "3g" then
49 return "comgt"
50 elseif p == "pppoe" then
51 return "ppp-mod-pppoe"
52 elseif p == "pppoa" then
53 return "ppp-mod-pppoa"
54 end
55 end
56
57 function proto.is_installed(self)
58 return nixio.fs.access("/lib/network/" .. p .. ".sh")
59 end
60
61 function proto.is_floating(self)
62 return (p ~= "pppoe")
63 end
64
65 function proto.is_virtual(self)
66 return true
67 end
68
69 function proto.get_interfaces(self)
70 if self:is_floating() then
71 return nil
72 else
73 return netmod.protocol.get_interfaces(self)
74 end
75 end
76
77 function proto.contains_interface(self, ifc)
78 if self:is_floating() then
79 return (netmod:ifnameof(ifc) == self:ifname())
80 else
81 return netmod.protocol.contains_interface(self, ifc)
82 end
83 end
84
85 netmod:register_pattern_virtual("^%s-%%w" % p)
86 end