123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- if (!DEFINED('EGP'))
- exit(header('Refresh: 0; URL=http://' . $_SERVER['SERVER_NAME'] . '/404'));
- class ssh
- {
- var $conn;
- var $stream;
- public function auth($passwd, $address)
- {
- if ($this->connect($address) and $this->auth_pwd('root', $passwd))
- return true;
- return false;
- }
- public function connect($address)
- {
- if (strpos($address, ':') !== false) {
- list($host, $port) = explode(':', $address);
- } else {
- $host = $address;
- $port = 22;
- }
- ini_set('default_socket_timeout', '3');
- if ($this->conn = ssh2_connect($host, $port)) {
- ini_set('default_socket_timeout', '180');
- return true;
- }
- return false;
- }
- public function setfile($localFile, $remoteFile, $permision)
- {
- if (@ssh2_scp_send($this->conn, $localFile, $remoteFile, $permision))
- return true;
- return false;
- }
- public function getfile($remoteFile, $localFile)
- {
- if (@ssh2_scp_recv($this->conn, $remoteFile, $localFile))
- return true;
- return false;
- }
- public function set($cmd)
- {
- $this->stream = ssh2_exec($this->conn, $cmd);
- stream_set_blocking($this->stream, true);
- }
- public function auth_pwd($u, $p)
- {
- if (@ssh2_auth_password($this->conn, $u, $p))
- return true;
- return false;
- }
- public function get($cmd = false)
- {
- if ($cmd) {
- $this->stream = ssh2_exec($this->conn, $cmd);
- stream_set_blocking($this->stream, true);
- }
- $line = '';
- while ($get = fgets($this->stream))
- $line .= $get;
- return $line;
- }
- public function esc()
- {
- if (function_exists('ssh2_disconnect'))
- ssh2_disconnect($this->conn);
- else {
- @fclose($this->conn);
- unset($this->conn);
- }
- return NULL;
- }
- }
- $ssh = new ssh;
- ?>
|