Advertisement
Guest User

Untitled

a guest
Jan 19th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2.     namespace bc_utils;
  3.  
  4.     class ssh {
  5.  
  6.         protected $conn;
  7.  
  8.         // constructor
  9.         public function __construct($host, authentication $auth, $port = 22) {
  10.             $this -> conn = ssh2_connect($host, $port);
  11.  
  12.             switch(get_class($auth)) {
  13.                 case "password":
  14.                     $username = $auth -> get_username();
  15.                     $password = $auth -> get_password();
  16.                     if (ssh2_auth_password($this -> conn, $username, $password) === false) {
  17.                         throw new Exception("SSH2 login is invalid");
  18.                     }
  19.                     break;
  20.  
  21.                 case "key":
  22.                     $username    = $auth -> get_username();
  23.                     $public_key  = $auth -> get_public_key();
  24.                     $private_key = $auth -> get_private_key();
  25.  
  26.                     if (ssh2_auth_pubkey_file($this -> conn, $username, $public_key, $private_key) === false) {
  27.                         throw new Exception("SSH2 login is invalid");
  28.                     }
  29.                     break;
  30.  
  31.                 default:
  32.                     throw new Exception("Unknown SSH2 login type");
  33.                     break;
  34.             }
  35.         }
  36.     }
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement