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