--
-- (C) 2013-16 - ntop.org
--
dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
if((dirs.scriptdir ~= nil) and (dirs.scriptdir ~= "")) then package.path = dirs.scriptdir .. "/lua/modules/?.lua;" .. package.path end
if ntop.isPro() then
package.path = dirs.installdir .. "/scripts/lua/pro/modules/?.lua;" .. package.path
package.path = dirs.installdir .. "/pro/scripts/callbacks/?.lua;" .. package.path
require "common"
local json = require "dkjson"
end
require "lua_utils"
require "prefs_utils"
require "graph_utils"
require "alert_utils"
require "db_utils"
sendHTTPHeader('text/html; charset=iso-8859-1')
page = _GET["page"]
if_name = _GET["if_name"]
ifid = (_GET["id"] or _GET["ifId"])
msg = ""
function inline_input_form(name, placeholder, tooltip, value, can_edit, input_opts, input_clss)
print [[
\n")
print("| Id | " .. ifstats.id .. " ")
print(" |
\n")
if interface.isPcapDumpInterface() == false then
print("| State | ")
state = toggleTableButton("", "", "Active", "1","primary", "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
print("| Remote Probe | Interface Name: "..ifstats["remote.name"].." [ ".. maxRateToString(ifstats.speed*1000) .." ] | ")
if(ifstats["remote.if_addr"] ~= "") then print("Interface IP: "..ifstats["remote.if_addr"].." | ") end
if(ifstats["probe.ip"] ~= "") then print("Probe IP: "..ifstats["probe.ip"].." | | ") end
if(ifstats["probe.public_ip"] ~= "") then
print("Public Probe IP: "..ifstats["probe.public_ip"].." | \n")
else
print(" | \n")
end
print("
\n")
end
local is_physical_iface = (interface.isPacketInterface()) and (interface.isPcapDumpInterface() == false)
if not interface.isBridgeInterface() then
print('| Name | ' .. ifstats.name..' | \n')
if is_physical_iface then
if(ifstats.name ~= nil) then
print('Custom Name | ')
label = getInterfaceNameAlias(ifstats.name)
inline_input_form("custom_name", "Custom Name",
"Specify an alias for the interface",
label, isAdministrator(), 'autocorrect="off" spellcheck="false" pattern="^[_\\-a-zA-Z0-9]*$"')
print(" |
\n")
end
local speed_key = 'ntopng.prefs.'..ifname..'.speed'
local speed = ntop.getCache(speed_key)
if speed == nil or speed == "" or tonumber(speed) == nil then
speed = ifstats.speed
end
print("| Speed | " .. maxRateToString(speed*1000) .. " | ")
if interface.isPacketInterface() then
print("Scaling Factor | ")
local label = ntop.getCache(getRedisIfacePrefix(ifid)..".scaling_factor")
if((label == nil) or (label == "")) then label = "1" end
inline_input_form("scaling_factor", "Scaling Factor",
"This should match your capture interface sampling rate",
label, isAdministrator(), 'type="number" min="1" step="1"', 'no-spinner')
end
print(" |
\n")
else
print(" | ")
end
else
print("| Bridge | "..ifstats["bridge.device_a"].." "..ifstats["bridge.device_b"].." |
")
end
if(ifstats.ip_addresses ~= "") then
tokens = split(ifstats.ip_addresses, ",")
if(tokens ~= nil) then
print("| IP Address | ")
for _,s in pairs(tokens) do
t = string.split(s, "/")
host = interface.getHostInfo(t[1])
if(host ~= nil) then
print("".. t[1].."\n")
else
print("".. t[1].."\n")
end
end
print(" |
")
end
end
print("| Family | ")
print(ifstats.type)
if(ifstats.inline) then
print(" In-Path Interface (Bump in the Wire)")
end
if is_physical_iface then
print(" | MTU | "..ifstats.mtu.." bytes |
\n")
else
print(" | ")
end
if(ifstats["pkt_dumper"] ~= nil) then
print("| Packet Dumper | Dumped Packets | Dumped Files |
\n")
print("".. formatValue(ifstats["pkt_dumper"]["num_dumped_pkts"]) .." | ")
print("".. formatValue(ifstats["pkt_dumper"]["num_dumped_files"]) .." |
\n")
end
label = "Pkts"
print[[ | Traffic Breakdown | ]]
if(ifstats.type ~= "zmq") then
print [[ | |
]]
else
print [[ | ]]
end
print [[
\n")
if(ifstats.zmqRecvStats ~= nil) then
print("| ZMQ RX Statistics |
\n")
print("| Collected Flows | "..formatValue(ifstats.zmqRecvStats.flows).."")
print(" | Interface RX Updates | "..formatValue(ifstats.zmqRecvStats.events).."")
print(" | sFlow Counter Updates | "..formatValue(ifstats.zmqRecvStats.counters).." |
")
end
print("| Ingress Traffic |
\n")
print("| Received Traffic | "..bytesToSize(ifstats.stats.bytes).." [".. formatValue(ifstats.stats.packets) .. " ".. label .."] ")
print(" | Dropped Packets | ")
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(" | |
\n")
if(prefs.is_dump_flows_enabled) then
local dump_to = "MySQL"
if prefs.is_dump_flows_to_es_enabled == true then
dump_to = "ElasticSearch"
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 > 0 and export_count > 0 then
export_drops_pct = export_drops / export_count * 100
end
print("| "..dump_to.." Flows Export Statistics |
\n")
print("")
print("| Exported Flows | ")
print(""..formatValue(export_count).."")
print(" ["..formatValue(round(export_rate, 2)).." Flows/s] | ")
print("Dropped Flows | ")
local span_danger = ""
if(export_drops > 0) then
span_danger = ' class="label label-danger"'
end
print(""..formatValue(export_drops).." ")
print("["
..formatValue(round(export_drops_pct, 2)).."%] | ")
print(" | ")
print("
")
end
if(interface.isBridgeInterface()) then
print("| Bridged Traffic |
\n")
print("| Interface Direction | Ingress Packets | Egress Packets | Shaped Packets | Filtered Packets | Send Error | Buffer Full |
\n")
print("| ".. ifstats["bridge.device_a"] .. " ".. ifstats["bridge.device_b"] .." | ".. formatPackets(ifstats["bridge.a_to_b.in_pkts"]) .." | ")
print("".. formatPackets(ifstats["bridge.a_to_b.out_pkts"]) .." | ")
print("".. formatPackets(ifstats["bridge.a_to_b.shaped_pkts"]) .." | ")
print("".. formatPackets(ifstats["bridge.a_to_b.filtered_pkts"]) .." | ")
print("".. formatPackets(ifstats["bridge.a_to_b.num_pkts_send_error"]) .." | ")
print("".. formatPackets(ifstats["bridge.a_to_b.num_pkts_send_buffer_full"]) .." | ")
print("
\n")
print("| ".. ifstats["bridge.device_b"] .. " ".. ifstats["bridge.device_a"] .." | ".. formatPackets(ifstats["bridge.b_to_a.in_pkts"]) .." | ")
print(""..formatPackets( ifstats["bridge.b_to_a.out_pkts"]) .." | ")
print("".. formatPackets(ifstats["bridge.b_to_a.shaped_pkts"]) .." | ")
print("".. formatPackets(ifstats["bridge.b_to_a.filtered_pkts"]) .." | ")
print("".. formatPackets(ifstats["bridge.b_to_a.num_pkts_send_error"]) .." | ")
print("".. formatPackets(ifstats["bridge.b_to_a.num_pkts_send_buffer_full"]) .." | ")
print("
\n")
end
print [[
| NOTE: In ethernet networks, each packet has an overhead of 24 bytes [preamble (7 bytes), start of frame (1 byte), CRC (4 bytes), and IFG (12 bytes)]. Such overhead needs to be accounted to the interface traffic, but it is not added to the traffic being exchanged between IP addresses. This is because such data contributes to interface load, but it cannot be accounted in the traffic being exchanged by hosts, and thus expect little discrepancies between host and interface traffic values. |
]]
print("
\n")
elseif((page == "packets")) then
print [[
]]
elseif(page == "ndpi") then
--fc = interface.getnDPIFlowsCount()
--for k,v in pairs(fc) do
-- io.write(k.."="..v.."\n")
--end
print [[
\n")
print("| Packet Dump | ")
print [[
')
print(" |
\n")
print("| Packet Dump To Disk | ")
print [[
')
print(" |
\n")
print(" | ")
print [[
')
print(" |
\n")
print(" | ")
print [[
')
print(" |
\n")
print("| Packet Dump To Tap | ")
if(interface.getInterfaceDumpTapName() ~= "") then
print [[
')
else
print("Disabled. Please restart ntopng with --enable-taps")
end
print(" |
\n")
print("| Sampling Rate | \n")
print [[]]
if(dump_security_checked ~= "") then
print[[
NOTE: Sampling rate is applied only when dumping packets caused by a security alert
(e.g. a volumetric DDoS attack) and not to those hosts/flows that have been marked explicitly for dump.
]]
else
print('Disabled. Enable packet dump on security alert.')
end
print[[
|
]]
print("| Dump To Disk Parameters |
")
print("| Pcap Dump Directory | ")
pcapdir = dirs.workingdir .."/"..ifstats.id.."/pcap/"
print(pcapdir.." |
\n")
print("| Max Packets per File | \n")
print [[
Maximum number of packets to store on a pcap file before creating a new file.
|
]]
print("| Max Duration of File | \n")
print [[
Maximum pcap file duration before creating a new file. NOTE: a dump file is closed when it reaches first the maximum size or duration specified.
|
]]
print("| Max Size of Dump Files | \n")
print [[
Maximum size of created pcap files. NOTE: total file size is checked daily and old dump files are automatically overwritten after reaching the threshold.
|
]]
print("
")
end
elseif(page == "alerts") then
local ifname_clean = "iface_"..tostring(ifid)
local tab = _GET["tab"]
local re_arm_minutes = nil
if(tab == nil) then tab = alerts_granularity[1][1] end
print [[ ]]
-- ==== Manage policies tab ====
print [[
]]
-- ==== Create policies tab ====
print[[
]]
-- ==== Manage shapers tab ====
print[[
]]
shaper_id = _GET["shaper_id"]
max_rate = _GET["max_rate"]
if((_GET["csrf"] ~= nil) and (shaper_id ~= nil) and (max_rate ~= nil)) then
shaper_id = tonumber(shaper_id)
max_rate = tonumber(max_rate)
if((shaper_id >= 0) and (shaper_id < max_num_shapers)) then
if(max_rate > 1048576) then max_rate = -1 end
if(max_rate < -1) then max_rate = -1 end
ntop.setHashCache(shaper_key, shaper_id, max_rate.."")
interface.reloadShapers()
jsRedirect("if_stats.lua?id="..ifid.."&page=filtering#shapers")
end
end
print [[
| Shaper Id | Max Rate |
]]
for i=0,max_num_shapers-1 do
max_rate = ntop.getHashCache(shaper_key, i)
if(max_rate == "") then max_rate = -1 end
print('| '..i)
print [[
| |
')
end
print [[
NOTES
- Shaper 0 is the default shaper used for local hosts that have no shaper defined.
- Set max rate to:
- -1 for no shaping
- 0 for dropping all traffic
]]
elseif page == "traffic_report" then
dofile(dirs.installdir .. "/pro/scripts/lua/enterprise/traffic_report.lua")
end
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")
print("
]]
print [[
]]