From e42c4575d5ba230c4b88a097d7b22d936b23183e Mon Sep 17 00:00:00 2001
From: Jose Gonzalez
Date: Thu, 16 Feb 2023 07:25:26 +0100
Subject: [PATCH] Double authentication active
---
.../godmode/users/configure_user.php | 933 +++++++++---------
.../godmode/users/user_management.php | 7 +-
.../include/ajax/double_auth.ajax.php | 94 +-
3 files changed, 546 insertions(+), 488 deletions(-)
diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php
index 6aa95574c6..fe8c781be5 100644
--- a/pandora_console/godmode/users/configure_user.php
+++ b/pandora_console/godmode/users/configure_user.php
@@ -1,4 +1,5 @@
'.__('Metaconsole access').' './* ui_print_help_icon('meta_access', true). */'
';
+ $meta_access = ''.__('Metaconsole access').' './* ui_print_help_icon('meta_access', true). */ '
';
$metaconsole_accesses = [
'basic' => __('Basic'),
'advanced' => __('Advanced'),
@@ -1531,27 +1532,50 @@ if (isset($config['ehorus_user_level_conf']) === true && (bool) $config['ehorus_
$ehorus .= '
';
}
-$double_auth_enabled = (bool) db_get_value('id', 'tuser_double_auth', 'id_user', $id);
-
+// Double authentication.
+$doubleAuthElementsContent = [];
if (isset($config['double_auth_enabled']) === true && (bool) ($config['double_auth_enabled']) === true && check_acl($config['id_user'], 0, 'PM')) {
- $double_authentication = ''.__('Double authentication').'
';
+ // Know if Double Auth is enabled.
+ $double_auth_enabled = (bool) db_get_value('id', 'tuser_double_auth', 'id_user', $id);
+ // Double authentication elements.
+ $doubleAuthElementsSubContent = [];
+ // Caption.
+ $doubleAuthElementsSubContent[] = '
'.__('Double authentication').'';
+ // Switch.
if (($config['2FA_all_users'] == '' && !$double_auth_enabled)
|| ($config['double_auth_enabled'] == '' && $double_auth_enabled)
|| check_acl($config['id_user'], 0, 'PM')
) {
if ($new_user === false) {
- $double_authentication .= html_print_checkbox_switch('double_auth', 1, $double_auth_enabled, true);
+ $doubleAuthElementsSubContent[] = html_print_checkbox_switch('double_auth', 1, $double_auth_enabled, true);
} else {
- $double_authentication .= ui_print_help_tip(__('User must be created before activating double authentication.'), true);
+ $doubleAuthElementsSubContent[] = ui_print_help_tip(__('User must be created before activating double authentication.'), true);
}
}
+ // Control for show.
+ $doubleAuthElementsContent[] = html_print_div(
+ [
+ 'style' => 'display: flex; flex-direction: row-reverse; align-items: center;',
+ 'class' => 'margin-top-10',
+ 'content' => implode('', $doubleAuthElementsSubContent),
+ ],
+ true
+ );
+
// Dialog.
- $double_authentication .= '
';
+ $doubleAuthElementsContent[] = html_print_div(
+ [
+ 'id' => 'dialog-double_auth',
+ 'class' => 'invisible',
+ 'content' => html_print_div(['id' => 'dialog-double_auth-container'], true),
+ ],
+ true
+ );
}
-if ($double_auth_enabled && $config['double_auth_enabled'] && $config['2FA_all_users'] != '') {
- $double_authentication .= html_print_button(
+if ($double_auth_enabled === true && (bool) $config['double_auth_enabled'] === true && empty($config['2FA_all_users']) === false) {
+ $doubleAuthElementsContent[] = html_print_button(
__('Show information'),
'show_info',
false,
@@ -1561,9 +1585,29 @@ if ($double_auth_enabled && $config['double_auth_enabled'] && $config['2FA_all_u
);
}
-if (isset($double_authentication)) {
+$doubleAuthentication = html_print_div(['content' => implode('', $doubleAuthElementsContent)], true);
+
+/*
+ if (isset($double_authentication)) {
$double_authentication .= '
';
-}
+}*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1870,7 +1914,7 @@ if (is_metaconsole() === false) {
+ $dialogContainer
+ .empty()
+ .append(message)
+ .append($button);
+
+ var request;
+
+ $button.click(function(e) {
+ e.preventDefault();
+
+ $dialogContainer.html($loadingSpinner);
+
+ // Deactivate the double auth
+ request = $.ajax({
+ url: "",
+ type: 'POST',
+ dataType: 'json',
+ data: {
+ page: 'include/ajax/double_auth.ajax',
+ id_user: userID,
+ FA_forced: 1,
+ deactivate_double_auth: 1
+ },
+ complete: function(xhr, textStatus) {
+
+ },
+ success: function(data, textStatus, xhr) {
+ if (data === -1) {
+ $dialogContainer.html("'.__('Authentication error').'
'; ?>");
+ } else if (data) {
+ $dialogContainer.html("'.__('The double autentication was deactivated successfully').'
'; ?>");
+ $("input#checkbox-double_auth").prop("checked", false);
+ } else {
+ $dialogContainer.html("'.__('There was an error deactivating the double autentication').'
'; ?>");
+ }
+ },
+ error: function(xhr, textStatus, errorThrown) {
+ $dialogContainer.html("'.__('There was an error deactivating the double autentication').'
'; ?>");
+ }
+ });
+ });
+
+
+ $("div#dialog-double_auth").dialog({
+ resizable: true,
+ draggable: true,
+ modal: true,
+ title: "",
+ overlay: {
+ opacity: 0.5,
+ background: "black"
+ },
+ width: 300,
+ height: 150,
+ close: function(event, ui) {
+ // Abort the ajax request
+ if (typeof request != 'undefined')
+ request.abort();
+ // Remove the contained html
+ $dialogContainer.empty();
+
+ }
+ })
+ .show();
+ }
+
+
+ /* ]]> */
+
\ No newline at end of file
diff --git a/pandora_console/godmode/users/user_management.php b/pandora_console/godmode/users/user_management.php
index 206725a4b6..c7e4ab43ee 100644
--- a/pandora_console/godmode/users/user_management.php
+++ b/pandora_console/godmode/users/user_management.php
@@ -220,6 +220,9 @@ $userManagementTable->data['fields_phone'][0] = html_print_input_text_extended(
true
);
+$userManagementTable->rowclass['captions_fields_admin_user'] = 'field_half_width w50p';
+$userManagementTable->cellclass['captions_fields_admin_user'][0] = 'wrap';
+$userManagementTable->data['captions_fields_admin_user'][0] = $doubleAuthentication;
if (users_is_admin() === true) {
$globalProfileContent = [];
$globalProfileContent[] = ''.__('Administrator user').'';
@@ -230,8 +233,8 @@ if (users_is_admin() === true) {
true
);
- $userManagementTable->rowclass['captions_fields_admin_user'] = 'field_half_width';
- $userManagementTable->data['captions_fields_admin_user'][0] = html_print_div(
+ $userManagementTable->cellclass['captions_fields_admin_user'][1] = 'wrap';
+ $userManagementTable->data['captions_fields_admin_user'][1] = html_print_div(
[
'class' => 'margin-top-10',
'style' => 'display: flex; flex-direction: row-reverse; align-items: center;',
diff --git a/pandora_console/include/ajax/double_auth.ajax.php b/pandora_console/include/ajax/double_auth.ajax.php
index 0f85c9c0f5..3a995ce43a 100644
--- a/pandora_console/include/ajax/double_auth.ajax.php
+++ b/pandora_console/include/ajax/double_auth.ajax.php
@@ -1,21 +1,39 @@
$id_user];
db_process_sql_delete('tuser_double_auth', $where);
- // Insert the new value
+ // Insert the new value.
$values = [
'id_user' => $id_user,
'secret' => $secret,
@@ -116,12 +134,12 @@ if ($save_double_auth_secret) {
return;
}
-// Disable the double auth for the user
+// Disable the double auth for the user.
$deactivate_double_auth = (bool) get_parameter('deactivate_double_auth');
if ($deactivate_double_auth) {
$result = false;
- // Delete the actual value (if exists)
+ // Delete the actual value (if exists).
$where = ['id_user' => $id_user];
$result = db_process_sql_delete('tuser_double_auth', $where);
@@ -129,7 +147,7 @@ if ($deactivate_double_auth) {
return;
}
-// Get the info page to the container dialog
+// Get the info page to the container dialog.
$get_double_auth_data_page = (bool) get_parameter('get_double_auth_data_page');
if ($get_double_auth_data_page) {
$secret = db_get_value('secret', 'tuser_double_auth', 'id_user', $id_user);
@@ -146,7 +164,7 @@ if ($get_double_auth_data_page) {
$html .= '
';
$html .= '';
$html .= '';
- $html .= __('Code').":
$secret";
+ $html .= __('Code').':
'.$secret.'';
$html .= '
';
$html .= __('QR').':
';
$html .= '
';
@@ -161,7 +179,7 @@ if ($get_double_auth_data_page) {
var secret = "";
var id_user_auth = "";
- // QR code with the secret to add it to the app
+ // QR code with the secret to add it to the app.
paint_qrcode("otpauth://totp/"+id_user_auth+"?secret="+secret, $("div#qr-container").get(0), 200, 200);
$("div#qr-container").attr("title", "").find("canvas").remove();
@@ -179,7 +197,7 @@ if ($get_double_auth_data_page) {
return;
}
-// Get the info page to the container dialog
+// Get the info page to the container dialog.
$get_double_auth_info_page = (bool) get_parameter('get_double_auth_info_page');
if ($get_double_auth_info_page) {
$container_id = (string) get_parameter('containerID');
@@ -209,14 +227,14 @@ if ($get_double_auth_info_page) {
ob_clean();
?>