コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if ($this->iohandler->get_input('submit_ftp', false)) {
         $this->update_helper->include_file('includes/functions_transfer.' . $this->php_ext);
         $method = 'ftp';
         $methods = \transfer::methods();
         if (!in_array($method, $methods, true)) {
             $method = $methods[0];
         }
         $ftp_host = $this->iohandler->get_input('ftp_host', '');
         $ftp_user = $this->iohandler->get_input('ftp_user', '');
         $ftp_pass = htmlspecialchars_decode($this->iohandler->get_input('ftp_pass', ''));
         $ftp_path = $this->iohandler->get_input('ftp_path', '');
         $ftp_port = $this->iohandler->get_input('ftp_port', 21);
         $ftp_time = $this->iohandler->get_input('ftp_timeout', 10);
         $this->installer_config->set('ftp_host', $ftp_host);
         $this->installer_config->set('ftp_user', $ftp_user);
         $this->installer_config->set('ftp_pass', $ftp_pass);
         $this->installer_config->set('ftp_path', $ftp_path);
         $this->installer_config->set('ftp_port', (int) $ftp_port);
         $this->installer_config->set('ftp_timeout', (int) $ftp_time);
         $this->installer_config->set('ftp_method', $method);
     } else {
         $this->iohandler->add_user_form_group('FTP_SETTINGS', array('ftp_host' => array('label' => 'FTP_HOST', 'description' => 'FTP_HOST_EXPLAIN', 'type' => 'text'), 'ftp_user' => array('label' => 'FTP_USERNAME', 'description' => 'FTP_USERNAME_EXPLAIN', 'type' => 'text'), 'ftp_pass' => array('label' => 'FTP_PASSWORD', 'description' => 'FTP_PASSWORD_EXPLAIN', 'type' => 'password'), 'ftp_path' => array('label' => 'FTP_ROOT_PATH', 'description' => 'FTP_ROOT_PATH_EXPLAIN', 'type' => 'text'), 'ftp_port' => array('label' => 'FTP_PORT', 'description' => 'FTP_PORT_EXPLAIN', 'type' => 'text', 'default' => 21), 'ftp_timeout' => array('label' => 'FTP_TIMEOUT', 'description' => 'FTP_TIMEOUT_EXPLAIN', 'type' => 'text', 'default' => 10), 'submit_ftp' => array('label' => 'SUBMIT', 'type' => 'submit')));
         throw new user_interaction_required_exception();
     }
 }
コード例 #2
0
ファイル: file_check.php プロジェクト: phpbb/phpbb-core
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if (!$this->installer_config->has_restart_point('check_update_files')) {
         $this->installer_config->create_progress_restart_point('check_update_files');
     }
     $old_path = $this->update_helper->get_path_to_old_update_files();
     $new_path = $this->update_helper->get_path_to_new_update_files();
     $update_info = $this->installer_config->get('update_info', array());
     $file_update_info = $this->installer_config->get('update_files', array());
     if (empty($update_info)) {
         $root_path = $this->phpbb_root_path;
         $update_info = $this->installer_config->get('update_info_unprocessed', array());
         $file_update_info = array();
         $file_update_info['update_without_diff'] = array_diff($update_info['binary'], $update_info['deleted']);
         // Filter out files that are already deleted
         $file_update_info['delete'] = array_filter($update_info['deleted'], function ($filename) use($root_path) {
             return file_exists($root_path . $filename);
         });
     }
     $progress_count = $this->installer_config->get('file_check_progress_count', 0);
     $task_count = count($update_info['files']);
     $this->iohandler->set_task_count($task_count);
     $this->iohandler->set_progress('UPDATE_CHECK_FILES', 0);
     foreach ($update_info['files'] as $key => $filename) {
         $old_file = $old_path . $filename;
         $new_file = $new_path . $filename;
         $file = $this->phpbb_root_path . $filename;
         if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) {
             // Save progress
             $this->installer_config->set('update_info', $update_info);
             $this->installer_config->set('file_check_progress_count', $progress_count);
             $this->installer_config->set('update_files', $file_update_info);
             // Request refresh
             throw new resource_limit_reached_exception();
         }
         $progress_count++;
         $this->iohandler->set_progress('UPDATE_CHECK_FILES', $progress_count);
         if (!$this->filesystem->exists($file)) {
             $file_update_info['new'][] = $filename;
         } else {
             $file_checksum = md5_file($file);
             if ($file_checksum === md5_file($new_file)) {
                 // File already up to date
                 continue;
             } else {
                 if ($this->filesystem->exists($old_file) && $file_checksum === md5_file($old_file)) {
                     // No need to diff the file
                     $file_update_info['update_without_diff'][] = $filename;
                 } else {
                     $file_update_info['update_with_diff'][] = $filename;
                 }
             }
         }
         unset($update_info['files'][$key]);
     }
     $this->installer_config->set('update_files', $file_update_info);
     $this->installer_config->set('update_info', array());
 }
