1import{j as e}from"./ui-j_BOR4Bz.js";import{r as L}from"./vendor-3J8TqX-d.js";import{b as O,u as j,c as v}from"./query-BNSb6A4E.js";import{c as P,e as i,x as n,y as d,f as c,T as b,z as w,B as C,i as _,$ as R,s as m,k as x}from"./index-I58FL1tg.js";import{A as I}from"./AdminLayout-CJVwtAe-.js";import{B as h}from"./badge-CLggev_4.js";import{A as K,h as $,a as z,b as F,c as Q,d as V,e as G,f as J,g as X}from"./alert-dialog-CAGNk1hk.js";import{C as A}from"./circle-check-big-CXWgjl-A.js";import{S as k}from"./shield-CtVf10CI.js";import{C as Y}from"./clock-DOShILIs.js";import{f as u}from"./format-CaTZjsmt.js";import{p as T}from"./pt-BR-7gxBXGgQ.js";import"./motion-B44LIdVn.js";import"./building-2-XvU0ubCv.js";import"./moon-CwBUbK4G.js";import"./log-out-Ce2iy99h.js";import"./layout-dashboard-VzcdXI7O.js";import"./wallet-Chj2gvwv.js";import"./globe-Blghe4s9.js";import"./file-text-DJLk2wS0.js";import"./mail-D16P_s8Z.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const q=P("Key",[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]]);function ge(){const p=O(),[g,y]=L.useState(null),{data:o,isLoading:D}=j({queryKey:["encryption-key-backups"],queryFn:async()=>{const{data:s,error:a}=await m.from("encryption_key_backups").select("*").order("created_at",{ascending:!1}).limit(20);if(a)throw a;return s}}),{data:t,isLoading:E}=j({queryKey:["security-alerts"],queryFn:async()=>{const{data:s,error:a}=await m.from("security_alert_queue").select("*").order("created_at",{ascending:!1}).limit(50);if(a)throw a;return s}}),{data:l,isLoading:S}=j({queryKey:["security-audit-logs"],queryFn:async()=>{const{data:s,error:a}=await m.from("audit_logs").select("*").in("action",["KEY_ROTATION","LOGIN_FAILED","RATE_LIMIT_EXCEEDED"]).order("created_at",{ascending:!1}).limit(30);if(a)throw a;return s}}),B=v({mutationFn:async s=>{const{data:{session:a}}=await m.auth.getSession();if(!a)throw new Error("Não autenticado");const r=await fetch("https://gtqfrqphqarcqzkutyff.supabase.co/functions/v1/verify-encryption-key",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a.access_token}`},body:JSON.stringify({backup_id:s})}),N=await r.json();if(!r.ok)throw new Error(N.error||"Erro ao verificar");return N},onSuccess:s=>{s.is_valid?x.success("Chave de criptografia verificada com sucesso!"):x.error("ATENÃÃO: Chave atual não corresponde ao backup!"),p.invalidateQueries({queryKey:["encryption-key-backups"]})},onError:s=>{x.error(s.message)}}),f=v({mutationFn:async()=>{const{data:{session:s}}=await m.auth.getSession();if(!s)throw new Error("Não autenticado");const a=await fetch("https://gtqfrqphqarcqzkutyff.supabase.co/functions/v1/rotate-encryption-key",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s.access_token}`},body:JSON.stringify({generate_new_key:!0})}),r=await a.json();if(!a.ok)throw new Error(r.error||"Erro na rotação");return r},onSuccess:s=>{x.success(`Chave rotacionada! ${s.records_updated} registros atualizados.`),p.invalidateQueries({queryKey:["encryption-key-backups"]}),p.invalidateQueries({queryKey:["security-audit-logs"]})},onError:s=>{x.error(s.message)}}),H=async s=>{y(s);try{await B.mutateAsync(s)}finally{y(null)}},M=s=>({otp_rate_limit:{label:"Rate Limit OTP",color:"bg-orange-100 text-orange-800"},reservation_rate_limit:{label:"Rate Limit Reserva",color:"bg-red-100 text-red-800"}})[s]||{label:s,color:"bg-gray-100 text-gray-800"};return e.jsx(I,{title:"Segurança",children:e.jsxs("div",{className:"grid gap-6",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-4",children:[e.jsxs(i,{children:[e.jsxs(n,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(d,{className:"text-sm font-medium",children:"Backups de Chave"}),e.jsx(q,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-2xl font-bold",children:(o==null?void 0:o.length)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total de backups registrados"})]})]}),e.jsxs(i,{children:[e.jsxs(n,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(d,{className:"text-sm font-medium",children:"Alertas Pendentes"}),e.jsx(b,{className:"h-4 w-4 text-destructive"})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-2xl font-bold",children:(t==null?void 0:t.filter(s=>!s.processed).length)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Aguardando processamento"})]})]}),e.jsxs(i,{children:[e.jsxs(n,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(d,{className:"text-sm font-medium",children:"Alertas Processados"}),e.jsx(A,{className:"h-4 w-4 text-primary"})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-2xl font-bold",children:(t==null?void 0:t.filter(s=>s.processed).length)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Notificações envi
6adas"})]})]}),e.jsxs(i,{children:[e.jsxs(n,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(d,{className:"text-sm font-medium",children:"Eventos de Auditoria"}),e.jsx(k,{className:"h-4 w-4 text-primary"})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-2xl font-bold",children:(l==null?void 0:l.length)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ãltimos 30 eventos"})]})]})]}),e.jsxs(i,{children:[e.jsxs(n,{children:[e.jsxs(d,{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-5 w-5"}),"Gerenciamento de Chaves de Criptografia"]}),e.jsx(w,{children:"Gerencie a chave de criptografia PII usada para proteger dados sensÃveis"})]}),e.jsxs(c,{className:"space-y-4",children:[e.jsx("div",{className:"flex gap-4",children:e.jsxs(K,{children:[e.jsx($,{asChild:!0,children:e.jsxs(C,{variant:"destructive",disabled:f.isPending,children:[f.isPending?e.jsx(_,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(R,{className:"mr-2 h-4 w-4"}),"Rotacionar Chave"]})}),e.jsxs(z,{children:[e.jsxs(F,{children:[e.jsx(Q,{children:"Rotacionar Chave de Criptografia?"}),e.jsxs(V,{children:["Esta ação irá gerar uma nova chave e re-encriptar todos os dados sensÃveis. O backup da chave antiga será salvo automaticamente.",e.jsx("br",{}),e.jsx("br",{}),e.jsx("strong",{className:"text-destructive",children:"ATENÃÃO: Esta operação pode levar alguns minutos dependendo da quantidade de dados."})]})]}),e.jsxs(G,{children:[e.jsx(J,{children:"Cancelar"}),e.jsx(X,{onClick:()=>f.mutate(),children:"Confirmar Rotação"})]})]})]})}),e.jsxs("div",{className:"mt-6",children:[e.jsx("h4",{className:"mb-3 font-medium",children:"Histórico de Backups"}),D?e.jsx("p",{className:"text-muted-foreground",children:"Carregando..."}):o&&o.length>0?e.jsx("div",{className:"overflow-x-auto rounded-md border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3 text-left font-medium",children:"Data"}),e.jsx("th",{className:"p-3 text-left font-medium",children:"Hash"}),e.jsx("th",{className:"p-3 text-left font-medium",children:"Notas"}),e.jsx("th",{className:"p-3 text-left font-medium",children:"Verificado"}),e.jsx("th",{className:"p-3 text-left font-medium",children:"Ações"})]})}),e.jsx("tbody",{children:o.map(s=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"p-3",children:u(new Date(s.created_at),"dd/MM/yyyy HH:mm",{locale:T})}),e.jsx("td",{className:"p-3",children:e.jsxs("code",{className:"rounded bg-muted px-2 py-1 text-xs",children:[s.backup_hash.substring(0,16),"..."]})}),e.jsx("td",{className:"p-3 text-muted-foreground",children:s.notes||"-"}),e.jsx("td",{className:"p-3",children:s.verified_at?e.jsxs(h,{variant:"secondary",className:"text-primary",children:[e.jsx(A,{className:"mr-1 h-3 w-3"}),u(new Date(s.verified_at),"dd/MM HH:mm")]}):e.jsx(h,{variant:"outline",children:"Não verificado"})}),e.jsx("td",{className:"p-3",children:e.jsx(C,{size:"sm",variant:"outline",onClick:()=>H(s.id),disabled:g===s.id,children:g===s.id?e.jsx(_,{className:"h-4 w-4 animate-spin"}):"Verificar"})})]},s.id))})]})}):e.jsx("p",{className:"text-muted-foreground",children:"Nenhum backup registrado"})]})]})]}),e.jsxs(i,{children:[e.jsxs(n,{children:[e.jsxs(d,{className:"flex items-center gap-2",children:[e.jsx(b,{className:"h-5 w-5 text-destructive"}),"Alertas de Segurança"]}),e.jsx(w,{children:"Tentativas de brute-force e violações de rate limit detectadas"})]}),e.jsx(c,{children:E?e.jsx("p",{className:"text-muted-foreground",children:"Carregando..."}):t&&t.length>0?e.jsx("div",{className:"space-y-3 max-h-96 overflow-y-auto",children:t.map(s=>{const a=s.payload,r=M(a.type);return e.jsxs("div",{className:"flex items-start justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{variant:r.color==="bg-red-100 text-red-800"?"destructive":"secondary",children:r.label}),s.processed&&e.jsx(h,{variant:"secondary",className:"text-primary",children:"Processado"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[a.phone&&`Telefone: ${String(a.phone).substring(0,5)}***`,a.ip_address&&` ⢠IP: ${a.ip_address}`]}),e.jsxs("p",{className:"text-sm",children:["Tentativas: ",e.jsx("strong",{children:a.attempts}),a.blocked_until&&e.jsxs("span",{className:"text-destructive",children:[" ","⢠Bloqueado at
6é ",u(new Date(a.blocked_until),"dd/MM HH:mm")]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Y,{className:"h-4 w-4"}),u(new Date(s.created_at),"dd/MM HH:mm:ss")]})]},s.id)})}):e.jsx("p",{className:"text-muted-foreground",children:"Nenhum alerta registrado"})})]}),e.jsxs(i,{children:[e.jsx(n,{children:e.jsxs(d,{className:"flex items-center gap-2",children:[e.jsx(k,{className:"h-5 w-5"}),"Log de Auditoria de Segurança"]})}),e.jsx(c,{children:S?e.jsx("p",{className:"text-muted-foreground",children:"Carregando..."}):l&&l.length>0?e.jsx("div",{className:"overflow-x-auto rounded-md border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3 text-left font-medium",children:"Data"}),e.jsx("th",{className:"p-3 text-left font-medium",children:"Ação"}),e.jsx("th",{className:"p-3 text-left font-medium",children:"Tabela"}),e.jsx("th",{className:"p-3 text-left font-medium",children:"Detalhes"})]})}),e.jsx("tbody",{children:l.map(s=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"p-3",children:u(new Date(s.created_at),"dd/MM/yyyy HH:mm:ss",{locale:T})}),e.jsx("td",{className:"p-3",children:e.jsx(h,{variant:"outline",children:s.action})}),e.jsx("td",{className:"p-3",children:s.table_name}),e.jsx("td",{className:"p-3 text-muted-foreground",children:s.new_data?JSON.stringify(s.new_data).substring(0,50)+"...":"-"})]},s.id))})]})}):e.jsx("p",{className:"text-muted-foreground",children:"Nenhum evento de auditoria"})})]})]})})}export{ge 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.