Installation:
composer require mwguerra/web-terminal
php artisan vendor:publish --provider="Mwguerra\WebTerminal\WebTerminalServiceProvider" --tag="web-terminal-config"
php artisan migrate
Basic Configuration:
config/web-terminal.php to define:
['ls', 'pwd', 'php artisan'])session_timeout_minutes = 30)First Use Case:
use Mwguerra\WebTerminal\Components\Terminal;
Terminal::make()
->connection('local') // or 'ssh'
->allowedCommands(['ls', 'php artisan'])
->width('100%')
->height('600px')
config/web-terminal.php:
'connections' => [
'ssh' => [
'host' => 'your-server.com',
'username' => 'deploy',
'password' => env('SSH_PASSWORD'), // or use 'private_key'
'port' => 22,
],
],
Command Whitelisting:
config/web-terminal.php under allowed_commands:
'allowed_commands' => [
'ls -la',
'php artisan {command}',
'composer {command}',
],
{command}) for dynamic arguments (e.g., php artisan {command} allows php artisan migrate).SSH Management:
TerminalConnection model) and fetch them dynamically:
Terminal::make()
->connection('ssh')
->connectionConfig(fn () => TerminalConnection::find(1)->toArray())
private_key and private_key_passphrase in config:
'connections' => [
'ssh' => [
'private_key' => file_get_contents('/path/to/key'),
'private_key_passphrase' => env('SSH_KEY_PASSPHRASE'),
],
],
Scripts:
config/web-terminal.php:
'scripts' => [
'deploy' => [
'commands' => [
'git pull origin main',
'php artisan migrate',
'php artisan optimize',
],
'description' => 'Run full deployment',
],
],
Terminal::make()->script('deploy')
Filament Integration:
php artisan make:filament-page TerminalPage
Then register it in AppServiceProvider:
Filament::registerPages([
\App\Filament\Pages\TerminalPage::class,
]);
Terminal::make()->connection('local')
Permissions:
TerminalPermission enum:
use Mwguerra\WebTerminal\Enums\TerminalPermission;
$user->givePermissionTo(TerminalPermission::EXECUTE_COMMANDS);
public function viewTerminal(User $user): bool
{
return $user->hasPermissionTo(TerminalPermission::VIEW_TERMINAL);
}
Session Handling:
config/web-terminal.php:
'session_timeout_minutes' => 15,
'disconnect_on_navigate' => true,
php artisan make:filament-resource TerminalSession
Multi-Tenant Isolation:
TerminalConnection::where('tenant_id', $tenant->id) to scope SSH connections.getAllowedCommands() in a custom TerminalService to filter by tenant.Custom Command Handlers:
Mwguerra\WebTerminal\Services\CommandHandler to add logic for specific commands:
public function handleCommand(string $command, TerminalSession $session): CommandResult
{
if (str_starts_with($command, 'custom:')) {
return $this->executeCustomCommand($command);
}
return parent::handleCommand($command, $session);
}
WebSocket Streaming:
vim, htop):
'streaming' => [
'enabled' => true,
'websocket_path' => '/terminal/stream',
],
Command Injection:
php artisan {command}) can expose your system to injection if {command} isn’t sanitized.* or ?.SSH Key Permissions:
chmod 600 /path/to/private_key
chown www-data:www-data /path/to/private_key
PTY Resource Limits:
tmux, screen) may exhaust system resources.max_sessions in config and monitor usage via Filament stats.Filament Caching:
defer:
Terminal::make()->defer()
WebSocket CORS:
config/cors.php:
'paths' => ['terminal/stream', 'api/*'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
Artisan Command Restrictions:
queue:work or schedule:run may hang indefinitely.--once flags or limit to non-blocking commands:
'allowed_commands' => [
'php artisan queue:work --once',
],
Logs:
config/web-terminal.php:
'logging' => [
'enabled' => true,
'level' => 'debug',
],
storage/logs/laravel.log for connection/command errors.SSH Debugging:
'ssh' => [
'debug' => true,
],
ssh -vvv manually to test connections.WebSocket Issues:
curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: your-app.test" http://your-app.test/terminal/stream
Permission Denied:
www-data) has execute permissions for local commands:
sudo chmod +x /usr/bin/php /usr/bin/composer
Custom Connection Types:
Mwguerra\WebTerminal\Contracts\ConnectionInterface to add support for Docker, Kubernetes, etc.Command Pre/Post Processing:
Mwguerra\WebTerminal\Services\CommandHandler to:
--env=production).rm -rf).UI Customization:
resources/views/vendor/web-terminal.Terminal::make()->extraAttributes(['class' => 'custom-terminal-theme'])
Audit Trail:
Mwguerra\WebTerminal\Models\TerminalLog to add custom fields (e.g., user_agent, ip_address):
php artisan make:m
How can I help you explore Laravel packages today?