summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base
diff options
context:
space:
mode:
Diffstat (limited to 'modules/luci-base')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/cbi.js22
-rw-r--r--modules/luci-base/luasrc/cbi/datatypes.lua10
-rw-r--r--modules/luci-base/luasrc/util.lua22
-rw-r--r--modules/luci-base/luasrc/view/cbi/value.htm2
4 files changed, 55 insertions, 1 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js
index 02c54ad3e..8a3cb6fca 100644
--- a/modules/luci-base/htdocs/luci-static/resources/cbi.js
+++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js
@@ -161,6 +161,28 @@ var cbi_validators = {
cbi_validators.host.apply(this);
},
+ 'hostport': function()
+ {
+ var hp = this.split(/:/);
+
+ if (hp.length == 2)
+ return (cbi_validators.host.apply(hp[0]) &&
+ cbi_validators.port.apply(hp[1]));
+
+ return false;
+ },
+
+ 'ipaddrport': function()
+ {
+ var hp = this.split(/:/);
+
+ if (hp.length == 2)
+ return (cbi_validators.ipaddr.apply(hp[0]) &&
+ cbi_validators.port.apply(hp[1]));
+
+ return false;
+ },
+
'wpakey': function()
{
var v = this;
diff --git a/modules/luci-base/luasrc/cbi/datatypes.lua b/modules/luci-base/luasrc/cbi/datatypes.lua
index ebd7e594f..52f90afee 100644
--- a/modules/luci-base/luasrc/cbi/datatypes.lua
+++ b/modules/luci-base/luasrc/cbi/datatypes.lua
@@ -184,6 +184,16 @@ function network(val)
return uciname(val) or host(val)
end
+function hostport(val)
+ local h, p = val:match("^([^:]+):([^:]+)$")
+ return not not (h and p and host(h) and port(p))
+end
+
+function ipaddrport(val)
+ local h, p = val:match("^([^:]+):([^:]+)$")
+ return not not (h and p and ipaddr(h) and port(p))
+end
+
function wpakey(val)
if #val == 64 then
return (val:match("^[a-fA-F0-9]+$") ~= nil)
diff --git a/modules/luci-base/luasrc/util.lua b/modules/luci-base/luasrc/util.lua
index 787bc66f9..5bf0beb6c 100644
--- a/modules/luci-base/luasrc/util.lua
+++ b/modules/luci-base/luasrc/util.lua
@@ -151,6 +151,28 @@ function striptags(value)
return value and tparser.striptags(tostring(value))
end
+-- for bash, ash and similar shells single-quoted strings are taken
+-- literally except for single quotes (which terminate the string)
+-- (and the exception noted below for dash (-) at the start of a
+-- command line parameter).
+function shellsqescape(value)
+ local res
+ res, _ = string.gsub(res, "'", "'\\''")
+ return res
+end
+
+-- bash, ash and other similar shells interpret a dash (-) at the start
+-- of a command-line parameters as an option indicator regardless of
+-- whether it is inside a single-quoted string. It must be backlash
+-- escaped to resolve this. This requires in some funky special-case
+-- handling. It may actually be a property of the getopt function
+-- rather than the shell proper.
+function shellstartsqescape(value)
+ res, _ = string.gsub(value, "^\-", "\\-")
+ res, _ = string.gsub(res, "^-", "\-")
+ return shellsqescape(value)
+end
+
-- containing the resulting substrings. The optional max parameter specifies
-- the number of bytes to process, regardless of the actual length of the given
-- string. The optional last parameter, regex, specifies whether the separator
diff --git a/modules/luci-base/luasrc/view/cbi/value.htm b/modules/luci-base/luasrc/view/cbi/value.htm
index 8a08e08f2..c43dab5f4 100644
--- a/modules/luci-base/luasrc/view/cbi/value.htm
+++ b/modules/luci-base/luasrc/view/cbi/value.htm
@@ -29,7 +29,7 @@
<%- end -%>');
<%- end %>
<% if self.datatype then -%>
- cbi_validate_field('<%=cbid%>', <%=tostring((self.optional or self.rmempty) == true)%>, '<%=self.datatype:gsub("'", "\\'")%>');
+ cbi_validate_field('<%=cbid%>', <%=tostring((self.optional or self.rmempty) == true)%>, '<%=self.datatype:gsub("\\", "\\\\"):gsub("'", "\\'")%>');
<%- end %>
//]]></script>
<% end -%>