--
-- (C) 2013-17 - ntop.org
--
dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
if(ntop.isPro()) then
package.path = dirs.installdir .. "/pro/scripts/lua/modules/?.lua;" .. package.path
require "snmp_utils"
shaper_utils = require("shaper_utils")
host_pools_utils = require "host_pools_utils"
end
require "lua_utils"
require "graph_utils"
require "alert_utils"
require "historical_utils"
local json = require ("dkjson")
local host_pools_utils = require "host_pools_utils"
local discover = require "discover_utils"
local debug_hosts = false
local page = _GET["page"]
local protocol_id = _GET["protocol"]
local application = _GET["application"]
local host_info = url2hostinfo(_GET)
local host_ip = host_info["host"]
local host_name = hostinfo2hostkey(host_info)
local host_vlan = host_info["vlan"] or 0
local always_show_hist = _GET["always_show_hist"]
local ntopinfo = ntop.getInfo()
local active_page = "hosts"
interface.select(ifname)
local ifstats = interface.getStats()
ifId = ifstats.id
local is_packetdump_enabled = isLocalPacketdumpEnabled()
local host = nil
local family = nil
local prefs = ntop.getPrefs()
local hostkey = hostinfo2hostkey(host_info, nil, true --[[ force show vlan --]])
local labelKey = host_info["host"].."@"..host_info["vlan"]
if((host_name == nil) or (host_ip == nil)) then
sendHTTPContentTypeHeader('text/html')
ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/header.inc")
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
print("
\n")
if(host["ip"] ~= nil) then
if(host["mac"] ~= "00:00:00:00:00:00") then
print("| "..i18n("details.router_access_point_mac_address").." | " ..get_symbolic_mac(host["mac"]).. " " .. discover.devtype2icon(host["device_type"]))
print(' | ')
if(host['localhost'] and (macinfo ~= nil)) then
-- This is a known device type
print(discover.devtype2icon(macinfo.devtype) .. " ")
if macinfo.devtype ~= 0 then
print(discover.devtype2string(macinfo.devtype) .. " ")
else
print(i18n("host_details.unknown_device_type") .. " ")
end
print('\n')
else
print(" ")
end
print(' |
')
end
if(host['localhost'] and (host["mac"] ~= "") and (info["version.enterprise_edition"])) then
local ports = find_mac_snmp_ports(host["mac"], _GET["snmp_recache"] == "true")
if(ports ~= nil) then
local rsps = 1
for snmp_device_ip,port in pairs(ports) do
rsps = rsps + 1
end
if(rsps > 1) then
print('| '.. i18n("details.host_snmp_localization") ..' '..i18n("details.note")..': '..i18n("details.note_hosts_located_snmp_device",{url="https://tools.ietf.org/html/rfc4188"})..' | ')
print(""..i18n("snmp.snmp_device").." | "..i18n("details.device_port").." |
\n")
for snmp_device_ip,port in pairs(ports) do
local community = get_snmp_community(snmp_device_ip)
local trunk
print("| "..getResolvedAddress(hostkey2hostinfo(snmp_device_ip)).." | ")
if(port.trunk) then trunk = ' trunk' else trunk = "" end
print(""..port.id.." "..get_snmp_port_label(snmp_device_ip, community, port.id)..""..trunk.." |
\n")
end
end
end
end
print("")
print("| "..i18n("ip_address").." | " .. host["ip"])
if(host.childSafe == true) then print(getSafeChildIcon()) end
historicalProtoHostHref(getInterfaceId(ifname), host["ip"], nil, nil, nil)
if(host["local_network_name"] ~= nil) then
print(" [ ".. host["local_network_name"].." ]")
end
if((host["city"] ~= nil) and (host["city"] ~= "")) then
print(" [ " .. host["city"] .." "..getFlag(host["country"]).." ]")
end
print[[ | ]] print(i18n("details.host_pool")..": ")
if not ifstats.isView then
print[[]] print(host_pools_utils.getPoolName(ifId, host_pool_id)) print[[]]
print[[ ]]
print[[]]
else
-- no link for view interfaces
print(host_pools_utils.getPoolName(ifId, host_pool_id))
end
print(" |
")
else
if(host["mac"] ~= nil) then
print("| "..i18n("mac_address").." | " .. host["mac"].. " |
\n")
end
end
if(ifstats.vlan and (host["vlan"] ~= nil)) then
print("| ")
if(ifstats.sprobe) then
print(i18n("details.source_id"))
else
print(i18n("details.vlan_id"))
end
print(" | "..host["vlan"].." |
\n")
end
if(host["os"] ~= "") then
print("")
if(host["os"] ~= "") then
print("| "..i18n("os").." | "..mapOS2Icon(host["os"]) .. " | | \n")
else
print(" | | \n")
end
print("
")
end
if((host["asn"] ~= nil) and (host["asn"] > 0)) then
print("| "..i18n("asn").." | ")
print(""..host.asname.." [ "..i18n("asn").." ".. host.asn.." ] | ")
print(''..i18n("details.whois_lookup")..' | ')
print("
\n")
end
if(host["ip"] ~= nil) then
if(host["name"] == nil) then
host["name"] = getResolvedAddress(hostkey2hostinfo(host["ip"]))
end
print("| "..i18n("name").." | ")
if(isAdministrator()) then
print(" ")
else
print(" | ")
end
if(host["ip"] == host["name"]) then
print(" ")
end
--tprint(host) io.write("\n")
print(host["name"] .. " ")
print[[ ]]
print[[ ]]
if(host["localhost"] == true) then print(''..i18n("details.label_local_host")..'') else print(''..i18n("details.label_remote")..'') end
if(host["privatehost"] == true) then print(' '..i18n("details.label_private_ip")..'') end
if(host["systemhost"] == true) then print(' '..i18n("details.label_system_ip")..' '..'') end
if(host["is_blacklisted"] == true) then print(' '..i18n("details.label_blacklisted_host")..'') end
print(" | | \n")
end
if(host["num_alerts"] > 0) then
print("
|---|
| "..i18n("details.alerts").." | "..host["num_alerts"] .. " |
\n")
end
if ntop.isPro() and ifstats.inline and (host["has_blocking_quota"] or host["has_blocking_shaper"]) then
local msg = ""
local target = ""
local quotas_page = "/lua/host_details.lua?"..hostinfo2url(host).."&page=quotas&ifid="..ifId
local policies_page = "/lua/if_stats.lua?ifid="..ifId.."&page=filtering&pool="..host_pool_id
if host["has_blocking_quota"] then
if host["has_blocking_shaper"] then
msg = i18n("host_details.host_traffic_blocked_quota_and_shaper")
target = quotas_page
else
msg = i18n("host_details.host_traffic_blocked_quota")
target = quotas_page
end
else
msg = i18n("host_details.host_traffic_blocked_shaper")
target = policies_page
end
print("| "..i18n("host_details.blocked_traffic").." | "..msg)
print(".")
print(" |
")
end
print("| "..i18n("details.first_last_seen").." | " .. formatEpoch(host["seen.first"]) .. " [" .. secondsToTime(os.time()-host["seen.first"]) .. " "..i18n("details.ago").."]" .. " | \n")
print("" .. formatEpoch(host["seen.last"]) .. " [" .. secondsToTime(os.time()-host["seen.last"]) .. " "..i18n("details.ago") .. "]" .. " |
\n")
if((host["bytes.sent"]+host["bytes.rcvd"]) > 0) then
print("| "..i18n("details.sent_vs_received_traffic_breakdown").." | ")
breakdownBar(host["bytes.sent"], i18n("sent"), host["bytes.rcvd"], i18n("details.rcvd"), 0, 100)
print(" |
\n")
end
print("| "..i18n("details.traffic_sent_received").." | " .. formatPackets(host["packets.sent"]) .. " / ".. bytesToSize(host["bytes.sent"]) .. " | " .. formatPackets(host["packets.rcvd"]) .. " / ".. bytesToSize(host["bytes.rcvd"]) .. " |
\n")
local flows_th = i18n("details.flows_non_packet_iface")
if interface.isPacketInterface() then
if interface.isPcapDumpInterface() == false then
flows_th = i18n("details.flows_packet_iface")
else
flows_th = i18n("details.flows_packet_pcap_dump_iface")
end
end
print("| "..flows_th.." | '"..i18n("details.as_client").."' | '"..i18n("details.as_server").."' |
\n")
print("| " .. formatValue(host["active_flows.as_client"]) .. " \n")
print("/ " .. formatValue(host["flows.as_client"]) .. " \n")
if interface.isPacketInterface() then
print("/ " .. formatValue(host["low_goodput_flows.as_client"]) .. " \n")
end
print(" | ")
print("" .. formatValue(host["active_flows.as_server"]) .. " \n")
print("/ "..formatValue(host["flows.as_server"]) .. " \n")
if interface.isPacketInterface() then
print("/ " .. formatValue(host["low_goodput_flows.as_server"]) .. " \n")
end
print(" |
")
if interface.isBridgeInterface(ifstats) then
print("")
print("| "..i18n("details.flows_dropped_by_bridge").." | ")
print("" .. formatValue((host["flows.dropped"] or 0)) .. " ")
print(" |
")
end
if host["tcp.packets.seq_problems"] == true then
print("| "..i18n("details.tcp_packets_sent_analysis").." | "..i18n("details.retransmissions").." | ".. formatPackets(host["tcp.packets.retransmissions"]) .." |
\n")
print("| "..i18n("details.out_of_order").." | ".. formatPackets(host["tcp.packets.out_of_order"]) .." |
\n")
print("| "..i18n("details.lost").." | ".. formatPackets(host["tcp.packets.lost"]) .." |
\n")
end
if((host["info"] ~= nil) or (host["label"] ~= nil))then
print("| "..i18n("details.further_host_names_information").." | ")
if(host["info"] ~= nil) then print(host["info"]) end
if((host["label"] ~= nil) and (host["info"] ~= host["label"])) then print(host["label"]) end
print(" |
\n")
end
if(host["json"] ~= nil) then
print("| JSON | "..i18n("download").." |
\n")
end
if(host["ssdp"] ~= nil) then
print("| SSDP (UPnP) | "..host["ssdp"].." |
\n")
end
print("
\n")
elseif((page == "packets")) then
print [[
]]
elseif((page == "peers")) then
host_info = url2hostinfo(_GET)
peers = getTopFlowPeers(hostinfo2hostkey(host_info), 1 --[[exists query]])
found = 0
for key, value in pairs(peers) do
found = 1
break
end
if(found) then
print [[
]]
local direction_filter = ""
local base_url = ntop.getHttpPrefix().."/lua/host_details.lua?ifid="..ifId.."&"..hostinfo2url(host_info).."&page=ndpi";
if(direction ~= nil) then
direction_filter = ''
end
print('