Net_SSH2::read PHP Метод

read() публичный Метод

Returns when there's a match for $expect, which can take the form of a string literal or, if $mode == NET_SSH2_READ_REGEX, a regular expression.
См. также: self::write()
public read ( string $expect = '', integer $mode = NET_SSH2_READ_SIMPLE ) : string
$expect string
$mode integer
Результат string
    function read($expect = '', $mode = NET_SSH2_READ_SIMPLE)
    {
        $this->curTimeout = $this->timeout;
        $this->is_timeout = false;
        if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) {
            user_error('Operation disallowed prior to login()');
            return false;
        }
        if (!($this->bitmap & NET_SSH2_MASK_SHELL) && !$this->_initShell()) {
            user_error('Unable to initiate an interactive shell session');
            return false;
        }
        $channel = $this->_get_interactive_channel();
        $match = $expect;
        while (true) {
            if ($mode == NET_SSH2_READ_REGEX) {
                preg_match($expect, substr($this->interactiveBuffer, -1024), $matches);
                $match = isset($matches[0]) ? $matches[0] : '';
            }
            $pos = strlen($match) ? strpos($this->interactiveBuffer, $match) : false;
            if ($pos !== false) {
                return $this->_string_shift($this->interactiveBuffer, $pos + strlen($match));
            }
            $response = $this->_get_channel_packet($channel);
            if (is_bool($response)) {
                $this->in_request_pty_exec = false;
                return $response ? $this->_string_shift($this->interactiveBuffer, strlen($this->interactiveBuffer)) : false;
            }
            $this->interactiveBuffer .= $response;
        }
    }

Usage Example

Пример #1
0
    public function Exec($command, $stdin = '')
    {
        $database = $this->session->getDatabase();
        $name = $database['name'];
        $engine = $this->session->getSpoolerByName($name, 'waae');
        if (!isset($engine[0]['shell'])) {
            print "?!";
            exit;
        }
        set_include_path('../vendor/phpseclib' . PATH_SEPARATOR . get_include_path());
        include 'Net/SSH2.php';
        include 'Crypt/RSA.php';
        $shell = $engine[0]['shell'];
        $host = $shell['host'];
        $user = $shell['user'];
        $ssh = new \Net_SSH2($host);
        if (isset($shell['key'])) {
            $key = new \Crypt_RSA();
            $ret = $key->loadKey($shell['key']);
            if (!$ret) {
                echo "loadKey failed\n";
                print "<pre>" . $ssh->getLog() . '</pre>';
                exit;
            }
        } elseif (isset($shell['password'])) {
            $key = $shell['password'];
        } else {
            $key = '';
            // ?! possible ?
        }
        if (!$ssh->login('autosys', $key)) {
            print 'Login Failed';
            print "<pre>" . $ssh->getLog() . '</pre>';
            exit;
        }
        if ($stdin == '') {
            return $ssh->exec(". ~/.bash_profile;{$command}");
        }
        // Test STDIN
        $ssh->enablePTY();
        print "profile" . $ssh->exec(". ~/.bash_profile");
        print "sort" . ($exec = $ssh->exec('sort'));
        $ssh->write(<<<EOF
echo "update_job: SE.ERIC.JOB.JobType_UNIX"
echo "description: 'ok!!'
EOF
);
        $ssh->reset(true);
        $ssh->setTimeout(2);
        print $ssh->read();
        return;
        return $ssh->read();
        // outputs the echo above
    }
All Usage Examples Of Net_SSH2::read