WordPress.org

Make WordPress Core

Ticket #8210: 8210-ssh-keys-test.diff

File 8210-ssh-keys-test.diff, 4.3 KB (added by DD32, 5 years ago)
  • wp-admin/includes/class-wp-filesystem-ssh2.php

     
    8484                        $this->wp_base = $opt['base']; 
    8585 
    8686                // Check if the options provided are OK. 
    87                 if ( empty ($opt['username']) ) 
    88                         $this->errors->add('empty_username', __('SSH2 username is required')); 
    89                 else 
    90                         $this->options['username'] = $opt['username']; 
    91  
    92                 if ( ( !empty ($opt['public_key']) ) && ( !empty ($opt['private_key']) ) ) { 
     87                if ( !empty ($opt['public_key']) && !empty ($opt['private_key']) ) { 
    9388                        $this->options['public_key'] = $opt['public_key']; 
    9489                        $this->options['private_key'] = $opt['private_key']; 
    9590 
    96                         $this->options['hostkey'] = array("hostkey" => "ssh-rsa"); 
     91                        $this->options['hostkey'] = array('hostkey' => 'ssh-rsa'); 
    9792 
    9893                        $this->keys = true; 
     94                } elseif ( empty ($opt['username']) ) { 
     95                        $this->errors->add('empty_username', __('SSH2 username is required')); 
    9996                } 
    10097 
     98                if ( !empty($opt['username']) ) 
     99                        $this->options['username'] = $opt['username']; 
    101100 
    102101                if ( empty ($opt['password']) ) { 
    103102                        if ( !$this->keys )     //       password can be blank if we are using keys 
     
    114113                if ( ! $this->keys ) { 
    115114                        $this->link = @ssh2_connect($this->options['hostname'], $this->options['port']); 
    116115                } else { 
    117                         $this->link = @ssh2_connect($this->options['hostname'], $this->options['port'], $this->options['hostkey']); 
     116                        $this->link = ssh2_connect($this->options['hostname'], $this->options['port'], $this->options['hostkey']); 
    118117                } 
    119118 
    120119                if ( ! $this->link ) { 
     
    128127                                return false; 
    129128                        } 
    130129                } else { 
    131                         if ( ! @ssh2_auth_pubkey_file($this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'], $this->options['password'] ) ) { 
     130                        if ( ! ssh2_auth_pubkey_file($this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'] ) ) { //, $this->options['password'] 
    132131                                $this->errors->add('auth', sprintf(__('Public and Private keys incorrent for %s'), $this->options['username'])); 
    133132                                return false; 
    134133                        } 
  • wp-admin/includes/file.php

     
    681681                $credentials['connection_type'] = 'ftps'; 
    682682        else if ( !isset($credentials['connection_type']) || (isset($_POST['connection_type']) && 'ftp' == $_POST['connection_type']) ) 
    683683                $credentials['connection_type'] = 'ftp'; 
    684  
    685         if ( ! $error && !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) { 
     684var_Dump($credentials); 
     685        if ( ! $error &&  
     686                        ( 
     687                                ( !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) || 
     688                                ( 'ssh' == $credentials['connection_type'] && !empty($credentials['public_key']) && !empty($credentials['private_key']) ) 
     689                        ) ) { 
    686690                $stored_credentials = $credentials; 
    687691                if ( !empty($stored_credentials['port']) ) //save port as part of hostname to simplify above code. 
    688692                        $stored_credentials['hostname'] .= ':' . $stored_credentials['port']; 
     
    743747<label for="public_key"><?php _e('Public Key:') ?></label ><br /> 
    744748<label for="private_key"><?php _e('Private Key:') ?></label> 
    745749</div></th> 
    746 <td><br /><input name="public_key" type="text" id="public_key" value=""<?php if( defined('FTP_PUBKEY') ) echo ' disabled="disabled"' ?> size="40" /><br /><input name="private_key" type="text" id="private_key" value=""<?php if( defined('FTP_PRIKEY') ) echo ' disabled="disabled"' ?> size="40" /> 
     750<td><br /><input name="public_key" type="text" id="public_key" value="<?php echo attribute_escape($public_key) ?>"<?php if( defined('FTP_PUBKEY') ) echo ' disabled="disabled"' ?> size="40" /><br /><input name="private_key" type="text" id="private_key" value="<?php echo attribute_escape($private_key) ?>"<?php if( defined('FTP_PRIKEY') ) echo ' disabled="disabled"' ?> size="40" /> 
    747751<div><?php _e('Enter the location on the server where the keys are located. If a passphrase is needed, enter that in the password field above.') ?></div></td> 
    748752</tr> 
    749753