Merge pull request #1614 from dibdot/adblock
[project/luci.git] / applications / luci-app-dynapoint / luasrc / model / cbi / dynapoint.lua
1 local uci = require "luci.model.uci".cursor()
2 local a = require "luci.model.ipkg"
3 local DISP = require "luci.dispatcher"
4
5 local wlcursor = luci.model.uci.cursor_state()
6 local wireless = wlcursor:get_all("wireless")
7 local ifaces = {}
8
9 for k, v in pairs(wireless) do
10   if v[".type"] == "wifi-iface" then
11     table.insert(ifaces, v)
12   end
13 end
14
15 m = Map("dynapoint")
16 m:chain("wireless")
17
18 s = m:section(NamedSection, "internet", "rule", translate("Configuration"), translate("Check Internet connectivity via HTTP header download"))
19
20 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"))
21 hosts.datatype = "string"
22
23 interval = s:option(Value, "interval", translate("Test-run interval"), translate("Time interval in seconds to re-start a new test run"))
24 interval.datatype = "uinteger"
25 interval.default = "30"
26
27 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"))
28 offline_treshold.datatype = "uinteger"
29 offline_treshold.default = "1"
30
31 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"))
32 add_hostname_to_ssid.rmempty = false
33
34
35 if (a.installed("curl") == true) then
36   use_curl = s:option(Flag, "use_curl", translate("Use curl"), translate("Use curl instead of wget for testing the connectivity."))
37   use_curl.rmempty = false
38
39   curl_interface = s:option(Value, "curl_interface", translate("Used interface"), translate("Which interface should curl use. (Use ifconfig to find out)"))
40   curl_interface.datatype = "string"
41   curl_interface:depends("use_curl","1")
42   curl_interface.placeholder = "eth0"
43 else
44   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")
45   ..[[ <a href="]] .. DISP.build_url("admin", "system", "packages")
46   .. "?display=available&query=curl"..[[">]]
47   .. translate ("Software Section") .. [[</a>]]
48   .. "."
49   )
50   use_curl.rmempty = false
51   use_curl.template = "dynapoint/cbi_checkbox"
52 end
53
54 m1 = Map("wireless", "DynaPoint", translate("Dynamic Access Point Manager"))
55
56 aps = m1:section(TypedSection, "wifi-iface", translate("List of Wireless Virtual Interfaces (wVIF)"))
57 aps.addremove = false
58 aps.anonymous = true
59 aps.template  = "cbi/tblsection"
60
61 status = aps:option(DummyValue, "disabled", translate("WiFi Status"))
62 status.template = "dynapoint/cbi_color"
63
64 function status.cfgvalue(self,section)
65   local val = m1:get(section, "disabled")
66   if val == "1" then return translate("Disabled") end
67   if (val == nil or val == "0") then return translate("Enabled") end
68   return val
69 end
70
71 device = aps:option(DummyValue, "device", translate("Device"))
72 function device.cfgvalue(self,section)
73   local dev = m1:get(section, "device")
74   local val = m1:get(dev, "hwmode")
75   if val == "11a" then return dev .. " (5 GHz)"  else
76   return dev .. " (2,4 GHz)"
77   end
78   return val
79 end
80
81
82
83
84
85 mode = aps:option(DummyValue, "mode", translate("Mode"))
86
87 ssid = aps:option(DummyValue, "ssid", translate("SSID"))
88
89
90 action = aps:option(ListValue, "dynapoint_rule", translate("Activate this wVIF if status is:"))
91 action.widget="select"
92 action:value("internet",translate("Online"))
93 action:value("!internet",translate("Offline"))
94 action:value("",translate("Not used by DynaPoint"))
95 action.default = ""
96
97 return m1,m
98