1import{j as e}from"./vendor-ui-BeVD6iDL.js";import{a as o}from"./vendor-react-Dmhbt9i7.js";import{a as x}from"./vendor-query-vEtoV3ax.js";import{s as m}from"./index-cXBC_5Uy.js";import{A as p}from"./AdminPageShell-B5XdvC8l.js";import"./vendor-motion-CENv1AvF.js";import"./BackIcon-B0Ptl-7G.js";function u(l={}){const{hours:c=24,severity:a,eventType:r,limit:n=200}=l;return x({queryKey:["security-access-logs",{hours:c,severity:a,eventType:r,limit:n}],queryFn:async()=>{const i=new Date(Date.now()-c*36e5).toISOString();let s=m.from("security_access_logs").select("*").gte("created_at",i).order("created_at",{ascending:!1}).limit(n);a&&(s=s.eq("severity",a)),r&&(s=s.eq("event_type",r));const{data:d,error:t}=await s;if(t)throw t;return d??[]},staleTime:3e4,refetchInterval:6e4,refetchOnWindowFocus:!1})}const h=["","info","warning","critical"];function w(){const[l,c]=o.useState(24),[a,r]=o.useState(""),[n,i]=o.useState(""),{data:s=[],isLoading:d}=u({hours:l,severity:a||void 0,eventType:n||void 0,limit:500});return e.jsx(p,{title:"Logs de segurança",description:"Tentativas suspeitas registradas pelo backend (anon/authenticated). Use para investigar IPs, usuários ou padrões anormais.",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-3 text-sm",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Janela (h)"}),e.jsx("input",{type:"number",min:1,max:168,value:l,onChange:t=>c(Math.max(1,Math.min(168,Number(t.target.value)||24))),className:"border rounded px-2 py-1 w-24 bg-background"})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Severidade"}),e.jsx("select",{value:a,onChange:t=>r(t.target.value),className:"border rounded px-2 py-1 bg-background",children:h.map(t=>e.jsx("option",{value:t,children:t||"todas"},t))})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Event type"}),e.jsx("input",{value:n,onChange:t=>i(t.target.value.trim()),placeholder:"rls_denied, rate_limit_hitâ¦",className:"border rounded px-2 py-1 bg-background w-64"})]})]}),e.jsx("div",{className:"border rounded-lg overflow-hidden bg-card",children:d?e.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:"Carregandoâ¦"}):s.length===0?e.jsx("div",{className:"p-6 text-sm text-emerald-600",children:"Nenhum evento de segurança no perÃodo."}):e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-muted text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-2",children:"Quando"}),e.jsx("th",{className:"text-left p-2",children:"Sev"}),e.jsx("th",{className:"text-left p-2",children:"Evento"}),e.jsx("th",{className:"text-left p-2",children:"Papel"}),e.jsx("th",{className:"text-left p-2",children:"User"}),e.jsx("th",{className:"text-left p-2",children:"IP"}),e.jsx("th",{className:"text-left p-2",children:"Rota"}),e.jsx("th",{className:"text-left p-2",children:"Recurso"}),e.jsx("th",{className:"text-left p-2",children:"Motivo"})]})}),e.jsx("tbody",{children:s.map(t=>e.jsxs("tr",{className:"border-t align-top",children:[e.jsx("td",{className:"p-2 whitespace-nowrap",children:new Date(t.created_at).toLocaleString()}),e.jsx("td",{className:"p-2",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-semibold ${t.severity==="critical"?"bg-destructive text-destructive-foreground":t.severity==="warning"?"bg-yellow-500 text-black":"bg-blue-500 text-white"}`,children:t.severity})}),e.jsx("td",{className:"p-2 font-mono",children:t.event_type}),e.jsx("td",{className:"p-2",children:t.role??"â"}),e.jsx("td",{className:"p-2 font-mono truncate max-w-[140px]",children:t.user_id??"â"}),e.jsx("td",{className:"p-2 font-mono",children:t.ip??"â"}),e.jsx("td",{className:"p-2 truncate max-w-[200px]",children:t.request_path??"â"}),e.jsx("td",{className:"p-2 truncate max-w-[200px]",children:t.resource??"â"}),e.jsx("td",{className:"p-2 truncate max-w-[260px]",children:t.reason??"â"})]},t.id))})]})})]})})}export{w as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.