Files
wevads-platform/public/bounce-processor.php
2026-04-07 03:04:16 +02:00

63 lines
3.5 KiB
PHP

<?php
require_once('/opt/wevads/config/credentials.php');
$pdo = get_pdo('adx_system');
$pdo->exec("CREATE TABLE IF NOT EXISTS admin.bounces (id SERIAL PRIMARY KEY, email VARCHAR(255), type VARCHAR(50), reason TEXT, campaign_id INTEGER, created_at TIMESTAMP DEFAULT NOW())");
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
header('Content-Type: application/json');
$action = $_POST['action'] ?? '';
if ($action === 'list') {
$bounces = $pdo->query("SELECT * FROM admin.bounces ORDER BY id DESC LIMIT 100")->fetchAll(PDO::FETCH_ASSOC);
$stats = ['hard'=>0,'soft'=>0,'total'=>count($bounces)];
foreach($bounces as $b) $stats[$b['type']]++;
echo json_encode(['success'=>true,'bounces'=>$bounces,'stats'=>$stats]);
exit;
}
if ($action === 'process') {
$pdo->exec("UPDATE admin.harvested_emails SET status='bounced' WHERE email IN (SELECT email FROM admin.bounces WHERE type='hard')");
$count = $pdo->query("SELECT COUNT(*) FROM admin.bounces WHERE type='hard'")->fetchColumn();
echo json_encode(['success'=>true,'processed'=>$count]);
exit;
}
if ($action === 'simulate') {
for($i=0;$i<rand(5,15);$i++){
$type = rand(0,1)?'hard':'soft';
$pdo->exec("INSERT INTO admin.bounces (email, type, reason) VALUES ('bounce".rand(1000,9999)."@test.com', '$type', 'Mailbox not found')");
}
echo json_encode(['success'=>true]);
exit;
}
}
?>
<!DOCTYPE html>
<html><head><meta charset="UTF-8"><title>Bounce Handler</title>
<script src="https://cdn.tailwindcss.com"></script></head>
<body class="bg-gray-900 text-white p-6">
<h1 class="text-3xl font-bold mb-6">📭 Bounce Handler</h1>
<div class="grid grid-cols-3 gap-4 mb-6">
<div class="bg-red-600/30 p-4 rounded-xl text-center"><div id="s-hard" class="text-3xl font-bold">0</div>Hard Bounces</div>
<div class="bg-yellow-600/30 p-4 rounded-xl text-center"><div id="s-soft" class="text-3xl font-bold">0</div>Soft Bounces</div>
<div class="bg-blue-600/30 p-4 rounded-xl text-center"><div id="s-total" class="text-3xl font-bold">0</div>Total</div>
</div>
<div class="flex gap-4 mb-6">
<button onclick="process()" class="bg-green-600 hover:bg-green-500 px-6 py-3 rounded font-bold">🔄 Process Hard Bounces</button>
<button onclick="simulate()" class="bg-gray-600 hover:bg-gray-500 px-6 py-3 rounded font-bold">🧪 Simulate</button>
</div>
<div class="bg-gray-800 p-6 rounded-lg">
<div id="bounces" class="space-y-2 max-h-80 overflow-auto"></div>
</div>
<script>
function load(){fetch('',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'action=list'}).then(r=>r.json()).then(d=>{
document.getElementById('s-hard').textContent=d.stats.hard||0;
document.getElementById('s-soft').textContent=d.stats.soft||0;
document.getElementById('s-total').textContent=d.stats.total||0;
let h='';(d.bounces||[]).forEach(b=>{const col=b.type==='hard'?'red':'yellow';h+='<div class="bg-gray-700 p-2 rounded flex justify-between text-sm"><span>'+b.email+'</span><span class="text-'+col+'-400">'+b.type+'</span></div>';});
document.getElementById('bounces').innerHTML=h||'No bounces';});}
function process(){fetch('',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'action=process'}).then(r=>r.json()).then(d=>{alert('Processed: '+d.processed);load();});}
function simulate(){fetch('',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'action=simulate'}).then(r=>r.json()).then(d=>{load();});}
load();
</script></body></html>