-- -- (C) 2014-26 - ntop.org -- -- This require is okay, it just adds up a couple of utilities require "string_utils" require "check_redis_prefs" -- GENERIC UTILS -- split function split(s, delimiter) result = {}; if(s ~= nil) then if delimiter == nil then -- No delimiter, split all characters for match in s:gmatch"." do result[#result + 1] = match; end else -- Split by delimiter for match in (s..delimiter):gmatch("(.-)"..delimiter) do result[#result + 1] = match; end end end return result; end -- strsplit function strsplit(s, delimiter) result = {}; for match in (s..delimiter):gmatch("(.-)"..delimiter) do if(match ~= "") then result[match] = true end end return result; end -- isempty function isempty(array) local count = 0 for _,__ in pairs(array) do count = count + 1 end return (count == 0) end -- isin function isin(s, array) if (s == nil or s == "" or array == nil or isempty(array)) then return false end for _, v in pairs(array) do if (s == v) then return true end end return false end -- hasKey function hasKey(key, theTable) if((theTable == nil) or (theTable[key] == nil)) then return(false) else return(true) end end -- ############################################### function get_domain_from_url(url) -- Strips the prefix (either http:// or https://) and a possible port -- Extract the domain, e.g., -- http://user:password@www.example.com/p1/p2 becomes www.example.com -- http://www.example.com:3000/p1/p2 becomes www.example.com -- See if domain has user and password encoded, i.e., -- http://user:password@www.example.com becomes www.example.com local domain = url:match('^%w+://[^:]+:[^@]+@([^/:]+)') if not domain then -- Domain has no user and password encoded, i.e., -- http://www.example.com:3000/p1/p2 domain = url:match('^%w+://([^/:]+)') end return domain end -- ############################################### -- ############################################### -- Escapes a string so it can be safely embedded inside a JavaScript string -- literal (single OR double quoted). Use when printing i18n() output into an -- inline