diff --git a/log_frontend.php b/log_frontend.php new file mode 100755 index 0000000..3ceee74 --- /dev/null +++ b/log_frontend.php @@ -0,0 +1,39 @@ + 'Missing required fields']); + exit; + } + + $type = $data['type']; // 'log', 'error', 'info' + $message = $data['message']; + $details = $data['details'] ?? null; + + $logDir = __DIR__ . '/logs'; + if (!is_dir($logDir)) { + mkdir($logDir, 0755, true); + } + + $logFile = $logDir . '/image_editor.log'; + + $timestamp = date('Y-m-d H:i:s'); + $user = $_SESSION['username'] ?? 'unknown'; + + $logEntry = "[$timestamp] [$type] [User: $user] $message"; + if ($details) { + $logEntry .= " | Details: " . json_encode($details); + } + $logEntry .= "\n"; + + file_put_contents($logFile, $logEntry, FILE_APPEND); + + echo json_encode(['success' => true]); + exit; +} +?> diff --git a/login.php b/login.php index cade26b..d030ffe 100755 --- a/login.php +++ b/login.php @@ -30,7 +30,7 @@ $error = $_GET['error'] ?? ''; Iniciar Sesión - Bot Discord - +
diff --git a/profile.php b/profile.php index 4bb7453..bc065ff 100755 --- a/profile.php +++ b/profile.php @@ -135,6 +135,425 @@ require_once __DIR__ . '/templates/header.php';
+ + + +
+

Panel de Administrador

+ +
+ +
+
+
+
Cambiar Imagen de Login
+
+
+

Actualiza la imagen de fondo de la pantalla de inicio de sesión (Máximo 5MB).

+ + +
+ +
+ Login Image +
+
+ + +
+
+ + + Formatos: JPG, PNG, GIF, WebP +
+ + + + + + + + +
+
+
+
+
+ + +
+
+
+
Cambiar Logo
+
+
+

Actualiza el logo que se muestra en la navegación (Máximo 5MB).

+ + +
+ +
+ Logo +
+
+ + +
+
+ + + Formatos: JPG, PNG, GIF, WebP +
+ + + + + + + + +
+
+
+
+
+
+ + + + + + + + + + + \ No newline at end of file diff --git a/upload_admin_images.php b/upload_admin_images.php new file mode 100755 index 0000000..24f1f87 --- /dev/null +++ b/upload_admin_images.php @@ -0,0 +1,107 @@ + 'Acceso denegado. Solo administradores pueden subir imágenes.']); + exit; +} + +// Configuración +$uploadDir = __DIR__ . '/'; +$maxFileSize = 5 * 1024 * 1024; // 5MB +$allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp']; +$allowedMimes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp']; + +$response = ['success' => false, 'message' => '']; + +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['image'])) { + $imageType = $_POST['type'] ?? ''; + $file = $_FILES['image']; + + // Validar tipo de imagen + if (!in_array($imageType, ['login', 'logo'])) { + $response['message'] = 'Tipo de imagen inválido.'; + echo json_encode($response); + exit; + } + + // Validar que el archivo exista + if (!isset($file['tmp_name']) || !is_uploaded_file($file['tmp_name'])) { + $response['message'] = 'No se recibió ningún archivo o hubo un error en la subida.'; + echo json_encode($response); + exit; + } + + // Validar tamaño + if ($file['size'] > $maxFileSize) { + $response['message'] = 'El archivo es demasiado grande. Máximo 5MB.'; + echo json_encode($response); + exit; + } + + // Validar extensión + $fileExtension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); + if (!in_array($fileExtension, $allowedExtensions)) { + $response['message'] = 'Formato de archivo no permitido. Usa: ' . implode(', ', $allowedExtensions); + echo json_encode($response); + exit; + } + + // Validar MIME type + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $fileMime = finfo_file($finfo, $file['tmp_name']); + finfo_close($finfo); + + if (!in_array($fileMime, $allowedMimes)) { + $response['message'] = 'El archivo no es una imagen válida.'; + echo json_encode($response); + exit; + } + + try { + // Determinar la ruta destino + if ($imageType === 'login') { + $filename = 'login.png'; + $destinationPath = $uploadDir . 'galeria/' . $filename; + $relativeUrl = '/galeria/' . $filename; + } else { // logo + $filename = 'logo.png'; + $destinationPath = $uploadDir . 'assets/images/' . $filename; + $relativeUrl = '/assets/images/' . $filename; + } + + // Crear directorio si no existe + $destDir = dirname($destinationPath); + if (!is_dir($destDir)) { + mkdir($destDir, 0755, true); + } + + // Mover el archivo + if (move_uploaded_file($file['tmp_name'], $destinationPath)) { + // Registrar actividad + $actionDesc = $imageType === 'login' ? 'Updated login background image' : 'Updated logo image'; + log_activity($_SESSION['user_id'], 'Image Upload', 'Admin ' . $_SESSION['username'] . ' ' . $actionDesc); + + // Log del archivo guardado + error_log('Image uploaded successfully: ' . $destinationPath . ' (Size: ' . filesize($destinationPath) . ' bytes)'); + + $response['success'] = true; + $response['message'] = ucfirst($imageType) . ' actualizado correctamente.'; + $response['url'] = $relativeUrl . '?t=' . time(); // Cache buster + } else { + $response['message'] = 'Error al mover el archivo. Verifica los permisos de la carpeta.'; + error_log('Failed to move uploaded file to: ' . $destinationPath); + } + } catch (Exception $e) { + error_log('Error uploading admin image: ' . $e->getMessage()); + $response['message'] = 'Error al procesar la imagen.'; + } +} + +header('Content-Type: application/json'); +echo json_encode($response); +exit; +?>