PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/nacridan/forum/admin_statistics.php

https://gitlab.com/nacridan/Nacridan
PHP | 139 lines | 97 code | 27 blank | 15 comment | 36 complexity | 728bb35d27ff37d217f3aff82d984804 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright (C) 2008-2012 FluxBB
  4. * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
  5. * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  6. */
  7. // Tell header.php to use the admin template
  8. define('PUN_ADMIN_CONSOLE', 1);
  9. define('PUN_ROOT', dirname(__FILE__).'/');
  10. require PUN_ROOT.'include/common.php';
  11. require PUN_ROOT.'include/common_admin.php';
  12. if (!$pun_user['is_admmod'])
  13. message($lang_common['No permission'], false, '403 Forbidden');
  14. // Load the admin_index.php language file
  15. require PUN_ROOT.'lang/'.$admin_language.'/admin_index.php';
  16. $action = isset($_GET['action']) ? $_GET['action'] : null;
  17. // Show phpinfo() output
  18. if ($action == 'phpinfo' && $pun_user['g_id'] == PUN_ADMIN)
  19. {
  20. // Is phpinfo() a disabled function?
  21. if (strpos(strtolower((string) ini_get('disable_functions')), 'phpinfo') !== false)
  22. message($lang_admin_index['PHPinfo disabled message']);
  23. phpinfo();
  24. exit;
  25. }
  26. // Get the server load averages (if possible)
  27. if (@file_exists('/proc/loadavg') && is_readable('/proc/loadavg'))
  28. {
  29. // We use @ just in case
  30. $fh = @fopen('/proc/loadavg', 'r');
  31. $load_averages = @fread($fh, 64);
  32. @fclose($fh);
  33. if (($fh = @fopen('/proc/loadavg', 'r')))
  34. {
  35. $load_averages = fread($fh, 64);
  36. fclose($fh);
  37. }
  38. else
  39. $load_averages = '';
  40. $load_averages = @explode(' ', $load_averages);
  41. $server_load = isset($load_averages[2]) ? $load_averages[0].' '.$load_averages[1].' '.$load_averages[2] : $lang_admin_index['Not available'];
  42. }
  43. else if (!in_array(PHP_OS, array('WINNT', 'WIN32')) && preg_match('%averages?: ([0-9\.]+),?\s+([0-9\.]+),?\s+([0-9\.]+)%i', @exec('uptime'), $load_averages))
  44. $server_load = $load_averages[1].' '.$load_averages[2].' '.$load_averages[3];
  45. else
  46. $server_load = $lang_admin_index['Not available'];
  47. // Get number of current visitors
  48. $result = $db->query('SELECT COUNT(user_id) FROM '.$db->prefix.'online WHERE idle=0') or error('Unable to fetch online count', __FILE__, __LINE__, $db->error());
  49. $num_online = $db->result($result);
  50. // Collect some additional info about MySQL
  51. if ($db_type == 'mysql' || $db_type == 'mysqli' || $db_type == 'mysql_innodb' || $db_type == 'mysqli_innodb')
  52. {
  53. // Calculate total db size/row count
  54. $result = $db->query('SHOW TABLE STATUS LIKE \''.$db->prefix.'%\'') or error('Unable to fetch table status', __FILE__, __LINE__, $db->error());
  55. $total_records = $total_size = 0;
  56. while ($status = $db->fetch_assoc($result))
  57. {
  58. $total_records += $status['Rows'];
  59. $total_size += $status['Data_length'] + $status['Index_length'];
  60. }
  61. $total_size = file_size($total_size);
  62. }
  63. // Check for the existence of various PHP opcode caches/optimizers
  64. if (function_exists('mmcache'))
  65. $php_accelerator = '<a href="http://'.$lang_admin_index['Turck MMCache link'].'">'.$lang_admin_index['Turck MMCache'].'</a>';
  66. else if (isset($_PHPA))
  67. $php_accelerator = '<a href="http://'.$lang_admin_index['ionCube PHP Accelerator link'].'">'.$lang_admin_index['ionCube PHP Accelerator'].'</a>';
  68. else if (ini_get('apc.enabled'))
  69. $php_accelerator ='<a href="http://'.$lang_admin_index['Alternative PHP Cache (APC) link'].'">'.$lang_admin_index['Alternative PHP Cache (APC)'].'</a>';
  70. else if (ini_get('zend_optimizer.optimization_level'))
  71. $php_accelerator = '<a href="http://'.$lang_admin_index['Zend Optimizer link'].'">'.$lang_admin_index['Zend Optimizer'].'</a>';
  72. else if (ini_get('eaccelerator.enable'))
  73. $php_accelerator = '<a href="http://'.$lang_admin_index['eAccelerator link'].'">'.$lang_admin_index['eAccelerator'].'</a>';
  74. else if (ini_get('xcache.cacher'))
  75. $php_accelerator = '<a href="http://'.$lang_admin_index['XCache link'].'">'.$lang_admin_index['XCache'].'</a>';
  76. else
  77. $php_accelerator = $lang_admin_index['NA'];
  78. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Server statistics']);
  79. define('PUN_ACTIVE_PAGE', 'admin');
  80. require PUN_ROOT.'header.php';
  81. generate_admin_menu('index');
  82. ?>
  83. <div class="block">
  84. <h2><span><?php echo $lang_admin_index['Server statistics head'] ?></span></h2>
  85. <div id="adstats" class="box">
  86. <div class="inbox">
  87. <dl>
  88. <dt><?php echo $lang_admin_index['Server load label'] ?></dt>
  89. <dd>
  90. <?php printf($lang_admin_index['Server load data']."\n", $server_load, $num_online) ?>
  91. </dd>
  92. <?php if ($pun_user['g_id'] == PUN_ADMIN): ?> <dt><?php echo $lang_admin_index['Environment label'] ?></dt>
  93. <dd>
  94. <?php printf($lang_admin_index['Environment data OS'], PHP_OS) ?><br />
  95. <?php printf($lang_admin_index['Environment data version'], phpversion(), '<a href="admin_statistics.php?action=phpinfo">'.$lang_admin_index['Show info'].'</a>') ?><br />
  96. <?php printf($lang_admin_index['Environment data acc']."\n", $php_accelerator) ?>
  97. </dd>
  98. <dt><?php echo $lang_admin_index['Database label'] ?></dt>
  99. <dd>
  100. <?php echo implode(' ', $db->get_version())."\n" ?>
  101. <?php if (isset($total_records) && isset($total_size)): ?> <br /><?php printf($lang_admin_index['Database data rows']."\n", forum_number_format($total_records)) ?>
  102. <br /><?php printf($lang_admin_index['Database data size']."\n", $total_size) ?>
  103. <?php endif; ?> </dd>
  104. <?php endif; ?>
  105. </dl>
  106. </div>
  107. </div>
  108. </div>
  109. <div class="clearer"></div>
  110. </div>
  111. <?php
  112. require PUN_ROOT.'footer.php';