コード例 #3
0
 /**
  * Set the compression method
  *
  * @param string	$method	Compression method's file extension
  *
  * @return string	Archive's filename
  */
 public function init($method)
 {
     $this->update_helper->include_file('includes/functions_compress.' . $this->php_ext);
     $archive_filename = 'update_archive_' . time() . '_' . uniqid();
     $path = $this->phpbb_root_path . 'store/' . $archive_filename . '' . $method;
     if ($method === '.zip') {
         $this->compress = new \compress_zip('w', $path);
     } else {
         $this->compress = new \compress_tar('w', $path, $method);
     }
     return $path;
 }
コード例 #4
0
ファイル: container_factory.php プロジェクト: MrAdder/phpbb
 /**
  * Build dependency injection container
  *
  * @throws \phpbb\install\exception\cannot_build_container_exception	When container cannot be built
  */
 protected function build_container()
 {
     // If the container has been already built just return.
     // Although this should never happen
     if ($this->container instanceof \Symfony\Component\DependencyInjection\ContainerInterface) {
         return;
     }
     // Check whether container can be built
     // We need config.php for that so let's check if it has been set up yet
     if (!filesize($this->phpbb_root_path . 'config.' . $this->php_ext)) {
         throw new cannot_build_container_exception();
     }
     $phpbb_config_php_file = new \phpbb\config_php_file($this->phpbb_root_path, $this->php_ext);
     $phpbb_container_builder = new \phpbb\di\container_builder($this->phpbb_root_path, $this->php_ext);
     // For BC with functions that we need during install
     global $phpbb_container, $table_prefix;
     $disable_super_globals = $this->request->super_globals_disabled();
     // This is needed because container_builder::get_env_parameters() uses $_SERVER
     if ($disable_super_globals) {
         $this->request->enable_super_globals();
     }
     $other_config_path = $this->phpbb_root_path . 'install/update/new/config';
     $config_path = is_dir($other_config_path) ? $other_config_path : $this->phpbb_root_path . 'config';
     $this->container = $phpbb_container_builder->with_environment('production')->with_config($phpbb_config_php_file)->with_config_path($config_path)->without_cache()->without_compiled_container()->get_container();
     // Setting request is required for the compatibility globals as those are generated from
     // this container
     $this->container->register('request')->setSynthetic(true);
     $this->container->set('request', $this->request);
     $this->container->register('language')->setSynthetic(true);
     $this->container->set('language', $this->language);
     // Replace cache service, as config gets cached, and we don't want that when we are installing
     if (!is_dir($other_config_path)) {
         $this->container->register('cache.driver')->setSynthetic(true);
         $this->container->set('cache.driver', new dummy());
     }
     $this->container->compile();
     $phpbb_container = $this->container;
     $table_prefix = $phpbb_config_php_file->get('table_prefix');
     // Restore super globals to previous state
     if ($disable_super_globals) {
         $this->request->disable_super_globals();
     }
     // Get compatibilty globals and constants
     $this->update_helper->include_file('includes/compatibility_globals.' . $this->php_ext);
     $this->update_helper->include_file('includes/constants.' . $this->php_ext);
 }
