Merge pull request #983 from stangri/luci-app-vpnbypass_makefileFix
[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.")
45   .." Please install the package in the "
46   ..[[<a href="]] .. DISP.build_url("admin", "system", "packages")
47   .. "?display=available&query=curl"..[[">]]
48   .. "Software Section" .. [[</a>]]
49   .. "."
50   )
51   use_curl.rmempty = false
52   use_curl.template = "dynapoint/cbi_checkbox"
53 end
54
55 m1 = Map("wireless", "DynaPoint", translate("Dynamic Access Point Manager"))
56
57 aps = m1:section(TypedSection, "wifi-iface", translate("List of Wireless Virtual Interfaces (wVIF)"))
58 aps.addremove = false
59 aps.anonymous = true
60 aps.template  = "cbi/tblsection"
61
62 status = aps:option(DummyValue, "disabled", translate("WiFi Status"))
63 status.template = "dynapoint/cbi_color"
64
65 function status.cfgvalue(self,section)
66   local val = m1:get(section, "disabled")
67   if val == "1" then return translate("Disabled") end
68   if (val == nil or val == "0") then return translate("Enabled") end
69   return val
70 end
71
72 device = aps:option(DummyValue, "device", translate("Device"))
73 function device.cfgvalue(self,section)
74   local dev = m1:get(section, "device")
75   local val = m1:get(dev, "hwmode")
76   if val == "11a" then return dev .. " (5 GHz)"  else
77   return dev .. " (2,4 GHz)"
78   end
79   return val
80 end
81
82
83
84
85
86 mode = aps:option(DummyValue, "mode", translate("Mode"))
87
88 ssid = aps:option(DummyValue, "ssid", translate("SSID"))
89
90
91 action = aps:option(ListValue, "dynapoint_rule", translate("Activate this wVIF if status is:"))
92 action.widget="select"
93 action:value("internet",translate("Online"))
94 action:value("!internet",translate("Offline"))
95 action:value("",translate("Not used by DynaPoint"))
96 action.default = ""
97
98 return m1,m
99