diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index 531c7cc025..91b3ba7fcf 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -112,14 +112,88 @@ if (! check_acl($config['id_user'], 0, 'UM')) { return; } -/* - * Disabled at the moment. - if (!check_referer()) { - require ("general/noaccess.php"); +if (is_ajax()) { + $delete_profile = (bool) get_parameter('delete_profile'); + if ($delete_profile) { + $id2 = (string) get_parameter('id_user'); + $id_up = (int) get_parameter('id_user_profile'); - return; + $perfilUser = db_get_row('tusuario_perfil', 'id_up', $id_up); + $id_perfil = $perfilUser['id_perfil']; + $perfil = db_get_row('tperfil', 'id_perfil', $id_perfil); + + db_pandora_audit( + 'User management', + 'Deleted profile for user '.io_safe_input($id2), + false, + false, + 'The profile with id '.$id_perfil.' in the group '.$perfilUser['id_grupo'] + ); + + $return = profile_delete_user_profile($id2, $id_up); + ui_print_result_message( + $return, + __('Successfully deleted'), + __('Could not be deleted') + ); + + + $has_profile = db_get_row('tusuario_perfil', 'id_usuario', $id2); + if ($has_profile == false) { + $result = delete_user($id2); + + if ($result) { + db_pandora_audit( + 'User management', + __('Deleted user %s', io_safe_input($id_user)) + ); + } + + ui_print_result_message( + $result, + __('Successfully deleted'), + __('There was a problem deleting the user') + ); + + // Delete the user in all the consoles + if (defined('METACONSOLE')) { + $servers = metaconsole_get_servers(); + foreach ($servers as $server) { + // Connect to the remote console + metaconsole_connect($server); + + // 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(); + + // Log to the metaconsole too + if ($result) { + db_pandora_audit( + 'User management', + __('Deleted user %s from %s', io_safe_input($id_user), io_safe_input($server['server_name'])) + ); + } + + ui_print_result_message( + $result, + __('Successfully deleted from %s', io_safe_input($server['server_name'])), + __('There was a problem deleting the user from %s', io_safe_input($server['server_name'])) + ); + } + } + } + + return; } - */ +} $tab = get_parameter('tab', 'user'); @@ -168,9 +242,9 @@ if ($config['user_can_update_info']) { $new_user = (bool) get_parameter('new_user'); $create_user = (bool) get_parameter('create_user'); $add_profile = (bool) get_parameter('add_profile'); -$delete_profile = (bool) get_parameter('delete_profile'); $update_user = (bool) get_parameter('update_user'); $status = get_parameter('status', -1); +$json_profile = get_parameter('json_profile', ''); // Reset status var if current action is not update_user if ($new_user || $create_user || $add_profile @@ -372,6 +446,41 @@ if ($create_user) { $user_info = get_user_info($id); $new_user = false; + + if (!empty($json_profile)) { + $json_profile = json_decode(io_safe_output($json_profile), true); + foreach ($json_profile as $key => $profile) { + if (!empty($profile)) { + $group2 = $profile['group']; + $profile2 = $profile['profile']; + $tags = $profile['tags']; + foreach ($tags as $k => $tag) { + if (empty($tag)) { + unset($tags[$k]); + } + } + + $tags = implode(',', $tags); + $no_hierarchy = $profile['hierarchy']; + + db_pandora_audit( + 'User management', + 'Added profile for user '.io_safe_input($id2), + false, + false, + 'Profile: '.$profile2.' Group: '.$group2.' Tags: '.$tags + ); + + $result_profile = profile_create_user_profile($id, $profile2, $group2, false, $tags, $no_hierarchy); + + ui_print_result_message( + $result_profile, + __('Profile added successfully'), + __('Profile cannot be added') + ); + } + } + } } else { $user_info = $values; $new_user = true; @@ -598,7 +707,7 @@ if ($status != -1) { ); } -if ($add_profile) { +if ($add_profile && empty($json_profile)) { $id2 = (string) get_parameter('id'); $group2 = (int) get_parameter('assign_group'); $profile2 = (int) get_parameter('assign_profile'); @@ -628,34 +737,38 @@ if ($add_profile) { ); } -if ($delete_profile) { - $id2 = (string) get_parameter('id_user'); - $id_up = (int) get_parameter('id_user_profile'); - - $perfilUser = db_get_row('tusuario_perfil', 'id_up', $id_up); - $id_perfil = $perfilUser['id_perfil']; - $perfil = db_get_row('tperfil', 'id_perfil', $id_perfil); - - db_pandora_audit( - 'User management', - 'Deleted profile for user '.io_safe_input($id2), - false, - false, - 'The profile with id '.$id_perfil.' in the group '.$perfilUser['id_grupo'] - ); - - $return = profile_delete_user_profile($id2, $id_up); - ui_print_result_message( - $return, - __('Successfully deleted'), - __('Could not be deleted') - ); -} - if ($values) { $user_info = $values; } +if (!users_is_admin() && $config['id_user'] != $id && !$new_user) { + $group_um = users_get_groups_UM($config['id_user']); + if (isset($group_um[0])) { + $group_um_string = implode(',', array_keys(users_get_groups($config['id_user'], 'um', true))); + } else { + $group_um_string = implode(',', array_keys($group_um)); + } + + $sql = sprintf( + "SELECT tusuario_perfil.* FROM tusuario_perfil + INNER JOIN tperfil ON tperfil.id_perfil = tusuario_perfil.id_perfil + WHERE id_usuario like '%s' AND id_grupo IN (%s) AND user_management = 0", + $id, + $group_um_string + ); + + $result = db_get_all_rows_sql($sql); + if ($result == false || $user_info['is_admin']) { + db_pandora_audit( + 'ACL Violation', + 'Trying to access User Management' + ); + include 'general/noaccess.php'; + + return; + } +} + if (defined('METACONSOLE')) { if ($id) { echo '