From 88f7986aedf88b3bd612263cb0ce38a3bb55dd10 Mon Sep 17 00:00:00 2001 From: nilsteampassnet Date: Mon, 3 Jul 2023 15:45:35 +0200 Subject: [PATCH] 3.0.9 Improvements on logs (#3759) --- includes/language/bulgarian.php | 3 + includes/language/catalan.php | 3 + includes/language/chinese.php | 3 + includes/language/czech.php | 3 + includes/language/dutch.php | 3 + includes/language/english.php | 3 + includes/language/estonian.php | 3 + includes/language/french.php | 3 + includes/language/german.php | 3 + includes/language/greek.php | 3 + includes/language/hungarian.php | 3 + includes/language/italian.php | 3 + includes/language/japanese.php | 3 + includes/language/norwegian.php | 3 + includes/language/polish.php | 3 + includes/language/portuguese.php | 3 + includes/language/portuguese_br.php | 3 + includes/language/romanian.php | 3 + includes/language/russian.php | 3 + includes/language/spanish.php | 3 + includes/language/swedish.php | 3 + includes/language/turkish.php | 3 + includes/language/ukrainian.php | 3 + includes/language/vietnamese.php | 3 + install/install.queries.php | 3 + install/upgrade_run_3.0.0.php | 1 - install/upgrade_run_3.0.php | 87 ++++++++++++++++++++++++++++- pages/utilities.logs.php | 15 ++--- sources/logs.datatables.php | 35 ++++++++++-- sources/users.datatable.php | 7 +++ sources/users.queries.php | 10 +++- 31 files changed, 216 insertions(+), 14 deletions(-) diff --git a/includes/language/bulgarian.php b/includes/language/bulgarian.php index ef2239291..d7a1c78a4 100755 --- a/includes/language/bulgarian.php +++ b/includes/language/bulgarian.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/catalan.php b/includes/language/catalan.php index 1619e1ffb..6fb4d4de1 100755 --- a/includes/language/catalan.php +++ b/includes/language/catalan.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/chinese.php b/includes/language/chinese.php index ff0bb3c5e..48ab2d737 100755 --- a/includes/language/chinese.php +++ b/includes/language/chinese.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/czech.php b/includes/language/czech.php index a586a7a95..c9db0bebb 100755 --- a/includes/language/czech.php +++ b/includes/language/czech.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/dutch.php b/includes/language/dutch.php index f87c93a59..c8f07b4b7 100755 --- a/includes/language/dutch.php +++ b/includes/language/dutch.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/english.php b/includes/language/english.php index e92377ce1..892953721 100755 --- a/includes/language/english.php +++ b/includes/language/english.php @@ -16,6 +16,9 @@ * @see https://www.teampass.net */ return array( + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', 'error_while_creating_file' => 'Error while creating file', 'field' => 'Field', 'exceeds_maximum_length_of' => 'exceeds maximum length of', diff --git a/includes/language/estonian.php b/includes/language/estonian.php index 01d909a03..5db5794af 100755 --- a/includes/language/estonian.php +++ b/includes/language/estonian.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/french.php b/includes/language/french.php index 5400ec45c..83f5e34e2 100755 --- a/includes/language/french.php +++ b/includes/language/french.php @@ -1101,5 +1101,8 @@ 'day' => 'Jour', 'reset' => 'Réinitialiser', 'error_while_creating_file' => 'Création du fichier impossible', + 'new_keys_generated' => 'Nouvelles clés générées', + 'user_creation' => 'Utilisateur créé', + 'user_deletion' => 'Utilisateur supprimé', ); diff --git a/includes/language/german.php b/includes/language/german.php index 5ded49b75..a78a73aa6 100755 --- a/includes/language/german.php +++ b/includes/language/german.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/greek.php b/includes/language/greek.php index e9adaeace..2452dfffd 100755 --- a/includes/language/greek.php +++ b/includes/language/greek.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/hungarian.php b/includes/language/hungarian.php index 4c4ca7d19..ca592a423 100755 --- a/includes/language/hungarian.php +++ b/includes/language/hungarian.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/italian.php b/includes/language/italian.php index 912bb0232..099c25f20 100755 --- a/includes/language/italian.php +++ b/includes/language/italian.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/japanese.php b/includes/language/japanese.php index 3f0bad724..d726ed041 100755 --- a/includes/language/japanese.php +++ b/includes/language/japanese.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/norwegian.php b/includes/language/norwegian.php index 14fdb8d68..b981a5d59 100755 --- a/includes/language/norwegian.php +++ b/includes/language/norwegian.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/polish.php b/includes/language/polish.php index be09e1d7e..4d6b8eb77 100755 --- a/includes/language/polish.php +++ b/includes/language/polish.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/portuguese.php b/includes/language/portuguese.php index 0c2955a74..8c2fd3a51 100755 --- a/includes/language/portuguese.php +++ b/includes/language/portuguese.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/portuguese_br.php b/includes/language/portuguese_br.php index cd83c046e..01de710d6 100755 --- a/includes/language/portuguese_br.php +++ b/includes/language/portuguese_br.php @@ -1101,5 +1101,8 @@ 'day' => 'Dia', 'reset' => 'Redefinir', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/romanian.php b/includes/language/romanian.php index 77f0daa65..ce00c78d0 100755 --- a/includes/language/romanian.php +++ b/includes/language/romanian.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/russian.php b/includes/language/russian.php index 09164be2b..2eba236be 100755 --- a/includes/language/russian.php +++ b/includes/language/russian.php @@ -1102,5 +1102,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/spanish.php b/includes/language/spanish.php index 26d0b717c..fde17a8e9 100755 --- a/includes/language/spanish.php +++ b/includes/language/spanish.php @@ -1101,5 +1101,8 @@ 'day' => 'Día', 'reset' => 'Restablecer', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/swedish.php b/includes/language/swedish.php index f047df1ad..5fae328b8 100755 --- a/includes/language/swedish.php +++ b/includes/language/swedish.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/turkish.php b/includes/language/turkish.php index a6b7f2670..72e2df1b8 100755 --- a/includes/language/turkish.php +++ b/includes/language/turkish.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/ukrainian.php b/includes/language/ukrainian.php index 9c49d66af..4ae32e12f 100755 --- a/includes/language/ukrainian.php +++ b/includes/language/ukrainian.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/includes/language/vietnamese.php b/includes/language/vietnamese.php index 619f8d064..fb6b642cc 100755 --- a/includes/language/vietnamese.php +++ b/includes/language/vietnamese.php @@ -1101,5 +1101,8 @@ 'day' => 'Day', 'reset' => 'Reset', 'error_while_creating_file' => 'Error while creating file', + 'new_keys_generated' => 'New keys generated', + 'user_creation' => 'User creation', + 'user_deletion' => 'User deletion', ); diff --git a/install/install.queries.php b/install/install.queries.php index 0b494f5f7..6e72e793e 100755 --- a/install/install.queries.php +++ b/install/install.queries.php @@ -787,6 +787,9 @@ function encryptFollowingDefuse($message, $ascii_key) `roles_from_ad_groups` varchar(1000) NULL, `ongoing_process_id` VARCHAR(100) NULL, `mfa_enabled` tinyint(1) NOT null DEFAULT '1', + `created_at` varchar(30) NULL, + `updated_at` varchar(30) NULL, + `deleted_at` varchar(30) NULL, PRIMARY KEY (`id`), UNIQUE KEY `login` (`login`) ) CHARSET=utf8;" diff --git a/install/upgrade_run_3.0.0.php b/install/upgrade_run_3.0.0.php index 9020165f8..ed39ac73e 100755 --- a/install/upgrade_run_3.0.0.php +++ b/install/upgrade_run_3.0.0.php @@ -1195,7 +1195,6 @@ mysqli_query( $db_link, "ALTER TABLE `" . $pre . "export` - MODIFY COLUMN `id` int(12) NOT NULL, MODIFY COLUMN `label` VARCHAR(500) NOT NULL, MODIFY COLUMN `path` VARCHAR(500) NOT NULL;" ); diff --git a/install/upgrade_run_3.0.php b/install/upgrade_run_3.0.php index 5d85f736b..30e7177a4 100755 --- a/install/upgrade_run_3.0.php +++ b/install/upgrade_run_3.0.php @@ -314,6 +314,51 @@ "int(12) NOT NULL" ); +// Add field created_at to USERS table +$res = addColumnIfNotExist( + $pre . 'users', + 'created_at', + "varchar(30) NULL;" +); +if ($res === false) { + echo '[{"finish":"1", "msg":"", "error":"An error appears when adding field created_at to table USERS! ' . mysqli_error($db_link) . '!"}]'; + mysqli_close($db_link); + exit(); +} + +// Add field updated_at to USERS table +$res = addColumnIfNotExist( + $pre . 'users', + 'updated_at', + "varchar(30) NULL;" +); +if ($res === false) { + echo '[{"finish":"1", "msg":"", "error":"An error appears when adding field updated_at to table USERS! ' . mysqli_error($db_link) . '!"}]'; + mysqli_close($db_link); + exit(); +} + +// Add field deleted_at to USERS table +$res = addColumnIfNotExist( + $pre . 'users', + 'deleted_at', + "varchar(30) NULL;" +); +if ($res === false) { + echo '[{"finish":"1", "msg":"", "error":"An error appears when adding field deleted_at to table USERS! ' . mysqli_error($db_link) . '!"}]'; + mysqli_close($db_link); + exit(); +} + +// +$tmp = mysqli_num_rows(mysqli_query($db_link, "SELECT * FROM `" . $pre . "users` WHERE created_at IS NOT NULL")); +if (intval($tmp) === 0) { + populateUsersTable($pre); +} + + +// populate created_at, updated_at and deleted_at fields in USERS table + //---
- +
@@ -109,7 +109,7 @@
- +
@@ -120,7 +120,7 @@
- +
@@ -131,18 +131,19 @@
- +
- + +
- +
@@ -157,7 +158,7 @@
- +
diff --git a/sources/logs.datatables.php b/sources/logs.datatables.php index 6e471f0aa..89b028519 100755 --- a/sources/logs.datatables.php +++ b/sources/logs.datatables.php @@ -328,7 +328,7 @@ */ } elseif (isset($_GET['action']) && $_GET['action'] === 'admin') { //Columns name - $aColumns = ['l.date', 'u.login', 'l.label']; + $aColumns = ['l.date', 'u.login', 'l.label', 'l.field_1']; //Ordering if (isset($_GET['order'][0]['dir']) === true && in_array($_GET['order'][0]['dir'], $aSortTypes) === true @@ -343,7 +343,7 @@ } // Filtering - $sWhere = "WHERE l.type = 'admin_action'"; + $sWhere = "WHERE l.type IN ('admin_action', 'user_mngt')"; if (isset($_GET['search']['value']) === true && $_GET['search']['value'] !== '') { $sWhere .= ' AND ('; for ($i = 0; $i < count($aColumns); ++$i) { @@ -359,7 +359,7 @@ $sWhere ); $rows = DB::query( - 'SELECT l.date as date, u.login as login, u.name AS name, u.lastname AS lastname, l.label as label + 'SELECT l.date as date, u.login as login, u.name AS name, u.lastname AS lastname, l.label as label, l.field_1 as field_1 FROM '.prefixTable('log_system').' as l INNER JOIN '.prefixTable('users').' as u ON (l.qui=u.id) '. $sWhere. @@ -383,7 +383,34 @@ //col2 $sOutput_item .= '"'.htmlspecialchars(stripslashes((string) $record['login']), ENT_QUOTES).'", '; //col3 - $sOutput_item .= '"'.htmlspecialchars(stripslashes((string) $record['label']), ENT_QUOTES).'" '; + if ($record['label'] === 'at_user_added') { + $cell = langHdl('user_creation'); + } elseif ($record['label'] === 'at_user_deleted' || $record['label'] === 'user_deleted') { + $cell = langHdl('user_deletion'); + } elseif ($record['label'] === 'at_user_updated') { + $cell = langHdl('user_updated'); + } elseif (strpos($record['label'], 'at_user_email_changed') !== false) { + $change = explode(':', $record['label']); + $cell = langHdl('log_user_email_changed').' '.$change[1]; + } elseif ($record['label'] === 'at_user_new_keys') { + $cell = langHdl('new_keys_generated'); + } else { + $cell = htmlspecialchars(stripslashes((string) $record['label']), ENT_QUOTES); + } + $sOutput_item .= '"'.$cell.'" '; + //col4 + if (empty($record['field_1']) === false) { + // get user name + $info = DB::queryfirstrow( + 'SELECT u.login as login, u.name AS name, u.lastname AS lastname + FROM '.prefixTable('users').' as u + WHERE u.id = %i', + $record['field_1'] + ); + $sOutput_item .= ', "'.(empty($info['name']) === false ? htmlspecialchars(stripslashes((string) $info['name'].' '.$info['lastname']), ENT_QUOTES) : 'Removed user ('.$record['field_1'].')').'" '; + } else { + $sOutput_item .= ', "" '; + } //Finish the line $sOutput_item .= '], '; if ($get_item_in_list === true) { diff --git a/sources/users.datatable.php b/sources/users.datatable.php index f2f9f7f92..0694f2f35 100755 --- a/sources/users.datatable.php +++ b/sources/users.datatable.php @@ -146,6 +146,13 @@ } } +// exclude any deleted user +if (empty($sWhere) === true) { + $sWhere = ' WHERE deleted_at IS NULL '; +} else { + $sWhere .= ' AND deleted_at IS NULL '; +} + $rows = DB::query( 'SELECT * FROM '.prefixTable('users'). $sWhere. diff --git a/sources/users.queries.php b/sources/users.queries.php index 45bf0fae1..f370fe3f0 100755 --- a/sources/users.queries.php +++ b/sources/users.queries.php @@ -409,10 +409,18 @@ || ((int) $_SESSION['user_can_manage_all_users'] === 1 && (int) $data_user['admin'] !== 1) ) { // delete user in database - DB::delete( + /*DB::delete( prefixTable('users'), 'id = %i', $post_id + );*/ + DB::update( + prefixTable('users'), + array( + 'deleted_at' => time(), + ), + 'id = %i', + $post_id ); // delete user api DB::delete(