@@ -65,6 +65,8 @@ class Router
|
||||
$path === '/rules' && $method === 'POST' => $this->createRule(),
|
||||
preg_match('#^/rules/(\d+)$#', $path, $m) && $method === 'DELETE'
|
||||
=> $this->deleteEntity('rule', (int) $m[1]),
|
||||
preg_match('#^/rules/(\d+)$#', $path, $m) && $method === 'PUT'
|
||||
=> $this->updateRule((int) $m[1]),
|
||||
|
||||
$path === '/alerts' && $method === 'GET' => $this->getAlerts(),
|
||||
$path === '/alerts/search' && $method === 'GET' => $this->searchAlerts(),
|
||||
@@ -185,6 +187,19 @@ class Router
|
||||
return ['status' => 'deleted', 'id' => $id];
|
||||
}
|
||||
|
||||
private function updateRule(int $id): mixed
|
||||
{
|
||||
$body = json_decode(file_get_contents('php://input'), true);
|
||||
return $this->repo->updateRule(
|
||||
id: $id,
|
||||
name: $body['name'],
|
||||
pattern: $body['pattern'],
|
||||
severity: $body['severity'] ?? 'warning',
|
||||
rateLimitSeconds: $body['rate_limit_seconds'] ?? null,
|
||||
active: $body['active'] ?? true,
|
||||
);
|
||||
}
|
||||
|
||||
private function getAlerts(): mixed
|
||||
{
|
||||
$limit = (int) ($_GET['limit'] ?? 100);
|
||||
|
||||
@@ -82,6 +82,15 @@ class Repository
|
||||
$this->db->pdo()->prepare("DELETE FROM rules WHERE id = ?")->execute([$id]);
|
||||
}
|
||||
|
||||
public function updateRule(int $id, string $name, string $pattern, string $severity, ?int $rateLimitSeconds = null, bool $active = true): Rule
|
||||
{
|
||||
$stmt = $this->db->pdo()->prepare(
|
||||
"UPDATE rules SET name = ?, pattern = ?, severity = ?, rate_limit_seconds = ?, active = ? WHERE id = ?"
|
||||
);
|
||||
$stmt->execute([$name, $pattern, $severity, $rateLimitSeconds, (int) $active, $id]);
|
||||
return $this->getRule($id);
|
||||
}
|
||||
|
||||
// --- Alerts ---
|
||||
|
||||
public function createAlert(int $ruleId, string $ruleName, string $severity, string $message, string $rawLine, ?int $sourceId = null, ?string $sourceName = null): Alert
|
||||
|
||||
Reference in New Issue
Block a user