当前位置: 首页>>代码示例>>PHP>>正文


PHP ssh2_auth_password函数代码示例

本文整理汇总了PHP中ssh2_auth_password函数的典型用法代码示例。如果您正苦于以下问题:PHP ssh2_auth_password函数的具体用法?PHP ssh2_auth_password怎么用?PHP ssh2_auth_password使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ssh2_auth_password函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sshiconn

function sshiconn($cmd, $pass, $ip, $sshp = 22)
{
    $ip = $_REQUEST['ip'];
    $pass = $_REQUEST['pass'];
    $sshp = $_REQUEST['sshp'];
    if (!isset($_REQUEST['sshp'])) {
        $sshp = '22';
    }
    $connection = ssh2_connect($ip, $sshp);
    if (!$connection) {
        throw new Exception("fail: unable to establish connection\nPlease IP or if server is on and connected");
    }
    $pass_success = ssh2_auth_password($connection, 'root', $pass);
    if (!$pass_success) {
        throw new Exception("fail: unable to establish connection\nPlease Check your password");
    }
    $stream = ssh2_exec($connection, $cmd);
    $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
    stream_set_blocking($errorStream, true);
    stream_set_blocking($stream, true);
    print_r($cmd);
    $output = stream_get_contents($stream);
    fclose($stream);
    fclose($errorStream);
    ssh2_exec($connection, 'exit');
    unset($connection);
    return $output;
}
开发者ID:shadowhome,项目名称:synxb,代码行数:28,代码来源:functions.php

示例2: Authenticate

 public function Authenticate($uid, $pass)
 {
     $this->AuthResult = false;
     // Connect
     $con = ssh2_connect($this->RemoteHost, $this->RemotePort);
     if ($con === false) {
         return ulLoginBackend::ERROR;
     }
     // Check fingerprint
     if ($this->RemoteFingerprint != '') {
         if (ssh2_fingerprint($con, SSH2_FINGERPRINT_SHA1 | SSH2_FINGERPRINT_HEX) != $this->RemoteFingerprint) {
             return ulLoginBackend::ERROR;
         }
     }
     // Test if server supports password-based authentication
     $auth_methods = ssh2_auth_none($con, 'user');
     if (!in_array('password', $auth_methods)) {
         return ulLoginBackend::ERROR;
     }
     // Connect again, because we can only try to authenticate once on a connection
     $con = ssh2_connect($this->RemoteHost, $this->RemotePort);
     if ($con === false) {
         return ulLoginBackend::ERROR;
     }
     // Try to authenticate
     if (ssh2_auth_password($con, $uid, $pass)) {
         $this->AuthResult = $uid;
         return true;
     } else {
         return ulLoginBackend::BAD_CREDENTIALS;
     }
 }
开发者ID:hoangsoft90,项目名称:cpanel-manager,代码行数:32,代码来源:Ssh2LoginBackend.inc.php

示例3: _connectandexecute

 function _connectandexecute($hostname, $port, $fingerprint, $user, $pass, $command)
 {
     // connect via ssh2
     $ssh = ssh2_connect($hostname, $port);
     if (!$ssh) {
         die("connection failed!");
     }
     $theirfingerprint = ssh2_fingerprint($ssh, SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX);
     if (strtoupper($theirfingerprint) != strtoupper($fingerprint)) {
         die("fingerprint mismatch!");
     }
     if (!ssh2_auth_password($ssh, $user, $pass)) {
         die("authentication failed!");
     }
     // shell, as Brocade really doesn't seem to like exec
     if (!($sock = ssh2_shell($ssh, 'vt102', null, 80, 40, SSH2_TERM_UNIT_CHARS))) {
         die("failed to establish shell!\n");
     }
     fwrite($sock, "terminal length 0" . PHP_EOL);
     fwrite($sock, $command . PHP_EOL);
     sleep(1);
     // seems to be a magic trick...
     stream_set_blocking($sock, true);
     $data = "";
     while ($buf = fread($sock, 4096)) {
         flush();
         if (preg_match('/SSH@.+#$/', $buf)) {
             break;
         }
         $data .= $buf;
     }
     fclose($sock);
     return $data;
 }
开发者ID:klaver,项目名称:peerlist,代码行数:34,代码来源:brocadessh.class.php

