"
end
end
end
-- parse interface names and possibly fall back to the selected interface:
-- priority goes to the interface id
if ifid ~= nil and ifid ~= "" then
if_name = getInterfaceName(ifid)
else
-- fall-back to the default interface
if_name = ifname
ifid = interface.name2id(ifname)
end
interface.select(ifname)
-- local pcap dump is disabled if the nbox integration is enabled or
-- if the user is not an administrator or if the interface:
-- is a view
-- is not a packet interface (i.e., it is zmq)
local is_packetdump_enabled = isLocalPacketdumpEnabled()
local is_packet_interface = interface.isPacketInterface()
local ifstats = interface.getStats()
-- this is a user-browseable page, so we must return counters from
-- the latest reset as the user may have chosen to reset statistics at some point
if ifstats.stats and ifstats.stats_since_reset then
-- override stats with the values calculated from the latest user reset
for k, v in pairs(ifstats.stats_since_reset) do
ifstats.stats[k] = v
end
end
if (isAdministrator()) then
if (page == "config") and (not table.empty(_POST)) then
-- TODO move keys to new schema: replace ifstats.name with ifid
ntop.setCache('ntopng.prefs.'..ifstats.name..'.name',_POST["custom_name"])
local ifspeed_cache = 'ntopng.prefs.'..ifstats.name..'.speed'
if isEmptyString(_POST["ifSpeed"]) then
ntop.delCache(ifspeed_cache)
else
ntop.setCache(ifspeed_cache, _POST["ifSpeed"])
end
local hide_set = getHideFromTopSet(ifstats.id)
ntop.delCache(hide_set)
for _, net in pairs(split(_POST["hide_from_top"] or "", ",")) do
net = trimSpace(net)
if not isEmptyString(net) then
local address, prefix = splitNetworkPrefix(net)
if isIPv6(address) and prefix == "128" then
net = address
elseif isIPv4(address) and prefix == "32" then
net = address
end
ntop.setMembersCache(hide_set, net)
end
end
interface.reloadHideFromTop()
setInterfaceRegreshRate(ifstats.id, tonumber(_POST["ifRate"]))
local sf = tonumber(_POST["scaling_factor"])
if(sf == nil) then sf = 1 end
ntop.setCache(getRedisIfacePrefix(ifid)..'.scaling_factor',tostring(sf))
interface.loadScalingFactorPrefs()
end
if is_packetdump_enabled and (page == "packetdump") and (_SERVER["REQUEST_METHOD"] == "POST") then
ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_all_traffic', ternary(isEmptyString(_POST["dump_all_traffic"]), "false", "true"))
ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_tap', ternary(isEmptyString(_POST["dump_traffic_to_tap"]), "false", "true"))
ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_disk', ternary(isEmptyString(_POST["dump_traffic_to_disk"]), "false", "true"))
ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_unknown_traffic', ternary(isEmptyString(_POST["dump_unknown_to_disk"]), "false", "true"))
ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_sampling_rate', _POST["sampling_rate"])
ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_max_pkts_file', _POST["max_pkts_file"])
ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_max_sec_file',_POST["max_sec_file"])
local max_files = ternary(not isEmptyString(_POST["max_files"]), _POST["max_files"], 500)
max_files = tonumber(max_files) * 1e6
ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_max_files', tostring(max_files))
interface.loadDumpPrefs()
end
end
ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/header.inc")
print("")
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
print(msg)
url = ntop.getHttpPrefix()..'/lua/if_stats.lua?ifid=' .. ifid
-- Added global javascript variable, in order to disable the refresh of pie chart in case
-- of historical interface
print('\n\n')
print [[
]]
if((page == "overview") or (page == nil)) then
print("
\n")
print("
"..i18n("if_stats_overview.id").."
" .. ifstats.id .. " ")
if(ifstats.description ~= ifstats.name) then print(" ("..ifstats.description..")") end
print("
\n")
if interface.isPcapDumpInterface() == false and ifstats["type"] ~= "netfilter" then
print("
"..i18n("if_stats_overview.state").."
")
state = toggleTableButton("", "", i18n("if_stats_overview.active"), "1","primary", i18n("if_stats_overview.paused"), "0","primary", "toggle_local", "ntopng.prefs."..if_name.."_not_idle")
if(state == "0") then
on_state = true
else
on_state = false
end
interface.setInterfaceIdleState(on_state)
print("
\n")
end
if(ifstats["remote.name"] ~= nil) then
local remote_if_addr, remote_probe_ip, remote_probe_public_ip = '', '', ''
local num_remote_flow_exports, num_remote_flow_exporters = '', ''
if not isEmptyString(ifstats["remote.if_addr"]) then
remote_if_addr = ""..i18n("if_stats_overview.interface_ip")..": "..ifstats["remote.if_addr"]
end
if not isEmptyString(ifstats["probe.ip"]) then
remote_probe_ip = ""..i18n("if_stats_overview.probe_ip")..": "..ifstats["probe.ip"]
end
if not isEmptyString(ifstats["probe.public_ip"]) then
remote_probe_public_ip = ""..i18n("if_stats_overview.public_probe_ip")..": "..ifstats["probe.public_ip"].." \n"
end
if not isEmptyString(ifstats["zmq.num_flow_exports"]) then
num_remote_flow_exports = ""..i18n("if_stats_overview.probe_zmq_num_flow_exports")..": "..formatValue(ifstats["zmq.num_flow_exports"])..""
end
if not isEmptyString(ifstats["zmq.num_exporters"]) then
num_remote_flow_exporters = ""..i18n("if_stats_overview.probe_zmq_num_endpoints")..": "..formatValue(ifstats["zmq.num_exporters"])..""
end
print("
")
end
local is_physical_iface = (interface.isPacketInterface()) and (interface.isPcapDumpInterface() == false)
local is_bridge_iface = (ifstats["bridge.device_a"] ~= nil) and (ifstats["bridge.device_b"] ~= nil)
if not is_bridge_iface then
local label = getHumanReadableInterfaceName(ifstats.name)
local s
if ((not isEmptyString(label)) and (label ~= ifstats.name)) then
s = label.." (" .. ifstats.name .. ")"
else
s = ifstats.name
end
if((isAdministrator()) and (interface.isPcapDumpInterface() == false)) then
s = s .. " "
end
print('
'..i18n("name")..'
' .. s ..'
\n')
else
print("
"..i18n("bridge").."
"..ifstats["bridge.device_a"].." "..ifstats["bridge.device_b"])
if(user_group == "administrator") and isBridgeInterface(ifstats) and ntop.isEnterprise() and not have_nedge then
print[[ ]]
show_bridge_wizard = true
end
print("
")
end
print("
"..i18n("if_stats_overview.family").."
")
print(ifstats.type)
if(ifstats.inline) then
print(" "..i18n("if_stats_overview.in_path_interface"))
end
if(ifstats.has_traffic_directions) then
print(" ".. i18n("if_stats_overview.has_traffic_directions") .. " ")
end
print("
")
if not is_bridge_iface then
if(ifstats.ip_addresses ~= "") then
tokens = split(ifstats.ip_addresses, ",")
end
if(tokens ~= nil) then
print("
"..i18n("ip_address").."
")
local addresses = {}
for _,s in pairs(tokens) do
t = string.split(s, "/")
host = interface.getHostInfo(t[1])
if(host ~= nil) then
addresses[#addresses+1] = "".. t[1]..""
else
addresses[#addresses+1] = t[1]
end
end
print(table.concat(addresses, ", "))
print("
")
end
end
if is_physical_iface then
print("
")
print("
"..i18n("mtu").."
"..ifstats.mtu.." "..i18n("bytes").."
\n")
if (not is_bridge_iface) then
local speed_key = 'ntopng.prefs.'..ifname..'.speed'
local speed = ntop.getCache(speed_key)
if (tonumber(speed) == nil) then
speed = ifstats.speed
end
print("
"..i18n("speed").."
" .. maxRateToString(speed*1000) .. "
")
else
print("
")
end
print("")
end
if(ifstats["pkt_dumper"] ~= nil) then
print("
")
if(ifstats.stats.drops > 0) then
print('')
end
print(formatValue(ifstats.stats.drops).. " " .. label)
if((ifstats.stats.packets+ifstats.stats.drops) > 0) then
local pctg = round((ifstats.stats.drops*100)/(ifstats.stats.packets+ifstats.stats.drops), 2)
if(pctg > 0) then print(" [ " .. pctg .. " % ] ") end
end
if(ifstats.stats.drops > 0) then print('') end
print(" ")
if(ifstats.zmqRecvStats ~= nil) then
print("
"..i18n("if_stats_overview.note")..": ".. i18n("if_stats_overview.note_drops_sflow").."")
end
print("
")
if(prefs.is_dump_flows_enabled and ifstats.isView == false) then
local dump_to = "MySQL"
if prefs.is_dump_flows_to_es_enabled == true then
dump_to = "ElasticSearch"
end
if prefs.is_dump_flows_to_ls_enabled == true then
dump_to = "Logstash"
end
local export_count = ifstats.stats.flow_export_count
local export_rate = ifstats.stats.flow_export_rate
local export_drops = ifstats.stats.flow_export_drops
local export_drops_pct = 0
if export_drops == nill then
elseif export_drops > 0 and export_count > 0 then
export_drops_pct = export_drops / export_count * 100
elseif export_drops > 0 then
export_drops_pct = 100
end
print("
")
end
if (isAdministrator() and ifstats.isView == false and ifstats.isDynamic == false) then
print("
"..i18n("download").."
")
local live_traffic_utils = require("live_traffic_utils")
live_traffic_utils.printLiveTrafficForm(ifId)
print("
\n")
print("
"..i18n("if_stats_overview.reset_counters").."
")
print("
")
local tot = ifstats.stats.bytes + ifstats.stats.packets + ifstats.stats.drops
if(ifstats.stats.flow_export_count ~= nil) then
tot = tot + ifstats.stats.flow_export_count + ifstats.stats.flow_export_drops
end
print(' ')
print('')
print("
")
print("
\n")
end
if have_nedge and ifstats.type == "netfilter" and ifstats.netfilter then
local st = ifstats.netfilter
print("
"..i18n("if_stats_overview.nf_queue_total").."
")
local span_class = ''
if st.nfq.queue_pct > 80 then
span_class = "class='label label-danger'"
end
print("
\n")
if show_bridge_wizard then
dofile(dirs.installdir .. "/scripts/lua/inc/bridge_wizard.lua")
end
elseif((page == "packets")) then
local nedge_hidden = ternary(have_nedge, 'class="hidden"', '')
print [[
\n")
for pname,pbytes in pairs(ifstats.profiles) do
local trimmed = trimSpace(pname)
local statschart_icon = ''
if ts_utils.exists("profile:traffic", {ifid=ifid}) then
statschart_icon = ''
end
print("
"..pname.."
"..statschart_icon.."
"..bytesToSize(pbytes).."
\n")
end
print [[
]]
elseif(page == "packetdump") then
if is_packetdump_enabled then
local dump_all_traffic = ntop.getCache('ntopng.prefs.'..ifstats.name..'.dump_all_traffic')
local dump_unknown_traffic = ntop.getCache('ntopng.prefs.'..ifstats.name..'.dump_unknown_traffic')
local dump_status_tap = ntop.getCache('ntopng.prefs.'..ifstats.name..'.dump_tap')
local dump_status_disk = ntop.getCache('ntopng.prefs.'..ifstats.name..'.dump_disk')
if(dump_all_traffic == "true") then
dump_all_traffic_checked = 'checked="checked"'
dump_all_traffic_value = "false" -- Opposite
else
dump_all_traffic_checked = ""
dump_all_traffic_value = "true" -- Opposite
end
if(dump_status_disk == "true") then
dump_traffic_checked = 'checked="checked"'
dump_traffic_value = "false" -- Opposite
else
dump_traffic_checked = ""
dump_traffic_value = "true" -- Opposite
end
if(dump_unknown_traffic == "true") then
dump_unknown_checked = 'checked="checked"'
dump_unknown_value = "false" -- Opposite
else
dump_unknown_checked = ""
dump_unknown_value = "true" -- Opposite
end
if(dump_status_tap == "true") then
dump_traffic_tap_checked = 'checked="checked"'
dump_traffic_tap_value = "false" -- Opposite
else
dump_traffic_tap_checked = ""
dump_traffic_tap_value = "true" -- Opposite
end
print("")
print[[]]
end
elseif(page == "alerts") then
drawAlertSourceSettings("interface", ifname_clean,
i18n("show_alerts.iface_delete_config_btn", {iface=if_name}), "show_alerts.iface_delete_config_confirm",
"if_stats.lua", {ifid=ifid},
if_name)
elseif(page == "config") then
if(not isAdministrator()) then
return
end
print[[
]]
elseif(page == "snmp_bind") then
if ((not hasSnmpDevices(ifstats.id)) or (not is_packet_interface)) then
return
end
local snmp_host = _POST["ip"]
local snmp_interface = _POST["snmp_port_idx"] or ""
if (snmp_host ~= nil) then
-- snmp_host can be empty
set_snmp_bound_interface(ifstats.id, snmp_host, snmp_interface)
else
local value = get_snmp_bound_interface(ifstats.id)
if value ~= nil then
snmp_host = value.snmp_device
snmp_interface = value.snmp_port
end
end
local snmp_devices = get_snmp_devices(ifstats.id)
print[[
]] print(i18n("snmp.note") .. ":") print[[
]] print(i18n("snmp.bound_interface_description")) print[[
]]
elseif(page == "pools") then
if ifstats.isView then
error()
end
dofile(dirs.installdir .. "/scripts/lua/admin/host_pools.lua")
elseif page == "traffic_report" then
dofile(dirs.installdir .. "/pro/scripts/lua/enterprise/traffic_report.lua")
end
print("
]]
print [[
]]
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")