BastionGuard/webui/notification_action.php

35 lines
1.3 KiB
PHP

<?php
include 'auth.php';
bg_require_admin();
header('Content-Type: application/json; charset=utf-8');
csrf_validate();
$id = trim((string)($_POST['id'] ?? ''));
$action = trim((string)($_POST['action'] ?? ''));
$path = trim((string)($_POST['path'] ?? ''));
if ($id === '' || !in_array($action, ['ignore','quarantine'], true)) {
http_response_code(400);
echo json_encode(['ok'=>false, 'error'=>'Invalid request.']);
exit;
}
$matchingAlert = null;
foreach (bg_alerts_read(1000, true) as $alert) {
if (hash_equals((string)$alert['id'], $id)) { $matchingAlert = $alert; break; }
}
if ($matchingAlert === null || $path !== (string)$matchingAlert['path']) {
http_response_code(404);
echo json_encode(['ok'=>false, 'error'=>'Alert not found or path mismatch.']);
exit;
}
$out = '';
$code = 0;
if ($action === 'quarantine') {
$res = bg_quarantine_alert_path($path);
$code = (int)($res['code'] ?? 1);
$out = trim((string)($res['output'] ?? ''));
if ($code !== 0) {
echo json_encode(['ok'=>false, 'error'=>$out ?: 'Quarantine failed.', 'code'=>$code], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
exit;
}
}
bg_alert_mark_handled($id, $action);
echo json_encode(['ok'=>true, 'output'=>$out], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);