コード例 #5
0
ファイル: check_update.php プロジェクト: phpbb/phpbb-core
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     // Array of update files
     $update_files = array($this->phpbb_root_path . 'install/update', $this->phpbb_root_path . 'install/update/index.' . $this->php_ext);
     // Check for a valid update directory
     if (!$this->filesystem->exists($update_files) || !$this->filesystem->is_readable($update_files)) {
         $this->iohandler->add_warning_message('UPDATE_FILES_NOT_FOUND');
         $this->set_test_passed(false);
         // If there are no update files, we can't check the version etc
         // However, we can let the users run migrations if they really want to...
         $this->installer_config->set('disable_filesystem_update', true);
         return true;
     }
     // Recover version numbers
     $update_info = array();
     @(include $this->phpbb_root_path . 'install/update/index.' . $this->php_ext);
     $info = empty($update_info) || !is_array($update_info) ? false : $update_info;
     $update_version = false;
     if ($info !== false) {
         $update_version = !empty($info['version']['to']) ? trim($info['version']['to']) : false;
     }
     // Get current and latest version
     try {
         $latest_version = $this->version_helper->get_latest_on_current_branch(true);
     } catch (\RuntimeException $e) {
         $latest_version = $update_version;
     }
     $current_version = !empty($this->config['version_update_from']) ? $this->config['version_update_from'] : $this->config['version'];
     // Check if the update package
     if (!$this->update_helper->phpbb_version_compare($current_version, $update_version, '<')) {
         $this->iohandler->add_error_message('NO_UPDATE_FILES_UP_TO_DATE');
         $this->tests_passed = false;
     }
     // Check if the update package works with the installed version
     if (empty($info['version']['from']) || $info['version']['from'] !== $current_version) {
         $this->iohandler->add_error_message(array('INCOMPATIBLE_UPDATE_FILES', $current_version, $info['version']['from'], $update_version));
         $this->tests_passed = false;
     }
     // check if this is the latest update package
     if ($this->update_helper->phpbb_version_compare($update_version, $latest_version, '<')) {
         $this->iohandler->add_warning_message(array('OLD_UPDATE_FILES', $info['version']['from'], $update_version, $latest_version));
     }
     return $this->tests_passed;
 }
コード例 #6
0
ファイル: diff_files.php プロジェクト: ZerGabriel/phpbb
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     // Include diff engine
     $this->update_helper->include_file('includes/diff/diff.' . $this->php_ext);
     $this->update_helper->include_file('includes/diff/engine.' . $this->php_ext);
     // Set up basic vars
     $old_path = $this->update_helper->get_path_to_old_update_files();
     $new_path = $this->update_helper->get_path_to_new_update_files();
     $files_to_diff = $this->installer_config->get('update_files', array());
     $files_to_diff = $files_to_diff['update_with_diff'];
     // Set progress bar
     $this->iohandler->set_task_count(count($files_to_diff), true);
     $this->iohandler->set_progress('UPDATE_FILE_DIFF', 0);
     $progress_count = $this->installer_config->get('file_diff_update_count', 0);
     // Recover progress
     $progress_key = $this->installer_config->get('differ_progress_key', -1);
     $progress_recovered = $progress_key === -1;
     $merge_conflicts = $this->installer_config->get('merge_conflict_list', array());
     foreach ($files_to_diff as $key => $filename) {
         if ($progress_recovered === false) {
             if ($progress_key === $key) {
                 $progress_recovered = true;
             }
             continue;
         }
         // Read in files' content
         $file_contents = array();
         // Handle the special case when user created a file with the filename that is now new in the core
         $file_contents[0] = file_exists($old_path . $filename) ? file_get_contents($old_path . $filename) : '';
         $filenames = array($this->phpbb_root_path . $filename, $new_path . $filename);
         foreach ($filenames as $file_to_diff) {
             $file_contents[] = file_get_contents($file_to_diff);
             if ($file_contents[sizeof($file_contents) - 1] === false) {
                 $this->iohandler->add_error_message(array('FILE_DIFFER_ERROR_FILE_CANNOT_BE_READ', $files_to_diff));
                 unset($file_contents);
                 throw new user_interaction_required_exception();
             }
         }
         $diff = new \diff3($file_contents[0], $file_contents[1], $file_contents[2]);
         unset($file_contents);
         // Handle conflicts
         if ($diff->get_num_conflicts() !== 0) {
             $merge_conflicts[] = $filename;
         }
         // Save merged output
         $this->cache->put('_file_' . md5($filename), base64_encode(implode("\n", $diff->merged_output())));
         unset($diff);
         $progress_count++;
         $this->iohandler->set_progress('UPDATE_FILE_DIFF', $progress_count);
         if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) {
             // Save differ progress
             $this->installer_config->set('differ_progress_key', $key);
             $this->installer_config->set('merge_conflict_list', $merge_conflicts);
             $this->installer_config->set('file_diff_update_count', $progress_count);
             // Request refresh
             throw new resource_limit_reached_exception();
         }
     }
     $this->iohandler->finish_progress('ALL_FILES_DIFFED');
     $this->installer_config->set('merge_conflict_list', $merge_conflicts);
 }
