up
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
// Función para cargar archivo .env
|
||||
if (!function_exists('loadEnvFile')) {
|
||||
function loadEnvFile($path) {
|
||||
if (!file_exists($path)) {
|
||||
return false;
|
||||
@@ -30,14 +31,17 @@ function loadEnvFile($path) {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Cargar .env si existe
|
||||
$envLoaded = loadEnvFile(__DIR__ . '/../.env');
|
||||
$envLoaded = function_exists('loadEnvFile') ? loadEnvFile(__DIR__ . '/../.env') : false;
|
||||
|
||||
// Función helper para obtener variables de entorno con fallback
|
||||
if (!function_exists('env')) {
|
||||
function env($key, $default = null) {
|
||||
return $_ENV[$key] ?? getenv($key) ?: $default;
|
||||
}
|
||||
}
|
||||
|
||||
// Configuración de la base de datos
|
||||
define('DB_HOST', env('DB_HOST', 'localhost'));
|
||||
@@ -122,6 +126,7 @@ if (!defined('AUTO_DETECTED_URL')) {
|
||||
}
|
||||
|
||||
// Función para logging centralizado
|
||||
if (!function_exists('writeLog')) {
|
||||
function writeLog($level, $message, $context = []) {
|
||||
if (!ENABLE_LOGGING) return;
|
||||
|
||||
@@ -143,18 +148,24 @@ function writeLog($level, $message, $context = []) {
|
||||
|
||||
file_put_contents($logDir . '/system.log', $logMessage, FILE_APPEND | LOCK_EX);
|
||||
}
|
||||
}
|
||||
|
||||
// Función para verificar si la instalación está completada
|
||||
if (!function_exists('isInstallationCompleted')) {
|
||||
function isInstallationCompleted() {
|
||||
return file_exists(dirname(__DIR__) . '/.installation_completed');
|
||||
}
|
||||
}
|
||||
|
||||
// Función para verificar login
|
||||
if (!function_exists('isUserLoggedIn')) {
|
||||
function isUserLoggedIn() {
|
||||
return isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true;
|
||||
}
|
||||
}
|
||||
|
||||
// Función para verificar intentos de login
|
||||
if (!function_exists('checkLoginAttempts')) {
|
||||
function checkLoginAttempts($ip) {
|
||||
$attemptsFile = dirname(__DIR__) . '/.login_attempts.json';
|
||||
|
||||
@@ -178,8 +189,10 @@ function checkLoginAttempts($ip) {
|
||||
|
||||
return $ipData['attempts'] < MAX_LOGIN_ATTEMPTS;
|
||||
}
|
||||
}
|
||||
|
||||
// Función para registrar intento de login fallido
|
||||
if (!function_exists('recordFailedLogin')) {
|
||||
function recordFailedLogin($ip) {
|
||||
$attemptsFile = dirname(__DIR__) . '/.login_attempts.json';
|
||||
|
||||
@@ -201,8 +214,10 @@ function recordFailedLogin($ip) {
|
||||
file_put_contents($attemptsFile, json_encode($attempts));
|
||||
writeLog('WARNING', 'Failed login attempt', ['ip' => $ip, 'attempts' => $attempts[$ip]['attempts']]);
|
||||
}
|
||||
}
|
||||
|
||||
// Función para limpiar intentos de login exitoso
|
||||
if (!function_exists('clearLoginAttempts')) {
|
||||
function clearLoginAttempts($ip) {
|
||||
$attemptsFile = dirname(__DIR__) . '/.login_attempts.json';
|
||||
|
||||
@@ -214,6 +229,7 @@ function clearLoginAttempts($ip) {
|
||||
|
||||
writeLog('INFO', 'Successful login', ['ip' => $ip]);
|
||||
}
|
||||
}
|
||||
|
||||
// Autoloader mejorado
|
||||
spl_autoload_register(function ($class) {
|
||||
@@ -236,6 +252,7 @@ spl_autoload_register(function ($class) {
|
||||
});
|
||||
|
||||
// Función para obtener configuración desde base de datos
|
||||
if (!function_exists('getConfigFromDB')) {
|
||||
function getConfigFromDB($key, $default = null) {
|
||||
static $configs = null;
|
||||
|
||||
@@ -267,8 +284,10 @@ function getConfigFromDB($key, $default = null) {
|
||||
|
||||
return $configs[$key] ?? $default;
|
||||
}
|
||||
}
|
||||
|
||||
// Función para validar configuración de WhatsApp
|
||||
if (!function_exists('validateWhatsAppConfig')) {
|
||||
function validateWhatsAppConfig() {
|
||||
$errors = [];
|
||||
|
||||
@@ -286,14 +305,17 @@ function validateWhatsAppConfig() {
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
// Función para crear directorio si no existe
|
||||
if (!function_exists('ensureDirectoryExists')) {
|
||||
function ensureDirectoryExists($path) {
|
||||
if (!is_dir($path)) {
|
||||
mkdir($path, 0755, true);
|
||||
writeLog('INFO', 'Directory created', ['path' => $path]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Crear directorios necesarios
|
||||
ensureDirectoryExists(dirname(__DIR__) . '/logs');
|
||||
|
||||
Reference in New Issue
Block a user