dynapoint.lua 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. Please install the package in the")
  34. ..[[ <a href="]] .. DISP.build_url("admin", "system", "packages")
  35. .. "?display=available&query=curl"..[[">]]
  36. .. translate ("Software Section") .. [[</a>]]
  37. .. "."
  38. )
  39. use_curl.rmempty = false
  40. use_curl.template = "dynapoint/cbi_checkbox"
  41. end
  42. m1 = Map("wireless", "DynaPoint", translate("Dynamic Access Point Manager"))
  43. aps = m1:section(TypedSection, "wifi-iface", translate("List of Wireless Virtual Interfaces (wVIF)"))
  44. aps.addremove = false
  45. aps.anonymous = true
  46. aps.template = "cbi/tblsection"
  47. status = aps:option(DummyValue, "disabled", translate("WiFi Status"))
  48. status.template = "dynapoint/cbi_color"
  49. function status.cfgvalue(self,section)
  50. local val = m1:get(section, "disabled")
  51. if val == "1" then return translate("Disabled") end
  52. if (val == nil or val == "0") then return translate("Enabled") end
  53. return val
  54. end
  55. device = aps:option(DummyValue, "device", translate("Device"))
  56. function device.cfgvalue(self,section)
  57. local dev = m1:get(section, "device")
  58. local val = m1:get(dev, "hwmode")
  59. if val == "11a" then return dev .. " (5 GHz)" else
  60. return dev .. " (2,4 GHz)"
  61. end
  62. return val
  63. end
  64. mode = aps:option(DummyValue, "mode", translate("Mode"))
  65. ssid = aps:option(DummyValue, "ssid", translate("SSID"))
  66. action = aps:option(ListValue, "dynapoint_rule", translate("Activate this wVIF if status is:"))
  67. action.widget="select"
  68. action:value("internet",translate("Online"))
  69. action:value("!internet",translate("Offline"))
  70. action:value("",translate("Not used by DynaPoint"))
  71. action.default = ""
  72. return m1,m