Exemplo n.º 1
0
Arquivo: Shell.php Projeto: bravo3/ssh
 /**
  * Typically called from Connection::getShell()
  *
  * @param Connection $connection
  * @param Terminal   $terminal
  */
 function __construct(Connection $connection, Terminal $terminal)
 {
     if (!$connection->isConnected()) {
         throw new NotConnectedException();
     }
     if (!$connection->isAuthenticated()) {
         throw new NotAuthenticatedException();
     }
     $this->shell_type = null;
     $this->connection = $connection;
     $this->terminal = $terminal;
     $this->resource = ssh2_shell($connection->getResource(), $terminal->getTerminalType(), $terminal->getEnv(), $terminal->getWidth(), $terminal->getHeight(), $terminal->getDimensionUnitType());
 }
Exemplo n.º 2
0
 /**
  * Typically called from Connection::execute()
  *
  * @param string     $command
  * @param Connection $connection
  * @param Terminal   $terminal
  * @param string     $pty
  */
 function __construct($command, Connection $connection, Terminal $terminal, $pty = null)
 {
     $this->command = $command;
     $this->connection = $connection;
     $this->terminal = $terminal;
     if (!$connection->isConnected()) {
         throw new NotConnectedException();
     }
     if (!$connection->isAuthenticated()) {
         throw new NotAuthenticatedException();
     }
     $this->resource = ssh2_exec($connection->getResource(), $command, $pty, $terminal->getEnv(), $terminal->getWidth(), $terminal->getHeight(), $terminal->getDimensionUnitType());
 }
Exemplo n.º 3
0
 /**
  * Tests the connection procedure including checking fingerprint - requires working SSH server
  *
  * @group server
  * @medium
  */
 public function testConnection()
 {
     $logger = new Logger();
     $connection = new Connection(\properties::$host, \properties::$port);
     $connection->setLogger($logger);
     $this->assertTrue($connection->connect());
     $fp = $connection->getFingerprint();
     $this->assertEquals(32, strlen($fp));
     // 32 byte MD5 HEX encoded fingerprint
     $this->assertTrue($connection->checkFingerprint($fp));
     $this->assertFalse($connection->checkFingerprint(self::BAD_FINGERPRINT));
     $this->assertNotEmpty($connection->getResource());
     $this->assertFalse($connection->isAuthenticated());
     $connection->disconnect();
     $this->assertContains('Disconnected', $logger->getHistory());
 }