Skip to content

Commit

Permalink
Merge pull request #4256 from corentin-soriano/upgrade_improvement
Browse files Browse the repository at this point in the history
BUGFIX - Upgrade process improvement and speedup
  • Loading branch information
nilsteampassnet authored Aug 25, 2024
2 parents 08a4fbb + 60b2493 commit fb9f5aa
Show file tree
Hide file tree
Showing 17 changed files with 284 additions and 199 deletions.
2 changes: 1 addition & 1 deletion includes/config/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
define('TP_COPYRIGHT', '2009-'.date('Y'));
define('TP_ALLOWED_TAGS', '<b><i><sup><sub><em><strong><u><br><br /><a><strike><ul><blockquote><blockquote><img><li><h1><h2><h3><h4><h5><ol><small><font>');
define('TP_FILE_PREFIX', 'EncryptedFile_');
define('NUMBER_ITEMS_IN_BATCH', 100);
define('NUMBER_ITEMS_IN_BATCH', 1000);
define('WIP', false);
define('UPGRADE_SEND_EMAILS', true);
define('KEY_LENGTH', 16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function migratePassword(string $hashedPassword, string $plainPassword, i
// Vérifiez si le mot de passe a été haché avec passwordlib
if ($this->isPasswordLibHash($hashedPassword)) {
// Utilisez la vérification de passwordlib ici
if ($this->passwordLibVerify($hashedPassword, $plainPassword)) {
if ($this->passwordLibVerify($hashedPassword, html_entity_decode($plainPassword))) {
// Password is valid, hash it with new system
$newHashedPassword = $this->hashPassword($plainPassword);
$userInfo['pw'] = $newHashedPassword;
Expand Down
18 changes: 11 additions & 7 deletions install/install.queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ function encryptFollowingDefuse($message, $ascii_key)
`object_id` int(12) NOT NULL,
`user_id` int(12) NOT NULL,
`share_key` text NOT NULL,
PRIMARY KEY (`increment_id`)
PRIMARY KEY (`increment_id`),
INDEX idx_object_user (`object_id`, `user_id`)
) CHARSET=utf8;'
);
$mysqli_result = mysqli_query(
Expand Down Expand Up @@ -471,7 +472,8 @@ function encryptFollowingDefuse($message, $ascii_key)
`updated_at` varchar(30) NULL,
`deleted_at` varchar(30) NULL,
PRIMARY KEY (`id`),
KEY `restricted_inactif_idx` (`restricted_to`,`inactif`)
KEY `restricted_inactif_idx` (`restricted_to`,`inactif`),
INDEX items_perso_id_idx (`perso`, `id`)
) CHARSET=utf8;"
);
} elseif ($task === 'log_items') {
Expand All @@ -486,7 +488,8 @@ function encryptFollowingDefuse($message, $ascii_key)
`raison` text NULL,
`old_value` MEDIUMTEXT NULL DEFAULT NULL,
`encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set',
PRIMARY KEY (`increment_id`)
PRIMARY KEY (`increment_id`),
INDEX log_items_item_action_user_idx (`id_item`, `action`, `id_user`)
) CHARSET=utf8;"
);
// create index
Expand Down Expand Up @@ -1311,13 +1314,14 @@ function encryptFollowingDefuse($message, $ascii_key)
$dbTmp,
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "background_tasks_logs` (
`increment_id` int(12) NOT NULL AUTO_INCREMENT,
`created_at` varchar(20) NOT NULL,
`created_at` INT NOT NULL,
`job` varchar(50) NOT NULL,
`status` varchar(10) NOT NULL,
`updated_at` varchar(20) DEFAULT NULL,
`finished_at` varchar(20) DEFAULT NULL,
`updated_at` INT DEFAULT NULL,
`finished_at` INT DEFAULT NULL,
`treated_objects` varchar(20) DEFAULT NULL,
PRIMARY KEY (`increment_id`)
PRIMARY KEY (`increment_id`),
INDEX idx_created_at (`created_at`)
) CHARSET=utf8;"
);
} else if ($task === 'ldap_groups_roles') {
Expand Down
2 changes: 1 addition & 1 deletion install/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ function aesEncrypt(text)
function manageUpgradeScripts(file_number)
{
var start_at = 0;
var noitems_by_loop = 100;
var noitems_by_loop = 1000;
var loop_number = 0;

if (file_number == 0) {
Expand Down
47 changes: 38 additions & 9 deletions install/upgrade_operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,15 @@
$port = DB_PORT;
$user = DB_USER;

if (mysqli_connect(
$server,
$user,
$pass,
$database,
$port
)) {
$db_link = mysqli_connect(
if ($db_link = mysqli_connect(
$server,
$user,
$pass,
$database,
$port
);
)
) {
$db_link->set_charset(DB_ENCODING);
} else {
$res = 'Impossible to get connected to server. Error is: ' . addslashes(mysqli_connect_error());
echo '[{"finish":"1", "msg":"", "error":"Impossible to get connected to server. Error is: ' . addslashes(mysqli_connect_error()) . '!"}]';
Expand All @@ -102,6 +97,9 @@
// ---->
// OPERATION - 20230604_1 - generate key for item_key

// Start transaction to avoid autocommit
mysqli_begin_transaction($db_link, MYSQLI_TRANS_START_READ_WRITE);

// Get items to treat
$rows = mysqli_query(
$db_link,
Expand All @@ -113,6 +111,8 @@
// Handle error on query
if (!$rows) {
echo '[{"finish":"1" , "error":"'.mysqli_error($db_link).'"}]';
mysqli_commit($db_link);
mysqli_close($db_link);
exit();
}

Expand All @@ -131,6 +131,8 @@
);
if (mysqli_error($db_link)) {
echo '[{"finish":"1", "next":"", "error":"MySQL Error! '.addslashes(mysqli_error($db_link)).'"}]';
mysqli_commit($db_link);
mysqli_close($db_link);
exit();
}
}
Expand Down Expand Up @@ -158,12 +160,17 @@
}
// Return back
echo '[{"finish":"'.$finish.'" , "next":"", "error":"", "total":"'.$total.'"}]';
// Commit transaction.
mysqli_commit($db_link);
}


function populateItemsTable_CreatedAt($pre, $post_nb)
{
global $db_link;
// Start transaction to avoid autocommit
mysqli_begin_transaction($db_link, MYSQLI_TRANS_START_READ_WRITE);

// loop on items - created_at
$items = mysqli_query(
$db_link,
Expand All @@ -190,12 +197,19 @@ function populateItemsTable_CreatedAt($pre, $post_nb)
"SELECT * FROM `" . $pre . "items` WHERE created_at IS NULL"
)
);

// Commit transaction.
mysqli_commit($db_link);

return $remainingItems > 0 ? 0 : 1;
}

function populateItemsTable_UpdatedAt($pre)
{
global $db_link;
// Start transaction to avoid autocommit
mysqli_begin_transaction($db_link, MYSQLI_TRANS_START_READ_WRITE);

// loop on items - updated_at
$items = mysqli_query(
$db_link,
Expand All @@ -212,12 +226,18 @@ function populateItemsTable_UpdatedAt($pre)
}
}

// Commit transaction.
mysqli_commit($db_link);

return 1;
}

