-- -- (C) 2013-15 - ntop.org -- dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path require "lua_utils" require "flow_utils" require "voip_utils" local json = require ("dkjson") sendHTTPHeader('text/html; charset=iso-8859-1') ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/header.inc") warn_shown = 0 function displayProc(proc) print("User Name".. proc.user_name .."\n") print("Process PID/Name".. proc.pid .. "/" .. proc.name .. "") print(" [son of " .. proc.father_pid .. "/" .. proc.father_name .."]\n") if(proc.actual_memory > 0) then print("Average CPU Load") cpu_load = round(proc.average_cpu_load, 2).."" if(proc.average_cpu_load < 33) then if(proc.average_cpu_load == 0) then proc.average_cpu_load = "< 1" end print(""..cpu_load.." %") elseif(proc.average_cpu_load < 66) then print(""..cpu_load.." %") else print(""..cpu_load.." %") end print(" \n") print("I/O Wait Time Percentage") cpu_load = round(proc.percentage_iowait_time, 2).."" if(proc.percentage_iowait_time < 33) then if(proc.percentage_iowait_time == 0) then proc.percentage_iowait_time = "< 1" end print(""..cpu_load.." %") elseif(proc.percentage_iowait_time < 66) then print(""..cpu_load.." %") else print(""..cpu_load.." %") end print(" \n") print("Memory Actual / Peak".. bytesToSize(proc.actual_memory) .. " / ".. bytesToSize(proc.peak_memory) .. " [" .. round((proc.actual_memory*100)/proc.peak_memory, 1) .."%]\n") print("VM Page Faults") if(proc.num_vm_page_faults > 0) then print(""..proc.num_vm_page_faults.."") else print(""..proc.num_vm_page_faults.."") end print("\n") end if(proc.actual_memory == 0) then if(warn_shown == 0) then warn_shown = 1 print(' Process information report is limited unless you use ntopng with nProbe and the sprobe plugin\n') end end end active_page = "flows" dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua") a = _GET["label"] if((a ~= nil) and (a ~= "")) then patterns = { ['_'] = "", ['-_'] = " " } for search,replace in pairs(patterns) do a = string.gsub(a, search, replace) end end print [[
]] throughput_type = getThroughputType() flow_key = _GET["flow_key"] if(flow_key == nil) then flow = nil else interface.select(ifname) flow = interface.findFlowByKey(tonumber(flow_key)) end if(flow == nil) then print("
This flow cannot be found (expired ?)
") else if(_GET["drop_flow_policy"] == "true") then interface.dropFlowTraffic(tonumber(flow_key)) flow["verdict.pass"] = false end if(_GET["dump_flow_to_disk"] ~= nil) then interface.dumpFlowTraffic(tonumber(flow_key), ternary(_GET["dump_flow_to_disk"] == "true", 1, 0)) flow["dump.disk"] = ternary(_GET["dump_flow_to_disk"] == "true", true, false) end ifstats = aggregateInterfaceStats(interface.getStats()) print("\n") if (ifstats.vlan and (flow["vlan"] ~= nil)) then print("\n") end print("\n") print("") if(ifstats.inline and flow["verdict.pass"]) then print("") if(ifstats.inline) then print('') end print("\n") if(ifstats.inline and (flow["shaper.cli2srv_a"] ~= nil)) then print("") c = flowinfo2hostname(flow,"cli",ifstats.vlan) s = flowinfo2hostname(flow,"srv",ifstats.vlan) shaper_key = "ntopng.prefs."..ifstats.id..".shaper_max_rate" cli_max_rate = ntop.getHashCache(shaper_key, flow["shaper.cli2srv_a"]) if(cli_max_rate == "") then cli_max_rate = -1 end srv_max_rate = ntop.getHashCache(shaper_key, flow["shaper.cli2srv_b"]) if(srv_max_rate == "") then srv_max_rate = -1 end max_rate = getFlowMaxRate(cli_max_rate, srv_max_rate) print("") cli_max_rate = ntop.getHashCache(shaper_key, flow["shaper.srv2cli_a"]) if(cli_max_rate == "") then cli_max_rate = -1 end srv_max_rate = ntop.getHashCache(shaper_key, flow["shaper.srv2cli_b"]) if(srv_max_rate == "") then srv_max_rate = -1 end max_rate = getFlowMaxRate(cli_max_rate, srv_max_rate) print("") print("") end print("\n") print("\n") print("\n") print("\n") if(flow["tcp.nw_latency.client"] ~= nil) then s = flow["tcp.nw_latency.client"] + flow["tcp.nw_latency.server"] if(s > 0) then print("\n") end end print("\n") print("\n") if(flow["tcp.seq_problems"]) then print("\n") print("\n") print("\n") print("\n") end if(flow["ssl.certificate"] ~= nil) then print("\n") end if((flow["tcp_flags"] ~= nil) and (flow["tcp_flags"] > 0)) then print("\n") end if((flow.client_process == nil) and (flow.server_process == nil)) then print("\n") else if((flow.client_process ~= nil) or (flow.server_process ~= nil)) then print('\n') end if(flow.client_process ~= nil) then print("\n") displayProc(flow.client_process) end if(flow.server_process ~= nil) then print("\n") displayProc(flow.server_process) end end if(flow["dns.last_query"] ~= nil) then print("\n") end if(flow["http.last_url"] ~= nil) then print("\n") print("\n") print("\n") print("\n") else if((flow["host_server_name"] ~= nil) and (flow["dns.last_query"] == nil)) then print("\n") end end if(flow["profile"] ~= nil) then print("\n") end dump_flow_to_disk = flow["dump.disk"] if(dump_flow_to_disk == true) then dump_flow_to_disk_checked = 'checked="checked"' dump_flow_to_disk_value = "false" -- Opposite else dump_flow_to_disk_checked = "" dump_flow_to_disk_value = "true" -- Opposite end print("\n") if (flow["moreinfo.json"] ~= nil) then local info, pos, err = json.decode(flow["moreinfo.json"], 1, nil) -- get SIP rows local sip_table_rows = getSIPTableRows(info) print(sip_table_rows) info = removeProtocolFields("SIP",info) isThereSIP = isThereProtocol(SIP, info) -- get RTP rows local rtp_table_rows = getRTPTableRows(info) print(rtp_table_rows) info = removeProtocolFields("RTP",info) isThereRTP = isThereProtocol(RTP, info) num = 0 for key,value in pairs(info) do if(num == 0) then print("\n") end if(value ~= "") then print("\n") end num = num + 1 end end print("
") if(ifstats.sprobe) then print('Source Id') else print('VLAN ID') end print("" .. flow["vlan"].. "
Flow Peers") print(flowinfo2hostname(flow,"cli",ifstats.vlan)) if(flow["cli.systemhost"] == true) then print(" ") end print("") if(flow["cli.port"] > 0) then print(":" .. flow["cli.port"]) end print(" \n") print("") print(flowinfo2hostname(flow,"srv",ifstats.vlan)) if(flow["srv.systemhost"] == true) then print(" ") end print("") if(flow["srv.port"] > 0) then print(":" .. flow["srv.port"].. "") end print("
Protocol") else print("") end if(flow["verdict.pass"] == false) then print("") end print(flow["proto.l4"].." / ") print(getApplicationLabel(flow["proto.ndpi"]).." ("..flow["proto.ndpi_id"]..")") print(" ".. formatBreed(flow["proto.ndpi_breed"])) if(flow["verdict.pass"] == false) then print("") end print("') if(flow["verdict.pass"]) then print('
') print('') print('') print('\n') print('
') end print('
Flow Shapers"..c.." "..s..""..maxRateToString(max_rate).."
"..c.." "..s..""..maxRateToString(max_rate).."
First / Last Seen
" .. formatEpoch(flow["seen.first"]) .. " [" .. secondsToTime(os.time()-flow["seen.first"]) .. " ago]" .. "
" .. formatEpoch(flow["seen.last"]) .. " [" .. secondsToTime(os.time()-flow["seen.last"]) .. " ago]" .. "
Total Traffic Volume" .. bytesToSize(flow["bytes"]) .. "
Client vs Server Traffic Breakdown") cli2srv = round((flow["cli2srv.bytes"] * 100) / flow["bytes"], 0) cli_name = shortHostName(ntop.getResolvedAddress(flow["cli.ip"])) srv_name = shortHostName(ntop.getResolvedAddress(flow["srv.ip"])) if(flow["cli.port"] > 0) then cli_name = cli_name .. ":" .. flow["cli.port"] srv_name = srv_name .. ":" .. flow["srv.port"] end print('
'.. cli_name..'
' .. srv_name .. '
') print("
Network Latency Breakdown") cli2srv = round(((flow["tcp.nw_latency.client"] * 100) / s), 0) c = string.format("%.3f", flow["tcp.nw_latency.client"]) print('
'.. c ..' ms (client)
') s = string.format("%.3f", flow["tcp.nw_latency.server"]) print('
' .. s .. ' ms (server)
') print("
Client to Server Traffic" .. formatPackets(flow["cli2srv.packets"]) .. " / ".. bytesToSize(flow["cli2srv.bytes"]) .. "
Server to Client Traffic" .. formatPackets(flow["srv2cli.packets"]) .. " / ".. bytesToSize(flow["srv2cli.bytes"]) .. "
TCP Packet Analysis") print("
 Client to Server / Server to Client
Retransmissions".. formatPackets(flow["cli2srv.retransmissions"]) .." / ".. formatPackets(flow["srv2cli.retransmissions"]) .."
Out of Order".. formatPackets(flow["cli2srv.out_of_order"]) .." / ".. formatPackets(flow["srv2cli.out_of_order"]) .."
Lost".. formatPackets(flow["cli2srv.lost"]) .." / ".. formatPackets(flow["srv2cli.lost"]) .."
SSL Certificate") print(flow["ssl.certificate"]) if(flow["category"] ~= nil) then print(" "..getCategoryIcon(flow["ssl.certificate"], flow["category"])) end print("
TCP Flags") flow_completed = false flow_reset = false if(hasbit(flow["tcp_flags"],0x01)) then print('FIN ') flow_completed = true end if(hasbit(flow["tcp_flags"],0x02)) then print('SYN ') end if(hasbit(flow["tcp_flags"],0x04)) then print('RST ') flow_completed = true flow_reset = true end if(hasbit(flow["tcp_flags"],0x08)) then print('PUSH ') end if(hasbit(flow["tcp_flags"],0x10)) then print('ACK ') end if(hasbit(flow["tcp_flags"],0x20)) then print('URG ') end if(flow_reset) then print(" This flow has been reset and probably the server application is down.") else if(flow_completed) then print(" This flow is completed and will soon expire.") else print(" This flow is active.") end end print("
Actual / Peak Throughput") if (throughput_type == "bps") then print("" .. bitsToSize(8*flow["throughput_bps"]) .. " ") elseif (throughput_type == "pps") then print("" .. pktsToSize(flow["throughput_bps"]) .. " ") end if (throughput_type == "bps") then print(" / " .. bitsToSize(8*flow["top_throughput_bps"]) .. " ") elseif (throughput_type == "pps") then print(" / " .. pktsToSize(flow["top_throughput_bps"]) .. " ") end print("0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0") print("
') width = 1024 height = 200 url = ntop.getHttpPrefix().."/lua/sprobe_flow_data.lua?flow_key="..flow_key dofile(dirs.installdir .. "/scripts/lua/inc/sprobe.lua") print('
Client Process Information
Server Process Information
DNS Query") if(string.ends(flow["dns.last_query"], "arpa")) then print(flow["dns.last_query"]) else print(""..flow["dns.last_query"].." ") end if(flow["category"] ~= nil) then print(" "..getCategoryIcon(flow["dns.last_query"], flow["category"])) end print("
HTTPHTTP Method"..flow["http.last_method"].."
Server Name") if(flow["host_server_name"] ~= nil) then s = flow["host_server_name"] else s = flowinfo2hostname(flow,"srv",ifstats.vlan) end print(s) if(flow["category"] ~= nil) then print(" "..getCategoryIcon(flow["host_server_name"], flow["category"])) end print("
URL") if(flow["http.last_url"] ~= "") then print(""..shortenString(flow["http.last_url"]).." ") else print(shortenString(flow["http.last_url"])) end print("
Response Code"..flow["http.last_return_code"].."
Server Name"..flow["host_server_name"].."
Profile Name"..flow["profile"].."
Dump Flow Traffic") print [[
') print(' ') print('\n') print('
') print("
Additional Flow Elements
" .. getFlowKey(key) .. "" .. handleCustomFlowField(key, value) .. "
\n") end print [[ ]] dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")