--
-- (C) 2013-18 - ntop.org
--
local 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"
end
require "lua_utils"
require "graph_utils"
require "alert_utils"
require "historical_utils"
require "discover_utils"
local page_utils = require("page_utils")
local ts_utils = require("ts_utils")
active_page = "hosts"
local have_nedge = ntop.isnEdge()
local info = ntop.getInfo(false)
local os_utils = require "os_utils"
local discover = require "discover_utils"
local host_pools_utils = require "host_pools_utils"
local page = _GET["page"]
local host_info = url2hostinfo(_GET)
local mac = host_info["host"]
local pool_id
interface.select(ifname)
local ifstats = interface.getStats()
local ifId = ifstats.id
local prefs = ntop.getPrefs()
if isAdministrator() then
if _SERVER["REQUEST_METHOD"] == "POST" then
setHostAltName(mac, _POST["custom_name"])
local devtype = tonumber(_POST["device_type"])
setCustomDeviceType(mac, devtype)
interface.setMacDeviceType(mac, devtype, true --[[ overwrite ]])
pool_id = _POST["pool"]
local prev_pool = host_pools_utils.getMacPool(mac)
if pool_id ~= prev_pool then
local key = mac
if not host_pools_utils.changeMemberPool(ifId, key, pool_id) then
pool_id = nil
else
interface.reloadHostPools()
end
end
end
end
if (pool_id == nil) then
pool_id = host_pools_utils.getMacPool(mac)
end
local vlanId = host_info["vlan"]
local label = getHostAltName(mac)
local devicekey = hostinfo2hostkey(host_info)
if(vlanId == nil) then vlanId = 0 end
sendHTTPContentTypeHeader('text/html')
page_utils.print_header()
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
if(mac == nil) then
print("
\n")
print("| "..i18n("mac_address").." | "..mac)
local s = get_symbolic_mac(mac, true)
if(s ~= mac) then
print(" ("..s..")")
end
if mac_info["num_hosts"] > 0 then
print(" [ "..i18n("details.show_hosts").." ]")
end
if(mac_info.dhcpHost) then
print(' ')
end
print(" | ")
print("")
print(discover.devtype2icon(mac_info.devtype) .. " ")
if mac_info.devtype ~= 0 then
print(discover.devtype2string(mac_info.devtype) .. " ")
else
print(i18n("host_details.unknown_device_type") .. " ")
end
if isAdministrator() then
print('\n')
end
if(mac_info.model ~= nil) then
local _model = discover.apple_products[mac_info.model] or mac_info.model
print(" [ "..i18n("model")..": ".. _model .." ]")
end
print(" |
")
if ntop.isPro() then
print_host_snmp_localization_table_entry(mac)
end
print("| "..i18n("name").." | "..label.."")
if(mac_info.operatingSystem ~= 0) then
print(" "..getOperatingSystemIcon(mac_info.operatingSystem).." ")
end
if isAdministrator() then
print[[ ]]
print[[ ]]
end
print(" | \n")
print("\n")
print[[]] print(i18n(ternary(have_nedge, "nedge.user", "details.host_pool"))..": ")
if not ifstats.isView then
print[[]] print(host_pools_utils.getPoolName(ifId, pool_id)) print[[]]
if isAdministrator() then
print[[ ]]
print[[]]
end
else
-- no link for view interfaces
print(host_pools_utils.getPoolName(ifId, pool_id))
end
print(" |
")
print("\n")
print("")
if(mac_info.devtype ~= 0) then
-- This is a known device type
print("| ".. i18n("details.device_type") .. " | " .. discover.devtype2icon(mac_info.devtype) .. " ")
print(discover.devtype2string(mac_info.devtype))
if(mac_info.ssid ~= nil) then
print(' ( '..mac_info.ssid..' )')
end
print(" | |
\n")
end
if(mac_info.fingerprint ~= "") then
print("| DHCP Fingerprint "..''
.." | "..mac_info.fingerprint.." |
\n")
end
if have_nedge then
print("| " .. i18n("hosts_stats.location") .. " | ".. firstToUpper(mac_info.location) .." |
\n")
end
print("| ".. i18n("details.first_last_seen") .. " | " .. formatEpoch(mac_info["seen.first"]) .. " [" .. secondsToTime(os.time()-mac_info["seen.first"]) .. " " .. i18n("details.ago").."]" .. " | \n")
print("" .. formatEpoch(mac_info["seen.last"]) .. " [" .. secondsToTime(os.time()-mac_info["seen.last"]) .. " " .. i18n("details.ago").."]" .. " |
\n")
if((mac_info["bytes.sent"]+mac_info["bytes.rcvd"]) > 0) then
print("| " .. i18n("details.sent_vs_received_traffic_breakdown") .. " | ")
breakdownBar(mac_info["bytes.sent"], i18n("sent"), mac_info["bytes.rcvd"], i18n("details.rcvd"), 0, 100)
print(" |
\n")
end
local first_observed = ntop.getHashCache(getFirstSeenDevicesHashKey(ifId), mac_info["mac"])
if(not isEmptyString(first_observed)) then
print("| " .. i18n("details.first_observed_on") .. " | ")
print(formatEpoch(first_observed))
print(" |
\n")
end
if interface.isBridgeInterface(ifstats) then
print("")
print("| "..i18n("details.flows_dropped_by_bridge").." | ")
print("" .. formatValue((mac_info["flows.dropped"] or 0)) .. "")
print(" |
")
end
print("| " .. i18n("details.traffic_sent_received") .. " | " .. formatPackets(mac_info["packets.sent"]) .. " / ".. bytesToSize(mac_info["bytes.sent"]) .. " | " .. formatPackets(mac_info["packets.rcvd"]) .. " / ".. bytesToSize(mac_info["bytes.rcvd"]) .. " |
\n")
if not have_nedge then
print([[
| ]]) print(i18n("details.address_resolution_protocol")) print[[ |
]] print(i18n("details.arp_requests")) print[[ |
]] print(i18n("details.arp_replies")) print([[ |
]])
print([[
| ]]..formatValue(mac_info["arp_requests.sent"])..[[ ]]..i18n("sent")..[[ / ]]..formatValue(mac_info["arp_requests.rcvd"])..[[ ]]..i18n("received")..[[ |
]]..formatValue(mac_info["arp_replies.sent"])..[[ ]]..i18n("sent")..[[ / ]]..formatValue(mac_info["arp_replies.rcvd"])..[[ ]]..i18n("received")..[[ |
]])
end
print("
")
print('')
elseif(page == "packets") then
print [[