From 4067a323fbe7e2be0ec20b7753d50f5151fb88bd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 25 Jan 2026 20:17:21 +0000 Subject: [PATCH] Add Docker support and migrate data paths to /DATA/ Co-authored-by: naielv <109038805+naielv@users.noreply.github.com> --- .dockerignore | 8 + .env.example | 8 + .gitignore | 4 + DOCKER.md | 166 ++++++++++++++++++++ Dockerfile | 43 +++++ docker-compose.yml | 26 +++ public_html/_login.php | 2 +- public_html/entreaulas/_incl/auth_redir.php | 2 +- public_html/entreaulas/_login.php | 4 +- public_html/entreaulas/admin/aularios.php | 4 +- public_html/entreaulas/aulario.php | 2 +- public_html/entreaulas/index.php | 2 +- 12 files changed, 263 insertions(+), 8 deletions(-) create mode 100644 .dockerignore create mode 100644 .env.example create mode 100644 DOCKER.md create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..34f2cfa --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.git +.gitignore +README.md +Dockerfile +docker-compose.yml +.dockerignore +DATA +*.md diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..0fc6349 --- /dev/null +++ b/.env.example @@ -0,0 +1,8 @@ +# Example environment configuration for Axia4 +# Copy this file to .env and customize as needed + +# Port to expose the application on +WEB_PORT=8080 + +# Data directory (mounted as /DATA in container) +DATA_DIR=./DATA diff --git a/.gitignore b/.gitignore index 1ed8d0e..055e10e 100644 --- a/.gitignore +++ b/.gitignore @@ -471,3 +471,7 @@ composer.lock *.css.map *.sass.map *.scss.map + +##### Docker +.env +DATA/ diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 0000000..b41952d --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,166 @@ +# Axia4 Docker Setup + +This document explains how to run the Axia4 PHP application using Docker. + +## Prerequisites + +- Docker Engine 20.10+ +- Docker Compose V2 + +## Quick Start + +1. **Prepare the data directory** + ```bash + mkdir -p DATA/entreaulas/Usuarios + mkdir -p DATA/entreaulas/Centros + ``` + +2. **Build and start the application** + ```bash + docker-compose up -d + ``` + +3. **Access the application** + + Open your browser and navigate to: `http://localhost:8080` + +## Configuration + +### Data Directory Structure + +The application stores all data in the `/DATA` directory which is mounted from `./DATA` on the host: + +``` +DATA/ +├── Usuarios.json # Main user accounts +└── entreaulas/ + ├── Usuarios/ # EntreAulas user files + │ └── {username}.json + └── Centros/ # Centro data + └── {centro_id}/ + └── Aularios/ # Aulario configurations + └── {aulario_id}.json +``` + +### Creating Initial Users + +**Main Users** (`DATA/Usuarios.json`): +```json +{ + "username": { + "password_hash": "hashed_password_here" + } +} +``` + +**EntreAulas Users** (`DATA/entreaulas/Usuarios/{username}.json`): +```json +{ + "password_hash": "hashed_password_here", + "display_name": "Full Name", + "centro": "centro_id", + "aulas": ["aulario_id_1", "aulario_id_2"] +} +``` + +To generate a password hash, you can use PHP: +```bash +docker exec -it axia4-app php -r "echo password_hash('your_password', PASSWORD_DEFAULT);" +``` + +### Port Configuration + +By default, the application runs on port 8080. To change this, edit `docker-compose.yml`: + +```yaml +ports: + - "YOUR_PORT:80" +``` + +## Docker Commands + +### Start the application +```bash +docker-compose up -d +``` + +### Stop the application +```bash +docker-compose down +``` + +### View logs +```bash +docker-compose logs -f +``` + +### Rebuild after changes +```bash +docker-compose up -d --build +``` + +### Access the container shell +```bash +docker exec -it axia4-app bash +``` + +## Development Mode + +To enable live code updates without rebuilding, uncomment the volume mount in `docker-compose.yml`: + +```yaml +volumes: + - ./DATA:/DATA + - ./public_html:/var/www/html # Uncomment this line +``` + +## Troubleshooting + +### Permission Issues + +If you encounter permission errors with the DATA directory: + +```bash +sudo chown -R 33:33 DATA +sudo chmod -R 755 DATA +``` + +(User ID 33 is typically the www-data user in the container) + +### Check Application Logs + +```bash +docker-compose logs axia4-web +``` + +### Inspect Container + +```bash +docker exec -it axia4-app bash +# Then inside the container: +ls -la /DATA +cat /var/log/apache2/error.log +``` + +## Security Notes + +- Change default passwords immediately in production +- Ensure the DATA directory has appropriate permissions +- Consider using environment variables for sensitive configuration +- Use HTTPS in production (add a reverse proxy like Nginx or Traefik) + +## Backup + +To backup your data: + +```bash +tar -czf axia4-data-backup-$(date +%Y%m%d).tar.gz DATA/ +``` + +## Restore + +To restore from backup: + +```bash +tar -xzf axia4-data-backup-YYYYMMDD.tar.gz +``` diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..172c42b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +# Use official PHP image with Apache +FROM php:8.2-apache + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + libpng-dev \ + libjpeg-dev \ + libfreetype6-dev \ + zip \ + unzip \ + && rm -rf /var/lib/apt/lists/* + +# Configure PHP extensions +RUN docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-install -j$(nproc) gd + +# Enable Apache modules +RUN a2enmod rewrite + +# Set working directory +WORKDIR /var/www/html + +# Copy application files +COPY public_html/ /var/www/html/ + +# Create DATA directory with proper permissions +RUN mkdir -p /DATA && \ + chown -R www-data:www-data /DATA && \ + chmod -R 755 /DATA + +# Set permissions for web directory +RUN chown -R www-data:www-data /var/www/html && \ + chmod -R 755 /var/www/html + +# Configure PHP settings +RUN echo "session.cookie_lifetime = 604800" >> /usr/local/etc/php/conf.d/custom.ini && \ + echo "session.gc_maxlifetime = 604800" >> /usr/local/etc/php/conf.d/custom.ini + +# Expose port 80 +EXPOSE 80 + +# Start Apache +CMD ["apache2-foreground"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2afc08b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: '3.8' + +services: + axia4-web: + build: . + container_name: axia4-app + ports: + - "${WEB_PORT:-8080}:80" + volumes: + # Mount the DATA directory for persistent storage + - ${DATA_DIR:-./DATA}:/DATA + # Optional: Mount the application code for development + # - ./public_html:/var/www/html + environment: + - APACHE_DOCUMENT_ROOT=/var/www/html + restart: unless-stopped + networks: + - axia4-network + +networks: + axia4-network: + driver: bridge + +volumes: + data: + driver: local diff --git a/public_html/_login.php b/public_html/_login.php index 6feaab8..da5de5d 100755 --- a/public_html/_login.php +++ b/public_html/_login.php @@ -5,7 +5,7 @@ if (isset($_POST["user"])) { $valid = ""; $user = trim(strtolower($_POST["user"])); $password = $_POST["password"]; - $users = json_decode(file_get_contents("/mnt/dietpi_userdata/www_userdata/Usuarios.json"), true); + $users = json_decode(file_get_contents("/DATA/Usuarios.json"), true); if (!isset($users)) { $valid = "Fallo del sistema: No hay cuentas."; } diff --git a/public_html/entreaulas/_incl/auth_redir.php b/public_html/entreaulas/_incl/auth_redir.php index 26cea0b..5dfcb32 100755 --- a/public_html/entreaulas/_incl/auth_redir.php +++ b/public_html/entreaulas/_incl/auth_redir.php @@ -7,7 +7,7 @@ if (str_starts_with($ua, "EntreAulasAuth/")) { $username = explode("/", $ua)[1]; $userpass = explode("/", $ua)[2]; $_SESSION["entreaulas_auth_user"] = $username; - $_SESSION["entreaulas_auth_data"] = json_decode(file_get_contents("/srv/storage/entreaulas/Usuarios/$username.json"), true); + $_SESSION["entreaulas_auth_data"] = json_decode(file_get_contents("/DATA/entreaulas/Usuarios/$username.json"), true); $_SESSION["entreaulas_auth_ok"] = true; session_regenerate_id(); ini_set("session.use_only_cookies", "true"); diff --git a/public_html/entreaulas/_login.php b/public_html/entreaulas/_login.php index 99473a8..5d66ec4 100755 --- a/public_html/entreaulas/_login.php +++ b/public_html/entreaulas/_login.php @@ -2,7 +2,7 @@ session_start(); if ($_GET["reload_users"] == "1") { $user = $_SESSION['entreaulas_auth_user']; - $userdata = json_decode(file_get_contents("/srv/storage/entreaulas/Usuarios/$user.json"), true); + $userdata = json_decode(file_get_contents("/DATA/entreaulas/Usuarios/$user.json"), true); $_SESSION['entreaulas_auth_data'] = $userdata; header("Location: /entreaulas/"); die(); @@ -16,7 +16,7 @@ if (isset($_POST["user"])) { $valid = ""; $user = trim(strtolower($_POST["user"])); $password = $_POST["password"]; - $userdata = json_decode(file_get_contents("/srv/storage/entreaulas/Usuarios/$user.json"), true); + $userdata = json_decode(file_get_contents("/DATA/entreaulas/Usuarios/$user.json"), true); if (!isset($userdata["password_hash"])) { $valid = "El usuario no existe."; } diff --git a/public_html/entreaulas/admin/aularios.php b/public_html/entreaulas/admin/aularios.php index 2a6de49..c0cffdc 100644 --- a/public_html/entreaulas/admin/aularios.php +++ b/public_html/entreaulas/admin/aularios.php @@ -11,8 +11,8 @@ switch ($_GET["form"]) { "icon" => $_POST["icon"] ?? "/static/logo-entreaulas.png" ]; // Make path recursive (mkdir -p equivalent) - @mkdir("/srv/storage/entreaulas/Centros/$centro_id/Aularios/", 0777, true); - file_put_contents("/srv/storage/entreaulas/Centros/$centro_id/Aularios/$aulario_id.json", json_encode($aulario_data)); + @mkdir("/DATA/entreaulas/Centros/$centro_id/Aularios/", 0777, true); + file_put_contents("/DATA/entreaulas/Centros/$centro_id/Aularios/$aulario_id.json", json_encode($aulario_data)); // Update user data $_SESSION["entreaulas_auth_data"]["aulas"][] = $aulario_id; header("Location: ?action=index"); diff --git a/public_html/entreaulas/aulario.php b/public_html/entreaulas/aulario.php index 0796837..53b57ca 100644 --- a/public_html/entreaulas/aulario.php +++ b/public_html/entreaulas/aulario.php @@ -3,7 +3,7 @@ require_once "_incl/auth_redir.php"; require_once "_incl/pre-body.php"; $aulario_id = $_GET["id"]; $centro_id = $_SESSION["entreaulas_auth_data"]["centro"]; -$aulario = json_decode(file_get_contents("/srv/storage/entreaulas/Centros/$centro_id/Aularios/$aulario_id.json"), true); +$aulario = json_decode(file_get_contents("/DATA/entreaulas/Centros/$centro_id/Aularios/$aulario_id.json"), true); ?>