Add Docker support and migrate data paths to /DATA/

Co-authored-by: naielv <109038805+naielv@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-25 20:17:21 +00:00
parent f4200cbbd6
commit 4067a323fb
12 changed files with 263 additions and 8 deletions

8
.dockerignore Normal file
View File

@@ -0,0 +1,8 @@
.git
.gitignore
README.md
Dockerfile
docker-compose.yml
.dockerignore
DATA
*.md

8
.env.example Normal file
View File

@@ -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

4
.gitignore vendored
View File

@@ -471,3 +471,7 @@ composer.lock
*.css.map
*.sass.map
*.scss.map
##### Docker
.env
DATA/

166
DOCKER.md Normal file
View File

@@ -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
```

43
Dockerfile Normal file
View File

@@ -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"]

26
docker-compose.yml Normal file
View File

@@ -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

View File

@@ -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.";
}

View File

@@ -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");

View File

@@ -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.";
}

View File

@@ -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");

View File

@@ -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);
?>
<div class="card pad">
<h1>Aulario: <?= htmlspecialchars($aulario["name"]) ?></h1>

View File

@@ -11,7 +11,7 @@ require_once "_incl/pre-body.php";?>
<?php $user_data = $_SESSION["entreaulas_auth_data"];
$centro_id = $user_data["centro"];
foreach ($user_data["aulas"] as $aulario_id) {
$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);
echo '<a href="/entreaulas/aulario.php?id=' . $aulario_id . '" class="button grid-item">
<img style="height: 125px;" src="' . $aulario["icon"] . '" alt="' . htmlspecialchars($aulario["name"]) . ' Icono">
<br>