Webhook-Events & Health-Endpoint
- Notifier: controllerUnreachable, loginNewIp, updateAvailable - Login von neuer IP -> Webhook (Abgleich gegen audit_log) - cron_sync meldet nicht erreichbare Controller; cron_cleanup prüft täglich optional auf Updates und meldet Verfügbarkeit - health.php: Status-Endpoint (DB; optional Controller per ?deep=1&token=)
This commit is contained in:
parent
c7f9b7d39c
commit
0b1d4ec3b8
5 changed files with 116 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/Totp.php';
|
||||
require_once __DIR__ . '/Notifier.php';
|
||||
|
||||
class Auth {
|
||||
private $db;
|
||||
|
|
@ -71,6 +72,7 @@ class Auth {
|
|||
return 'totp_required';
|
||||
}
|
||||
|
||||
$this->notifyIfNewIp($user, $ip);
|
||||
$this->setUserSession($user);
|
||||
$this->updateLastLogin($user['id']);
|
||||
$this->writeAuditLog($user['id'], 'user_login', 'user', $user['id'], 'Login erfolgreich');
|
||||
|
|
@ -81,6 +83,19 @@ class Auth {
|
|||
return false;
|
||||
}
|
||||
|
||||
/** Webhook bei Login von einer für diesen Nutzer bisher unbekannten IP. */
|
||||
private function notifyIfNewIp($user, $ip) {
|
||||
try {
|
||||
$seen = $this->db->fetchOne(
|
||||
"SELECT 1 FROM audit_log WHERE user_id = ? AND action = 'user_login' AND ip_address = ? LIMIT 1",
|
||||
[$user['id'], $ip]
|
||||
);
|
||||
if (!$seen) {
|
||||
Notifier::loginNewIp($user['email'], $ip);
|
||||
}
|
||||
} catch (\Exception $e) { /* nie blockierend */ }
|
||||
}
|
||||
|
||||
/** Liegt ein Login vor, der noch auf den 2FA-Code wartet? */
|
||||
public function isTotpPending() {
|
||||
return isset($_SESSION['totp_pending_user_id'])
|
||||
|
|
@ -112,6 +127,7 @@ class Auth {
|
|||
return false;
|
||||
}
|
||||
unset($_SESSION['totp_pending_user_id'], $_SESSION['totp_pending_time']);
|
||||
$this->notifyIfNewIp($user, $this->clientIp());
|
||||
$this->setUserSession($user);
|
||||
$this->updateLastLogin($user['id']);
|
||||
$this->writeAuditLog($user['id'], 'user_login', 'user', $user['id'], 'Login erfolgreich (2FA)');
|
||||
|
|
|
|||
|
|
@ -41,6 +41,24 @@ class Notifier {
|
|||
curl_close($ch);
|
||||
}
|
||||
|
||||
/** Controller nicht erreichbar (z.B. beim Sync). */
|
||||
public static function controllerUnreachable($siteName, $detail = '') {
|
||||
self::send("⚠️ UniFi-Controller für \"{$siteName}\" nicht erreichbar." . ($detail ? " ({$detail})" : ''),
|
||||
['type' => 'controller_unreachable', 'site' => $siteName, 'detail' => $detail]);
|
||||
}
|
||||
|
||||
/** Anmeldung von einer bisher unbekannten IP. */
|
||||
public static function loginNewIp($email, $ip) {
|
||||
self::send("🔐 Neue Anmeldung für {$email} von IP {$ip}.",
|
||||
['type' => 'login_new_ip', 'email' => $email, 'ip' => $ip]);
|
||||
}
|
||||
|
||||
/** Update verfügbar. */
|
||||
public static function updateAvailable($sha) {
|
||||
self::send("⬆️ Update verfügbar (" . substr((string)$sha, 0, 7) . "). Siehe Administration → System-Update.",
|
||||
['type' => 'update_available', 'sha' => $sha]);
|
||||
}
|
||||
|
||||
/** Bequemer Helfer für erstellte Voucher. */
|
||||
public static function voucherCreated($count, $siteName, $byUser = null) {
|
||||
$who = $byUser ? " von {$byUser}" : '';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue