268 lines
9.9 KiB
PHP
Executable File
268 lines
9.9 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* BRAIN ENGINE - ORCHESTRATEUR AUTOMATIQUE
|
|
*
|
|
* 1. Scan tous les comptes O365 → trouve les fonctionnels
|
|
* 2. Scan tous les seeds → trouve les fonctionnels
|
|
* 3. Test envoi multi-méthodes
|
|
* 4. Log Firebase temps réel
|
|
* 5. Vérifie délivrabilité IMAP
|
|
* 6. Adapte stratégie selon résultats
|
|
*/
|
|
|
|
require '/opt/wevads/vendor/autoload.php';
|
|
require '/opt/wevads/vendor/phpmailer/phpmailer/src/PHPMailer.php';
|
|
require '/opt/wevads/vendor/phpmailer/phpmailer/src/SMTP.php';
|
|
require '/opt/wevads/vendor/phpmailer/phpmailer/src/Exception.php';
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
|
class BrainEngine {
|
|
private $db;
|
|
private $firebase;
|
|
private $workingAccounts = [];
|
|
private $workingSeeds = [];
|
|
|
|
public function __construct() {
|
|
$this->db = new PDO('pgsql:host=localhost;dbname=adx_system', 'admin', 'admin123');
|
|
$this->initFirebase();
|
|
}
|
|
|
|
private function initFirebase() {
|
|
$output = shell_exec("python3 -c \"
|
|
import firebase_admin
|
|
from firebase_admin import credentials, firestore
|
|
try:
|
|
firebase_admin.get_app()
|
|
except:
|
|
cred = credentials.Certificate('/opt/wevads/config/firebase-service-account.json')
|
|
firebase_admin.initialize_app(cred)
|
|
print('OK')
|
|
\" 2>&1");
|
|
$this->firebase = (trim($output) === 'OK');
|
|
}
|
|
|
|
public function logFirebase($collection, $docId, $data) {
|
|
if (!$this->firebase) return;
|
|
$json = json_encode($data);
|
|
shell_exec("python3 -c \"
|
|
import firebase_admin
|
|
from firebase_admin import credentials, firestore
|
|
try:
|
|
firebase_admin.get_app()
|
|
except:
|
|
cred = credentials.Certificate('/opt/wevads/config/firebase-service-account.json')
|
|
firebase_admin.initialize_app(cred)
|
|
db = firestore.client()
|
|
db.collection('$collection').document('$docId').set($json)
|
|
\" 2>&1");
|
|
}
|
|
|
|
// 1. SCANNER COMPTES O365 FONCTIONNELS
|
|
public function scanO365($limit = 50) {
|
|
echo "=== SCAN O365 ($limit comptes) ===\n";
|
|
$stmt = $this->db->query("
|
|
SELECT admin_email, admin_password
|
|
FROM admin.office_accounts
|
|
WHERE status='Active' AND admin_password IS NOT NULL AND admin_password != ''
|
|
ORDER BY RANDOM() LIMIT $limit
|
|
");
|
|
|
|
$tested = 0;
|
|
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $acc) {
|
|
$tested++;
|
|
$mail = new PHPMailer();
|
|
$mail->isSMTP();
|
|
$mail->Host = 'smtp.office365.com';
|
|
$mail->SMTPAuth = true;
|
|
$mail->Username = $acc['admin_email'];
|
|
$mail->Password = $acc['admin_password'];
|
|
$mail->SMTPSecure = 'tls';
|
|
$mail->Port = 587;
|
|
$mail->Timeout = 3;
|
|
|
|
try {
|
|
if ($mail->smtpConnect()) {
|
|
$this->workingAccounts[] = $acc;
|
|
echo " ✓ {$acc['admin_email']}\n";
|
|
}
|
|
} catch (Exception $e) {}
|
|
$mail->smtpClose();
|
|
|
|
if (count($this->workingAccounts) >= 10) break;
|
|
}
|
|
|
|
echo "Trouvé: " . count($this->workingAccounts) . " comptes fonctionnels\n";
|
|
return $this->workingAccounts;
|
|
}
|
|
|
|
// 2. SCANNER SEEDS FONCTIONNELS
|
|
public function scanSeeds($isp = null, $limit = 20) {
|
|
$where = $isp ? "AND isp='$isp'" : "";
|
|
echo "=== SCAN SEEDS" . ($isp ? " ($isp)" : "") . " ===\n";
|
|
|
|
$smtpServers = [
|
|
'GMX' => ['host' => 'mail.gmx.net', 'port' => 587],
|
|
'T-ONLINE' => ['host' => 'securesmtp.t-online.de', 'port' => 587],
|
|
'HOTMAIL' => ['host' => 'smtp-mail.outlook.com', 'port' => 587],
|
|
'GMAIL' => ['host' => 'smtp.gmail.com', 'port' => 587],
|
|
'ORANGE' => ['host' => 'smtp.orange.fr', 'port' => 587],
|
|
];
|
|
|
|
$stmt = $this->db->query("
|
|
SELECT email, password, isp
|
|
FROM admin.brain_seeds
|
|
WHERE password IS NOT NULL AND password != '' $where
|
|
ORDER BY RANDOM() LIMIT $limit
|
|
");
|
|
|
|
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $seed) {
|
|
if (!isset($smtpServers[$seed['isp']])) continue;
|
|
$smtp = $smtpServers[$seed['isp']];
|
|
|
|
$mail = new PHPMailer();
|
|
$mail->isSMTP();
|
|
$mail->Host = $smtp['host'];
|
|
$mail->SMTPAuth = true;
|
|
$mail->Username = $seed['email'];
|
|
$mail->Password = $seed['password'];
|
|
$mail->SMTPSecure = 'tls';
|
|
$mail->Port = $smtp['port'];
|
|
$mail->Timeout = 3;
|
|
|
|
try {
|
|
if ($mail->smtpConnect()) {
|
|
$this->workingSeeds[] = array_merge($seed, $smtp);
|
|
echo " ✓ {$seed['email']} ({$seed['isp']})\n";
|
|
}
|
|
} catch (Exception $e) {}
|
|
$mail->smtpClose();
|
|
}
|
|
|
|
echo "Trouvé: " . count($this->workingSeeds) . " seeds fonctionnels\n";
|
|
return $this->workingSeeds;
|
|
}
|
|
|
|
// 3. ENVOYER EMAIL AVEC TRACKING
|
|
public function send($method, $account, $recipient, $subject, $body) {
|
|
$trackingId = strtolower($method) . '_' . substr(md5(microtime()), 0, 8);
|
|
|
|
$mail = new PHPMailer();
|
|
$mail->isSMTP();
|
|
|
|
switch ($method) {
|
|
case 'O365':
|
|
$mail->Host = 'smtp.office365.com';
|
|
$mail->SMTPAuth = true;
|
|
$mail->Username = $account['admin_email'];
|
|
$mail->Password = $account['admin_password'];
|
|
$mail->SMTPSecure = 'tls';
|
|
$mail->Port = 587;
|
|
$mail->setFrom($account['admin_email'], 'Brain Engine');
|
|
break;
|
|
|
|
case 'SEED':
|
|
$mail->Host = $account['host'];
|
|
$mail->SMTPAuth = true;
|
|
$mail->Username = $account['email'];
|
|
$mail->Password = $account['password'];
|
|
$mail->SMTPSecure = 'tls';
|
|
$mail->Port = $account['port'];
|
|
$mail->setFrom($account['email'], 'Brain Engine');
|
|
break;
|
|
}
|
|
|
|
// Ajouter tracking dans le body
|
|
$trackingLink = "https://weval.ma/?t=$trackingId&m=$method";
|
|
$bodyWithTracking = str_replace('{TRACKING_LINK}', $trackingLink, $body);
|
|
$bodyWithTracking = str_replace('{TRACKING_ID}', $trackingId, $bodyWithTracking);
|
|
|
|
$mail->addAddress($recipient);
|
|
$mail->Subject = str_replace('{TRACKING_ID}', $trackingId, $subject);
|
|
$mail->isHTML(true);
|
|
$mail->Body = $bodyWithTracking;
|
|
|
|
// Log Firebase AVANT envoi
|
|
$this->logFirebase('brain_sends', $trackingId, [
|
|
'tracking_id' => $trackingId,
|
|
'method' => $method,
|
|
'sender' => $mail->Username,
|
|
'recipient' => $recipient,
|
|
'subject' => $mail->Subject,
|
|
'status' => 'sending',
|
|
'timestamp' => date('c')
|
|
]);
|
|
|
|
try {
|
|
if ($mail->send()) {
|
|
$this->logFirebase('brain_sends', $trackingId, [
|
|
'status' => 'sent',
|
|
'sent_at' => date('c')
|
|
]);
|
|
return ['success' => true, 'tracking_id' => $trackingId];
|
|
}
|
|
} catch (Exception $e) {
|
|
$this->logFirebase('brain_sends', $trackingId, [
|
|
'status' => 'failed',
|
|
'error' => $e->getMessage()
|
|
]);
|
|
}
|
|
|
|
return ['success' => false, 'tracking_id' => $trackingId];
|
|
}
|
|
|
|
// 4. CAMPAGNE AUTOMATIQUE
|
|
public function runCampaign($recipient, $count = 5) {
|
|
echo "\n╔═══════════════════════════════════════════════════════════╗\n";
|
|
echo "║ BRAIN ENGINE - CAMPAGNE AUTO ║\n";
|
|
echo "╚═══════════════════════════════════════════════════════════╝\n\n";
|
|
|
|
// Scanner si pas encore fait
|
|
if (empty($this->workingAccounts)) $this->scanO365(50);
|
|
if (empty($this->workingSeeds)) $this->scanSeeds(null, 30);
|
|
|
|
$template = '
|
|
<html><body style="font-family:Arial;padding:20px;background:#f5f5f5;">
|
|
<div style="max-width:600px;margin:auto;background:white;padding:30px;border-radius:10px;">
|
|
<h1 style="color:#10b981;">🎯 Offre Exclusive</h1>
|
|
<p>Tracking: <strong>{TRACKING_ID}</strong></p>
|
|
<p style="text-align:center;margin:30px;">
|
|
<a href="{TRACKING_LINK}" style="background:#10b981;color:white;padding:20px 50px;text-decoration:none;border-radius:8px;font-size:18px;display:inline-block;">VOIR L\'OFFRE</a>
|
|
</p>
|
|
</div>
|
|
</body></html>';
|
|
|
|
$results = [];
|
|
$sent = 0;
|
|
|
|
// Envoyer via O365
|
|
foreach (array_slice($this->workingAccounts, 0, $count) as $acc) {
|
|
$r = $this->send('O365', $acc, $recipient, "Offre #{TRACKING_ID}", $template);
|
|
$results[] = $r;
|
|
if ($r['success']) {
|
|
echo "✓ O365: {$acc['admin_email']} → {$r['tracking_id']}\n";
|
|
$sent++;
|
|
}
|
|
}
|
|
|
|
// Envoyer via Seeds
|
|
foreach (array_slice($this->workingSeeds, 0, $count) as $seed) {
|
|
$r = $this->send('SEED', $seed, $recipient, "Offre #{TRACKING_ID}", $template);
|
|
$results[] = $r;
|
|
if ($r['success']) {
|
|
echo "✓ SEED ({$seed['isp']}): {$seed['email']} → {$r['tracking_id']}\n";
|
|
$sent++;
|
|
}
|
|
}
|
|
|
|
echo "\n=== RÉSUMÉ: $sent emails envoyés ===\n";
|
|
echo "Vérifie $recipient (inbox + spam)!\n";
|
|
|
|
return $results;
|
|
}
|
|
}
|
|
|
|
// EXÉCUTION
|
|
$brain = new BrainEngine();
|
|
$brain->runCampaign('joecloud0101@proton.me', 3);
|