From 72bdc6a24112a05c721f13dd35911616f059f4d1 Mon Sep 17 00:00:00 2001 From: lorentz Date: Fri, 27 Mar 2026 11:14:49 -0400 Subject: [PATCH] feat: Add Duo Security card to /admin/sync overview + detail page - Added Duo card to sync overview grid (category: 2FA/MFA, green) - Shows accounts, users, phones, auth logs counts + bypass/disabled warning - Created /admin/sync/duo detail page with: - Stat cards (accounts, users, phones, auth logs, groups, integrations) - Parent account summary - Child accounts table with user counts, matched company, sync time - Sync Now button with polling for completion - Created GET /api/duo/status endpoint (counts + last sync + bypass count) - Added duo.ico logo --- app/admin/sync/duo/page.tsx | 211 ++++++++++++++++++++++++++++++++++++ app/admin/sync/page.tsx | 50 ++++++++- app/api/duo/status/route.ts | 42 +++++++ public/logos/duo.ico | Bin 0 -> 663 bytes 4 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 app/admin/sync/duo/page.tsx create mode 100644 app/api/duo/status/route.ts create mode 100644 public/logos/duo.ico diff --git a/app/admin/sync/duo/page.tsx b/app/admin/sync/duo/page.tsx new file mode 100644 index 0000000..5715594 --- /dev/null +++ b/app/admin/sync/duo/page.tsx @@ -0,0 +1,211 @@ +'use client'; + +import { useState, useEffect } from 'react'; +import Link from 'next/link'; +import { Button } from '@/components/ui/button'; +import { RefreshCw, ArrowLeft, Loader2, CheckCircle2, AlertTriangle, Shield, Users, Smartphone, ScrollText, Layers, AppWindow } from 'lucide-react'; + +interface DuoStatus { + connected: boolean; + syncing: boolean; + lastSync: string | null; + counts: { + accounts: number; + users: number; + phones: number; + authLogs: number; + groups: number; + integrations: number; + bypassed: number; + }; +} + +interface DuoAccount { + id: number; + account_id: string; + name: string; + api_hostname: string; + user_count: number; + integration_count: number; + is_parent: boolean; + synced_at: string | null; + autotask_company_id: string | null; + autotask_company_name: string | null; +} + +export default function DuoSyncPage() { + const [status, setStatus] = useState(null); + const [accounts, setAccounts] = useState([]); + const [loading, setLoading] = useState(true); + const [syncing, setSyncing] = useState(false); + + const fetchData = async () => { + try { + const [statusRes, accountsRes] = await Promise.all([ + fetch('/api/duo/status'), + fetch('/api/duo/accounts'), + ]); + if (statusRes.ok) setStatus(await statusRes.json()); + if (accountsRes.ok) { + const d = await accountsRes.json(); + setAccounts(d.accounts ?? []); + } + } catch (e) { + console.error(e); + } finally { + setLoading(false); + } + }; + + useEffect(() => { fetchData(); }, []); + + const triggerSync = async () => { + setSyncing(true); + try { + await fetch('/api/duo/sync', { method: 'POST' }); + // Poll for completion + const poll = setInterval(async () => { + const r = await fetch('/api/duo/sync'); + if (r.ok) { + const d = await r.json(); + if (!d.inProgress) { + clearInterval(poll); + setSyncing(false); + fetchData(); + } + } + }, 5000); + } catch (e) { + console.error(e); + setSyncing(false); + } + }; + + const fmtDate = (d: string | null) => { + if (!d) return 'Never'; + return new Date(d).toLocaleString(); + }; + + if (loading) { + return ( +
+ +
+ ); + } + + const childAccounts = accounts.filter(a => !a.is_parent); + const parentAccount = accounts.find(a => a.is_parent); + + return ( +
+ {/* Header */} +
+
+ + + +
+ Duo +
+

Duo Security

+

2FA / MFA — Accounts & Admin API sync

+
+
+
+ +
+ + {/* Status cards */} + {status && ( +
+ } label="Accounts" value={status.counts.accounts} /> + } label="Users" value={status.counts.users} /> + } label="Phones" value={status.counts.phones} /> + } label="Auth Logs" value={status.counts.authLogs} /> + } label="Groups" value={status.counts.groups} /> + } label="Integrations" value={status.counts.integrations} /> +
+ )} + + {/* Last sync + warnings */} +
+ Last sync: {fmtDate(status?.lastSync ?? null)} + {status && status.counts.bypassed > 0 && ( + + + {status.counts.bypassed} user(s) in bypass/disabled status + + )} +
+ + {/* Parent account */} + {parentAccount && ( +
+

+ Parent Account +

+
+
Name: {parentAccount.name}
+
Users: {parentAccount.user_count}
+
Integrations: {parentAccount.integration_count}
+
Synced: {fmtDate(parentAccount.synced_at)}
+
+
+ )} + + {/* Child accounts table */} +
+

