Add Docker support and migrate data paths to /DATA/
Co-authored-by: naielv <109038805+naielv@users.noreply.github.com>
This commit is contained in:
8
.dockerignore
Normal file
8
.dockerignore
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
README.md
|
||||||
|
Dockerfile
|
||||||
|
docker-compose.yml
|
||||||
|
.dockerignore
|
||||||
|
DATA
|
||||||
|
*.md
|
||||||
8
.env.example
Normal file
8
.env.example
Normal 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
4
.gitignore
vendored
@@ -471,3 +471,7 @@ composer.lock
|
|||||||
*.css.map
|
*.css.map
|
||||||
*.sass.map
|
*.sass.map
|
||||||
*.scss.map
|
*.scss.map
|
||||||
|
|
||||||
|
##### Docker
|
||||||
|
.env
|
||||||
|
DATA/
|
||||||
|
|||||||
166
DOCKER.md
Normal file
166
DOCKER.md
Normal 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
43
Dockerfile
Normal 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
26
docker-compose.yml
Normal 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
|
||||||
@@ -5,7 +5,7 @@ if (isset($_POST["user"])) {
|
|||||||
$valid = "";
|
$valid = "";
|
||||||
$user = trim(strtolower($_POST["user"]));
|
$user = trim(strtolower($_POST["user"]));
|
||||||
$password = $_POST["password"];
|
$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)) {
|
if (!isset($users)) {
|
||||||
$valid = "Fallo del sistema: No hay cuentas.";
|
$valid = "Fallo del sistema: No hay cuentas.";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ if (str_starts_with($ua, "EntreAulasAuth/")) {
|
|||||||
$username = explode("/", $ua)[1];
|
$username = explode("/", $ua)[1];
|
||||||
$userpass = explode("/", $ua)[2];
|
$userpass = explode("/", $ua)[2];
|
||||||
$_SESSION["entreaulas_auth_user"] = $username;
|
$_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["entreaulas_auth_ok"] = true;
|
||||||
session_regenerate_id();
|
session_regenerate_id();
|
||||||
ini_set("session.use_only_cookies", "true");
|
ini_set("session.use_only_cookies", "true");
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
session_start();
|
session_start();
|
||||||
if ($_GET["reload_users"] == "1") {
|
if ($_GET["reload_users"] == "1") {
|
||||||
$user = $_SESSION['entreaulas_auth_user'];
|
$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;
|
$_SESSION['entreaulas_auth_data'] = $userdata;
|
||||||
header("Location: /entreaulas/");
|
header("Location: /entreaulas/");
|
||||||
die();
|
die();
|
||||||
@@ -16,7 +16,7 @@ if (isset($_POST["user"])) {
|
|||||||
$valid = "";
|
$valid = "";
|
||||||
$user = trim(strtolower($_POST["user"]));
|
$user = trim(strtolower($_POST["user"]));
|
||||||
$password = $_POST["password"];
|
$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"])) {
|
if (!isset($userdata["password_hash"])) {
|
||||||
$valid = "El usuario no existe.";
|
$valid = "El usuario no existe.";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ switch ($_GET["form"]) {
|
|||||||
"icon" => $_POST["icon"] ?? "/static/logo-entreaulas.png"
|
"icon" => $_POST["icon"] ?? "/static/logo-entreaulas.png"
|
||||||
];
|
];
|
||||||
// Make path recursive (mkdir -p equivalent)
|
// Make path recursive (mkdir -p equivalent)
|
||||||
@mkdir("/srv/storage/entreaulas/Centros/$centro_id/Aularios/", 0777, true);
|
@mkdir("/DATA/entreaulas/Centros/$centro_id/Aularios/", 0777, true);
|
||||||
file_put_contents("/srv/storage/entreaulas/Centros/$centro_id/Aularios/$aulario_id.json", json_encode($aulario_data));
|
file_put_contents("/DATA/entreaulas/Centros/$centro_id/Aularios/$aulario_id.json", json_encode($aulario_data));
|
||||||
// Update user data
|
// Update user data
|
||||||
$_SESSION["entreaulas_auth_data"]["aulas"][] = $aulario_id;
|
$_SESSION["entreaulas_auth_data"]["aulas"][] = $aulario_id;
|
||||||
header("Location: ?action=index");
|
header("Location: ?action=index");
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ require_once "_incl/auth_redir.php";
|
|||||||
require_once "_incl/pre-body.php";
|
require_once "_incl/pre-body.php";
|
||||||
$aulario_id = $_GET["id"];
|
$aulario_id = $_GET["id"];
|
||||||
$centro_id = $_SESSION["entreaulas_auth_data"]["centro"];
|
$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">
|
<div class="card pad">
|
||||||
<h1>Aulario: <?= htmlspecialchars($aulario["name"]) ?></h1>
|
<h1>Aulario: <?= htmlspecialchars($aulario["name"]) ?></h1>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ require_once "_incl/pre-body.php";?>
|
|||||||
<?php $user_data = $_SESSION["entreaulas_auth_data"];
|
<?php $user_data = $_SESSION["entreaulas_auth_data"];
|
||||||
$centro_id = $user_data["centro"];
|
$centro_id = $user_data["centro"];
|
||||||
foreach ($user_data["aulas"] as $aulario_id) {
|
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">
|
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">
|
<img style="height: 125px;" src="' . $aulario["icon"] . '" alt="' . htmlspecialchars($aulario["name"]) . ' Icono">
|
||||||
<br>
|
<br>
|
||||||
|
|||||||
Reference in New Issue
Block a user