-- -- (C) 2013-20 - ntop.org -- local dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path package.path = dirs.installdir .. "/scripts/lua/modules/timeseries/drivers/?.lua;" .. package.path -- for influxdb if((dirs.scriptdir ~= nil) and (dirs.scriptdir ~= "")) then package.path = dirs.scriptdir .. "/lua/modules/?.lua;" .. package.path end require "lua_utils" require "prefs_utils" local alert_utils = require "alert_utils" local template = require "template_utils" local callback_utils = require "callback_utils" local lists_utils = require "lists_utils" local telemetry_utils = require "telemetry_utils" local alert_consts = require "alert_consts" local recording_utils = require "recording_utils" local remote_assistance = require "remote_assistance" local data_retention_utils = require "data_retention_utils" local page_utils = require("page_utils") local ts_utils = require("ts_utils") local influxdb = require("influxdb") local plugins_utils = require("plugins_utils") local nindex_utils = nil local info = ntop.getInfo() local auth = require "auth" local email_peer_pattern = [[^(([A-Za-z0-9._%+-]|\s)+<)?[A-Za-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}>?$]] if(ntop.isPro()) then package.path = dirs.installdir .. "/scripts/lua/pro/?.lua;" .. package.path package.path = dirs.installdir .. "/scripts/lua/pro/modules/?.lua;" .. package.path if hasNindexSupport() then nindex_utils = require("nindex_utils") end end sendHTTPContentTypeHeader('text/html') local alerts_disabled = false local product = ntop.getInfo().product local message_info = "" local message_severity = "alert-warning" -- NOTE: all the auth methods should be listed below local auth_toggles = { ["local"] = "toggle_local_auth", ["ldap"] = "toggle_ldap_auth", ["http"] = "toggle_http_auth", ["radius"] = "toggle_radius_auth", } if auth.has_capability(auth.capabilities.preferences) then if not table.empty(_POST) then if _GET["tab"] == "auth" then local one_enabled = false for k, v in pairs(auth_toggles) do if _POST[v] == "1" then one_enabled = true break end end end end if(_GET["tab"] == "ext_alerts") then local available_endpoints = plugins_utils.getLoadedAlertEndpoints() for _, endpoint in ipairs(available_endpoints) do if(endpoint.handlePost) then local mi, ms = endpoint.handlePost() if mi then message_info = mi end if ms then message_severity = ms end end end end if(_POST["flush_alerts_data"] ~= nil) then local alert_utils = require "alert_utils" alert_utils.flushAlertsData() elseif(_POST["disable_alerts_generation"] == "1") then local alert_utils = require "alert_utils" alert_utils.disableAlertsGeneration() elseif (_POST["timeseries_driver"] == "influxdb") then local url = string.gsub(string.gsub( _POST["ts_post_data_url"], "http:__", "http://"), "https:__", "https://") if ntop.getPref("ntopng.prefs.timeseries_driver") ~= "influxdb" or (url ~= ntop.getPref("ntopng.prefs.ts_post_data_url")) or (_POST["influx_dbname"] ~= ntop.getPref("ntopng.prefs.influx_dbname")) or (_POST["influx_retention"] ~= ntop.getPref("ntopng.prefs.influx_retention")) or (_POST["toggle_influx_auth"] ~= ntop.getPref("ntopng.prefs.influx_auth_enabled")) or (_POST["influx_username"] ~= ntop.getPref("ntopng.prefs.influx_username")) or (_POST["influx_password"] ~= ntop.getPref("ntopng.prefs.influx_password")) then local username = nil local password = nil if _POST["toggle_influx_auth"] == "1" then username = _POST["influx_username"] password = _POST["influx_password"] end local ok, message = influxdb.init(_POST["influx_dbname"], url, tonumber(_POST["influx_retention"]), username, password, false --[[verbose]]) if not ok then -- NOTE: already logged --~ message_info = message --~ message_severity = "alert-danger" -- reset driver to the old one _POST["timeseries_driver"] = nil elseif message then message_info = message message_severity = "alert-success" end end elseif(_POST["n2disk_license"] ~= nil) then recording_utils.setLicense(_POST["n2disk_license"]) end if _POST["timeseries_driver"] or _POST["data_retention_days"] then ts_utils.setupAgain() end local slack_channels_key = "ntopng.prefs.alerts.slack_channels" for k, v in pairs(_POST) do if starts(k, "slack_ch_") then local alert_entity = tonumber(split(k, "slack_ch_")[2]) local alert_entity_raw = alert_consts.alertEntityRaw(alert_entity) if alert_entity_raw then -- map entity -> channel name if alert_entity_raw == v then ntop.delHashCache(slack_channels_key, alert_entity_raw) else ntop.setHashCache(slack_channels_key, alert_entity_raw, v) end end end end page_utils.set_active_menu_entry(page_utils.menu_entries.preferences) dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua") prefs = ntop.getPrefs() if not isEmptyString(message_info) then print[[
]] end local show_advanced_prefs = false if toboolean(_POST["show_advanced_prefs"]) ~= nil then ntop.setPref(show_advanced_prefs_key, _POST["show_advanced_prefs"]) show_advanced_prefs = toboolean(_POST["show_advanced_prefs"]) notifyNtopng(show_advanced_prefs_key, _POST["show_advanced_prefs"]) else show_advanced_prefs = toboolean(ntop.getPref(show_advanced_prefs_key)) if isEmptyString(show_advanced_prefs) then show_advanced_prefs = false end end if _GET['show_advanced_prefs'] ~= nil then show_advanced_prefs = (_GET['show_advanced_prefs'] == '1') end page_utils.print_page_title(i18n("prefs.runtime_prefs")) if(false) then io.write("------- SERVER ----------------\n") tprint(_SERVER) io.write("-------- GET ---------------\n") tprint(_GET) io.write("-------- POST ---------------\n") tprint(_POST) io.write("-----------------------\n") end if hasAlertsDisabled() then alerts_disabled = true end local subpage_active, tab = prefsGetActiveSubpage(show_advanced_prefs, _GET["tab"]) -- ================================================================================ function printInterfaces() print(' ]] end -- ================================================================================ function printAlerts() print( template.gen("modal_confirm_dialog.html", { dialog={ id = "flushAlertsData", action = "flushAlertsData()", title = i18n("show_alerts.reset_alert_database"), message = i18n("show_alerts.reset_alert_database_message") .. "?", confirm = i18n("show_alerts.flush_data"), confirm_button = "btn-danger", } }) ) print(' ]] end -- ================================================================================ function printProtocolPrefs() print(' ]] end -- ================================================================================ function printNetworkDiscovery() print(']] end -- ================================================================================ function printTelemetry() print(']] end -- ================================================================================ function printRecording() local n2disk_info = recording_utils.getN2diskInfo() print(']] end -- ================================================================================ function printRemoteAssitance() if not remote_assistance.isAvailable() then return end print(']] end -- ================================================================================ function printDataRetention() print(']] end -- ================================================================================ function printGUI() print(']] end -- ###################### function printMisc() print(']] end -- ================================================================================ function printUpdates() print(']] end -- ================================================================================ local function printAuthDuration() print('