93 lines
3.0 KiB
PHP
Executable File
93 lines
3.0 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Réactiver les seeds valides en testant leur connexion IMAP
|
|
*/
|
|
ini_set('max_execution_time', 600);
|
|
|
|
$pdo = new PDO("pgsql:host=localhost;dbname=adx_system", "admin", "admin123");
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
echo "🌱 SEED REACTIVATOR - Testing & Reactivating Valid Seeds\n";
|
|
echo str_repeat("=", 60) . "\n\n";
|
|
|
|
// Récupérer les seeds expirés mais potentiellement valides
|
|
$seeds = $pdo->query("
|
|
SELECT id, email, password, isp, imap_host, imap_port
|
|
FROM admin.brain_seeds
|
|
WHERE is_active = false
|
|
AND password IS NOT NULL
|
|
AND password != ''
|
|
AND imap_host IS NOT NULL
|
|
ORDER BY RANDOM()
|
|
LIMIT 50
|
|
")->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
echo "Testing " . count($seeds) . " seeds...\n\n";
|
|
|
|
$reactivated = 0;
|
|
$failed = 0;
|
|
|
|
foreach ($seeds as $seed) {
|
|
echo "Testing: {$seed['email']} ({$seed['isp']})... ";
|
|
|
|
$imap_host = $seed['imap_host'] ?: getImapHost($seed['isp']);
|
|
$imap_port = $seed['imap_port'] ?: 993;
|
|
|
|
// Test IMAP connection
|
|
$result = testIMAP($seed['email'], $seed['password'], $imap_host, $imap_port);
|
|
|
|
if ($result['success']) {
|
|
echo "✅ VALID!\n";
|
|
$pdo->prepare("UPDATE admin.brain_seeds SET is_active = true, check_status = 'valid', last_checked = NOW(), check_error = NULL WHERE id = ?")->execute([$seed['id']]);
|
|
$reactivated++;
|
|
} else {
|
|
echo "❌ {$result['error']}\n";
|
|
$pdo->prepare("UPDATE admin.brain_seeds SET check_status = 'invalid', last_checked = NOW(), check_error = ? WHERE id = ?")->execute([$result['error'], $seed['id']]);
|
|
$failed++;
|
|
}
|
|
|
|
usleep(500000); // 0.5s delay
|
|
}
|
|
|
|
echo "\n" . str_repeat("=", 60) . "\n";
|
|
echo "✅ Reactivated: $reactivated\n";
|
|
echo "❌ Failed: $failed\n";
|
|
|
|
// Afficher le total actif
|
|
$active = $pdo->query("SELECT COUNT(*) FROM admin.brain_seeds WHERE is_active = true")->fetchColumn();
|
|
echo "\n🌱 Total Active Seeds: $active\n";
|
|
|
|
function testIMAP($email, $password, $host, $port) {
|
|
$mailbox = "{" . $host . ":" . $port . "/imap/ssl/novalidate-cert}INBOX";
|
|
|
|
// Suppress errors
|
|
$prev = error_reporting(0);
|
|
$imap = @imap_open($mailbox, $email, $password, OP_READONLY, 1);
|
|
error_reporting($prev);
|
|
|
|
if ($imap) {
|
|
imap_close($imap);
|
|
return ['success' => true];
|
|
}
|
|
|
|
$error = imap_last_error();
|
|
imap_errors(); // Clear error stack
|
|
return ['success' => false, 'error' => substr($error ?: 'Connection failed', 0, 100)];
|
|
}
|
|
|
|
function getImapHost($isp) {
|
|
$hosts = [
|
|
'GMAIL' => 'imap.gmail.com',
|
|
'OUTLOOK' => 'outlook.office365.com',
|
|
'HOTMAIL' => 'outlook.office365.com',
|
|
'YAHOO' => 'imap.mail.yahoo.com',
|
|
'AOL' => 'imap.aol.com',
|
|
'GMX' => 'imap.gmx.net',
|
|
'T-ONLINE' => 'secureimap.t-online.de',
|
|
'WEB.DE' => 'imap.web.de',
|
|
'ORANGE' => 'imap.orange.fr',
|
|
'FREE' => 'imap.free.fr',
|
|
];
|
|
return $hosts[strtoupper($isp)] ?? 'imap.' . strtolower($isp) . '.com';
|
|
}
|