diff options
-rwxr-xr-x | lib/validator.lua | 31 | ||||
-rw-r--r-- | lib/viewfunctions.lua | 3 |
2 files changed, 34 insertions, 0 deletions
diff --git a/lib/validator.lua b/lib/validator.lua index d57ca5f..afea72c 100755 --- a/lib/validator.lua +++ b/lib/validator.lua @@ -108,6 +108,37 @@ function is_ipv4(ipv4) return true, validator.msg.err.Success[lang.Current] end +-- +-- This function validates a partial ipv4 address. +-- On success it returns 1 otherwise a negative value +-- +function is_partial_ipv4(ipv4) + local retval = false; + local nums = {}; + + -- Check to see if any invalid characters + if not ipv4 or not ipv4:match("^[%d%.]+$") then + return false, validator.msg.err.InvalidFormat[lang.Current] + end + + -- NC: Split the string into an array. separate with '.' (dots) + -- %d+ one or more digits + for num in ipv4:gmatch("%d+") do + nums[#nums+1] = num + -- too big? + if tonumber(num) > 255 then + return false, validator.msg.err.InvalidFormat[lang.Current] + end + end + + -- too many numbers + if #nums > 4 then + return false, validator.msg.err.InvalidFormat[lang.Current] + end + + return true, validator.msg.err.Success[lang.Current] +end + function is_mac(mac) local tmpmac = string.upper(mac) diff --git a/lib/viewfunctions.lua b/lib/viewfunctions.lua index a8ad444..e927e2b 100644 --- a/lib/viewfunctions.lua +++ b/lib/viewfunctions.lua @@ -134,6 +134,9 @@ function displayformitem(myitem, name, viewtype) if (myitem.value == true) then myitem.checked = "" end myitem.value = "true" io.write(html.form.checkbox(myitem) .. "\n") + elseif myitem.type == "list" then + myitem.value = table.concat(myitem.value, "\n") + io.write(html.form.longtext(myitem) .. "\n") else io.write((html.form[myitem.type](myitem) or "") .. "\n") end |