示例4: connect

 public function connect()
 {
     $methods = array();
     if ($this->use_pubkey_file_) {
         $methods['hostkey'] = 'ssh-rsa';
     }
     $conn = ssh2_connect($this->conf_['host'], $this->conf_['port'], $methods);
     if (false === $conn) {
         $this->setErr_(-1, sprintf('failed to connect [%s:%d]', $this->conf_['host'], $this->conf_['port']));
         return false;
     }
     if ($this->use_pubkey_file_) {
         $rc = ssh2_auth_pubkey_file($conn, $this->conf_['user'], $this->conf_['pubkey_file'], $this->conf_['privkey_file'], isset($this->conf_['passphrase']) ? $this->conf_['passphrase'] : NULL);
         if (false === $rc) {
             $this->setErr_(-1, sprintf('failed to auth with[%s:%s,%s,%s]', $this->conf_['user'], $this->conf_['pubkey_file'], $this->conf_['privkey_file'], $this->conf_['passphrase']));
             return false;
         }
     } else {
         $rc = ssh2_auth_password($conn, $this->conf_['user'], $this->conf_['passwd']);
         if (false === $rc) {
             $this->setErr_(-1, sprintf('failed to auth with[%s:%s]', $this->conf_['user'], $this->conf_['passwd']));
             return false;
         }
     }
     $this->conn_ = $conn;
     return true;
 }
开发者ID:nicevoice,项目名称:yhtx,代码行数:27,代码来源:Sftp.php

示例5: authenticate

 public function authenticate($resource)
 {
     if (!is_resource($resource)) {
         throw new \Exception("Invalid SSH resource!");
     }
     return ssh2_auth_password($resource, $this->username, $this->password);
 }
开发者ID:weelrs8,项目名称:ssh,代码行数:7,代码来源:Password.php

示例6: connect

 /**
  * Connect operation
  */
 public function connect()
 {
     if ($this->_ssh2 != null) {
         // Already connected
         return;
     }
     // Connect to server
     $host = isset($this->_config['hostname']) ? $this->_config['hostname'] : 'localhost';
     $port = isset($this->_config['port']) ? $this->_config['port'] : 22;
     $username = isset($this->_config['username']) ? $this->_config['username'] : '';
     $password = isset($this->_config['password']) ? $this->_config['password'] : null;
     $this->_ssh2 = ssh2_connect($host, $port);
     if ($this->_ssh2 === FALSE) {
         throw new Kohana_Transfer_Exception(Kohana::message('transfer', 'fail_open_connection'), array(':host' => $host, 'port' => $port));
     }
     // Check fingerprint if it is specified
     if (isset($this->_config['fingerprint'])) {
         if (strtolower(ssh2_fingerprint($this->_ssh2)) != strtolower($this->_config['fingerprint'])) {
             throw new Kohana_Transfer_Exception(Kohana::message('transfer', 'fail_fingerprint_validation'), array(':key' => ssh2_fingerprint($this->_ssh2)));
         }
     }
     // Connect with certificate if it is specified
     if (isset($this->_config['pubkeyfile']) and isset($this->_config['privkeyfile'])) {
         if (!@ssh2_auth_pubkey_file($this->_ssh2, $username, $this->_config['pubkeyfile'], $this->_config['privkeyfile'], $password)) {
             throw new Kohana_Transfer_Exception(Kohana::message('transfer', 'fail_authentication'));
         }
     } else {
         if (!@ssh2_auth_password($this->_ssh2, $username, $password)) {
             throw new Kohana_Transfer_Exception(Kohana::message('transfer', 'fail_authentication'));
         }
     }
     // Enable SFTP mode
     $this->_sftp = ssh2_sftp($this->_ssh2);
 }
开发者ID:rpringle,项目名称:transfer,代码行数:37,代码来源:sftp.php

