[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/phpbb/install/module/install_database/task/ -> add_config_settings.php (source)

   1  <?php
   2  /**
   3   *
   4   * This file is part of the phpBB Forum Software package.
   5   *
   6   * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7   * @license GNU General Public License, version 2 (GPL-2.0)
   8   *
   9   * For full copyright and license information, please see
  10   * the docs/CREDITS.txt file.
  11   *
  12   */
  13  
  14  namespace phpbb\install\module\install_database\task;
  15  
  16  use phpbb\install\exception\resource_limit_reached_exception;
  17  
  18  /**
  19   * Create database schema
  20   */
  21  class add_config_settings extends \phpbb\install\task_base
  22  {
  23      /**
  24       * @var \phpbb\db\driver\driver_interface
  25       */
  26      protected $db;
  27  
  28      /**
  29       * @var \phpbb\filesystem\filesystem_interface
  30       */
  31      protected $filesystem;
  32  
  33      /**
  34       * @var \phpbb\install\helper\config
  35       */
  36      protected $install_config;
  37  
  38      /**
  39       * @var \phpbb\install\helper\iohandler\iohandler_interface
  40       */
  41      protected $iohandler;
  42  
  43      /**
  44       * @var \phpbb\language\language
  45       */
  46      protected $language;
  47  
  48      /**
  49       * @var \phpbb\passwords\manager
  50       */
  51      protected $password_manager;
  52  
  53      /**
  54       * @var string
  55       */
  56      protected $phpbb_root_path;
  57  
  58      /**
  59       * @var string
  60       */
  61      protected $config_table;
  62  
  63      /**
  64       * @var string
  65       */
  66      protected $user_table;
  67  
  68      /**
  69       * @var string
  70       */
  71      protected $topics_table;
  72  
  73      /**
  74       * @var string
  75       */
  76      protected $forums_table;
  77  
  78      /**
  79       * @var string
  80       */
  81      protected $posts_table;
  82  
  83      /**
  84       * @var string
  85       */
  86      protected $moderator_cache_table;
  87  
  88      /**
  89       * Constructor
  90       *
  91       * @param \phpbb\filesystem\filesystem_interface                $filesystem            Filesystem service
  92       * @param \phpbb\install\helper\config                            $install_config        Installer's config helper
  93       * @param \phpbb\install\helper\iohandler\iohandler_interface    $iohandler            Installer's input-output handler
  94       * @param \phpbb\install\helper\container_factory                $container            Installer's DI container
  95       * @param \phpbb\language\language                                $language            Language service
  96       * @param string                                                $phpbb_root_path    Path to phpBB's root
  97       */
  98  	public function __construct(\phpbb\filesystem\filesystem_interface $filesystem,
  99                                  \phpbb\install\helper\config $install_config,
 100                                  \phpbb\install\helper\iohandler\iohandler_interface $iohandler,
 101                                  \phpbb\install\helper\container_factory $container,
 102                                  \phpbb\language\language $language,
 103                                  $phpbb_root_path)
 104      {
 105          $this->db                = $container->get('dbal.conn');
 106          $this->filesystem        = $filesystem;
 107          $this->install_config    = $install_config;
 108          $this->iohandler        = $iohandler;
 109          $this->language            = $language;
 110          $this->password_manager    = $container->get('passwords.manager');
 111          $this->phpbb_root_path    = $phpbb_root_path;
 112  
 113          // Table names
 114          $this->config_table                = $container->get_parameter('tables.config');
 115          $this->forums_table                = $container->get_parameter('tables.forums');
 116          $this->topics_table                = $container->get_parameter('tables.topics');
 117          $this->user_table                = $container->get_parameter('tables.users');
 118          $this->moderator_cache_table    = $container->get_parameter('tables.moderator_cache');
 119          $this->posts_table                = $container->get_parameter('tables.posts');
 120  
 121          parent::__construct(true);
 122      }
 123  
 124      /**
 125       * {@inheritdoc}
 126       */
 127  	public function run()
 128      {
 129          $this->db->sql_return_on_error(true);
 130  
 131          $server_name    = $this->install_config->get('server_name');
 132          $current_time     = time();
 133          $user_ip        = phpbb_ip_normalise($this->iohandler->get_server_variable('REMOTE_ADDR'));
 134          $user_ip        = ($user_ip === false) ? '' : $user_ip;
 135          $referer        = $this->iohandler->get_server_variable('REFERER');
 136  
 137          // Calculate cookie domain
 138          $cookie_domain = $server_name;
 139  
 140          if (strpos($cookie_domain, 'www.') === 0)
 141          {
 142              $cookie_domain = substr($cookie_domain, 3);
 143          }
 144  
 145          // Set default config and post data, this applies to all DB's
 146          $sql_ary = array(
 147              'INSERT INTO ' . $this->config_table . " (config_name, config_value)
 148                  VALUES ('board_startdate', '$current_time')",
 149  
 150              'INSERT INTO ' . $this->config_table . " (config_name, config_value)
 151                  VALUES ('default_lang', '" . $this->db->sql_escape($this->install_config->get('default_lang')) . "')",
 152  
 153              'UPDATE ' . $this->config_table . "
 154                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('server_name')) . "'
 155                  WHERE config_name = 'server_name'",
 156  
 157              'UPDATE ' . $this->config_table . "
 158                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('server_port')) . "'
 159                  WHERE config_name = 'server_port'",
 160  
 161              'UPDATE ' . $this->config_table . "
 162                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'
 163                  WHERE config_name = 'board_email'",
 164  
 165              'UPDATE ' . $this->config_table . "
 166                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'
 167                  WHERE config_name = 'board_contact'",
 168  
 169              'UPDATE ' . $this->config_table . "
 170                  SET config_value = '" . $this->db->sql_escape($cookie_domain) . "'
 171                  WHERE config_name = 'cookie_domain'",
 172  
 173              'UPDATE ' . $this->config_table . "
 174                  SET config_value = '" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "'
 175                  WHERE config_name = 'default_dateformat'",
 176  
 177              'UPDATE ' . $this->config_table . "
 178                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('email_enable')) . "'
 179                  WHERE config_name = 'email_enable'",
 180  
 181              'UPDATE ' . $this->config_table . "
 182                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_delivery')) . "'
 183                  WHERE config_name = 'smtp_delivery'",
 184  
 185              'UPDATE ' . $this->config_table . "
 186                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_host')) . "'
 187                  WHERE config_name = 'smtp_host'",
 188  
 189              'UPDATE ' . $this->config_table . "
 190                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_port')) . "'
 191                  WHERE config_name = 'smtp_port'",
 192  
 193              'UPDATE ' . $this->config_table . "
 194                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_auth')) . "'
 195                  WHERE config_name = 'smtp_auth_method'",
 196  
 197              'UPDATE ' . $this->config_table . "
 198                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_user')) . "'
 199                  WHERE config_name = 'smtp_username'",
 200  
 201              'UPDATE ' . $this->config_table . "
 202                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_pass')) . "'
 203                  WHERE config_name = 'smtp_password'",
 204  
 205              'UPDATE ' . $this->config_table . "
 206                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('cookie_secure')) . "'
 207                  WHERE config_name = 'cookie_secure'",
 208  
 209              'UPDATE ' . $this->config_table . "
 210                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('force_server_vars')) . "'
 211                  WHERE config_name = 'force_server_vars'",
 212  
 213              'UPDATE ' . $this->config_table . "
 214                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('script_path')) . "'
 215                  WHERE config_name = 'script_path'",
 216  
 217              'UPDATE ' . $this->config_table . "
 218                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('server_protocol')) . "'
 219                  WHERE config_name = 'server_protocol'",
 220  
 221              'UPDATE ' . $this->config_table . "
 222                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
 223                  WHERE config_name = 'newest_username'",
 224  
 225              'UPDATE ' . $this->config_table . "
 226                  SET config_value = '" . md5(mt_rand()) . "'
 227                  WHERE config_name = 'avatar_salt'",
 228  
 229              'UPDATE ' . $this->config_table . "
 230                  SET config_value = '" . md5(mt_rand()) . "'
 231                  WHERE config_name = 'plupload_salt'",
 232  
 233              'UPDATE ' . $this->config_table . "
 234                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_name')) . "'
 235                  WHERE config_name = 'sitename'",
 236  
 237              'UPDATE ' . $this->config_table . "
 238                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_description')) . "'
 239                  WHERE config_name = 'site_desc'",
 240  
 241              'UPDATE ' . $this->user_table . "
 242                  SET username = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',
 243                      user_password='" . $this->password_manager->hash($this->install_config->get('admin_passwd')) . "',
 244                      user_ip = '" . $this->db->sql_escape($user_ip) . "',
 245                      user_lang = '" . $this->db->sql_escape($this->install_config->get('user_language', 'en')) . "',
 246                      user_email='" . $this->db->sql_escape($this->install_config->get('board_email')) . "',
 247                      user_dateformat='" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "',
 248                      user_email_hash = " . $this->db->sql_escape(phpbb_email_hash($this->install_config->get('board_email'))) . ",
 249                      username_clean = '" . $this->db->sql_escape(utf8_clean_string($this->install_config->get('admin_name'))) . "'
 250                  WHERE username = 'Admin'",
 251  
 252              'UPDATE ' . $this->moderator_cache_table . "
 253                  SET username = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
 254                  WHERE username = 'Admin'",
 255  
 256              'UPDATE ' . $this->forums_table . "
 257                  SET forum_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
 258                  WHERE forum_last_poster_name = 'Admin'",
 259  
 260              'UPDATE ' . $this->topics_table . "
 261                  SET topic_first_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',
 262                  topic_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
 263                  WHERE topic_first_poster_name = 'Admin'
 264                      OR topic_last_poster_name = 'Admin'",
 265  
 266              'UPDATE ' . $this->user_table . "
 267                  SET user_regdate = $current_time",
 268  
 269              'UPDATE ' . $this->posts_table . "
 270                  SET post_time = $current_time, poster_ip = '" . $this->db->sql_escape($user_ip) . "'",
 271  
 272              'UPDATE ' . $this->topics_table . "
 273                  SET topic_time = $current_time, topic_last_post_time = $current_time",
 274  
 275              'UPDATE ' . $this->forums_table . "
 276                  SET forum_last_post_time = $current_time",
 277  
 278              'UPDATE ' . $this->config_table . "
 279                  SET config_value = '" . $this->db->sql_escape($this->db->sql_server_info(true)) . "'
 280                  WHERE config_name = 'dbms_version'",
 281          );
 282  
 283          if (@extension_loaded('gd'))
 284          {
 285              $sql_ary[] = 'UPDATE ' . $this->config_table . "
 286                  SET config_value = 'core.captcha.plugins.gd'
 287                  WHERE config_name = 'captcha_plugin'";
 288  
 289              $sql_ary[] = 'UPDATE ' . $this->config_table . "
 290                  SET config_value = '1'
 291                  WHERE config_name = 'captcha_gd'";
 292          }
 293  
 294          $ref = substr($referer, strpos($referer, '://') + 3);
 295          if (!(stripos($ref, $server_name) === 0))
 296          {
 297              $sql_ary[] = 'UPDATE ' . $this->config_table . "
 298                  SET config_value = '0'
 299                  WHERE config_name = 'referer_validation'";
 300          }
 301  
 302          // We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
 303          $cookie_name = 'phpbb3_';
 304          $rand_str = md5(mt_rand());
 305          $rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35));
 306          $rand_str = substr($rand_str, 0, 5);
 307          $cookie_name .= strtolower($rand_str);
 308  
 309          $sql_ary[] = 'UPDATE ' . $this->config_table . "
 310              SET config_value = '" . $this->db->sql_escape($cookie_name) . "'
 311              WHERE config_name = 'cookie_name'";
 312  
 313          // Disable avatars if upload directory is not writable
 314          if (!$this->filesystem->is_writable($this->phpbb_root_path . 'images/avatars/upload/'))
 315          {
 316              $sql_ary[] = 'UPDATE ' . $this->config_table . "
 317                  SET config_value = '0'
 318                  WHERE config_name = 'allow_avatar'";
 319  
 320              $sql_ary[] = 'UPDATE ' . $this->config_table . "
 321                  SET config_value = '0'
 322                  WHERE config_name = 'allow_avatar_upload'";
 323          }
 324  
 325          $i = $this->install_config->get('add_config_settings_index', 0);
 326          $total = count($sql_ary);
 327          $sql_ary = array_slice($sql_ary, $i);
 328  
 329          foreach ($sql_ary as $sql)
 330          {
 331              if (!$this->db->sql_query($sql))
 332              {
 333                  $error = $this->db->sql_error($this->db->get_sql_error_sql());
 334                  $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
 335              }
 336  
 337              $i++;
 338  
 339              // Stop execution if resource limit is reached
 340              if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0)
 341              {
 342                  break;
 343              }
 344          }
 345  
 346          if ($i < $total)
 347          {
 348              $this->install_config->set('add_config_settings_index', $i);
 349              throw new resource_limit_reached_exception();
 350          }
 351      }
 352  
 353      /**
 354       * {@inheritdoc}
 355       */
 356  	static public function get_step_count()
 357      {
 358          return 1;
 359      }
 360  
 361      /**
 362       * {@inheritdoc}
 363       */
 364  	public function get_task_lang_name()
 365      {
 366          return 'TASK_ADD_CONFIG_SETTINGS';
 367      }
 368  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1