From 0ddc1929fac6b07eb06f982af0cb7ba467dec990 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 2 Feb 2021 11:25:26 +0100 Subject: [PATCH] multiple fixes --- pandora_console/godmode/tag/tag.php | 3 +++ pandora_console/godmode/users/user_list.php | 28 +++++++++++---------- pandora_console/include/ajax/events.php | 16 ++++++++---- pandora_console/include/functions.php | 6 ++++- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/pandora_console/godmode/tag/tag.php b/pandora_console/godmode/tag/tag.php index a80c2b76bb..d5711cbab7 100644 --- a/pandora_console/godmode/tag/tag.php +++ b/pandora_console/godmode/tag/tag.php @@ -66,6 +66,7 @@ if (is_ajax()) { function ($counter, $server) use ($id_tag) { if (metaconsole_connect($server) === NOERR) { $counter += tags_get_local_modules_count($id_tag); + metaconsole_restore_db(); } return $counter; @@ -83,6 +84,7 @@ if (is_ajax()) { function ($counter, $server) use ($id_tag) { if (metaconsole_connect($server) === NOERR) { $counter += tags_get_policy_modules_count($id_tag); + metaconsole_restore_db(); } return $counter; @@ -261,6 +263,7 @@ if (!empty($result)) { function ($counter, $server) use ($tag_id) { if (metaconsole_connect($server) === NOERR) { $counter += tags_get_modules_count($tag_id); + metaconsole_restore_db(); } return $counter; diff --git a/pandora_console/godmode/users/user_list.php b/pandora_console/godmode/users/user_list.php index 5178cce690..488361b1d0 100644 --- a/pandora_console/godmode/users/user_list.php +++ b/pandora_console/godmode/users/user_list.php @@ -232,21 +232,21 @@ if (isset($_GET['user_del'])) { if (defined('METACONSOLE') && isset($_GET['delete_all'])) { $servers = metaconsole_get_servers(); foreach ($servers as $server) { - // Connect to the remote console - metaconsole_connect($server); + // Connect to the remote console. + if (metaconsole_connect($server) === NOERR) { + // Delete the user + $result = delete_user($id_user); + if ($result) { + db_pandora_audit( + 'User management', + __('Deleted user %s from metaconsole', io_safe_input($id_user)) + ); + } - // Delete the user - $result = delete_user($id_user); - if ($result) { - db_pandora_audit( - 'User management', - __('Deleted user %s from metaconsole', io_safe_input($id_user)) - ); + // Restore the db connection. + metaconsole_restore_db(); } - // Restore the db connection - metaconsole_restore_db(); - // Log to the metaconsole too if ($result) { db_pandora_audit( @@ -613,7 +613,9 @@ foreach ($info as $user_id => $user_info) { $data[6] .= ''.html_print_image('images/config.png', true, ['title' => __('Edit')]).''; if ($config['admin_can_delete_user'] && $user_info['id_user'] != $config['id_user'] && !isset($user_info['not_delete'])) { $data[6] .= "".html_print_image('images/cross.png', true, ['title' => __('Delete'), 'onclick' => "if (! confirm ('".__('Deleting User').' '.$user_info['id_user'].'. '.__('Are you sure?')."')) return false"]).''; - if (defined('METACONSOLE')) { + if ((bool) is_metaconsole() === true + && (bool) can_user_access_node() === true + ) { $data[6] .= "".html_print_image('images/cross_double.png', true, ['title' => __('Delete from all consoles'), 'onclick' => "if (! confirm ('".__('Deleting User %s from all consoles', $user_info['id_user']).'. '.__('Are you sure?')."')) return false"]).''; } } else { diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index b47a750e85..5e14d73ae8 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -1436,15 +1436,21 @@ if ($get_extended_event) { $related = events_page_related($event, $server); } + $connected = true; if ($meta) { - metaconsole_connect($server); + if (metaconsole_connect($server) === NOERR) { + $connected = true; + } else { + $connected = false; + } } - $custom_fields = events_page_custom_fields($event); + if ($connected === true) { + $custom_fields = events_page_custom_fields($event); + $custom_data = events_page_custom_data($event); + } - $custom_data = events_page_custom_data($event); - - if ($meta) { + if ($meta && $connected === true) { metaconsole_restore_db(); } diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 2509a67a66..0b07c16ebc 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -2850,7 +2850,11 @@ function can_user_access_node() { global $config; - $userinfo = get_user_info($config['id_user']); + static $userinfo; + + if ($userinfo === null) { + $userinfo = get_user_info($config['id_user']); + } if (is_metaconsole()) { return $userinfo['is_admin'] == 1 ? 1 : $userinfo['metaconsole_access_node'];