- Add coraza-caddy/v2 to Caddy Docker build - Add waf_events + waf_log_parse_state DB tables (migration 0010) - Add WafSettings type and get/save functions to settings - Add WafHostConfig/WafMode types to proxy-hosts model - Add resolveEffectiveWaf + buildWafHandler to caddy config generation - Create waf-log-parser.ts: parse Coraza JSON audit log → waf_events - Add WafFields.tsx per-host WAF UI (accordion, mode, CRS, directives) - Add global WAF settings card to SettingsClient - Add WAF Events dashboard page with search, pagination, severity chips - Add WAF Events nav link to sidebar Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
24 lines
899 B
TypeScript
24 lines
899 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { requireAdmin } from "@/src/lib/auth";
|
|
import { listWafEvents, countWafEvents } from "@/src/lib/models/waf-events";
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
await requireAdmin();
|
|
const { searchParams } = request.nextUrl;
|
|
const page = Math.max(1, parseInt(searchParams.get("page") ?? "1", 10) || 1);
|
|
const perPage = Math.min(200, Math.max(1, parseInt(searchParams.get("per_page") ?? "50", 10) || 50));
|
|
const search = searchParams.get("search")?.trim() || undefined;
|
|
const offset = (page - 1) * perPage;
|
|
|
|
const [events, total] = await Promise.all([
|
|
listWafEvents(perPage, offset, search),
|
|
countWafEvents(search),
|
|
]);
|
|
|
|
return NextResponse.json({ events, total, page, perPage });
|
|
} catch {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
}
|