d82c0e26a427f210943dd8201c66b9c7bb9bffc4
[project/luci.git] / protocols / luci-proto-ppp / luasrc / model / network / proto_ppp.lua
1 -- Copyright 2011 Jo-Philipp Wich <xm@subsignal.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"}) 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                 end
25         end
26
27         function proto.ifname(self)
28                 return p .. "-" .. self.sid
29         end
30
31         function proto.opkg_package(self)
32                 if p == "ppp" then
33                         return p
34                 elseif p == "3g" then
35                         return "comgt"
36                 elseif p == "pptp" then
37                         return "ppp-mod-pptp"
38                 elseif p == "pppoe" then
39                         return "ppp-mod-pppoe"
40                 elseif p == "pppoa" then
41                         return "ppp-mod-pppoa"
42                 elseif p == "l2tp" then
43                         return "xl2tpd"
44                 end
45         end
46
47         function proto.is_installed(self)
48                 if p == "pppoa" then
49                         return (nixio.fs.glob("/usr/lib/pppd/*/pppoatm.so")() ~= nil)
50                 elseif p == "pppoe" then
51                         return (nixio.fs.glob("/usr/lib/pppd/*/rp-pppoe.so")() ~= nil)
52                 elseif p == "pptp" then
53                         return (nixio.fs.glob("/usr/lib/pppd/*/pptp.so")() ~= nil)
54                 elseif p == "3g" then
55                         return nixio.fs.access("/lib/netifd/proto/3g.sh")
56                 elseif p == "l2tp" then
57                         return nixio.fs.access("/lib/netifd/proto/l2tp.sh")
58                 else
59                         return nixio.fs.access("/lib/netifd/proto/ppp.sh")
60                 end
61         end
62
63         function proto.is_floating(self)
64                 return (p ~= "pppoe")
65         end
66
67         function proto.is_virtual(self)
68                 return true
69         end
70
71         function proto.get_interfaces(self)
72                 if self:is_floating() then
73                         return nil
74                 else
75                         return netmod.protocol.get_interfaces(self)
76                 end
77         end
78
79         function proto.contains_interface(self, ifc)
80                 if self:is_floating() then
81                         return (netmod:ifnameof(ifc) == self:ifname())
82                 else
83                         return netmod.protocol.contains_interface(self, ifc)
84                 end
85         end
86
87         netmod:register_pattern_virtual("^%s-%%w" % p)
88 end