From 06e7740234c03425a24192d5fe628858aec12ad5 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 11 Apr 2024 15:47:00 +0200 Subject: [PATCH] #13344 no enable create tokens when date is older than today --- pandora_console/godmode/users/token_list.php | 39 ++++++++++++++------ pandora_console/include/functions_ui.php | 2 +- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/pandora_console/godmode/users/token_list.php b/pandora_console/godmode/users/token_list.php index b37be0534c..8090339187 100644 --- a/pandora_console/godmode/users/token_list.php +++ b/pandora_console/godmode/users/token_list.php @@ -77,6 +77,7 @@ if ($create_token === true || $update_token === true) { $expirationDate = get_parameter('date-expiration', null); $expirationTime = get_parameter('time-expiration', null); $validity = null; + $error_date = false; if (empty($expirationDate) === false && $expirationDate >= date('Y-m-d')) { $validity = $expirationDate; if (empty($expirationTime) === false && $expirationTime > date('H:i:s')) { @@ -84,6 +85,8 @@ if ($create_token === true || $update_token === true) { } else { $validity .= ' 23:59:59'; } + } else if ($expirationDate < date('Y-m-d')) { + $error_date = true; } $values = [ @@ -95,16 +98,22 @@ if ($create_token === true || $update_token === true) { // Create token. if ($create_token === true) { try { - $token = create_user_token($values); - $smgInfo = __('This code will appear only once, please keep it in a safe place'); - $smgInfo .= '.
'; - $smgInfo .= __('If you lose the code, you will only able to delete it and create a new one'); - $smgInfo .= '.

'; - $smgInfo .= ''; - $smgInfo .= $token['token']; - $smgInfo .= ''; - $tokenMsg = ui_print_info_message($smgInfo, '', true); - ui_print_success_message(__('Successfully created')); + if ($error_date === false) { + $token = create_user_token($values); + $smgInfo = __('This code will appear only once, please keep it in a safe place'); + $smgInfo .= '.
'; + $smgInfo .= __('If you lose the code, you will only able to delete it and create a new one'); + $smgInfo .= '.

'; + $smgInfo .= ''; + $smgInfo .= $token['token']; + $smgInfo .= ''; + $tokenMsg = ui_print_info_message($smgInfo, '', true); + ui_print_success_message(__('Successfully created')); + } else { + ui_print_error_message( + __('Date expiration must be bigger than today') + ); + } } catch (\Exception $e) { ui_print_error_message( __('There was a problem creating this token, %s', $e->getMessage()) @@ -115,8 +124,14 @@ if ($create_token === true || $update_token === true) { // Update token. if ($update_token === true) { try { - $token = update_user_token($id_token, $values); - ui_print_success_message(__('Successfully updated')); + if ($error_date === false) { + $token = update_user_token($id_token, $values); + ui_print_success_message(__('Successfully updated')); + } else { + echo ui_print_error_message( + __('Date expiration must be bigger than today') + ); + } } catch (\Exception $e) { ui_print_error_message( __('There was a problem updating this token, %s', $e->getMessage()) diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 468dae0c4d..79ea2de93f 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -436,7 +436,7 @@ function ui_print_message($message, $class='', $attributes='', $return=false, $t $_SESSION['info_box_count']++; } - $position = (20 + ((int) $_SESSION['info_box_count'] * 100)); + $position = (20 + (int) $_SESSION['info_box_count']); $output = html_print_div( [