proto_ppp.lua 2.1 KB

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