diff options
author | Mike Mason <ms13sp@gmail.com> | 2007-12-05 21:54:10 +0000 |
---|---|---|
committer | Mike Mason <ms13sp@gmail.com> | 2007-12-05 21:54:10 +0000 |
commit | 15f95a3134ed82b8e65b23fad5b71ef088061970 (patch) | |
tree | 20747171c8e87e6946b7c659023b2bfc4bbdae7d | |
parent | a2fc97fd31df9a05c66cb3dbf4246727fff97f88 (diff) | |
download | acf-core-15f95a3134ed82b8e65b23fad5b71ef088061970.tar.bz2 acf-core-15f95a3134ed82b8e65b23fad5b71ef088061970.tar.xz |
Made validator functions useful after load, fixed a bug in format, changed README to reflect changes
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@413 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | lib/README | 1 | ||||
-rw-r--r-- | lib/format.lua | 1 | ||||
-rw-r--r-- | lib/fs.lua | 2 | ||||
-rwxr-xr-x | lib/validator.lua | 35 |
4 files changed, 33 insertions, 6 deletions
@@ -9,6 +9,7 @@ fs.lua - File and filesystem library pidof.lua - Process libraries not provided by LPOSIX format.lua - Library to help reformat string,tables,files or any input. Good place for split and join +authenticator-plaintext.lua - Used to parse through the username:password file and for permission help validator.lua - Validate web input for ACF. html.lua - Helps with form building in ACF menubuilder.lua -Helps create the menus on left window in ACF diff --git a/lib/format.lua b/lib/format.lua index dff5019..9c21395 100644 --- a/lib/format.lua +++ b/lib/format.lua @@ -31,6 +31,7 @@ end return lines end +--string format function to cap the beginging of each word. function cap_begin_word ( a ) --first need to do the first word local data = string.gsub(a, "^%l", string.upper) @@ -56,7 +56,7 @@ end function write_file ( path, str ) local file = io.open(path, "w") - --append a newline char + --append a newline char to EOF str = str .. "\n" if ( file ) then file:write(str) diff --git a/lib/validator.lua b/lib/validator.lua index 951d716..6f7fb65 100755 --- a/lib/validator.lua +++ b/lib/validator.lua @@ -1,6 +1,7 @@ -------------------------------------------------- -- Validation Functions for Alpine Linux' Webconf -------------------------------------------------- +module (..., package.seeall) -- setup the 'language' table lang = {} @@ -34,11 +35,35 @@ validator.msg.err.OutOfRange = {} validator.msg.err.OutOfRange[lang.English] = "Value out of range!" validator.msg.err.OutOfRange[lang.German] = "Wert ausserhalb des Bereichs!" +function is_string ( str ) + if type(str) == "string" then + return true, str, "Is a string." + else + return false, str, "Is not a string." + end +end + +function is_boolean ( str ) + if type(str) == "boolean" then + return true, str, "Is a boolean." + else + return false, str, "Is not a boolean." + end +end + +function is_number ( str ) + if type(str) == "number" then + return true, str, "Is a number." + else + return false, str, "Is not a number." + end +end + -- -- This function validates an ipv4 address. -- On success it returns 1 otherwise a negative value -- -function validator.is_ipv4(ipv4) +function is_ipv4(ipv4) local retval = false; local nums = { "", "", "", ""}; local iplen = string.len(ipv4); @@ -77,7 +102,7 @@ function validator.is_ipv4(ipv4) return true, validator.msg.err.Success[lang.Current] end -function validator.is_mac(mac) +function is_mac(mac) local tmpmac = string.upper(mac) @@ -125,7 +150,7 @@ end -- consists of number-chars between 0..9 only -- and eventually a leading '-' -- -function validator.is_integer(numstr) +function is_integer(numstr) -- ^ beginning of string -- -? one or zero ot the char '-' -- %d+ one or more digits @@ -139,7 +164,7 @@ end -- consists of number-chars between 0..9 only -- and if it is within a given range. -- -function validator.is_integer_in_range(numstr, min, max) +function is_integer_in_range(numstr, min, max) return validator.is_integer(numstr) and numstr >= min and numstr <= max @@ -150,7 +175,7 @@ end -- This function checks if the given number is an integer -- and wheter it is between 1 .. 65535 -- -function validator.is_port(numstr) +function is_port(numstr) return validator.is_integer_in_range(numstr, 1, 65535) end |