-- -- (C) 2014-19 - ntop.org -- local dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path local alerts_api = require "alerts_api" local format_utils = require "format_utils" local user_scripts = require "user_scripts" local flow_callbacks_utils = {} -- ############################################## local function print_callbacks_config_tbody_simple_view(descr) print[[]] print[[]] print[[]] print(i18n("flow_callbacks.callback")) print[[]] print[[]] print(i18n("flow_callbacks.callback_config")) print[[]] print[[]] print(i18n("flow_callbacks.callback_function_duration_simple_view")) print[[]] print[[]] print[[
]] print('\n') local has_modules = false for _, user_script in pairsByKeys(descr.modules, asc) do if user_script.gui then if not has_modules then has_modules = true end print("".. i18n(user_script.gui.i18n_title) .."
") print(""..i18n(user_script.gui.i18n_description)..".\n") print("") print(user_script.gui.input_builder(user_script)) print("") if user_script.benchmark and table.len(user_script.benchmark) > 0 then local max_duration for mod_fn, mod_benchmark in pairsByKeys(user_script.benchmark, asc) do -- Just show the maximum duration among all available functions if not max_duration or max_duration < mod_benchmark["tot_elapsed"] then max_duration = mod_benchmark["tot_elapsed"] end end print(string.format("%s", format_utils.secondsToTime(max_duration))) else print("") end print("") end end if not has_modules then print(""..i18n("flow_callbacks.no_callbacks_defined")..".") end print[[]] return has_modules end -- ################################# local function print_callbacks_config_tbody_expert_view(descr) print[[]] print[[]] print[[]] print[[]] print(i18n("flow_callbacks.callback_latest_run")) print[[]] print[[]] print[[]] print[[]] print(i18n("flow_callbacks.callback")) print[[]] print[[]] print(i18n("flow_callbacks.callback_config")) print[[]] print[[]] print(i18n("flow_callbacks.callback_function")) print[[]] print[[]] print(i18n("flow_callbacks.callback_function_duration")) print[[]] print[[]] print(i18n("flow_callbacks.callback_function_num_flows")) print[[]] print[[]] print(i18n("flow_callbacks.callback_function_throughput")) print[[]] print[[]] print[[]] print('\n') local has_modules = false for _, user_script in pairsByKeys(descr.modules, asc) do if user_script.gui then if not has_modules then has_modules = true end local rowspan = 1 if user_script.benchmark and table.len(user_script.benchmark) > 0 then rowspan = table.len(user_script.benchmark) end print("".. i18n(user_script.gui.i18n_title) .."
") print(""..i18n(user_script.gui.i18n_description)..".\n") print("") print(user_script.gui.input_builder(user_script)) print("") print("") local num = 1 if user_script.benchmark and table.len(user_script.benchmark) > 0 then for mod_fn, mod_benchmark in pairsByKeys(user_script.benchmark, asc) do local avg_fps = mod_benchmark["tot_num_calls"] / mod_benchmark["tot_elapsed"] if avg_fps ~= avg_fps or not avg_fps or avg_fps < 0.01 then avg_fps = "< 0.01" else avg_fps = format_utils.formatValue(format_utils.round(avg_fps, 0)) end local trtd, slash_tdtr = "", "" if num == 1 then trtd = '' end print(string.format("%s %s %s%s%s %s
%s", trtd, mod_fn, format_utils.secondsToTime(mod_benchmark["tot_elapsed"]), format_utils.formatValue(mod_benchmark["tot_num_calls"]), avg_fps, i18n("flow_callbacks.callback_elapsed_time_avg"), slash_tdtr)) num = num + 1 end else print("") end end end if not has_modules then print(""..i18n("flow_callbacks.no_callbacks_defined")..".") end print[[]] return has_modules end -- ################################# function flow_callbacks_utils.print_callbacks_config() local show_advanced_prefs = false if _POST and _POST["show_advanced_prefs"] and _POST["show_advanced_prefs"] == "true" then show_advanced_prefs = true end local ifid = interface.getId() local descr = user_scripts.load(user_scripts.script_types.flow, ifid, "flow", nil, true --[[ also return disabled ]]) print [[
]] if table.len(_POST) > 0 then for mod_key, user_script in pairs(descr.modules) do local pref_key = "enabled_" .. mod_key local val = _POST[pref_key] if(val ~= nil) then if(val == "on") then user_scripts.enableModule(ifid, "flow", mod_key) user_script.enabled = true else user_scripts.disableModule(ifid, "flow", mod_key) user_script.enabled = false end end end end local has_modules if show_advanced_prefs then has_modules = print_callbacks_config_tbody_expert_view(descr) else has_modules = print_callbacks_config_tbody_simple_view(descr) end print[[
]] if has_modules then print[[]] print[[]] end print[[
]] print[[
]] local cls_on = "btn btn-sm" local cls_off = cls_on if show_advanced_prefs then cls_on = cls_on..' btn-primary active' cls_off = cls_off..' btn-default' else cls_on = cls_on..' btn-default' cls_off = cls_off..' btn-primary active' end print('') print('') print[[
]] print("
" .. i18n("flow_callbacks.notes") .. ":
") end return flow_callbacks_utils