Changeset 8865
- Timestamp:
- 09/11/2008 05:44:43 PM (16 years ago)
- Location:
- trunk/wp-admin/includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-filesystem-ssh2.php
r8852 r8865 42 42 class WP_Filesystem_SSH2 extends WP_Filesystem_Base { 43 43 44 var $debugtest = false; // this is my var that will output the text when debuggin this class44 var $debugtest = false; // set this to true only if your a debuging your connection 45 45 46 46 var $link = null; 47 47 var $sftp_link = null; 48 var $keys = false; 48 49 /* 49 50 * This is the timeout value for ssh results to comeback. … … 89 90 $this->options['username'] = $opt['username']; 90 91 92 if (( !empty ($opt['public_key']) ) && ( !empty ($opt['private_key']) )) { 93 $this->options['public_key'] = $opt['public_key']; 94 $this->options['private_key'] = $opt['private_key']; 95 96 $this->options['hostkey'] = array("hostkey" => "ssh-rsa"); 97 98 $this->keys = true; 99 } 100 101 91 102 if ( empty ($opt['password']) ) 92 $this->errors->add('empty_password', __('SSH2 password is required')); 103 if ( !$this->keys ) // password can be blank if we are using keys 104 $this->errors->add('empty_password', __('SSH2 password is required')); 93 105 else 94 106 $this->options['password'] = $opt['password']; 107 95 108 } 96 109 97 110 function connect() { 98 111 $this->debug("connect();"); 99 $this->link = @ssh2_connect($this->options['hostname'], $this->options['port']); 100 112 if ( ! $this->keys ) 113 $this->link = @ssh2_connect($this->options['hostname'], $this->options['port']); 114 else 115 $this->link = @ssh2_connect($this->options['hostname'], $this->options['port'], $this->options['hostkey']); 116 101 117 if ( ! $this->link ) { 102 118 $this->errors->add('connect', sprintf(__('Failed to connect to SSH2 Server %1$s:%2$s'), $this->options['hostname'], $this->options['port'])); … … 104 120 } 105 121 106 if ( ! @ssh2_auth_password($this->link,$this->options['username'], $this->options['password']) ) { 107 $this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username'])); 108 return false; 122 if ( !$this->keys ) { 123 if ( ! @ssh2_auth_password($this->link, $this->options['username'], $this->options['password']) ) { 124 $this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username'])); 125 return false; 126 } 127 } else { 128 if ( ! @ssh2_auth_pubkey_file($this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'], $this->options['password'] ) ) { 129 $this->errors->add('auth', sprintf(__('Public and Private keys incorrent for %s'), $this->options['username'])); 130 return false; 131 } 109 132 } 110 133 … … 115 138 116 139 function run_command($link, $command, $returnbool = false) { 117 //$this->debug("run_command(".$command.",".$returnbool.");");140 $this->debug("run_command();"); 118 141 if(!($stream = @ssh2_exec( $link, $command . "; echo \"__COMMAND_FINISHED__\";"))) { 119 142 $this->errors->add('command', sprintf(__('Unable to perform command: %s'), $command)); … … 137 160 fclose($stream); 138 161 $data = str_replace("__COMMAND_FINISHED__", "", $data); 139 //$this->debug("run_command(".$command."); --> \$data = " . $data);140 162 if (($returnbool) && ( (int) $data )) { 141 $this->debug("Data. Returning: True");142 163 return true; 143 164 } elseif (($returnbool) && (! (int) $data )) { 144 $this->debug("Data. Returning: False");145 165 return false; 146 166 } else { 147 $this->debug("Data Only.");148 167 return $data; 149 168 } … … 167 186 168 187 function get_contents($file, $type = '', $resumepos = 0 ) { 188 $this->debug("get_contents();"); 169 189 $tempfile = wp_tempnam( $file ); 170 190 if ( ! $tempfile ) … … 183 203 184 204 function put_contents($file, $contents, $type = '' ) { 205 $this->debug("put_contents();"); 185 206 $tempfile = wp_tempnam( $file ); 186 207 $temp = fopen($tempfile, 'w'); … … 195 216 196 217 function cwd() { 218 $this->debug("cwd();"); 197 219 $cwd = $this->run_command($this->link, 'pwd'); 198 220 if( $cwd ) … … 202 224 203 225 function chdir($dir) { 226 $this->debug("chdir();"); 204 227 return $this->run_command($this->link, 'cd ' . $dir, true); 205 228 } … … 270 293 271 294 function delete($file, $recursive = false) { 295 $this->debug("delete();"); 272 296 if ( $this->is_file($file) ) 273 297 return ssh2_sftp_unlink($this->sftp_link, $file); … … 284 308 285 309 function exists($file) { 310 $this->debug("exists();"); 286 311 $list = $this->run_command($this->link, sprintf('ls -lad %s', $file)); 287 312 return (bool) $list; … … 289 314 290 315 function is_file($file) { 316 $this->debug("is_file();"); 291 317 //DO NOT RELY ON dirlist()! 292 318 $list = $this->run_command($this->link, sprintf('ls -lad %s', $file)); … … 299 325 300 326 function is_dir($path) { 327 $this->debug("is_dir();"); 301 328 //DO NOT RELY ON dirlist()! 302 329 $list = $this->parselisting($this->run_command($this->link, sprintf('ls -lad %s', rtrim($path, '/')))); … … 330 357 //Not implmented. 331 358 } 332 359 333 360 function mkdir($path, $chmod = null, $chown = false, $chgrp = false) { 361 $this->debug("mkdir();"); 362 $path = trim($path, '/'); 334 363 if( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) ) 335 364 return false; … … 342 371 343 372 function rmdir($path, $recursive = false) { 373 $this->debug("rmdir();"); 344 374 return $this->delete($path, $recursive); 345 375 } … … 464 494 return $ret; 465 495 } 466 467 function __destruct(){496 function __destruct() { 497 $this->debug("__destruct();"); 468 498 if ( $this->link ) 469 499 unset($this->link); -
trunk/wp-admin/includes/file.php
r8852 r8865 406 406 $tmppath = $to . implode('/', array_slice($path, 0, $i) ); 407 407 if ( $fs->is_dir($tmppath) ) {//Found the highest folder that exists, Create from here 408 for ( $i = $i + 1; $i < count($path); $i++ ) { //< count() no file component please.408 for ( $i = $i + 1; $i <= count($path); $i++ ) { //< count() no file component please. 409 409 $tmppath = $to . implode('/', array_slice($path, 0, $i) ); 410 410 if ( ! $fs->mkdir($tmppath, 0755) ) … … 511 511 $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? $_POST['password'] : $credentials['password']); 512 512 513 // Check to see if we are setting the public/private keys for ssh 514 $credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($_POST['public_key']) ? $_POST['public_key'] : $credentials['public_key']); 515 $credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($_POST['private_key']) ? $_POST['private_key'] : $credentials['private_key']); 516 513 517 if ( strpos($credentials['hostname'], ':') ) 514 518 list( $credentials['hostname'], $credentials['port'] ) = explode(':', $credentials['hostname'], 2); … … 523 527 if ( ! $error && !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) { 524 528 $stored_credentials = $credentials; 525 unset($stored_credentials['password'] );529 unset($stored_credentials['password'], $stored_credentials['private_key'], $stored_credentials['public_key']); 526 530 update_option('ftp_credentials', $stored_credentials); 527 531 return $credentials; … … 540 544 } 541 545 ?> 546 <script type="text/javascript"> 547 <!-- 548 jQuery(function($){ 549 jQuery("#ssh").click(function () { 550 jQuery("#ssh_keys").show(); 551 }); 552 jQuery("#ftp").click(function () { 553 jQuery("#ssh_keys").hide(); 554 }); 555 jQuery("#ftps").click(function () { 556 jQuery("#ssh_keys").hide(); 557 }); 558 jQuery(document).ready(function(){ 559 if ( jQuery("#ssh:checked").length ) 560 { 561 jQuery("#ssh_keys").show(); 562 } 563 }); 564 }); 565 --> 566 </script> 542 567 <form action="<?php echo $form_post ?>" method="post"> 543 568 <div class="wrap"> … … 557 582 <td><input name="password" type="password" id="password" value=""<?php if( defined('FTP_PASS') ) echo ' disabled="disabled"' ?> size="40" /><?php if( defined('FTP_PASS') && !empty($password) ) echo '<em>'.__('(Password not shown)').'</em>'; ?></td> 558 583 </tr> 584 <tr id="ssh_keys" valign="top" style="display:none"> 585 <th scope="row"><label id="keys" for="keys"><?php _e('Authentication Keys') ?></label></th> 586 <td><label for="public_key"><?php _e('Public Key:') ?></label ><input name="public_key" type="text" id="public_key" value=""<?php if( defined('FTP_PUBKEY') ) echo ' disabled="disabled"' ?> size="40" /> <label for="private_key"><?php _e('Private Key:') ?></label> <input name="private_key" type="text" id="private_key" value=""<?php if( defined('FTP_PRIKEY') ) echo ' disabled="disabled"' ?> size="40" /><br/><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> 587 </tr> 559 588 <tr valign="top"> 560 589 <th scope="row"><?php _e('Connection Type') ?></th> 561 590 <td> 562 591 <fieldset><legend class="hidden"><?php _e('Connection Type') ?> </legend> 563 <p><label><input name="connection_type" type="radio" value="ftp" <?php checked('ftp', $connection_type); ?> /> <?php _e('FTP') ?></label><br />564 <label><input name="connection_type" type="radio" value="ftps" <?php checked('ftps', $connection_type); ?> /> <?php _e('FTPS (SSL)') ?></label><br />565 <?php if ( extension_loaded('ssh2') ) { ?><label><input name="connection_type" type="radio" value="ssh" <?php checked('ssh', $connection_type); ?> /> <?php _e('SSH') ?></label><?php } ?></p>592 <p><label><input id="ftp" name="connection_type" type="radio" value="ftp" <?php checked('ftp', $connection_type); ?> /> <?php _e('FTP') ?></label><br /> 593 <label><input id="ftps" name="connection_type" type="radio" value="ftps" <?php checked('ftps', $connection_type); ?> /> <?php _e('FTPS (SSL)') ?></label><br /> 594 <?php if ( extension_loaded('ssh2') ) { ?><label><input id="ssh" name="connection_type" type="radio" value="ssh" <?php checked('ssh', $connection_type); ?> /> <?php _e('SSH') ?></label><?php } ?></p> 566 595 </fieldset> 567 596 </td>
Note: See TracChangeset
for help on using the changeset viewer.