コード例 #7
0
ファイル: ftp_file_updater.php プロジェクト: MrAdder/phpbb
 /**
  * Initialize FTP connection
  *
  * @param string	$method
  * @param string	$host
  * @param string	$user
  * @param string	$pass
  * @param string	$path
  * @param int		$port
  * @param int		$timeout
  */
 public function init($method, $host, $user, $pass, $path, $port, $timeout)
 {
     $this->update_helper->include_file('includes/functions_transfer.' . $this->php_ext);
     $this->transfer = new $method($host, $user, $pass, $path, $port, $timeout);
     $this->transfer->open_session();
 }
コード例 #8
0
ファイル: file_check.php プロジェクト: phpbb/phpbb
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if (!$this->installer_config->has_restart_point('check_update_files')) {
         $this->installer_config->create_progress_restart_point('check_update_files');
     }
     $old_path = $this->update_helper->get_path_to_old_update_files();
     $new_path = $this->update_helper->get_path_to_new_update_files();
     $update_info = $this->installer_config->get('update_info', array());
     $file_update_info = $this->installer_config->get('update_files', array());
     if (empty($update_info)) {
         $root_path = $this->phpbb_root_path;
         $update_info = $this->installer_config->get('update_info_unprocessed', array());
         $file_update_info = array();
         $file_update_info['update_without_diff'] = array_diff($update_info['binary'], $update_info['deleted']);
         // Filter out files that are already deleted
         $file_update_info['delete'] = array_filter($update_info['deleted'], function ($filename) use($root_path) {
             return file_exists($root_path . $filename);
         });
     }
     $progress_count = $this->installer_config->get('file_check_progress_count', 0);
     $task_count = count($update_info['files']);
     $this->iohandler->set_task_count($task_count);
     $this->iohandler->set_progress('UPDATE_CHECK_FILES', 0);
     // Create list of default extensions that should have been added prior
     // to this update
     $default_update_extensions = [];
     foreach (\phpbb\install\module\update_database\task\update_extensions::$default_extensions_update as $version => $extensions) {
         if ($this->update_helper->phpbb_version_compare($update_info['version']['from'], $version, '>')) {
             $default_update_extensions = array_merge($default_update_extensions, $extensions);
         }
     }
     foreach ($update_info['files'] as $key => $filename) {
         $old_file = $old_path . $filename;
         $new_file = $new_path . $filename;
         $file = $this->phpbb_root_path . $filename;
         if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) {
             // Save progress
             $this->installer_config->set('update_info', $update_info);
             $this->installer_config->set('file_check_progress_count', $progress_count);
             $this->installer_config->set('update_files', $file_update_info);
             // Request refresh
             throw new resource_limit_reached_exception();
         }
         $progress_count++;
         $this->iohandler->set_progress('UPDATE_CHECK_FILES', $progress_count);
         // Do not copy default extension again if the previous version was
         // packaged with it but it does not exist (e.g. deleted by admin)
         if (strpos($file, $this->phpbb_root_path . 'ext/') !== false) {
             $skip_file = false;
             foreach ($default_update_extensions as $ext_name) {
                 if (strpos($file, $this->phpbb_root_path . 'ext/' . $ext_name) !== false && !$this->filesystem->exists($this->phpbb_root_path . 'ext/' . $ext_name . '/composer.json')) {
                     $skip_file = true;
                     break;
                 }
             }
             if ($skip_file) {
                 continue;
             }
         }
         if (!$this->filesystem->exists($file)) {
             $file_update_info['new'][] = $filename;
         } else {
             $file_checksum = md5_file($file);
             if ($file_checksum === md5_file($new_file)) {
                 // File already up to date
                 continue;
             } else {
                 if ($this->filesystem->exists($old_file) && $file_checksum === md5_file($old_file)) {
                     // No need to diff the file
                     $file_update_info['update_without_diff'][] = $filename;
                 } else {
                     $file_update_info['update_with_diff'][] = $filename;
                 }
             }
         }
         unset($update_info['files'][$key]);
     }
     $this->installer_config->set('update_files', $file_update_info);
     $this->installer_config->set('update_info', array());
 }
