272 lines
11 KiB
PHP
272 lines
11 KiB
PHP
<?php
|
|
/**
|
|
* Utilidad de Recuperación de Contraseña - WhatsApp Bot Manager
|
|
* Fecha: 4 de enero de 2026
|
|
*/
|
|
|
|
require_once 'config/config.php';
|
|
|
|
// Solo permitir acceso desde localhost o IP específicas para seguridad
|
|
$allowedIPs = ['127.0.0.1', '::1', 'localhost'];
|
|
$clientIP = $_SERVER['REMOTE_ADDR'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? 'unknown';
|
|
|
|
if (!in_array($clientIP, $allowedIPs) && $clientIP !== 'unknown') {
|
|
die("❌ Acceso denegado. Esta utilidad solo puede ejecutarse desde localhost por seguridad.");
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>🔑 Recuperar Contraseña - WhatsApp Bot Manager</title>
|
|
<style>
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
|
|
color: #333;
|
|
margin: 0;
|
|
padding: 20px;
|
|
min-height: 100vh;
|
|
}
|
|
.container {
|
|
max-width: 600px;
|
|
margin: 0 auto;
|
|
background: white;
|
|
padding: 40px;
|
|
border-radius: 15px;
|
|
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
|
|
}
|
|
h1 {
|
|
color: #25D366;
|
|
text-align: center;
|
|
margin-bottom: 30px;
|
|
}
|
|
.info-box {
|
|
background: #e8f5e8;
|
|
padding: 20px;
|
|
border-left: 5px solid #25D366;
|
|
margin: 20px 0;
|
|
border-radius: 5px;
|
|
}
|
|
.warning-box {
|
|
background: #fff3cd;
|
|
padding: 20px;
|
|
border-left: 5px solid #ffc107;
|
|
margin: 20px 0;
|
|
border-radius: 5px;
|
|
}
|
|
.error-box {
|
|
background: #f8d7da;
|
|
padding: 20px;
|
|
border-left: 5px solid #dc3545;
|
|
margin: 20px 0;
|
|
border-radius: 5px;
|
|
}
|
|
.form-group {
|
|
margin: 20px 0;
|
|
}
|
|
label {
|
|
display: block;
|
|
font-weight: bold;
|
|
margin-bottom: 8px;
|
|
color: #333;
|
|
}
|
|
input[type="password"], input[type="text"] {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 2px solid #ddd;
|
|
border-radius: 8px;
|
|
font-size: 16px;
|
|
box-sizing: border-box;
|
|
}
|
|
input[type="password"]:focus, input[type="text"]:focus {
|
|
outline: none;
|
|
border-color: #25D366;
|
|
}
|
|
.btn {
|
|
background: #25D366;
|
|
color: white;
|
|
padding: 12px 30px;
|
|
border: none;
|
|
border-radius: 8px;
|
|
font-size: 16px;
|
|
cursor: pointer;
|
|
width: 100%;
|
|
margin: 10px 0;
|
|
}
|
|
.btn:hover {
|
|
background: #1aa347;
|
|
}
|
|
.btn-danger {
|
|
background: #dc3545;
|
|
}
|
|
.btn-danger:hover {
|
|
background: #c82333;
|
|
}
|
|
.current-info {
|
|
background: #f8f9fa;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
margin: 20px 0;
|
|
}
|
|
code {
|
|
background: #f8f9fa;
|
|
padding: 2px 6px;
|
|
border-radius: 3px;
|
|
font-family: monospace;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>🔑 Recuperar Contraseña de Administrador</h1>
|
|
|
|
<div class="warning-box">
|
|
<strong>⚠️ Advertencia de Seguridad:</strong>
|
|
<p>Esta utilidad solo debe usarse desde el servidor local y debe eliminarse después del uso. Nunca la dejes accesible públicamente.</p>
|
|
</div>
|
|
|
|
<div class="current-info">
|
|
<h3>📋 Información Actual del Sistema:</h3>
|
|
<p><strong>Usuario administrador:</strong> <code><?php echo ADMIN_USERNAME; ?></code></p>
|
|
<p><strong>Hash actual:</strong> <code><?php echo substr(ADMIN_PASSWORD, 0, 30); ?>...</code></p>
|
|
<p><strong>IP de acceso:</strong> <code><?php echo $clientIP; ?></code></p>
|
|
</div>
|
|
|
|
<?php
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (isset($_POST['action'])) {
|
|
|
|
if ($_POST['action'] === 'reset_password') {
|
|
$newPassword = $_POST['new_password'] ?? '';
|
|
$confirmPassword = $_POST['confirm_password'] ?? '';
|
|
|
|
if (empty($newPassword) || empty($confirmPassword)) {
|
|
echo '<div class="error-box">❌ <strong>Error:</strong> Todos los campos son requeridos.</div>';
|
|
} elseif ($newPassword !== $confirmPassword) {
|
|
echo '<div class="error-box">❌ <strong>Error:</strong> Las contraseñas no coinciden.</div>';
|
|
} elseif (strlen($newPassword) < 6) {
|
|
echo '<div class="error-box">❌ <strong>Error:</strong> La contraseña debe tener al menos 6 caracteres.</div>';
|
|
} else {
|
|
// Generar nuevo hash
|
|
$newHash = password_hash($newPassword, PASSWORD_DEFAULT);
|
|
|
|
// Leer el archivo config.php
|
|
$configFile = 'config/config.php';
|
|
$configContent = file_get_contents($configFile);
|
|
|
|
// Reemplazar la línea del password
|
|
$oldLine = "define('ADMIN_PASSWORD', '" . ADMIN_PASSWORD . "');";
|
|
$newLine = "define('ADMIN_PASSWORD', '" . $newHash . "');";
|
|
|
|
$newConfigContent = str_replace($oldLine, $newLine, $configContent);
|
|
|
|
if ($newConfigContent !== $configContent && file_put_contents($configFile, $newConfigContent)) {
|
|
echo '<div class="info-box">✅ <strong>¡Éxito!</strong> La contraseña ha sido actualizada correctamente.</div>';
|
|
echo '<div class="info-box">🔄 <strong>Importante:</strong> Recarga la página para ver los cambios reflejados.</div>';
|
|
|
|
// Log del cambio
|
|
$logEntry = "[" . date('Y-m-d H:i:s') . "] Password reset from IP: " . $clientIP . PHP_EOL;
|
|
file_put_contents('logs/system.log', $logEntry, FILE_APPEND | LOCK_EX);
|
|
} else {
|
|
echo '<div class="error-box">❌ <strong>Error:</strong> No se pudo actualizar el archivo de configuración. Verifica permisos de escritura.</div>';
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($_POST['action'] === 'verify_password') {
|
|
$testPassword = $_POST['test_password'] ?? '';
|
|
|
|
if (password_verify($testPassword, ADMIN_PASSWORD)) {
|
|
echo '<div class="info-box">✅ <strong>Correcto:</strong> La contraseña ingresada es válida.</div>';
|
|
} else {
|
|
echo '<div class="error-box">❌ <strong>Incorrecto:</strong> La contraseña ingresada no es válida.</div>';
|
|
}
|
|
}
|
|
|
|
if ($_POST['action'] === 'clear_login_attempts') {
|
|
$attemptsFile = '.login_attempts.json';
|
|
if (file_exists($attemptsFile)) {
|
|
unlink($attemptsFile);
|
|
echo '<div class="info-box">✅ <strong>Éxito:</strong> Intentos de login bloqueados eliminados.</div>';
|
|
} else {
|
|
echo '<div class="warning-box">⚠️ <strong>Info:</strong> No hay intentos de login bloqueados.</div>';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!-- Formulario para verificar contraseña actual -->
|
|
<form method="post" style="margin-bottom: 30px;">
|
|
<h3>🔍 Verificar Contraseña Actual</h3>
|
|
<div class="form-group">
|
|
<label for="test_password">Contraseña a verificar:</label>
|
|
<input type="password" id="test_password" name="test_password" required>
|
|
</div>
|
|
<input type="hidden" name="action" value="verify_password">
|
|
<button type="submit" class="btn">🔍 Verificar Contraseña</button>
|
|
</form>
|
|
|
|
<hr>
|
|
|
|
<!-- Formulario para cambiar contraseña -->
|
|
<form method="post">
|
|
<h3>🔄 Establecer Nueva Contraseña</h3>
|
|
<div class="form-group">
|
|
<label for="new_password">Nueva contraseña:</label>
|
|
<input type="password" id="new_password" name="new_password" required minlength="6">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="confirm_password">Confirmar contraseña:</label>
|
|
<input type="password" id="confirm_password" name="confirm_password" required minlength="6">
|
|
</div>
|
|
<input type="hidden" name="action" value="reset_password">
|
|
<button type="submit" class="btn">🔄 Cambiar Contraseña</button>
|
|
</form>
|
|
|
|
<hr>
|
|
|
|
<!-- Opciones adicionales -->
|
|
<h3>🛠️ Herramientas Adicionales</h3>
|
|
|
|
<form method="post" style="margin-bottom: 20px;">
|
|
<input type="hidden" name="action" value="clear_login_attempts">
|
|
<button type="submit" class="btn btn-danger">🗑️ Limpiar Intentos de Login Bloqueados</button>
|
|
</form>
|
|
|
|
<div class="info-box">
|
|
<h4>📝 Información Útil:</h4>
|
|
<ul>
|
|
<li><strong>Usuario por defecto:</strong> <code>admin</code></li>
|
|
<li><strong>Archivo de configuración:</strong> <code>config/config.php</code></li>
|
|
<li><strong>Página de login:</strong> <a href="login.php">login.php</a></li>
|
|
<li><strong>Timeout de sesión:</strong> <?php echo SESSION_TIMEOUT/60; ?> minutos</li>
|
|
<li><strong>Intentos máximos:</strong> <?php echo MAX_LOGIN_ATTEMPTS; ?> intentos</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="warning-box">
|
|
<h4>🔒 Recomendaciones de Seguridad:</h4>
|
|
<ul>
|
|
<li>Usa una contraseña fuerte con al menos 8 caracteres</li>
|
|
<li>Incluye mayúsculas, minúsculas, números y símbolos</li>
|
|
<li>No uses la misma contraseña en otros sitios</li>
|
|
<li>Elimina este archivo después de usar: <code>rm recuperar_password.php</code></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="current-info" style="margin-top: 30px;">
|
|
<h4>🚀 Próximos Pasos:</h4>
|
|
<ol>
|
|
<li>Cambia la contraseña usando el formulario de arriba</li>
|
|
<li>Prueba el login en <a href="login.php" target="_blank">login.php</a></li>
|
|
<li>Elimina este archivo por seguridad</li>
|
|
<li>Accede al panel de administración</li>
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|