Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

add_config_settings.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 12.12 KiB


001  <?php
002  /**
003   *
004   * This file is part of the phpBB Forum Software package.
005   *
006   * @copyright (c) phpBB Limited <https://www.phpbb.com>
007   * @license GNU General Public License, version 2 (GPL-2.0)
008   *
009   * For full copyright and license information, please see
010   * the docs/CREDITS.txt file.
011   *
012   */
013   
014  namespace phpbb\install\module\install_database\task;
015   
016  use phpbb\install\exception\resource_limit_reached_exception;
017   
018  /**
019   * Create database schema
020   */
021  class add_config_settings extends \phpbb\install\task_base
022  {
023      /**
024       * @var \phpbb\db\driver\driver_interface
025       */
026      protected $db;
027   
028      /**
029       * @var \phpbb\filesystem\filesystem_interface
030       */
031      protected $filesystem;
032   
033      /**
034       * @var \phpbb\install\helper\config
035       */
036      protected $install_config;
037   
038      /**
039       * @var \phpbb\install\helper\iohandler\iohandler_interface
040       */
041      protected $iohandler;
042   
043      /**
044       * @var \phpbb\language\language
045       */
046      protected $language;
047   
048      /**
049       * @var \phpbb\passwords\manager
050       */
051      protected $password_manager;
052   
053      /**
054       * @var string
055       */
056      protected $phpbb_root_path;
057   
058      /**
059       * @var string
060       */
061      protected $config_table;
062   
063      /**
064       * @var string
065       */
066      protected $user_table;
067   
068      /**
069       * @var string
070       */
071      protected $topics_table;
072   
073      /**
074       * @var string
075       */
076      protected $forums_table;
077   
078      /**
079       * @var string
080       */
081      protected $posts_table;
082   
083      /**
084       * @var string
085       */
086      protected $moderator_cache_table;
087   
088      /**
089       * Constructor
090       *
091       * @param \phpbb\filesystem\filesystem_interface                $filesystem            Filesystem service
092       * @param \phpbb\install\helper\config                            $install_config        Installer's config helper
093       * @param \phpbb\install\helper\iohandler\iohandler_interface    $iohandler            Installer's input-output handler
094       * @param \phpbb\install\helper\container_factory                $container            Installer's DI container
095       * @param \phpbb\language\language                                $language            Language service
096       * @param string                                                $phpbb_root_path    Path to phpBB's root
097       */
098      public function __construct(\phpbb\filesystem\filesystem_interface $filesystem,
099                                  \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('img_imagick')) . "'
155                  WHERE config_name = 'img_imagick'",
156   
157              'UPDATE ' . $this->config_table . "
158                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('server_name')) . "'
159                  WHERE config_name = 'server_name'",
160   
161              'UPDATE ' . $this->config_table . "
162                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('server_port')) . "'
163                  WHERE config_name = 'server_port'",
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_email'",
168   
169              'UPDATE ' . $this->config_table . "
170                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'
171                  WHERE config_name = 'board_contact'",
172   
173              'UPDATE ' . $this->config_table . "
174                  SET config_value = '" . $this->db->sql_escape($cookie_domain) . "'
175                  WHERE config_name = 'cookie_domain'",
176   
177              'UPDATE ' . $this->config_table . "
178                  SET config_value = '" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "'
179                  WHERE config_name = 'default_dateformat'",
180   
181              'UPDATE ' . $this->config_table . "
182                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('email_enable')) . "'
183                  WHERE config_name = 'email_enable'",
184   
185              'UPDATE ' . $this->config_table . "
186                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_delivery')) . "'
187                  WHERE config_name = 'smtp_delivery'",
188   
189              'UPDATE ' . $this->config_table . "
190                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_host')) . "'
191                  WHERE config_name = 'smtp_host'",
192   
193              'UPDATE ' . $this->config_table . "
194                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_port')) . "'
195                  WHERE config_name = 'smtp_port'",
196   
197              'UPDATE ' . $this->config_table . "
198                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_auth')) . "'
199                  WHERE config_name = 'smtp_auth_method'",
200   
201              'UPDATE ' . $this->config_table . "
202                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_user')) . "'
203                  WHERE config_name = 'smtp_username'",
204   
205              'UPDATE ' . $this->config_table . "
206                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_pass')) . "'
207                  WHERE config_name = 'smtp_password'",
208   
209              'UPDATE ' . $this->config_table . "
210                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('cookie_secure')) . "'
211                  WHERE config_name = 'cookie_secure'",
212   
213              'UPDATE ' . $this->config_table . "
214                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('force_server_vars')) . "'
215                  WHERE config_name = 'force_server_vars'",
216   
217              'UPDATE ' . $this->config_table . "
218                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('script_path')) . "'
219                  WHERE config_name = 'script_path'",
220   
221              'UPDATE ' . $this->config_table . "
222                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('server_protocol')) . "'
223                  WHERE config_name = 'server_protocol'",
224   
225              'UPDATE ' . $this->config_table . "
226                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
227                  WHERE config_name = 'newest_username'",
228   
229              'UPDATE ' . $this->config_table . "
230                  SET config_value = '" . md5(mt_rand()) . "'
231                  WHERE config_name = 'avatar_salt'",
232   
233              'UPDATE ' . $this->config_table . "
234                  SET config_value = '" . md5(mt_rand()) . "'
235                  WHERE config_name = 'plupload_salt'",
236   
237              'UPDATE ' . $this->config_table . "
238                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_name')) . "'
239                  WHERE config_name = 'sitename'",
240   
241              'UPDATE ' . $this->config_table . "
242                  SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_description')) . "'
243                  WHERE config_name = 'site_desc'",
244   
245              'UPDATE ' . $this->user_table . "
246                  SET username = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',
247                      user_password='" . $this->password_manager->hash($this->install_config->get('admin_passwd')) . "',
248                      user_ip = '" . $this->db->sql_escape($user_ip) . "',
249                      user_lang = '" . $this->db->sql_escape($this->install_config->get('user_language', 'en')) . "',
250                      user_email='" . $this->db->sql_escape($this->install_config->get('board_email')) . "',
251                      user_dateformat='" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "',
252                      user_email_hash = " . $this->db->sql_escape(phpbb_email_hash($this->install_config->get('board_email'))) . ",
253                      username_clean = '" . $this->db->sql_escape(utf8_clean_string($this->install_config->get('admin_name'))) . "'
254                  WHERE username = 'Admin'",
255   
256              'UPDATE ' . $this->moderator_cache_table . "
257                  SET username = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
258                  WHERE username = 'Admin'",
259   
260              'UPDATE ' . $this->forums_table . "
261                  SET forum_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
262                  WHERE forum_last_poster_name = 'Admin'",
263   
264              'UPDATE ' . $this->topics_table . "
265                  SET topic_first_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',
266                  topic_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
267                  WHERE topic_first_poster_name = 'Admin'
268                      OR topic_last_poster_name = 'Admin'",
269   
270              'UPDATE ' . $this->user_table . "
271                  SET user_regdate = $current_time",
272   
273              'UPDATE ' . $this->posts_table . "
274                  SET post_time = $current_time, poster_ip = '" . $this->db->sql_escape($user_ip) . "'",
275   
276              'UPDATE ' . $this->topics_table . "
277                  SET topic_time = $current_time, topic_last_post_time = $current_time",
278   
279              'UPDATE ' . $this->forums_table . "
280                  SET forum_last_post_time = $current_time",
281   
282              'UPDATE ' . $this->config_table . "
283                  SET config_value = '" . $this->db->sql_escape($this->db->sql_server_info(true)) . "'
284                  WHERE config_name = 'dbms_version'",
285          );
286   
287          if (@extension_loaded('gd'))
288          {
289              $sql_ary[] = 'UPDATE ' . $this->config_table . "
290                  SET config_value = 'core.captcha.plugins.gd'
291                  WHERE config_name = 'captcha_plugin'";
292   
293              $sql_ary[] = 'UPDATE ' . $this->config_table . "
294                  SET config_value = '1'
295                  WHERE config_name = 'captcha_gd'";
296          }
297   
298          $ref = substr($referer, strpos($referer, '://') + 3);
299          if (!(stripos($ref, $server_name) === 0))
300          {
301              $sql_ary[] = 'UPDATE ' . $this->config_table . "
302                  SET config_value = '0'
303                  WHERE config_name = 'referer_validation'";
304          }
305   
306          // We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
307          $cookie_name = 'phpbb3_';
308          $rand_str = md5(mt_rand());
309          $rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35));
310          $rand_str = substr($rand_str, 0, 5);
311          $cookie_name .= strtolower($rand_str);
312   
313          $sql_ary[] = 'UPDATE ' . $this->config_table . "
314              SET config_value = '" . $this->db->sql_escape($cookie_name) . "'
315              WHERE config_name = 'cookie_name'";
316   
317          // Disable avatars if upload directory is not writable
318          if (!$this->filesystem->is_writable($this->phpbb_root_path . 'images/avatars/upload/'))
319          {
320              $sql_ary[] = 'UPDATE ' . $this->config_table . "
321                  SET config_value = '0'
322                  WHERE config_name = 'allow_avatar'";
323   
324              $sql_ary[] = 'UPDATE ' . $this->config_table . "
325                  SET config_value = '0'
326                  WHERE config_name = 'allow_avatar_upload'";
327          }
328   
329          $i = $this->install_config->get('add_config_settings_index', 0);
330          $total = sizeof($sql_ary);
331          $sql_ary = array_slice($sql_ary, $i);
332   
333          foreach ($sql_ary as $sql)
334          {
335              if (!$this->db->sql_query($sql))
336              {
337                  $error = $this->db->sql_error($this->db->get_sql_error_sql());
338                  $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
339              }
340   
341              $i++;
342   
343              // Stop execution if resource limit is reached
344              if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0)
345              {
346                  break;
347              }
348          }
349   
350          if ($i < $total)
351          {
352              $this->install_config->set('add_config_settings_index', $i);
353              throw new resource_limit_reached_exception();
354          }
355      }
356   
357      /**
358       * {@inheritdoc}
359       */
360      static public function get_step_count()
361      {
362          return 1;
363      }
364   
365      /**
366       * {@inheritdoc}
367       */
368      public function get_task_lang_name()
369      {
370          return 'TASK_ADD_CONFIG_SETTINGS';
371      }
372  }
373