-- -- (C) 2013-24 - ntop.org -- local dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path package.path = dirs.installdir .. "/scripts/lua/modules/pools/?.lua;" .. package.path local snmp_utils local snmp_location if(ntop.isPro()) then package.path = dirs.installdir .. "/pro/scripts/lua/modules/?.lua;" .. package.path snmp_utils = require "snmp_utils" snmp_location = require "snmp_location" end require "lua_utils" local graph_utils = require "graph_utils" local alert_utils = require "alert_utils" require "discover_utils" require "mac_utils" local page_utils = require("page_utils") local have_nedge = ntop.isnEdge() local info = ntop.getInfo() local os_utils = require "os_utils" local discover = require "discover_utils" local host_pools = require "host_pools" local template = require "template_utils" local page = _GET["page"] local host_info = url2hostinfo(_GET) local mac = host_info["host"] local pool_id interface.select(ifname) -- Instantiate host pools local host_pools_instance = host_pools:create() local ifstats = interface.getStats() local ifId = ifstats.id local prefs = ntop.getPrefs() if isAdministrator() then if (_SERVER["REQUEST_METHOD"] == "POST") and (page == "config") then setHostAltName(mac, _POST["custom_name"]) local devtype = tonumber(_POST["device_type"]) setCustomDeviceType(mac, devtype) ntop.setMacDeviceType(mac, devtype, true --[[ overwrite ]]) pool_id = _POST["pool"] host_pools_instance:bind_member(mac, tonumber(pool_id)) end end if (pool_id == nil) then local cur_pool = host_pools_instance:get_pool_by_member(mac) if cur_pool then pool_id = cur_pool["pool_id"] else pool_id = host_pools_instance.DEFAULT_POOL_ID end end local vlanId = host_info["vlan"] local label = mac2label(mac) local devicekey = hostinfo2hostkey(host_info) if(vlanId == nil) then vlanId = 0 end sendHTTPContentTypeHeader('text/html') page_utils.print_header_and_set_active_menu_entry(page_utils.menu_entries.devices) dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua") if(mac == nil) then print("
" .. " " .. i18n("mac_details.mac_parameter_missing_message") .. "
") dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua") return end if isAdministrator() then if _POST["action"] == "reset_stats" then if interface.resetMacStats(mac) then print("
") print(i18n("mac_details.reset_stats_in_progress")) print([[]]) print("
") end end end local mac_info = interface.getMacInfo(mac) -- tprint(mac_info) local only_historical = (mac_info == nil) and (page == "historical") local serialize_by_mac = ntop.getPref(string.format("ntopng.prefs.ifid_" .. ifId .. ".serialize_local_broadcast_hosts_as_macs")) == "1" local historical_flow_link = ntop.getHttpPrefix() .. "/lua/db_search.lua?ifid=" .. ifId .. ";eq&mac=" .. mac .. ";eq" if(mac_info == nil) and not only_historical then print('
'..' '..i18n("mac_details.mac_cannot_be_found_message",{mac=mac})) print("
") dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua") return end local url = ntop.getHttpPrefix().."/lua/mac_details.lua?"..hostinfo2url(host_info) local has_snmp_location = snmp_location and snmp_location.host_has_snmp_location(mac) local title = i18n("mac_details.mac")..": "..mac page_utils.print_navbar(title, url, { { hidden = only_historical, active = page == "overview" or page == nil, page_name = "overview", label = "", }, { hidden = only_historical or (mac_info["packets.sent"] + mac_info["packets.rcvd"] == 0), active = page == "packets", page_name = "packets", label = i18n("packets"), }, { hidden = not has_snmp_location, active = page == "snmp", page_name = "snmp", label = i18n("host_details.snmp"), }, { hidden = not areMacsTimeseriesEnabled(ifId) and not serialize_by_mac, active = page == "historical", page_name = "historical", label = "", }, { hidden = not prefs.is_dump_flows_to_clickhouse_enabled, active = page == "db_search", page_name = "db_search", label = "", url = historical_flow_link }, { hidden = not isAdministrator() or interface.isPcapDumpInterface(), active = page == "config", page_name = "config", label = "", }, } ) if((page == "overview") or (page == nil)) then print("\n") print("") print("") if mac_info["num_hosts"] > 0 then print("") print("") print("") end if has_snmp_location then snmp_location.print_host_snmp_location(mac, url .. [[&page=snmp]]) end print("\n") print("") print("\n") print("") if(mac_info.devtype ~= 0) then -- This is a known device type print("\n") end if(mac_info.fingerprint ~= "") then print("\n") end if have_nedge then print("\n") end print("\n") print("\n") if((mac_info["bytes.sent"]+mac_info["bytes.rcvd"]) > 0) then print("\n") end local first_observed = ntop.getHashCache(getDevicesHashMapKey(ifId), mac_info["mac"]) if(not isEmptyString(first_observed)) and (tonumber(first_observed)) then print("\n") end if interface.isBridgeInterface(ifstats) then print("") print("") print("") end print("\n") print("\n") if not have_nedge then print([[ ]]) print([[]]) end -- Stats reset print( template.gen("modal_confirm_dialog.html", { dialog={ id = "reset_mac_stats_dialog", action = "$('#reset_mac_stats_form').submit();", title = i18n("mac_details.reset_mac_stats"), message = i18n("host_details.reset_host_stats_confirm", {host=mac}) .. "

" .. i18n("mac_details.reset_mac_stats_note"), confirm = i18n("reset"), } }) ) print[[]] 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 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(not isEmptyString(mac_info.model)) then local _model = discover.apple_products[mac_info.model] or mac_info.model print(" [ "..i18n("model")..": ".. _model .." ]") end print("
"..i18n("ip_address")..""..printMacHosts(mac).."
"..i18n("name")..""..label.."") if isAdministrator() then print[[ ]] print[[ ]] end print("\n") print[[]] print(i18n(ternary(have_nedge, "nedge.user", "details.host_pool"))..": ") if not ifstats.isView then print[[]] print(host_pools_instance:get_pool_name(pool_id)) print[[]] if isAdministrator() then print[[  ]] print[[]] end else -- no link for view interfaces print(host_pools_instance:get_pool_name(pool_id)) end 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("
DHCP Fingerprint "..'' ..""..mac_info.fingerprint.."
" .. i18n("hosts_stats.location") .. " ".. firstToUpper(mac_info.location) .."
".. i18n("details.first_last_seen") .. "" .. formatEpoch(mac_info["seen.first"]) .. " [" .. secondsToTime(os.time()-mac_info["seen.first"]) .. " " .. i18n("details.ago").."]" .. "" .. formatEpoch(mac_info["seen.last"]) .. " [" .. secondsToTime(os.time()-mac_info["seen.last"]) .. " " .. i18n("details.ago").."]" .. "
" .. i18n("details.sent_vs_received_traffic_breakdown") .. "") graph_utils.breakdownBar(mac_info["bytes.sent"], i18n("sent"), mac_info["bytes.rcvd"], i18n("details.rcvd"), 0, 100) print("
" .. i18n("details.first_observed_on") .. "") print(formatEpoch(first_observed)) print("
"..i18n("details.flows_dropped_by_bridge").."" .. formatValue((mac_info["flows.dropped"] or 0)) .. "") 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"]) .. "
" .. i18n("details.dhcp_sent_received") .. "" .. formatPackets(mac_info["dhcp.sent"]) .. " " .. formatPackets(mac_info["dhcp.rcvd"]) .. "
]]) print(i18n("details.address_resolution_protocol")) print[[ ]] print(i18n("details.arp_requests")) print[[ ]] print(i18n("details.arp_replies")) 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")..[[
]] print(i18n("mac_details.reset_mac_stats")) print[[
") print('') elseif(page == "packets") then print [[ ]] print("\n') print[[
" .. i18n("packets_page.ip_version_distribution") .. '
]] elseif(page == "snmp" and has_snmp_location) then print[[]] snmp_location.print_host_snmp_localization_table_entry(mac) print[[
]] elseif(page == "historical") then local source_value_object = { ifid = interface.getId() } graph_utils.drawNewGraphs(source_value_object) elseif(page == "config") then if(not isAdministrator()) then return end print[[
]] if not ifstats.isView then graph_utils.printPoolChangeDropdown(ifId, pool_id.."", have_nedge) end print[[
]] print(i18n("host_config.host_alias")) print[[ ]] print[[  
") discover.printDeviceTypeSelector(mac_info.devtype, "device_type") print [[


]] end dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")