コード例 #9
0
ファイル: update_files.php プロジェクト: ramukumar555/phpbb
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $new_path = $this->update_helper->get_path_to_new_update_files();
     $file_update_info = $this->installer_config->get('update_files', array());
     $update_type_progress = $this->installer_config->get('file_updater_type_progress', '');
     $update_elem_progress = $this->installer_config->get('file_updater_elem_progress', '');
     $type_progress_found = false;
     $elem_progress_found = false;
     // Progress bar
     $task_count = 0;
     foreach ($file_update_info as $sub_array) {
         $task_count += count($sub_array);
     }
     // Everything is up to date, so just continue
     if ($task_count === 0) {
         return;
     }
     $progress_count = $this->installer_config->get('file_update_progress_count', 0);
     $this->iohandler->set_task_count($task_count, true);
     $this->iohandler->set_progress('UPDATE_UPDATING_FILES', 0);
     $this->file_updater = $this->get_file_updater();
     // File updater fallback logic
     try {
         // Update files
         foreach ($file_update_info as $type => $file_update_vector) {
             if (!$type_progress_found) {
                 if ($type === $update_type_progress || empty($update_elem_progress)) {
                     $type_progress_found = true;
                 } else {
                     continue;
                 }
             }
             foreach ($file_update_vector as $path) {
                 if (!$elem_progress_found) {
                     if ($path === $update_elem_progress || empty($update_elem_progress)) {
                         $elem_progress_found = true;
                     } else {
                         continue;
                     }
                 }
                 switch ($type) {
                     case 'delete':
                         $this->file_updater->delete_file($path);
                         break;
                     case 'new':
                         $this->file_updater->create_new_file($path, $new_path . $path);
                         break;
                     case 'update_without_diff':
                         $this->file_updater->update_file($path, $new_path . $path);
                         break;
                     case 'update_with_diff':
                         $this->file_updater->update_file($path, $this->cache->get('_file_' . md5($path)), true);
                         break;
                 }
                 // Save progress
                 $this->installer_config->set('file_updater_type_progress', $type);
                 $this->installer_config->set('file_updater_elem_progress', $path);
                 $progress_count++;
                 $this->iohandler->set_progress('UPDATE_UPDATING_FILES', $progress_count);
                 if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) {
                     // Request refresh
                     throw new resource_limit_reached_exception();
                 }
             }
         }
         $this->iohandler->finish_progress('UPDATE_UPDATING_FILES');
     } catch (runtime_exception $e) {
         if ($e instanceof resource_limit_reached_exception) {
             throw new resource_limit_reached_exception();
         }
         $current_method = $this->installer_config->get('file_update_method', '');
         // File updater failed, try to fallback to download file update mode
         if ($current_method !== 'compression') {
             $this->iohandler->add_warning_message(array('UPDATE_FILE_UPDATER_HAS_FAILED', $current_method, 'compression'));
             $this->installer_config->set('file_update_method', 'compression');
             // We only want a simple refresh here
             throw new resource_limit_reached_exception();
         } else {
             // Nowhere to fallback to :(
             // Due to the way the installer handles fatal errors, we need to throw a low level exception
             throw new runtime_exception('UPDATE_FILE_UPDATERS_HAVE_FAILED');
         }
     }
     $file_updater_method = $this->installer_config->get('file_update_method', '');
     if ($file_updater_method === 'compression' || $file_updater_method === 'ftp') {
         $this->file_updater->close();
     }
 }