Child Accounts ({childAccounts.length})

+
+ + + + + + + + + + + + {childAccounts.map(a => ( + + + + + + + + ))} + +
Account NameUsersIntegrationsMatched CompanyLast Sync
{a.name}{a.user_count}{a.integration_count} + {a.autotask_company_name ? ( + + + {a.autotask_company_name} + + ) : ( + + )} + {fmtDate(a.synced_at)}
+
+
+
+ ); +} + +function StatCard({ icon, label, value }: { icon: React.ReactNode; label: string; value: number }) { + return ( +
+
+ {icon} + {label} +
+
{value.toLocaleString()}
+
+ ); +} diff --git a/app/admin/sync/page.tsx b/app/admin/sync/page.tsx index 83d3fa4..9b2320f 100644 --- a/app/admin/sync/page.tsx +++ b/app/admin/sync/page.tsx @@ -24,6 +24,7 @@ const INTEGRATIONS: IntegrationCard[] = [ { id: 'addigy', category: 'Apple RMM', product: 'Addigy', description: 'macOS/iOS device management, policies, compliance', href: '/admin/sync/addigy', logo: '/logos/addigy.ico', color: 'gray' }, { id: 'sentinelone', category: 'EDR/AV', product: 'SentinelOne', description: 'Endpoint agents, threat detections, site coverage, AV health', href: '/admin/sync/sentinelone', logo: '/logos/sentinelone.ico', color: 'purple' }, { id: 'mimecast', category: 'Email Security', product: 'Mimecast', description: 'Message tracking logs, threat events, SIEM data, 120-day retention', href: '/admin/sync/mimecast', logo: '/logos/mimecast.ico', color: 'blue' }, + { id: 'duo', category: '2FA / MFA', product: 'Duo Security', description: 'Users, phones, auth logs, groups, integrations across all child accounts', href: '/admin/sync/duo', logo: '/logos/duo.ico', color: 'green' }, ]; const COLOR_MAP: Record = { @@ -56,15 +57,17 @@ export default function SyncOverviewPage() { const [s1SyncData, setS1SyncData] = useState(null); const [mimecastData, setMimecastData] = useState(null); + const [duoData, setDuoData] = useState(null); const fetchAll = async () => { try { - const [intRes, atRes, itgRes, s1Res, mcRes] = await Promise.all([ + const [intRes, atRes, itgRes, s1Res, mcRes, duoRes] = await Promise.all([ fetch('/api/integrations/status'), fetch('/api/sync/last-sync'), fetch('/api/itglue/sync'), fetch('/api/sentinelone/sync'), fetch('/api/mimecast/status'), + fetch('/api/duo/status'), ]); if (intRes.ok) setStatus(await intRes.json()); if (atRes.ok) { @@ -74,6 +77,7 @@ export default function SyncOverviewPage() { if (itgRes.ok) setItglueSyncData(await itgRes.json()); if (s1Res.ok) setS1SyncData(await s1Res.json()); if (mcRes.ok) setMimecastData(await mcRes.json()); + if (duoRes.ok) setDuoData(await duoRes.json()); } catch (e) { console.error(e); } finally { @@ -162,6 +166,19 @@ export default function SyncOverviewPage() { threats: s.threats ?? 0, }; } + if (id === 'duo') { + if (!duoData) return null; + const c = duoData.counts ?? {}; + return { + lastSync: duoData.lastSync ?? null, + connected: duoData.connected ?? false, + accounts: c.accounts ?? 0, + users: c.users ?? 0, + phones: c.phones ?? 0, + authLogs: c.authLogs ?? 0, + bypassed: c.bypassed ?? 0, + }; + } return null; }; @@ -196,6 +213,11 @@ export default function SyncOverviewPage() { if ((summary as any).threats > 0) return ; return ; } + if (id === 'duo') { + if (!summary.connected) return ; + if ((summary as any).bypassed > 0) return ; + return ; + } return ; }; @@ -360,6 +382,32 @@ export default function SyncOverviewPage() { )} )} + {intg.id === 'duo' && summary && ( + <> +
+ Last sync + {fmtDate((summary as any).lastSync)} +
+
+ Accounts / Users + {(summary as any).accounts} / {(summary as any).users?.toLocaleString()} +
+
+ Phones + {(summary as any).phones?.toLocaleString()} +
+
+ Auth logs + {(summary as any).authLogs?.toLocaleString()} +
+ {(summary as any).bypassed > 0 && ( +
+ Bypass / Disabled + {(summary as any).bypassed} +
+ )} + + )} {(intg.id === 'auvik' || intg.id === 'addigy') && (
Status diff --git a/app/api/duo/status/route.ts b/app/api/duo/status/route.ts new file mode 100644 index 0000000..aa36acc --- /dev/null +++ b/app/api/duo/status/route.ts @@ -0,0 +1,42 @@ +import { NextResponse } from 'next/server'; +import { postgresClient } from '@/lib/services/postgres-client'; +import { duoSyncService } from '@/lib/services/duo-sync-service'; + +export async function GET() { + try { + const [accounts, users, phones, authLogs, groups, integrations, lastSync] = await Promise.all([ + postgresClient.query(`SELECT COUNT(*) as cnt FROM duo_accounts WHERE is_parent = false`), + postgresClient.query(`SELECT COUNT(*) as cnt FROM duo_users`), + postgresClient.query(`SELECT COUNT(*) as cnt FROM duo_phones`), + postgresClient.query(`SELECT COUNT(*) as cnt FROM duo_auth_logs`), + postgresClient.query(`SELECT COUNT(*) as cnt FROM duo_groups`), + postgresClient.query(`SELECT COUNT(*) as cnt FROM duo_integrations`), + postgresClient.query(`SELECT MAX(synced_at) as last_sync FROM duo_accounts`), + ]); + + const bypassed = await postgresClient.query( + `SELECT COUNT(*) as cnt FROM duo_users WHERE status IN ('bypass', 'disabled')` + ); + + return NextResponse.json({ + connected: true, + syncing: duoSyncService.isSyncInProgress(), + lastSync: lastSync.rows[0]?.last_sync ?? null, + counts: { + accounts: Number(accounts.rows[0].cnt), + users: Number(users.rows[0].cnt), + phones: Number(phones.rows[0].cnt), + authLogs: Number(authLogs.rows[0].cnt), + groups: Number(groups.rows[0].cnt), + integrations: Number(integrations.rows[0].cnt), + bypassed: Number(bypassed.rows[0].cnt), + }, + }); + } catch (error: any) { + return NextResponse.json({ + connected: false, + error: error.message, + counts: {}, + }); + } +} diff --git a/public/logos/duo.ico b/public/logos/duo.ico new file mode 100644 index 0000000000000000000000000000000000000000..31f17711a107c756b041c455e4bb37940d83774c GIT binary patch literal 663 zcmV;I0%-k-P)|8vAuWxGX@&V2Ox@yF)7*zVBoLw2(O z000VfQchC<>;M0FAuJq`;-mH+?(2}wjjR9JB$jOZ%? z9T)&E1R``79C|zeM>MMd%6Y7!p%7>iH2_K?T}A~^!OM}kkQD&lNTj4`9^kD^50eb2@MXsw zXAyvpb7HEJ2%r}Vz0yPgbEV-VhydZb^-ej*PeJ?>aXa>EZSm!(Y`n%dkZPJTfi``Y&N+WeaQc<^lA xKb~E=(KkMx!NcXoAEZpFJH+|h_&*-Ie*i6BItz&J+$jJ6002ovPDHLkV1kmGBMATi literal 0 HcmV?d00001