-- -- (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 "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"] 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" ifstats = aggregateInterfaceStats(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 print('\n\n') print [[ ]] if((page == "overview") or (page == nil)) then print("\n") print("\n") print("\n") print("\n") if(ifstats.name ~= nil) then label = getInterfaceNameAlias(ifstats.name) if(not isAdministrator()) then print(" ]] else print("") end end print("\n") if(ifstats.ip_addresses ~= "") then tokens = split(ifstats.ip_addresses, ",") if(tokens ~= nil) then print("") end 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("") print("") print("") print("") print("") print("\n") print("") print("") print("") print("") print("") 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 [[  
Speed" .. maxRateToString(ifstats.speed*1000) .. "MTU"..ifstats.mtu.." bytes
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("
  • Family ") if(ifstats.isView == true) then print(" ") end print(ifstats.type) if(ifstats.inline) then print(" In-Path Interface (Bump in the Wire)") elseif(ifstats.isView == true) 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.bytes).." [".. formatValue(ifstats.packets) .. " ".. label .."] ") print("Dropped Packets") if(ifstats.drops > 0) then print('') end print(formatValue(ifstats.drops).. " " .. label) if((ifstats.packets+ifstats.drops) > 0) then local pctg = round((ifstats.drops*100)/(ifstats.packets+ifstats.drops), 2) if(pctg > 0) then print(" [ " .. pctg .. " % ] ") end end if(ifstats.drops > 0) then print('') end print("  
    Bridged Traffic
    Interface DirectionIngress PacketsEgress PacketsShaped PacketsFiltered PacketsSend ErrorBuffer Full
    ".. 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.shaped_pkts"]) .."".. formatPackets(ifstats["bridge.a_to_b.filtered_pkts"]) .."".. formatPackets(ifstats["bridge.a_to_b.num_pkts_send_error"]) .."".. formatPackets(ifstats["bridge.a_to_b.num_pkts_send_buffer_full"]) .."
    ".. 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.shaped_pkts"]) .."".. formatPackets(ifstats["bridge.b_to_a.filtered_pkts"]) .."".. formatPackets(ifstats["bridge.b_to_a.num_pkts_send_error"]) .."".. formatPackets(ifstats["bridge.b_to_a.num_pkts_send_buffer_full"]) .."
    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 == "trafficprofiles") then print("\n") print("\n") for pname,pbytes in pairs(ifstats.profiles) do local trimmed = trimSpace(pname) local rrdname = fixPath(dirs.workingdir .. "/" .. ifid .. "/profilestats/" .. getPathFromKey(trimmed) .. "/bytes.rrd") local statschart_icon = '' if ntop.exists(rrdname) then statschart_icon = '' end print("\n") end print [[
    Profile NameGraphTraffic
    "..pname..""..statschart_icon..""..bytesToSize(pbytes).."
    ]] elseif(page == "packetdump") then if(isAdministrator()) then interface.select(if_name) 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("\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
    Pcap Dump Directory") pcapdir = dirs.workingdir .."/"..ifstats.id.."/pcap/" print(pcapdir.."
    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"] local re_arm_minutes = nil 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("
    Re-arm minutes
    The re-arm is the dead time between one alert generation and the potential generation of the next alert of the same kind.
    [ 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 == "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 -- We need to check if this network is local or not 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"] any_net = "0.0.0.0/0@0" nets = ntop.getHashKeysCache(key, any_net) if((nets == nil) or (nets == "")) then nets = ntop.getHashKeysCache(policy_key) end if((net == nil) and (nets ~= nil)) then -- If there is not &network= parameter then use the first network available for k,v in pairsByKeys(nets, asc) do net = k break end end 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 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
    Local Network : VLAN
    ]] end dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua") print(" ]] print [[ ]]