X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fweb%2Fluasrc%2Fcbi%2Fdatatypes.lua;h=65a8eedeb13d75db545b22c56e292b6c05c77bb8;hp=6640db639251769de94b9214ed0b17f3b1ea3afc;hb=375a476d27afae5c978b48a555fe32c94e2cf854;hpb=354aeb44f67d716d44fa7c03617e48265a28dd3f diff --git a/libs/web/luasrc/cbi/datatypes.lua b/libs/web/luasrc/cbi/datatypes.lua index 6640db639..65a8eedeb 100644 --- a/libs/web/luasrc/cbi/datatypes.lua +++ b/libs/web/luasrc/cbi/datatypes.lua @@ -141,7 +141,11 @@ function macaddr(val) end function hostname(val) - if val and (#val < 254) and val.match(val, "^[a-zA-Z0-9][a-zA-Z0-9%-%.]*[a-zA-Z0-9]$") then + if val and (#val < 254) and ( + val:match("^[a-zA-Z]+$") or + (val:match("^[a-zA-Z0-9][a-zA-Z0-9%-%.]*[a-zA-Z0-9]$") and + val:match("[^0-9%.]")) + ) then return true end return false @@ -151,6 +155,10 @@ function host(val) return hostname(val) or ipaddr(val) end +function network(val) + return uciname(val) or host(val) +end + function wpakey(val) if #val == 64 then return (val:match("^[a-fA-F0-9]+$") ~= nil) @@ -231,7 +239,7 @@ function neg_network_ip4addr(val) if type(v) == "string" then v = v:gsub("^%s*!", "") return (uciname(v) or ip4addr(v)) - end + end end function range(val, min, max) @@ -267,3 +275,25 @@ function max(val, max) return false end + +function neg(val, what) + if what and type(_M[what]) == "function" then + return _M[what](val:gsub("^%s*!%s*", "")) + end + + return false +end + +function list(val, what, ...) + if type(val) == "string" and what and type(_M[what]) == "function" then + for val in val:gmatch("%S+") do + if not _M[what](val, ...) then + return false + end + end + + return true + end + + return false +end