Ticket #58541: class-wp-filesystem-ssh2.patch
File class-wp-filesystem-ssh2.patch, 3.8 KB (added by , 16 months ago) |
---|
-
.php
old new 70 70 return; 71 71 } 72 72 73 // Get what can be found in DB and/or wp-config.php 74 // This will set any KEY not found to '' 75 $ajaxURL = admin_url('admin-ajax.php'); 76 $credentials = request_filesystem_credentials($ajaxURL, 'ssh', false, ABSPATH ); 77 73 78 // Set defaults: 74 79 if ( empty( $opt['port'] ) ) { 75 80 $this->options['port'] = 22; … … 77 82 $this->options['port'] = $opt['port']; 78 83 } 79 84 85 // Fill ALL $this->options with data required for a proper connection 86 // If a $opt[key] is passed, use that 87 // If a $opt[key] is NOT passed, use $credentials[key] from above 88 // If both not found, raise error 89 90 // Check if hostname is OK 80 91 if ( empty( $opt['hostname'] ) ) { 81 $this->errors->add( 'empty_hostname', __( 'SSH2 hostname is required' ) ); 92 if ( ! empty ( $credentials['hostname'] ) ) { 93 // assign value found in the DB and/or wp-config.php 94 $this->options['hostname'] = $credentials['hostname']; 95 96 } else { 97 // create/raise an error 98 $this->errors->add( 'empty_hostname', __( 'SSH2 credentials (hostname) is required!' ) ); 99 $this->options['hostname'] = ''; 100 } 82 101 } else { 83 102 $this->options['hostname'] = $opt['hostname']; 84 103 } 85 104 86 // Check if the options provided are OK. 105 // Check if username is OK 106 // Needs to be done before the keys! 107 if ( empty( $opt['username'] ) ) { 108 if ( ! empty ( $credentials['username'] ) ) { 109 // assign value found in the DB and/or wp-config.php 110 $this->options['username'] = $credentials['username']; 111 } else { 112 // create/raise an error 113 $this->errors->add( 'empty_username', __( 'SSH2 credentials (username) is required!' ) ); 114 $this->options['username'] = ''; 115 } 116 } else { 117 $this->options['username'] = $opt['username']; 118 } 119 120 // Check if the key options provided are OK. 87 121 if ( ! empty( $opt['public_key'] ) && ! empty( $opt['private_key'] ) ) { 88 122 $this->options['public_key'] = $opt['public_key']; 89 123 $this->options['private_key'] = $opt['private_key']; 90 91 124 $this->options['hostkey'] = array( 'hostkey' => 'ssh-rsa,ssh-ed25519' ); 92 93 125 $this->keys = true; 94 } elseif ( empty( $opt['username'] ) ) { 95 $this->errors->add( 'empty_username', __( 'SSH2 username is required' ) ); 96 } 97 98 if ( ! empty( $opt['username'] ) ) { 99 $this->options['username'] = $opt['username']; 100 } 126 } else { 127 if ( ! empty( $credentials['public_key'] ) && ! empty ( $credentials['private_key'] ) ) { 128 $this->options['public_key'] = $credentials['public_key']; 129 $this->options['private_key'] = $credentials['private_key']; 130 $this->options['hostkey'] = array( 'hostkey' => 'ssh-rsa,ssh-ed25519' ); 131 $this->keys = true; 132 } elseif ( empty( $this->options['username'] ) ) { 133 $this->errors->add( 'empty_username', __( 'SSH2 credentials (username) is required when using SSH keys!' ) ); 134 } 135 } 101 136 137 // Check for password OK, only required when not using keys 102 138 if ( empty( $opt['password'] ) ) { 103 139 // Password can be blank if we are using keys. 104 140 if ( ! $this->keys ) { 105 $this->errors->add( 'empty_password', __( 'SSH2 password is required' ) ); 141 if ( ! empty ( $credentials['passwrod'] ) ) { 142 // assign value found in the DB and/or wp-config.php 143 $this->options['password'] = $credentials['password']; 144 } else { 145 // create/raise an error 146 $this->errors->add( 'empty_password', __( 'SSH2 credentials (password) is required when not using SSH keys!' ) ); 147 $this->options['password'] = ''; 148 } 106 149 } 107 150 } else { 108 151 $this->options['password'] = $opt['password']; 109 152 } 153 110 154 } 111 155 112 156 /**