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
This commit is contained in:
parent
eec28f77b8
commit
9463486225
18 changed files with 972 additions and 0 deletions
53
includes/Notifier.php
Normal file
53
includes/Notifier.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?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]
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue