Shellbox
Library and server for containerized shell execution
Loading...
Searching...
No Matches
Shellbox\Command\BoxedCommand Class Reference

A command with input and output files in an otherwise empty working directory. More...

+ Inheritance diagram for Shellbox\Command\BoxedCommand:

Public Member Functions

 __construct (BoxedExecutor $boxedExecutor)
 
 routeName (string $routeName)
 Set the route name.
 
 inputFileFromString (string $boxedName, string $contents)
 Add an input file, with the contents given by a string.
 
 inputFileFromFile (string $boxedName, string $sourcePath)
 Add an input file, with the contents copied from another file.
 
 inputFileFromStream (string $boxedName, StreamInterface $stream)
 Add an input file, with the contents copied from a stream.
 
 outputFileToString (string $boxedName)
 Register an output file.
 
 outputFileToFile (string $boxedName, string $destPath)
 Register an output file.
 
 outputFileToStream (string $boxedName, StreamInterface $stream)
 Register an output file.
 
 outputGlobToString (string $prefix, string $extension)
 Register a series of expected output files identified by the pattern <prefix>*.
 
 outputGlobToFile (string $prefix, string $extension, string $destDir)
 Register a series of expected output files identified by the pattern <prefix>*.
 
 execute ()
 Execute the command.
 
 getClientData ()
 Get command parameters for JSON serialization by the client.
 
 setClientData ( $data)
 Set command parameters using a data array created by getClientData()
 
 getRouteName ()
 Get the route name.
 
 getInputFiles ()
 Get InputFile objects describing the registered input files.
 
 getOutputFiles ()
 Get OutputFile objects describing the registered output files.
 
 getOutputGlobs ()
 Get OutputGlob objects describing the registered output globs.
 
- Public Member Functions inherited from Shellbox\Command\Command
 params (... $args)
 Adds parameters to the command.
 
 unsafeParams (... $args)
 Adds unsafe parameters to the command.
 
 replaceParams (... $args)
 Replace the whole command with the given set of arguments.
 
 unsafeCommand (string $command)
 Replace the whole command string with something else.
 
 cpuTimeLimit ( $limit)
 Set the CPU time limit, that is, the amount of time the process spends in the running state.
 
 wallTimeLimit ( $limit)
 Set the wall clock time limit, that is, the amount of real time the process may run for.
 
 memoryLimit ( $limit)
 Set the memory limit in bytes.
 
 fileSizeLimit ( $limit)
 Set the maximum file size that the command may create.
 
 environment (array $environment)
 Sets environment variables which should be added to the executed command environment.
 
 stdin (string $stdin)
 Sends the provided input to the command.
 
 passStdin (bool $yesno=true)
 Controls whether stdin is passed through to the command, so that the user can interact with the command when it is run in CLI mode.
 
 includeStderr (bool $includeStderr=true)
 Controls whether stderr should be included in stdout, including errors from wrappers.
 
 forwardStderr (bool $yesno=true)
 If this is set to true, text written to stderr by the command will be passed through to PHP's stderr.
 
 logStderr (bool $yesno=true)
 When enabled, text sent to stderr will be logged with a level of 'error'.
 
 useLogPipe (bool $yesno=true)
 Open FD 3 as a pipe and pass the write side to the command.
 
 workingDirectory (string $path)
 Set the working directory under which the command will be run.
 
 procOpenOptions (array $options)
 Set special options to proc_open().
 
 disableNetwork (bool $yesno=true)
 Disable networking, if possible.
 
 disabledSyscalls (array $syscalls)
 Specify the set of disabled syscalls.
 
 firejailDefaultSeccomp (bool $yesno=true)
 Enable/disable the default Firejail seccomp filter.
 
 noNewPrivs (bool $yesno=true)
 Enable the no_new_privs attribute to prevent privilege escalation via setuid executables and similar.
 
 privateUserNamespace (bool $yesno=true)
 Use a private user namespace.
 
 privateDev (bool $yesno=true)
 Create a private /dev mount.
 
 allowPath (... $paths)
 If called, the files/directories that are allowed will certainly be available to the shell command.
 
 allowedPaths (array $paths)
 Replace the list of allowed paths.
 
 disallowPath (... $paths)
 Disallow the specified paths so that the command cannot access them.
 
 disallowedPaths (array $paths)
 Replace the list of disallowed paths.
 
 disableSandbox (bool $yesno=true)
 Disable firejail and similar sandboxes.
 
 getCommandString ()
 Get the current command string.
 
 getCpuTimeLimit ()
 Get the CPU limit.
 
 getWallTimeLimit ()
 Get the wall clock time limit.
 
 getMemoryLimit ()
 Get the memory limit.
 
 getFileSizeLimit ()
 Get the file size limit.
 
 getEnvironment ()
 Get the environment.
 
 getStdin ()
 Get the text to be passed to stdin.
 
 getPassStdin ()
 Get whether to pass through stdin.
 
 getIncludeStderr ()
 Get whether to duplicate stderr to stdout.
 
 getLogStderr ()
 Get whether to log text seen on stderr.
 
 getForwardStderr ()
 Get whether to forward the command's stderr to the parent's stderr.
 
 getUseLogPipe ()
 Get whether to enable the log pipe.
 
 getWorkingDirectory ()
 
 getProcOpenOptions ()
 Get the additional proc_open() options.
 
 getDisableNetwork ()
 Get whether to disable external networking.
 
 getDisabledSyscalls ()
 Get the list of disabled syscalls.
 
 getFirejailDefaultSeccomp ()
 Get whether to use firejail's default seccomp filter.
 
 getNoNewPrivs ()
 Get whether to enable the no_new_privs process attribute.
 
 getPrivateUserNamespace ()
 Get whether to use a private user namespace.
 
 getPrivateDev ()
 Get whether to mount a private /dev filesystem.
 
 getAllowedPaths ()
 Get the allowed paths.
 
 getDisallowedPaths ()
 Get the disallowed paths.
 
 getDisableSandbox ()
 Get whether to disable firejail and similar sandboxes.
 
 getSyntaxInfo ()
 Parse the current command string.
 