コード例 #10
0
ファイル: update_extensions.php プロジェクト: phpbb/phpbb
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->user->session_begin();
     $this->user->setup(array('common', 'acp/common', 'cli'));
     $update_info = $this->install_config->get('update_info_unprocessed', []);
     $version_from = !empty($update_info) ? $update_info['version']['from'] : $this->config['version_update_from'];
     if (!empty($version_from)) {
         $update_extensions = $this->iohandler->get_input('update-extensions', []);
         // Create list of default extensions that need to be enabled in update
         $default_update_extensions = [];
         foreach (self::$default_extensions_update as $version => $extensions) {
             if ($this->update_helper->phpbb_version_compare($version_from, $version, '<=')) {
                 $default_update_extensions = array_merge($default_update_extensions, $extensions);
             }
         }
         $all_available_extensions = $this->extension_manager->all_available();
         $i = $this->install_config->get('update_extensions_index', 0);
         $available_extensions = array_slice($all_available_extensions, $i);
         // Update available extensions
         foreach ($available_extensions as $ext_name => $ext_path) {
             // Update extensions if:
             //	1) Extension is currently enabled
             //	2) Extension was implicitly defined as needing an update
             //	3) Extension was newly added as default phpBB extension in
             //		this update and should be enabled by default.
             if ($this->extension_manager->is_enabled($ext_name) || in_array($ext_name, $update_extensions) || in_array($ext_name, $default_update_extensions)) {
                 try {
                     $extension_enabled = $this->extension_manager->is_enabled($ext_name);
                     if ($extension_enabled) {
                         $this->extension_manager->disable($ext_name);
                     }
                     $this->extension_manager->enable($ext_name);
                     $extensions = $this->get_extensions();
                     if (isset($extensions[$ext_name]) && $extensions[$ext_name]['ext_active']) {
                         // Create log
                         $this->log->add('admin', ANONYMOUS, '', 'LOG_EXT_UPDATE', time(), array($ext_name));
                         $this->iohandler->add_success_message(array('CLI_EXTENSION_UPDATE_SUCCESS', $ext_name));
                     } else {
                         $this->iohandler->add_log_message('CLI_EXTENSION_UPDATE_FAILURE', array($ext_name));
                     }
                     // Disable extensions if it was disabled by the admin before
                     if (!$extension_enabled && !in_array($ext_name, $default_update_extensions)) {
                         $this->extension_manager->disable($ext_name);
                     }
                 } catch (\Exception $e) {
                     // Add fail log and continue
                     $this->iohandler->add_log_message('CLI_EXTENSION_UPDATE_FAILURE', array($ext_name));
                 }
             }
             $i++;
             // Stop execution if resource limit is reached
             if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) {
                 break;
             }
         }
         $this->install_config->set('update_extensions_index', $i);
         if ($i < sizeof($all_available_extensions)) {
             throw new resource_limit_reached_exception();
         }
     }
     $this->config->delete('version_update_from');
     $this->cache->purge();
     $this->config->increment('assets_version', 1);
 }