| Server IP : 89.39.208.18 / Your IP : 216.73.217.74 Web Server : LiteSpeed System : User : ( ) PHP Version : 7.4.33 Disable Function : eval,./,ln,passthru,dl,system,exec,popen,shell_exec,posix_getpwuid,posix_uname,ftp_exec,posix_uname,posix_getpwuid,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,get_current_user,getmyuid,getmygid,listen,chgrp,apache_note,apache_setenv,apache_child_terminate,closelog,debugger_off,debugge_on,ini_restore,netscript,escapeshellarg,cmd,backtick,virtual,show_sourc,show_source,pclose,pcntl_exec,datasec,old_offset,ctrl_dir,ini_alter,leak,listen,chgrp,apache_setenv,define_syslog_variables,root,diskfreespace,disk_free_space,disk_total_space,posix_kill,getmyuid,getmygid,apache_child_terminate,php_ini_scanned_files,ls,ps_aux,chown,getrusage,posixc,posame,chgrp,posix_setuid,posix_setsid,posix_setgid,apache_note,apache_setenv,x_getuid,e_ini_file,nfo,SQL,mysql_li,t_dbs,filegroup,highlight_file,ilegetcontents,get_dir,popen,popens,pfsockopen,dos_conv,apache_get_modules,crack_check,crack_closedict,rar_open,bzopen,bzread,bzwrite,shellcode,posix_isatty,posix_getservbyname,escapeshellarg,hypot,pg_host,pos,posix_access,inurl,posix_times,posix_mknod,pclose,ps_fill,symlink,id,escapeshellcmd,php_uname,phpinfo MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home3/mahyarcake/www/wp-content/plugins/duplicator-pro/src/Libs/Shell/ |
Upload File : |
<?php
namespace Duplicator\Libs\Shell;
use Exception;
class ShellOutput
{
/** @var int ENUM of shell command can be Shell::[CMD_POPEN,CMD_EXEC] */
private $method = 0;
/** @var string[] */
private $output = [];
/** @var int */
private $code = -1;
/** @var bool */
private $isCodeAvailable = true;
/**
* Initialise the Shell Output Response with real output
*
* @param null|string|string[] $output Shell Output Lines
* @param int $code Shell Output return code
* @param int $method ENUM of shell command can be Shell::[CMD_POPEN,CMD_EXEC,CMD_SHELL_EXEC]
* @param bool $isCodeAvailable is false attempting to read the code generates an exception
*/
public function __construct($output, $code, $method, $isCodeAvailable = true)
{
if (is_scalar($output) || is_null($output)) {
$output = (string) $output;
if (strlen($output) == 0) {
$output = [];
} elseif (($output = preg_split("/(\r\n|\n|\r)/", (string) $output)) === false) {
$output = [];
}
}
if ($method == 0) {
throw new Exception('Invalid method');
}
$this->output = self::formatOutput($output);
$this->code = (int) $code;
$this->method = $method;
$this->isCodeAvailable = (bool) $isCodeAvailable;
}
/**
* Format the Shell Output
*
* @param string[] $output Initial Shell Output
*
* @return string[] return Array of formatted Shell Output Lines
*/
private static function formatOutput($output)
{
foreach ($output as $key => $line) {
$line = preg_replace('~\r\n?~', "\n", $line);
if (strlen($line) == 0 || substr($line, -1) !== "\n") {
$line .= "\n";
}
$output[$key] = $line;
}
return $output;
}
/**
* Get complete Shell Output as a string
*
* @return string complete Shell output as a string
*/
public function getOutputAsString()
{
return implode('', $this->output);
}
/**
* Get complete Shell Output
*
* @return string[] complete Shell output as array lines
*/
public function getArrayWithAllOutputLines()
{
return $this->output;
}
/**
* Get complete Shell output return code
*
* @return integer shell output return code
*/
public function getCode()
{
if (!$this->isCodeAvailable) {
throw new Exception('The shell command return code is not available.');
}
return $this->code;
}
/**
* Get Shell PHP Function used for the Shell Output
*
* @return int ENUM of shell command can be Shell::[CMD_POPEN,CMD_EXEC,CMD_SHELL_EXEC]
*/
public function getOutputMethod()
{
return $this->method;
}
/**
* Get Shell PHP Function used for the Shell Output
*
* @return string Shell php function name
*/
public function getOutputMethodName()
{
switch ($this->method) {
case Shell::CMD_POPEN:
return 'popen';
case Shell::CMD_EXEC:
return 'exec';
case Shell::CMD_SHELL_EXEC:
return 'shell_exec';
default:
return 'unknown';
}
}
/**
* Check if Shell Output response is empty
*
* @return boolean
*/
public function isEmpty()
{
return (strlen(trim($this->getOutputAsString())) == 0);
}
}