示例7: handle

 public function handle()
 {
     /**
      * Estamblish SSH connection,
      * put site under maintenance,
      * pull chamges from git,
      * install composer dependencies,
      * execute migrations,
      * put site online
      */
     $remote = config('pckg.framework.' . DeployProject::class . '.remotes.default');
     $path = $remote['root'];
     $commands = ['cd ' . $path => 'Changing root directory', 'php ' . $path . 'console project:down' => 'Putting project offline', 'php ' . $path . 'console project:pull' => 'Executing project:pull', 'php ' . $path . 'console migrator:install' => 'Installing migrations', 'php ' . $path . 'console project:up' => 'Putting project up', 'php ' . $path . 'console cache:clear' => 'Clearing cache'];
     $this->output('Estamblishing SSH connection.');
     $sshConnection = ssh2_connect($remote['host'], $remote['port']);
     $this->output('SSH connection estamblished.');
     /**
      * Authenticate.
      */
     if (!ssh2_auth_password($sshConnection, $remote['username'], $remote['password'])) {
         throw new Exception('Cannot estamblish SSH connection to remote');
     }
     foreach ($commands as $command => $notice) {
         $this->output($notice);
         $stream = ssh2_exec($sshConnection, $command);
         $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
         stream_set_blocking($errorStream, true);
         stream_set_blocking($stream, true);
         $errorStreamContent = stream_get_contents($errorStream);
         $streamContent = stream_get_contents($stream);
         $this->output($errorStreamContent . "\n" . $streamContent);
     }
     $this->output('Done!');
 }
开发者ID:pckg,项目名称:framework,代码行数:34,代码来源:DeployProject.php

示例8: getSFTPList

 function getSFTPList()
 {
     $ftp_info = Context::getRequestVars();
     if (!$ftp_info->ftp_host) {
         $ftp_info->ftp_host = "127.0.0.1";
     }
     $connection = ssh2_connect($ftp_info->ftp_host, $ftp_info->ftp_port);
     if (!ssh2_auth_password($connection, $ftp_info->ftp_user, $ftp_info->ftp_password)) {
         return new Object(-1, 'msg_ftp_invalid_auth_info');
     }
     $sftp = ssh2_sftp($connection);
     $curpwd = "ssh2.sftp://{$sftp}" . $this->pwd;
     $dh = @opendir($curpwd);
     if (!$dh) {
         return new Object(-1, 'msg_ftp_invalid_path');
     }
     $list = array();
     while (($file = readdir($dh)) !== false) {
         if (!is_dir($curpwd . $file)) {
             continue;
         }
         $list[] = $file . "/";
     }
     closedir($dh);
     $this->add('list', $list);
 }
开发者ID:rhymix,项目名称:rhymix,代码行数:26,代码来源:install.model.php

示例9: coneccionSshImg

 function coneccionSshImg($ids, $mBanner, $config)
 {
     $porciones = explode(",", $ids);
     foreach ($porciones as $value) {
         $dataBanner = $mBanner->select($value);
         $avanzado = ROOT_IMG_DINAMIC . '/banner/avanzado/' . $dataBanner["ImgAvanzado"];
         $basico128 = ROOT_IMG_DINAMIC . '/banner/basico128/' . $dataBanner["ImgBasico128"];
         $basico240 = ROOT_IMG_DINAMIC . '/banner/basico240/' . $dataBanner["ImgBasico240"];
         $basico360 = ROOT_IMG_DINAMIC . '/banner/basico360/' . $dataBanner["ImgBasico360"];
         if (!function_exists("ssh2_connect")) {
             die("function ssh2_connect doesn't exist");
         }
         if (!($con = ssh2_connect($config['app']['server'], $config['app']['puerto']))) {
             echo "fail: unable to establish connection\n";
         } else {
             if (!ssh2_auth_password($con, $config['app']['user'], $config['app']['pass'])) {
                 echo "fail: unable to authenticate\n";
             } else {
                 ssh2_scp_send($con, $avanzado, $config['app']['rutaImg'] . 'banner/avanzado/' . $dataBanner["ImgAvanzado"], 0644);
                 ssh2_scp_send($con, $basico128, $config['app']['rutaImg'] . 'banner/basico128/' . $dataBanner["ImgBasico128"], 0644);
                 ssh2_scp_send($con, $basico240, $config['app']['rutaImg'] . 'banner/basico240/' . $dataBanner["ImgBasico240"], 0644);
                 ssh2_scp_send($con, $basico360, $config['app']['rutaImg'] . 'banner/basico360/' . $dataBanner["ImgBasico360"], 0644);
             }
             ssh2_exec($con, 'exit');
         }
     }
     return;
 }
开发者ID:josmel,项目名称:movistar,代码行数:28,代码来源:SetBannerGroup.php

