/** * @medium * @group server */ public function testShellDetection() { $shell = $this->getShell(); $type = $shell->getShellType(3); $this->assertFalse($type == ShellType::UNKNOWN()); }
function __construct(array $variables = []) { $this->variables = $variables; $this->shell_type = ShellType::UNKNOWN(); }
/** * Resolve the shell type * * @param float $timeout * @return ShellType */ public function getShellType($timeout = 15.0) { if ($this->shell_type !== null) { return $this->shell_type; } $this->readyShell($timeout); $this->sendln("echo \$0"); $regex = '/echo \\$0$\\n^(\\-[a-z]+)/sm'; $out = $this->readUntilExpression($regex, $timeout, true); $matches = null; preg_match_all($regex, $out, $matches); $shell_name = @$matches[1][0]; // $0 over SSH may prefix with a hyphen if ($shell_name[0] == '-') { $shell_name = substr($shell_name, 1); } try { $this->shell_type = ShellType::memberByValue($shell_name); } catch (UndefinedMemberException $e) { $this->shell_type = ShellType::UNKNOWN(); } return $this->shell_type; }