コード例 #1
0
ファイル: SFTP.php プロジェクト: msulistijo/PhpseclibBundle
 /**
  * Disconnect
  *
  * @param int $reason
  * @return bool
  * @access private
  */
 function _disconnect($reason)
 {
     $this->pwd = false;
     parent::_disconnect($reason);
 }
コード例 #2
0
ファイル: Stream.php プロジェクト: msulistijo/PhpseclibBundle
 /**
  * Path Parser
  *
  * Extract a path from a URI and actually connect to an SSH server if appropriate
  *
  * If "notification" is set as a context parameter the message code for successful login is
  * NET_SSH2_MSG_USERAUTH_SUCCESS. For a failed login it's NET_SSH2_MSG_USERAUTH_FAILURE.
  *
  * @param string $path
  * @return string
  * @access private
  */
 function _parse_path($path)
 {
     extract(parse_url($path) + array('port' => 22));
     if (!isset($host)) {
         return false;
     }
     if (isset($this->context)) {
         $context = stream_context_get_params($this->context);
         if (isset($context['notification'])) {
             $this->notification = $context['notification'];
         }
     }
     if (preg_match('/^{[a-z0-9]+}$/i', $host)) {
         $host = SSH2::getConnectionByResourceId($host);
         if ($host === false) {
             return false;
         }
         $this->sftp = $host;
     } else {
         if (isset($this->context)) {
             $context = stream_context_get_options($this->context);
         }
         if (isset($context[$scheme]['session'])) {
             $sftp = $context[$scheme]['session'];
         }
         if (isset($context[$scheme]['sftp'])) {
             $sftp = $context[$scheme]['sftp'];
         }
         if (isset($sftp) && $sftp instanceof SFTP) {
             $this->sftp = $sftp;
             return $path;
         }
         if (isset($context[$scheme]['username'])) {
             $user = $context[$scheme]['username'];
         }
         if (isset($context[$scheme]['password'])) {
             $pass = $context[$scheme]['password'];
         }
         if (isset($context[$scheme]['privkey']) && $context[$scheme]['privkey'] instanceof RSA) {
             $pass = $context[$scheme]['privkey'];
         }
         if (!isset($user) || !isset($pass)) {
             return false;
         }
         // casting $pass to a string is necessary in the event that it's a \phpseclib\Crypt\RSA object
         if (isset(self::$instances[$host][$port][$user][(string) $pass])) {
             $this->sftp = self::$instances[$host][$port][$user][(string) $pass];
         } else {
             $this->sftp = new SFTP($host, $port);
             $this->sftp->disableStatCache();
             if (isset($this->notification) && is_callable($this->notification)) {
                 /* if !is_callable($this->notification) we could do this:
                 
                                        user_error('fopen(): failed to call user notifier', E_USER_WARNING);
                 
                                        the ftp wrapper gives errors like that when the notifier isn't callable.
                                        i've opted not to do that, however, since the ftp wrapper gives the line
                                        on which the fopen occurred as the line number - not the line that the
                                        user_error is on.
                                     */
                 call_user_func($this->notification, STREAM_NOTIFY_CONNECT, STREAM_NOTIFY_SEVERITY_INFO, '', 0, 0, 0);
                 call_user_func($this->notification, STREAM_NOTIFY_AUTH_REQUIRED, STREAM_NOTIFY_SEVERITY_INFO, '', 0, 0, 0);
                 if (!$this->sftp->login($user, $pass)) {
                     call_user_func($this->notification, STREAM_NOTIFY_AUTH_RESULT, STREAM_NOTIFY_SEVERITY_ERR, 'Login Failure', NET_SSH2_MSG_USERAUTH_FAILURE, 0, 0);
                     return false;
                 }
                 call_user_func($this->notification, STREAM_NOTIFY_AUTH_RESULT, STREAM_NOTIFY_SEVERITY_INFO, 'Login Success', NET_SSH2_MSG_USERAUTH_SUCCESS, 0, 0);
             } else {
                 if (!$this->sftp->login($user, $pass)) {
                     return false;
                 }
             }
             self::$instances[$host][$port][$user][(string) $pass] = $this->sftp;
         }
     }
     return $path;
 }