getLine().PHP_EOL);exit(1);}); $root=dirname(__DIR__,2);require $root.'/vendor/autoload.php';$app=require $root.'/bootstrap/app.php';(new Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables)->bootstrap($app);(new Illuminate\Foundation\Bootstrap\LoadConfiguration)->bootstrap($app); $c=config('database.connections.'.config('database.default'));if($c['database']!=='investemoz'||(int)$c['port']!==5432||!in_array($c['host'],['127.0.0.1','localhost'])||!empty($c['url']))throw new RuntimeException('Active identity'); $db=new PDO('pgsql:host='.$c['host'].';port=5432;dbname=investemoz',$c['username'],$c['password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$db->exec('BEGIN READ ONLY'); try{ $pair=$db->query('SELECT p.id,p.first_user_id,u.name AS first_name,p.second_user_id,v.name AS second_name FROM portal_superuser_pair p LEFT JOIN users u ON u.id=p.first_user_id LEFT JOIN users v ON v.id=p.second_user_id')->fetchAll(PDO::FETCH_ASSOC); $roles=$db->query("SELECT r.user_id,u.name,r.role,r.organization_id,r.opportunity_types,r.source,u.email_verified_at IS NOT NULL AS verified FROM portal_role_assignments r JOIN users u ON u.id=r.user_id WHERE r.revoked_at IS NULL AND r.starts_at <= CURRENT_TIMESTAMP AND (r.expires_at IS NULL OR r.expires_at > CURRENT_TIMESTAMP) ORDER BY r.user_id,r.role")->fetchAll(PDO::FETCH_ASSOC); $owners=$db->query('SELECT o.owner_user_id,u.name,COUNT(*) AS records FROM opportunities o LEFT JOIN users u ON u.id=o.owner_user_id WHERE o.deleted_at IS NULL GROUP BY o.owner_user_id,u.name ORDER BY o.owner_user_id NULLS FIRST')->fetchAll(PDO::FETCH_ASSOC); $osm=$db->query("SELECT id,name,email_verified_at IS NOT NULL AS verified FROM users WHERE name ILIKE '%Osmane%Nala%' ORDER BY id")->fetchAll(PDO::FETCH_ASSOC); $denials=$db->query("SELECT actor_user_id,action,occurred_at,after_data->>'path' AS path,after_data->>'method' AS method,after_data->>'status' AS status FROM audit_events WHERE source_system='portal-profiles-v1' AND action='request_denied' AND after_data->>'path'='minhas-oportunidades/create' ORDER BY occurred_at DESC,id DESC LIMIT 5")->fetchAll(PDO::FETCH_ASSOC); $elevations=$db->query("SELECT subject_user_id,COUNT(*) AS current_approved_elevations FROM portal_security_approvals WHERE kind='elevation' AND approved_by IS NOT NULL AND consumed_at IS NULL AND expires_at>CURRENT_TIMESTAMP GROUP BY subject_user_id ORDER BY subject_user_id")->fetchAll(PDO::FETCH_ASSOC); $proof=['recent_create_denials'=>$denials,'current_approved_elevations'=>$elevations,'at' =>gmdate('c'),'target'=>['database'=>'investemoz','port'=>5432],'read_only'=>true,'osm'=> $osm,'superuser_pair'=>$pair,'current_operational_assignments'=>$roles,'opportunity_owners'=>$owners,'permission_changes'=>0]; file_put_contents(__DIR__.'/CONTAS-AMBITO-READONLY.json',json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL);echo json_encode($proof,JSON_UNESCAPED_UNICODE).PHP_EOL; }finally{$db->exec('ROLLBACK');}