示例10: __construct

 function __construct($cfg)
 {
     // set default options if missing
     static $defaults = array('port' => 22, 'user' => 'root');
     if (is_object($cfg)) {
         $cfg = json_decode(json_encode($cfg), 1);
     }
     foreach ($defaults as $k => $v) {
         if (!isset($cfg[$k])) {
             $cfg[$k] = $v;
         }
     }
     // connect ssh2
     $this->ssh2 = ssh2_connect($cfg['host'], $cfg['port']);
     if (!$this->ssh2) {
         throw new \Exception("can't connect trough ssh2\n");
     }
     // authorize
     if (isset($cfg['key'])) {
         // private/public key authentication requested
         if (!ssh2_auth_pubkey_file($this->ssh2, $cfg['user'], $cfg['key']['pub'], $cfg['key']['pvt'], isset($cfg['key']['pass']) ? $cfg['key']['pass'] : NULL)) {
             throw new \Exception("can't authorize via key");
         }
     } elseif (isset($cfg['pass'])) {
         // username & password authentication
         if (!ssh2_auth_password($this->ssh2, $cfg['user'], $cfg['pass'])) {
             throw new \Exception("can't authorize via user & pass");
         }
     } else {
         throw new \Exception("not enough authentication information provided");
     }
     $this->sftp = ssh2_sftp($this->ssh2);
 }
开发者ID:ngorchilov,项目名称:lgr,代码行数:33,代码来源:ssh2.class.php

示例11: get_list

function get_list($myhost, $usern, $passw, $mypath, &$data)
{
    if (!function_exists("ssh2_connect")) {
        die("function ssh2_connect doesn't exist");
    }
    if (!($conn = ssh2_connect($myhost, 22))) {
        echo "fail: unable to establish connection\n";
    } else {
        if (!ssh2_auth_password($conn, $usern, $passw)) {
            echo "fail: unable to authenticate\n";
        } else {
            if (!($stream = ssh2_exec($conn, "ls -1 " . $mypath))) {
                echo "fail: unable to execute command\n";
            } else {
                stream_set_blocking($stream, true);
                // allow command to finish
                $data = "";
                while ($buf = fread($stream, 4096)) {
                    $data .= $buf;
                }
                fclose($stream);
            }
        }
    }
    ssh2_exec($conn, 'exit');
}
开发者ID:AdamDS,项目名称:GenomeVIP,代码行数:26,代码来源:listfiles_real_json_key2.php

示例12: password

 function password($username, $password)
 {
     if ($this->ssh && is_resource($this->ssh)) {
         $this->auth = new AuthenticatedDetails(__FUNCTION__, array($username, $password));
         return ssh2_auth_password($this->ssh, $username, $password);
     }
 }
开发者ID:splitice,项目名称:radical-net,代码行数:7,代码来源:Authenticate.php

示例13: authenticate

 /**
  * @param Client $client
  * @throws \RuntimeException
  *
  * @return mixed
  */
 public function authenticate(Client $client)
 {
     if (!@ssh2_auth_password($client->getConnection(), $this->getUser(), $this->getPassword())) {
         throw new \RuntimeException('Authentication Failed');
     }
     parent::authenticate($client);
 }
开发者ID:oncesk,项目名称:ssh2,代码行数:13,代码来源:Password.php

示例14: authenticate

 /**
  * @param resource $resource
  * @throws \Exception
  */
 public function authenticate($resource)
 {
     if (!@ssh2_auth_password($resource, $this->username, $this->password)) {
         // @ prevent warning, on invalid authentication throws exception
         throw new \Exception("Authentication failed for user '{$this->username}' using public key: Username/Password combination invalid");
     }
 }
开发者ID:brabijan,项目名称:ssh,代码行数:11,代码来源:Password.php

示例15: authPassword

 public function authPassword($user, $password, $skiperror = false)
 {
     $this->user = $user;
     $this->password = $password;
     if ($this->lib == 'phpext') {
         try {
             $auth = @ssh2_auth_password($this->con, $this->user, $this->password);
         } catch (Exception $e) {
         }
         if (!$auth) {
             if ($skiperror) {
                 return false;
             }
             die("Authorization failed !");
         }
     } else {
         if (!$this->con->login($this->user, $this->password)) {
             if ($skiperror) {
                 return false;
             }
             die("Authorization failed !");
         }
     }
     return true;
 }
开发者ID:catding,项目名称:w3esxi,代码行数:25,代码来源:vmware_class.php


注:本文中的ssh2_auth_password函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。