WordPress.org

Make WordPress Core

Changeset 11632


Ignore:
Timestamp:
06/23/09 21:54:53 (6 years ago)
Author:
ryan
Message:

Enforce stream_get_contents() requirement for ssh2 fs. Props dd32. fixes #10093 for trunk

Location:
trunk/wp-admin/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-filesystem-ssh2.php

    r11564 r11632  
    1414 * @contrib http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/ - Installation Notes 
    1515 * 
    16  * Complie libssh2 (Note: Only 0.14 is officaly working with PHP 5.2.6+ right now.) 
     16 * Complie libssh2 (Note: Only 0.14 is officaly working with PHP 5.2.6+ right now, But many users have found the latest versions work) 
    1717 * 
    1818 * cd /usr/src 
     
    2323 * make all install 
    2424 * 
    25  * Note: No not leave the directory yet! 
     25 * Note: Do not leave the directory yet! 
    2626 * 
    2727 * Enter: pecl install -f ssh2 
     
    3434 * Check phpinfo() streams to confirm that: ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp  exist. 
    3535 * 
     36 * Note: as of WordPress 2.8, This utilises the PHP5+ function 'stream_get_contents' 
    3637 * 
    3738 * @since 2.7 
     
    4647    var $keys = false; 
    4748    /* 
    48      * This is the timeout value for ssh results to comeback. 
     49     * This is the timeout value for ssh results. 
    4950     * Slower servers might need this incressed, but this number otherwise should not change. 
    5051     * 
     
    6768            return false; 
    6869        } 
    69         if ( ! version_compare(phpversion(), '5', '>=') ) { 
    70             $this->errors->add('ssh2_php_requirement', __('The ssh2 PHP extension is available, however requires PHP 5+')); 
     70        if ( !function_exists('stream_get_contents') ) { 
     71            $this->errors->add('ssh2_php_requirement', __('The ssh2 PHP extension is available, however, we require the PHP5 function <code>stream_get_contents()</code>')); 
    7172            return false; 
    7273        } 
     
    102103 
    103104        if ( empty ($opt['password']) ) { 
    104             if ( !$this->keys ) //   password can be blank if we are using keys 
     105            if ( !$this->keys ) //password can be blank if we are using keys 
    105106                $this->errors->add('empty_password', __('SSH2 password is required')); 
    106107        } else { 
     
    149150            stream_set_blocking( $stream, true ); 
    150151            stream_set_timeout( $stream, $this->timeout ); 
    151             $data = stream_get_contents($stream); 
     152            $data = stream_get_contents( $stream ); 
     153            fclose( $stream ); 
    152154 
    153155            if ( $returnbool ) 
    154                 return '' != trim($data); 
     156                return ( $data === false ) ? false : '' != trim($data); 
    155157            else 
    156158                return $data; 
     
    167169    function get_contents($file, $type = '', $resumepos = 0 ) { 
    168170        $file = ltrim($file, '/'); 
    169         return file_get_contents('ssh2.sftp://' . $this->sftp_link .'/' . $file); 
     171        return file_get_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file); 
    170172    } 
    171173 
    172174    function get_contents_array($file) { 
    173175        $file = ltrim($file, '/'); 
    174         return file('ssh2.sftp://' . $this->sftp_link .'/' . $file); 
     176        return file('ssh2.sftp://' . $this->sftp_link . '/' . $file); 
    175177    } 
    176178 
    177179    function put_contents($file, $contents, $type = '' ) { 
    178180        $file = ltrim($file, '/'); 
    179         return file_put_contents('ssh2.sftp://' . $this->sftp_link .'/' . $file, $contents); 
     181        return file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents); 
    180182    } 
    181183 
     
    271273 
    272274    function exists($file) { 
    273         //return $this->run_command(sprintf('ls -lad %s', escapeshellarg($file)), true); 
    274         $file = ltrim($file, '/'); 
    275         return file_exists('ssh2.sftp://' . $this->sftp_link .'/' . $file); 
     275        $file = ltrim($file, '/'); 
     276        return file_exists('ssh2.sftp://' . $this->sftp_link . '/' . $file); 
    276277    } 
    277278 
    278279    function is_file($file) { 
    279280        $file = ltrim($file, '/'); 
    280         return is_file('ssh2.sftp://' . $this->sftp_link .'/' . $file); 
     281        return is_file('ssh2.sftp://' . $this->sftp_link . '/' . $file); 
    281282    } 
    282283 
    283284    function is_dir($path) { 
    284285        $path = ltrim($path, '/'); 
    285         return is_dir('ssh2.sftp://' . $this->sftp_link .'/' . $path); 
     286        return is_dir('ssh2.sftp://' . $this->sftp_link . '/' . $path); 
    286287    } 
    287288 
    288289    function is_readable($file) { 
    289290        $file = ltrim($file, '/'); 
    290         return is_readable('ssh2.sftp://' . $this->sftp_link .'/' . $file); 
     291        return is_readable('ssh2.sftp://' . $this->sftp_link . '/' . $file); 
    291292    } 
    292293 
    293294    function is_writable($file) { 
    294295        $file = ltrim($file, '/'); 
    295         return is_writable('ssh2.sftp://' . $this->sftp_link .'/' . $file); 
     296        return is_writable('ssh2.sftp://' . $this->sftp_link . '/' . $file); 
    296297    } 
    297298 
    298299    function atime($file) { 
    299300        $file = ltrim($file, '/'); 
    300         return fileatime('ssh2.sftp://' . $this->sftp_link .'/' . $file); 
     301        return fileatime('ssh2.sftp://' . $this->sftp_link . '/' . $file); 
    301302    } 
    302303 
    303304    function mtime($file) { 
    304305        $file = ltrim($file, '/'); 
    305         return filemtime('ssh2.sftp://' . $this->sftp_link .'/' . $file); 
     306        return filemtime('ssh2.sftp://' . $this->sftp_link . '/' . $file); 
    306307    } 
    307308 
    308309    function size($file) { 
    309310        $file = ltrim($file, '/'); 
    310         return filesize('ssh2.sftp://' . $this->sftp_link .'/' . $file); 
     311        return filesize('ssh2.sftp://' . $this->sftp_link . '/' . $file); 
    311312    } 
    312313 
  • trunk/wp-admin/includes/file.php

    r11587 r11632  
    646646    } 
    647647 
    648     if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && extension_loaded('sockets') ) $method = 'ssh2'; 
     648    if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && function_exists('stream_get_contents') ) $method = 'ssh2'; 
    649649    if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext'; 
    650650    if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread 
     
    762762</tr> 
    763763 
    764 <?php if ( extension_loaded('ssh2') ) : ?> 
     764<?php if ( extension_loaded('ssh2') && function_exists('stream_get_contents') ) : ?> 
    765765<tr id="ssh_keys" valign="top" style="<?php if ( 'ssh' != $connection_type ) echo 'display:none' ?>"> 
    766766<th scope="row"><?php _e('Authentication Keys') ?> 
     
    782782<br /><label><input id="ftps" name="connection_type" type="radio" value="ftps" <?php checked('ftps', $connection_type); if ( defined('FTP_SSL') || defined('FTP_SSH') ) echo ' disabled="disabled"';  ?>/> <?php _e('FTPS (SSL)') ?></label> 
    783783<?php endif; ?> 
    784 <?php if ( extension_loaded('ssh2') ) : ?> 
     784<?php if ( extension_loaded('ssh2') && function_exists('stream_get_contents') ) : ?> 
    785785<br /><label><input id="ssh" name="connection_type" type="radio" value="ssh" <?php checked('ssh', $connection_type);  if ( defined('FTP_SSL') || defined('FTP_SSH') ) echo ' disabled="disabled"'; ?>/> <?php _e('SSH') ?></label> 
    786786<?php endif; ?> 
Note: See TracChangeset for help on using the changeset viewer.