diff --git a/model/TotpPf.php b/model/TotpPf.php index 14865dbd..f8d73611 100644 --- a/model/TotpPf.php +++ b/model/TotpPf.php @@ -69,7 +69,8 @@ class TotpPf return false; } - $sql = "SELECT totp_secret FROM {$this->table} WHERE username = :username AND active = :active"; + $table_name = table_by_key($this->table); + $sql = "SELECT totp_secret FROM $table_name WHERE username = :username AND active = :active"; $active = db_get_boolean(true); @@ -93,7 +94,8 @@ class TotpPf */ public function checkUserTOTP(string $username, string $code): bool { - $sql = "SELECT totp_secret FROM {$this->table} WHERE username = :username AND active = :active"; + $table_name = table_by_key($this->table); + $sql = "SELECT totp_secret FROM $table_name WHERE username = :username AND active = :active"; $active = db_get_boolean(true); @@ -129,7 +131,8 @@ class TotpPf public function removeTotpFromUser(string $username): void { - $sql = "UPDATE {$this->table} SET totp_secret = NULL WHERE username = :username"; + $table_name = table_by_key($this->table); + $sql = "UPDATE $table_name SET totp_secret = NULL WHERE username = :username"; db_execute($sql, ['username' => $username]); } @@ -146,7 +149,8 @@ class TotpPf throw new \Exception(Config::Lang('pPassword_password_current_text_error')); } - $sql = "SELECT totp_secret FROM {$this->table} WHERE username = :username AND active = :active"; + $table_name = table_by_key($this->table); + $sql = "SELECT totp_secret FROM $table_name WHERE username = :username AND active = :active"; $active = db_get_boolean(true); @@ -309,8 +313,10 @@ class TotpPf if ($error == 0) { // OK to insert/replace. + + $totp_exception_address = table_by_key('totp_exception_address'); // As PostgeSQL lacks REPLACE we first check and delete any previous rows matching this ip and user - $exists = db_query_all('SELECT id FROM totp_exception_address WHERE ip = :ip AND username = :username', + $exists = db_query_all("SELECT id FROM $totp_exception_address WHERE ip = :ip AND username = :username", ['ip' => $ip_address, 'username' => $exception_username]); if (isset($exists[0])) { foreach ($exists as $x) { @@ -405,7 +411,8 @@ class TotpPf } - $result = db_execute('DELETE FROM totp_exception_address WHERE id = :id', ['id' => $id]); + $totp_exception_address = table_by_key('totp_exception_address'); + $result = db_execute("DELETE FROM $totp_exception_address WHERE id = :id", ['id' => $id]); if ($result != 1) { db_log($Exception_domain, 'pViewlog_action_delete_totp_exception', "FAILURE: " . $username); @@ -449,7 +456,8 @@ class TotpPf */ public function getAllExceptions(): array { - return db_query_all("SELECT * FROM totp_exception_address"); + $totp_exception_address = table_by_key('totp_exception_address'); + return db_query_all("SELECT * FROM $totp_exception_address"); } /** @@ -460,7 +468,8 @@ class TotpPf public function getExceptionsFor(string $username): array { list($local_part, $domain) = explode('@', $username); - return db_query_all("SELECT * FROM totp_exception_address WHERE username = :username OR username = :domain OR username IS NULL", ['username' => $username, 'domain' => $domain]); + $totp_exception_address = table_by_key('totp_exception_address'); + return db_query_all("SELECT * FROM $totp_exception_address WHERE username = :username OR username = :domain OR username IS NULL", ['username' => $username, 'domain' => $domain]); } /** @@ -470,6 +479,7 @@ class TotpPf */ public function getException(int $id): ?array { - return db_query_one("SELECT * FROM totp_exception_address WHERE id = :id", ['id' => $id]); + $totp_exception_address = table_by_key('totp_exception_address'); + return db_query_one("SELECT * FROM $totp_exception_address WHERE id = :id", ['id' => $id]); } } diff --git a/public/setup.php b/public/setup.php index 6485c5cd..785c0cae 100644 --- a/public/setup.php +++ b/public/setup.php @@ -301,11 +301,15 @@ if ($authenticated) { $php_error_log = ini_get('error_log'); } else { if (!empty($check['error'])) { - echo '
Hosting Environment errors found. Login to see details.
'; } if (!empty($check['warn'])) { - echo 'Hosting Environment warnings found. Login to see details.
'; + } + + if (empty($check['warn']) && empty($check['error'])) { + echo "$tick No problems detected.
"; } } @@ -316,188 +320,195 @@ if ($authenticated) {Everything seems fine... attempting to create/update database structure
\n"; + echo "Exception message: {$e->getMessage()} - check logs!
"; + echo "Something went wrong while trying to apply database updates, a message should be logged - check PHP's error_log (" . ini_get('error_log') . ')
'; + echo "Admin addition failed; check field error messages or server logs.
"; - } else { - // all good!. - $setupMessage .= "You are done with your basic setup. You can now login to PostfixAdmin using the account you just created.
"; - } - - echo "Admin addition failed; check field error messages or server logs.
"; + } else { + // all good!. + $setupMessage .= "You are done with your basic setup. You can now login to PostfixAdmin using the account you just created.
"; + } -The following 'super-admin' accounts have already been added to the database.
-= $setupMessage ?>
-