-- -- (C) 2013-20 - ntop.org -- local dirs = ntop.getDirs() local info = ntop.getInfo() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path local code_editor = {} local os_utils = require "os_utils" -- ################################################################ -- Given absolute plugin and plugin file paths, this function strips out their absolute parts -- to create pseudo-paths that are safe to be passed as parameters to an url local function file_url(plugin_path, plugin_file_path) plugin_path = string.sub(plugin_path, string.len(dirs.scriptdir) + 1) plugin_file_path = string.sub(plugin_file_path, string.len(dirs.scriptdir) + 1) return string.format("%s/lua/code_viewer.lua?plugin_file_path=%s&plugin_path=%s", ntop.getHttpPrefix(), plugin_file_path, plugin_path) end -- ################################################################ -- This recursive function is in charge of printing dropdown menu entries for all the plugin files (except manifest.lua in the root) -- All the plugin subdirectories are navigated recursively, and their files printed as menu entries. -- @param string plugin_file_path The path to the plugin file as received from the original caller (never changes during recursion) -- @param string plugin_path The path to the plugin as received from the original caller (never changes during recursion) -- @param string subdir_path The path to the current working directory (changes during recursion) -- @param string subdir_level The current level of recursion (starts from 1) -- @param string subdir_header The header printed as dropdown-header for the current subdir_path local function plugin_subdir_files_dropdown(plugin_file_path, plugin_path, subdir_path, subdir_level, subdir_header) local plugin_contents = ntop.readdir(subdir_path) for plugin_content, _ in pairsByKeys(plugin_contents) do if plugin_content then local subdir_path = os_utils.fixPath(string.format("%s/%s", subdir_path, plugin_content)) if ntop.isdir(subdir_path) then -- If this is a directory, and the recursion level is 1, then a dropdown-header is printed. -- Headers are not printed at every recursion level to keep the dropdown as simple as possible if subdir_level == 1 then print[[
]] print(plugin_file_path) print [[
]] end -- ################################# return code_editor