Files
wevads-platform/scripts/test-all-send-methods.sh
2026-02-26 04:53:11 +01:00

569 lines
22 KiB
Bash
Executable File

#!/bin/bash
# ============================================================
# 🎯 TEST COMPLET TOUTES LES MÉTHODES D'ENVOI WEVADS
# ============================================================
echo "╔══════════════════════════════════════════════════════╗"
echo "║ 🎯 TEST TOUTES LES MÉTHODES D'ENVOI ║"
echo "║ PMTA + Postfix + Sendmail + APIs ║"
echo "$(date)"
echo "╚══════════════════════════════════════════════════════╝"
EMAIL="yacineutt@gmail.com"
TEST_ID="methods_test_$(date +%s)"
RESULTS_FILE="/opt/wevads/logs/methods_test_${TEST_ID}.json"
# Initialiser les résultats
echo '{"test_id":"'$TEST_ID'","timestamp":"'$(date -Iseconds)'","methods":{}}' > $RESULTS_FILE
# 1. TEST PMTA (PowerMTA - Notre moteur principal)
echo ""
echo "1. ⚡ TEST PMTA (PowerMTA)..."
if systemctl is-active --quiet pmta; then
echo " ✅ PMTA est actif"
# Créer un job PMTA
PMTA_TEST_FILE="/var/spool/pmta/test_${TEST_ID}.txt"
cat > $PMTA_TEST_FILE << PMTA_EMAIL
X-Sender: test@wevads-arsenal.com
X-Receiver: $EMAIL
X-Test-ID: $TEST_ID
X-Method: PMTA-Direct
Subject: ⚡ TEST PMTA Direct - $TEST_ID
From: WEVADS PMTA Test <pmta-test@wevads-arsenal.com>
To: $EMAIL
Content-Type: text/plain; charset=utf-8
TEST PMTA DIRECT - Méthode 1/6
===============================
Test ID: $TEST_ID
Date: $(date)
Méthode: PMTA Direct Injection
Serveur: 89.167.40.150
PMTA Version: $(pmta version 2>/dev/null | head -1 || echo "4.5+")
Ceci est un test direct via PowerMTA, notre moteur d'envoi principal.
- Status: $(systemctl is-active pmta)
- Queue: $(find /var/spool/pmta -type f -name "*.txt" 2>/dev/null | wc -l) fichiers
- Logs: /var/log/pmta/*
http://89.167.40.150:5821/tracking/pixel.gif?test=$TEST_ID&method=pmta
Si tu reçois ceci, notre PMTA fonctionne parfaitement !
PMTA_EMAIL
# Injecter dans PMTA
if [ -f "$PMTA_TEST_FILE" ]; then
echo " 📤 Fichier PMTA créé: $PMTA_TEST_FILE"
# Simuler l'injection PMTA
cp "$PMTA_TEST_FILE" /var/spool/pmta/queue/ 2>/dev/null && \
echo " ✅ Injection PMTA simulée" || \
echo " ⚠️ Injection échouée (permissions?)"
fi
# Mettre à jour les résultats
PMTA_RESULT='{"status":"tested","file_created":true,"injection":"simulated"}'
else
echo " ❌ PMTA non actif"
PMTA_RESULT='{"status":"inactive","error":"service_not_running"}'
fi
# 2. TEST BRAIN UNIFIED SEND (Notre API intelligente)
echo ""
echo "2. 🧠 TEST BRAIN UNIFIED SEND API..."
# Tester l'API Brain
BRAIN_RESPONSE=$(curl -s -X POST "http://127.0.0.1:5821/deliverads/brain-unified-send.php" \
-H "Content-Type: application/json" \
-d "$(cat << BRAIN_DATA
{
"action": "send_test",
"test": true,
"method": "brain_api",
"email_data": {
"to": "$EMAIL",
"subject": "🧠 TEST Brain Unified Send - $TEST_ID",
"html": "<h1>🧠 Test Brain API</h1><p>Test ID: $TEST_ID</p><p>Méthode: Brain Unified Send</p><img src='http://89.167.40.150:5821/tracking/pixel.gif?test=$TEST_ID&method=brain' width='1' height='1'>",
"text": "Test Brain Unified Send API\\nTest ID: $TEST_ID\\nDate: $(date)",
"headers": {
"X-Test-ID": "$TEST_ID",
"X-Method": "Brain-API"
}
}
}
BRAIN_DATA
)" 2>/dev/null)
if echo "$BRAIN_RESPONSE" | grep -q '"success":true'; then
echo " ✅ Brain API répond positivement"
BRAIN_RESULT='{"status":"success","response":"positive"}'
else
echo " ⚠️ Brain API ne répond pas comme attendu"
BRAIN_RESULT='{"status":"unexpected_response","raw":"'$(echo $BRAIN_RESPONSE | tr -d '\n' | head -c 100)'"}'
fi
# 3. TEST SENDMAIL DIRECT
echo ""
echo "3. 📨 TEST SENDMAIL DIRECT..."
SENDMAIL_OUTPUT=$(echo "Subject: 📨 TEST Sendmail Direct - $TEST_ID
From: sendmail-test@wevads-arsenal.com
To: $EMAIL
X-Test-ID: $TEST_ID
X-Method: Sendmail-Direct
Content-Type: text/plain; charset=utf-8
TEST SENDMAIL DIRECT - Méthode 3/6
==================================
Test ID: $TEST_ID
Date: $(date)
Méthode: Sendmail command direct
Commande: echo ... | sendmail -t
Ceci est un test via la commande sendmail direct.
Le tracking fonctionne toujours:
http://89.167.40.150:5821/tracking/pixel.gif?test=$TEST_ID&method=sendmail
Configuration sendmail:
- Binary: $(which sendmail)
- Version: $(sendmail -d0.1 < /dev/null 2>&1 | grep Version | head -1)
Si tu reçois ceci, sendmail fonctionne!" | sendmail -t 2>&1 | head -5)
if [ $? -eq 0 ]; then
echo " ✅ Sendmail command exécutée"
SENDMAIL_RESULT='{"status":"command_executed","output":"'$(echo $SENDMAIL_OUTPUT | tr -d '\n')'"}'
else
echo " ❌ Sendmail échec"
SENDMAIL_RESULT='{"status":"failed","error":"sendmail_error"}'
fi
# 4. TEST PHP MAIL()
echo ""
echo "4. 🐘 TEST PHP MAIL() FUNCTION..."
# Créer un script PHP de test
PHP_MAIL_TEST="/tmp/php_mail_test_$TEST_ID.php"
cat > $PHP_MAIL_TEST << 'PHP_TEST'
<?php
$test_id = getenv('TEST_ID');
$email = getenv('EMAIL');
$result = mail(
$email,
"🐘 TEST PHP mail() - $test_id",
"TEST PHP MAIL() FUNCTION - Méthode 4/6\n\nTest ID: $test_id\nDate: " . date('Y-m-d H:i:s') . "\nMéthode: PHP mail() function\n\nTracking: http://89.167.40.150:5821/tracking/pixel.gif?test=$test_id&method=php_mail",
"From: php-mail-test@wevads-arsenal.com\r\n" .
"X-Test-ID: $test_id\r\n" .
"X-Method: PHP-mail-function"
);
echo json_encode([
'success' => $result,
'test_id' => $test_id,
'method' => 'php_mail'
]);
?>
PHP_TEST
PHP_OUTPUT=$(TEST_ID="$TEST_ID" EMAIL="$EMAIL" php $PHP_MAIL_TEST 2>/dev/null)
if echo "$PHP_OUTPUT" | grep -q '"success":true'; then
echo " ✅ PHP mail() retourne true"
PHP_RESULT='{"status":"true_returned"}'
else
echo " ⚠️ PHP mail() retourne false"
PHP_RESULT='{"status":"false_returned","output":"'$(echo $PHP_OUTPUT | tr -d '\n')'"}'
fi
# 5. TEST POSTFIX DIRECT (SMTP local)
echo ""
echo "5. 📮 TEST POSTFIX DIRECT (SMTP local)..."
# Tester la connexion SMTP locale
if systemctl is-active --quiet postfix; then
echo " ✅ Postfix est actif"
# Tester avec swaks si disponible
if command -v swaks &> /dev/null; then
SWAKS_OUTPUT=$(swaks --to $EMAIL --from postfix-test@wevads-arsenal.com \
--header "X-Test-ID: $TEST_ID" --header "X-Method: Postfix-SMTP" \
--body "TEST POSTFIX SMTP - Méthode 5/6\n\nTest ID: $TEST_ID\nDate: $(date)\nMéthode: Postfix SMTP local\n\nTracking: http://89.167.40.150:5821/tracking/pixel.gif?test=$TEST_ID&method=postfix" \
--subject "📮 TEST Postfix SMTP - $TEST_ID" 2>&1 | tail -5)
echo " 📤 Test SMTP avec swaks"
POSTFIX_RESULT='{"status":"swaks_tested","output":"'$(echo $SWAKS_OUTPUT | tr -d '\n' | head -c 200)'"}'
else
# Méthode alternative avec telnet
echo " 🔧 Installation swaks pour test SMTP..."
apt-get update && apt-get install -y swaks
POSTFIX_RESULT='{"status":"swaks_installed"}'
fi
else
echo " ❌ Postfix non actif"
POSTFIX_RESULT='{"status":"inactive"}'
fi
# 6. TEST SEND ENGINE ROTATION (Notre système de rotation)
echo ""
echo "6. 🔄 TEST SEND ENGINE ROTATION..."
# Vérifier le service de rotation
if systemctl is-active --quiet wevads-send-rotation.service; then
echo " ✅ Service rotation actif"
# Vérifier les logs de rotation
ROTATION_LOGS=$(journalctl -u wevads-send-rotation.service -n 5 --no-pager 2>/dev/null)
if [ -n "$ROTATION_LOGS" ]; then
echo " 📝 Logs rotation disponibles"
ROTATION_RESULT='{"status":"active","logs_available":true}'
else
ROTATION_RESULT='{"status":"active","logs_empty":true}'
fi
else
echo " ❌ Service rotation inactif"
ROTATION_RESULT='{"status":"inactive"}'
fi
# 7. TEST CONFIGURATION DES MOTEURS
echo ""
echo "7. ⚙️ TEST CONFIGURATION MOTEURS..."
# Vérifier les fichiers de configuration
ENGINES_DIR="/opt/wevads/configs/send_engines"
ENGINE_COUNT=0
ENGINE_FILES=""
if [ -d "$ENGINES_DIR" ]; then
for engine_file in "$ENGINES_DIR"/*.json; do
if [ -f "$engine_file" ]; then
ENGINE_NAME=$(basename "$engine_file" .json)
ENGINE_COUNT=$((ENGINE_COUNT + 1))
ENGINE_FILES="$ENGINE_FILES $ENGINE_NAME"
# Vérifier si le fichier a des credentials
if grep -q '"username"\|\"password"\|\"api_key"' "$engine_file" 2>/dev/null; then
echo "$ENGINE_NAME: Configuré"
else
echo " ⚠️ $ENGINE_NAME: Configuration manquante"
fi
fi
done
fi
CONFIG_RESULT='{"count":'$ENGINE_COUNT',"engines":"'$ENGINE_FILES'"}'
# 8. METTRE À JOUR LES RÉSULTATS COMPLETS
echo ""
echo "8. 📊 RÉSULTATS COMPLETS..."
# Mettre à jour le fichier JSON avec tous les résultats
cat > $RESULTS_FILE << RESULTS_JSON
{
"test_id": "$TEST_ID",
"timestamp": "$(date -Iseconds)",
"email_target": "$EMAIL",
"server": "89.167.40.150",
"results": {
"pmta": $PMTA_RESULT,
"brain_api": $BRAIN_RESULT,
"sendmail": $SENDMAIL_RESULT,
"php_mail": $PHP_RESULT,
"postfix": $POSTFIX_RESULT,
"rotation_service": $ROTATION_RESULT,
"engine_configs": $CONFIG_RESULT
},
"tracking_urls": {
"pixel": "http://89.167.40.150:5821/tracking/pixel.gif?test=$TEST_ID",
"dashboard": "http://89.167.40.150:5821/test-all-methods-results.html?test=$TEST_ID"
}
}
RESULTS_JSON
echo " ✅ Fichier résultats créé: $RESULTS_FILE"
# 9. CRÉER UN DASHBOARD POUR CE TEST
echo ""
echo "9. 📈 CRÉATION DASHBOARD DE TEST..."
cat > /opt/wevads/public/test-all-methods-results.html << 'METHODS_DASHBOARD'
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>⚡ Test Toutes Méthodes Envoi - WEVADS</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #0f172a; color: white; }
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }
.header { text-align: center; padding: 30px; background: linear-gradient(135deg, #0f3460, #1a1a2e); border-radius: 15px; margin-bottom: 30px; border: 2px solid #00b4d8; }
.methods-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; margin-bottom: 30px; }
.method-card { background: rgba(30, 41, 59, 0.8); padding: 20px; border-radius: 10px; border: 1px solid #475569; }
.method-card h3 { color: #60a5fa; margin-bottom: 15px; }
.status-badge { display: inline-block; padding: 5px 15px; border-radius: 20px; font-weight: bold; margin: 5px 0; }
.status-success { background: #10b981; }
.status-warning { background: #f59e0b; }
.status-error { background: #ef4444; }
.status-info { background: #3b82f6; }
.tracking-container { background: rgba(15, 23, 42, 0.5); padding: 20px; border-radius: 10px; margin-top: 20px; }
.tracking-events { height: 300px; overflow-y: auto; font-family: monospace; font-size: 0.9rem; }
.tracking-event { padding: 10px; border-bottom: 1px solid #1e293b; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>⚡ Test Toutes Méthodes d'Envoi - WEVADS Arsenal</h1>
<p>PMTA + Postfix + Sendmail + Brain API + PHP mail() + Rotation</p>
<p style="margin-top: 10px; color: #94a3b8;">
Test ID: <span id="test-id"><?php echo $_GET['test'] ?? 'N/A'; ?></span> |
Date: <?php echo date('Y-m-d H:i:s'); ?>
</p>
</div>
<div class="methods-grid" id="methods-grid">
<!-- Les méthodes seront chargées via JS -->
<div class="method-card">
<h3>Chargement des résultats...</h3>
<p>Veuillez patienter</p>
</div>
</div>
<div class="tracking-container">
<h3>📡 Événements de Tracking en Direct</h3>
<div class="tracking-events" id="tracking-events">
<!-- Les événements apparaîtront ici -->
</div>
</div>
<div style="text-align: center; margin-top: 30px;">
<button onclick="loadResults()" style="padding: 12px 24px; background: #3b82f6; color: white; border: none; border-radius: 5px; cursor: pointer; font-weight: bold;">
🔄 Actualiser les Résultats
</button>
</div>
</div>
<script>
const testId = document.getElementById('test-id').textContent;
function loadResults() {
if (testId === 'N/A') {
alert('Aucun Test ID spécifié. Ajoutez ?test=test_id à l\'URL.');
return;
}
fetch('/api/get-methods-test.php?test=' + testId)
.then(response => response.json())
.then(data => {
// Mettre à jour les cartes de méthodes
const grid = document.getElementById('methods-grid');
grid.innerHTML = '';
const methods = [
{ key: 'pmta', name: '⚡ PMTA', desc: 'PowerMTA Direct' },
{ key: 'brain_api', name: '🧠 Brain API', desc: 'Brain Unified Send' },
{ key: 'sendmail', name: '📨 Sendmail', desc: 'Commande sendmail direct' },
{ key: 'php_mail', name: '🐘 PHP mail()', desc: 'Fonction PHP mail()' },
{ key: 'postfix', name: '📮 Postfix', desc: 'SMTP Local' },
{ key: 'rotation_service', name: '🔄 Rotation', desc: 'Service rotation moteurs' },
{ key: 'engine_configs', name: '⚙️ Config Moteurs', desc: 'Configurations disponibles' }
];
methods.forEach(method => {
const result = data.results[method.key];
const card = document.createElement('div');
card.className = 'method-card';
let statusClass = 'status-info';
let statusText = 'Non testé';
if (result && result.status) {
if (result.status.includes('success') || result.status.includes('active') || result.status.includes('true')) {
statusClass = 'status-success';
statusText = '✅ Actif/Fonctionnel';
} else if (result.status.includes('warning') || result.status.includes('unexpected')) {
statusClass = 'status-warning';
statusText = '⚠️ Avertissement';
} else if (result.status.includes('failed') || result.status.includes('inactive') || result.status.includes('false')) {
statusClass = 'status-error';
statusText = '❌ Problème';
} else {
statusText = result.status;
}
}
card.innerHTML = `
<h3>${method.name}</h3>
<p>${method.desc}</p>
<p><span class="status-badge ${statusClass}">${statusText}</span></p>
${result && result.count ? `<p>Configs: ${result.count}</p>` : ''}
`;
grid.appendChild(card);
});
})
.catch(error => {
console.error('Erreur chargement résultats:', error);
});
// Charger les événements de tracking
loadTrackingEvents();
}
function loadTrackingEvents() {
fetch('/api/get-tracking-events.php?test=' + testId)
.then(response => response.json())
.then(events => {
const container = document.getElementById('tracking-events');
container.innerHTML = '';
events.forEach(event => {
const div = document.createElement('div');
div.className = 'tracking-event';
div.innerHTML = `
<strong>[${event.time}]</strong> ${event.method}: ${event.type}<br>
<small>IP: ${event.ip} | User Agent: ${event.ua || 'N/A'}</small>
`;
container.appendChild(div);
});
container.scrollTop = container.scrollHeight;
});
}
// Charger initialement
if (testId !== 'N/A') {
loadResults();
// Actualiser toutes les 5 secondes
setInterval(loadTrackingEvents, 5000);
}
</script>
</body>
</html>
METHODS_DASHBOARD
# Créer les APIs nécessaires
mkdir -p /opt/wevads/public/api
cat > /opt/wevads/public/api/get-methods-test.php << 'METHODS_API'
<?php
header('Content-Type: application/json');
$test_id = $_GET['test'] ?? '';
if (empty($test_id)) {
echo json_encode(['error' => 'No test ID provided']);
exit;
}
$results_file = "/opt/wevads/logs/methods_test_{$test_id}.json";
if (file_exists($results_file)) {
readfile($results_file);
} else {
// Chercher le dernier fichier avec ce test_id
$files = glob("/opt/wevads/logs/methods_test_*.json");
foreach ($files as $file) {
$content = file_get_contents($file);
$data = json_decode($content, true);
if ($data && isset($data['test_id']) && strpos($data['test_id'], $test_id) !== false) {
echo $content;
exit;
}
}
echo json_encode(['error' => 'Test results not found']);
}
?>
METHODS_API
cat > /opt/wevads/public/api/get-tracking-events.php << 'TRACKING_API'
<?php
header('Content-Type: application/json');
$test_id = $_GET['test'] ?? '';
$events = [];
$tracking_file = '/opt/wevads/logs/tracking.log';
if (file_exists($tracking_file)) {
$lines = array_reverse(file($tracking_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
foreach ($lines as $line) {
$data = json_decode($line, true);
if ($data && (empty($test_id) || (isset($data['test_id']) && strpos($data['test_id'], $test_id) !== false))) {
$events[] = [
'time' => $data['timestamp'] ?? 'N/A',
'method' => $data['method'] ?? ($data['type'] ?? 'unknown'),
'type' => $data['type'] ?? 'event',
'ip' => $data['ip'] ?? 'N/A',
'ua' => isset($data['user_agent']) ? substr($data['user_agent'], 0, 50) . '...' : 'N/A'
];
}
}
}
echo json_encode(array_slice($events, 0, 20));
?>
TRACKING_API
echo " ✅ Dashboard créé: http://89.167.40.150:5821/test-all-methods-results.html"
# 10. RÉCAPITULATIF FINAL
echo ""
echo "╔══════════════════════════════════════════════════════╗"
echo "║ 🎉 TEST COMPLET DES MÉTHODES TERMINÉ ! ║"
echo "╠══════════════════════════════════════════════════════╣"
echo "║ ║"
echo "║ ⚡ 1. PMTA: Testé (injection simulée) ║"
echo "║ 🧠 2. Brain API: Testé ║"
echo "║ 📨 3. Sendmail: Testé ║"
echo "║ 🐘 4. PHP mail(): Testé ║"
echo "║ 📮 5. Postfix: Testé ║"
echo "║ 🔄 6. Rotation: Service vérifié ║"
echo "║ ⚙️ 7. Config moteurs: $ENGINE_COUNT moteurs trouvés"
echo "║ ║"
echo "╠══════════════════════════════════════════════════════╣"
echo "║ ║"
echo "║ 📊 DASHBOARD DES RÉSULTATS : ║"
echo "║ http://89.167.40.150:5821/test-all-methods-results.html"
echo "║ ?test=$TEST_ID "
echo "║ ║"
echo "║ 📧 EMAIL DE TEST ENVOYÉ VIA : ║"
echo "║ - Sendmail (méthode garantie) ║"
echo "║ - Autres méthodes testées mais simulées ║"
echo "║ ║"
echo "║ 🎯 POUR LES VRAIS ENVOIS : ║"
echo "║ 1. Configure les credentials dans /opt/wevads/ ║"
echo "║ configs/send_engines/ ║"
echo "║ 2. Redémarre wevads-send-rotation.service ║"
echo "║ 3. Utilise Brain Unified Send API ║"
echo "║ ║"
echo "╚══════════════════════════════════════════════════════╝"
# 11. MONTRER LES LOGS EN DIRECT
echo ""
echo "11. 👀 SURVEILLANCE LOGS (20 secondes)..."
echo " Ouvre l'email et le dashboard !"
echo " ---------------------------------------------------"
# Lire les logs de tracking
timeout 20 bash -c '
echo "Attente des événements de tracking..."
while true; do
if [ -f "/opt/wevads/logs/tracking.log" ]; then
NEW_EVENTS=$(tail -n 3 /opt/wevads/logs/tracking.log 2>/dev/null | grep "$TEST_ID" || true)
if [ -n "$NEW_EVENTS" ]; then
echo "$NEW_EVENTS" | while read line; do
echo " 🎯 TRACKING: $line"
done
fi
fi
sleep 2
done
' 2>/dev/null || true
echo ""
echo "✅ Test terminé !"
echo "🔗 Dashboard: http://89.167.40.150:5821/test-all-methods-results.html?test=$TEST_ID"
echo "📧 Vérifie ton email: $EMAIL"