Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. <?php
  2. ////////////////////////////
  3. // Made by Filipe Fernandes
  4. // v0.1
  5. ////////////////////////////
  6.  
  7. class ssh2 {
  8.     private $host = "host";
  9.     private $user = "root";
  10.     private $pass = "ehsegredonaodigasaninguem";
  11.     Private $port = "22";
  12.     var $conn;
  13.     var $error;
  14.     var $stream;
  15.    
  16.    
  17.     function login() {
  18.         if ($this->connect()) {
  19.             if ($this->auth()) {return 1;}
  20.             else {return 0;}
  21.         }
  22.         else {return 0;}
  23.     }
  24.    
  25.     function connect() {
  26.         if ($this->conn=ssh2_connet($this->host, $this->port)) { return 1; }
  27.         else
  28.             { echo "erro"; $this->error=" Cannot connect to host "; return 0; }
  29.     }
  30.    
  31.     function auth() {
  32.         if (@ssh2_auth_password($this->conn, $this->user, $this->pass)) {return 1;}
  33.         else {$this->error="invalid login"; return 0; }
  34.     }
  35.    
  36.     function cmd($cmd) {
  37.         $this->stream=ssh2_exec($this->conn, $cmd);
  38.         stream_set_blocking($this->stream, true);
  39.     }
  40.    
  41.     function output() {
  42.         while ($get=fgets($this->stream)) {
  43.               $line.=$get;
  44.         }
  45.         return $line;
  46.         }
  47. }
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement