mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-01 00:19:33 +00:00
272 lines
10 KiB
Lua
272 lines
10 KiB
Lua
--
|
|
-- (C) 2013-17 - 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"
|
|
|
|
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(_POST["custom_name"] ~= nil) then
|
|
setHostAltName(mac, _POST["custom_name"])
|
|
end
|
|
|
|
if(_POST["device_type"] ~=nil) then
|
|
local devtype = tonumber(_POST["device_type"])
|
|
setCustomDeviceType(mac, devtype)
|
|
interface.setMacDeviceType(mac, devtype, true --[[ overwrite ]])
|
|
end
|
|
|
|
if (_POST["pool"] ~= nil) then
|
|
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
|
|
|
|
if (pool_id == nil) then
|
|
pool_id = host_pools_utils.getMacPool(mac)
|
|
end
|
|
|
|
end
|
|
|
|
local vlanId = host_info["vlan"]
|
|
local label = getHostAltName(mac)
|
|
|
|
if(vlanId == nil) then vlanId = 0 end
|
|
|
|
sendHTTPContentTypeHeader('text/html')
|
|
ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/header.inc")
|
|
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
|
|
|
|
if(mac == nil) then
|
|
print("<div class=\"alert alert alert-danger\"><img src=".. ntop.getHttpPrefix() .. "/img/warning.png>" .. " " .. i18n("mac_details.mac_parameter_missing_message") .. "</div>")
|
|
return
|
|
end
|
|
|
|
local mac_info = interface.getMacInfo(mac, vlanId)
|
|
|
|
-- tprint(mac_info)
|
|
|
|
if(mac_info == nil) then
|
|
print('<div class=\"alert alert-danger\"><i class="fa fa-warning fa-lg"></i>'..' '..i18n("mac_details.mac_cannot_be_found_message",{mac=mac}))
|
|
print("</div>")
|
|
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")
|
|
return
|
|
end
|
|
|
|
print [[
|
|
<div class="bs-docs-example">
|
|
<nav class="navbar navbar-default" role="navigation">
|
|
<div class="navbar-collapse collapse">
|
|
<ul class="nav navbar-nav">
|
|
]]
|
|
|
|
print("<li><a href=\"#\">"..i18n("mac_details.mac")..": "..mac.."</A> </li>")
|
|
|
|
if((page == "overview") or (page == nil)) then
|
|
print("<li class=\"active\"><a href=\"#\"><i class=\"fa fa-home fa-lg\"></i>\n")
|
|
else
|
|
print("<li><a href=\""..ntop.getHttpPrefix().."/lua/mac_details.lua?"..hostinfo2url(host_info).."&page=overview\"><i class=\"fa fa-home fa-lg\"></i>\n")
|
|
end
|
|
|
|
if(page == "config") then
|
|
print("<li class=\"active\"><a href=\"#\"><i class=\"fa fa-cog fa-lg\"></i>\n")
|
|
else
|
|
print("<li><a href=\""..ntop.getHttpPrefix().."/lua/mac_details.lua?"..hostinfo2url(host_info).."&page=config\"><i class=\"fa fa-cog fa-lg\"></i>\n")
|
|
end
|
|
|
|
print("<li><a href='javascript:history.go(-1)'><i class='fa fa-reply'></i></a></li></ul></div></nav></div>")
|
|
|
|
|
|
if((page == "overview") or (page == nil)) then
|
|
|
|
print("<table class=\"table table-bordered table-striped\">\n")
|
|
print("<tr><th width=35%>"..i18n("mac_address").."</th><td> "..mac)
|
|
|
|
local s = get_symbolic_mac(mac, true)
|
|
|
|
if(s ~= mac) then
|
|
print(" ("..s..")")
|
|
end
|
|
|
|
if mac_info["num_hosts"] > 0 then
|
|
print(" [ <A HREF=\"".. ntop.getHttpPrefix().."/lua/hosts_stats.lua?mac="..mac.."\">"..i18n("details.show_hosts").."</A> ]")
|
|
end
|
|
|
|
if(mac_info.dhcpHost) then
|
|
print(' <i class="fa fa-flash fa-lg" aria-hidden="true" title="DHCP Host"></i>')
|
|
end
|
|
|
|
print("</td>")
|
|
|
|
print("<td>")
|
|
|
|
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
|
|
print('<a href="'..ntop.getHttpPrefix()..'/lua/mac_details.lua?'..hostinfo2url(mac_info)..'&page=config"><i class="fa fa-cog"></i></a>\n')
|
|
|
|
print("</td></tr>")
|
|
|
|
print("<tr><th>"..i18n("name").."</th><td><span id=name>"..label.."</span>")
|
|
|
|
print[[ <a href="]] print(ntop.getHttpPrefix()) print[[/lua/mac_details.lua?]] print(hostinfo2url(mac_info)) print[[&page=config">]]
|
|
print[[<i class="fa fa-sm fa-cog" aria-hidden="true" title="Set Host Alias"></i></a></span> ]]
|
|
|
|
print("</td>\n")
|
|
|
|
print("<td>\n")
|
|
|
|
print[[<span>]] print(i18n("details.host_pool")..": ")
|
|
|
|
if not ifstats.isView then
|
|
print[[<a href="]] print(ntop.getHttpPrefix()) print[[/lua/hosts_stats.lua?pool=]] print(pool_id) print[[">]] print(host_pools_utils.getPoolName(ifId, pool_id)) print[[</a></span>]]
|
|
print[[ <a href="]] print(ntop.getHttpPrefix()) print[[/lua/mac_details.lua?]] print(hostinfo2url(mac_info)) print[[&page=config&ifid=]] print(tostring(ifId)) print[[">]]
|
|
print[[<i class="fa fa-sm fa-cog" aria-hidden="true" title=]] print('\"'..i18n("host_details.change_host_pool_popup_msg")..'\"') print[[></i></a></span>]]
|
|
else
|
|
-- no link for view interfaces
|
|
print(host_pools_utils.getPoolName(ifId, pool_id))
|
|
end
|
|
print("</td></tr>")
|
|
|
|
print("</td>\n")
|
|
|
|
print("</td></tr>")
|
|
|
|
if(mac_info.devtype ~= 0) then
|
|
-- This is a known device type
|
|
print("<tr><th>".. i18n("details.device_type") .. "</th><td>" .. discover.devtype2icon(mac_info.devtype) .. " ")
|
|
print(discover.devtype2string(mac_info.devtype) .. "</td><td></td></tr>\n")
|
|
end
|
|
|
|
if(mac_info.fingerprint ~= "") then
|
|
print("<tr><th><A HREF=https://en.wikipedia.org/wiki/Device_fingerprint>DHCP Fingerprint</A> "..'<i class="fa fa-hand-o-up fa-lg" aria-hidden="true"></i>'
|
|
.."</th><td>"..mac_info.fingerprint.."</td><td>Operating System: "..getOperatingSystemIcon(mac_info.operatingSystem).."</td></tr>\n")
|
|
end
|
|
|
|
print("<tr><th>".. i18n("details.first_last_seen") .. "</th><td nowrap><span id=first_seen>" .. formatEpoch(mac_info["seen.first"]) .. " [" .. secondsToTime(os.time()-mac_info["seen.first"]) .. " " .. i18n("details.ago").."]" .. "</span></td>\n")
|
|
print("<td width='35%'><span id=last_seen>" .. formatEpoch(mac_info["seen.last"]) .. " [" .. secondsToTime(os.time()-mac_info["seen.last"]) .. " " .. i18n("details.ago").."]" .. "</span></td></tr>\n")
|
|
|
|
if((mac_info["bytes.sent"]+mac_info["bytes.rcvd"]) > 0) then
|
|
print("<tr><th>" .. i18n("details.sent_vs_received_traffic_breakdown") .. "</th><td colspan=2>")
|
|
breakdownBar(mac_info["bytes.sent"], i18n("sent"), mac_info["bytes.rcvd"], i18n("details.rcvd"), 0, 100)
|
|
print("</td></tr>\n")
|
|
end
|
|
|
|
print("<tr><th>" .. i18n("details.traffic_sent_received") .. "</th><td><span id=pkts_sent>" .. formatPackets(mac_info["packets.sent"]) .. "</span> / <span id=bytes_sent>".. bytesToSize(mac_info["bytes.sent"]) .. "</span> <span id=sent_trend></span></td><td><span id=pkts_rcvd>" .. formatPackets(mac_info["packets.rcvd"]) .. "</span> / <span id=bytes_rcvd>".. bytesToSize(mac_info["bytes.rcvd"]) .. "</span> <span id=rcvd_trend></span></td></tr>\n")
|
|
print([[
|
|
<tr>
|
|
<th rowspan="2"><A HREF=https://en.wikipedia.org/wiki/Address_Resolution_Protocol>]]) print(i18n("details.address_resolution_protocol")) print[[</A></th>
|
|
<th>]] print(i18n("details.arp_requests")) print[[</th>
|
|
<th>]] print(i18n("details.arp_replies")) print([[</th>
|
|
</tr>
|
|
<tr>
|
|
<td><span id="arp_requests_sent">]]..formatValue(mac_info["arp_requests.sent"])..[[</span> ]]..i18n("sent")..[[ / <span id="arp_requests_rcvd">]]..formatValue(mac_info["arp_requests.rcvd"])..[[</span> ]]..i18n("received")..[[</td>
|
|
<td><span id="arp_replies_sent">]]..formatValue(mac_info["arp_replies.sent"])..[[</span> ]]..i18n("sent")..[[ / <span id="arp_replies_rcvd">]]..formatValue(mac_info["arp_replies.rcvd"])..[[</span> ]]..i18n("received")..[[</td>
|
|
</tr>]])
|
|
|
|
print("</table>")
|
|
|
|
print('<script type="text/javascript">')
|
|
|
|
print("var last_pkts_sent = " .. mac_info["packets.sent"] .. ";\n")
|
|
print("var last_pkts_rcvd = " .. mac_info["packets.rcvd"] .. ";\n")
|
|
|
|
print [[
|
|
|
|
var host_details_interval = window.setInterval(function() {
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: ']] print (ntop.getHttpPrefix()) print [[/lua/mac_stats.lua',
|
|
data: { ifid: "]] print(ifId.."") print('", '..hostinfo2json(mac_info)) print [[ },
|
|
datatype: "json",
|
|
/* error: function(content) { alert("JSON Error: inactive host purged or ntopng terminated?"); }, */
|
|
success: function(content) {
|
|
var host = jQuery.parseJSON(content);
|
|
$('#first_seen').html(epoch2Seen(host["seen.first"]));
|
|
$('#last_seen').html(epoch2Seen(host["seen.last"]));
|
|
$('#pkts_sent').html(formatPackets(host["packets.sent"]));
|
|
$('#pkts_rcvd').html(formatPackets(host["packets.rcvd"]));
|
|
$('#bytes_sent').html(bytesToVolume(host["bytes.sent"]));
|
|
$('#bytes_rcvd').html(bytesToVolume(host["bytes.rcvd"]));
|
|
$('#arp_requests_sent').html(addCommas(host["arp_requests.sent"]));
|
|
$('#arp_requests_rcvd').html(addCommas(host["arp_requests.rcvd"]));
|
|
$('#arp_replies_sent').html(addCommas(host["arp_replies.sent"]));
|
|
$('#arp_replies_rcvd').html(addCommas(host["arp_replies.rcvd"]));
|
|
},
|
|
});
|
|
}, 3000);
|
|
|
|
]]
|
|
print('</script>')
|
|
|
|
elseif(page == "config") then
|
|
|
|
if(not isAdministrator()) then
|
|
return
|
|
end
|
|
|
|
print[[
|
|
<table class="table table-bordered table-striped">
|
|
<tr>
|
|
<th>]] print(i18n("host_config.host_alias")) print[[</th>
|
|
<td>]]
|
|
print [[<form class="form-inline" style="margin-bottom: 0px;" method="post">]]
|
|
|
|
print[[<input type="text" name="custom_name" class="form-control" placeholder="Custom Name" value="]]
|
|
if(label ~= nil) then print(label) end
|
|
print("\"></input> ")
|
|
|
|
discover.printDeviceTypeSelector(mac_info.devtype, "device_type")
|
|
|
|
print [[
|
|
<button type="submit" class="btn btn-default">]] print(i18n("save")) print[[</button>]]
|
|
print('<input id="csrf" name="csrf" type="hidden" value="'..ntop.getRandomCSRFValue()..'" />\n')
|
|
print [[</form>
|
|
</td>
|
|
</tr>]]
|
|
|
|
if not ifstats.isView then
|
|
printPoolChangeDropdown(pool_id)
|
|
end
|
|
|
|
print[[</table>]]
|
|
|
|
end
|
|
|
|
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")
|