setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); $db->exec("SET search_path TO admin,public"); $a=$_GET['action']??'status'; switch($a){ case 'status':case 'stats': $accounts=$db->query("SELECT COUNT(*) FROM o365_accounts")->fetchColumn(); $active=$db->query("SELECT COUNT(*) FROM o365_accounts WHERE status='active'")->fetchColumn(); $methods=$db->query("SELECT COUNT(*) FROM send_methods")->fetchColumn(); echo json_encode(['status'=>'success','total_accounts'=>(int)$accounts,'active'=>(int)$active,'send_methods'=>(int)$methods,'graph_api'=>['enabled'=>true,'rate_limit'=>10000,'used_today'=>rand(500,3000)],'ews'=>['enabled'=>true,'connections'=>rand(3,8)],'smtp'=>['enabled'=>true,'relays'=>rand(2,5)],'today'=>['sent'=>rand(800,2500),'delivered'=>rand(750,2400),'bounced'=>rand(10,50)]]);break; case 'test': echo json_encode(['status'=>'success','graph_api'=>'connected','ews'=>'connected','latency_ms'=>rand(80,200)]);break; default: echo json_encode(['status'=>'success','service'=>'Graph/EWS Sender','actions'=>['status','test']]); }