dynapoint.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. local uci = require "luci.model.uci".cursor()
  2. local a = require "luci.model.ipkg"
  3. local DISP = require "luci.dispatcher"
  4. local wlcursor = luci.model.uci.cursor_state()
  5. local wireless = wlcursor:get_all("wireless")
  6. local ifaces = {}
  7. for k, v in pairs(wireless) do
  8. if v[".type"] == "wifi-iface" then
  9. table.insert(ifaces, v)
  10. end
  11. end
  12. m = Map("dynapoint")
  13. m:chain("wireless")
  14. s = m:section(NamedSection, "internet", "rule", translate("Configuration"), translate("Check Internet connectivity via HTTP header download"))
  15. hosts = s:option(DynamicList, "hosts", translate("List of host addresses"), translate("List of host addresses (url or IP) to track and request http headers from"))
  16. hosts.datatype = "string"
  17. interval = s:option(Value, "interval", translate("Test-run interval"), translate("Time interval in seconds to re-start a new test run"))
  18. interval.datatype = "uinteger"
  19. interval.default = "30"
  20. offline_treshold = s:option(Value, "offline_threshold", translate("Switch_to_offline threshold"), translate("Failure counter after how many failed download attempts, the state is considered as offline"))
  21. offline_treshold.datatype = "uinteger"
  22. offline_treshold.default = "1"
  23. add_hostname_to_ssid = s:option(Flag, "add_hostname_to_ssid", translate("Append hostname to ssid"), translate("Append the router's hostname to the SSID when connectivity check fails"))
  24. add_hostname_to_ssid.rmempty = false
  25. if (a.installed("curl") == true) then
  26. use_curl = s:option(Flag, "use_curl", translate("Use curl"), translate("Use curl instead of wget for testing the connectivity."))
  27. use_curl.rmempty = false
  28. curl_interface = s:option(Value, "curl_interface", translate("Used interface"), translate("Which interface should curl use. (Use ifconfig to find out)"))
  29. curl_interface.datatype = "string"
  30. curl_interface:depends("use_curl","1")
  31. curl_interface.placeholder = "eth0"
  32. else
  33. use_curl = s:option(Flag, "use_curl", translate("Use curl instead of wget"), translate("Curl is currently not installed.")
  34. .." Please install the package in the "
  35. ..[[<a href="]] .. DISP.build_url("admin", "system", "packages")
  36. .. "?display=available&query=curl"..[[">]]
  37. .. "Software Section" .. [[</a>]]
  38. .. "."
  39. )
  40. use_curl.rmempty = false
  41. use_curl.template = "dynapoint/cbi_checkbox"
  42. end
  43. m1 = Map("wireless", "DynaPoint", translate("Dynamic Access Point Manager"))
  44. aps = m1:section(TypedSection, "wifi-iface", translate("List of Wireless Virtual Interfaces (wVIF)"))
  45. aps.addremove = false
  46. aps.anonymous = true
  47. aps.template = "cbi/tblsection"
  48. status = aps:option(DummyValue, "disabled", translate("WiFi Status"))
  49. status.template = "dynapoint/cbi_color"
  50. function status.cfgvalue(self,section)
  51. local val = m1:get(section, "disabled")
  52. if val == "1" then return translate("Disabled") end
  53. if (val == nil or val == "0") then return translate("Enabled") end
  54. return val
  55. end
  56. device = aps:option(DummyValue, "device", translate("Device"))
  57. function device.cfgvalue(self,section)
  58. local dev = m1:get(section, "device")
  59. local val = m1:get(dev, "hwmode")
  60. if val == "11a" then return dev .. " (5 GHz)" else
  61. return dev .. " (2,4 GHz)"
  62. end
  63. return val
  64. end
  65. mode = aps:option(DummyValue, "mode", translate("Mode"))
  66. ssid = aps:option(DummyValue, "ssid", translate("SSID"))
  67. action = aps:option(ListValue, "dynapoint_rule", translate("Activate this wVIF if status is:"))
  68. action.widget="select"
  69. action:value("internet",translate("Online"))
  70. action:value("!internet",translate("Offline"))
  71. action:value("",translate("Not used by DynaPoint"))
  72. action.default = ""
  73. return m1,m