mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 15:39:33 +00:00
Fix various bugs and add ports in the host scan modal. (#7698)
This commit is contained in:
parent
a7c49205ef
commit
a93201e42f
20 changed files with 540 additions and 109 deletions
|
|
@ -87,7 +87,7 @@ end
|
|||
-- **********************************************************
|
||||
|
||||
-- Function to save host configuration
|
||||
function vs_utils.save_host_to_scan(scan_type, host, scan_result, last_scan_time, last_duration, is_ok_last_scan)
|
||||
function vs_utils.save_host_to_scan(scan_type, host, scan_result, last_scan_time, last_duration, is_ok_last_scan, ports)
|
||||
local saved_hosts_string = ntop.getCache(host_to_scan_key)
|
||||
local saved_hosts = {}
|
||||
|
||||
|
|
@ -109,11 +109,15 @@ function vs_utils.save_host_to_scan(scan_type, host, scan_result, last_scan_time
|
|||
local new_item = {
|
||||
host=host,
|
||||
scan_type=scan_type,
|
||||
ports=ports
|
||||
}
|
||||
|
||||
if last_scan_time then
|
||||
if last_scan_time or last_duration then
|
||||
local time_formatted = format_utils.formatPastEpochShort(last_scan_time)
|
||||
|
||||
if last_duration <= 0 then
|
||||
last_duration = 1
|
||||
end
|
||||
last_duration = secondsToTime(last_duration)
|
||||
new_item.last_scan = {
|
||||
epoch = last_scan_time,
|
||||
time = time_formatted,
|
||||
|
|
@ -170,26 +174,32 @@ end
|
|||
-- **********************************************************
|
||||
|
||||
-- Function to delete host to scan
|
||||
function vs_utils.delete_host_to_scan(host, scan_type)
|
||||
function vs_utils.delete_host_to_scan(host, scan_type, all)
|
||||
local saved_hosts_string = ntop.getCache(host_to_scan_key)
|
||||
local saved_hosts = {}
|
||||
if not isEmptyString(saved_hosts_string) then
|
||||
saved_hosts = json.decode(saved_hosts_string)
|
||||
local index_to_remove = 0
|
||||
for index,value in ipairs(saved_hosts) do
|
||||
if value.host == host and value.scan_type == scan_type then
|
||||
index_to_remove = index
|
||||
end
|
||||
end
|
||||
|
||||
if index_to_remove ~= 0 then
|
||||
table.remove(saved_hosts, index_to_remove)
|
||||
|
||||
if all then
|
||||
|
||||
ntop.delCache(host_to_scan_key)
|
||||
else
|
||||
if not isEmptyString(saved_hosts_string) then
|
||||
saved_hosts = json.decode(saved_hosts_string)
|
||||
local index_to_remove = 0
|
||||
for index,value in ipairs(saved_hosts) do
|
||||
if value.host == host and value.scan_type == scan_type then
|
||||
index_to_remove = index
|
||||
end
|
||||
end
|
||||
|
||||
if index_to_remove ~= 0 then
|
||||
table.remove(saved_hosts, index_to_remove)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
ntop.setCache(host_to_scan_key, json.encode(saved_hosts))
|
||||
end
|
||||
|
||||
ntop.setCache(host_to_scan_key, json.encode(saved_hosts))
|
||||
|
||||
return 1
|
||||
end
|
||||
|
||||
|
|
@ -238,7 +248,40 @@ function vs_utils.scan_host(scan_type, host, ports)
|
|||
local scan_module = vs_utils.load_module(scan_type)
|
||||
local result,duration,scan_result = scan_module:scan_host(host, ports)
|
||||
|
||||
vs_utils.save_host_to_scan(scan_type, host, result, now, duration, scan_result)
|
||||
vs_utils.save_host_to_scan(scan_type, host, result, now, duration, scan_result, ports)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
-- **********************************************************
|
||||
|
||||
-- Function to update single host status
|
||||
function vs_utils.set_status_scan(scan_type, host, ports)
|
||||
|
||||
local saved_hosts_string = ntop.getCache(host_to_scan_key)
|
||||
local saved_hosts = {}
|
||||
|
||||
if not isEmptyString(saved_hosts_string) then
|
||||
saved_hosts = json.decode(saved_hosts_string)
|
||||
local index_to_update = 0
|
||||
local value_to_update = {}
|
||||
|
||||
for index,value in ipairs(saved_hosts) do
|
||||
if value.host == host and value.scan_type == scan_type then
|
||||
index_to_update = index
|
||||
value.is_ok_last_scan = 4
|
||||
value_to_update = value
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
if index_to_remove ~= 0 then
|
||||
table.remove(saved_hosts, index_to_update)
|
||||
table.insert(saved_hosts, index_to_update, value_to_update)
|
||||
end
|
||||
end
|
||||
|
||||
ntop.setCache(host_to_scan_key, json.encode(saved_hosts))
|
||||
|
||||
return true
|
||||
end
|
||||
|
|
@ -247,7 +290,8 @@ end
|
|||
|
||||
function vs_utils.schedule_host_scan(scan_type, host, ports)
|
||||
local scan = { scan_type = scan_type, host = host, ports = ports }
|
||||
|
||||
vs_utils.set_status_scan(scan_type, host, ports)
|
||||
|
||||
ntop.rpushCache(host_scan_queue_key, json.encode(scan))
|
||||
|
||||
return true
|
||||
|
|
@ -313,4 +357,19 @@ end
|
|||
|
||||
-- **********************************************************
|
||||
|
||||
-- Process to retrieve list of ports using nmap
|
||||
function vs_utils.get_ports(host)
|
||||
-- FIXME
|
||||
-- must returns array of object {key: port_id}
|
||||
local result = {}
|
||||
|
||||
result[#result+1] = {
|
||||
key = 22
|
||||
}
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
-- **********************************************************
|
||||
|
||||
return vs_utils
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue