/**
  * This listener is run when the KernelEvents::EXCEPTION event is triggered
  *
  * @param GetResponseForExceptionEvent $event
  * @return null
  */
 public function on_kernel_exception(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $message = $exception->getMessage();
     if ($exception instanceof \phpbb\exception\exception_interface) {
         $message = $this->language->lang_array($message, $exception->get_parameters());
     }
     if (!$event->getRequest()->isXmlHttpRequest()) {
         page_header($this->language->lang('INFORMATION'));
         $this->template->assign_vars(array('MESSAGE_TITLE' => $this->language->lang('INFORMATION'), 'MESSAGE_TEXT' => $message));
         $this->template->set_filenames(array('body' => 'message_body.html'));
         page_footer(true, false, false);
         $response = new Response($this->template->assign_display('body'), 500);
     } else {
         $data = array();
         if (!empty($message)) {
             $data['message'] = $message;
         }
         if (defined('DEBUG')) {
             $data['trace'] = $exception->getTrace();
         }
         $response = new JsonResponse($data, 500);
     }
     if ($exception instanceof HttpExceptionInterface) {
         $response->setStatusCode($exception->getStatusCode());
         $response->headers->add($exception->getHeaders());
     }
     $event->setResponse($response);
 }
 /**
  * {@inheritdoc}
  */
 public function write($message, $verbosity)
 {
     if ($verbosity <= migrator_output_handler_interface::VERBOSITY_VERBOSE) {
         $final_message = $this->language->lang_array(array_shift($message), $message);
         echo $final_message . "<br />\n";
     }
 }
 /**
  * This listener is run when the KernelEvents::EXCEPTION event is triggered
  *
  * @param GetResponseForExceptionEvent	$event
  */
 public function on_kernel_exception(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $message = $exception->getMessage();
     if ($exception instanceof exception_interface) {
         $message = $this->language->lang_array($message, $exception->get_parameters());
     }
     if (!$event->getRequest()->isXmlHttpRequest()) {
         $this->template->assign_vars(array('TITLE' => $this->language->lang('INFORMATION'), 'BODY' => $message));
         $response = $this->controller_helper->render('installer_main.html', $this->language->lang('INFORMATION'), false, 500);
     } else {
         $data = array();
         if (!empty($message)) {
             $data['message'] = $message;
         }
         if (defined('DEBUG')) {
             $data['trace'] = $exception->getTrace();
         }
         $response = new JsonResponse($data, 500);
     }
     if ($exception instanceof HttpExceptionInterface) {
         $response->setStatusCode($exception->getStatusCode());
         $response->headers->add($exception->getHeaders());
     }
     $event->setResponse($response);
 }
Exemplo n.º 4
0
 public function test_lang_plural_rules()
 {
     $this->assertEquals($this->lang->lang('PLURAL_ARRY', 0), '0 is 0');
     $this->assertEquals($this->lang->lang('PLURAL_ARRY', 1), '1 is 1');
     $this->assertEquals($this->lang->lang('PLURAL_ARRY', 103), '103 ends with 01-10');
     $this->assertEquals($this->lang->lang('PLURAL_ARRY', 15), '15 ends with 11-19');
     $this->assertEquals($this->lang->lang('PLURAL_ARRY', 300), '300 is part of the last rule');
 }
Exemplo n.º 5
0
 public function test_not_up_to_date_verbose()
 {
     $command_tester = $this->get_command_tester('0');
     $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true, '--verbose' => true));
     $this->assertContains($this->language->lang('UPDATE_NEEDED'), $command_tester->getDisplay());
     $this->assertContains($this->language->lang('UPDATES_AVAILABLE'), $command_tester->getDisplay());
     $this->assertSame($status, 1);
 }
Exemplo n.º 6
0
 /**
  * Remote upload method
  * Uploads file from given url
  *
  * @param string $upload_url URL pointing to file to upload, for example http://www.foobar.com/example.gif
  * @return filespec $file Object "filespec" is returned, all further operations can be done with this object
  * @access public
  */
 protected function remote_upload($upload_url)
 {
     $upload_ary = array();
     $upload_ary['local_mode'] = true;
     if (!preg_match('#^(https?://).*?\\.(' . implode('|', $this->upload->allowed_extensions) . ')$#i', $upload_url, $match)) {
         return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'URL_INVALID'));
     }
     $url = parse_url($upload_url);
     $upload_ary['type'] = 'application/octet-stream';
     $url['path'] = explode('.', $url['path']);
     $ext = array_pop($url['path']);
     $url['path'] = implode('', $url['path']);
     $upload_ary['name'] = utf8_basename($url['path']) . ($ext ? '.' . $ext : '');
     $remote_max_filesize = $this->get_max_file_size();
     $guzzle_options = ['timeout' => $this->upload->upload_timeout, 'connect_timeout' => $this->upload->upload_timeout, 'verify' => !empty($this->config['remote_upload_verify']) ? (bool) $this->config['remote_upload_verify'] : false];
     $client = new \GuzzleHttp\Client($guzzle_options);
     try {
         $response = $client->get($upload_url, $guzzle_options);
     } catch (\GuzzleHttp\Exception\ClientException $clientException) {
         return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'URL_NOT_FOUND');
     } catch (\GuzzleHttp\Exception\RequestException $requestException) {
         if (strpos($requestException->getMessage(), 'cURL error 28') !== false || preg_match('/408|504/', $requestException->getCode())) {
             return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'REMOTE_UPLOAD_TIMEOUT');
         } else {
             return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED'));
         }
     } catch (\Exception $e) {
         return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED'));
     }
     $content_length = $response->getBody()->getSize();
     if ($remote_max_filesize && $content_length > $remote_max_filesize) {
         $max_filesize = get_formatted_filesize($remote_max_filesize, false);
         return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'WRONG_FILESIZE', $max_filesize['value'], $max_filesize['unit']));
     }
     if ($content_length == 0) {
         return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'EMPTY_REMOTE_DATA');
     }
     $data = $response->getBody();
     $filename = tempnam(sys_get_temp_dir(), unique_id() . '-');
     if (!($fp = @fopen($filename, 'wb'))) {
         return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'NOT_UPLOADED');
     }
     $upload_ary['size'] = fwrite($fp, $data);
     fclose($fp);
     unset($data);
     $upload_ary['tmp_name'] = $filename;
     /** @var filespec $file */
     $file = $this->factory->get('filespec')->set_upload_ary($upload_ary)->set_upload_namespace($this->upload);
     $this->upload->common_checks($file);
     return $file;
 }
 /**
  * {@inheritdoc}
  */
 public function write($message, $verbosity)
 {
     $this->migrator->write($message, $verbosity);
     if ($this->file_handle !== false) {
         $translated_message = $this->language->lang_array(array_shift($message), $message);
         if ($verbosity <= migrator_output_handler_interface::VERBOSITY_NORMAL) {
             $translated_message = '[INFO] ' . $translated_message;
         } else {
             $translated_message = '[DEBUG] ' . $translated_message;
         }
         fwrite($this->file_handle, $translated_message);
         fflush($this->file_handle);
     }
 }
Exemplo n.º 8
0
 /**
  * Check if upload exceeds maximum file size
  *
  * @param \phpbb\files\filespec $file Filespec object
  *
  * @return \phpbb\files\filespec Returns same filespec instance
  */
 public function check_upload_size($file)
 {
     // PHP Upload filesize exceeded
     if ($file->get('filename') == 'none') {
         $max_filesize = $this->php_ini->getString('upload_max_filesize');
         $unit = 'MB';
         if (!empty($max_filesize)) {
             $unit = strtolower(substr($max_filesize, -1, 1));
             $max_filesize = (int) $max_filesize;
             $unit = $unit == 'k' ? 'KB' : ($unit == 'g' ? 'GB' : 'MB');
         }
         $file->error[] = empty($max_filesize) ? $this->language->lang($this->upload->error_prefix . 'PHP_SIZE_NA') : $this->language->lang($this->upload->error_prefix . 'PHP_SIZE_OVERRUN', $max_filesize, $this->language->lang($unit));
     }
     return $file;
 }
Exemplo n.º 9
0
 /**
  * Callback function for language replacing
  *
  * @param array	$matches
  * @return string
  */
 public function lang_replace_callback($matches)
 {
     if (!empty($matches[1])) {
         return $this->db->sql_escape($this->language->lang($matches[1]));
     }
     return '';
 }
Exemplo n.º 10
0
    /**
     * {@inheritdoc}
     */
    public function run()
    {
        $this->db->sql_return_on_error(true);
        $sql = 'SELECT group_id
			FROM ' . GROUPS_TABLE . "\n\t\t\tWHERE group_name = 'BOTS'";
        $result = $this->db->sql_query($sql);
        $group_id = (int) $this->db->sql_fetchfield('group_id');
        $this->db->sql_freeresult($result);
        if (!$group_id) {
            // If we reach this point then something has gone very wrong
            $this->io_handler->add_error_message('NO_GROUP');
        }
        foreach ($this->bot_list as $bot_name => $bot_ary) {
            $user_row = array('user_type' => USER_IGNORE, 'group_id' => $group_id, 'username' => $bot_name, 'user_regdate' => time(), 'user_password' => '', 'user_colour' => '9E8DA7', 'user_email' => '', 'user_lang' => $this->install_config->get('default_lang'), 'user_style' => 1, 'user_timezone' => 'UTC', 'user_dateformat' => $this->language->lang('default_dateformat'), 'user_allow_massemail' => 0, 'user_allow_pm' => 0);
            if (!function_exists('user_add')) {
                include $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext;
            }
            $user_id = user_add($user_row);
            if (!$user_id) {
                // If we can't insert this user then continue to the next one to avoid inconsistent data
                $this->io_handler->add_error_message('CONV_ERROR_INSERT_BOT');
                continue;
            }
            $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array('bot_active' => 1, 'bot_name' => (string) $bot_name, 'user_id' => (int) $user_id, 'bot_agent' => (string) $bot_ary[0], 'bot_ip' => (string) $bot_ary[1]));
            $this->db->sql_query($sql);
        }
    }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function finish_progress($message_lang_key)
 {
     if (!empty($message_lang_key)) {
         $this->current_task_name = $this->language->lang($message_lang_key);
     }
     $this->current_task_progress = $this->task_progress_count;
 }
Exemplo n.º 12
0
 /**
  * @return Response
  */
 public function main()
 {
     $this->lang->add_lang('common', 'paul999/downloadpage');
     $sql = 'SELECT * FROM ' . $this->versions_table . ' WHERE active = 1 ORDER BY sort DESC';
     $result = $this->db->sql_query($sql);
     while ($row = $this->db->sql_fetchrow($result)) {
         $this->template->assign_block_vars('releases', array('NAME' => $row['name'], 'EOL' => $row['eol'], 'L_EOL' => $this->lang->lang('PHPBB_EOL', $row['name']), 'L_ALWAYS_CURRENT_DOWNLOAD' => $this->lang->lang('ALWAYS_CURRENT', ''), 'L_ALWAYS_CURRENT_UPDATE' => $this->lang->lang('ALWAYS_CURRENT', '')));
         // Yes, we do a queries in a loop here.
         // However, as the versions table should have <= 3 versions this should be fine.
         $sql_row = 'SELECT * FROM ' . $this->releases_table . ' WHERE version_id = ' . $row['version_id'] . ' AND active = 1 ORDER BY release_time DESC';
         $result_row = $this->db->sql_query($sql_row);
         while ($row_row = $this->db->sql_fetchrow($result_row)) {
             $this->template->assign_block_vars('releases.versions', array('RELEASED_AT' => $this->lang->lang('RELEASED_AT', $this->user->format_date($row_row['release_time']))));
             $sql = 'SELECT * FROM ' . $this->downloads_table . ' WHERE active = 1 AND release_id = ' . (int) $row_row['release_id'];
             $int_result = $this->db->sql_query($sql);
             while ($int_row = $this->db->sql_fetchrow($int_result)) {
                 $this->template->assign_block_vars('releases.versions.downloads', array('U_DOWNLOAD' => $this->controller_helper->route('paul999_downloadpage_download', array('id' => $int_row['download_id'])), 'NAME' => $int_row['name'], 'S_FULL_PACKAGE' => $int_row['type'] == constants::FULL_PACKAGE, 'S_LANG_PACKAGE' => $int_row['type'] == constants::TRANSLATION, 'S_UPDATE_PACKAGE' => $int_row['type'] == constants::UPDATE_PACKAGE));
             }
             $this->db->sql_freeresult($int_result);
         }
         $this->db->sql_freeresult($result_row);
     }
     $this->db->sql_freeresult($result);
     return $this->controller_helper->render('@paul999_downloadpage/download_main.html');
 }
Exemplo n.º 13
0
 /**
  * @param auth       $auth
  * @param config     $config
  * @param helper     $helper
  * @param ideas      $ideas
  * @param language   $language
  * @param linkhelper $link_helper
  * @param pagination $pagination
  * @param request    $request
  * @param template   $template
  * @param user       $user
  * @param string     $root_path
  * @param string     $php_ext
  */
 public function __construct(auth $auth, config $config, helper $helper, ideas $ideas, language $language, linkhelper $link_helper, pagination $pagination, request $request, template $template, user $user, $root_path, $php_ext)
 {
     $this->auth = $auth;
     $this->config = $config;
     $this->helper = $helper;
     $this->ideas = $ideas;
     $this->language = $language;
     $this->link_helper = $link_helper;
     $this->pagination = $pagination;
     $this->request = $request;
     $this->template = $template;
     $this->user = $user;
     $this->root_path = $root_path;
     $this->php_ext = $php_ext;
     $this->language->add_lang('common', 'phpbb/ideas');
 }
Exemplo n.º 14
0
 public function test_add_block_double_switch()
 {
     $block_name = 'abc';
     $switch_expected = true;
     $this->language->expects($this->at(0))->method('lang')->with($block_name)->willReturn(strtoupper($block_name));
     $this->template->expects($this->at(0))->method('assign_block_vars')->with('faq_block', array('BLOCK_TITLE' => strtoupper($block_name), 'SWITCH_COLUMN' => $switch_expected));
     $this->manager->add_block($block_name, true);
     $this->assertTrue($this->manager->switched_column());
     // Add a second block with switch
     $block_name = 'def';
     $switch_expected = false;
     $this->language->expects($this->at(0))->method('lang')->with($block_name)->willReturn(strtoupper($block_name));
     $this->template->expects($this->at(0))->method('assign_block_vars')->with('faq_block', array('BLOCK_TITLE' => strtoupper($block_name), 'SWITCH_COLUMN' => $switch_expected));
     $this->manager->add_block($block_name, true);
     $this->assertTrue($this->manager->switched_column());
 }
Exemplo n.º 15
0
 /**
  * Executes the command user:reclean
  *
  * Cleans user names that are unclean.
  *
  * @param InputInterface  $input  The input stream used to get the options
  * @param OutputInterface $output The output stream, used to print messages
  *
  * @return int 0 if all is well, 1 if any errors occurred
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $io->section($this->language->lang('CLI_USER_RECLEAN_START'));
     $this->processed = 0;
     $this->progress = $this->create_progress_bar($this->get_count(), $io, $output);
     $this->progress->setMessage($this->language->lang('CLI_USER_RECLEAN_START'));
     $this->progress->start();
     $stage = 0;
     while ($stage !== true) {
         $stage = $this->reclean_usernames($stage);
     }
     $this->progress->finish();
     $io->newLine(2);
     $io->success($this->language->lang('CLI_USER_RECLEAN_DONE', $this->processed));
     return 0;
 }
Exemplo n.º 16
0
 /**
  * Interacts with the user.
  * Confirm they really want to delete the account...last chance!
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $question = new ConfirmationQuestion($this->language->lang('CLI_USER_DELETE_CONFIRM', $input->getArgument('username')), false);
     if (!$helper->ask($input, $output, $question)) {
         $input->setArgument('username', false);
     }
 }
Exemplo n.º 17
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->language->add_lang('migrator');
     if (!isset($this->config['version_update_from'])) {
         $this->config->set('version_update_from', $this->config['version']);
     }
     $original_version = $this->config['version_update_from'];
     $this->migrator->set_output_handler(new log_wrapper_migrator_output_handler($this->language, new installer_migrator_output_handler($this->iohandler), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem));
     $this->migrator->create_migrations_table();
     $migrations = $this->extension_manager->get_finder()->core_path('phpbb/db/migration/data/')->extension_directory('/migrations')->get_classes();
     $this->migrator->set_migrations($migrations);
     $migration_step_count = $this->installer_config->get('database_update_migration_steps', -1);
     if ($migration_step_count < 0) {
         $migration_step_count = count($this->migrator->get_installable_migrations()) * 2;
         $this->installer_config->set('database_update_migration_steps', $migration_step_count);
     }
     $progress_count = $this->installer_config->get('database_update_count', 0);
     $restart_progress_bar = $progress_count === 0;
     // Only "restart" when the update runs for the first time
     $this->iohandler->set_task_count($migration_step_count, $restart_progress_bar);
     $this->installer_config->set_task_progress_count($migration_step_count);
     while (!$this->migrator->finished()) {
         try {
             $this->migrator->update();
             $progress_count++;
             $last_run_migration = $this->migrator->get_last_run_migration();
             if (isset($last_run_migration['effectively_installed']) && $last_run_migration['effectively_installed']) {
                 // We skipped two step, so increment $progress_count by another one
                 $progress_count++;
             } else {
                 if ($last_run_migration['task'] === 'process_schema_step' && !$last_run_migration['state']['migration_schema_done'] || $last_run_migration['task'] === 'process_data_step' && !$last_run_migration['state']['migration_data_done']) {
                     // We just run a step that wasn't counted yet so make it count
                     $migration_step_count++;
                 }
             }
             $this->iohandler->set_task_count($migration_step_count);
             $this->installer_config->set_task_progress_count($migration_step_count);
             $this->iohandler->set_progress('STAGE_UPDATE_DATABASE', $progress_count);
         } catch (exception $e) {
             $msg = $e->getParameters();
             array_unshift($msg, $e->getMessage());
             $this->iohandler->add_error_message($msg);
             throw new user_interaction_required_exception();
         }
         if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) {
             $this->installer_config->set('database_update_count', $progress_count);
             $this->installer_config->set('database_update_migration_steps', $migration_step_count);
             throw new resource_limit_reached_exception();
         }
     }
     if ($original_version !== $this->config['version']) {
         $this->log->add('admin', isset($this->user->data['user_id']) ? $this->user->data['user_id'] : ANONYMOUS, $this->user->ip, 'LOG_UPDATE_DATABASE', false, array($original_version, $this->config['version']));
     }
     $this->iohandler->add_success_message('INLINE_UPDATE_SUCCESSFUL');
     $this->config->delete('version_update_from');
     $this->cache->purge();
     $this->config->increment('assets_version', 1);
 }
Exemplo n.º 18
0
 /**
  * Generate ideas forum select options
  *
  * @return string Select menu HTML code
  * @access protected
  */
 protected function select_ideas_forum()
 {
     $ideas_forum_id = (int) $this->config['ideas_forum_id'];
     $s_forums_list = '<select id="ideas_forum_id" name="config[ideas_forum_id]">';
     $s_forums_list .= '<option value="0"' . (!$ideas_forum_id ? ' selected="selected"' : '') . '>' . $this->language->lang('ACP_IDEAS_NO_FORUM') . '</option>';
     $forum_list = make_forum_select($ideas_forum_id, false, true, true);
     $s_forums_list .= $forum_list . '</select>';
     return $s_forums_list;
 }
Exemplo n.º 19
0
 /**
  * Specify/Get image
  */
 function img($img, $alt = '')
 {
     $title = '';
     if ($alt) {
         $alt = $this->language->lang($alt);
         $title = ' title="' . $alt . '"';
     }
     return '<span class="imageset ' . $img . '"' . $title . '>' . $alt . '</span>';
 }
Exemplo n.º 20
0
 /**
  * Load language file of module
  *
  * @param object $module Module of which language file should be loaded
  */
 public function load_module_language($module)
 {
     if ($language_file = $module->get_language()) {
         // Load language file from vendor if specified
         if (is_array($language_file)) {
             $this->language->add_lang($language_file['file'], $language_file['vendor']);
         } else {
             $this->language->add_lang('modules/' . $language_file, 'board3/portal');
         }
     }
 }
Exemplo n.º 21
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $server_name = $this->install_config->get('server_name');
     $current_time = time();
     $user_ip = phpbb_ip_normalise($this->iohandler->get_server_variable('REMOTE_ADDR'));
     $user_ip = $user_ip === false ? '' : $user_ip;
     $referer = $this->iohandler->get_server_variable('REFERER');
     // Calculate cookie domain
     $cookie_domain = $server_name;
     if (strpos($cookie_domain, 'www.') === 0) {
         $cookie_domain = substr($cookie_domain, 3);
     }
     // Set default config and post data, this applies to all DB's
     $sql_ary = array('INSERT INTO ' . $this->config_table . " (config_name, config_value)\n\t\t\t\tVALUES ('board_startdate', '{$current_time}')", 'INSERT INTO ' . $this->config_table . " (config_name, config_value)\n\t\t\t\tVALUES ('default_lang', '" . $this->db->sql_escape($this->install_config->get('default_lang')) . "')", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('img_imagick')) . "'\n\t\t\t\tWHERE config_name = 'img_imagick'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_name')) . "'\n\t\t\t\tWHERE config_name = 'server_name'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_port')) . "'\n\t\t\t\tWHERE config_name = 'server_port'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'\n\t\t\t\tWHERE config_name = 'board_email'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'\n\t\t\t\tWHERE config_name = 'board_contact'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($cookie_domain) . "'\n\t\t\t\tWHERE config_name = 'cookie_domain'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "'\n\t\t\t\tWHERE config_name = 'default_dateformat'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('email_enable')) . "'\n\t\t\t\tWHERE config_name = 'email_enable'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_delivery')) . "'\n\t\t\t\tWHERE config_name = 'smtp_delivery'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_host')) . "'\n\t\t\t\tWHERE config_name = 'smtp_host'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_port')) . "'\n\t\t\t\tWHERE config_name = 'smtp_port'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_auth')) . "'\n\t\t\t\tWHERE config_name = 'smtp_auth_method'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_user')) . "'\n\t\t\t\tWHERE config_name = 'smtp_username'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_pass')) . "'\n\t\t\t\tWHERE config_name = 'smtp_password'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('cookie_secure')) . "'\n\t\t\t\tWHERE config_name = 'cookie_secure'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('force_server_vars')) . "'\n\t\t\t\tWHERE config_name = 'force_server_vars'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('script_path')) . "'\n\t\t\t\tWHERE config_name = 'script_path'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_protocol')) . "'\n\t\t\t\tWHERE config_name = 'server_protocol'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE config_name = 'newest_username'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'avatar_salt'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'plupload_salt'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_name')) . "'\n\t\t\t\tWHERE config_name = 'sitename'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_description')) . "'\n\t\t\t\tWHERE config_name = 'site_desc'", 'UPDATE ' . $this->user_table . "\n\t\t\t\tSET username = '******'admin_name')) . "',\n\t\t\t\t\tuser_password='******'admin_passwd')) . "',\n\t\t\t\t\tuser_ip = '" . $this->db->sql_escape($user_ip) . "',\n\t\t\t\t\tuser_lang = '" . $this->db->sql_escape($this->install_config->get('user_language', 'en')) . "',\n\t\t\t\t\tuser_email='" . $this->db->sql_escape($this->install_config->get('board_email')) . "',\n\t\t\t\t\tuser_dateformat='" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "',\n\t\t\t\t\tuser_email_hash = " . $this->db->sql_escape(phpbb_email_hash($this->install_config->get('board_email'))) . ",\n\t\t\t\t\tusername_clean = '" . $this->db->sql_escape(utf8_clean_string($this->install_config->get('admin_name'))) . "'\n\t\t\t\tWHERE username = '******'", 'UPDATE ' . $this->moderator_cache_table . "\n\t\t\t\tSET username = '******'admin_name')) . "'\n\t\t\t\tWHERE username = '******'", 'UPDATE ' . $this->forums_table . "\n\t\t\t\tSET forum_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE forum_last_poster_name = 'Admin'", 'UPDATE ' . $this->topics_table . "\n\t\t\t\tSET topic_first_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',\n\t\t\t\ttopic_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE topic_first_poster_name = 'Admin'\n\t\t\t\t\tOR topic_last_poster_name = 'Admin'", 'UPDATE ' . $this->user_table . "\n\t\t\t\tSET user_regdate = {$current_time}", 'UPDATE ' . $this->posts_table . "\n\t\t\t\tSET post_time = {$current_time}, poster_ip = '" . $this->db->sql_escape($user_ip) . "'", 'UPDATE ' . $this->topics_table . "\n\t\t\t\tSET topic_time = {$current_time}, topic_last_post_time = {$current_time}", 'UPDATE ' . $this->forums_table . "\n\t\t\t\tSET forum_last_post_time = {$current_time}", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->db->sql_server_info(true)) . "'\n\t\t\t\tWHERE config_name = 'dbms_version'");
     if (@extension_loaded('gd')) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = 'core.captcha.plugins.gd'\n\t\t\t\tWHERE config_name = 'captcha_plugin'";
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '1'\n\t\t\t\tWHERE config_name = 'captcha_gd'";
     }
     $ref = substr($referer, strpos($referer, '://') + 3);
     if (!(stripos($ref, $server_name) === 0)) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'referer_validation'";
     }
     // We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
     $cookie_name = 'phpbb3_';
     $rand_str = md5(mt_rand());
     $rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35));
     $rand_str = substr($rand_str, 0, 5);
     $cookie_name .= strtolower($rand_str);
     $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\tSET config_value = '" . $this->db->sql_escape($cookie_name) . "'\n\t\t\tWHERE config_name = 'cookie_name'";
     // Disable avatars if upload directory is not writable
     if (!$this->filesystem->is_writable($this->phpbb_root_path . 'images/avatars/upload/')) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'allow_avatar'";
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'allow_avatar_upload'";
     }
     $i = $this->install_config->get('add_config_settings_index', 0);
     $total = sizeof($sql_ary);
     $sql_ary = array_slice($sql_ary, $i);
     foreach ($sql_ary as $sql) {
         if (!$this->db->sql_query($sql)) {
             $error = $this->db->sql_error($this->db->get_sql_error_sql());
             $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
         }
         $i++;
         // Stop execution if resource limit is reached
         if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) {
             break;
         }
     }
     if ($i < $total) {
         $this->install_config->set('add_config_settings_index', $i);
         throw new resource_limit_reached_exception();
     }
 }
Exemplo n.º 22
0
 /**
  * Renders an error form
  *
  * @param string		$msg
  * @param string|bool	$desc
  */
 public function render_error($msg, $desc = false)
 {
     if ($this->request->is_ajax()) {
         $this->iohandler->add_error_message($msg, $desc);
         $this->iohandler->send_response(true);
     } else {
         $this->template->assign_vars(array('S_ERROR_BOX' => true, 'ERROR_TITLE' => $this->language->lang($msg)));
         if ($desc) {
             $this->template->assign_var('ERROR_MSG', $this->language->lang($desc));
         }
     }
 }
Exemplo n.º 23
0
 /**
  * Controller logic
  *
  * @return Response|StreamedResponse
  */
 public function handle()
 {
     if ($this->install_helper->is_phpbb_installed()) {
         die('phpBB is already installed');
     }
     $this->template->assign_vars(array('U_ACTION' => $this->controller_helper->route('phpbb_installer_install')));
     // Set up input-output handler
     if ($this->request->is_ajax()) {
         $this->iohandler_factory->set_environment('ajax');
     } else {
         $this->iohandler_factory->set_environment('nojs');
     }
     // Set the appropriate input-output handler
     $this->installer->set_iohandler($this->iohandler_factory->get());
     // Set up navigation
     $nav_data = $this->installer_config->get_navigation_data();
     /** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */
     $iohandler = $this->iohandler_factory->get();
     // Set active navigation stage
     if (isset($nav_data['active']) && is_array($nav_data['active'])) {
         $iohandler->set_active_stage_menu($nav_data['active']);
         $this->menu_provider->set_nav_property($nav_data['active'], array('selected' => true, 'completed' => false));
     }
     // Set finished navigation stages
     if (isset($nav_data['finished']) && is_array($nav_data['finished'])) {
         foreach ($nav_data['finished'] as $finished_stage) {
             $iohandler->set_finished_stage_menu($finished_stage);
             $this->menu_provider->set_nav_property($finished_stage, array('selected' => false, 'completed' => true));
         }
     }
     if ($this->request->is_ajax()) {
         $installer = $this->installer;
         $response = new StreamedResponse();
         $response->setCallback(function () use($installer) {
             $installer->run();
         });
         // Try to bypass any server output buffers
         $response->headers->set('X-Accel-Buffering', 'no');
         return $response;
     } else {
         // Determine whether the installation was started or not
         if (true) {
             $this->controller_helper->handle_language_select();
             // Set active stage
             $this->menu_provider->set_nav_property(array('install', 0, 'introduction'), array('selected' => true, 'completed' => false));
             // If not, let's render the welcome page
             $this->template->assign_vars(array('SHOW_INSTALL_START_FORM' => true, 'TITLE' => $this->language->lang('INSTALL_INTRO'), 'CONTENT' => $this->language->lang('INSTALL_INTRO_BODY')));
             return $this->controller_helper->render('installer_install.html', 'INSTALL', true);
         }
         // @todo: implement no js controller logic
     }
 }
Exemplo n.º 24
0
 /**
  * Load the user's notifications for a given method
  *
  * @param string $method_name
  * @param array $options Optional options to control what notifications are loaded
  *				notification_id		Notification id to load (or array of notification ids)
  *				user_id				User id to load notifications for (Default: $user->data['user_id'])
  *				order_by			Order by (Default: notification_time)
  *				order_dir			Order direction (Default: DESC)
  * 				limit				Number of notifications to load (Default: 5)
  * 				start				Notifications offset (Default: 0)
  * 				all_unread			Load all unread notifications? If set to true, count_unread is set to true (Default: false)
  * 				count_unread		Count all unread notifications? (Default: false)
  * 				count_total			Count all notifications? (Default: false)
  * @return array Array of information based on the request with keys:
  *	'notifications'		array of notification type objects
  *	'unread_count'		number of unread notifications the user has if count_unread is true in the options
  *	'total_count'		number of notifications the user has if count_total is true in the options
  * @throws \phpbb\notification\exception when the method doesn't refer to a class extending \phpbb\notification\method\method_interface
  */
 public function load_notifications($method_name, array $options = array())
 {
     $method = $this->get_method_class($method_name);
     if (!$method instanceof \phpbb\notification\method\method_interface) {
         throw new \phpbb\notification\exception($this->language->lang('NOTIFICATION_METHOD_INVALID', $method_name));
     } else {
         if ($method->is_available()) {
             return $method->load_notifications($options);
         } else {
             return array('notifications' => array(), 'unread_count' => 0, 'total_count' => 0);
         }
     }
 }
Exemplo n.º 25
0
 /**
  * Move file from another location to phpBB
  *
  * @param string $source_file Filename of source file
  * @param array|bool $filedata Array with filedata or false
  *
  * @return filespec Object "filespec" is returned, all further operations can be done with this object
  */
 protected function local_upload($source_file, $filedata = false)
 {
     $upload = $this->get_upload_ary($source_file, $filedata);
     /** @var filespec $file */
     $file = $this->factory->get('filespec')->set_upload_ary($upload)->set_upload_namespace($this->upload);
     if ($file->init_error()) {
         $file->error[] = '';
         return $file;
     }
     // PHP Upload file size check
     $file = $this->check_upload_size($file);
     if (sizeof($file->error)) {
         return $file;
     }
     // Not correctly uploaded
     if (!$file->is_uploaded()) {
         $file->error[] = $this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED');
         return $file;
     }
     $this->upload->common_checks($file);
     $this->request->overwrite('local', $upload, request_interface::FILES);
     return $file;
 }
Exemplo n.º 26
0
 /**
  * Check if there is enough free space available on disk
  *
  * @return bool True if disk space is available, false if not
  */
 protected function check_disk_space()
 {
     if ($free_space = @disk_free_space($this->phpbb_root_path . $this->config['upload_path'])) {
         if ($free_space <= $this->file->get('filesize')) {
             if ($this->auth->acl_get('a_')) {
                 $this->file_data['error'][] = $this->language->lang('ATTACH_DISK_FULL');
             } else {
                 $this->file_data['error'][] = $this->language->lang('ATTACH_QUOTA_REACHED');
             }
             $this->file_data['post_attach'] = false;
             $this->file->remove();
             return false;
         }
     }
     return true;
 }
Exemplo n.º 27
0
 /**
  * Display the details of the available updates
  *
  * @param SymfonyStyle	$io					IO handler, for formatted and unified IO
  * @param array			$updates_available	The list of the available updates
  */
 protected function display_versions(SymfonyStyle $io, $updates_available)
 {
     $io->section($this->language->lang('UPDATES_AVAILABLE'));
     $rows = [];
     foreach ($updates_available as $version_data) {
         $row = ['', '', ''];
         $row[0] = $version_data['current'];
         if (isset($version_data['announcement'])) {
             $row[1] = $version_data['announcement'];
         }
         if (isset($version_data['download'])) {
             $row[2] = $version_data['download'];
         }
         $rows[] = $row;
     }
     $io->table([$this->language->lang('VERSION'), $this->language->lang('ANNOUNCEMENT_TOPIC'), $this->language->lang('DOWNLOAD_LATEST')], $rows);
 }
Exemplo n.º 28
0
    /**
     * Submits a new idea.
     *
     * @param string $title   The title of the idea.
     * @param string $message    The description of the idea.
     * @param int    $user_id The ID of the author.
     *
     * @return array|int Either an array of errors, or the ID of the new idea.
     */
    public function submit($title, $message, $user_id)
    {
        $error = array();
        if (utf8_clean_string($title) === '') {
            $error[] = $this->language->lang('TITLE_TOO_SHORT');
        }
        if (utf8_strlen($title) > 64) {
            $error[] = $this->language->lang('TITLE_TOO_LONG');
        }
        if (utf8_strlen($message) < $this->config['min_post_chars']) {
            $error[] = $this->language->lang('TOO_FEW_CHARS');
        }
        if (utf8_strlen($message) > $this->config['max_post_chars']) {
            $error[] = $this->language->lang('TOO_MANY_CHARS');
        }
        if (count($error)) {
            return $error;
        }
        // Submit idea
        $sql_ary = array('idea_title' => $title, 'idea_author' => $user_id, 'idea_date' => time(), 'topic_id' => 0);
        $idea_id = $this->insert_idea_data($sql_ary, 'table_ideas');
        // Initial vote
        $idea = $this->get_idea($idea_id);
        $this->vote($idea, $this->user->data['user_id'], 1);
        $uid = $bitfield = $options = '';
        generate_text_for_storage($message, $uid, $bitfield, $options, true, true, true);
        $data = array('forum_id' => (int) $this->config['ideas_forum_id'], 'topic_id' => 0, 'icon_id' => false, 'poster_id' => (int) $this->config['ideas_poster_id'], 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $message, 'message_md5' => md5($message), 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'post_edit_locked' => 0, 'topic_title' => $title, 'notify_set' => false, 'notify' => false, 'post_time' => 0, 'forum_name' => 'Ideas forum', 'enable_indexing' => true, 'force_approved_state' => true);
        // Get Ideas Bot info
        $sql = 'SELECT *
			FROM ' . USERS_TABLE . '
			WHERE user_id = ' . (int) $this->config['ideas_poster_id'];
        $result = $this->db->sql_query_limit($sql, 1);
        $poster_bot = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        $poster_bot['is_registered'] = true;
        $tmpdata = $this->user->data;
        $this->user->data = $poster_bot;
        $poll = array();
        submit_post('post', $title, $this->user->data['username'], POST_NORMAL, $poll, $data);
        $this->user->data = $tmpdata;
        // Edit topic ID into idea; both should link to each other
        $sql_ary = array('topic_id' => $data['topic_id']);
        $this->update_idea_data($sql_ary, $idea_id, 'table_ideas');
        return $idea_id;
    }
Exemplo n.º 29
0
 /**
  * Show users as viewing Ideas on Who Is Online page
  *
  * @param \phpbb\event\data $event The event object
  * @return void
  * @access public
  */
 public function viewonline_ideas($event)
 {
     if ($event['on_page'][1] === 'app') {
         if (strrpos($event['row']['session_page'], 'app.' . $this->php_ext . '/ideas/post') === 0) {
             $event['location'] = $this->language->lang('POSTING_NEW_IDEA');
             $event['location_url'] = $this->helper->route('phpbb_ideas_index_controller');
         } else {
             if (strrpos($event['row']['session_page'], 'app.' . $this->php_ext . '/ideas') === 0) {
                 $event['location'] = $this->language->lang('VIEWING_IDEAS');
                 $event['location_url'] = $this->helper->route('phpbb_ideas_index_controller');
             }
         }
     } else {
         if ($event['on_page'][1] === 'viewtopic' && $event['row']['session_forum_id'] == $this->config['ideas_forum_id']) {
             $event['location'] = $this->language->lang('VIEWING_IDEAS');
             $event['location_url'] = $this->helper->route('phpbb_ideas_index_controller');
         }
     }
 }
Exemplo n.º 30
0
 /**
  * Render navigation
  */
 protected function render_navigation()
 {
     // Get navigation items
     $nav_array = $this->navigation_provider->get();
     $nav_array = $this->sort_navigation_level($nav_array);
     $active_main_menu = $this->get_active_main_menu($nav_array);
     // Pass navigation to template
     foreach ($nav_array as $key => $entry) {
         $this->template->assign_block_vars('t_block1', array('L_TITLE' => $this->language->lang($entry['label']), 'S_SELECTED' => $active_main_menu === $key, 'U_TITLE' => $this->route($entry['route'])));
         if (is_array($entry[0]) && $active_main_menu === $key) {
             $entry[0] = $this->sort_navigation_level($entry[0]);
             foreach ($entry[0] as $name => $sub_entry) {
                 if (isset($sub_entry['stage']) && $sub_entry['stage'] === true) {
                     $this->template->assign_block_vars('l_block2', array('L_TITLE' => $this->language->lang($sub_entry['label']), 'S_SELECTED' => isset($sub_entry['selected']) && $sub_entry['selected'] === true, 'S_COMPLETE' => isset($sub_entry['completed']) && $sub_entry['completed'] === true, 'STAGE_NAME' => $name));
                 } else {
                     $this->template->assign_block_vars('l_block1', array('L_TITLE' => $this->language->lang($sub_entry['label']), 'S_SELECTED' => isset($sub_entry['route']) && $sub_entry['route'] === $this->request->get('_route'), 'U_TITLE' => $this->route($sub_entry['route'])));
                 }
             }
         }
     }
 }