コード例 #1
0
ファイル: PasswordCredentialTest.php プロジェクト: bravo3/ssh
 /**
  * @group server
  * @medium
  */
 public function testPasswordAuthentication()
 {
     $connection = new Connection(\properties::$host, \properties::$port, new PasswordCredential(\properties::$user, \properties::$pass));
     $this->assertTrue($connection->connect());
     $this->assertTrue($connection->authenticate());
     $this->assertTrue($connection->isAuthenticated());
     $connection->disconnect();
 }
コード例 #2
0
ファイル: PublicKeyTest.php プロジェクト: bravo3/ssh
 /**
  * @dataProvider keyFileProvider
  * @group server
  * @medium
  */
 public function testNoPublicKey($public, $private, $password)
 {
     $credential = new KeyCredential(\properties::$user, null, $private, $password);
     $connection = new Connection(\properties::$host, \properties::$port, $credential);
     $this->assertTrue($connection->connect());
     $this->assertTrue($connection->authenticate());
     $this->assertTrue($connection->isAuthenticated());
     $connection->disconnect();
 }
コード例 #3
0
ファイル: Shell.php プロジェクト: 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());
 }
コード例 #4
0
ファイル: ExecutionStream.php プロジェクト: bravo3/ssh
 /**
  * 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());
 }
コード例 #5
0
ファイル: ConnectionTest.php プロジェクト: bravo3/ssh
 /**
  * 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());
 }