devture/symfony-web-command-bundle
Installation
composer require devture/symfony-web-command-bundle
Add to config/bundles.php:
Devture\Bundle\WebCommandBundle\DevtureWebCommandBundle::class => ['all' => true],
Configuration
Add to config/packages/devture_web_command.yaml:
devture_web_command:
auth_token: '%env(DEVTURE_WEB_COMMAND_AUTH_TOKEN)%'
forced_uri: '%env(DEVTURE_WEB_COMMAND_FORCED_URI)%'
Set environment variables in .env:
DEVTURE_WEB_COMMAND_AUTH_TOKEN="$(pwgen -Bsv1 64)"
DEVTURE_WEB_COMMAND_FORCED_URI="https://your-app.com"
First Use Case Trigger a command via HTTP:
curl -X POST -H "Authorization: Bearer $DEVTURE_WEB_COMMAND_AUTH_TOKEN" http://your-app/web-command/execute/your:command
Cron Job Replacement Replace direct cron calls with HTTP requests:
* * * * * curl -sS -X POST -H "Authorization: Bearer $TOKEN" http://app/web-command/execute/app:task
API-Driven Command Execution Build a frontend UI to trigger commands securely (e.g., admin dashboard buttons).
Dynamic Command Arguments Pass arguments via query params or JSON body:
curl -X POST -H "Authorization: Bearer $TOKEN" -d '{"arg1": "value1"}' http://app/web-command/execute/app:command
Output Handling Capture command output via HTTP response (default) or redirect to a file:
devture_web_command:
output_file: '%kernel.project_dir%/var/web-command.log'
spatie/laravel-web-command) for seamless integration.monolog or Laravel’s log channel.rate_limiter to prevent abuse.Authentication Leaks
DEVTURE_WEB_COMMAND_AUTH_TOKEN in client-side code. Use server-side proxies or environment variables strictly.Forced URI Mismatches
forced_uri is misconfigured, generated URLs (e.g., for email links) may break. Test locally with http://localhost and update to production URI.forced_uri empty if commands don’t generate URLs (e.g., cache:clear).Command Output Size
debug:container) may hit PHP’s max_execution_time or HTTP limits. Stream output or paginate results:
devture_web_command:
output_stream: true
CSRF Protection
csrf_token middleware if needed:
# config/packages/security.yaml
firewalls:
main:
csrf_protection: true
auth_token matches exactly (case-sensitive) and is passed in the Authorization header.var/log/dev.log for command-specific exceptions. Wrap commands in try-catch blocks for graceful failures.console.command) and the bundle is loaded before the command.Custom Authentication
Override the Devture\Bundle\WebCommandBundle\Security\Authenticator to integrate with Symfony’s security system:
// src/Security/CustomAuthenticator.php
use Devture\Bundle\WebCommandBundle\Security\Authenticator as BaseAuthenticator;
class CustomAuthenticator extends BaseAuthenticator {
public function supports($token): bool {
// Custom logic (e.g., JWT, OAuth)
}
}
Command Whitelisting Restrict accessible commands via YAML:
devture_web_command:
allowed_commands:
- 'app:safe-command'
- 'app:another-safe-command'
Event Listeners Hook into command execution via Symfony events:
// src/EventListener/WebCommandListener.php
use Devture\Bundle\WebCommandBundle\Event\CommandExecuteEvent;
class WebCommandListener {
public function onCommandExecute(CommandExecuteEvent $event) {
if ($event->getCommandName() === 'app:critical') {
$event->stopPropagation(); // Block execution
}
}
}
Register in services.yaml:
services:
App\EventListener\WebCommandListener:
tags:
- { name: kernel.event_listener, event: devture.web_command.execute, method: onCommandExecute }
How can I help you explore Laravel packages today?