up
This commit is contained in:
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
/**
|
||||
* 🔧 DIAGNÓSTICO API - WhatsApp Bot
|
||||
* Prueba específica de los archivos de la API
|
||||
*/
|
||||
|
||||
// Headers para mostrar errores
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
echo "<!DOCTYPE html><html><head><meta charset='UTF-8'>";
|
||||
echo "<title>🔧 Diagnóstico API</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 "pre{background:#222;padding:10px;color:#ccc;overflow:auto;max-height:200px}";
|
||||
echo "</style></head><body>";
|
||||
|
||||
echo "<h1>🔧 DIAGNÓSTICO DE LA API</h1>";
|
||||
echo "<div class='warning'>Ejecutándose desde: " . __DIR__ . "</div>";
|
||||
|
||||
// 1. Verificar estructura de carpetas
|
||||
echo "<div class='section'>";
|
||||
echo "<h2>📁 ESTRUCTURA DE ARCHIVOS...</h2>";
|
||||
|
||||
// Verificar que existe la carpeta api
|
||||
if (!is_dir('api')) {
|
||||
echo "<div class='error'>❌ CRÍTICO: Carpeta 'api' no encontrada</div>";
|
||||
exit;
|
||||
}
|
||||
echo "<div class='ok'>✅ Carpeta 'api' encontrada</div>";
|
||||
|
||||
// Verificar config desde diferentes ubicaciones
|
||||
$config_paths = [
|
||||
'config/config.php' => 'Ruta desde raíz',
|
||||
'api/../config/config.php' => 'Ruta desde API (relativa)',
|
||||
'../config/config.php' => 'Ruta desde API (parent)'
|
||||
];
|
||||
|
||||
foreach ($config_paths as $path => $desc) {
|
||||
if (file_exists($path)) {
|
||||
echo "<div class='ok'>✅ $desc: $path existe</div>";
|
||||
} else {
|
||||
echo "<div class='error'>❌ $desc: $path NO existe</div>";
|
||||
}
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
|
||||
// 2. Listar archivos de la API
|
||||
echo "<div class='section'>";
|
||||
echo "<h2>📋 ARCHIVOS DE LA API...</h2>";
|
||||
|
||||
$api_files = glob('api/*.php');
|
||||
if (empty($api_files)) {
|
||||
echo "<div class='error'>❌ No se encontraron archivos PHP en la API</div>";
|
||||
exit;
|
||||
}
|
||||
|
||||
echo "<div class='ok'>✅ Encontrados " . count($api_files) . " archivos en la API:</div>";
|
||||
foreach ($api_files as $file) {
|
||||
$filename = basename($file);
|
||||
$size = filesize($file);
|
||||
$readable = is_readable($file) ? '✅' : '❌';
|
||||
echo "<div class='warning'>$readable $filename ($size bytes)</div>";
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
|
||||
// 3. Analizar el primer archivo de API
|
||||
echo "<div class='section'>";
|
||||
echo "<h2>🔍 ANÁLISIS DEL PRIMER ARCHIVO...</h2>";
|
||||
|
||||
$test_file = $api_files[0];
|
||||
$filename = basename($test_file);
|
||||
|
||||
echo "<div class='warning'>Analizando: $filename</div>";
|
||||
|
||||
$content = file_get_contents($test_file);
|
||||
if (!$content) {
|
||||
echo "<div class='error'>❌ No se pudo leer el archivo</div>";
|
||||
} else {
|
||||
// Buscar require_once
|
||||
if (preg_match('/require_once\s+[\'"]([^\'"]+)[\'"]/', $content, $matches)) {
|
||||
$required_path = $matches[1];
|
||||
echo "<div class='warning'>🔗 Requiere: $required_path</div>";
|
||||
|
||||
// Verificar si la ruta existe desde la perspectiva del archivo API
|
||||
$full_path_from_api = 'api/' . $required_path;
|
||||
$parent_path_from_api = dirname('api/' . basename($test_file)) . '/' . $required_path;
|
||||
|
||||
if (file_exists($required_path)) {
|
||||
echo "<div class='ok'>✅ Ruta directa '$required_path' existe</div>";
|
||||
} elseif (file_exists($full_path_from_api)) {
|
||||
echo "<div class='warning'>⚠️ Ruta '$required_path' existe como '$full_path_from_api'</div>";
|
||||
} else {
|
||||
echo "<div class='error'>❌ Ruta '$required_path' NO existe</div>";
|
||||
echo "<div class='error'>❌ Tampoco existe como '$full_path_from_api'</div>";
|
||||
}
|
||||
|
||||
} else {
|
||||
echo "<div class='warning'>⚠️ No se encontró require_once en el archivo</div>";
|
||||
}
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
|
||||
// 4. Test de carga de configuración DESDE la API
|
||||
echo "<div class='section'>";
|
||||
echo "<h2>⚙️ TEST CARGA CONFIG DESDE API...</h2>";
|
||||
|
||||
// Simular estar en la carpeta API
|
||||
$original_dir = getcwd();
|
||||
|
||||
try {
|
||||
// Cambiar al directorio API
|
||||
chdir('api');
|
||||
echo "<div class='warning'>📁 Cambiado a directorio: " . getcwd() . "</div>";
|
||||
|
||||
// Intentar cargar configuración con diferentes rutas
|
||||
$config_attempts = [
|
||||
'../config/config.php' => 'Ruta parent (.../config/config.php)',
|
||||
'config/config.php' => 'Ruta directa (config/config.php)',
|
||||
'../config.php' => 'Config en raíz (../config.php)'
|
||||
];
|
||||
|
||||
$config_loaded = false;
|
||||
|
||||
foreach ($config_attempts as $path => $desc) {
|
||||
echo "<div class='warning'>🔄 Probando: $desc</div>";
|
||||
|
||||
if (file_exists($path)) {
|
||||
echo "<div class='ok'>✅ Archivo existe: $path</div>";
|
||||
|
||||
try {
|
||||
// Capturar errores
|
||||
ob_start();
|
||||
$error_before = error_get_last();
|
||||
|
||||
include_once $path;
|
||||
|
||||
$output = ob_get_clean();
|
||||
$error_after = error_get_last();
|
||||
|
||||
if ($error_after && $error_after !== $error_before) {
|
||||
echo "<div class='error'>❌ Error cargando: " . htmlspecialchars($error_after['message']) . "</div>";
|
||||
} else {
|
||||
echo "<div class='ok'>✅ Config cargado desde: $path</div>";
|
||||
$config_loaded = true;
|
||||
|
||||
// Verificar algunas constantes
|
||||
$test_constants = ['DB_HOST', 'DB_NAME', 'DB_USER'];
|
||||
foreach ($test_constants as $const) {
|
||||
if (defined($const)) {
|
||||
echo "<div class='ok'>✅ $const definido</div>";
|
||||
} else {
|
||||
echo "<div class='error'>❌ $const no definido</div>";
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "<div class='error'>❌ Excepción: " . htmlspecialchars($e->getMessage()) . "</div>";
|
||||
}
|
||||
} else {
|
||||
echo "<div class='error'>❌ Archivo no existe: $path</div>";
|
||||
}
|
||||
}
|
||||
|
||||
if (!$config_loaded) {
|
||||
echo "<div class='error'>❌ CRÍTICO: No se pudo cargar ninguna configuración</div>";
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "<div class='error'>❌ Error general: " . htmlspecialchars($e->getMessage()) . "</div>";
|
||||
} finally {
|
||||
// Volver al directorio original
|
||||
chdir($original_dir);
|
||||
echo "<div class='warning'>📁 Vuelto a directorio: " . getcwd() . "</div>";
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
|
||||
// 5. Revisar el .htaccess
|
||||
echo "<div class='section'>";
|
||||
echo "<h2>🔧 VERIFICACIÓN .HTACCESS...</h2>";
|
||||
|
||||
if (file_exists('.htaccess')) {
|
||||
echo "<div class='ok'>✅ .htaccess existe en raíz</div>";
|
||||
$htaccess_content = file_get_contents('.htaccess');
|
||||
|
||||
// Verificar reglas que pueden afectar a la API
|
||||
if (strpos($htaccess_content, 'RewriteEngine On') !== false) {
|
||||
echo "<div class='ok'>✅ RewriteEngine habilitado</div>";
|
||||
}
|
||||
|
||||
if (strpos($htaccess_content, 'api/') !== false) {
|
||||
echo "<div class='warning'>⚠️ Hay reglas específicas para api/</div>";
|
||||
preg_match_all('/.*api.*/', $htaccess_content, $api_rules);
|
||||
foreach ($api_rules[0] as $rule) {
|
||||
echo "<div class='warning'>📋 " . htmlspecialchars(trim($rule)) . "</div>";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo "<div class='error'>❌ .htaccess no encontrado</div>";
|
||||
}
|
||||
|
||||
// Verificar .htaccess en API
|
||||
if (file_exists('api/.htaccess')) {
|
||||
echo "<div class='warning'>⚠️ .htaccess existe en api/</div>";
|
||||
} else {
|
||||
echo "<div class='ok'>✅ No hay .htaccess específico en api/</div>";
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
|
||||
// 6. Resumen y recomendaciones
|
||||
echo "<div class='section'>";
|
||||
echo "<h2>📊 DIAGNÓSTICO Y RECOMENDACIONES</h2>";
|
||||
|
||||
echo "<div class='warning'><strong>PROBLEMA IDENTIFICADO:</strong></div>";
|
||||
echo "<div class='error'>Los archivos de la API están buscando 'config/config.php' desde su propia carpeta</div>";
|
||||
echo "<div class='error'>Pero config.php está en '../config/config.php' desde la perspectiva de la API</div>";
|
||||
|
||||
echo "<br><div class='warning'><strong>SOLUCIONES:</strong></div>";
|
||||
echo "<div class='ok'>1. Cambiar todas las rutas en api/ de 'config/config.php' a '../config/config.php'</div>";
|
||||
echo "<div class='ok'>2. O crear un archivo api/config.php que incluya '../config/config.php'</div>";
|
||||
echo "<div class='ok'>3. Verificar permisos de archivos</div>";
|
||||
|
||||
echo "<br><div class='warning'><strong>ARCHIVO CORRECTOR AUTOMÁTICO:</strong></div>";
|
||||
echo "<div class='ok'>Necesitas ejecutar un script que corrija todas las rutas en los archivos API</div>";
|
||||
|
||||
echo "</div>";
|
||||
|
||||
echo "</body></html>";
|
||||
?>
|
||||
Reference in New Issue
Block a user