From fdad32e4f07510ea1b71dfe299f68fff60b84a12 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 22 Jul 2020 10:56:16 +0200 Subject: [PATCH] Add public link dashboards --- pandora_console/ajax.php | 74 +++++++++-- .../include/functions_reporting.php | 9 +- .../include/functions_treeview.php | 39 +++--- pandora_console/include/functions_ui.php | 5 +- .../include/javascript/pandora_dashboards.js | 73 ++++++++--- .../include/javascript/tree/TreeController.js | 25 ++-- .../include/lib/Dashboard/Manager.php | 121 ++++++++++++++++-- .../lib/Dashboard/Widgets/network_map.php | 6 +- .../lib/Dashboard/Widgets/tree_view.php | 14 +- .../Widgets/wux_transaction_stats.php | 4 + .../operation/dashboard/dashboard.php | 4 - .../operation/dashboard/public_dashboard.php | 66 ++++++++++ pandora_console/views/dashboard/header.php | 37 +++++- pandora_console/views/dashboard/layout.php | 7 +- 14 files changed, 392 insertions(+), 92 deletions(-) create mode 100644 pandora_console/operation/dashboard/public_dashboard.php diff --git a/pandora_console/ajax.php b/pandora_console/ajax.php index 9ccb73b8ae..7d7619ff95 100644 --- a/pandora_console/ajax.php +++ b/pandora_console/ajax.php @@ -41,7 +41,9 @@ if (__PAN_XHPROF__ === 1) { } } -if ((! file_exists('include/config.php')) || (! is_readable('include/config.php'))) { +if ((! file_exists('include/config.php')) + || (! is_readable('include/config.php')) +) { exit; } @@ -52,7 +54,9 @@ require_once 'include/functions.php'; require_once 'include/functions_db.php'; require_once 'include/auth/mysql.php'; -if (isset($config['console_log_enabled']) && $config['console_log_enabled'] == 1) { +if (isset($config['console_log_enabled']) === true + && $config['console_log_enabled'] == 1 +) { ini_set('log_errors', 1); ini_set('error_log', $config['homedir'].'/log/console.log'); } else { @@ -60,14 +64,15 @@ if (isset($config['console_log_enabled']) && $config['console_log_enabled'] == 1 ini_set('error_log', 0); } - -// Hash login process -if (isset($_GET['loginhash'])) { +// Hash login process. +if (isset($_GET['loginhash']) === true) { $loginhash_data = get_parameter('loginhash_data', ''); $loginhash_user = str_rot13(get_parameter('loginhash_user', '')); if ($config['loginhash_pwd'] != '' - && $loginhash_data == md5($loginhash_user.io_output_password($config['loginhash_pwd'])) + && $loginhash_data == md5( + $loginhash_user.io_output_password($config['loginhash_pwd']) + ) ) { db_logon($loginhash_user, $_SERVER['REMOTE_ADDR']); $_SESSION['id_usuario'] = $loginhash_user; @@ -76,14 +81,38 @@ if (isset($_GET['loginhash'])) { include_once 'general/login_page.php'; db_pandora_audit('Logon Failed (loginhash', '', 'system'); while (@ob_end_flush()) { + // Dumping... + continue; } exit(''); } } +$auth_class = io_safe_output( + get_parameter('auth_class', 'PandoraFMS\Dashboard\Manager') +); +$public_hash = get_parameter('auth_hash', false); +$public_login = false; // Check user. -check_login(); +if (class_exists($auth_class) === false || $public_hash === false) { + check_login(); +} else { + if ($auth_class::validatePublicHash($public_hash) === false) { + db_pandora_audit( + 'Invalid public hash', + 'Trying to access public dashboard' + ); + include 'general/noaccess.php'; + exit; + } + + // OK. Simulated user log in. If you want to use your own auth_class + // remember to set $config['force_instant_logout'] to true to avoid + // persistent user login. +} + +ob_start(); // Enterprise support. if (file_exists(ENTERPRISE_DIR.'/load_enterprise.php')) { @@ -98,7 +127,10 @@ $page .= '.php'; $config['id_user'] = $_SESSION['id_usuario']; $isFunctionSkins = enterprise_include_once('include/functions_skins.php'); if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK) { - $config['relative_path'] = enterprise_hook('skins_set_image_skin_path', [$config['id_user']]); + $config['relative_path'] = enterprise_hook( + 'skins_set_image_skin_path', + [$config['id_user']] + ); } if (is_metaconsole()) { @@ -115,3 +147,29 @@ if (file_exists($page)) { if (__PAN_XHPROF__ === 1) { pandora_xhprof_display_result('ajax', 'console'); } + + +if ($config['force_instant_logout'] === true) { + // Force user logout. + if (session_status() !== PHP_SESSION_ACTIVE) { + session_start(); + } + + $iduser = $_SESSION['id_usuario']; + $_SESSION = []; + session_destroy(); + header_remove('Set-Cookie'); + setcookie(session_name(), $_COOKIE[session_name()], (time() - 4800), '/'); + + if ($config['auth'] == 'saml') { + include_once $config['saml_path'].'simplesamlphp/lib/_autoload.php'; + $as = new SimpleSAML_Auth_Simple('PandoraFMS'); + $as->logout(); + } +} + + +while (@ob_end_flush()) { + // Dumping... + continue; +} diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 09d3b009de..33729dc5b0 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -11739,7 +11739,6 @@ function reporting_get_stats_servers() $table_srv->style[1] = $table_srv->style[3] = 'text-align: left; padding: 5px;'; $tdata = []; - ''.format_numeric($server_performance['total_local_modules']).''; $tdata[0] = html_print_image('images/module.png', true, ['title' => __('Total running modules')]); $tdata[1] = ''.format_numeric($server_performance['total_modules']).''; $tdata[2] = ''.format_numeric($server_performance['total_modules_rate'], 2).''; @@ -11846,12 +11845,6 @@ function reporting_get_stats_servers() ); $tdata[1] = ''.html_print_image('images/spinner.gif', true).''; - /* - Hello there! :) - We added some of what seems to be "buggy" messages to the openSource version recently. This is not to force open-source users to move to the enterprise version, this is just to inform people using Pandora FMS open source that it requires skilled people to maintain and keep it running smoothly without professional support. This does not imply open-source version is limited in any way. If you check the recently added code, it contains only warnings and messages, no limitations except one: we removed the option to add custom logo in header. In the Update Manager section, it warns about the 'danger’ of applying automated updates without a proper backup, remembering in the process that the Enterprise version comes with a human-tested package. Maintaining an OpenSource version with more than 500 agents is not so easy, that's why someone using a Pandora with 8000 agents should consider asking for support. It's not a joke, we know of many setups with a huge number of agents, and we hate to hear that “its becoming unstable and slow” :( - You can of course remove the warnings, that's why we include the source and do not use any kind of trick. And that's why we added here this comment, to let you know this does not reflect any change in our opensource mentality of does the last 14 years. - */ - if ($system_events > 50000 && !enterprise_installed()) { $tdata[2] = "
"; } else { @@ -11865,7 +11858,7 @@ function reporting_get_stats_servers() $output = '
'.__('Server performance').''.html_print_table($table_srv, true).'
'; - $public_hash = get_parameter('hash', false); + $public_hash = get_parameter('auth_hash', false); if ($public_hash === false) { $output .= '