示例#1
0
文件: Password.php 项目: oncesk/ssh2
 /**
  * @param Client $client
  * @throws \RuntimeException
  *
  * @return mixed
  */
 public function authenticate(Client $client)
 {
     if (!@ssh2_auth_password($client->getConnection(), $this->getUser(), $this->getPassword())) {
         throw new \RuntimeException('Authentication Failed');
     }
     parent::authenticate($client);
 }
示例#2
0
文件: Shell.php 项目: oncesk/ssh2
 /**
  * @param Client $client
  * @param string $term_type
  * @param array  $env
  * @param int    $width
  * @param int    $height
  * @param int    $widthHeightType
  * @throws \Exception
  */
 public function __construct(Client $client, $term_type = self::TERMINAL_XTERM, $env = array(), $width = SSH2_DEFAULT_TERM_WIDTH, $height = SSH2_DEFAULT_TERM_WIDTH, $widthHeightType = SSH2_DEFAULT_TERM_UNIT)
 {
     if (!$client->isAlive()) {
         throw new \Exception('Client is not connected');
     }
     $this->client = $client;
     $this->stream = @ssh2_shell($client->getConnection(), $term_type, $env, $width, $height, $widthHeightType);
     if (!$this->stream) {
         throw new \Exception('Can not get shell');
     }
     stream_set_blocking($this->stream, true);
     usleep(500000);
     $read = fread($this->stream, 8192);
     $lines = preg_split('/\\r?\\n/', $read);
     $end = $lines[count($lines) - 1];
     if (!preg_match(sprintf("/%s@/", $client->getUser()), $end)) {
         throw new \RuntimeException('Can not find terminal command line label');
     }
     $this->hostName = $this->exec('hostname');
     if (!preg_match(sprintf('/%s@%s/', $client->getUser(), $this->hostName), $end)) {
         throw new \RuntimeException('Can not find terminal command line label');
     }
     $this->commandLineLabel = $client->getUser() . '@' . $this->hostName;
     $this->fetchErrorStream();
 }
示例#3
0
文件: PublicKey.php 项目: oncesk/ssh2
 /**
  * @param Client $client
  *
  * @throws \RuntimeException
  *
  * @return mixed
  */
 public function authenticate(Client $client)
 {
     if (!@ssh2_auth_pubkey_file($client->getConnection(), $this->getUser(), $this->pubKeyFile, $this->privateKeyFile, $this->passphrase)) {
         throw new \RuntimeException('Authentication Failed');
     }
     parent::authenticate($client);
 }
示例#4
0
文件: Auth.php 项目: oncesk/ssh2
 /**
  * @param Client $client
  *
  * @return bool
  */
 public function isAuthenticated(Client $client)
 {
     return isset($this->authenticated[(int) $client->getConnection()]);
 }