fix: fix boolean return type in totp.php, handle multi-statement sql and enable error reporting
This commit is contained in:
@@ -15,6 +15,7 @@ if (has_admin_user()) {
|
|||||||
$error = null;
|
$error = null;
|
||||||
$success = false;
|
$success = false;
|
||||||
$backupCodes = [];
|
$backupCodes = [];
|
||||||
|
$email = '';
|
||||||
|
|
||||||
// Haal of genereer een tijdelijke sessie-sleutel voor de 2FA configuratie
|
// Haal of genereer een tijdelijke sessie-sleutel voor de 2FA configuratie
|
||||||
if (empty($_SESSION['setup_totp_secret'])) {
|
if (empty($_SESSION['setup_totp_secret'])) {
|
||||||
|
|||||||
@@ -6,3 +6,4 @@
|
|||||||
"ext-mysqli": "*"
|
"ext-mysqli": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,3 +80,10 @@ define('APP_ENV', fociz_env('APP_ENV', 'development')); // 'development' of 'liv
|
|||||||
|
|
||||||
// Tijdzone
|
// Tijdzone
|
||||||
date_default_timezone_set('Europe/Amsterdam');
|
date_default_timezone_set('Europe/Amsterdam');
|
||||||
|
|
||||||
|
// Foutrapportage: in development tonen we fouten direct op het scherm
|
||||||
|
if (APP_ENV !== 'live') {
|
||||||
|
ini_set('display_errors', '1');
|
||||||
|
ini_set('display_startup_errors', '1');
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
}
|
||||||
|
|||||||
+12
-3
@@ -53,6 +53,9 @@ function get_db_connection(): PDO {
|
|||||||
PDO::ATTR_EMULATE_PREPARES => false,
|
PDO::ATTR_EMULATE_PREPARES => false,
|
||||||
PDO::ATTR_TIMEOUT => 5,
|
PDO::ATTR_TIMEOUT => 5,
|
||||||
];
|
];
|
||||||
|
if (defined('PDO::MYSQL_ATTR_MULTI_STATEMENTS')) {
|
||||||
|
$options[PDO::MYSQL_ATTR_MULTI_STATEMENTS] = true;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$pdo = new PDO($dsn, DB_USER, DB_PASS, $options);
|
$pdo = new PDO($dsn, DB_USER, DB_PASS, $options);
|
||||||
@@ -100,10 +103,16 @@ function ensure_tables_exist(PDO $pdo): void {
|
|||||||
$schemaFile = __DIR__ . '/../schema.sql';
|
$schemaFile = __DIR__ . '/../schema.sql';
|
||||||
if (file_exists($schemaFile)) {
|
if (file_exists($schemaFile)) {
|
||||||
$sql = file_get_contents($schemaFile);
|
$sql = file_get_contents($schemaFile);
|
||||||
$pdo->exec($sql);
|
// Splits op puntkomma om elk CREATE TABLE statement apart uit te voeren
|
||||||
|
$statements = array_filter(array_map('trim', explode(';', $sql)));
|
||||||
|
foreach ($statements as $stmt) {
|
||||||
|
if (!empty($stmt)) {
|
||||||
|
$pdo->exec($stmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (PDOException $e) {
|
}
|
||||||
// Tabellen bestaan waarschijnlijk al
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log("Fout bij uitvoeren schema.sql: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -13,7 +13,6 @@ function start_secure_session(): void {
|
|||||||
session_set_cookie_params([
|
session_set_cookie_params([
|
||||||
'lifetime' => 7 * 24 * 60 * 60, // 7 dagen
|
'lifetime' => 7 * 24 * 60 * 60, // 7 dagen
|
||||||
'path' => '/',
|
'path' => '/',
|
||||||
'domain' => '',
|
|
||||||
'secure' => $isSecure,
|
'secure' => $isSecure,
|
||||||
'httponly' => true,
|
'httponly' => true,
|
||||||
'samesite' => 'Lax'
|
'samesite' => 'Lax'
|
||||||
@@ -26,9 +25,13 @@ function start_secure_session(): void {
|
|||||||
* Controleert of er al een beheerder bestaat in MariaDB
|
* Controleert of er al een beheerder bestaat in MariaDB
|
||||||
*/
|
*/
|
||||||
function has_admin_user(): bool {
|
function has_admin_user(): bool {
|
||||||
|
try {
|
||||||
$db = get_db_connection();
|
$db = get_db_connection();
|
||||||
$stmt = $db->query("SELECT COUNT(*) FROM users WHERE role = 'ADMIN'");
|
$stmt = $db->query("SELECT COUNT(*) FROM users WHERE role = 'ADMIN'");
|
||||||
return ((int)$stmt->fetchColumn()) > 0;
|
return ((int)$stmt->fetchColumn()) > 0;
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -76,7 +76,7 @@ class TOTP {
|
|||||||
/**
|
/**
|
||||||
* Verifieert een ingevoerde 6-cijferige 2FA code (met 1 tijdstap speling naar voor/achter)
|
* Verifieert een ingevoerde 6-cijferige 2FA code (met 1 tijdstap speling naar voor/achter)
|
||||||
*/
|
*/
|
||||||
public static function verifyCode(string $secret, string $userInputCode, int $window = 1): boolean {
|
public static function verifyCode(string $secret, string $userInputCode, int $window = 1): bool {
|
||||||
$userInputCode = trim(str_replace(' ', '', $userInputCode));
|
$userInputCode = trim(str_replace(' ', '', $userInputCode));
|
||||||
if (strlen($userInputCode) !== 6 || !ctype_digit($userInputCode)) {
|
if (strlen($userInputCode) !== 6 || !ctype_digit($userInputCode)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user