From 27e7bfafeff0e314ea39529fb00c48e695c1854d Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sat, 14 Nov 2015 14:03:41 +0100 Subject: ntop - package fixes and cleanups - Split PHP code to an inc file - Make it possible to disable ntop without uninstalling - Add Keep Data/Settings feature - Remove graphs/data/configuration on uninstall if Keep Data/Settings is disabled - Fix flipped 'Allow merging interfaces' meaning - Do not restart ntop during boot - Add privileges configuration - Code style cleanups --- config/ntop2/ntop.inc | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 config/ntop2/ntop.inc (limited to 'config') diff --git a/config/ntop2/ntop.inc b/config/ntop2/ntop.inc new file mode 100644 index 00000000..7c846b87 --- /dev/null +++ b/config/ntop2/ntop.inc @@ -0,0 +1,157 @@ + "ntop.sh", "start" => $start, "stop" => "/usr/bin/killall ntop")); + + /* Set up admin password and (re)start services if not booting */ + if ((function_exists("platform_booting")) && (!platform_booting())) { + ntop_stop_service(); + ntop_set_password(); + start_service("ntop"); + } elseif (!($g['booting'])) { + ntop_stop_service(); + ntop_set_password(); + start_service("ntop"); + } + + conf_mount_ro(); +} + +function ntop_stop_service() { + if (is_service_running("ntop")) { + stop_service("ntop"); + // Wait for ntop to shut down cleanly. + for ($i = 0; $i <= 10; $i++) { + if (!is_process_running("ntop")) { + break; + } + sleep(2); + } + } +} + +function ntop_set_password() { + global $config; + + if (is_array($config['installedpackages']['ntop'])) { + $ntop_config = $config['installedpackages']['ntop']['config'][0]; + } else { + $ntop_config = array(); + } + $ntop_password = $ntop_config['password'] ?: "admin"; + unlink_if_exists("/var/db/ntop/ntop_pw.db"); + mwexec("/usr/local/bin/ntop --set-admin-password={$ntop_password}"); + sleep(2); +} + +function ntop_validate_input($post, &$input_errors) { + if (empty($post['password']) || empty($post['passwordagain'])) { + $input_errors[] = "You must provide (and confirm) ntop's password."; + } + + if ($post['password'] != $post['passwordagain']) { + $input_errors[] = "The provided passwords did not match."; + } +} + +?> -- cgit v1.2.3