Files
whatsapp/login.php
T
2026-01-28 03:09:52 -05:00

326 lines
11 KiB
PHP

<?php
/**
* Sistema de Login del WhatsApp Bot Manager
* Desarrollado por U-Site.app
* Con protección contra ataques de fuerza bruta
*/
require_once 'config/config.php';
// Con Docker, la instalación siempre está completada
// El archivo .installation_completed se crea automáticamente o no es necesario
// Si ya está logueado, redirigir al panel
if (isUserLoggedIn()) {
header('Location: index.php');
exit;
}
$error = '';
$success = '';
$loginBlocked = false;
$clientIp = $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0';
// Verificar si viene de logout
if (isset($_GET['logged_out']) && $_GET['logged_out'] == '1') {
$success = 'Sesión cerrada correctamente.';
}
// Verificar si la sesión expiró
if (isset($_GET['session_expired']) && $_GET['session_expired'] == '1') {
$error = 'Su sesión ha expirado por inactividad. Por favor, inicie sesión nuevamente.';
}
// Verificar si la IP está bloqueada
if (!checkLoginAttempts($clientIp)) {
$loginBlocked = true;
$error = 'Demasiados intentos de login. Inténtalo en ' . (LOGIN_LOCKOUT_TIME / 60) . ' minutos.';
}
// Procesar login
if ($_POST && !$loginBlocked) {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
// Usar el nuevo sistema de autenticación unificado
$adminUser = authenticateUser($username, $password);
if ($adminUser) {
// Login exitoso
clearLoginAttempts($clientIp);
$_SESSION['admin_logged_in'] = true;
$_SESSION['admin_user'] = $adminUser;
$_SESSION['last_activity'] = time();
$_SESSION['login_ip'] = $clientIp;
$_SESSION['login_time'] = time();
header('Location: index.php');
exit;
} else {
// Login fallido
recordFailedLogin($clientIp);
$error = 'Usuario o contraseña incorrectos.';
// Verificar si se bloqueó después de este intento
if (!checkLoginAttempts($clientIp)) {
$loginBlocked = true;
$error = 'Demasiados intentos de login. Cuenta bloqueada por ' . (LOGIN_LOCKOUT_TIME / 60) . ' minutos.';
}
}
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🔐 Login - WhatsApp Bot Manager</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<style>
:root {
--primary-color: #25d366;
--secondary-color: #075e54;
--bg-gradient: linear-gradient(135deg, #25d366 0%, #075e54 100%);
}
body {
background: var(--bg-gradient);
min-height: 100vh;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 0.75rem;
padding: 2rem 1rem;
}
.login-card {
background: rgba(255,255,255,0.95);
border-radius: 20px;
backdrop-filter: blur(10px);
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
border: 1px solid rgba(255, 255, 255, 0.3);
width: 100%;
max-width: 400px;
}
.btn-login {
background: var(--bg-gradient);
border: none;
color: white;
padding: 12px;
border-radius: 10px;
font-weight: 600;
width: 100%;
}
.btn-login:hover {
transform: translateY(-2px);
color: white;
box-shadow: 0 8px 25px rgba(37, 211, 102, 0.3);
}
.btn-login:disabled {
background: #6c757d;
transform: none;
box-shadow: none;
}
.form-control {
padding: 12px;
border-radius: 10px;
border: 2px solid #e9ecef;
}
.form-control:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 0.2rem rgba(37, 211, 102, 0.25);
}
.logo-icon {
font-size: 4rem;
background: var(--bg-gradient);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.developer-info {
background: linear-gradient(45deg, #667eea 0%, #764ba2 100%);
color: white;
border-radius: 15px;
padding: 1rem;
margin-top: 2rem;
text-align: center;
}
.security-badge {
background: #28a745;
color: white;
padding: 5px 10px;
border-radius: 15px;
font-size: 0.8rem;
margin: 2px;
display: inline-block;
}
.attempts-warning {
background: linear-gradient(45deg, #ff6b6b, #ee5a24);
color: white;
border-radius: 10px;
padding: 15px;
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
/* Pie de desarrollador discreto */
.developer-footer {
font-size: 0.85rem;
color: rgba(31,41,55,0.65);
text-align: center;
width: 100%;
max-width: 420px;
}
</style>
</head>
<body>
<div class="login-card p-5">
<!-- Header -->
<div class="text-center mb-4">
<i class="fab fa-whatsapp logo-icon"></i>
<h2 class="mt-3 fw-bold">WhatsApp Bot Manager</h2>
<p class="text-muted mb-0">Panel de Administración</p>
</div>
<!-- Características de Seguridad -->
<div class="mb-4 text-center">
<span class="security-badge"><i class="fas fa-shield-alt me-1"></i>Protección Brute Force</span>
<span class="security-badge"><i class="fas fa-lock me-1"></i>Sesiones Seguras</span>
<span class="security-badge"><i class="fas fa-user-shield me-1"></i>Control de Acceso</span>
</div>
<!-- Error de bloqueo -->
<?php if ($loginBlocked): ?>
<div class="attempts-warning mb-4">
<div class="text-center">
<i class="fas fa-ban fa-2x mb-2"></i>
<h5>Acceso Bloqueado</h5>
<p class="mb-0"><?= htmlspecialchars($error) ?></p>
</div>
</div>
<?php endif; ?>
<!-- Formulario de Login -->
<form method="POST" id="loginForm">
<!-- Campo Usuario -->
<div class="mb-3">
<label for="username" class="form-label">
<i class="fas fa-user me-2"></i>Usuario
</label>
<input
type="text"
class="form-control"
id="username"
name="username"
required
<?= $loginBlocked ? 'disabled' : '' ?>
placeholder="Ingresa tu usuario"
value="<?= htmlspecialchars($_POST['username'] ?? '') ?>"
>
</div>
<!-- Campo Contraseña -->
<div class="mb-3">
<label for="password" class="form-label">
<i class="fas fa-lock me-2"></i>Contraseña
</label>
<div class="input-group">
<input
type="password"
class="form-control"
id="password"
name="password"
required
<?= $loginBlocked ? 'disabled' : '' ?>
placeholder="Ingresa tu contraseña"
>
<button
class="btn btn-outline-secondary"
type="button"
id="togglePassword"
<?= $loginBlocked ? 'disabled' : '' ?>
>
<i class="fas fa-eye"></i>
</button>
</div>
</div>
<!-- Success conversations -->
<?php if ($success): ?>
<div class="alert alert-success">
<i class="fas fa-check-circle me-2"></i>
<?= htmlspecialchars($success) ?>
</div>
<?php endif; ?>
<!-- Error conversations -->
<?php if ($error && !$loginBlocked): ?>
<div class="alert alert-danger">
<i class="fas fa-exclamation-triangle me-2"></i>
<?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<!-- Submit Button -->
<button
type="submit"
class="btn-login"
<?= $loginBlocked ? 'disabled' : '' ?>
>
<?php if ($loginBlocked): ?>
<i class="fas fa-ban me-2"></i>Acceso Bloqueado
<?php else: ?>
<i class="fas fa-sign-in-alt me-2"></i>Iniciar Sesión
<?php endif; ?>
</button>
</form>
</div>
<!-- Pequeño pie discreto del desarrollador -->
<div class="developer-footer mt-3">
<small style="color: rgba(246, 247, 248, 0.65); text-align: center;">Desarrollado con ❤️ por <a href="https://u-site.app" target="_blank" rel="noopener noreferrer" style="text-decoration: underline; color:white;">usite</a></small>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Toggle password visibility
document.getElementById('togglePassword').addEventListener('click', function() {
const password = document.getElementById('password');
const icon = this.querySelector('i');
if (password.type === 'password') {
password.type = 'text';
icon.classList.remove('fa-eye');
icon.classList.add('fa-eye-slash');
} else {
password.type = 'password';
icon.classList.remove('fa-eye-slash');
icon.classList.add('fa-eye');
}
});
// Auto-focus en password field
<?php if (!$loginBlocked): ?>
document.getElementById('password').focus();
<?php endif; ?>
// Disable form on blocked
<?php if ($loginBlocked): ?>
document.getElementById('loginForm').addEventListener('submit', function(e) {
e.preventDefault();
return false;
});
<?php endif; ?>
</script>
<!-- Footer U-Site -->
<footer style="position: fixed; bottom: 0; left: 0; right: 0; background: transparent; padding: 15px; text-align: center; font-size: 12px; color: rgba(255,255,255,0.6);">
Desarrollado con 💚 por <a href="https://u-site.app" target="_blank" style="color: #25d366; text-decoration: none; font-weight: 600;">U-Site.app</a>
</footer>
</body>
</html>