-- -- (C) 2013-18 - 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 "snmp_utils" end local json = require "dkjson" local host_pools_utils = require "host_pools_utils" local template = require "template_utils" local os_utils = require "os_utils" require "lua_utils" require "prefs_utils" require "graph_utils" require "alert_utils" require "db_utils" require "rrd_utils" local have_nedge = ntop.isnEdge() if ntop.isPro() then shaper_utils = require("shaper_utils") end local show_bridge_wizard = false sendHTTPContentTypeHeader('text/html') page = _GET["page"] ifid = _GET["ifid"] ifname_clean = "iface_"..tostring(ifid) msg = "" function inline_input_form(name, placeholder, tooltip, value, can_edit, input_opts, input_class) if(can_edit) then print(']] else if(value ~= nil) then print(value) end end end if(_POST["switch_interface"] ~= nil) then -- First switch interfaces so the new cookie will have effect ifname = interface.setActiveInterfaceId(tonumber(ifid)) --print("@"..ifname.."="..id.."@") if((ifname ~= nil) and (_SESSION["session"] ~= nil)) then key = getRedisPrefix("ntopng.prefs") .. ".ifname" ntop.setCache(key, ifname) msg = "
" .. i18n("if_stats_overview.iface_switch_active_msg", {interface=getHumanReadableInterfaceName(ifname), ifid=ifid}) .. "
" ntop.setCache(getRedisPrefix("ntopng.prefs")..'.iface', ifid) else msg = "
" .. i18n("if_stats_overview.iface_switch_error_msg") .. "
" if(_SESSION["session"] == nil) then msg = msg .."
" .. i18n("if_stats_overview.iface_switch_empty_session_msg") .. "
" 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() 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("") if page == "filtering" then print('') end dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua") print(msg) rrdname = os_utils.fixPath(dirs.workingdir .. "/" .. ifstats.id .. "/rrd/bytes.rrd") 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("\n") if interface.isPcapDumpInterface() == false then 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("") print("") print("") print("\n") print("\n") print("") print("") print("") print("") 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('\n') else print("") end print("") if not is_bridge_iface then if(ifstats.ip_addresses ~= "") then tokens = split(ifstats.ip_addresses, ",") end if(tokens ~= nil) then print("") end end if is_physical_iface then print("") print("\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("") else print("") end print("") end if(ifstats["pkt_dumper"] ~= nil) then print("\n") print("") print("\n") end label = i18n("pkts") print[[ ]] if(ifstats.type ~= "zmq") then print [[ ]] else print [[ ]] end print [[ \n") if(ifstats.zmqRecvStats ~= nil) then print("\n") print("") print("") print("") print("") end print("\n") print("") if ifstats.isDynamic == false then print("") print("") else print("") 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("\n") print("") print("") print("") print("") local span_danger = "" if export_drops == nil then elseif(export_drops > 0) then span_danger = ' class="label label-danger"' end print("") print("") print("") end if (isAdministrator() and ifstats.isView == false and ifstats.isDynamic == false) then print("") print("") print("\n") end if((ifstats["bridge.device_a"] ~= nil) and (ifstats["bridge.device_b"] ~= nil)) then print("\n") print("\n") print("") print("") print("") print("") print("") print("\n") print("") print("") print("") print("") print("") print("\n") end print [[ ]] print("
"..i18n("if_stats_overview.id").."" .. ifstats.id .. " ") if(ifstats.description ~= ifstats.name) then print(" ("..ifstats.description..")") end 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("
"..i18n("if_stats_overview.remote_probe")..""..i18n("if_stats_overview.interface_name")..": "..ifstats["remote.name"].." [ ".. maxRateToString(ifstats.speed*1000) .." ]"..remote_if_addr..""..remote_probe_ip..""..remote_probe_public_ip.."
"..i18n("if_stats_overview.probe_timeout_lifetime")..": "..secondsToTime(ifstats["timeout.lifetime"])..""..i18n("if_stats_overview.probe_timeout_idle")..": "..secondsToTime(ifstats["timeout.idle"])..""..num_remote_flow_exporters.."
'..i18n("name")..'' .. s ..'
"..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(""..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("
"..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("
"..i18n("mtu")..""..ifstats.mtu.." "..i18n("bytes")..""..i18n("speed").."" .. maxRateToString(speed*1000) .. "
"..i18n("if_stats_overview.packet_dumper")..""..i18n("if_stats_overview.dumped_packets")..""..i18n("if_stats_overview.dumped_files").."
".. formatValue(ifstats["pkt_dumper"]["num_dumped_pkts"]) .."
".. formatValue(ifstats["pkt_dumper"]["num_dumped_files"]) .."
]] print(i18n("if_stats_overview.traffic_breakdown")) print[[
"..i18n("if_stats_overview.zmq_rx_statistics").."
"..i18n("if_stats_overview.collected_flows")..""..formatValue(ifstats.zmqRecvStats.flows)..""..i18n("if_stats_overview.interface_rx_updates")..""..formatValue(ifstats.zmqRecvStats.events)..""..i18n("if_stats_overview.sflow_counter_updates")..""..formatValue(ifstats.zmqRecvStats.counters).."
"..i18n("if_stats_overview.zmq_message_drops")..""..formatValue(ifstats.zmqRecvStats.zmq_msg_drops).."
"..i18n("if_stats_overview.ingress_traffic").."
"..i18n("if_stats_overview.received_traffic")..""..bytesToSize(ifstats.stats.bytes).." [".. formatValue(ifstats.stats.packets) .. " ".. label .."] ") print(" ") print(i18n("if_stats_overview.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(" ") if(ifstats.zmqRecvStats ~= nil) then print("

"..i18n("if_stats_overview.note")..":
".. i18n("if_stats_overview.note_drops_sflow").."
") end print("

") print(""..i18n("if_stats_overview.note")..": "..i18n("if_stats_overview.note_drop_ifstats_dynamic").."") print("
"..dump_to.." "..i18n("if_stats_overview.flows_export_statistics").."
"..i18n("if_stats_overview.exported_flows")..""..formatValue(export_count).."") if export_rate == nil then export_rate = 0 end print(" ["..formatValue(round(export_rate, 2)).." Flows/s] ") print(i18n("if_stats_overview.dropped_flows")..""..formatValue(export_drops).." ") print("[" ..formatValue(round(export_drops_pct, 2)).."%] 
"..i18n("if_stats_overview.reset_counters").."") 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("
"..i18n("if_stats_overview.bridged_traffic").."
"..i18n("interface")..""..i18n("if_stats_overview.ingress_packets")..""..i18n("if_stats_overview.egress_packets")..""..i18n("if_stats_overview.shaped_filtered_packets")..""..i18n("if_stats_overview.send_error")..""..i18n("if_stats_overview.buffer_full").."
".. ifstats["bridge.device_a"] .. "".. formatPackets(ifstats["bridge.a_to_b.in_pkts"]) .." ".. formatPackets(ifstats["bridge.a_to_b.out_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"] .. "".. formatPackets(ifstats["bridge.b_to_a.in_pkts"]) .." "..formatPackets( ifstats["bridge.b_to_a.out_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"]) .."
]] print(i18n("if_stats_overview.note")..":

"..i18n("if_stats_overview.note_packets")) 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 [[ ]] print("\n") print("\n") print("\n") if(ifstats.type ~= "zmq") then print [[]] end print[[
" .. i18n("packets_page.tcp_packets_analysis") .. "" .. i18n("packets_page.retransmissions") .."".. formatPackets(ifstats.tcpPacketStats.retransmissions) .."
" .. i18n("packets_page.out_of_order") .. "".. formatPackets(ifstats.tcpPacketStats.out_of_order) .."
" .. i18n("packets_page.lost") .. "".. formatPackets(ifstats.tcpPacketStats.lost) .."
]] print(i18n("packets_page.size_distribution")) print [[
]] print(i18n("packets_page.tcp_flags_distribution")) print[[
]] print(i18n("packets_page.ip_version_distribution")) print[[

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

]] print(i18n("ndpi_page.overview", {what = i18n("ndpi_page.application_protocol")})) print [[
]] print(i18n("ndpi_page.overview", {what = i18n("ndpi_page.application_protocol_category")})) print [[
]] print(i18n("ndpi_page.live_flows_count")) print [[

]] print(i18n("ndpi_page.note")) print [[ :]] print(i18n("ndpi_page.note_live_flows_chart")) print [[
]] print [[ ]] print("\n") print ('\n') print ("") print("
" .. i18n("ndpi_page.application_protocol") .. "" .. i18n("ndpi_page.total_since_startup") .. "" .. i18n("percentage") .. "
\n") print [[ ]] print [[ ]] print("\n") print ('\n') print ("") print("
" .. i18n("ndpi_page.application_protocol_category") .. "" .. i18n("ndpi_page.total_since_startup") .. "" .. i18n("percentage") .. "
\n") print [[ ]] elseif(page == "ICMP") then print [[
]] print(i18n("icmp_page.icmp_message")) print [[]] print(i18n("packets")) print[[
]] elseif(page == "ARP") then print [[
]] print(i18n("arp_page.arp_type")) print [[]] print(i18n("packets")) print[[
]] elseif(page == "historical") then rrd_file = _GET["rrd_file"] selected_epoch = _GET["epoch"] if(selected_epoch == nil) then selected_epoch = "" end if(rrd_file == nil) then rrd_file = "bytes.rrd" end drawRRD(ifstats.id, nil, rrd_file, _GET["zoom"], url.."&page=historical", 1, _GET["epoch"], selected_epoch) --drawRRD(ifstats.id, nil, rrd_file, _GET["zoom"], url.."&page=historical", 1, _GET["epoch"], selected_epoch, topArray, _GET["comparison_period"]) if ntop.isPro() then print[[

]] print(i18n('notes')) print[[
]] end elseif(page == "trafficprofiles") then print("\n") print("\n") for pname,pbytes in pairs(ifstats.profiles) do local trimmed = trimSpace(pname) local rrdname = os_utils.fixPath(dirs.workingdir .. "/" .. ifid .. "/profilestats/" .. getPathFromKey(trimmed) .. "/bytes.rrd") local statschart_icon = '' if ntop.exists(rrdname) then statschart_icon = '' end print("\n") end print [[
" .. i18n("traffic_profiles.profile_name") .. "" .. i18n("chart") .. "" .. i18n("traffic") .. "
"..pname..""..statschart_icon..""..bytesToSize(pbytes).."
]] 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("\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("
" .. i18n("packetdump_page.packet_dump") .. "") print(''..' '..i18n("packetdump_page.dump_all_traffic")) print('') print("
") print(' '..i18n("packetdump_page.dump_unknown_traffic")..' ') print("
" .. i18n("packetdump_page.packet_dump_to_disk").. "") print(' '..i18n("packetdump_page.dump_traffic_to_disk")) if(dump_traffic_checked ~= "") then local dumped = interface.getInterfacePacketsDumpedFile() print(" - " .. i18n("packetdump_page.num_dumped_packets",{num_pkts=ternary(dumped, dumped, 0)})) end print('') print("
" .. i18n("packetdump_page.packet_dump_to_tap") .. "") if(interface.getInterfaceDumpTapName() ~= "") then print(' '..i18n("packetdump_page.dump_traffic_to_tap")..' ') print('('..interface.getInterfaceDumpTapName()..')') if(dump_traffic_tap_checked ~= "") then dumped = interface.getInterfacePacketsDumpedTap() print(" - " .. i18n("packetdump_page.num_dumped_packets",{num_pkts=ternary(dumped, dumped, 0)})) end print(' ') else print(i18n("packetdump_page.packet_dump_to_tap_disabled_message")) end print("
"..i18n("packetdump_page.sampling_rate").."]] print [[
" .. i18n("packetdump_page.dump_to_disk_parameters") .. "
" .. i18n("packetdump_page.pcap_dump_directory") .. "") pcapdir = dirs.workingdir .."/"..ifstats.id.."/pcap/" print(pcapdir.."
" .. i18n("packetdump_page.max_packets_per_file") .. "]] print [[ pkts
]] print(i18n("packetdump_page.max_packets_per_file_description")) print [[
" .. i18n("packetdump_page.max_duration_file") .. "]] print [[ sec
]] print(i18n("packetdump_page.max_duration_file_description") .. "
") print(i18n("packetdump_page.note") .. ": " .. i18n("packetdump_page.note_max_duration_file")) print[[
" .. i18n("packetdump_page.max_dump_files") .. "]] print [[ MB
]] print(i18n("packetdump_page.max_size_dump_files_description")) print[[
]] print(i18n("packetdump_page.note") .. ": " .. i18n("packetdump_page.note_max_size_dump_files")) print[[
") print[[

]] 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[[
]] if ((not interface.isPcapDumpInterface()) and (ifstats.name ~= nil) and (ifstats.name ~= "dummy")) then -- Custom name print[[ ]] -- Interface speed if not have_nedge then print[[ ]] -- Interface refresh rate print[[ ]] end end if not have_nedge then -- Scaling factor if interface.isPacketInterface() and not have_nedge then local label = ntop.getCache(getRedisIfacePrefix(ifid)..".scaling_factor") if((label == nil) or (label == "")) then label = "1" end print[[ ]] end end local rv = ntop.getMembersCache(getHideFromTopSet(ifstats.id)) or {} local members = {} -- impose sort order for _, net in pairsByValues(rv, asc) do members[#members + 1] = net end local hide_top = table.concat(members, ",") print[[ ]] -- Alerts local trigger_alerts = true local trigger_alerts_checked = "checked" if _SERVER["REQUEST_METHOD"] == "POST" then if _POST["trigger_alerts"] ~= "1" then trigger_alerts = false trigger_alerts_checked = "" end ntop.setHashCache(get_alerts_suppressed_hash_name(getInterfaceId(ifname)), ifname_clean, tostring(trigger_alerts)) else trigger_alerts = ntop.getHashCache(get_alerts_suppressed_hash_name(getInterfaceId(ifname)), ifname_clean) if trigger_alerts == "false" then trigger_alerts = false trigger_alerts_checked = "" end end print [[]] -- per-interface RRD generation local interface_rrd_creation = true local interface_rrd_creation_checked = "checked" if _SERVER["REQUEST_METHOD"] == "POST" then if _POST["interface_rrd_creation"] ~= "1" then interface_rrd_creation = false interface_rrd_creation_checked = "" end ntop.setPref(get_interface_rrd_creation_key(ifId), tostring(interface_rrd_creation)) else interface_rrd_creation = ntop.getPref(get_interface_rrd_creation_key(ifId)) if interface_rrd_creation == "false" then interface_rrd_creation = false interface_rrd_creation_checked = "" end end print [[]] -- per-interface Network Discovery if interface.isDiscoverableInterface() and (ntop.getPref("ntopng.prefs.is_network_discovery_enabled") == "1") then local discover = require "discover_utils" local interface_network_discovery = true local interface_network_discovery_checked = "checked" if _SERVER["REQUEST_METHOD"] == "POST" then if _POST["interface_network_discovery"] ~= "1" then interface_network_discovery = false interface_network_discovery_checked = "" end ntop.setPref(discover.getInterfaceNetworkDiscoveryEnabledKey(ifId), tostring(interface_network_discovery)) else interface_network_discovery = ntop.getPref(discover.getInterfaceNetworkDiscoveryEnabledKey(ifId)) if interface_network_discovery == "false" then interface_network_discovery = false interface_network_discovery_checked = "" end end print [[]] end print[[
]] print(i18n("if_stats_config.custom_name")) print[[ ]] local label = getHumanReadableInterfaceName(ifstats.name) inline_input_form("custom_name", "Custom Name", i18n("if_stats_config.custom_name_popup_msg"), label, isAdministrator(), 'autocorrect="off" spellcheck="false"') print[[
]] print(i18n("if_stats_config.interface_speed")) print[[ ]] local ifspeed = getInterfaceSpeed(ifstats) inline_input_form("ifSpeed", "Interface Speed", i18n("if_stats_config.interface_speed_popup_msg"), ifspeed, isAdministrator(), 'type="number" min="1"') print[[
]] print(i18n("if_stats_config.refresh_rate")) print[[ ]] local refreshrate = getInterfaceRefreshRate(ifstats.id) inline_input_form("ifRate", "Refresh Rate", i18n("if_stats_config.refresh_rate_popup_msg"), refreshrate, isAdministrator(), 'type="number" min="1"') print[[
]] print(i18n("if_stats_config.scaling_factor")) print[[ ]] inline_input_form("scaling_factor", "Scaling Factor", i18n("if_stats_config.scaling_factor_popup_msg"), label, isAdministrator(), 'type="number" min="1" step="1"') print[[
]] print(i18n("if_stats_config.hide_from_top_networks")) print[[ ]] print('') print[[
]] print(i18n("if_stats_config.trigger_interface_alerts")) print[[
]] print(i18n("if_stats_config.interface_rrd_creation")) print[[
]] print(i18n("if_stats_config.interface_network_discovery")) 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[[
]] print(i18n("snmp.snmp_device")) print[[ ]] print(i18n("snmp.view_device")) print[[
]] print(i18n("snmp.snmp_interface")) 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 == "filtering") then if not isAdministrator() then error() end -- ==================================== -- possibly decode parameters pairs local _POST = paramsPairsDecode(_POST) local perPageProtos if tonumber(tablePreferences("protocolShapers")) == nil then perPageProtos = "10" else perPageProtos = tablePreferences("protocolShapers") end -- TODO refactor view_network logic local selected_pool_id = _GET["pool"] or _POST["target_pool"] local selected_pool = nil local available_pools = host_pools_utils.getPoolsList(ifId) for _, pool in ipairs(available_pools) do if pool.id == selected_pool_id then selected_pool = pool end end if selected_pool == nil then selected_pool = available_pools[2] or available_pools[1] end local SHAPERS_MAX_RATE_KPBS = 100*1000*1000 -- 100 Gbit/s if(_POST["add_shapers"] ~= nil) then local num_added = 0 local last_added = nil for shaper,mrate in pairs(_POST) do local sp = split(shaper, "shaper_") if #sp == 2 then local shaper_id = tonumber(sp[2]) local max_rate = tonumber(mrate) --~ tprint(shaper_id.." "..max_rate) if(max_rate > SHAPERS_MAX_RATE_KPBS) then max_rate = -1 end if(max_rate < -1) then max_rate = -1 end shaper_utils.setShaperMaxRate(ifid, shaper_id, max_rate) num_added = num_added + 1 last_added = shaper_id end end if num_added == 1 then print("") end interface.reloadShapers() end if(_POST["delete_shaper"] ~= nil) then local shaper_id = _POST["delete_shaper"] shaper_utils.deleteShaper(ifid, shaper_id) end if(_POST["target_pool"] ~= nil) then local target_pool = _POST["target_pool"] if (_POST["del_l7_proto"] ~= nil) then local protocol_id = _POST["del_l7_proto"] shaper_utils.deleteProtocol(ifid, target_pool, protocol_id) elseif (_POST["delete_all_policies"] ~= nil) then shaper_utils.flushPoolRules(ifid, target_pool) else -- first remove the rules which have changed protocol local rules_to_delete = {} for option,value in pairs(_POST) do local sp = split(option, "oldrule_") if #sp == 2 then -- mark the rule as to be deleted rules_to_delete[sp[2]] = true end end shaper_utils.get_shapers_from_parameters(function(proto_id) -- A new rule will be set for the protocol, no need to delete it rules_to_delete[proto_id] = nil end) for proto in pairs(rules_to_delete) do shaper_utils.deleteProtocol(ifid, target_pool, proto) end -- set protocols policy for the pool shaper_utils.get_shapers_from_parameters(function(proto_id, ingress_shaper, egress_shaper, traffic_quota, time_quota) if proto_id == "default" then -- This is not the default protocol quota but the overall quota shaper_utils.setCrossApplicationQuotas(ifid, target_pool, traffic_quota, time_quota) traffic_quota = shaper_utils.NO_QUOTA time_quota = shaper_utils.NO_QUOTA end shaper_utils.setProtocolShapers(ifid, target_pool, proto_id, ingress_shaper, egress_shaper, traffic_quota, time_quota) end) end interface.reloadL7Rules(tonumber(selected_pool.id)) end print [[
]] -- ****************************************** local shapers = shaper_utils.getSortedShapers(ifid) function print_shapers(shapers, curshaper_id, terminator) terminator = terminator or "\n" if(curshaper_id == "") then curshaper_id = "0" else curshaper_id = tostring(curshaper_id) end for _,shaper in ipairs(shapers) do print(""..terminator) end end -- ****************************************** -- Create delete dialogs print( template.gen("modal_confirm_dialog.html", { dialog={ id = "delete_policy_dialog", action = "deleteShapedProtocol(delete_protocol_id)", title = i18n("shaping.delete_policy"), message = i18n("shaping.confirm_delete_policy") .. ' ' .. i18n("shaping.policy_from_pool") .. " \"" .. selected_pool.name .. "\"?", confirm = i18n("delete"), } }) ) print( template.gen("modal_confirm_dialog.html", { dialog={ id = "delete_shaper_dialog", action = "deleteShaper(delete_shaper_id)", title = i18n("shaping.delete_shaper"), message = i18n("shaping.confirm_delete_shaper") .. ' ?', confirm = i18n("delete"), } }) ) print( template.gen("modal_confirm_dialog.html", { dialog={ id = "deleteAllPolicies", action = "deleteAllPoliciesConfig()", title = i18n("shaping.delete_all_policies"), message = i18n("shaping.confirm_delete_all_policies", {pool_name = selected_pool.name}).."?", confirm = i18n("delete"), } }) ) -- ****************************************** -- ==== Manage policies tab ==== print [[

]] print(i18n("host_pools.pool")..":") print[[ ') if selected_pool.id ~= host_pools_utils.DEFAULT_POOL_ID then print(' ') local poolstats_rrd = host_pools_utils.getRRDBase(ifstats.id, selected_pool.id) if ntop.getCache("ntopng.prefs.host_pools_rrd_creation") == "1" and ntop.exists(poolstats_rrd) then print("  ") end end print[[
]] local protos = interface.getnDPIProtocols() local protos_in_use = shaper_utils.getPoolProtoShapers(ifid, selected_pool.id, true --[[ do not aggregate into categories ]]) local protocol_categories = shaper_utils.getCategoriesWithProtocols() local uses_per_member_quota = selected_pool.enforce_quotas_per_pool_member -- families of protocols which are currently used by at least one protocol local categories_in_use = {} for k,v in pairs(protos_in_use) do local proto_id = tonumber(v.protoId) -- can be null for default if proto_id ~= nil then local category_id = tostring(interface.getnDPIProtoCategory(proto_id).id) if not categories_in_use[category_id] then categories_in_use[category_id] = 1 else categories_in_use[category_id] = categories_in_use[category_id] + 1 end end end local policy_target_type = ntop.getPref("ntopng.prefs.bridging_policy_target_type") if isEmptyString(policy_target_type) then policy_target_type = "per_category" end function print_ndpi_families(categories, protos, categories_disabled, protos_disabled, terminator) local protos_excluded = {GRE=1, BGP=1, IGMP=1, IPP=1, IP_in_IP=1, OSPF=1, PPTP=1, SCTP=1, TFTP=1} local show_groups = (policy_target_type == "both") if show_groups then print('') end if (policy_target_type == "per_category") or (policy_target_type == "both") then for k,category in pairsByKeys(categories, asc_insensitive) do print(''..terminator) end end if show_groups then print('') end if show_groups then print('') end if (policy_target_type == "per_protocol") or (policy_target_type == "both") then for protoName,protoId in pairsByKeys(protos, asc_insensitive) do if not protos_excluded[protoName] then -- find protocol category for _,category in pairs(categories) do for _,catProto in pairs(category.protos) do if catProto == protoId then print('"..terminator) break end end end end end end if show_groups then print('') else print(' ') end end local split_shaping_directions = (ntop.getPref("ntopng.prefs.split_shaping_directions") == "1") print [[
]] if selected_pool.id ~= host_pools_utils.DEFAULT_POOL_ID then print([[]]..i18n("shaping.notes")..[[:]]) print([[
]] end local rate_buttons = shaper_utils.buttons("rate") local traffic_buttons = shaper_utils.buttons("traffic") local time_buttons = shaper_utils.buttons("time") print("
]] -- ****************************************** -- ==== Bandwidth Manager tab ==== print[[

]] print [[
]] print(i18n('shaping.notes')) print[[
]] 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")