This feature adds the ability to execute commands inside running Docker containers directly from the CyberPanel web interface. This is particularly useful for applications like Honeygain that require specific command-line arguments to function properly.
- New View Function:
executeContainerCommandindockerManager/views.py - New Container Method:
executeContainerCommandindockerManager/container.py - New URL Pattern:
/docker/executeContainerCommandindockerManager/urls.py
- New Action Button: "Run Command" button in Container Actions section
- Command Execution Modal: Interactive modal for executing commands
- Command History: Tracks last 10 executed commands
- Real-time Output: Displays command output with proper formatting
- Permission Checks: Only admin users can execute commands
- Container Ownership: Users can only execute commands on containers they own
- Input Validation: Commands are properly sanitized using
shlex.split() - Error Handling: Comprehensive error handling for various failure scenarios
- Navigate to your Docker container in CyberPanel
- Ensure the container is running (the "Run Command" button is disabled for stopped containers)
- Click the "Run Command" button in the Container Actions section
- Enter your command in the input field (e.g.,
-tou-accept,ls -la,ps aux) - Press Enter or click the "Execute" button
- View the output in the terminal-style output area
- Use command history to quickly re-run previous commands
For applications requiring command-line arguments:
- Start your container
- Click "Run Command"
- Enter the required command (e.g.,
-tou-accept,--help,--version) - Click "Execute"
- View the output to confirm successful execution
For debugging and maintenance:
ls -la- List files and directoriesps aux- Show running processeswhoami- Display current userenv- Show environment variablesdf -h- Display disk usage
- Validation: Check if container exists and user has permissions
- Status Check: Ensure container is running
- Command Parsing: Use
shlex.split()to properly parse command arguments - Execution: Use Docker's
exec_run()method to execute command - Response: Return output, exit code, and any errors
- Container not found
- Container not running
- Permission denied
- Command execution failures
- Network connectivity issues
- Commands are executed with the same user as the container's default user
- No privileged execution (unless container is privileged)
- Input is sanitized to prevent injection attacks
- Only admin users can execute commands
dockerManager/container.py- AddedexecuteContainerCommandmethoddockerManager/views.py- AddedexecuteContainerCommandview functiondockerManager/urls.py- Added URL pattern for command execution
dockerManager/templates/dockerManager/viewContainer.html- Added UI componentsdockerManager/static/dockerManager/dockerManager.js- Added JavaScript functionality
POST /docker/executeContainerCommand
Request Body:
{
"name": "container_name",
"command": "command_to_execute"
}Response:
{
"commandStatus": 1,
"error_message": "None",
"output": "command_output",
"exit_code": 0,
"command": "executed_command"
}- "Container must be running" - Start the container first
- "Permission denied" - Ensure you have admin access
- "Command not found" - Check if the command exists in the container
- Empty output - Some commands may not produce visible output
- Check container logs for additional information
- Verify the container's base image supports the command
- Ensure proper command syntax for the container's shell
- Interactive terminal mode
- Command templates for common tasks
- Output filtering and search
- Command scheduling
- Multi-container command execution
- This feature should only be used by trusted administrators
- Commands are executed with the container's user permissions
- Consider implementing additional logging for audit purposes
- Monitor command execution for security compliance
- Pull any Docker image (e.g.,
ubuntu:latest,alpine:latest,nginx:latest) - Create a container with the image
- Start the container
- Use the "Run Command" feature to execute various commands:
ls -la- List filesps aux- Show processeswhoami- Check userenv- View environment
- Verify commands execute properly and output is displayed correctly
This feature provides a secure and user-friendly way to execute commands in Docker containers directly from the CyberPanel interface, making it easy to manage applications like Honeygain that require specific command-line arguments.