From 6e78e3aaf4402ab4e2466ad6b2801680b4935170 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 12 Dec 2008 20:12:16 +0000 Subject: [PATCH] Reset port when saving credntials. Props dwenaus and DD32. fixes #8580 for trunk git-svn-id: http://svn.automattic.com/wordpress/trunk@10198 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/file.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index a68606719..cddfaa92f 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -667,8 +667,13 @@ function request_filesystem_credentials($form_post, $type = '', $error = false) $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']); + //sanitize the hostname, Some people might pass in odd-data: + $credentials['hostname'] = preg_replace('|\w+://|', '', $credentials['hostname']); //Strip any schemes off + if ( strpos($credentials['hostname'], ':') ) list( $credentials['hostname'], $credentials['port'] ) = explode(':', $credentials['hostname'], 2); + else + unset($credentials['port']); if ( defined('FTP_SSH') || (isset($_POST['connection_type']) && 'ssh' == $_POST['connection_type']) ) $credentials['connection_type'] = 'ssh'; @@ -679,7 +684,10 @@ 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'], $stored_credentials['private_key'], $stored_credentials['public_key']); + if ( !empty($stored_credentials['port']) ) //save port as part of hostname to simplify above code. + $stored_credentials['hostname'] .= ':' . $stored_credentials['port']; + + unset($stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key']); update_option('ftp_credentials', $stored_credentials); return $credentials; }