Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 400
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
acp_main
0.00% covered (danger)
0.00%
0 / 398
0.00% covered (danger)
0.00%
0 / 2
7482
0.00% covered (danger)
0.00%
0 / 1
 main
0.00% covered (danger)
0.00%
0 / 392
0.00% covered (danger)
0.00%
0 / 1
6972
 check_captcha_type
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
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/**
15* @ignore
16*/
17if (!defined('IN_PHPBB'))
18{
19    exit;
20}
21
22class acp_main
23{
24    var $u_action;
25    private $php_ini;
26
27    function main($id, $mode)
28    {
29        global $config, $db, $cache, $user, $auth, $template, $request, $phpbb_log;
30        global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container, $phpbb_dispatcher, $phpbb_filesystem;
31
32        // Show restore permissions notice
33        if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm'))
34        {
35            $this->tpl_name = 'acp_main';
36            $this->page_title = 'ACP_MAIN';
37
38            $sql = 'SELECT user_id, username, user_colour
39                FROM ' . USERS_TABLE . '
40                WHERE user_id = ' . $user->data['user_perm_from'];
41            $result = $db->sql_query($sql);
42            $user_row = $db->sql_fetchrow($result);
43            $db->sql_freeresult($result);
44
45            $perm_from = get_username_string('full', $user_row['user_id'], $user_row['username'], $user_row['user_colour']);
46
47            $template->assign_vars(array(
48                'S_RESTORE_PERMISSIONS'        => true,
49                'U_RESTORE_PERMISSIONS'        => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm'),
50                'PERM_FROM'                    => $perm_from,
51                'L_PERMISSIONS_TRANSFERRED_EXPLAIN'    => sprintf($user->lang['PERMISSIONS_TRANSFERRED_EXPLAIN'], $perm_from, append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm')),
52            ));
53
54            return;
55        }
56
57        $action = $request->variable('action', '');
58
59        if ($action)
60        {
61            if ($action === 'admlogout')
62            {
63                if (check_link_hash($request->variable('hash', ''), 'acp_logout'))
64                {
65                    $user->unset_admin();
66                    redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
67                }
68                else
69                {
70                    redirect(append_sid("{$phpbb_admin_path}index.$phpEx"));
71                }
72            }
73
74            if (!confirm_box(true))
75            {
76                switch ($action)
77                {
78                    case 'online':
79                        $confirm = true;
80                        $confirm_lang = 'RESET_ONLINE_CONFIRM';
81                    break;
82                    case 'stats':
83                        $confirm = true;
84                        $confirm_lang = 'RESYNC_STATS_CONFIRM';
85                    break;
86                    case 'user':
87                        $confirm = true;
88                        $confirm_lang = 'RESYNC_POSTCOUNTS_CONFIRM';
89                    break;
90                    case 'date':
91                        $confirm = true;
92                        $confirm_lang = 'RESET_DATE_CONFIRM';
93                    break;
94                    case 'db_track':
95                        $confirm = true;
96                        $confirm_lang = 'RESYNC_POST_MARKING_CONFIRM';
97                    break;
98                    case 'purge_cache':
99                        $confirm = true;
100                        $confirm_lang = 'PURGE_CACHE_CONFIRM';
101                    break;
102                    case 'purge_sessions':
103                        $confirm = true;
104                        $confirm_lang = 'PURGE_SESSIONS_CONFIRM';
105                    break;
106
107                    default:
108                        $confirm = true;
109                        $confirm_lang = 'CONFIRM_OPERATION';
110                }
111
112                if ($confirm)
113                {
114                    confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array(
115                        'i'            => $id,
116                        'mode'        => $mode,
117                        'action'    => $action,
118                    )));
119                }
120            }
121            else
122            {
123                switch ($action)
124                {
125
126                    case 'online':
127                        if (!$auth->acl_get('a_board'))
128                        {
129                            send_status_line(403, 'Forbidden');
130                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
131                        }
132
133                        $config->set('record_online_users', 1, false);
134                        $config->set('record_online_date', time(), false);
135                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESET_ONLINE');
136
137                        if ($request->is_ajax())
138                        {
139                            trigger_error('RESET_ONLINE_SUCCESS');
140                        }
141                    break;
142
143                    case 'stats':
144                        if (!$auth->acl_get('a_board'))
145                        {
146                            send_status_line(403, 'Forbidden');
147                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
148                        }
149
150                        $sql = 'SELECT COUNT(post_id) AS stat
151                            FROM ' . POSTS_TABLE . '
152                            WHERE post_visibility = ' . ITEM_APPROVED;
153                        $result = $db->sql_query($sql);
154                        $config->set('num_posts', (int) $db->sql_fetchfield('stat'), false);
155                        $db->sql_freeresult($result);
156
157                        $sql = 'SELECT COUNT(topic_id) AS stat
158                            FROM ' . TOPICS_TABLE . '
159                            WHERE topic_visibility = ' . ITEM_APPROVED;
160                        $result = $db->sql_query($sql);
161                        $config->set('num_topics', (int) $db->sql_fetchfield('stat'), false);
162                        $db->sql_freeresult($result);
163
164                        $sql = 'SELECT COUNT(user_id) AS stat
165                            FROM ' . USERS_TABLE . '
166                            WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')';
167                        $result = $db->sql_query($sql);
168                        $config->set('num_users', (int) $db->sql_fetchfield('stat'), false);
169                        $db->sql_freeresult($result);
170
171                        $sql = 'SELECT COUNT(attach_id) as stat
172                            FROM ' . ATTACHMENTS_TABLE . '
173                            WHERE is_orphan = 0';
174                        $result = $db->sql_query($sql);
175                        $config->set('num_files', (int) $db->sql_fetchfield('stat'), false);
176                        $db->sql_freeresult($result);
177
178                        $sql = 'SELECT SUM(filesize) as stat
179                            FROM ' . ATTACHMENTS_TABLE . '
180                            WHERE is_orphan = 0';
181                        $result = $db->sql_query($sql);
182                        $config->set('upload_dir_size', (float) $db->sql_fetchfield('stat'), false);
183                        $db->sql_freeresult($result);
184
185                        if (!function_exists('update_last_username'))
186                        {
187                            include($phpbb_root_path . "includes/functions_user.$phpEx");
188                        }
189                        update_last_username();
190
191                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESYNC_STATS');
192
193                        if ($request->is_ajax())
194                        {
195                            trigger_error('RESYNC_STATS_SUCCESS');
196                        }
197                    break;
198
199                    case 'user':
200                        if (!$auth->acl_get('a_board'))
201                        {
202                            send_status_line(403, 'Forbidden');
203                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
204                        }
205
206                        // Resync post counts
207
208                        // Find the maximum post ID, we can only stop the cycle when we've reached it
209                        $sql = 'SELECT MAX(forum_last_post_id) as max_post_id
210                            FROM ' . FORUMS_TABLE;
211                        $result = $db->sql_query($sql);
212                        $max_post_id = (int) $db->sql_fetchfield('max_post_id');
213                        $db->sql_freeresult($result);
214
215                        // No maximum post id? :o
216                        if (!$max_post_id)
217                        {
218                            $sql = 'SELECT MAX(post_id) as max_post_id
219                                FROM ' . POSTS_TABLE;
220                            $result = $db->sql_query($sql);
221                            $max_post_id = (int) $db->sql_fetchfield('max_post_id');
222                            $db->sql_freeresult($result);
223                        }
224
225                        // Still no maximum post id? Then we are finished
226                        if (!$max_post_id)
227                        {
228                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESYNC_POSTCOUNTS');
229                            break;
230                        }
231
232                        $step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
233                        $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0');
234
235                        $start = 0;
236                        while ($start < $max_post_id)
237                        {
238                            $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
239                                FROM ' . POSTS_TABLE . '
240                                WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
241                                    AND post_postcount = 1 AND post_visibility = ' . ITEM_APPROVED . '
242                                GROUP BY poster_id';
243                            $result = $db->sql_query($sql);
244
245                            if ($row = $db->sql_fetchrow($result))
246                            {
247                                do
248                                {
249                                    $sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
250                                    $db->sql_query($sql);
251                                }
252                                while ($row = $db->sql_fetchrow($result));
253                            }
254                            $db->sql_freeresult($result);
255
256                            $start += $step;
257                        }
258
259                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESYNC_POSTCOUNTS');
260
261                        if ($request->is_ajax())
262                        {
263                            trigger_error('RESYNC_POSTCOUNTS_SUCCESS');
264                        }
265                    break;
266
267                    case 'date':
268                        if (!$auth->acl_get('a_board'))
269                        {
270                            send_status_line(403, 'Forbidden');
271                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
272                        }
273
274                        $config->set('board_startdate', time() - 1);
275                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESET_DATE');
276
277                        if ($request->is_ajax())
278                        {
279                            trigger_error('RESET_DATE_SUCCESS');
280                        }
281                    break;
282
283                    case 'db_track':
284                        $db_tools = $phpbb_container->get('dbal.tools');
285                        $db_tools->sql_truncate_table(TOPICS_POSTED_TABLE);
286
287                        // This can get really nasty... therefore we only do the last six months
288                        $get_from_time = time() - (6 * 4 * 7 * 24 * 60 * 60);
289
290                        // Select forum ids, do not include categories
291                        $sql = 'SELECT forum_id
292                            FROM ' . FORUMS_TABLE . '
293                            WHERE forum_type <> ' . FORUM_CAT;
294                        $result = $db->sql_query($sql);
295
296                        $forum_ids = array();
297                        while ($row = $db->sql_fetchrow($result))
298                        {
299                            $forum_ids[] = $row['forum_id'];
300                        }
301                        $db->sql_freeresult($result);
302
303                        // Any global announcements? ;)
304                        $forum_ids[] = 0;
305
306                        // Now go through the forums and get us some topics...
307                        foreach ($forum_ids as $forum_id)
308                        {
309                            $sql = 'SELECT p.poster_id, p.topic_id
310                                FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
311                                WHERE t.forum_id = ' . $forum_id . '
312                                    AND t.topic_moved_id = 0
313                                    AND t.topic_last_post_time > ' . $get_from_time . '
314                                    AND t.topic_id = p.topic_id
315                                    AND p.poster_id <> ' . ANONYMOUS . '
316                                GROUP BY p.poster_id, p.topic_id';
317                            $result = $db->sql_query($sql);
318
319                            $posted = array();
320                            while ($row = $db->sql_fetchrow($result))
321                            {
322                                $posted[$row['poster_id']][] = $row['topic_id'];
323                            }
324                            $db->sql_freeresult($result);
325
326                            $sql_ary = array();
327                            foreach ($posted as $user_id => $topic_row)
328                            {
329                                foreach ($topic_row as $topic_id)
330                                {
331                                    $sql_ary[] = array(
332                                        'user_id'        => (int) $user_id,
333                                        'topic_id'        => (int) $topic_id,
334                                        'topic_posted'    => 1,
335                                    );
336                                }
337                            }
338                            unset($posted);
339
340                            if (count($sql_ary))
341                            {
342                                $db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
343                            }
344                        }
345
346                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESYNC_POST_MARKING');
347
348                        if ($request->is_ajax())
349                        {
350                            trigger_error('RESYNC_POST_MARKING_SUCCESS');
351                        }
352                    break;
353
354                    case 'purge_cache':
355                        $config->increment('assets_version', 1);
356                        $cache->purge();
357
358                        // Remove old renderers from the text_formatter service. Since this
359                        // operation is performed after the cache is purged, there is not "current"
360                        // renderer and in effect all renderers will be purged
361                        $phpbb_container->get('text_formatter.cache')->tidy();
362
363                        // Clear permissions
364                        $auth->acl_clear_prefetch();
365                        phpbb_cache_moderators($db, $phpbb_container->get('dbal.tools'), $cache, $auth);
366
367                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PURGE_CACHE');
368
369                        if ($request->is_ajax())
370                        {
371                            trigger_error('PURGE_CACHE_SUCCESS');
372                        }
373                    break;
374
375                    case 'purge_sessions':
376                        if ((int) $user->data['user_type'] !== USER_FOUNDER)
377                        {
378                            send_status_line(403, 'Forbidden');
379                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
380                        }
381
382                        $tables = array(CONFIRM_TABLE, SESSIONS_TABLE);
383                        $db_tools = $phpbb_container->get('dbal.tools');
384
385                        foreach ($tables as $table)
386                        {
387                            $db_tools->sql_truncate_table($table);
388                        }
389
390                        // let's restore the admin session
391                        $reinsert_ary = array(
392                                'session_id'            => (string) $user->session_id,
393                                'session_page'            => (string) substr($user->page['page'], 0, 199),
394                                'session_forum_id'        => $user->page['forum'],
395                                'session_user_id'        => (int) $user->data['user_id'],
396                                'session_start'            => (int) $user->data['session_start'],
397                                'session_last_visit'    => (int) $user->data['session_last_visit'],
398                                'session_time'            => (int) $user->time_now,
399                                'session_browser'        => (string) trim(substr($user->browser, 0, 149)),
400                                'session_forwarded_for'    => (string) $user->forwarded_for,
401                                'session_ip'            => (string) $user->ip,
402                                'session_autologin'        => (int) $user->data['session_autologin'],
403                                'session_admin'            => 1,
404                                'session_viewonline'    => (int) $user->data['session_viewonline'],
405                        );
406
407                        $sql = 'INSERT INTO ' . SESSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $reinsert_ary);
408                        $db->sql_query($sql);
409
410                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PURGE_SESSIONS');
411
412                        if ($request->is_ajax())
413                        {
414                            trigger_error('PURGE_SESSIONS_SUCCESS');
415                        }
416                    break;
417                }
418            }
419        }
420
421        // Version check
422        $user->add_lang('install');
423
424        if ($auth->acl_get('a_server') && version_compare(PHP_VERSION, '7.2.0', '<'))
425        {
426            $template->assign_vars(array(
427                'S_PHP_VERSION_OLD'    => true,
428                'L_PHP_VERSION_OLD'    => sprintf($user->lang['PHP_VERSION_OLD'], PHP_VERSION, '7.2.0', '<a href="https://www.phpbb.com/support/docs/en/3.3/ug/quickstart/requirements">', '</a>'),
429            ));
430        }
431
432        if ($auth->acl_get('a_board'))
433        {
434            $version_helper = $phpbb_container->get('version_helper');
435            try
436            {
437                $recheck = $request->variable('versioncheck_force', false);
438                $updates_available = $version_helper->get_update_on_branch($recheck);
439                $upgrades_available = $version_helper->get_suggested_updates();
440                if (!empty($upgrades_available))
441                {
442                    $upgrades_available = array_pop($upgrades_available);
443                }
444
445                $template->assign_vars(array(
446                    'S_VERSION_UP_TO_DATE'        => empty($updates_available),
447                    'S_VERSION_UPGRADEABLE'        => !empty($upgrades_available),
448                    'S_VERSIONCHECK_FORCE'        => (bool) $recheck,
449                    'UPGRADE_INSTRUCTIONS'        => !empty($upgrades_available) ? $user->lang('UPGRADE_INSTRUCTIONS', $upgrades_available['current'], $upgrades_available['announcement']) : false,
450                ));
451            }
452            catch (\RuntimeException $e)
453            {
454                $message = call_user_func_array(array($user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
455                $template->assign_vars(array(
456                    'S_VERSIONCHECK_FAIL'        => true,
457                    'VERSIONCHECK_FAIL_REASON'    => ($e->getMessage() !== 'VERSIONCHECK_FAIL') ? $message : '',
458                ));
459            }
460        }
461        else
462        {
463            // We set this template var to true, to not display an outdated version notice.
464            $template->assign_var('S_VERSION_UP_TO_DATE', true);
465        }
466
467        // Incomplete update?
468        if (phpbb_version_compare($config['version'], PHPBB_VERSION, '<'))
469        {
470            $template->assign_var('S_UPDATE_INCOMPLETE', true);
471        }
472
473        /**
474        * Notice admin
475        *
476        * @event core.acp_main_notice
477        * @since 3.1.0-RC3
478        */
479        $phpbb_dispatcher->trigger_event('core.acp_main_notice');
480
481        // Get forum statistics
482        $total_posts = $config['num_posts'];
483        $total_topics = $config['num_topics'];
484        $total_users = $config['num_users'];
485        $total_files = $config['num_files'];
486
487        $start_date = $user->format_date($config['board_startdate']);
488
489        $boarddays = (time() - (int) $config['board_startdate']) / 86400;
490
491        $posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
492        $topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
493        $users_per_day = sprintf('%.2f', $total_users / $boarddays);
494        $files_per_day = sprintf('%.2f', $total_files / $boarddays);
495
496        $upload_dir_size = get_formatted_filesize($config['upload_dir_size']);
497
498        $storage_avatar = $phpbb_container->get('storage.avatar');
499        $avatar_dir_size = get_formatted_filesize($storage_avatar->get_size());
500
501        if ($posts_per_day > $total_posts)
502        {
503            $posts_per_day = $total_posts;
504        }
505
506        if ($topics_per_day > $total_topics)
507        {
508            $topics_per_day = $total_topics;
509        }
510
511        if ($users_per_day > $total_users)
512        {
513            $users_per_day = $total_users;
514        }
515
516        if ($files_per_day > $total_files)
517        {
518            $files_per_day = $total_files;
519        }
520
521        $sql = 'SELECT COUNT(attach_id) AS total_orphan
522            FROM ' . ATTACHMENTS_TABLE . '
523            WHERE is_orphan = 1
524                AND filetime < ' . (time() - 3*60*60);
525        $result = $db->sql_query($sql);
526        $total_orphan = (int) $db->sql_fetchfield('total_orphan');
527        $db->sql_freeresult($result);
528
529        $dbsize = get_database_size();
530
531        $template->assign_vars(array(
532            'TOTAL_POSTS'        => $total_posts,
533            'POSTS_PER_DAY'        => $posts_per_day,
534            'TOTAL_TOPICS'        => $total_topics,
535            'TOPICS_PER_DAY'    => $topics_per_day,
536            'TOTAL_USERS'        => $total_users,
537            'USERS_PER_DAY'        => $users_per_day,
538            'TOTAL_FILES'        => $total_files,
539            'FILES_PER_DAY'        => $files_per_day,
540            'START_DATE'        => $start_date,
541            'AVATAR_DIR_SIZE'    => $avatar_dir_size,
542            'DBSIZE'            => $dbsize,
543            'UPLOAD_DIR_SIZE'    => $upload_dir_size,
544            'TOTAL_ORPHAN'        => $total_orphan,
545            'GZIP_COMPRESSION'    => ($config['gzip_compress'] && @extension_loaded('zlib')) ? $user->lang['ON'] : $user->lang['OFF'],
546            'DATABASE_INFO'        => $db->sql_server_info(),
547            'PHP_VERSION_INFO'    => PHP_VERSION,
548            'BOARD_VERSION'        => $config['version'],
549
550            'U_ACTION'            => $this->u_action,
551            'U_ADMIN_LOG'        => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=logs&amp;mode=admin'),
552            'U_INACTIVE_USERS'    => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=inactive&amp;mode=list'),
553            'U_VERSIONCHECK'    => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=update&amp;mode=version_check'),
554            'U_VERSIONCHECK_FORCE'    => append_sid("{$phpbb_admin_path}index.$phpEx", 'versioncheck_force=1'),
555            'U_ATTACH_ORPHAN'    => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=acp_attachments&mode=orphan'),
556
557            'S_VERSIONCHECK'    => ($auth->acl_get('a_board')) ? true : false,
558            'S_ACTION_OPTIONS'    => ($auth->acl_get('a_board')) ? true : false,
559            'S_FOUNDER'            => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
560            )
561        );
562
563        $log_data = array();
564        $log_count = false;
565
566        if ($auth->acl_get('a_viewlogs'))
567        {
568            view_log('admin', $log_data, $log_count, 5);
569
570            foreach ($log_data as $row)
571            {
572                $template->assign_block_vars('log', array(
573                    'USERNAME'    => $row['username_full'],
574                    'IP'        => $row['ip'],
575                    'DATE'        => $user->format_date($row['time']),
576                    'ACTION'    => $row['action'])
577                );
578            }
579        }
580
581        if ($auth->acl_get('a_user'))
582        {
583            $user->add_lang('memberlist');
584
585            $inactive = array();
586            $inactive_count = 0;
587
588            view_inactive_users($inactive, $inactive_count, 10);
589
590            foreach ($inactive as $row)
591            {
592                $template->assign_block_vars('inactive', array(
593                    'INACTIVE_DATE'    => $user->format_date($row['user_inactive_time']),
594                    'REMINDED_DATE'    => $user->format_date($row['user_reminded_time']),
595                    'JOINED'        => $user->format_date($row['user_regdate']),
596                    'LAST_VISIT'    => (!$row['user_lastvisit']) ? ' - ' : $user->format_date($row['user_lastvisit']),
597
598                    'REASON'        => $row['inactive_reason'],
599                    'USER_ID'        => $row['user_id'],
600                    'POSTS'            => ($row['user_posts']) ? $row['user_posts'] : 0,
601                    'REMINDED'        => $row['user_reminded'],
602
603                    'REMINDED_EXPLAIN'    => $user->lang('USER_LAST_REMINDED', (int) $row['user_reminded'], $user->format_date($row['user_reminded_time'])),
604
605                    'USERNAME_FULL'        => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&amp;mode=overview')),
606                    'USERNAME'            => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
607                    'USER_COLOR'        => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
608
609                    'U_USER_ADMIN'    => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;mode=overview&amp;u={$row['user_id']}"),
610                    'U_SEARCH_USER'    => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id={$row['user_id']}&amp;sr=posts") : '',
611                ));
612            }
613
614            $template->assign_var('S_INACTIVE_USERS', true);
615        }
616
617        // Warn if install is still present
618        if (!$phpbb_container->getParameter('allow_install_dir') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install'))
619        {
620            $template->assign_var('S_REMOVE_INSTALL', true);
621        }
622
623        // Warn if no search index is created
624        if ($config['num_posts'])
625        {
626            try
627            {
628                $search_backend_factory = $phpbb_container->get('search.backend_factory');
629                $search = $search_backend_factory->get_active();
630            }
631            catch (\phpbb\search\exception\no_search_backend_found_exception $e)
632            {
633                trigger_error('NO_SUCH_SEARCH_MODULE');
634            }
635
636            if (!$search->index_created())
637            {
638                $template->assign_vars(array(
639                    'S_SEARCH_INDEX_MISSING'    => true,
640                    'L_NO_SEARCH_INDEX'            => $user->lang('NO_SEARCH_INDEX', $search->get_name(), '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=acp_search&amp;mode=index') . '">', '</a>'),
641                ));
642            }
643        }
644
645        // Warn if incomplete captcha is enabled
646        $this->check_captcha_type($config, $template);
647
648        if (!defined('PHPBB_DISABLE_CONFIG_CHECK'))
649        {
650            // World-Writable? (000x)
651            $template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms($phpbb_root_path . 'config.' . $phpEx) & 0x0002));
652        }
653
654        $this->php_ini            = $phpbb_container->get('php_ini');
655        $func_overload            = $this->php_ini->getNumeric('mbstring.func_overload');
656        $encoding_translation    = $this->php_ini->getString('mbstring.encoding_translation');
657        $http_input                = $this->php_ini->getString('mbstring.http_input');
658        $http_output            = $this->php_ini->getString('mbstring.http_output');
659        $default_charset        = $this->php_ini->getString('default_charset');
660
661        if (extension_loaded('mbstring'))
662        {
663            /**
664             * “mbstring.http_input” and “mbstring.http_output” are deprecated as of PHP 5.6.0
665             * @link https://www.php.net/manual/mbstring.configuration.php#ini.mbstring.http-input
666             */
667            $template->assign_vars([
668                'S_MBSTRING_LOADED'                        => true,
669                'S_MBSTRING_FUNC_OVERLOAD_FAIL'            => $func_overload && ($func_overload & (MB_OVERLOAD_MAIL | MB_OVERLOAD_STRING)),
670                'S_MBSTRING_ENCODING_TRANSLATION_FAIL'    => $encoding_translation && ($encoding_translation != 0),
671                'S_MBSTRING_HTTP_INPUT_FAIL'            => !empty($http_input),
672                'S_MBSTRING_HTTP_OUTPUT_FAIL'            => !empty($http_output),
673                'S_DEFAULT_CHARSET_FAIL'                => $default_charset !== null && strtolower($default_charset) !== 'utf-8',
674            ]);
675        }
676
677        $this->tpl_name = 'acp_main';
678        $this->page_title = 'ACP_MAIN';
679    }
680
681    /**
682     * Check CAPTCHA type and output warning if incomplete type or unsafe config is used
683     *
684     * @param \phpbb\config\config $config
685     * @param \phpbb\template\template $template
686     * @return void
687     */
688    protected function check_captcha_type(\phpbb\config\config $config, \phpbb\template\template $template): void
689    {
690        $template_vars = [];
691
692        if (!$config['enable_confirm'])
693        {
694            $template_vars['S_CAPTCHA_UNSAFE'] = true;
695        }
696        else if ($config['captcha_plugin'] == 'core.captcha.plugins.incomplete')
697        {
698            $template_vars['S_CAPTCHA_INCOMPLETE'] = true;
699        }
700
701        $template->assign_vars($template_vars);
702    }
703}