johnhenryspike / php-web-terminal
A minimal single-endpoint PHP web terminal emulator with Bearer auth.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/johnhenryspike/php-web-terminal
This package is auto-updated.
Last update: 2025-10-12 16:59:54 UTC
README
A minimal web-based terminal emulator implemented in PHP. All interactions happen via one resource:
- GET /index.php → serves the UI
- POST /index.php (JSON) → executes whitelisted commands on the server via PHP handlers (no eval, no shell execution)
Features
- Single endpoint (UI + API)
- Commands implemented as PHP functions only (no
eval
, no system command execution) - Bearer token auth (token requested on page load and stored in localStorage)
- Minimal inline HTML/CSS/JS
- Client-side command history
Installation (Composer library)
This project can be installed as a Composer library.
- Require it in your project:
composer require spike/php-web-terminal
- Publish or serve the included web entry point
index.php
, or embed the services in your own controller.
Autoloading follows PSR-4: the App\\
namespace maps to src/
.
Embedding as a library (example)
<?php use SpikeTerminal\Application\{TerminalService}; use SpikeTerminal\Application\CommandRegistry; require __DIR__ . '/vendor/autoload.php'; $registry = new CommandRegistry(); $registry->register(new SomeCommand($registry));
Getting Started (Standalone)
Option A: Local PHP
- Ensure PHP 8.1+ is installed.
- From the project root, start the PHP dev server:
php -S localhost:8000
- Open http://localhost:8000/ in your browser.
Option B: Docker Compose
- Ensure Docker and Docker Compose are installed.
- From the project root, start the service:
docker compose up
- Open http://localhost:8000/ in your browser.
- Stop with Ctrl+C, or run in the background with
-d
and stop withdocker compose down
.
The sandbox directory storage/
is created automatically (a sample readme.txt
is included).
Security Notes
- All commands are server-side PHP handlers; there is no
eval()
and no OS shell execution. - In production, use signed JWTs and HTTPS.
Architecture (OOP, clean-like)
The single endpoint remains /index.php
, but the logic is refactored into layers under src/
:
- Domain:
App\Domain
— core contracts (e.g.,CommandInterface
). - Application:
App\Application
— orchestration and use-cases (e.g.,TerminalService
,CommandRegistry
). - Presentation:
App\Presentation
— HTTP controller (TerminalController
) that render the UI (GET). - Commands:
App\Commands
— each command is a class implementingCommandInterface
.
Customizing Commands
To add or modify commands:
- Create a class in
src/Commands
implementingApp\\Domain\\CommandInterface
withname()
andexecute(array $args): string
. - Register it in
index.php
via$registry->register(new YourCommand(...deps...));
before the controller handles the request.
Notes
- No use of
eval()
or OS shell execution. All commands are pure PHP.