This commit is contained in:
2025-11-12 11:15:47 +01:00
parent a77cf5f9df
commit 2171cc3cfb
2 changed files with 35 additions and 0 deletions

28
functions/logging.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
// functions/logging.php
/**
* Logt een actie in de database.
*
* @param PDO $pdo PDO-verbinding
* @param string $gebruiker Gebruikersnaam
* @param string $actie Beschrijving van de actie
* @param string $extra Optioneel extra info
* @return bool true bij succes, false bij fout
*/
function log_action(PDO $pdo, string $gebruiker, string $actie, string $extra = ''): bool
{
try {
$stmt = $pdo->prepare(
"INSERT INTO log (gebruiker, actie, extra) VALUES (:gebruiker, :actie, :extra)"
);
return $stmt->execute([
':gebruiker' => $gebruiker,
':actie' => $actie,
':extra' => $extra
]);
} catch (PDOException $e) {
error_log("Logging fout: " . $e->getMessage());
return false;
}
}

View File

@@ -1,5 +1,7 @@
<?php <?php
require __DIR__ . '/auth/ldap.php'; require __DIR__ . '/auth/ldap.php';
require __DIR__ . '/data/db.php'; // $pdo
require __DIR__ . '/functions/logging.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? ''; $username = $_POST['username'] ?? '';
@@ -17,8 +19,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
echo "<li>Email: " . htmlspecialchars($user['email']) . "</li>"; echo "<li>Email: " . htmlspecialchars($user['email']) . "</li>";
echo "<li>UserPrincipalName: " . htmlspecialchars($user['userPrincipalName']) . "</li>"; echo "<li>UserPrincipalName: " . htmlspecialchars($user['userPrincipalName']) . "</li>";
echo "</ul>"; echo "</ul>";
// Log de succesvolle login
log_action($pdo, $user['username'], 'Inloggen via LDAP', 'Test-login script');
} else { } else {
echo "<p style='color:red;'>❌ Ongeldige inloggegevens.</p>"; echo "<p style='color:red;'>❌ Ongeldige inloggegevens.</p>";
// Optioneel log mislukte login
log_action($pdo, $username, 'Mislukte login via LDAP', 'Test-login script');
} }
} }
?> ?>