summaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/cbi.js34
-rw-r--r--modules/luci-base/luasrc/cbi.lua58
-rw-r--r--modules/luci-base/luasrc/cbi/datatypes.lua31
-rw-r--r--modules/luci-base/luasrc/view/cbi/upload.htm16
-rw-r--r--modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/dhcp.lua2
-rw-r--r--modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi.lua4
-rw-r--r--modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/system.lua2
7 files changed, 114 insertions, 33 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js
index 4b7227f1a4..1c4123bdad 100644
--- a/modules/luci-base/htdocs/luci-static/resources/cbi.js
+++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js
@@ -139,10 +139,11 @@ var cbi_validators = {
return (this.match(/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/) != null);
},
- 'host': function()
+ 'host': function(ipv4only)
{
return cbi_validators.hostname.apply(this) ||
- cbi_validators.ipaddr.apply(this);
+ ((ipv4only != 1) && cbi_validators.ipaddr.apply(this)) ||
+ ((ipv4only == 1) && cb_validators.ip4addr.apply(this));
},
'hostname': function()
@@ -161,28 +162,49 @@ var cbi_validators = {
cbi_validators.host.apply(this);
},
- 'hostport': function()
+ 'hostport': function(ipv4only)
{
var hp = this.split(/:/);
if (hp.length == 2)
- return (cbi_validators.host.apply(hp[0]) &&
+ return (cbi_validators.host.apply(hp[0], ipv4only) &&
cbi_validators.port.apply(hp[1]));
return false;
},
- 'ipaddrport': function()
+ 'ip4addrport': function()
{
var hp = this.split(/:/);
if (hp.length == 2)
return (cbi_validators.ipaddr.apply(hp[0]) &&
cbi_validators.port.apply(hp[1]));
-
return false;
},
+ 'ipaddrport': function(bracket)
+ {
+ if (this.match(/^([^\[\]:]+):([^:]+)$/)) {
+ var addr = RegExp.$1
+ var port = RegExp.$2
+ return (cbi_validators.ip4addr.apply(addr) &&
+ cbi_validators.port.apply(port));
+ } else if ((bracket == 1) && (this.match(/^\[(.+)\]:([^:]+)$/))) {
+ var addr = RegExp.$1
+ var port = RegExp.$2
+ return (cbi_validators.ip6addr.apply(addr) &&
+ cbi_validators.port.apply(port));
+ } else if ((bracket != 1) && (this.match(/^([^\[\]]+):([^:]+)$/))) {
+ var addr = RegExp.$1
+ var port = RegExp.$2
+ return (cbi_validators.ip6addr.apply(addr) &&
+ cbi_validators.port.apply(port));
+ } else {
+ return false;
+ }
+ },
+
'wpakey': function()
{
var v = this;
diff --git a/modules/luci-base/luasrc/cbi.lua b/modules/luci-base/luasrc/cbi.lua
index 8fd0a337e2..2c1bb4d226 100644
--- a/modules/luci-base/luasrc/cbi.lua
+++ b/modules/luci-base/luasrc/cbi.lua
@@ -1811,6 +1811,7 @@ function Button.__init__(self, ...)
self.template = "cbi/button"
self.inputstyle = nil
self.rmempty = true
+ self.unsafeupload = false
end
@@ -1827,9 +1828,15 @@ function FileUpload.__init__(self, ...)
end
function FileUpload.formcreated(self, section)
- return AbstractValue.formcreated(self, section) or
- self.map:formvalue("cbi.rlf."..section.."."..self.option) or
- self.map:formvalue("cbi.rlf."..section.."."..self.option..".x")
+ if self.unsafeupload then
+ return AbstractValue.formcreated(self, section) or
+ self.map:formvalue("cbi.rlf."..section.."."..self.option) or
+ self.map:formvalue("cbi.rlf."..section.."."..self.option..".x") or
+ self.map:formvalue("cbid."..self.map.config.."."..section.."."..self.option..".textbox")
+ else
+ return AbstractValue.formcreated(self, section) or
+ self.map:formvalue("cbid."..self.map.config.."."..section.."."..self.option..".textbox")
+ end
end
function FileUpload.cfgvalue(self, section)
@@ -1840,27 +1847,50 @@ function FileUpload.cfgvalue(self, section)
return nil
end
+-- If we have a new value, use it
+-- otherwise use old value
+-- deletion should be managed by a separate button object
+-- unless self.unsafeupload is set in which case if the user
+-- choose to remove the old file we do so.
+-- Also, allow to specify (via textbox) a file already on router
function FileUpload.formvalue(self, section)
local val = AbstractValue.formvalue(self, section)
if val then
- if not self.map:formvalue("cbi.rlf."..section.."."..self.option) and
- not self.map:formvalue("cbi.rlf."..section.."."..self.option..".x")
- then
+ if self.unsafeupload then
+ if not self.map:formvalue("cbi.rlf."..section.."."..self.option) and
+ not self.map:formvalue("cbi.rlf."..section.."."..self.option..".x")
+ then
+ return val
+ end
+ fs.unlink(val)
+ self.value = nil
+ return nil
+ elseif val ~= "" then
return val
- end
- fs.unlink(val)
- self.value = nil
+ end
end
- return nil
+ val = luci.http.formvalue("cbid."..self.map.config.."."..section.."."..self.option..".textbox")
+ if val == "" then
+ val = nil
+ end
+ if not self.unsafeupload then
+ if not val then
+ val = self.map:formvalue("cbi.rlf."..section.."."..self.option)
+ end
+ end
+ return val
end
function FileUpload.remove(self, section)
- local val = AbstractValue.formvalue(self, section)
- if val and fs.access(val) then fs.unlink(val) end
- return AbstractValue.remove(self, section)
+ if self.unsafeupload then
+ local val = AbstractValue.formvalue(self, section)
+ if val and fs.access(val) then fs.unlink(val) end
+ return AbstractValue.remove(self, section)
+ else
+ return nil
+ end
end
-
FileBrowser = class(AbstractValue)
function FileBrowser.__init__(self, ...)
diff --git a/modules/luci-base/luasrc/cbi/datatypes.lua b/modules/luci-base/luasrc/cbi/datatypes.lua
index 4c003be2a1..626ad91c75 100644
--- a/modules/luci-base/luasrc/cbi/datatypes.lua
+++ b/modules/luci-base/luasrc/cbi/datatypes.lua
@@ -176,22 +176,41 @@ function hostname(val)
return false
end
-function host(val)
- return hostname(val) or ipaddr(val)
+function host(val, ipv4only)
+ return hostname(val) or ((ipv4only == 1) and ip4addr(val)) or ((not (ipv4only == 1)) and ipaddr(val))
end
function network(val)
return uciname(val) or host(val)
end
-function hostport(val)
+function hostport(val, ipv4only)
local h, p = val:match("^([^:]+):([^:]+)$")
- return not not (h and p and host(h) and port(p))
+ return not not (h and p and host(h, ipv4only) and port(p))
end
-function ipaddrport(val)
+function ip4addrport(val, bracket)
local h, p = val:match("^([^:]+):([^:]+)$")
- return not not (h and p and ipaddr(h) and port(p))
+ return (h and p and ip4addr(h) and port(p))
+end
+
+function ip4addrport(val)
+ local h, p = val:match("^([^:]+):([^:]+)$")
+ return (h and p and ip4addr(h) and port(p))
+end
+
+function ipaddrport(val, bracket)
+ local h, p = val:match("^([^%[%]:]+):([^:]+)$")
+ if (h and p and ip4addr(h) and port(p)) then
+ return true
+ elseif (bracket == 1) then
+ h, p = val:match("^%[(.+)%]:([^:]+)$")
+ if (h and p and ip6addr(h) and port(p)) then
+ return true
+ end
+ end
+ h, p = val:match("^([^%[%]]+):([^:]+)$")
+ return (h and p and ip6addr(h) and port(p))
end
function wpakey(val)
diff --git a/modules/luci-base/luasrc/view/cbi/upload.htm b/modules/luci-base/luasrc/view/cbi/upload.htm
index 7770934111..157f3b36fa 100644
--- a/modules/luci-base/luasrc/view/cbi/upload.htm
+++ b/modules/luci-base/luasrc/view/cbi/upload.htm
@@ -6,9 +6,19 @@
<%+cbi/valueheader%>
<% if s then %>
<%:Uploaded File%> (<%=t.byte_format(s.size)%>)
- <input type="hidden"<%= attr("value", v) .. attr("name", cbid) .. attr("id", cbid) %> />
- <input class="cbi-button cbi-input-image" type="image" value="<%:Replace entry%>" name="cbi.rlf.<%=section .. "." .. self.option%>" alt="<%:Replace entry%>" title="<%:Replace entry%>" src="<%=resource%>/cbi/reload.gif" />
- <% else %>
+ <% if self.unsafeupload then %>
+ <input type="hidden"<%= attr("value", v) .. attr("name", cbid) .. attr("id", cbid) %> />
+ <input class="cbi-button cbi-input-image" type="image" value="<%:Replace entry%>" name="cbi.rlf.<%=section .. "." .. self.option%>" alt="<%:Replace entry%>" title="<%:Replace entry%>" src="<%=resource%>/cbi/reload.gif" />
+ <% end %>
+ <% end %>
+
+ <% if not self.unsafeupload then %>
+ <input type="hidden"<%= attr("value", v) .. attr("name", "cbi.rlf." .. section .. "." .. self.option) .. attr("id", "cbi.rlf." .. section .. "." .. self.option) %> />
+ <% end %>
+
+ <% if (not s) or (s and not self.unsafeupload) then %>
<input class="cbi-input-file" type="file"<%= attr("name", cbid) .. attr("id", cbid) %> />
<% end %>
+ <input type="text" class="cbi-input-text" onchange="cbi_d_update(this.id)"<%=
+ attr("name", cbid .. ".textbox") .. attr("id", cbid .. ".textbox") .. attr("value", luci.cbi.AbstractValue.cfgvalue(self, section) or self.default) .. ifattr(self.size, "size") .. ifattr(self.placeholder, "placeholder") .. ifattr(self.readonly, "readonly") .. ifattr(self.maxlength, "maxlength") %> />
<%+cbi/valuefooter%>
diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/dhcp.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/dhcp.lua
index 4dc52ada06..572446feff 100644
--- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/dhcp.lua
+++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/dhcp.lua
@@ -135,7 +135,7 @@ rd = s:taboption("general", DynamicList, "rebind_domain",
translate("List of domains to allow RFC1918 responses for"))
rd:depends("rebind_protection", "1")
-rd.datatype = "host"
+rd.datatype = "host(1)"
rd.placeholder = "ihost.netflix.com"
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 b91c29b088..44528927e7 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
@@ -749,7 +749,7 @@ auth_server:depends({mode="ap", encryption="wpa2"})
auth_server:depends({mode="ap-wds", encryption="wpa"})
auth_server:depends({mode="ap-wds", encryption="wpa2"})
auth_server.rmempty = true
-auth_server.datatype = "host"
+auth_server.datatype = "host(0)"
auth_port = s:taboption("encryption", Value, "auth_port", translate("Radius-Authentication-Port"), translatef("Default %d", 1812))
auth_port:depends({mode="ap", encryption="wpa"})
@@ -773,7 +773,7 @@ acct_server:depends({mode="ap", encryption="wpa2"})
acct_server:depends({mode="ap-wds", encryption="wpa"})
acct_server:depends({mode="ap-wds", encryption="wpa2"})
acct_server.rmempty = true
-acct_server.datatype = "host"
+acct_server.datatype = "host(0)"
acct_port = s:taboption("encryption", Value, "acct_port", translate("Radius-Accounting-Port"), translatef("Default %d", 1813))
acct_port:depends({mode="ap", encryption="wpa"})
diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/system.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/system.lua
index 94ba8053ad..2874b5607e 100644
--- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/system.lua
+++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/system.lua
@@ -204,7 +204,7 @@ if has_ntpd then
o = s:option(DynamicList, "server", translate("NTP server candidates"))
- o.datatype = "host"
+ o.datatype = "host(0)"
o:depends("enable", "1")
-- retain server list even if disabled