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