Handle ssh keys in ssf2 fs. Props ShaneF. see #7690

git-svn-id: https://develop.svn.wordpress.org/trunk@8865 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2008-09-11 17:44:43 +00:00
parent d4bc35cf9e
commit d25dc6aa54
2 changed files with 79 additions and 20 deletions

View File

@@ -405,7 +405,7 @@ function unzip_file($file, $to) {
for ( $i = count($path) - 1; $i >= 0; $i-- ) { //>=0 as the first element contains data, count()-1, as we do not want the file component
$tmppath = $to . implode('/', array_slice($path, 0, $i) );
if ( $fs->is_dir($tmppath) ) {//Found the highest folder that exists, Create from here
for ( $i = $i + 1; $i < count($path); $i++ ) { //< count() no file component please.
for ( $i = $i + 1; $i <= count($path); $i++ ) { //< count() no file component please.
$tmppath = $to . implode('/', array_slice($path, 0, $i) );
if ( ! $fs->mkdir($tmppath, 0755) )
return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath);
@@ -510,6 +510,10 @@ function request_filesystem_credentials($form_post, $type = '', $error = false)
$credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? $_POST['username'] : $credentials['username']);
$credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? $_POST['password'] : $credentials['password']);
// Check to see if we are setting the public/private keys for ssh
$credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($_POST['public_key']) ? $_POST['public_key'] : $credentials['public_key']);
$credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($_POST['private_key']) ? $_POST['private_key'] : $credentials['private_key']);
if ( strpos($credentials['hostname'], ':') )
list( $credentials['hostname'], $credentials['port'] ) = explode(':', $credentials['hostname'], 2);
@@ -522,7 +526,7 @@ function request_filesystem_credentials($form_post, $type = '', $error = false)
if ( ! $error && !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) {
$stored_credentials = $credentials;
unset($stored_credentials['password']);
unset($stored_credentials['password'], $stored_credentials['private_key'], $stored_credentials['public_key']);
update_option('ftp_credentials', $stored_credentials);
return $credentials;
}
@@ -539,6 +543,27 @@ function request_filesystem_credentials($form_post, $type = '', $error = false)
echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
}
?>
<script type="text/javascript">
<!--
jQuery(function($){
jQuery("#ssh").click(function () {
jQuery("#ssh_keys").show();
});
jQuery("#ftp").click(function () {
jQuery("#ssh_keys").hide();
});
jQuery("#ftps").click(function () {
jQuery("#ssh_keys").hide();
});
jQuery(document).ready(function(){
if ( jQuery("#ssh:checked").length )
{
jQuery("#ssh_keys").show();
}
});
});
-->
</script>
<form action="<?php echo $form_post ?>" method="post">
<div class="wrap">
<h2><?php _e('FTP Connection Information') ?></h2>
@@ -556,13 +581,17 @@ function request_filesystem_credentials($form_post, $type = '', $error = false)
<th scope="row"><label for="password"><?php _e('Password') ?></label></th>
<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>
</tr>
<tr id="ssh_keys" valign="top" style="display:none">
<th scope="row"><label id="keys" for="keys"><?php _e('Authentication Keys') ?></label></th>
<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>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Connection Type') ?></th>
<td>
<fieldset><legend class="hidden"><?php _e('Connection Type') ?> </legend>
<p><label><input name="connection_type" type="radio" value="ftp" <?php checked('ftp', $connection_type); ?> /> <?php _e('FTP') ?></label><br />
<label><input name="connection_type" type="radio" value="ftps" <?php checked('ftps', $connection_type); ?> /> <?php _e('FTPS (SSL)') ?></label><br />
<?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>
<p><label><input id="ftp" name="connection_type" type="radio" value="ftp" <?php checked('ftp', $connection_type); ?> /> <?php _e('FTP') ?></label><br />
<label><input id="ftps" name="connection_type" type="radio" value="ftps" <?php checked('ftps', $connection_type); ?> /> <?php _e('FTPS (SSL)') ?></label><br />
<?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>
</fieldset>
</td>
</tr>