function populateItemsTable_DeletedAt($pre)
{
global $db_link;
// Start transaction to avoid autocommit
mysqli_begin_transaction($db_link, MYSQLI_TRANS_START_READ_WRITE);

// loop on items - deleted_at
$items = mysqli_query(
$db_link,
Expand All @@ -234,6 +254,9 @@ function populateItemsTable_DeletedAt($pre)
}
}

// Commit transaction.
mysqli_commit($db_link);

return 1;
}

Expand Down Expand Up @@ -273,6 +296,9 @@ function installPurgeUnnecessaryKeys(bool $allUsers = true, int $user_id=0, stri
function installPurgeUnnecessaryKeysForUser(int $user_id=0, string $pre)
{
global $db_link;
// Start transaction to avoid autocommit
mysqli_begin_transaction($db_link, MYSQLI_TRANS_START_READ_WRITE);

if ($user_id === 0) {
return;
}
Expand Down Expand Up @@ -319,6 +345,9 @@ function installPurgeUnnecessaryKeysForUser(int $user_id=0, string $pre)
WHERE object_id IN ('.$pfItemsList.') AND user_id NOT IN ('.TP_USER_ID.', '.$user_id.')'
);
}

// Commit transaction.
mysqli_commit($db_link);
}


Expand Down
16 changes: 6 additions & 10 deletions install/upgrade_run_3.0.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,15 @@
$port = DB_PORT;
$user = DB_USER;

