定制 johnhenryspike/php-web-terminal 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

johnhenryspike/php-web-terminal

最新稳定版本:1.0.0

Composer 安装命令:

composer require johnhenryspike/php-web-terminal

包简介

A minimal single-endpoint PHP web terminal emulator with Bearer auth.

README 文档

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.

  1. Require it in your project:
    composer require spike/php-web-terminal
  2. 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

  1. Ensure PHP 8.1+ is installed.
  2. From the project root, start the PHP dev server:
    php -S localhost:8000
  3. Open http://localhost:8000/ in your browser.

Option B: Docker Compose

  1. Ensure Docker and Docker Compose are installed.
  2. From the project root, start the service:
    docker compose up
  3. Open http://localhost:8000/ in your browser.
  4. Stop with Ctrl+C, or run in the background with -d and stop with docker 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 implementing CommandInterface.

Customizing Commands

To add or modify commands:

  1. Create a class in src/Commands implementing App\\Domain\\CommandInterface with name() and execute(array $args): string.
  2. 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.

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-12