mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 15:39:33 +00:00
Code cleanup
This commit is contained in:
parent
24f3aab201
commit
33f57c2d10
1 changed files with 15 additions and 51 deletions
|
|
@ -164,7 +164,6 @@ local function format_port_list_to_string(ports)
|
|||
end
|
||||
|
||||
return scan_ports
|
||||
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
|
@ -256,7 +255,6 @@ local function split_port_list(data, is_tcp)
|
|||
end
|
||||
|
||||
return {}
|
||||
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
|
@ -289,7 +287,6 @@ local function analyze_ports_diff(ports_difference)
|
|||
rsp["triggered"] = ports_difference.trigger
|
||||
|
||||
return rsp
|
||||
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
|
@ -316,7 +313,6 @@ local function check_differences(host, host_name, scan_type, old_data, new_data)
|
|||
local cve_solved = {}
|
||||
local new_cve = {}
|
||||
|
||||
|
||||
-- Checking the solved vulnerabilities
|
||||
for _, cve in ipairs(old_data.cve or {}) do
|
||||
-- the old cves have the score
|
||||
|
|
@ -397,13 +393,10 @@ local function check_differences(host, host_name, scan_type, old_data, new_data)
|
|||
|
||||
end
|
||||
|
||||
|
||||
|
||||
if num_cve_solved > 0 then
|
||||
rsp["num_cve_solved"] = num_cve_solved
|
||||
rsp["cve_solved"] = cve_solved
|
||||
rsp["measurement"] = "cve_changes_detected"
|
||||
|
||||
end
|
||||
|
||||
if num_new_cve_issues > 0 then
|
||||
|
|
@ -442,7 +435,7 @@ function vs_utils.cleanup_port(is_tcp, line)
|
|||
|
||||
end
|
||||
|
||||
-- remove the first/last few lines that contain nmap information that change at each scan
|
||||
-- Remove the first/last few lines that contain nmap information that change at each scan
|
||||
function vs_utils.cleanup_nmap_result(scan_result, scan_type)
|
||||
if(scan_result ~= nil) then
|
||||
scan_result = scan_result:gsub("|", "")
|
||||
|
|
@ -509,8 +502,8 @@ function vs_utils.cleanup_nmap_result(scan_result, scan_type)
|
|||
end
|
||||
|
||||
-- **********************************************************
|
||||
-- remove the first/last few lines that contain nmap information that change at each scan
|
||||
|
||||
-- Remove the first/last few lines that contain nmap information that change at each scan
|
||||
function vs_utils.cleanup_nmap_vulners_result(scan_result, scan_type)
|
||||
scan_result = scan_result:gsub("|_", "")
|
||||
scan_result = scan_result:gsub("|", "")
|
||||
|
|
@ -556,8 +549,8 @@ end
|
|||
|
||||
-- Function to save host configuration
|
||||
local function isAlreadyPresent(item)
|
||||
|
||||
local hosts_details = vs_utils.retrieve_hosts_to_scan()
|
||||
|
||||
for _,value in ipairs(hosts_details) do
|
||||
if (item.host == value.host and item.scan_type == value.scan_type ) then
|
||||
return true
|
||||
|
|
@ -640,7 +633,6 @@ end
|
|||
|
||||
-- Function to select correctly redis keys on periodic or scan all
|
||||
local function get_counter_periodic_all_scan_keys(is_periodic)
|
||||
|
||||
if (is_periodic) then
|
||||
return host_periodic_scan_info --host_periodic_scan_cve_num_key,host_periodic_scan_udp_ports_key,host_periodic_scan_tcp_ports_key
|
||||
else
|
||||
|
|
@ -705,7 +697,6 @@ local function update_periodicity_or_all_scan_info(is_periodic, new_item)
|
|||
end
|
||||
|
||||
ntop.setCache(redis_info_key, json.encode(info_json))
|
||||
|
||||
end
|
||||
|
||||
-- **********************************************************
|
||||
|
|
@ -733,7 +724,6 @@ function vs_utils.restore_host_to_scan()
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- **********************************************************
|
||||
|
|
@ -756,6 +746,7 @@ function vs_utils.restore_config_backup(vs_backup)
|
|||
end
|
||||
|
||||
-- *********************************************************
|
||||
|
||||
-- Function to retrieve hosts keys for backups
|
||||
function vs_utils.retrieve_hosts_backup()
|
||||
local hash_keys = ntop.getHashKeysCache(prefs_host_values_key)
|
||||
|
|
@ -771,12 +762,11 @@ function vs_utils.retrieve_hosts_backup()
|
|||
end
|
||||
|
||||
return rsp
|
||||
|
||||
end
|
||||
|
||||
-- **********************************************************
|
||||
--Function to save
|
||||
|
||||
--Function to save
|
||||
function vs_utils.add_host_pref(scan_type, host, ports, scan_frequency)
|
||||
|
||||
local host_hash_key = vs_utils.get_host_hash_key(host, scan_type)
|
||||
|
|
@ -795,14 +785,13 @@ function vs_utils.add_host_pref(scan_type, host, ports, scan_frequency)
|
|||
if (debug_me) then
|
||||
tprint("SAVING HOST: "..new_item.host)
|
||||
end
|
||||
|
||||
--saved_hosts[#saved_hosts+1] = new_item
|
||||
ntop.setHashCache(prefs_host_values_key, host_hash_key, json.encode(new_item))
|
||||
|
||||
return result
|
||||
|
||||
end
|
||||
|
||||
|
||||
function vs_utils.edit_host_pref(scan_type, host, ports, scan_frequency)
|
||||
local host_hash_key = vs_utils.get_host_hash_key(host, scan_type)
|
||||
local old_item_string = ntop.getHashCache(prefs_host_values_key,host_hash_key)
|
||||
|
|
@ -816,6 +805,7 @@ function vs_utils.edit_host_pref(scan_type, host, ports, scan_frequency)
|
|||
end
|
||||
return 2 -- not found
|
||||
end
|
||||
|
||||
-- **********************************************************
|
||||
|
||||
-- Function to update host scan values
|
||||
|
|
@ -888,7 +878,6 @@ function vs_utils.save_host_to_scan(scan_type, host, scan_result, last_scan_time
|
|||
local cve_formatted, max_score_cve = get_cve_with_score(cve)
|
||||
|
||||
local new_item = {
|
||||
|
||||
num_open_ports = num_open_ports,
|
||||
num_vulnerabilities_found = num_vulnerabilities_found,
|
||||
cve = cve_formatted,
|
||||
|
|
@ -904,7 +893,6 @@ function vs_utils.save_host_to_scan(scan_type, host, scan_result, last_scan_time
|
|||
if udp_ports ~= nil then
|
||||
new_item.udp_ports = udp_ports.num_ports
|
||||
new_item.udp_ports_list = udp_ports.ports
|
||||
|
||||
end
|
||||
|
||||
if (udp_ports == nil and tcp_ports == nil) then
|
||||
|
|
@ -950,20 +938,17 @@ function vs_utils.save_host_to_scan(scan_type, host, scan_result, last_scan_time
|
|||
handle:close()
|
||||
end
|
||||
|
||||
|
||||
|
||||
local result = 1 -- success
|
||||
if (debug_me) then
|
||||
tprint("UPDATING HOST: "..host)
|
||||
end
|
||||
-- edit case
|
||||
ntop.setHashCache(host_to_scan_key, host_hash_key, json.encode(new_item))
|
||||
|
||||
|
||||
|
||||
if (debug_me) then
|
||||
tprint("UPDATING HOST: "..host)
|
||||
end
|
||||
|
||||
-- edit case
|
||||
ntop.setHashCache(host_to_scan_key, host_hash_key, json.encode(new_item))
|
||||
|
||||
local counts = vs_utils.update_ts_counters()
|
||||
|
||||
--vs_utils.notify_end_periodicity()
|
||||
if (new_item.is_periodicity) then
|
||||
update_periodicity_or_all_scan_info(true, new_item)
|
||||
end
|
||||
|
|
@ -1054,7 +1039,6 @@ local function format_num_for_email(num, case)
|
|||
return(i18n("hosts_stats.page_scan_hosts.email.num_scanned_hosts", {num = formatted_num}))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- **********************************************************
|
||||
|
|
@ -1152,13 +1136,10 @@ end
|
|||
-- **********************************************************
|
||||
|
||||
-- Function to retrieve dates of scan all or periodic scan
|
||||
|
||||
function vs_utils.get_scan_all_dates()
|
||||
return ntop.getCache(hosts_scan_last_report_dates)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- **********************************************************
|
||||
|
||||
-- Function to verify if periodic scan is ended
|
||||
|
|
@ -1196,14 +1177,12 @@ function vs_utils.is_periodic_scan_over()
|
|||
end
|
||||
|
||||
return false
|
||||
|
||||
end
|
||||
|
||||
-- **********************************************************
|
||||
|
||||
-- Function to verify if scan all is ended
|
||||
function vs_utils.is_scan_all_over()
|
||||
|
||||
local scan_all_in_progress = ntop.getCache(host_to_scan_all_key) == "1"
|
||||
|
||||
if (scan_all_in_progress) then
|
||||
|
|
@ -1218,7 +1197,6 @@ function vs_utils.is_scan_all_over()
|
|||
|
||||
ntop.setCache(host_to_scan_all_key, "0")
|
||||
|
||||
|
||||
for _,item in ipairs(hosts_details) do
|
||||
local host_hash_key = vs_utils.get_host_hash_key(item.host, item.scan_type)
|
||||
local host_hash_value_string = ntop.getHashCache(host_to_scan_key, host_hash_key)
|
||||
|
|
@ -1236,7 +1214,6 @@ function vs_utils.is_scan_all_over()
|
|||
end
|
||||
|
||||
return false
|
||||
|
||||
end
|
||||
|
||||
-- **********************************************************
|
||||
|
|
@ -1273,8 +1250,6 @@ function vs_utils.retrieve_hosts_to_scan()
|
|||
local hash_prefs_string = ntop.getHashCache(prefs_host_values_key,k)
|
||||
local hash_value = json.decode(hash_prefs_string)
|
||||
|
||||
|
||||
|
||||
if (not isEmptyString(hash_value_string)) then
|
||||
-- hash value found
|
||||
|
||||
|
|
@ -1293,8 +1268,6 @@ function vs_utils.retrieve_hosts_to_scan()
|
|||
end
|
||||
|
||||
rsp[#rsp+1] = hash_value
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1305,10 +1278,10 @@ end
|
|||
|
||||
-- Function to retrieve hosts list to scan just for status_info
|
||||
function vs_utils.check_in_progress_status()
|
||||
|
||||
local hash_keys = ntop.getHashKeysCache(host_to_scan_key)
|
||||
local total_in_progress = 0
|
||||
local total = 0
|
||||
|
||||
if hash_keys then
|
||||
for k in pairs(hash_keys) do
|
||||
local hash_value_string = ntop.getHashCache(host_to_scan_key, k)
|
||||
|
|
@ -1392,7 +1365,6 @@ end
|
|||
|
||||
-- Function to delete host to scan by id
|
||||
function vs_utils.delete_host_to_scan_by_id(id)
|
||||
|
||||
local hosts_details = vs_utils.retrieve_hosts_to_scan()
|
||||
local host_to_delete = {}
|
||||
local id_number = tonumber(id)
|
||||
|
|
@ -1544,7 +1516,6 @@ end
|
|||
|
||||
-- Function to update single host status
|
||||
function vs_utils.set_status_scan(scan_type, host, ports, id, is_periodicity, is_all, status)
|
||||
|
||||
local host_hash_key = vs_utils.get_host_hash_key(host, scan_type)
|
||||
local host_hash_value_string = ntop.getHashCache(host_to_scan_key, host_hash_key)
|
||||
local host_hash_value
|
||||
|
|
@ -1566,8 +1537,6 @@ function vs_utils.set_status_scan(scan_type, host, ports, id, is_periodicity, is
|
|||
|
||||
ntop.setHashCache(host_to_scan_key, host_hash_key, json.encode(host_hash_value))
|
||||
|
||||
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
|
@ -1651,7 +1620,6 @@ function vs_utils.schedule_periodic_scan(periodicity)
|
|||
return true
|
||||
end
|
||||
|
||||
|
||||
-- **********************************************************
|
||||
|
||||
-- Process a single host scan request that has been queued
|
||||
|
|
@ -1990,9 +1958,7 @@ end
|
|||
-- **********************************************************
|
||||
|
||||
-- Migrate old configurations
|
||||
|
||||
function vs_utils.migrate_keys()
|
||||
|
||||
local old_hash_key = "ntopng.prefs.host_to_scan"
|
||||
local old_hosts = ntop.getHashKeysCache(old_hash_key) or {}
|
||||
|
||||
|
|
@ -2009,9 +1975,7 @@ function vs_utils.migrate_keys()
|
|||
}
|
||||
|
||||
ntop.setHashCache(prefs_host_values_key, key,json.encode(new_hash_value))
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
ntop.delCache(old_hash_key)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue