Skip to content

WhispPHP/whisp

Repository files navigation

Your pure* PHP SSH server & the best way to build SSH based TUIs

GitHub Workflow Status (master) Latest Version License

Note

Quick example: sign our guestbook (See the code)

ssh guestbook@whisp.fyi

Explore the docs at WhispPHP.com »

Installation

composer require whispphp/whisp

Requirements

  • PHP 8.1+
  • FFI module installed and enabled
  • pcntl module
  • libsodium module

Usage

Run the server on the port & IP you'd like, with the apps you want to make available. Each connection is forked to its own process and runs independently.

<?php

use Whisp\Server;

$server = new Server(port: 2222);

// Available apps - each is its own script forked
$server->run(apps: [
    'default' => __DIR__.'/examples/howdy.php',
    'guestbook' => __DIR__.'/examples/guestbook.php',
]);

// $server->run('full-path/howdy.php'); // Pass just one path if you'd like to only support 1 default script

Once running you can test with:

Default app

ssh localhost -p2222

Guestbook app

ssh guestbook@localhost -p2222

Environment variables available to each app

These are each available as environment variables.

Variable Description Notes
WHISP_APP The name of the app being requested
WHISP_CLIENT_IP The IP address of the connecting client
WHISP_TTY The TTY information for the connection e.g. /dev/ttys072
WHISP_USERNAME The username used in the SSH connection Unavailable when no username passed, or when the username is a valid app

Clients requesting apps

There are two ways for clients to request an available app:

  1. Username method: ssh app@server - we use the 'username' here as the app name if it matches an available app.
    • Much cleaner, but means if you need the username for auth you can't define the app this way
  2. Command method: ssh server -t app - request an interactive shell (-t) with the requested app

Examples

Play the Dinorun gameSee the code

ssh dinorun@whisp.fyi

View your sunrise/sunset timesSee the code

ssh daylight@whisp.fyi

Find your closest World Heritage Sites

ssh elec@whisp.fyi

Support & Credits

This was developed by Ashley Hindle. If you like it, please star it, share it, and let me know!