/** * Decrypts email, ftp and SQL users passwords in database * * @return array SQL statements to be executed */ protected function r53() { $sqlUpd = array(); // Decrypt all mail passwords $stmt = execute_query("\n\t\t\t\tSELECT\n\t\t\t\t\tmail_id, mail_pass\n\t\t\t\tFROM\n\t\t\t\t\tmail_users\n\t\t\t\tWHERE\n\t\t\t\t\tmail_type RLIKE '^(normal_mail|alias_mail|subdom_mail|alssub_mail)'\n\t\t\t"); if ($stmt->rowCount()) { while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) { $password = quoteValue(decryptBlowfishCbcPassword($row['mail_pass'])); $status = quoteValue('tochange'); $mailId = quoteValue($row['mail_id'], PDO::PARAM_INT); $sqlUpd[] = "UPDATE mail_users SET mail_pass = {$password}, status = {$status} WHERE mail_id = {$mailId}"; } } // Decrypt all SQL users passwords $stmt = exec_query('SELECT sqlu_id, sqlu_pass FROM sql_user'); if ($stmt->rowCount()) { while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) { $password = quoteValue(decryptBlowfishCbcPassword($row['sqlu_pass'])); $id = quoteValue($row['sqlu_id'], PDO::PARAM_INT); $sqlUpd[] = "UPDATE sql_user SET sqlu_pass = {$password} WHERE sqlu_id = {$id}"; } } // Decrypt all Ftp users passwords $stmt = exec_query('SELECT userid, passwd FROM ftp_users'); if ($stmt->rowCount()) { while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) { $password = quoteValue(decryptBlowfishCbcPassword($row['passwd'])); $userId = quoteValue($row['userid']); $sqlUpd[] = "UPDATE ftp_users SET rawpasswd = {$password} WHERE userid = {$userId}"; } } return $sqlUpd; }
/** * Establishes the connection to the database server * * This methods establishes the default connection to the database server by using configuration parameters that * come from the basis configuration object and then, register the {@link iMSCP_Database} instance in the * {@link iMSCP_Registry} for further usage. * * A PDO instance is also registered in the registry for further usage. * * @throws iMSCP_Exception_Database|iMSCP_Exception * @return void */ protected function initializeDatabase() { try { $db_pass_key = $db_pass_iv = ''; eval(@file_get_contents($this->config->CONF_DIR . '/imscp-db-keys')); if (!empty($db_pass_key) && !empty($db_pass_iv)) { iMSCP_Registry::set('MCRYPT_KEY', $db_pass_key); iMSCP_Registry::set('MCRYPT_IV', $db_pass_iv); $connection = iMSCP_Database::connect($this->config->DATABASE_USER, decryptBlowfishCbcPassword($this->config->DATABASE_PASSWORD), $this->config->DATABASE_TYPE, $this->config->DATABASE_HOST, $this->config->DATABASE_NAME); if (!$connection->execute('SET NAMES `utf8`')) { throw new iMSCP_Exception(sprintf('Unable to set charset for database communication. SQL returned: %s', $connection->errorMsg())); } } else { throw new iMSCP_Exception('Database key and/or initialization vector was not generated.'); } } catch (PDOException $e) { throw new iMSCP_Exception_Database('Unable to establish the connection to the database. SQL returned: ' . $e->getMessage()); } // Register Database instance in registry for further usage. iMSCP_Registry::set('db', $connection); }