if (mysqli_connect(
$server,
$user,
$pass,
$database,
$port
)) {
$db_link = mysqli_connect(
if ($db_link = mysqli_connect(
$server,
$user,
$pass,
$database,
$port
);
)
) {
$db_link->set_charset(DB_ENCODING);
} else {
$res = 'Impossible to get connected to server. Error is: ' . addslashes(mysqli_connect_error());
echo '[{"finish":"1", "msg":"", "error":"Impossible to get connected to server. Error is: ' . addslashes(mysqli_connect_error()) . '!"}]';
Expand Down Expand Up @@ -248,7 +243,8 @@
`object_id` int(12) NOT NULL,
`user_id` int(12) NOT NULL,
`share_key` text NOT NULL,
PRIMARY KEY (`increment_id`)
PRIMARY KEY (`increment_id`),
INDEX idx_object_user (`object_id`, `user_id`)
) CHARSET=utf8;'
);

Expand Down
15 changes: 4 additions & 11 deletions install/upgrade_run_3.0.0_fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,14 @@
$port = DB_PORT;
$user = DB_USER;

if (mysqli_connect(
$server,
$user,
$pass,
$database,
$port
)
) {
$db_link = mysqli_connect(
if ($db_link = mysqli_connect(
$server,
$user,
$pass,
$database,
$port
);
)
) {
$db_link->set_charset(DB_ENCODING);
} else {
$res = 'Impossible to get connected to server. Error is: '.addslashes(mysqli_connect_error());
Expand Down Expand Up @@ -161,7 +154,7 @@
);

// Encrypt with Object Key
$cryptedStuff = doDataEncryption($passwd['string']);
$cryptedStuff = doDataEncryption(html_entity_decode($passwd['string']));

// Store new password in DB
mysqli_query(
Expand Down
13 changes: 3 additions & 10 deletions install/upgrade_run_3.0.0_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,14 @@
$port = DB_PORT;
$user = DB_USER;

if (mysqli_connect(
$server,
$user,
$pass,
$database,
$port
)
) {
$db_link = mysqli_connect(
if ($db_link = mysqli_connect(
$server,
$user,
$pass,
$database,
$port
);
)
) {
$db_link->set_charset(DB_ENCODING);
} else {
$res = 'Impossible to get connected to server. Error is: '.addslashes(mysqli_connect_error());
Expand Down
11 changes: 2 additions & 9 deletions install/upgrade_run_3.0.0_logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,14 @@
$port = DB_PORT;
$user = DB_USER;

if (mysqli_connect(
if ($db_link = mysqli_connect(
$server,
$user,
$pass,
$database,
$port
)
) {
$db_link = mysqli_connect(
$server,
$user,
$pass,
$database,
$port
);
$db_link->set_charset(DB_ENCODING);
} else {
$res = 'Impossible to get connected to server. Error is: '.addslashes(mysqli_connect_error());
Expand Down Expand Up @@ -163,7 +156,7 @@
);

// Encrypt with Object Key
$cryptedStuff = doDataEncryption($passwd['string']);
$cryptedStuff = doDataEncryption(html_entity_decode($passwd['string']));

// Store new password in DB
mysqli_query(
Expand Down
Loading

0 comments on commit fb9f5aa

Please sign in to comment.