-- -- (C) 2013-15 - 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 require "lua_utils" require "graph_utils" require "alert_utils" sendHTTPHeader('text/html; charset=iso-8859-1') page = _GET["page"] if_name = _GET["if_name"] if(if_name == nil) then if_name = ifname end max_num_shapers = 10 interface.select(if_name) ifid = interface.name2id(ifname) shaper_key = "ntopng.prefs."..ifid..".shaper_max_rate" is_historical = interface.isHistoricalInterface(ifid) ifstats = interface.getStats() if(_GET["custom_name"] ~=nil) then if(_GET["csrf"] ~= nil) then ntop.setCache('ntopng.prefs.'..ifstats.name..'.name',_GET["custom_name"]) end end if(_GET["dump_all_traffic"] ~= nil and _GET["csrf"] ~= nil) then page = "packetdump" ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_all_traffic',_GET["dump_all_traffic"]) interface.loadDumpPrefs() end if(_GET["dump_traffic_to_tap"] ~= nil and _GET["csrf"] ~= nil) then page = "packetdump" ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_tap',_GET["dump_traffic_to_tap"]) interface.loadDumpPrefs() end if(_GET["dump_traffic_to_disk"] ~= nil and _GET["csrf"] ~= nil) then page = "packetdump" ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_disk',_GET["dump_traffic_to_disk"]) interface.loadDumpPrefs() end if(_GET["dump_unknown_to_disk"] ~= nil and _GET["csrf"] ~= nil) then page = "packetdump" ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_unknown_disk',_GET["dump_unknown_to_disk"]) interface.loadDumpPrefs() end if(_GET["dump_security_to_disk"] ~= nil and _GET["csrf"] ~= nil) then page = "packetdump" ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_security_disk',_GET["dump_security_to_disk"]) interface.loadDumpPrefs() end if(_GET["sampling_rate"] ~= nil and _GET["csrf"] ~= nil) then if (tonumber(_GET["sampling_rate"]) ~= nil) then page = "packetdump" val = ternary(_GET["sampling_rate"] ~= "0", _GET["sampling_rate"], "1") ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_sampling_rate', val) interface.loadDumpPrefs() end end if(_GET["max_pkts_file"] ~= nil and _GET["csrf"] ~= nil) then if (tonumber(_GET["max_pkts_file"]) ~= nil) then page = "packetdump" ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_max_pkts_file',_GET["max_pkts_file"]) interface.loadDumpPrefs() end end if(_GET["max_sec_file"] ~= nil and _GET["csrf"] ~= nil) then if (tonumber(_GET["max_sec_file"]) ~= nil) then page = "packetdump" ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_max_sec_file',_GET["max_sec_file"]) interface.loadDumpPrefs() end end if(_GET["max_files"] ~= nil and _GET["csrf"] ~= nil) then if (tonumber(_GET["max_files"]) ~= nil) then page = "packetdump" local max_files_size = tonumber(_GET["max_files"]) max_files_size = max_files_size * 1000000 ntop.setCache('ntopng.prefs.'..ifstats.name..'.dump_max_files', tostring(max_files_size)) interface.loadDumpPrefs() end end ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/header.inc") print("") active_page = "if_stats" dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua") rrdname = fixPath(dirs.workingdir .. "/" .. ifstats.id .. "/rrd/bytes.rrd") if(if_name == nil) then _ifname = ifname else _ifname = if_name end url= ntop.getHttpPrefix()..'/lua/if_stats.lua?if_name=' .. _ifname -- Added global javascript variable, in order to disable the refresh of pie chart in case -- of historical interface if not is_historical then print('\n\n') else print('\n\n') end print [[ ]] if((page == "overview") or (page == nil)) then print("\n") print("\n") if not (is_historical) then print("\n") end print("\n") if(ifstats.name ~= nil) then label = ntop.getCache('ntopng.prefs.'..ifstats.name..'.name') if(isAdministrator()) then print(" ]] else print("") end end if(ifstats.name ~= ifstats.description) then print("\n") end print("\n") if(ifstats["pkt_dumper"] ~= nil) then print("\n") print("") print("\n") end label = "Pkts" print[[ \n") print("\n") print("\n") if(ifstats["bridge.device_a"] ~= nil) then print("\n") print("\n") print("") print("\n") print("") print("\n") end print [[ ]] print("
Id" .. ifstats.id .. " ") 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("
Name" .. ifstats.name .. "") else print("") end print [[
]] if(isAdministrator()) then print('\n') print [[  
Description" .. ifstats.description .. "
Family " .. ifstats.type) if(ifstats.iface_inline) then print(" In-Path Interface (Bump in the Wire)") elseif(ifstats.iface_view) then print(" (Aggregated Interface View)") end print("
Packet DumperDumped PacketsDumped Files
".. formatValue(ifstats["pkt_dumper"]["num_dumped_pkts"]) .."
".. formatValue(ifstats["pkt_dumper"]["num_dumped_files"]) .."
Traffic Breakdown
Ingress Traffic
Received Traffic"..bytesToSize(ifstats.stats_bytes).." [".. formatValue(ifstats.stats_packets) .. " ".. label .."] 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("
Bridged Traffic
Interface DirectionIngress PacketsEgress PacketsFiltered Packets
".. ifstats["bridge.device_a"] .. " -> ".. ifstats["bridge.device_b"] .."".. formatPackets(ifstats["bridge.a_to_b.in_pkts"]) .."".. formatPackets(ifstats["bridge.a_to_b.out_pkts"]) .."".. formatPackets(ifstats["bridge.a_to_b.filtered_pkts"]) .."
".. ifstats["bridge.device_b"] .. " -> ".. ifstats["bridge.device_a"] .."".. formatPackets(ifstats["bridge.b_to_a.in_pkts"]) ..""..formatPackets( ifstats["bridge.b_to_a.out_pkts"]) .."".. formatPackets(ifstats["bridge.b_to_a.filtered_pkts"]) .."
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.

\n") elseif((page == "packets")) then print [[
Size Distribution

]] elseif(page == "ndpi") then --fc = interface.getNdpiFlowsCount() --for k,v in pairs(fc) do -- io.write(k.."="..v.."\n") --end print [[

Protocol Overview
Live Flows Count
]] print [[ ]] print("\n") print ('\n') print ("") print("
Application ProtocolTotal (Since Startup)Percentage
\n") print [[ ]] elseif(page == "historical") then rrd_file = _GET["rrd_file"] selected_epoch = _GET["epoch"] if(selected_epoch == nil) then selected_epoch = "" end topArray = makeTopStatsScriptsArray() if(rrd_file == nil) then rrd_file = "bytes.rrd" end drawRRD(ifstats.id, nil, rrd_file, _GET["graph_zoom"], url.."&page=historical", 1, _GET["epoch"], selected_epoch, topArray) elseif (page == "packetdump" and not is_historical) then if (isAdministrator()) then dump_all_traffic = ntop.getCache('ntopng.prefs.'..ifstats.name..'.dump_all_traffic') dump_status_tap = ntop.getCache('ntopng.prefs.'..ifstats.name..'.dump_tap') dump_status_disk = ntop.getCache('ntopng.prefs.'..ifstats.name..'.dump_disk') dump_unknown_disk = ntop.getCache('ntopng.prefs.'..ifstats.name..'.dump_unknown_disk') dump_security_disk = ntop.getCache('ntopng.prefs.'..ifstats.name..'.dump_security_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_disk == "true") then dump_unknown_checked = 'checked="checked"' dump_unknown_value = "false" -- Opposite else dump_unknown_checked = "" dump_unknown_value = "true" -- Opposite end if(dump_security_disk == "true") then dump_security_checked = 'checked="checked"' dump_security_value = "false" -- Opposite else dump_security_checked = "" dump_security_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("\n") print("\n") print("\n") print("\n") print("\n") print("\n") print("\n") print [[ ]] print("") print("\n") print [[ ]] print("\n") print [[ ]] print("\n") print [[ ]] print("
Packet Dump") print [[
Dump All Traffic') print('') print('\n') print('
') print("
Packet Dump To Disk") print [[
Dump Traffic To Disk') if (dump_traffic_checked ~= "") then dumped = interface.getInterfacePacketsDumpedFile() print(" - "..ternary(dumped, dumped, 0).." packets dumped") end print('') print('\n') print('
') print("
") print [[
Dump Unknown Traffic To Disk ') print('\n') print('
') print("
") print [[
Dump Traffic To Disk On Security Alert ') print('\n') print('
') print("
Packet Dump To Tap") if(interface.getInterfaceDumpTapName() ~= "") then print [[
Dump Traffic To Tap ') print('('..interface.getInterfaceDumpTapName()..')') if (dump_traffic_tap_checked ~= "") then dumped = interface.getInterfacePacketsDumpedTap() print(" - "..ternary(dumped, dumped, 0).." packets dumped") end print(' ') print('\n') print('
') else print("Disabled. Please restart ntopng with --enable-taps") end print("
Sampling Rate]] if (dump_security_checked ~= "") then print[[
]] print('1 : \n') 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[[
Dump To Disk Parameters
Max Packets per File
]] print('\n') print [[ pkts  
Maximum number of packets to store on a pcap file before creating a new file.
Max Duration of File
]] print('\n') print [[  sec  
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.
Max Size of Dump Files
]] print('\n') print [[   MB    
Maximum size of created pcap files.
NOTE: total file size is checked daily and old dump files are automatically overwritten after reaching the threshold.
") end elseif(page == "alerts") then local if_name = ifstats.name local ifname_clean = string.gsub(ifname, "/", "_") local tab = _GET["tab"] if(tab == nil) then tab = alerts_granularity[1][1] end print [[

]] print('\n') print("\n") print("\n") for k,v in pairsByKeys(alert_functions_description, asc) do print("\n") end print [[
Alert FunctionThreshold
"..k.."\n") print("\n") print("\n\n") print("
"..v.."\n") print("
[ Delete All Interface Configured Alerts ]
]] end elseif (page == "config") then local if_name = ifstats.name local ifname_clean = string.gsub(ifname, "/", "_") if(isAdministrator()) then trigger_alerts = _GET["trigger_alerts"] if(trigger_alerts ~= nil) then if(trigger_alerts == "true") then ntop.delHashCache("ntopng.prefs.alerts", "iface_"..ifname_clean) else ntop.setHashCache("ntopng.prefs.alerts", "iface_"..ifname_clean, trigger_alerts) end end end print("\n") suppressAlerts = ntop.getHashCache("ntopng.prefs.alerts", ifname_clean) if((suppressAlerts == "") or (suppressAlerts == nil) or (suppressAlerts == "true")) then alerts_checked = 'checked="checked"' alerts_value = "false" -- Opposite else alerts_checked = "" alerts_value = "true" -- Opposite end print [[ ') print [[]] print("
Interface Alerts
Trigger alerts for interface '..if_name..'') print('\n') print('') print('
') print('
") elseif(page == "config_historical") then -- -- Historical Interface configuration page -- historical_info = interface.getHistorical() print ('
') print('
') print('\n') print[[ ]] print("\n") print("\n") print("\n") print("\n") print [[
Begin Date/Time") print [[
Specify the date and time from which to begin loading data. ]] print("
End Date/Time") print [[
Specify the end of the loading interval. ]] print("
Source Interface") print [[
]] names = interface.getIfNames() current_name = historical_info["interface_name"] if(current_name ~= nil) then v = interface.name2id(current_name) key = 'ntopng.prefs.'..current_name..'.name' custom_name = ntop.getCache(key) if((custom_name ~= nil) and (custom_name ~= "")) then current_name = custom_name else current_name = getHumanReadableInterfaceName(tostring(v)) end else v = "" end if(current_name == nil) then for k,v in pairs(names) do if(v ~= "Historical") then current_name = v break end end end print('\n') print('
Specify the interface from which to load the data (previously saved into your data directory). ]] print("
]] print [[
]] print('\n') print [[
]] actual_time =os.time() mod = actual_time%300 actual_time = actual_time - mod print [[ ]] elseif(page == "shaping") then shaper_id = _GET["shaper_id"] max_rate = _GET["max_rate"] if((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() end end print [[ ]] for i=0,max_num_shapers-1 do max_rate = ntop.getHashCache(shaper_key, i) if(max_rate == "") then max_rate = -1 end print('') else print("") end end print [[
Shaper IdMax Rate
'..i) print [[
]] if(isAdministrator()) then print('\n') print(' Kbps') print(' 
NOTES ]] elseif(page == "filtering") then policy_key = "ntopng.prefs.".. ifid ..".l7_policy" -- ==================================== if((_GET["new_vlan"] ~= nil) and (_GET["new_network"] ~= nil)) then network_key = _GET["new_network"].."@".._GET["new_vlan"] ntop.setHashCache(policy_key, network_key, "") end if(_GET["delete_network"] ~= nil) then ntop.delHashCache(policy_key, _GET["delete_network"]) end net = _GET["network"] if(net ~= nil) then if(findString(net, "@") == nil) then net = net.."@0" end if(ntop.getHashCache(policy_key, net) == "") then ntop.setHashCache(policy_key, net, "") end end -- io.write(net.."\n") if((net ~= nil) and (_GET["blacklist"] ~= nil)) then ntop.setHashCache(policy_key, net, _GET["blacklist"]) -- ****************************** ingress_shaper_id = _GET["ingress_shaper_id"] if(ingress_shaper_id == nil) then ingress_shaper_id = 0 end key = "ntopng.prefs.".. ifid ..".l7_policy_ingress_shaper_id" ntop.setHashCache(key, net, ingress_shaper_id) -- ****************************** egress_shaper_id = _GET["egress_shaper_id"] if(egress_shaper_id == nil) then egress_shaper_id = 0 end key = "ntopng.prefs.".. ifid ..".l7_policy_egress_shaper_id" ntop.setHashCache(key, net, egress_shaper_id) -- ****************************** interface.reloadL7Rules() end any_net = "0.0.0.0/0@0" nets = ntop.getHashKeysCache(key) if((nets == nil) or (nets == "")) then ntop.setHashCache(policy_key, any_net, "") nets = ntop.getHashKeysCache(policy_key) end selected_network = net if(selected_network == nil) then selected_network = any_net end print [[
') -- ****************************************** print [[ ]] -- ****************************************** print [[ ]] -- ****************************************** print [[
Manage Traffic Filtering Policies
Network: ]] if((selected_found == true) and (string.contains(selected_network, "/32") or string.contains(selected_network, "/128"))) then nw = string.gsub(selected_network, "/32", ""); nw = string.gsub(nw, "/128", ""); print(" [ Show Host ] ") end print(' [ Delete '.. selected_network ..' ]') print('
Ingress Shaper Id
 
Specify the max ingress transmission bandwidth to be associated to this network/host.
Egress Shaper Id
 
Specify the max egress transmission bandwidth to be associated to this network/host.
 
Add VLAN/Network To Filter
Network VLAN
]] end dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua") print(" ]] print [[ ]]