Files
whatsapp/test_config.php
T
2026-01-12 11:06:43 -05:00

214 lines
7.7 KiB
PHP

<?php
/**
* 🔧 TEST CONFIGURACIÓN - WhatsApp Bot
* Prueba SOLO la configuración sin cargar todo el sistema
*/
// Headers para mostrar errores
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "<!DOCTYPE html><html><head><meta charset='UTF-8'>";
echo "<title>🔧 Test Configuración</title>";
echo "<style>body{font-family:monospace;margin:20px;background:#000;color:#00ff00}";
echo ".ok{color:#00ff00}.error{color:#ff0040}.warning{color:#ffaa00}";
echo ".section{background:#111;padding:15px;margin:10px 0;border:1px solid #333}";
echo "</style></head><body>";
echo "<h1>🔧 TEST CONFIGURACIÓN</h1>";
// 1. Verificar que el archivo existe
if (!file_exists('config/config.php')) {
echo "<div class='error'>❌ CRÍTICO: config/config.php no encontrado</div>";
echo "<div class='warning'>Asegúrate de que el archivo esté en: config/config.php</div>";
exit;
}
echo "<div class='ok'>✅ config/config.php encontrado</div>";
// 2. Verificar permisos del archivo
if (!is_readable('config/config.php')) {
echo "<div class='error'>❌ CRÍTICO: config/config.php no es legible</div>";
echo "<div class='warning'>Ejecuta: chmod 644 config/config.php</div>";
exit;
}
echo "<div class='ok'>✅ config/config.php es legible</div>";
// 3. Intentar cargar el archivo
echo "<div class='section'>";
echo "<h2>📋 CARGANDO CONFIGURACIÓN...</h2>";
try {
// Capturar cualquier output
ob_start();
// Capturar errores
$error_before = error_get_last();
// Incluir el archivo
require_once 'config/config.php';
// Obtener output
$output = ob_get_clean();
// Verificar si hubo errores
$error_after = error_get_last();
if ($error_after && $error_after !== $error_before) {
echo "<div class='error'>❌ ERROR al cargar config: " . htmlspecialchars($error_after['message']) . "</div>";
echo "<div class='warning'>Línea: " . $error_after['line'] . " en " . $error_after['file'] . "</div>";
} elseif (!empty($output)) {
echo "<div class='warning'>⚠️ ADVERTENCIA: config.php produce output:</div>";
echo "<div class='warning'>" . htmlspecialchars($output) . "</div>";
echo "<div class='warning'>Los archivos de configuración NO deben producir output</div>";
} else {
echo "<div class='ok'>✅ config/config.php cargado sin errores</div>";
}
} catch (ParseError $e) {
echo "<div class='error'>❌ ERROR DE SINTAXIS en config.php:</div>";
echo "<div class='error'>" . htmlspecialchars($e->getMessage()) . "</div>";
echo "<div class='error'>Línea: " . $e->getLine() . "</div>";
exit;
} catch (Error $e) {
echo "<div class='error'>❌ ERROR FATAL en config.php:</div>";
echo "<div class='error'>" . htmlspecialchars($e->getMessage()) . "</div>";
exit;
} catch (Exception $e) {
echo "<div class='error'>❌ EXCEPCIÓN en config.php:</div>";
echo "<div class='error'>" . htmlspecialchars($e->getMessage()) . "</div>";
exit;
}
echo "</div>";
// 4. Verificar constantes requeridas
echo "<div class='section'>";
echo "<h2>🗄️ VERIFICANDO CONSTANTES DE BD...</h2>";
$required_constants = [
'DB_HOST' => 'Servidor de base de datos',
'DB_NAME' => 'Nombre de la base de datos',
'DB_USER' => 'Usuario de la base de datos',
'DB_PASS' => 'Contraseña de la base de datos',
'DB_PORT' => 'Puerto de la base de datos',
'DB_CHARSET' => 'Charset de la base de datos'
];
$all_defined = true;
foreach ($required_constants as $const => $desc) {
if (defined($const)) {
$value = constant($const);
$display_value = ($const === 'DB_PASS') ? str_repeat('*', strlen($value)) : $value;
echo "<div class='ok'>✅ $const = '$display_value' ($desc)</div>";
} else {
echo "<div class='error'>❌ $const no definida ($desc)</div>";
$all_defined = false;
}
}
if (!$all_defined) {
echo "<div class='error'>❌ CRÍTICO: Faltan constantes de base de datos</div>";
echo "<div class='warning'>El sistema no puede funcionar sin estas constantes</div>";
}
echo "</div>";
// 5. Test de conexión a BD (solo si todas las constantes están)
if ($all_defined) {
echo "<div class='section'>";
echo "<h2>🔌 TEST CONEXIÓN BASE DE DATOS...</h2>";
try {
$dsn = "mysql:host=" . DB_HOST . ";port=" . DB_PORT . ";dbname=" . DB_NAME . ";charset=" . DB_CHARSET;
echo "<div class='ok'>DSN: $dsn</div>";
$pdo = new PDO($dsn, DB_USER, DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_TIMEOUT => 5
]);
echo "<div class='ok'>✅ CONEXIÓN EXITOSA a la base de datos</div>";
// Verificar algunas tablas
$tables_to_check = ['conversations', 'messages', 'settings', 'message_templates'];
foreach ($tables_to_check as $table) {
try {
$stmt = $pdo->query("SHOW TABLES LIKE '$table'");
if ($stmt->rowCount() > 0) {
echo "<div class='ok'>✅ Tabla '$table' existe</div>";
} else {
echo "<div class='warning'>⚠️ Tabla '$table' NO existe</div>";
}
} catch (Exception $e) {
echo "<div class='error'>❌ Error verificando tabla '$table': " . htmlspecialchars($e->getMessage()) . "</div>";
}
}
} catch (PDOException $e) {
echo "<div class='error'>❌ ERROR DE CONEXIÓN:</div>";
echo "<div class='error'>" . htmlspecialchars($e->getMessage()) . "</div>";
echo "<div class='warning'>Verifica:</div>";
echo "<div class='warning'>• Host: " . DB_HOST . "</div>";
echo "<div class='warning'>• Base datos: " . DB_NAME . "</div>";
echo "<div class='warning'>• Usuario: " . DB_USER . "</div>";
echo "<div class='warning'>• Puerto: " . DB_PORT . "</div>";
}
echo "</div>";
}
// 6. Verificar otras constantes importantes
echo "<div class='section'>";
echo "<h2>🔑 OTRAS CONSTANTES DEL SISTEMA...</h2>";
$other_constants = [
'ADMIN_USERNAME' => 'Usuario administrador',
'ADMIN_PASSWORD' => 'Contraseña administrador',
'SECRET_KEY' => 'Clave secreta',
'WHATSAPP_TOKEN' => 'Token de WhatsApp',
'WHATSAPP_PHONE_NUMBER_ID' => 'ID del número de teléfono'
];
foreach ($other_constants as $const => $desc) {
if (defined($const)) {
$value = constant($const);
if (in_array($const, ['ADMIN_PASSWORD', 'SECRET_KEY', 'WHATSAPP_TOKEN'])) {
$display_value = str_repeat('*', min(strlen($value), 20));
} else {
$display_value = $value;
}
echo "<div class='ok'>✅ $const = '$display_value' ($desc)</div>";
} else {
echo "<div class='warning'>⚠️ $const no definida ($desc)</div>";
}
}
echo "</div>";
// 7. Resumen final
echo "<div class='section'>";
echo "<h2>📊 RESUMEN</h2>";
if ($all_defined) {
echo "<div class='ok'>✅ Configuración básica completa</div>";
echo "<div class='ok'>✅ Archivo config.php funcional</div>";
echo "<div class='ok'>✅ Sistema puede intentar funcionar</div>";
echo "<br><div class='warning'><strong>SIGUIENTE PASO:</strong></div>";
echo "<div class='warning'>• Probar: <a href='login.php' style='color:#ffaa00'>login.php</a></div>";
echo "<div class='warning'>• Si funciona login, probar: <a href='index.php' style='color:#ffaa00'>index.php</a></div>";
} else {
echo "<div class='error'>❌ Configuración incompleta</div>";
echo "<div class='error'>❌ Sistema NO puede funcionar</div>";
echo "<div class='warning'>Corrige las constantes faltantes en config/config.php</div>";
}
echo "</div>";
echo "</body></html>";
?>