Files
wevads-platform/scripts/brain-accelerator.php

95 lines
4.7 KiB
PHP

<?php
/**
* brain-accelerator SMTP — Direct S89→S151 catch-all
* No DNS, no Graph API, instant delivery verification
*/
$BATCH = min(intval($argv[1] ?? 10), 20);
$ISP = strtoupper($argv[2] ?? '');
$WAIT = intval($argv[3] ?? 5);
$pdo = new PDO("pgsql:host=localhost;dbname=adx_system","admin","admin123");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
function smtpSend($to, $from, $subject, $body) {
$s = @stream_socket_client("tcp://151.80.235.110:25", $en, $es, 10);
if (!$s) return false;
fgets($s);
fwrite($s, "EHLO s89.wevup.app\r\n");
stream_set_timeout($s, 3);
do { $l = fgets($s); } while ($l && $l[3] !== ' ');
fwrite($s, "MAIL FROM:<$from>\r\n"); fgets($s);
fwrite($s, "RCPT TO:<$to>\r\n");
$rcpt = fgets($s);
if (strpos($rcpt, '250') === false) { fclose($s); return false; }
fwrite($s, "DATA\r\n"); fgets($s);
$msg = "From: $from\r\nTo: $to\r\nSubject: $subject\r\nContent-Type: text/html; charset=utf-8\r\nMIME-Version: 1.0\r\n\r\n$body\r\n.\r\n";
fwrite($s, $msg);
$resp = fgets($s);
fwrite($s, "QUIT\r\n"); fclose($s);
return strpos($resp, '250') !== false;
}
echo "═══ BRAIN ACCELERATOR (SMTP Direct) ═══\n";
echo "Batch: $BATCH | Wait: {$WAIT}s | S89→S151:25→DB\n\n";
$sql = "SELECT * FROM admin.brain_configs WHERE status IN ('untested','learning') AND total_sent < 10";
$p = [];
if ($ISP) { $sql .= " AND UPPER(isp_target)=?"; $p[] = $ISP; }
$sql .= " ORDER BY total_sent ASC, RANDOM() LIMIT ?";
$p[] = $BATCH;
$st = $pdo->prepare($sql); $st->execute($p);
$configs = $st->fetchAll(PDO::FETCH_ASSOC);
if (!$configs) die("No configs\n");
$tests = [];
foreach ($configs as $c) {
$tid = 'ba' . $c['id'] . 'x' . substr(uniqid(), 5);
$from = ($c['from_email'] ?: 'test@wevup.app');
// Simulate real headers from the config
$subj = ($c['subject_template'] ?: 'Test') . " [$tid]";
$body = "<html><body>";
$body .= "<p>" . ($c['from_name'] ?: 'Test') . " - {$c['isp_target']} {$c['send_method']}</p>";
$body .= "</body></html>";
$ok = smtpSend('brain@seed.wevup.app', $from, $subj, $body);
echo ($ok ? '✅' : '❌') . " #{$c['id']} {$c['isp_target']} {$c['send_method']} [$tid]\n";
if ($ok) {
$tests[] = ['id' => $c['id'], 'tid' => $tid, 'isp' => $c['isp_target'], 'method' => $c['send_method']];
$pdo->prepare("UPDATE admin.brain_configs SET total_sent=total_sent+1, status=CASE WHEN status='untested' THEN 'learning' ELSE status END, last_tested_at=NOW() WHERE id=?")->execute([$c['id']]);
}
usleep(100000);
}
echo "\n⏳ Waiting {$WAIT}s...\n";
sleep($WAIT);
echo "\n═══ DELIVERY CHECK ═══\n";
$delivered = 0;
foreach ($tests as $t) {
$cmd = "sshpass -p 'MX8D3zSAty7k3243242' ssh -o StrictHostKeyChecking=no ubuntu@151.80.235.110 \"sudo -u postgres psql -d brain_seeds -t -c \\\"SELECT COUNT(*) FROM brain_inbox WHERE track_id='{$t['tid']}'\\\"\" 2>/dev/null";
$count = intval(trim(shell_exec($cmd)));
if ($count > 0) {
$delivered++;
echo "📥 #{$t['id']} {$t['isp']} {$t['method']} → DELIVERED\n";
$pdo->prepare("UPDATE admin.brain_configs SET inbox_count=inbox_count+1, consecutive_inbox=consecutive_inbox+1, consecutive_spam=0, inbox_rate=ROUND((inbox_count::numeric/GREATEST(total_sent,1))*100,2), last_success_at=NOW() WHERE id=?")->execute([$t['id']]);
} else {
echo "❌ #{$t['id']} {$t['isp']} {$t['method']} → FAILED\n";
$pdo->prepare("UPDATE admin.brain_configs SET spam_count=spam_count+1, consecutive_spam=consecutive_spam+1, inbox_rate=ROUND((inbox_count::numeric/GREATEST(total_sent,1))*100,2) WHERE id=?")->execute([$t['id']]);
}
}
// Promote winners
echo "\n═══ WINNERS ═══\n";
$newW = $pdo->query("SELECT id,isp_target,send_method,inbox_rate,total_sent,inbox_count FROM admin.brain_configs WHERE inbox_rate>=80 AND total_sent>=3 AND status!='winner' AND is_active=true ORDER BY inbox_rate DESC")->fetchAll(PDO::FETCH_ASSOC);
foreach ($newW as $w) {
echo "🏆 NEW: #{$w['id']} {$w['isp_target']} {$w['send_method']} {$w['inbox_rate']}% ({$w['total_sent']} tests)\n";
$pdo->prepare("UPDATE admin.brain_configs SET status='winner',is_winner=true WHERE id=?")->execute([$w['id']]);
$pdo->prepare("INSERT INTO admin.brain_winners (config_id,isp_target,inbox_rate,total_tests,stability_score,is_active) VALUES(?,?,?,?,50,true) ON CONFLICT DO NOTHING")->execute([$w['id'],$w['isp_target'],$w['inbox_rate'],$w['total_sent']]);
}
if (!$newW) echo "No new winners yet (need >=80% on 3+ tests)\n";
echo "\nSent: " . count($tests) . " | Delivered: $delivered | Failed: " . (count($tests) - $delivered) . "\n";
echo "Winners: " . $pdo->query("SELECT COUNT(*) FROM admin.brain_winners")->fetchColumn() . "\n";