Files
whatsapp/diagnostico_500.php
T
2026-01-21 08:28:54 -05:00

272 lines
11 KiB
PHP

<?php
/**
* 🚨 DIAGNÓSTICO RÁPIDO - ERROR 500
* Script para identificar la causa del error Internal Server Error
*/
// Deshabilitar reporting de errores por si está causando problemas
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "<!DOCTYPE html><html><head><meta charset='UTF-8'>";
echo "<title>🚨 Diagnóstico Error 500</title>";
echo "<style>body{font-family:monospace;margin:20px;background:#1a1a1a;color:#00ff00}";
echo ".ok{color:#00ff00}.error{color:#ff0040}.warning{color:#ffaa00}";
echo ".section{background:#222;padding:15px;margin:10px 0;border-radius:5px}";
echo "h2{color:#00ccff;border-bottom:2px solid #333}";
echo "</style></head><body>";
echo "<h1>🚨 DIAGNÓSTICO ERROR 500 - WhatsApp Bot</h1>";
echo "<p>Fecha: " . date('Y-m-d H:i:s') . "</p>";
// 1. TEST BÁSICO PHP
echo "<div class='section'><h2>📍 1. TEST BÁSICO PHP</h2>";
echo "<div class='ok'>✅ PHP está funcionando (versión: " . phpversion() . ")</div>";
if (version_compare(phpversion(), '7.4', '>=')) {
echo "<div class='ok'>✅ Versión PHP compatible</div>";
} else {
echo "<div class='error'>❌ Versión PHP muy antigua (requiere 7.4+)</div>";
}
echo "</div>";
// 2. TEST ARCHIVOS CRÍTICOS
echo "<div class='section'><h2>📂 2. ARCHIVOS CRÍTICOS</h2>";
$critical_files = [
'config/config.php' => 'Configuración principal',
'classes/Database.php' => 'Clase Database',
'index.php' => 'Dashboard principal',
'login.php' => 'Sistema de login',
'.htaccess' => 'Configuración Apache'
];
foreach ($critical_files as $file => $desc) {
if (file_exists($file)) {
echo "<div class='ok'>✅ $file ($desc)</div>";
// Test de carga PHP (sin shell_exec)
if (str_ends_with($file, '.php')) {
try {
// Intentar incluir el archivo para verificar errores
if ($file === 'config/config.php') {
// Test especial para config.php
ob_start();
$error_before = error_get_last();
include_once $file;
$output = ob_get_clean();
$error_after = error_get_last();
if ($error_after && $error_after !== $error_before) {
echo "<div class='error'> → ❌ Error en archivo: " . htmlspecialchars($error_after['message']) . "</div>";
} elseif (!empty($output)) {
echo "<div class='warning'> → ⚠️ Archivo produce output: " . htmlspecialchars(substr($output, 0, 100)) . "</div>";
} else {
echo "<div class='ok'> → ✅ Archivo se carga correctamente</div>";
}
} else {
echo "<div class='ok'> → ✅ Archivo PHP existe</div>";
}
} catch (ParseError $e) {
echo "<div class='error'> → ❌ ERROR SINTAXIS: " . htmlspecialchars($e->getMessage()) . "</div>";
} catch (Error $e) {
echo "<div class='error'> → ❌ ERROR: " . htmlspecialchars($e->getMessage()) . "</div>";
} catch (Exception $e) {
echo "<div class='warning'> → ⚠️ ADVERTENCIA: " . htmlspecialchars($e->getMessage()) . "</div>";
}
}
} else {
echo "<div class='error'>❌ FALTA: $file ($desc)</div>";
}
}
echo "</div>";
// 3. TEST PERMISOS
echo "<div class='section'><h2>🔐 3. PERMISOS</h2>";
$dirs_permissions = [
'logs/' => ['required' => '777', 'writable' => true],
'uploads/' => ['required' => '777', 'writable' => true],
'config/' => ['required' => '755', 'writable' => false],
'.' => ['required' => '755', 'writable' => false]
];
foreach ($dirs_permissions as $dir => $config) {
if (is_dir($dir)) {
$perms = substr(sprintf('%o', fileperms($dir)), -3);
echo "<div class='ok'>✅ $dir existe (permisos: $perms)</div>";
if ($config['writable'] && !is_writable($dir)) {
echo "<div class='error'> → ❌ No es escribible (necesita chmod 777)</div>";
}
} else {
echo "<div class='error'>❌ Directorio $dir no existe</div>";
}
}
echo "</div>";
// 4. TEST CONFIGURACIÓN
echo "<div class='section'><h2>⚙️ 4. CONFIGURACIÓN</h2>";
if (file_exists('config/config.php')) {
try {
ob_start();
include_once 'config/config.php';
$config_output = ob_get_clean();
if (!empty($config_output)) {
echo "<div class='error'>❌ config.php produce output: " . htmlspecialchars($config_output) . "</div>";
} else {
echo "<div class='ok'>✅ config.php se carga sin errores</div>";
}
// Verificar constantes básicas
$constants = ['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS'];
foreach ($constants as $const) {
if (defined($const)) {
$value = constant($const);
$display_value = ($const === 'DB_PASS') ? '***' : $value;
echo "<div class='ok'>✅ $const = '$display_value'</div>";
} else {
echo "<div class='error'>❌ Constante $const no definida</div>";
}
}
} catch (Exception $e) {
echo "<div class='error'>❌ Error cargando config.php: " . htmlspecialchars($e->getMessage()) . "</div>";
} catch (Error $e) {
echo "<div class='error'>❌ Error fatal en config.php: " . htmlspecialchars($e->getMessage()) . "</div>";
}
} else {
echo "<div class='error'>❌ config/config.php no encontrado</div>";
}
echo "</div>";
// 5. TEST BASE DE DATOS
echo "<div class='section'><h2>🗄️ 5. BASE DE DATOS</h2>";
if (defined('DB_HOST') && defined('DB_NAME')) {
try {
$dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4";
$pdo = new PDO($dsn, DB_USER, DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
]);
echo "<div class='ok'>✅ Conexión a base de datos exitosa</div>";
// Verificar tablas principales
$tables = ['conversations', 'conversations', 'system_config'];
foreach ($tables as $table) {
$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 (PDOException $e) {
echo "<div class='error'>❌ Error BD: " . htmlspecialchars($e->getMessage()) . "</div>";
}
} else {
echo "<div class='error'>❌ Configuración de BD incompleta</div>";
}
echo "</div>";
// 6. TEST .HTACCESS
echo "<div class='section'><h2>🛡️ 6. .HTACCESS</h2>";
if (file_exists('.htaccess')) {
$htaccess_size = filesize('.htaccess');
echo "<div class='ok'>✅ .htaccess existe ($htaccess_size bytes)</div>";
// Verificar sintaxis básica
$htaccess_content = file_get_contents('.htaccess');
$problematic_lines = [];
// Buscar sintaxis antigua que puede causar problemas
if (strpos($htaccess_content, 'Order Allow,Deny') !== false) {
$problematic_lines[] = "Sintaxis antigua 'Order Allow,Deny' (usar 'Require all denied')";
}
if (strpos($htaccess_content, 'Allow from') !== false) {
$problematic_lines[] = "Sintaxis antigua 'Allow from' (usar 'Require ip')";
}
if (empty($problematic_lines)) {
echo "<div class='ok'>✅ Sintaxis .htaccess parece correcta</div>";
} else {
foreach ($problematic_lines as $issue) {
echo "<div class='error'>❌ $issue</div>";
}
}
} else {
echo "<div class='error'>❌ .htaccess no encontrado</div>";
}
echo "</div>";
// 7. TEST MÓDULOS APACHE
echo "<div class='section'><h2>🔧 7. EXTENSIONES PHP</h2>";
$required_extensions = ['pdo', 'pdo_mysql', 'curl', 'json', 'mbstring', 'openssl'];
foreach ($required_extensions as $ext) {
if (extension_loaded($ext)) {
echo "<div class='ok'>✅ Extensión '$ext' habilitada</div>";
} else {
echo "<div class='error'>❌ Extensión '$ext' NO habilitada</div>";
}
}
// Verificar funciones deshabilitadas
$dangerous_functions = ['shell_exec', 'exec', 'system', 'passthru'];
$disabled_functions = explode(',', ini_get('disable_functions'));
$disabled_functions = array_map('trim', $disabled_functions);
echo "<div class='ok'><strong>Funciones del sistema:</strong></div>";
foreach ($dangerous_functions as $func) {
if (in_array($func, $disabled_functions)) {
echo "<div class='warning'>⚠️ $func() deshabilitada (normal en hosting)</div>";
} else {
echo "<div class='ok'>✅ $func() habilitada</div>";
}
}
echo "</div>";
// 8. INFORMACIÓN DEL SERVIDOR
echo "<div class='section'><h2>🖥️ 8. INFO SERVIDOR</h2>";
echo "<div class='ok'>Servidor: " . ($_SERVER['SERVER_SOFTWARE'] ?? 'Desconocido') . "</div>";
echo "<div class='ok'>PHP: " . PHP_VERSION . "</div>";
echo "<div class='ok'>SAPI: " . php_sapi_name() . "</div>";
echo "<div class='ok'>Directorio: " . __DIR__ . "</div>";
echo "<div class='ok'>Usuario: " . get_current_user() . "</div>";
// Límites PHP importantes
$limits = [
'memory_limit' => ini_get('memory_limit'),
'max_execution_time' => ini_get('max_execution_time'),
'upload_max_filesize' => ini_get('upload_max_filesize'),
'post_max_size' => ini_get('post_max_size')
];
foreach ($limits as $setting => $value) {
echo "<div class='ok'>$setting: $value</div>";
}
echo "</div>";
// 9. SUGERENCIAS DE SOLUCIÓN
echo "<div class='section'><h2>🔧 9. ACCIONES RECOMENDADAS</h2>";
echo "<div class='warning'><strong>Si hay errores arriba, prueba estas soluciones:</strong></div>";
echo "<div class='warning'>1. <strong>Error sintaxis PHP:</strong> Corregir archivo mostrado</div>";
echo "<div class='warning'>2. <strong>Permisos:</strong> chmod 777 logs/ uploads/</div>";
echo "<div class='warning'>3. <strong>Base datos:</strong> Verificar credenciales en config.php</div>";
echo "<div class='warning'>4. <strong>.htaccess:</strong> Renombrar temporalmente a .htaccess.bak</div>";
echo "<div class='warning'>5. <strong>PHP version:</strong> Cambiar a PHP 8.1+ en panel</div>";
echo "<br><div class='ok'><strong>TESTS RÁPIDOS:</strong></div>";
echo "<div class='ok'>• Renombra .htaccess → .htaccess.bak y prueba</div>";
echo "<div class='ok'>• Ve a login.php directamente</div>";
echo "<div class='ok'>• Revisa error log del servidor</div>";
echo "</div>";
echo "<div class='section'><h2>📱 10. CONTACTO</h2>";
echo "<div class='ok'>Si necesitas ayuda, envía screenshot de este diagnóstico</div>";
echo "</div>";
echo "</body></html>";
?>