MediaWiki REL1_33
|
Class used for executing shell commands. More...
Public Member Functions | |
__construct () | |
Constructor. | |
__destruct () | |
Destructor. | |
__toString () | |
Returns the final command line before environment/limiting, etc are applied. | |
cgroup ( $cgroup) | |
Sets cgroup for this command. | |
environment (array $env) | |
Sets environment variables which should be added to the executed command environment. | |
execute () | |
Executes command. | |
includeStderr ( $yesno=true) | |
Controls whether stderr should be included in stdout, including errors from limit.sh. | |
input ( $inputString) | |
Sends the provided input to the command. | |
limits (array $limits) | |
Sets execution limits. | |
logStderr ( $yesno=true) | |
When enabled, text sent to stderr will be logged with a level of 'error'. | |
params () | |
Adds parameters to the command. | |
profileMethod ( $method) | |
Sets calling function for profiler. | |
restrict ( $restrictions) | |
Set additional restrictions for this request. | |
unsafeParams () | |
Adds unsafe parameters to the command. | |
whitelistPaths (array $paths) | |
If called, only the files/directories that are whitelisted will be available to the shell command. | |
Protected Member Functions | |
buildFinalCommand ( $command) | |
String together all the options and build the final command to execute. | |
hasRestriction ( $restriction) | |
Bitfield helper on whether a specific restriction is enabled. | |
Protected Attributes | |
string | $command = '' |
int | $restrictions = 0 |
bitfield with restrictions | |
Private Attributes | |
string false | $cgroup = false |
bool | $doIncludeStderr = false |
bool | $doLogStderr = false |
string[] | $env = [] |
bool | $everExecuted = false |
string null | $inputString |
array | $limits |
string | $method |
MediaWiki\Shell\Command::__construct | ( | ) |
Constructor.
Don't call directly, instead use Shell::command()
ShellDisabledError |
Definition at line 86 of file Command.php.
References MediaWiki\Shell\Shell\isDisabled().
MediaWiki\Shell\Command::__destruct | ( | ) |
Destructor.
Makes sure programmer didn't forget to execute the command after all
Definition at line 97 of file Command.php.
References MediaWiki\Shell\Command\$command, $context, and MediaWiki\Shell\Command\$method.
MediaWiki\Shell\Command::__toString | ( | ) |
Returns the final command line before environment/limiting, etc are applied.
Use string conversion only for debugging, don't try to pass this to some other execution medium.
Definition at line 564 of file Command.php.
|
protected |
String together all the options and build the final command to execute.
string | $command | Already-escaped command to run |
Reimplemented in MediaWiki\Shell\FirejailCommand.
Definition at line 290 of file Command.php.
References MediaWiki\Shell\Command\$command, $time, and(), MediaWiki\Shell\Command\cgroup(), MediaWiki\Shell\Command\limits(), and wfIsWindows().
Referenced by MediaWiki\Shell\Command\execute().
MediaWiki\Shell\Command::cgroup | ( | $cgroup | ) |
Sets cgroup for this command.
string | false | $cgroup | Absolute file path to the cgroup, or false to not use a cgroup |
Definition at line 238 of file Command.php.
References MediaWiki\Shell\Command\$cgroup, and(), and MediaWiki\Shell\Command\cgroup().
Referenced by MediaWiki\Shell\Command\buildFinalCommand(), and MediaWiki\Shell\Command\cgroup().
MediaWiki\Shell\Command::environment | ( | array | $env | ) |
Sets environment variables which should be added to the executed command environment.
string[] | $env | array of variable name => value |
Definition at line 177 of file Command.php.
References MediaWiki\Shell\Command\$env, and and().
MediaWiki\Shell\Command::execute | ( | ) |
Executes command.
Afterwards, getExitCode() and getOutput() can be used to access execution results.
Exception | |
ProcOpenError | |
ShellDisabledError |
Definition at line 349 of file Command.php.
References MediaWiki\Shell\Command\$inputString, $line, $lines, $res, and(), MediaWiki\Shell\Command\buildFinalCommand(), list, SHELL_MAX_ARG_STRLEN, string, and wfGetCaller().
|
protected |
Bitfield helper on whether a specific restriction is enabled.
int | $restriction |
Definition at line 264 of file Command.php.
References and().
Referenced by MediaWiki\Shell\FirejailCommand\buildFinalCommand().
MediaWiki\Shell\Command::includeStderr | ( | $yesno = true | ) |
Controls whether stderr should be included in stdout, including errors from limit.sh.
Default: don't include.
bool | $yesno |
Definition at line 214 of file Command.php.
References and().
MediaWiki\Shell\Command::input | ( | $inputString | ) |
Sends the provided input to the command.
When set to null (default), the command will use the standard input.
string | null | $inputString |
Definition at line 201 of file Command.php.
References MediaWiki\Shell\Command\$inputString, and(), null, and string.
MediaWiki\Shell\Command::limits | ( | array | $limits | ) |
Sets execution limits.
array | $limits | Associative array of limits. Keys (all optional): filesize (for ulimit -f), memory, time, walltime. |
Definition at line 160 of file Command.php.
References MediaWiki\Shell\Command\$limits, and(), and MediaWiki\Shell\Command\limits().
Referenced by MediaWiki\Shell\Command\buildFinalCommand(), and MediaWiki\Shell\Command\limits().
MediaWiki\Shell\Command::logStderr | ( | $yesno = true | ) |
When enabled, text sent to stderr will be logged with a level of 'error'.
bool | $yesno |
Definition at line 226 of file Command.php.
References and().
MediaWiki\Shell\Command::params | ( | ) |
Adds parameters to the command.
All parameters are sanitized via Shell::escape(). Null values are ignored.
string | string[] | $args,... |
Definition at line 117 of file Command.php.
References $args, and(), and MediaWiki\Shell\Shell\escape().
MediaWiki\Shell\Command::profileMethod | ( | $method | ) |
Sets calling function for profiler.
By default, the caller for execute() will be used.
string | $method |
Definition at line 189 of file Command.php.
References MediaWiki\Shell\Command\$method, and and().
MediaWiki\Shell\Command::restrict | ( | $restrictions | ) |
Set additional restrictions for this request.
int | $restrictions |
Definition at line 251 of file Command.php.
References MediaWiki\Shell\Command\$restrictions, and and().
MediaWiki\Shell\Command::unsafeParams | ( | ) |
Adds unsafe parameters to the command.
These parameters are NOT sanitized in any way. Null values are ignored.
string | string[] | $args,... |
Definition at line 136 of file Command.php.
MediaWiki\Shell\Command::whitelistPaths | ( | array | $paths | ) |
If called, only the files/directories that are whitelisted will be available to the shell command.
limit.sh will always be whitelisted
string[] | $paths |
Reimplemented in MediaWiki\Shell\FirejailCommand.
Definition at line 278 of file Command.php.
References and().
|
private |
Definition at line 72 of file Command.php.
Referenced by MediaWiki\Shell\Command\cgroup().
|
protected |
Definition at line 39 of file Command.php.
Referenced by MediaWiki\Shell\Command\__destruct(), MediaWiki\Shell\Command\buildFinalCommand(), and MediaWiki\Shell\FirejailCommand\buildFinalCommand().
|
private |
Definition at line 63 of file Command.php.
|
private |
Definition at line 66 of file Command.php.
|
private |
Definition at line 54 of file Command.php.
Referenced by MediaWiki\Shell\Command\environment().
|
private |
Definition at line 69 of file Command.php.
|
private |
Definition at line 60 of file Command.php.
Referenced by MediaWiki\Shell\Command\execute(), and MediaWiki\Shell\Command\input().
|
private |
Definition at line 42 of file Command.php.
Referenced by MediaWiki\Shell\Command\limits().
|
private |
Definition at line 57 of file Command.php.
Referenced by MediaWiki\Shell\Command\__destruct(), and MediaWiki\Shell\Command\profileMethod().
|
protected |
bitfield with restrictions
Definition at line 79 of file Command.php.
Referenced by MediaWiki\Shell\Command\restrict().