summaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/cbi.js44
-rw-r--r--modules/luci-base/luasrc/cbi/datatypes.lua80
-rw-r--r--modules/luci-base/luasrc/view/cbi/mvalue.htm2
-rw-r--r--modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi.lua17
-rw-r--r--modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/admin.lua4
-rw-r--r--modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/leds.lua40
6 files changed, 158 insertions, 29 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js
index 0ca7e264a7..8e66cbc380 100644
--- a/modules/luci-base/htdocs/luci-static/resources/cbi.js
+++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js
@@ -118,6 +118,50 @@ var cbi_validators = {
return false;
},
+ 'ipmask': function()
+ {
+ return cbi_validators.ipmask4.apply(this) ||
+ cbi_validators.ipmask6.apply(this);
+ },
+
+ 'ipmask4': function()
+ {
+ var ip = this, mask = 32;
+
+ if (ip.match(/^(\S+)\/(\S+)$/))
+ {
+ ip = RegExp.$1;
+ mask = RegExp.$2;
+ }
+
+ if (!isNaN(mask) && (mask < 0 || mask > 32))
+ return false;
+
+ if (isNaN(mask) && !cbi_validators.ip4addr.apply(mask))
+ return false;
+
+ return cbi_validators.ip4addr.apply(ip);
+ },
+
+ 'ipmask6': function()
+ {
+ var ip = this, mask = 128;
+
+ if (ip.match(/^(\S+)\/(\S+)$/))
+ {
+ ip = RegExp.$1;
+ mask = RegExp.$2;
+ }
+
+ if (!isNaN(mask) && (mask < 0 || mask > 128))
+ return false;
+
+ if (isNaN(mask) && !cbi_validators.ip6addr.apply(mask))
+ return false;
+
+ return cbi_validators.ip6addr.apply(ip);
+ },
+
'port': function()
{
var p = Int(this);
diff --git a/modules/luci-base/luasrc/cbi/datatypes.lua b/modules/luci-base/luasrc/cbi/datatypes.lua
index 626ad91c75..72b41ddad8 100644
--- a/modules/luci-base/luasrc/cbi/datatypes.lua
+++ b/modules/luci-base/luasrc/cbi/datatypes.lua
@@ -131,6 +131,40 @@ function ip6prefix(val)
return ( val and val >= 0 and val <= 128 )
end
+function ipmask(val)
+ return ipmask4(val) or ipmask6(val)
+end
+
+function ipmask4(val)
+ local ip, mask = val:match("^([^/]+)/([^/]+)$")
+ local bits = tonumber(mask)
+
+ if bits and (bits < 0 or bits > 32) then
+ return false
+ end
+
+ if not bits and mask and not ip4addr(mask) then
+ return false
+ end
+
+ return ip4addr(ip or val)
+end
+
+function ipmask6(val)
+ local ip, mask = val:match("^([^/]+)/([^/]+)$")
+ local bits = tonumber(mask)
+
+ if bits and (bits < 0 or bits > 128) then
+ return false
+ end
+
+ if not bits and mask and not ip6addr(mask) then
+ return false
+ end
+
+ return ip6addr(ip or val)
+end
+
function port(val)
val = tonumber(val)
return ( val and val >= 0 and val <= 65535 )
@@ -378,29 +412,29 @@ function dateyyyymmdd(val)
return false;
end
- local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
-
- local function is_leap_year(year)
- return (year % 4 == 0) and ((year % 100 ~= 0) or (year % 400 == 0))
- end
-
- function get_days_in_month(month, year)
- if (month == 2) and is_leap_year(year) then
- return 29
- else
- return days_in_month[month]
- end
- end
- if (year < 2015) then
- return false
- end
- if ((month == 0) or (month > 12)) then
- return false
- end
- if ((day == 0) or (day > get_days_in_month(month, year))) then
- return false
- end
- return true
+ local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+
+ local function is_leap_year(year)
+ return (year % 4 == 0) and ((year % 100 ~= 0) or (year % 400 == 0))
+ end
+
+ function get_days_in_month(month, year)
+ if (month == 2) and is_leap_year(year) then
+ return 29
+ else
+ return days_in_month[month]
+ end
+ end
+ if (year < 2015) then
+ return false
+ end
+ if ((month == 0) or (month > 12)) then
+ return false
+ end
+ if ((day == 0) or (day > get_days_in_month(month, year))) then
+ return false
+ end
+ return true
end
return false
end
diff --git a/modules/luci-base/luasrc/view/cbi/mvalue.htm b/modules/luci-base/luasrc/view/cbi/mvalue.htm
index 246ef43aad..db17450d27 100644
--- a/modules/luci-base/luasrc/view/cbi/mvalue.htm
+++ b/modules/luci-base/luasrc/view/cbi/mvalue.htm
@@ -36,7 +36,7 @@
<label<%= attr("for", cbid.."-"..key)%>></label>
<%=pcdata(self.vallist[i])%>
</label>
- <% if i == self.size then write('<br />') end %>
+ <% if self.size and (i % self.size) == 0 then write('<br />') end %>
<% end %>
</div>
<% end %>
diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi.lua
index 2dff4ddc81..afe0d662b7 100644
--- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi.lua
+++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi.lua
@@ -42,6 +42,9 @@ end
-- wireless toggle was requested, commit and reload page
function m.parse(map)
+ local new_cc = m:formvalue("cbid.wireless.%s.country" % wdev:name())
+ local old_cc = m:get(wdev:name(), "country")
+
if m:formvalue("cbid.wireless.%s.__toggle" % wdev:name()) then
if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
wnet:set("disabled", nil)
@@ -56,7 +59,14 @@ function m.parse(map)
luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", arg[1]))
return
end
+
Map.parse(map)
+
+ if m:get(wdev:name(), "type") == "mac80211" and new_cc and new_cc ~= old_cc then
+ luci.sys.call("iw reg set %q" % new_cc)
+ luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", arg[1]))
+ return
+ end
end
m.title = luci.util.pcdata(wnet:get_i18n())
@@ -94,7 +104,7 @@ local function txpower_current(pwr, list)
end
end
end
- return (list[#list] and list[#list].driver_dbm) or pwr or 0
+ return pwr or ""
end
local iw = luci.sys.wifi.getiwinfo(arg[1])
@@ -191,7 +201,7 @@ end
------------------- MAC80211 Device ------------------
if hwtype == "mac80211" then
- if #tx_power_list > 1 then
+ if #tx_power_list > 0 then
tp = s:taboption("general", ListValue,
"txpower", translate("Transmit Power"), "dBm")
tp.rmempty = true
@@ -200,6 +210,7 @@ if hwtype == "mac80211" then
return txpower_current(Value.cfgvalue(...), tx_power_list)
end
+ tp:value("", translate("auto"))
for _, p in ipairs(tx_power_list) do
tp:value(p.driver_dbm, "%i dBm (%i mW)"
%{ p.display_dbm, p.display_mw })
@@ -251,6 +262,7 @@ if hwtype == "atheros" then
return txpower_current(Value.cfgvalue(...), tx_power_list)
end
+ tp:value("", translate("auto"))
for _, p in ipairs(tx_power_list) do
tp:value(p.driver_dbm, "%i dBm (%i mW)"
%{ p.display_dbm, p.display_mw })
@@ -308,6 +320,7 @@ if hwtype == "broadcom" then
return txpower_current(Value.cfgvalue(...), tx_power_list)
end
+ tp:value("", translate("auto"))
for _, p in ipairs(tx_power_list) do
tp:value(p.driver_dbm, "%i dBm (%i mW)"
%{ p.display_dbm, p.display_mw })
diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/admin.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/admin.lua
index 1e475640be..493a735bde 100644
--- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/admin.lua
+++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/admin.lua
@@ -21,7 +21,7 @@ function s.cfgsections()
return { "_pass" }
end
-function m.on_commit(map)
+function m.parse(map)
local v1 = pw1:formvalue("_pass")
local v2 = pw2:formvalue("_pass")
@@ -36,6 +36,8 @@ function m.on_commit(map)
m.message = translate("Given password confirmation did not match, password not changed!")
end
end
+
+ Map.parse(map)
end
diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/leds.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/leds.lua
index 8d9bcb1371..74e2f1a19d 100644
--- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/leds.lua
+++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/leds.lua
@@ -7,10 +7,11 @@ local sysfs_path = "/sys/class/leds/"
local leds = {}
local fs = require "nixio.fs"
-local util = require "nixio.util"
+local nu = require "nixio.util"
+local util = require "luci.util"
if fs.access(sysfs_path) then
- leds = util.consume((fs.dir(sysfs_path)))
+ leds = nu.consume((fs.dir(sysfs_path)))
end
if #leds == 0 then
@@ -109,6 +110,33 @@ function usbdev.remove(self, section)
end
end
+
+usbport = s:option(MultiValue, "port", translate("USB Ports"))
+usbport:depends("trigger", "usbport")
+usbport.rmempty = true
+usbport.widget = "checkbox"
+usbport.cast = "table"
+usbport.size = 1
+
+function usbport.valuelist(self, section)
+ local port, ports = nil, {}
+ for port in util.imatch(m.uci:get("system", section, "port")) do
+ local b, n = port:match("^usb(%d+)-port(%d+)$")
+ if not (b and n) then
+ b, n = port:match("^(%d+)-(%d+)$")
+ end
+ if b and n then
+ ports[#ports+1] = "usb%u-port%u" %{ tonumber(b), tonumber(n) }
+ end
+ end
+ return ports
+end
+
+function usbport.validate(self, value)
+ return type(value) == "string" and { value } or value
+end
+
+
for p in nixio.fs.glob("/sys/bus/usb/devices/[0-9]*/manufacturer") do
local id = p:match("%d+-%d+")
local mf = nixio.fs.readfile("/sys/bus/usb/devices/" .. id .. "/manufacturer") or "?"
@@ -116,4 +144,12 @@ for p in nixio.fs.glob("/sys/bus/usb/devices/[0-9]*/manufacturer") do
usbdev:value(id, "%s (%s - %s)" %{ id, mf, pr })
end
+for p in nixio.fs.glob("/sys/bus/usb/devices/*/usb[0-9]*-port[0-9]*") do
+ local bus, port = p:match("usb(%d+)-port(%d+)")
+ if bus and port then
+ usbport:value("usb%u-port%u" %{ tonumber(bus), tonumber(port) },
+ "Hub %u, Port %u" %{ tonumber(bus), tonumber(port) })
+ end
+end
+
return m