proto_ppp.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local map, section, net = ...
  4. local device, username, password
  5. local ipv6, defaultroute, metric, peerdns, dns,
  6. keepalive_failure, keepalive_interval, demand, mtu
  7. device = section:taboption("general", Value, "device", translate("Modem device"))
  8. device.rmempty = false
  9. local device_suggestions = nixio.fs.glob("/dev/tty*S*")
  10. or nixio.fs.glob("/dev/tts/*")
  11. if device_suggestions then
  12. local node
  13. for node in device_suggestions do
  14. device:value(node)
  15. end
  16. end
  17. username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
  18. password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
  19. password.password = true
  20. if luci.model.network:has_ipv6() then
  21. ipv6 = section:taboption("advanced", Flag, "ipv6",
  22. translate("Enable IPv6 negotiation on the PPP link"))
  23. ipv6.default = ipv6.disabled
  24. end
  25. defaultroute = section:taboption("advanced", Flag, "defaultroute",
  26. translate("Use default gateway"),
  27. translate("If unchecked, no default route is configured"))
  28. defaultroute.default = defaultroute.enabled
  29. metric = section:taboption("advanced", Value, "metric",
  30. translate("Use gateway metric"))
  31. metric.placeholder = "0"
  32. metric.datatype = "uinteger"
  33. metric:depends("defaultroute", defaultroute.enabled)
  34. peerdns = section:taboption("advanced", Flag, "peerdns",
  35. translate("Use DNS servers advertised by peer"),
  36. translate("If unchecked, the advertised DNS server addresses are ignored"))
  37. peerdns.default = peerdns.enabled
  38. dns = section:taboption("advanced", DynamicList, "dns",
  39. translate("Use custom DNS servers"))
  40. dns:depends("peerdns", "")
  41. dns.datatype = "ipaddr"
  42. dns.cast = "string"
  43. keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
  44. translate("LCP echo failure threshold"),
  45. translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
  46. function keepalive_failure.cfgvalue(self, section)
  47. local v = m:get(section, "keepalive")
  48. if v and #v > 0 then
  49. return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
  50. end
  51. end
  52. keepalive_failure.placeholder = "0"
  53. keepalive_failure.datatype = "uinteger"
  54. keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
  55. translate("LCP echo interval"),
  56. translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
  57. function keepalive_interval.cfgvalue(self, section)
  58. local v = m:get(section, "keepalive")
  59. if v and #v > 0 then
  60. return tonumber(v:match("^%d+[ ,]+(%d+)"))
  61. end
  62. end
  63. function keepalive_interval.write(self, section, value)
  64. local f = tonumber(keepalive_failure:formvalue(section)) or 0
  65. local i = tonumber(value) or 5
  66. if i < 1 then i = 1 end
  67. if f > 0 then
  68. m:set(section, "keepalive", "%d %d" %{ f, i })
  69. else
  70. m:del(section, "keepalive")
  71. end
  72. end
  73. keepalive_interval.remove = keepalive_interval.write
  74. keepalive_failure.write = keepalive_interval.write
  75. keepalive_failure.remove = keepalive_interval.write
  76. keepalive_interval.placeholder = "5"
  77. keepalive_interval.datatype = "min(1)"
  78. demand = section:taboption("advanced", Value, "demand",
  79. translate("Inactivity timeout"),
  80. translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
  81. demand.placeholder = "0"
  82. demand.datatype = "uinteger"
  83. mtu = section:taboption("advanced", Value, "mtu", translate("Override MTU"))
  84. mtu.placeholder = "1500"
  85. mtu.datatype = "max(9200)"