require "lua_utils" local pcap_status_url = ntop.getHttpPrefix().."/lua/get_nbox_data.lua?action=status" local pcap_request_url = ntop.getHttpPrefix().."/lua/get_nbox_data.lua?action=schedule" local favourites_url = ntop.getHttpPrefix().."/lua/get_historical_favourites.lua" function commonJsUtils() print[[ function hideAll(cla){ $('.' + cla).hide(); } function showOne(cla, id){ $('.' + cla).not('#' + id).hide(); $('#' + id).show(); } function hostkey2hostid(host_key) { var info; var hostinfo = []; host_key = host_key.replace(/\:/g, "____"); host_key = host_key.replace(/\//g, "___"); host_key = host_key.replace(/\./g, "__"); info = host_key.split("@"); return(info); } function buildPcapRequestData(source_div_id){ var epoch_begin = $('#' + source_div_id).attr("epoch_begin"); var epoch_end = $('#' + source_div_id).attr("epoch_end"); var ifname = $('#' + source_div_id).attr("ifname"); var host = $('#' + source_div_id).attr("host"); var peer = $('#' + source_div_id).attr("peer"); var res = {epoch_begin: epoch_begin, epoch_end: epoch_end}; if (typeof ifname != 'undefined') res.ifname = ifname; if (typeof host != 'undefined') res.host = host; if (typeof peer != 'undefined') res.peer = peer; return res; } function addToFavourites(source_div_id, stats_type, favourite_type, select_id){ $.ajax({type:'GET',url:"]]print(favourites_url)print[[?action=set&stats_type=" + stats_type + "&favourite_type=" + favourite_type, data:buildPcapRequestData(source_div_id), success:function(data){ data=jQuery.parseJSON(data); populateFavourites(source_div_id, stats_type, favourite_type, select_id); }, error:function(){ perror('An HTTP error occurred.'); } }); } function populateFavourites(source_div_id, stats_type, favourite_type, select_id){ $('#'+select_id).find('option').remove(); $.ajax({type:'GET',url:"]]print(favourites_url)print[[?action=get&stats_type=" + stats_type + "&favourite_type=" + favourite_type, data:buildPcapRequestData(source_div_id), success:function(data){ data=jQuery.parseJSON(data); $.each(data, function(hosts, hostnames){ if (hosts.split(',').length == 1){ var option_data = ''; }else if (hosts.split(',').length == 2) { var option_data = ''; } $(option_data).appendTo('#'+select_id); }); }, error:function(){ perror('An HTTP error occurred.'); } }); $('#' + select_id).change(function() { var host = $(this).find(':selected').val(); host = host.split(','); if (host.length == 1){ populateHostTopTalkersTable(host[0]); } else if (host.length == 2){ populateAppsPerHostsPairTable(host[0], host[1]); } }); } ]] end function historicalPcapButton(button_id, pcap_request_data_container_div_id) if not ntop.isPro() then return end -- integrate only in the Pro version print("

") if false then a = 1 else print [[
Request a pcap containing the recorded traffic matching search criteria. Requests will be queued and pcaps will be available for download once generated.


]] end end function historicalTopTalkersTable(ifid, epoch_begin, epoch_end, host) local breadcrumb_root = "interface" local host_talkers_url_params = "" local interface_talkers_url_params = "" interface_talkers_url_params = interface_talkers_url_params.."&epoch_start="..epoch_begin interface_talkers_url_params = interface_talkers_url_params.."&epoch_end="..epoch_end if host and host ~= "" then host_talkers_url_params = interface_talkers_url_params.."&peer1="..host breadcrumb_root = "host" else host_talkers_url_params = interface_talkers_url_params end local preference = tablePreferences("rows_number",_GET["perPage"]) local sort_order = getDefaultTableSortOrder("historical_stats_top_talkers") local sort_column= getDefaultTableSort("historical_stats_top_talkers") if not sort_column or sort_column == "column_" then sort_column = "column_bytes" end print[[
Favorite Talkers
Favorite applications between pairs of talkers
]] historicalPcapButton("pcap-button-top-talkers", "historical-container") print [[ ]] end function historicalTopApplicationsTable(ifid, epoch_begin, epoch_end, host) local breadcrumb_root = "interface" local top_apps_url_params="" top_apps_url_params = top_apps_url_params.."&epoch_start="..epoch_begin top_apps_url_params = top_apps_url_params.."&epoch_end="..epoch_end if host and host ~= "" then breadcrumb_root="host" end local preference = tablePreferences("rows_number",_GET["perPage"]) local sort_order = getDefaultTableSortOrder("historical_stats_top_applications") local sort_column= getDefaultTableSort("historical_stats_top_applications") if not sort_column or sort_column == "column_" then sort_column = "column_bytes" end print[[
]] historicalPcapButton("pcap-button-top-protocols", "historical-apps-container") print [[ ]] end function historicalPcapsTable() print[[
]] end