Files
lxd-app/api
..
2025-09-03 15:57:56 +02:00
2025-09-03 16:05:59 +02:00
2025-09-03 15:57:56 +02:00
2025-07-22 12:51:53 +02:00
2025-09-03 15:57:56 +02:00
2025-09-03 15:57:56 +02:00
2025-07-22 12:51:53 +02:00
2025-07-22 12:51:53 +02:00

LXD Proxy API (Slim Framework)

This is a PHP-based API using the Slim 4 Framework that dynamically manages and proxies traffic to LXD containers based on subdomain mappings.


🧩 Features

  • CAPTCHA validation for provisioning
  • Proxies requests to containerized environments
  • Persists domain-to-container mapping
  • Waits for container service to be ready before forwarding
  • Logs last access per container

📁 Project Structure

api/ │ ├── src/ │ │ ├── Controllers/ │ │ │ └── ProxyController.php │ │ ├── Services/ │ │ │ └── LxdService.php │ │ └── Utils/ │ │ └── SubdomainHelper.php │ ├── vendor/ # Composer dependencies │ ├── public/ │ │ └── last-access-logs/ │ ├── config.json # Domain-to-container mappings │ └── index.php # Slim entry point ├── composer.json └── README.md


⚙️ Requirements

  • PHP 8.4+
  • LXD installed and configured
  • PHP-FPM + NGINX
  • Composer
  • slim/slim
  • slim/psr7
  • guzzlehttp/guzzle
  • vlucas/phpdotenv

🚀 Setup Instructions

  1. put the folder in /var/www/html

  2. Install dependencies

    composer install
    
    
    
  3. Ensure PHP and NGINX are configured

NGINX config example: ```bash Please check nginx.conf file in root

  1. Map domain in /etc/hosts

    127.0.0.1   testone.lxdapp.local
    
    
  2. Make sure LXD is working

    lxc list
    
    
  3. 🔐 CAPTCHA Protection

    The /api/ POST endpoint expects a field panswer with the correct CAPTCHA.

    You can configure PCaptcha class for custom logic.

  4. 🧪 API Usage

    POST /api

    Request Body:

    {
    "source": "login",
    "panswer": "abc123"
    }
    
    **Headers:**
    
    Origin: http://testone.lxdapp.local
    
    **Response:**
    ```bash
    {
    "status": "success",
    "ip": "10.210.189.24"
    }
    
    
    

🧠 Notes

Container names are auto-generated using the subdomain prefix.

All containers are mapped in config.json.

If a container does not yet exist, it's created, started, and software is installed.

The system waits for the container to expose port 80 before proxying.

🪵 Logs

Last access logs for containers are saved in:
public/last-access-logs/container-*.txt

NGINX error logs (for debugging):
```bash
tail -f /var/log/nginx/error.log

👨‍💻 Development

Codebase follows PSR-4 autoloading (App\ namespace).

To add new functionality, work within app/src/Controllers or Services.