Detailed Description

A command with input and output files in an otherwise empty working directory.

Member Function Documentation

◆ execute()

Shellbox\Command\BoxedCommand::execute ( )

Execute the command.

Returns
BoxedResult

◆ getClientData()

Shellbox\Command\BoxedCommand::getClientData ( )

Get command parameters for JSON serialization by the client.

Reimplemented from Shellbox\Command\Command.

◆ getRouteName()

Shellbox\Command\BoxedCommand::getRouteName ( )

Get the route name.

Returns
string|null

◆ inputFileFromFile()

Shellbox\Command\BoxedCommand::inputFileFromFile ( string $boxedName,
string $sourcePath )

Add an input file, with the contents copied from another file.

Parameters
string$boxedNameThe destination file name relative to the working directory
string$sourcePathThe path of the source file
Returns
$this

◆ inputFileFromStream()

Shellbox\Command\BoxedCommand::inputFileFromStream ( string $boxedName,
StreamInterface $stream )

Add an input file, with the contents copied from a stream.

Parameters
string$boxedNameThe destination file name relative to the working directory
StreamInterface$streamThe source stream
Returns
$this

◆ inputFileFromString()

Shellbox\Command\BoxedCommand::inputFileFromString ( string $boxedName,
string $contents )

Add an input file, with the contents given by a string.

Parameters
string$boxedNameThe file name relative to the working directory
string$contentsThe file contents
Returns
$this

◆ outputFileToFile()

Shellbox\Command\BoxedCommand::outputFileToFile ( string $boxedName,
string $destPath )

Register an output file.

If the command creates it, the contents will be copied to a specified location.

Parameters
string$boxedNameThe expected location of the file relative to the working directory.
string$destPathThe place where the file will be copied to
Returns
$this

◆ outputFileToStream()

Shellbox\Command\BoxedCommand::outputFileToStream ( string $boxedName,
StreamInterface $stream )

Register an output file.

If the command creates it, the contents will be copied to a stream.

Parameters
string$boxedNameThe expected location of the file relative to the working directory.
StreamInterface$stream
Returns
$this

◆ outputFileToString()

Shellbox\Command\BoxedCommand::outputFileToString ( string $boxedName)

Register an output file.

If the command creates it, the contents will be read into memory.

Parameters
string$boxedNameThe expected location of the file relative to the working directory.
Returns
$this

◆ outputGlobToFile()

Shellbox\Command\BoxedCommand::outputGlobToFile ( string $prefix,
string $extension,
string $destDir )

Register a series of expected output files identified by the pattern <prefix>*.

<extension>

Each file that appears in the working directory which matches the specified pattern will be copied to the specified destination directory

Parameters
string$prefixThe prefix, potentially including a subdirectory relative to the working directory.
string$extensionThe file extension, not including the dot.
string$destDirThe destination directory, which must already exist.
Returns
$this

◆ outputGlobToString()

Shellbox\Command\BoxedCommand::outputGlobToString ( string $prefix,
string $extension )

Register a series of expected output files identified by the pattern <prefix>*.

<extension>

Each file that appears in the working directory which matches the specified pattern will be read into memory.

Parameters
string$prefixThe prefix, potentially including a subdirectory relative to the working directory.
string$extensionThe file extension, not including the dot.
Returns
$this

◆ routeName()

Shellbox\Command\BoxedCommand::routeName ( string $routeName)

Set the route name.

This should be a short string used by system administrators to identify the command being run, in order to route it to the correct container.

Parameters
string$routeName
Returns
$this

◆ setClientData()

Shellbox\Command\BoxedCommand::setClientData ( $data)

Set command parameters using a data array created by getClientData()

Reimplemented from Shellbox\Command\Command.


The documentation for this class was generated from the following file: