Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 404 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| acp_main | |
0.00% |
0 / 402 |
|
0.00% |
0 / 2 |
7656 | |
0.00% |
0 / 1 |
| main | |
0.00% |
0 / 396 |
|
0.00% |
0 / 1 |
7140 | |||
| check_captcha_type | |
0.00% |
0 / 6 |
|
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 | */ |
| 17 | if (!defined('IN_PHPBB')) |
| 18 | { |
| 19 | exit; |
| 20 | } |
| 21 | |
| 22 | class 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 | $version_helper = $phpbb_container->get('version_helper'); |
| 462 | try |
| 463 | { |
| 464 | $recheck = $request->variable('versioncheck_force', false); |
| 465 | $updates_available = $version_helper->get_update_on_branch($recheck); |
| 466 | $upgrades_available = $version_helper->get_suggested_updates(); |
| 467 | if (!empty($upgrades_available)) |
| 468 | { |
| 469 | $upgrades_available = array_pop($upgrades_available); |
| 470 | } |
| 471 | |
| 472 | $template->assign_vars(array( |
| 473 | 'S_VERSION_UP_TO_DATE' => empty($updates_available), |
| 474 | 'S_VERSION_UPGRADEABLE' => !empty($upgrades_available), |
| 475 | 'S_VERSIONCHECK_FORCE' => (bool) $recheck, |
| 476 | 'UPGRADE_INSTRUCTIONS' => !empty($upgrades_available) ? $user->lang('UPGRADE_INSTRUCTIONS', $upgrades_available['current'], $upgrades_available['announcement']) : false, |
| 477 | )); |
| 478 | } |
| 479 | catch (\phpbb\exception\runtime_exception $e) |
| 480 | { |
| 481 | $message = call_user_func_array(array($user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); |
| 482 | $template->assign_vars(array( |
| 483 | 'S_VERSIONCHECK_FAIL' => true, |
| 484 | 'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== 'VERSIONCHECK_FAIL') ? $message : '', |
| 485 | )); |
| 486 | } |
| 487 | } |
| 488 | else |
| 489 | { |
| 490 | // We set this template var to true, to not display an outdated version notice. |
| 491 | $template->assign_var('S_VERSION_UP_TO_DATE', true); |
| 492 | } |
| 493 | |
| 494 | // Incomplete update? |
| 495 | if (phpbb_version_compare($config['version'], PHPBB_VERSION, '<')) |
| 496 | { |
| 497 | $template->assign_var('S_UPDATE_INCOMPLETE', true); |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Notice admin |
| 502 | * |
| 503 | * @event core.acp_main_notice |
| 504 | * @since 3.1.0-RC3 |
| 505 | */ |
| 506 | $phpbb_dispatcher->trigger_event('core.acp_main_notice'); |
| 507 | |
| 508 | // Get forum statistics |
| 509 | $total_posts = $config['num_posts']; |
| 510 | $total_topics = $config['num_topics']; |
| 511 | $total_users = $config['num_users']; |
| 512 | $total_files = $config['num_files']; |
| 513 | |
| 514 | $start_date = $user->format_date($config['board_startdate']); |
| 515 | |
| 516 | $boarddays = (time() - (int) $config['board_startdate']) / 86400; |
| 517 | |
| 518 | $posts_per_day = sprintf('%.2f', $total_posts / $boarddays); |
| 519 | $topics_per_day = sprintf('%.2f', $total_topics / $boarddays); |
| 520 | $users_per_day = sprintf('%.2f', $total_users / $boarddays); |
| 521 | $files_per_day = sprintf('%.2f', $total_files / $boarddays); |
| 522 | |
| 523 | $upload_dir_size = get_formatted_filesize($config['upload_dir_size']); |
| 524 | |
| 525 | $storage_avatar = $phpbb_container->get('storage.avatar'); |
| 526 | $avatar_dir_size = get_formatted_filesize($storage_avatar->total_size()); |
| 527 | |
| 528 | if ($posts_per_day > $total_posts) |
| 529 | { |
| 530 | $posts_per_day = $total_posts; |
| 531 | } |
| 532 | |
| 533 | if ($topics_per_day > $total_topics) |
| 534 | { |
| 535 | $topics_per_day = $total_topics; |
| 536 | } |
| 537 | |
| 538 | if ($users_per_day > $total_users) |
| 539 | { |
| 540 | $users_per_day = $total_users; |
| 541 | } |
| 542 | |
| 543 | if ($files_per_day > $total_files) |
| 544 | { |
| 545 | $files_per_day = $total_files; |
| 546 | } |
| 547 | |
| 548 | $sql = 'SELECT COUNT(attach_id) AS total_orphan |
| 549 | FROM ' . ATTACHMENTS_TABLE . ' |
| 550 | WHERE is_orphan = 1 |
| 551 | AND filetime < ' . (time() - 3*60*60); |
| 552 | $result = $db->sql_query($sql); |
| 553 | $total_orphan = (int) $db->sql_fetchfield('total_orphan'); |
| 554 | $db->sql_freeresult($result); |
| 555 | |
| 556 | $dbsize = get_database_size(); |
| 557 | |
| 558 | $template->assign_vars(array( |
| 559 | 'TOTAL_POSTS' => $total_posts, |
| 560 | 'POSTS_PER_DAY' => $posts_per_day, |
| 561 | 'TOTAL_TOPICS' => $total_topics, |
| 562 | 'TOPICS_PER_DAY' => $topics_per_day, |
| 563 | 'TOTAL_USERS' => $total_users, |
| 564 | 'USERS_PER_DAY' => $users_per_day, |
| 565 | 'TOTAL_FILES' => $total_files, |
| 566 | 'FILES_PER_DAY' => $files_per_day, |
| 567 | 'START_DATE' => $start_date, |
| 568 | 'AVATAR_DIR_SIZE' => $avatar_dir_size, |
| 569 | 'DBSIZE' => $dbsize, |
| 570 | 'UPLOAD_DIR_SIZE' => $upload_dir_size, |
| 571 | 'TOTAL_ORPHAN' => $total_orphan, |
| 572 | 'GZIP_COMPRESSION' => ($config['gzip_compress'] && @extension_loaded('zlib')) ? $user->lang['ON'] : $user->lang['OFF'], |
| 573 | 'DATABASE_INFO' => $db->sql_server_info(), |
| 574 | 'PHP_VERSION_INFO' => PHP_VERSION, |
| 575 | 'BOARD_VERSION' => $config['version'], |
| 576 | |
| 577 | 'U_ACTION' => $this->u_action, |
| 578 | 'U_ADMIN_LOG' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=logs&mode=admin'), |
| 579 | 'U_INACTIVE_USERS' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=inactive&mode=list'), |
| 580 | 'U_VERSIONCHECK' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=update&mode=version_check'), |
| 581 | 'U_VERSIONCHECK_FORCE' => append_sid("{$phpbb_admin_path}index.$phpEx", 'versioncheck_force=1'), |
| 582 | 'U_ATTACH_ORPHAN' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=acp_attachments&mode=orphan'), |
| 583 | |
| 584 | 'S_VERSIONCHECK' => ($auth->acl_get('a_board')) ? true : false, |
| 585 | 'S_ACTION_OPTIONS' => ($auth->acl_get('a_board')) ? true : false, |
| 586 | 'S_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false, |
| 587 | ) |
| 588 | ); |
| 589 | |
| 590 | $log_data = array(); |
| 591 | $log_count = false; |
| 592 | |
| 593 | if ($auth->acl_get('a_viewlogs')) |
| 594 | { |
| 595 | view_log('admin', $log_data, $log_count, 5); |
| 596 | |
| 597 | foreach ($log_data as $row) |
| 598 | { |
| 599 | $template->assign_block_vars('log', array( |
| 600 | 'USERNAME' => $row['username_full'], |
| 601 | 'IP' => $row['ip'], |
| 602 | 'DATE' => $user->format_date($row['time']), |
| 603 | 'ACTION' => $row['action']) |
| 604 | ); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | if ($auth->acl_get('a_user')) |
| 609 | { |
| 610 | $user->add_lang('memberlist'); |
| 611 | |
| 612 | $inactive = array(); |
| 613 | $inactive_count = 0; |
| 614 | |
| 615 | view_inactive_users($inactive, $inactive_count, 10); |
| 616 | |
| 617 | foreach ($inactive as $row) |
| 618 | { |
| 619 | $template->assign_block_vars('inactive', array( |
| 620 | 'INACTIVE_DATE' => $user->format_date($row['user_inactive_time']), |
| 621 | 'REMINDED_DATE' => $user->format_date($row['user_reminded_time']), |
| 622 | 'JOINED' => $user->format_date($row['user_regdate']), |
| 623 | 'LAST_VISIT' => (!$row['user_lastvisit']) ? ' - ' : $user->format_date($row['user_lastvisit']), |
| 624 | |
| 625 | 'REASON' => $row['inactive_reason'], |
| 626 | 'USER_ID' => $row['user_id'], |
| 627 | 'POSTS' => ($row['user_posts']) ? $row['user_posts'] : 0, |
| 628 | 'REMINDED' => $row['user_reminded'], |
| 629 | |
| 630 | 'REMINDED_EXPLAIN' => $user->lang('USER_LAST_REMINDED', (int) $row['user_reminded'], $user->format_date($row['user_reminded_time'])), |
| 631 | |
| 632 | 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=overview')), |
| 633 | 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), |
| 634 | 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), |
| 635 | |
| 636 | 'U_USER_ADMIN' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&mode=overview&u={$row['user_id']}"), |
| 637 | 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id={$row['user_id']}&sr=posts") : '', |
| 638 | )); |
| 639 | } |
| 640 | |
| 641 | $template->assign_var('S_INACTIVE_USERS', true); |
| 642 | } |
| 643 | |
| 644 | // Warn if install is still present |
| 645 | if (!$phpbb_container->getParameter('allow_install_dir') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install')) |
| 646 | { |
| 647 | $template->assign_var('S_REMOVE_INSTALL', true); |
| 648 | } |
| 649 | |
| 650 | // Warn if no search index is created |
| 651 | if ($config['num_posts']) |
| 652 | { |
| 653 | try |
| 654 | { |
| 655 | $search_backend_factory = $phpbb_container->get('search.backend_factory'); |
| 656 | $search = $search_backend_factory->get_active(); |
| 657 | } |
| 658 | catch (\phpbb\search\exception\no_search_backend_found_exception $e) |
| 659 | { |
| 660 | trigger_error('NO_SUCH_SEARCH_MODULE'); |
| 661 | } |
| 662 | |
| 663 | if (!$search->index_created()) |
| 664 | { |
| 665 | $template->assign_vars(array( |
| 666 | 'S_SEARCH_INDEX_MISSING' => true, |
| 667 | 'L_NO_SEARCH_INDEX' => $user->lang('NO_SEARCH_INDEX', $search->get_name(), '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=acp_search&mode=index') . '">', '</a>'), |
| 668 | )); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | // Warn if incomplete captcha is enabled |
| 673 | $this->check_captcha_type($config, $template); |
| 674 | |
| 675 | if (!defined('PHPBB_DISABLE_CONFIG_CHECK')) |
| 676 | { |
| 677 | // World-Writable? (000x) |
| 678 | $template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms($phpbb_root_path . 'config.' . $phpEx) & 0x0002)); |
| 679 | } |
| 680 | |
| 681 | $this->php_ini = $phpbb_container->get('php_ini'); |
| 682 | $func_overload = $this->php_ini->getNumeric('mbstring.func_overload'); |
| 683 | $encoding_translation = $this->php_ini->getString('mbstring.encoding_translation'); |
| 684 | $http_input = $this->php_ini->getString('mbstring.http_input'); |
| 685 | $http_output = $this->php_ini->getString('mbstring.http_output'); |
| 686 | $default_charset = $this->php_ini->getString('default_charset'); |
| 687 | |
| 688 | if (extension_loaded('mbstring')) |
| 689 | { |
| 690 | /** |
| 691 | * “mbstring.http_input” and “mbstring.http_output” are deprecated as of PHP 5.6.0 |
| 692 | * @link https://www.php.net/manual/mbstring.configuration.php#ini.mbstring.http-input |
| 693 | */ |
| 694 | $template->assign_vars([ |
| 695 | 'S_MBSTRING_LOADED' => true, |
| 696 | 'S_MBSTRING_FUNC_OVERLOAD_FAIL' => $func_overload && ($func_overload & (MB_OVERLOAD_MAIL | MB_OVERLOAD_STRING)), |
| 697 | 'S_MBSTRING_ENCODING_TRANSLATION_FAIL' => $encoding_translation && ($encoding_translation != 0), |
| 698 | 'S_MBSTRING_HTTP_INPUT_FAIL' => !empty($http_input), |
| 699 | 'S_MBSTRING_HTTP_OUTPUT_FAIL' => !empty($http_output), |
| 700 | 'S_DEFAULT_CHARSET_FAIL' => $default_charset !== null && strtolower($default_charset) !== 'utf-8', |
| 701 | ]); |
| 702 | } |
| 703 | |
| 704 | $this->tpl_name = 'acp_main'; |
| 705 | $this->page_title = 'ACP_MAIN'; |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * Check CAPTCHA type and output warning if incomplete type or unsafe config is used |
| 710 | * |
| 711 | * @param \phpbb\config\config $config |
| 712 | * @param \phpbb\template\template $template |
| 713 | * @return void |
| 714 | */ |
| 715 | protected function check_captcha_type(\phpbb\config\config $config, \phpbb\template\template $template): void |
| 716 | { |
| 717 | $template_vars = []; |
| 718 | |
| 719 | if (!$config['enable_confirm']) |
| 720 | { |
| 721 | $template_vars['S_CAPTCHA_UNSAFE'] = true; |
| 722 | } |
| 723 | else if ($config['captcha_plugin'] == 'core.captcha.plugins.incomplete') |
| 724 | { |
| 725 | $template_vars['S_CAPTCHA_INCOMPLETE'] = true; |
| 726 | } |
| 727 | |
| 728 | $template->assign_vars($template_vars); |
| 729 | } |
| 730 | } |