mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-28 23:19:33 +00:00
Fixes circular dependency and lightened some modules
This commit is contained in:
parent
de03d66a73
commit
ef27b0b058
14 changed files with 1929 additions and 2045 deletions
|
|
@ -2,16 +2,9 @@
|
|||
-- (C) 2014-24 - ntop.org
|
||||
--
|
||||
|
||||
if(pragma_once_lua_utils_generic == true) then
|
||||
-- io.write(debug.traceback().."\n")
|
||||
-- avoid multiple inclusions
|
||||
return
|
||||
end
|
||||
|
||||
pragma_once_lua_utils_generic = true
|
||||
|
||||
local clock_start = os.clock()
|
||||
|
||||
-- This require is okay, it just adds up a couple of utilities
|
||||
require "string_utils"
|
||||
require "check_redis_prefs"
|
||||
-- GENERIC UTILS
|
||||
|
||||
-- split
|
||||
|
|
@ -33,16 +26,6 @@ function split(s, delimiter)
|
|||
return result;
|
||||
end
|
||||
|
||||
-- startswith
|
||||
function startswith(s, char)
|
||||
return string.sub(s, 1, string.len(s)) == char
|
||||
end
|
||||
|
||||
-- endswith
|
||||
function endswith(s, char)
|
||||
return string.sub(s, -#char) == char
|
||||
end
|
||||
|
||||
-- strsplit
|
||||
function strsplit(s, delimiter)
|
||||
result = {};
|
||||
|
|
@ -81,21 +64,6 @@ end
|
|||
|
||||
-- ###############################################
|
||||
|
||||
-- removes trailing/leading spaces
|
||||
function trimString(s)
|
||||
return (s:gsub("^%s*(.-)%s*$", "%1"))
|
||||
end
|
||||
|
||||
-- ###############################################
|
||||
|
||||
-- removes all spaces
|
||||
function trimSpace(what)
|
||||
if(what == nil) then return("") end
|
||||
return(string.gsub(string.gsub(what, "%s+", ""), "+%s", ""))
|
||||
end
|
||||
|
||||
-- ###############################################
|
||||
|
||||
-- TODO: improve this function
|
||||
function jsonencode(what)
|
||||
what = string.gsub(what, '"', "'")
|
||||
|
|
@ -389,50 +357,6 @@ end
|
|||
|
||||
-- ##############################################
|
||||
|
||||
-- Note: Regexs are applied by default. Pass plain=true to disable them.
|
||||
function string.contains(str, start, is_plain)
|
||||
if type(str) ~= 'string' or type(start) ~= 'string' or isEmptyString(str) or isEmptyString(start) then
|
||||
return false
|
||||
end
|
||||
|
||||
local i, _ = string.find(str, start, 1, is_plain)
|
||||
|
||||
return(i ~= nil)
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function string.containsIgnoreCase(str, start, is_plain)
|
||||
return string.contains(string.lower(str), string.lower(start), is_plain)
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function shortenString(name, max_len)
|
||||
local ellipsis = "\u{2026}" -- The unicode ellipsis (takes less space than three separate dots)
|
||||
if(name == nil) then return("") end
|
||||
|
||||
if max_len == nil then
|
||||
max_len = ntop.getPref("ntopng.prefs.max_ui_strlen")
|
||||
max_len = tonumber(max_len)
|
||||
if(max_len == nil) then max_len = 24 end
|
||||
end
|
||||
|
||||
-- Error, max_len is not a number, print an error and return the name
|
||||
if not tonumber(max_len) then
|
||||
traceError(TRACE_DEBUG, TRACE_CONSOLE, "Length parameter is not a number.")
|
||||
tprint(debug.traceback())
|
||||
return name
|
||||
end
|
||||
if(string.len(name) < max_len + 1 --[[ The space taken by the ellipsis --]]) then
|
||||
return(name)
|
||||
else
|
||||
return(string.sub(name, 1, max_len)..ellipsis)
|
||||
end
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function convertDate(vardate)
|
||||
local m,d,y,h,i,s = string.match(vardate, '(%d+)/(%d+)/(%d+) (%d+):(%d+):(%d+)')
|
||||
local key = ntop.getPref('ntopng.user.' .. _SESSION["user"] .. '.date_format')
|
||||
|
|
@ -529,15 +453,6 @@ function printInterfaceIndex(idx)
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- NOTE: global nindex support may be enabled but some disable on some interfaces
|
||||
function interfaceHasClickHouseSupport()
|
||||
require "check_redis_prefs"
|
||||
return(hasClickHouseSupport() and ntop.getPrefs()["is_dump_flows_to_clickhouse_enabled"])
|
||||
end
|
||||
|
||||
-- ###########################################
|
||||
|
||||
function swapKeysValues(tbl)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue