/** * Admin Panel - Total RMI Ecosystem Control * God mode for developers - control everything */ import { useState, useEffect } from 'react'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { api } from '../services/api'; import { db } from '../services/supabase'; import { Cloud, Search, Database, Server, Activity, Users, Shield, Terminal, Clock, HardDrive, Cpu, Eye, Zap, Settings, ChevronDown, ChevronRight, Bot, Globe, MessageSquare, Bell, Play, Pause, RotateCcw, Send, Trash2, Edit3, Plus, Power, Radio, Layout, Coins, AlertCircle, Brain, RefreshCw, Download, Upload, Wifi, ToggleLeft, FileText, Key, } from 'lucide-react'; import UserManagement from './admin/UserManagement'; import EvidenceManagement from './admin/EvidenceManagement'; import InvestigationOperations from './admin/InvestigationOperations'; import RevenueDashboard from './admin/RevenueDashboard'; import TrenchesRehabManagement from './admin/TrenchesRehabManagement'; import FeatureFlags from './admin/FeatureFlags'; import AuditLogs from './admin/AuditLogs'; import APIManagement from './admin/APIManagement'; import ContentManagement from './admin/ContentManagement'; import InfrastructureDashboard from './admin/InfrastructureDashboard'; // N8N configuration const N8N_BASE = import.meta.env.VITE_N8N_URL || '/api/v1/admin/n8n'; // Telegram bots configuration const BOTS = [ { id: 'rugmunch', name: '@rugmunchbot', token: '***', type: 'main', status: 'active' }, { id: 'backend', name: '@rmi_backend_bot', token: '***', type: 'monitoring', status: 'active' }, { id: 'alerts', name: '@rmi_alerts_bot', token: '***', type: 'free_alerts', status: 'active' }, { id: 'alpha', name: '@rmi_alpha_bot', token: '***', type: 'paid_alerts', status: 'active' }, ]; // N8N Workflows const WORKFLOWS = [ { id: 'scan-result', name: 'Scan Results → @munchscans', webhook: '/webhook/scan-result', active: true }, { id: 'backend-alert', name: 'Backend Health → @rmi_backend', webhook: '/webhook/backend-alert', active: true }, { id: 'whale-alert', name: 'Whale Alerts → @rmi_alpha_alerts', webhook: '/webhook/whale-alert', active: true }, { id: 'scam-alert', name: 'Scam Detection → @rmi_alpha_alerts', webhook: '/webhook/scam-alert', active: true }, { id: 'daily-report', name: 'Daily Intel Report (Scheduled)', webhook: null, active: true, schedule: '9:00 AM' }, ]; export default function AdminPanel() { const [activeTab, setActiveTab] = useState<'overview' | 'users' | 'evidence' | 'investigations' | 'trenches' | 'revenue' | 'feature_flags' | 'audit_logs' | 'api_mgmt' | 'bots' | 'n8n' | 'website' | 'database' | 'ai' | 'alerts' | 'system' | 'content' | 'infrastructure'>('overview'); const [testMessage, setTestMessage] = useState(''); const [n8nStatus, setN8nStatus] = useState<'unknown' | 'online' | 'offline'>('unknown'); const [adminKey, setAdminKey] = useState(localStorage.getItem('admin_key') || ''); const [dbQuery, setDbQuery] = useState('SELECT * FROM profiles LIMIT 10'); const [dbResult, setDbResult] = useState(null); const [logLevel, setLogLevel] = useState(''); const queryClient = useQueryClient(); // Admin data fetching const { data: systemData, isLoading: systemLoading } = useQuery({ queryKey: ['admin-system', adminKey], queryFn: () => api.getSystemStats(adminKey), enabled: !!adminKey && (activeTab === 'system' || activeTab === 'overview'), refetchInterval: 5000, }); const { data: servicesData } = useQuery({ queryKey: ['admin-services', adminKey], queryFn: () => api.getServices(adminKey), enabled: !!adminKey && (activeTab === 'system' || activeTab === 'overview'), refetchInterval: 10000, }); const { data: logsData, refetch: refetchLogs } = useQuery({ queryKey: ['admin-logs', adminKey, logLevel], queryFn: () => api.getLogs(adminKey, 100, logLevel || undefined), enabled: !!adminKey && activeTab === 'system', }); const { data: dbTablesData } = useQuery({ queryKey: ['admin-db-tables', adminKey], queryFn: () => api.getDatabaseTables(adminKey), enabled: !!adminKey && activeTab === 'database', }); const { data: botsData } = useQuery({ queryKey: ['admin-bots', adminKey], queryFn: () => api.getBots(adminKey), enabled: !!adminKey && activeTab === 'bots', }); const { data: alertsData, refetch: refetchAlerts } = useQuery({ queryKey: ['admin-alerts', adminKey], queryFn: () => api.getAlertsHistory(adminKey, 50), enabled: !!adminKey && activeTab === 'alerts', }); const serviceActionMutation = useMutation({ mutationFn: ({ serviceId, action }: { serviceId: string; action: string }) => api.serviceAction(adminKey, serviceId, action), onSuccess: () => queryClient.invalidateQueries({ queryKey: ['admin-services'] }), }); const sendAlertMutation = useMutation({ mutationFn: ({ message, channel }: { message: string; channel: string }) => api.sendTestAlert(adminKey, message, channel), onSuccess: () => refetchAlerts(), }); const runQueryMutation = useMutation({ mutationFn: (sql: string) => api.runDatabaseQuery(adminKey, sql, 100), onSuccess: (data) => setDbResult(data), }); // Fetch data const { data: health } = useQuery({ queryKey: ['admin-health'], queryFn: () => api.health(), refetchInterval: 5000, }); const { data: stats } = useQuery({ queryKey: ['admin-stats'], queryFn: () => api.getStats(), refetchInterval: 10000, }); const { data: allWallets } = useQuery({ queryKey: ['admin-wallets'], queryFn: async () => { const { data } = await db.wallets.getAll(); return data || []; }, }); const { data: allInvestigations } = useQuery({ queryKey: ['admin-investigations'], queryFn: async () => { const { data } = await db.investigations.getAll(); return data || []; }, }); // Check N8N status useEffect(() => { fetch(`${N8N_BASE}/health`, { mode: 'no-cors' }) .then(() => setN8nStatus('online')) .catch(() => setN8nStatus('offline')); }, []); const sendTestAlert = async (webhook: string) => { try { await fetch(`${N8N_BASE}${webhook}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: testMessage || 'Test alert from admin panel', timestamp: new Date().toISOString(), test: true, }), }); alert('Test alert sent!'); } catch (err) { alert('Failed to send test alert: ' + err); } }; return (
{/* Header */}

RMI Control Center DEV MODE

Complete ecosystem management and monitoring

{ setAdminKey(e.target.value); localStorage.setItem('admin_key', e.target.value); }} className="bg-crypto-dark border border-crypto-border rounded px-3 py-2 text-sm text-white w-48" /> {adminKey ? ( KEY SET ) : ( NO KEY )}
{/* Navigation */}
{[ { id: 'overview', label: 'Overview', icon: Activity }, { id: 'users', label: 'Users', icon: Users }, { id: 'content', label: 'Content', icon: FileText }, { id: 'evidence', label: 'Evidence', icon: Shield }, { id: 'investigations', label: 'Investigations', icon: Search }, { id: 'trenches', label: 'Trenches & Rehab', icon: MessageSquare }, { id: 'revenue', label: 'Revenue', icon: Coins }, { id: 'feature_flags', label: 'Features', icon: ToggleLeft }, { id: 'audit_logs', label: 'Audit Logs', icon: Eye }, { id: 'api_mgmt', label: 'API', icon: Key }, { id: 'bots', label: 'Bots', icon: Bot }, { id: 'n8n', label: 'N8N', icon: Zap }, { id: 'website', label: 'Website', icon: Globe }, { id: 'database', label: 'Database', icon: Database }, { id: 'ai', label: 'AI/OSINT', icon: Brain }, { id: 'alerts', label: 'Alerts', icon: Bell }, { id: 'infrastructure', label: 'Infra', icon: Cloud }, { id: 'system', label: 'System', icon: Server }, ].map((tab) => ( ))}
{/* OVERVIEW TAB */} {activeTab === 'overview' && (
{/* Quick Stats Grid */}
{/* System Status Cards */}
{/* Backend Services */}

Backend Services

{servicesData?.services?.map((svc: any) => ( )) || ( <> )}
{/* Bot Fleet Status */}

Bot Fleet

{BOTS.map((bot) => (
{bot.name} {bot.type}
))}
{/* Quick Actions */}

Quick Actions

alert('Restart command sent')} /> alert('Cache cleared')} /> sendTestAlert('/webhook/backend-alert')} /> alert('Backup started')} /> alert('Website refresh triggered')} /> window.location.reload()} />
{/* Expandable Details */}
)} {/* BOTS TAB */} {activeTab === 'bots' && (

Telegram Bot Fleet

{botsData?.bots?.map((bot: any) => (

{bot.name}

{bot.type}
Messages Today {bot.messages_today ?? '-'}
Subscribers {bot.subscribers ?? '-'}
)) || (

No bots configured or admin key missing

)}
)} {/* N8N TAB */} {activeTab === 'n8n' && (

N8N Workflow Automation

Open N8N
{/* Test Alert Section */}

Send Test Alert

setTestMessage(e.target.value)} className="flex-1 bg-crypto-dark border border-crypto-border rounded px-4 py-2 text-white" />
{/* Workflows */}
{WORKFLOWS.map((wf) => (

{wf.name}

{wf.webhook && {wf.webhook}} {wf.schedule && ⏰ {wf.schedule}}
{wf.active ? 'ACTIVE' : 'PAUSED'}
))}
{/* Execution Logs */}

Recent Executions

Execution history will appear here

)} {/* WEBSITE TAB */} {activeTab === 'website' && (

Website Management

{/* Site Sections */}

Active Sections

{/* Content Management */}

Content Controls

{/* Stats */}

Website Stats

{/* Airdrop Management */}

V2 Airdrop

Waitlist Registrations -
Tokens Allocated -
)} {/* DATABASE TAB */} {activeTab === 'database' && (

Database Management

{dbTablesData?.tables?.map((t: any) => ( )) || ( <> )}
Table Rows Size Last Write Actions

Query Console