Unifi-Voucher-Tool/includes/Notifier.php
Claude 9463486225
Erweiterte Features (2/2): Cleanup/DSGVO, Webhooks, REST-API, Backup, CI, Docker
- Auto-Cleanup/DSGVO: cron_cleanup.php (token-geschützt) löscht abgelaufene
  Voucher, Audit-Log, Login-Versuche und Reset-Tokens nach konfigurierbaren
  Fristen
- Webhooks: includes/Notifier.php (Slack/Teams/generisch), Auslösung bei
  Voucher-Erstellung (Web + API)
- REST-API: includes/ApiKey.php (SHA-256, Präfix-Lookup), api/bootstrap.php,
  api/vouchers.php (GET/POST), api/sites.php; admin/api_keys.php zur Verwaltung
- Config-Backup/Restore: admin/backup.php (JSON Export/Import, Cron-Token
  geschützt)
- admin/integrations.php: Trusted-Proxy, Webhook, Cleanup-Fristen
- CI: .github/workflows/ci.yml (php -l auf 7.4 & 8.2, lang-Validierung)
- Docker: Dockerfile, docker-compose.yml (MariaDB), entrypoint (config aus ENV),
  .dockerignore
- Nav + i18n (DE/EN) für alle neuen Admin-Seiten
2026-06-05 19:45:28 +00:00

53 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Notifier sendet Ereignis-Benachrichtigungen an einen konfigurierten
* Webhook (Slack / Microsoft Teams / generischer JSON-Endpunkt).
*
* Gesteuert über Einstellungen:
* webhook_enabled (0/1), webhook_url
*
* Sendet ein Slack/Teams-kompatibles { "text": "..." }-Payload plus ein
* strukturiertes "event"-Feld. Fehler werden still ignoriert eine
* Benachrichtigung darf nie den eigentlichen Vorgang blockieren.
*/
class Notifier {
/** Generisches Event senden. */
public static function send($text, array $data = []) {
try {
$db = Database::getInstance();
if ((string)$db->getSetting('webhook_enabled', '0') !== '1') {
return;
}
$url = trim((string)$db->getSetting('webhook_url', ''));
if ($url === '' || !filter_var($url, FILTER_VALIDATE_URL)) {
return;
}
} catch (\Exception $e) {
return;
}
$payload = json_encode(array_merge(['text' => $text], $data ? ['event' => $data] : []));
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
CURLOPT_CONNECTTIMEOUT => 3,
]);
@curl_exec($ch);
curl_close($ch);
}
/** Bequemer Helfer für erstellte Voucher. */
public static function voucherCreated($count, $siteName, $byUser = null) {
$who = $byUser ? " von {$byUser}" : '';
$what = $count > 1 ? "{$count} Voucher" : 'Ein Voucher';
self::send(
"🎫 {$what} für \"{$siteName}\"{$who} erstellt.",
['type' => 'voucher_created', 'count' => $count, 'site' => $siteName, 'user' => $byUser]
);
}
}