aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorJim Wigginton <terrafrost@phpbb.com>2009-07-12 15:44:43 +0000
committerJim Wigginton <terrafrost@phpbb.com>2009-07-12 15:44:43 +0000
commit7909b729bbb1facce975b10da28754eb157723aa (patch)
tree1301cfee49fa963d06526b430ff1a7b2a572566e /phpBB/includes
parent2839f3a964d214b9c2741f047cf69f1f48662462 (diff)
downloadforums-7909b729bbb1facce975b10da28754eb157723aa.tar
forums-7909b729bbb1facce975b10da28754eb157723aa.tar.gz
forums-7909b729bbb1facce975b10da28754eb157723aa.tar.bz2
forums-7909b729bbb1facce975b10da28754eb157723aa.tar.xz
forums-7909b729bbb1facce975b10da28754eb157723aa.zip
unified the transfer routines from the updater and from acp_language.php. still needs work..
git-svn-id: file:///svn/phpbb/trunk@9751 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/functions_admin.php264
-rw-r--r--phpBB/includes/functions_transfer.php6
2 files changed, 267 insertions, 3 deletions
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 884c5526c4..dee0f82566 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -2984,4 +2984,268 @@ function add_permission_language()
return true;
}
+/**
+* Upload files or let the user download them as appropriate
+*/
+function process_transfer($module_url, $update_list, $new_location, $download_filename)
+{
+ // todo: add $s_hidden_fields as a parameter to this function
+ $s_hidden_fields = '';
+
+ if (request_var('download', false))
+ {
+ $use_method = request_var('use_method', '');
+ $methods = array('.tar');
+
+ $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib');
+ foreach ($available_methods as $type => $module)
+ {
+ if (!@extension_loaded($module))
+ {
+ continue;
+ }
+
+ $methods[] = $type;
+ }
+
+ // Let the user decide in which format he wants to have the pack
+ if (!$use_method)
+ {
+ $radio_buttons = '';
+ foreach ($methods as $method)
+ {
+ $radio_buttons .= '<label><input type="radio"' . ((!$radio_buttons) ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>';
+ }
+
+ phpbb::$template->assign_vars(array(
+ 'S_DOWNLOAD_FILES' => true,
+ 'U_ACTION' => append_sid($module_url),
+ 'RADIO_BUTTONS' => $radio_buttons,
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields)
+ );
+
+ // To ease the update process create a file location map
+ $script_path = (phpbb::$config['force_server_vars']) ? ((phpbb::$config['script_path'] == '/') ? '/' : phpbb::$config['script_path'] . '/') : phpbb::$user->page['root_script_path'];
+
+ foreach ($update_list as $status => $files)
+ {
+ if ($status == 'up_to_date' || $status == 'no_update' || $status == 'status')
+ {
+ continue;
+ }
+
+ foreach ($files as $file_struct)
+ {
+ phpbb::$template->assign_block_vars('location', array(
+ 'SOURCE' => htmlspecialchars($file_struct['filename']),
+ 'DESTINATION' => $script_path . htmlspecialchars($file_struct['filename']),
+ ));
+ }
+ }
+ return 'SELECT_DOWNLOAD_FORMAT';
+ }
+
+ if (!in_array($use_method, $methods))
+ {
+ $use_method = '.tar';
+ }
+
+ $update_mode = 'download';
+ }
+ else
+ {
+ // Choose FTP, if not available use fsock...
+ $method = basename(request_var('method', ''));
+ $submit = phpbb_request::is_set_post('update');
+ $test_ftp_connection = request_var('test_connection', '');
+
+ if (!$method || !class_exists($method))
+ {
+ $method = 'ftp';
+ $methods = transfer::methods();
+
+ if (!in_array('ftp', $methods))
+ {
+ $method = $methods[0];
+ }
+ }
+
+ $test_connection = false;
+ if ($test_ftp_connection || $submit)
+ {
+ $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
+ $test_connection = $transfer->open_session();
+
+ // Make sure that the directory is correct by checking for the existence of common.php
+ if ($test_connection === true)
+ {
+ // Check for common.php file
+ if (!$transfer->file_exists(PHPBB_ROOT_PATH, 'common.' . PHP_EXT))
+ {
+ $test_connection = 'ERR_WRONG_PATH_TO_PHPBB';
+ }
+ }
+
+ $transfer->close_session();
+
+ // Make sure the login details are correct before continuing
+ if ($submit && $test_connection !== true)
+ {
+ $submit = false;
+ $test_ftp_connection = true;
+ }
+ }
+
+ $s_hidden_fields .= build_hidden_fields(array('method' => $method));
+
+ if (!$submit)
+ {
+ if (!class_exists($method))
+ {
+ trigger_error('Method does not exist.', E_USER_ERROR);
+ }
+
+ $requested_data = call_user_func(array($method, 'data'));
+ foreach ($requested_data as $data => $default)
+ {
+ phpbb::$template->assign_block_vars('data', array(
+ 'DATA' => $data,
+ 'NAME' => phpbb::$user->lang[strtoupper($method . '_' . $data)],
+ 'EXPLAIN' => phpbb::$user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'],
+ 'DEFAULT' => (request_var($data, false)) ? request_var($data, '') : $default
+ ));
+ }
+
+ phpbb::$template->assign_vars(array(
+ 'S_CONNECTION_SUCCESS' => ($test_ftp_connection && $test_connection === true) ? true : false,
+ 'S_CONNECTION_FAILED' => ($test_ftp_connection && $test_connection !== true) ? true : false,
+ 'ERROR_MSG' => ($test_ftp_connection && $test_connection !== true) ? phpbb::$user->lang[$test_connection] : '',
+
+ 'S_FTP_UPLOAD' => true,
+ 'UPLOAD_METHOD' => $method,
+ 'U_ACTION' => $module_url,
+ 'U_DOWNLOAD_METHOD' => $module_url . '&amp;download=1',
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ ));
+
+ return 'SELECT_FTP_SETTINGS';
+ }
+
+ $update_mode = 'upload';
+ }
+
+ // Now init the connection
+ if ($update_mode == 'download')
+ {
+ // Now update the installation or download the archive...
+ $archive_filename = $download_filename . '_' . time() . '_' . unique_id();
+
+ if ($use_method == '.zip')
+ {
+ $compress = new compress_zip('w', PHPBB_ROOT_PATH . 'store/' . $archive_filename . $use_method);
+ }
+ else
+ {
+ $compress = new compress_tar('w', PHPBB_ROOT_PATH . 'store/' . $archive_filename . $use_method, $use_method);
+ }
+ }
+ else
+ {
+ $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
+ $transfer->open_session();
+ }
+
+ // Ok, go through the update list and do the operations based on their status
+ foreach ($update_list as $status => $files)
+ {
+ if (!is_array($files))
+ {
+ continue;
+ }
+
+ foreach ($files as $file_struct)
+ {
+ $original_filename = ($file_struct['custom']) ? $file_struct['original'] : $file_struct['filename'];
+
+ switch ($status)
+ {
+ case 'new':
+ case 'new_conflict':
+ case 'not_modified':
+
+ if ($update_mode == 'download')
+ {
+ $compress->add_custom_file($new_location . $original_filename, $file_struct['filename']);
+ }
+ else
+ {
+ if ($status != 'new')
+ {
+ $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak');
+ }
+
+ // New directory too?
+ $dirname = dirname($file_struct['filename']);
+
+ if ($dirname && !file_exists(PHPBB_ROOT_PATH . $dirname))
+ {
+ $transfer->make_dir($dirname);
+ }
+
+ $transfer->copy_file($new_location . $original_filename, $file_struct['filename']);
+ }
+ break;
+
+ case 'modified':
+
+ $contents = base64_decode($cache->get($file_list[$file_struct['filename']]));
+
+ if ($update_mode == 'download')
+ {
+ $compress->add_data($contents, $file_struct['filename']);
+ }
+ else
+ {
+ // @todo add option to specify if a backup file should be created?
+ $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak');
+ $transfer->write_file($file_struct['filename'], $contents);
+ }
+ break;
+
+ case 'conflict':
+
+ $contents = base64_decode($cache->get($file_list[$file_struct['filename']]));
+
+ if ($update_mode == 'download')
+ {
+ $compress->add_data($contents, $file_struct['filename']);
+ }
+ else
+ {
+ $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak');
+ $transfer->write_file($file_struct['filename'], $contents);
+ }
+ break;
+ }
+ }
+ }
+
+ if ($update_mode == 'download')
+ {
+ $compress->close();
+
+ $compress->download($archive_filename, $download_filename);
+ @unlink(PHPBB_ROOT_PATH . 'store/' . $archive_filename . $use_method);
+
+ exit;
+ }
+ else
+ {
+ $transfer->close_session();
+
+ phpbb::$template->assign_var('S_UPLOAD_SUCCESS', true);
+ return;
+ }
+}
+
?> \ No newline at end of file
diff --git a/phpBB/includes/functions_transfer.php b/phpBB/includes/functions_transfer.php
index a276bd304a..351f9517c5 100644
--- a/phpBB/includes/functions_transfer.php
+++ b/phpBB/includes/functions_transfer.php
@@ -16,7 +16,7 @@ if (!defined('IN_PHPBB'))
exit;
}
-require_once PHPBB_ROOT_PATH . 'includes/sftp/sftp.' . PHP_EXT;
+require_once PHPBB_ROOT_PATH . 'includes/libraries/sftp/sftp.' . PHP_EXT;
/**
* Transfer class, wrapper for ftp/sftp/ssh
@@ -192,7 +192,7 @@ class transfer
$directory = $this->root_path . str_replace(PHPBB_ROOT_PATH, '', $directory);
$this->_chdir($directory);
- $result = $this->_ls();
+ $result = $this->_ls('');
if ($result !== false && is_array($result))
{
@@ -455,7 +455,7 @@ class ftp extends transfer
$item = str_replace('\\', '/', $item);
$dir = str_replace('\\', '/', $dir);
- if (strpos($item, $dir) === 0)
+ if (!empty($dir) && strpos($item, $dir) === 0)
{
$item = substr($item, strlen($dir));
}