Files
html/api/dg-alert-ack.php

61 lines
1.7 KiB
PHP

<?php
// V37 DG Alert ACK API · doctrine 60 UX premium · reglage alertes business
// POST ?title=X&expires_h=24&note=...
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
$ACK_FILE = '/tmp/dg-alerts-ack.json';
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
$action = $_GET['action'] ?? ($_POST['action'] ?? 'list');
$acks = [];
if (file_exists($ACK_FILE)) {
$raw = @file_get_contents($ACK_FILE);
$decoded = @json_decode($raw, true);
if (is_array($decoded)) $acks = $decoded;
}
if ($action === 'ack' && $method === 'POST') {
$title = $_POST['title'] ?? '';
$expires_h = (int)($_POST['expires_h'] ?? 24);
$note = $_POST['note'] ?? 'acknowledged via DG';
$owner = $_POST['owner'] ?? 'Yacine';
if (empty($title)) {
echo json_encode(['error' => 'title required']);
exit;
}
$key = md5($title);
$acks[$key] = [
'title' => $title,
'ts' => date('c'),
'expires_h' => $expires_h,
'note' => $note,
'owner' => $owner
];
@file_put_contents($ACK_FILE, json_encode($acks, JSON_PRETTY_PRINT));
echo json_encode(['ok' => true, 'key' => $key, 'acked' => true, 'expires_h' => $expires_h]);
exit;
}
if ($action === 'unack' && $method === 'POST') {
$title = $_POST['title'] ?? '';
$key = md5($title);
unset($acks[$key]);
@file_put_contents($ACK_FILE, json_encode($acks, JSON_PRETTY_PRINT));
echo json_encode(['ok' => true, 'unacked' => true]);
exit;
}
if ($action === 'clear' && $method === 'POST') {
@unlink($ACK_FILE);
echo json_encode(['ok' => true, 'cleared' => true]);
exit;
}
// Default: list
echo json_encode(['acks' => $acks, 'count' => count($acks), 'ts' => date('c')]);