proto_ppp.lua 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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", "pppossh"}) 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. elseif p == "pppossh" then
  21. return luci.i18n.translate("PPPoSSH")
  22. end
  23. end
  24. function proto.ifname(self)
  25. return p .. "-" .. self.sid
  26. end
  27. function proto.opkg_package(self)
  28. if p == "ppp" then
  29. return p
  30. elseif p == "3g" then
  31. return "comgt"
  32. elseif p == "pptp" then
  33. return "ppp-mod-pptp"
  34. elseif p == "pppoe" then
  35. return "ppp-mod-pppoe"
  36. elseif p == "pppoa" then
  37. return "ppp-mod-pppoa"
  38. elseif p == "l2tp" then
  39. return "xl2tpd"
  40. elseif p == "pppossh" then
  41. return "pppossh"
  42. end
  43. end
  44. function proto.is_installed(self)
  45. if p == "pppoa" then
  46. return (nixio.fs.glob("/usr/lib/pppd/*/pppoatm.so")() ~= nil)
  47. elseif p == "pppoe" then
  48. return (nixio.fs.glob("/usr/lib/pppd/*/rp-pppoe.so")() ~= nil)
  49. elseif p == "pptp" then
  50. return (nixio.fs.glob("/usr/lib/pppd/*/pptp.so")() ~= nil)
  51. elseif p == "3g" then
  52. return nixio.fs.access("/lib/netifd/proto/3g.sh")
  53. elseif p == "l2tp" then
  54. return nixio.fs.access("/lib/netifd/proto/l2tp.sh")
  55. elseif p == "pppossh" then
  56. return nixio.fs.access("/lib/netifd/proto/pppossh.sh")
  57. else
  58. return nixio.fs.access("/lib/netifd/proto/ppp.sh")
  59. end
  60. end
  61. function proto.is_floating(self)
  62. return (p ~= "pppoe")
  63. end
  64. function proto.is_virtual(self)
  65. return true
  66. end
  67. function proto.get_interfaces(self)
  68. if self:is_floating() then
  69. return nil
  70. else
  71. return netmod.protocol.get_interfaces(self)
  72. end
  73. end
  74. function proto.contains_interface(self, ifc)
  75. if self:is_floating() then
  76. return (netmod:ifnameof(ifc) == self:ifname())
  77. else
  78. return netmod.protocol.contains_interface(self, ifc)
  79. end
  80. end
  81. netmod:register_pattern_virtual("^%s-%%w" % p)
  82. end