punbb/admin_index.php
changeset 0 f9ffdbd96607
child 2 a8a21e1c7afa
equal deleted inserted replaced
-1:000000000000 0:f9ffdbd96607
       
     1 <?php
       
     2 /***********************************************************************
       
     3 
       
     4   Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
       
     5 
       
     6   This file is part of PunBB.
       
     7 
       
     8   PunBB is free software; you can redistribute it and/or modify it
       
     9   under the terms of the GNU General Public License as published
       
    10   by the Free Software Foundation; either version 2 of the License,
       
    11   or (at your option) any later version.
       
    12 
       
    13   PunBB is distributed in the hope that it will be useful, but
       
    14   WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16   GNU General Public License for more details.
       
    17 
       
    18   You should have received a copy of the GNU General Public License
       
    19   along with this program; if not, write to the Free Software
       
    20   Foundation, Inc., 59 Temple Place, Suite 330, Boston,
       
    21   MA  02111-1307  USA
       
    22 
       
    23 ************************************************************************/
       
    24 
       
    25 
       
    26 // Tell header.php to use the admin template
       
    27 define('PUN_ADMIN_CONSOLE', 1);
       
    28 
       
    29 define('PUN_ROOT', './');
       
    30 require PUN_ROOT.'include/common.php';
       
    31 require PUN_ROOT.'include/common_admin.php';
       
    32 
       
    33 
       
    34 if ($pun_user['g_id'] > PUN_MOD)
       
    35 	message($lang_common['No permission']);
       
    36 
       
    37 
       
    38 $action = isset($_GET['action']) ? $_GET['action'] : null;
       
    39 
       
    40 // Check for upgrade
       
    41 if ($action == 'check_upgrade')
       
    42 {
       
    43 	if (!ini_get('allow_url_fopen'))
       
    44 		message('Unable to check for upgrade since \'allow_url_fopen\' is disabled on this system.');
       
    45 
       
    46 	$fp = @fopen('http://www.punbb.org/latest_version', 'r');
       
    47 	$latest_version = trim(@fread($fp, 16));
       
    48 	@fclose($fp);
       
    49 
       
    50 	if ($latest_version == '')
       
    51 		message('Check for upgrade failed for unknown reasons.');
       
    52 
       
    53 	$cur_version = str_replace(array('.', 'dev', 'beta', ' '), '', strtolower($pun_config['o_cur_version']));
       
    54 	$cur_version = (strlen($cur_version) == 2) ? intval($cur_version) * 10 : intval($cur_version);
       
    55 
       
    56 	$latest_version = str_replace('.', '', strtolower($latest_version));
       
    57 	$latest_version = (strlen($latest_version) == 2) ? intval($latest_version) * 10 : intval($latest_version);
       
    58 
       
    59 	if ($cur_version >= $latest_version)
       
    60 		message('You are running the latest version of PunBB.');
       
    61 	else
       
    62 		message('A new version of PunBB has been released. You can download the latest version at <a href="http://www.punbb.org/">PunBB.org</a>.');
       
    63 }
       
    64 
       
    65 
       
    66 // Show phpinfo() output
       
    67 else if ($action == 'phpinfo' && $pun_user['g_id'] == PUN_ADMIN)
       
    68 {
       
    69 	// Is phpinfo() a disabled function?
       
    70 	if (strpos(strtolower((string)@ini_get('disable_functions')), 'phpinfo') !== false)
       
    71 		message('The PHP function phpinfo() has been disabled on this server.');
       
    72 
       
    73 	phpinfo();
       
    74 	exit;
       
    75 }
       
    76 
       
    77 
       
    78 // Get the server load averages (if possible)
       
    79 if (@file_exists('/proc/loadavg') && is_readable('/proc/loadavg'))
       
    80 {
       
    81 	// We use @ just in case
       
    82 	$fh = @fopen('/proc/loadavg', 'r');
       
    83 	$load_averages = @fread($fh, 64);
       
    84 	@fclose($fh);
       
    85 
       
    86 	$load_averages = @explode(' ', $load_averages);
       
    87 	$server_load = isset($load_averages[2]) ? $load_averages[0].' '.$load_averages[1].' '.$load_averages[2] : 'Not available';
       
    88 }
       
    89 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))
       
    90 	$server_load = $load_averages[1].' '.$load_averages[2].' '.$load_averages[3];
       
    91 else
       
    92 	$server_load = 'Not available';
       
    93 
       
    94 
       
    95 // Get number of current visitors
       
    96 $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());
       
    97 $num_online = $db->result($result);
       
    98 
       
    99 
       
   100 // Get the database system version
       
   101 switch ($db_type)
       
   102 {
       
   103 	case 'sqlite':
       
   104 		$db_version = 'SQLite '.sqlite_libversion();
       
   105 		break;
       
   106 
       
   107 	default:
       
   108 		$result = $db->query('SELECT VERSION()') or error('Unable to fetch version info', __FILE__, __LINE__, $db->error());
       
   109 		$db_version = $db->result($result);
       
   110 		break;
       
   111 }
       
   112 
       
   113 
       
   114 // Collect some additional info about MySQL
       
   115 if ($db_type == 'mysql' || $db_type == 'mysqli')
       
   116 {
       
   117 	$db_version = 'MySQL '.$db_version;
       
   118 
       
   119 	// Calculate total db size/row count
       
   120 	$result = $db->query('SHOW TABLE STATUS FROM `'.$db_name.'`') or error('Unable to fetch table status', __FILE__, __LINE__, $db->error());
       
   121 
       
   122 	$total_records = $total_size = 0;
       
   123 	while ($status = $db->fetch_assoc($result))
       
   124 	{
       
   125 		$total_records += $status['Rows'];
       
   126 		$total_size += $status['Data_length'] + $status['Index_length'];
       
   127 	}
       
   128 
       
   129 	$total_size = $total_size / 1024;
       
   130 
       
   131 	if ($total_size > 1024)
       
   132 		$total_size = round($total_size / 1024, 2).' MB';
       
   133 	else
       
   134 		$total_size = round($total_size, 2).' KB';
       
   135 }
       
   136 
       
   137 
       
   138 // See if MMCache or PHPA is loaded
       
   139 if (function_exists('mmcache'))
       
   140 	$php_accelerator = '<a href="http://turck-mmcache.sourceforge.net/">Turck MMCache</a>';
       
   141 else if (isset($_PHPA))
       
   142 	$php_accelerator = '<a href="http://www.php-accelerator.co.uk/">ionCube PHP Accelerator</a>';
       
   143 else
       
   144 	$php_accelerator = 'N/A';
       
   145 
       
   146 
       
   147 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin';
       
   148 require PUN_ROOT.'header.php';
       
   149 
       
   150 generate_admin_menu('index');
       
   151 
       
   152 ?>
       
   153 	<div class="block">
       
   154 		<h2>Forum administration</h2>
       
   155 		<div id="adintro" class="box">
       
   156 			<div class="inbox">
       
   157 				<p>
       
   158 					Welcome to the PunBB administration control panel. From here you can control vital aspects of the forum. Depending on whether you are an administrator or a moderator you can<br /><br />
       
   159 					&nbsp;- organize categories and forums.<br />
       
   160 					&nbsp;- set forum-wide options and preferences.<br />
       
   161 					&nbsp;- control permissions for users and guests.<br />
       
   162 					&nbsp;- view IP statistics for users.<br />
       
   163 					&nbsp;- ban users.<br />
       
   164 					&nbsp;- censor words.<br />
       
   165 					&nbsp;- set up user ranks.<br />
       
   166 					&nbsp;- prune old posts.<br />
       
   167 					&nbsp;- handle post reports.
       
   168 				</p>
       
   169 			</div>
       
   170 		</div>
       
   171 
       
   172 		<h2 class="block2"><span>Statistics</span></h2>
       
   173 		<div id="adstats" class="box">
       
   174 			<div class="inbox">
       
   175 				<dl>
       
   176 					<dt>PunBB version</dt>
       
   177 					<dd>
       
   178 						PunBB <?php echo $pun_config['o_cur_version'] ?> - <a href="admin_index.php?action=check_upgrade">Check for upgrade</a><br />
       
   179 						&copy; Copyright 2002, 2003, 2004, 2005 Rickard Andersson
       
   180 					</dd>
       
   181 					<dt>Server load</dt>
       
   182 					<dd>
       
   183 						<?php echo $server_load ?> (<?php echo $num_online ?> users online)
       
   184 					</dd>
       
   185 <?php if ($pun_user['g_id'] == PUN_ADMIN): ?>					<dt>Environment</dt>
       
   186 					<dd>
       
   187 						Operating system: <?php echo PHP_OS ?><br />
       
   188 						PHP: <?php echo phpversion() ?> - <a href="admin_index.php?action=phpinfo">Show info</a><br />
       
   189 						Accelerator: <?php echo $php_accelerator."\n" ?>
       
   190 					</dd>
       
   191 					<dt>Database</dt>
       
   192 					<dd>
       
   193 						<?php echo $db_version."\n" ?>
       
   194 <?php if (isset($total_records) && isset($total_size)): ?>						<br />Rows: <?php echo $total_records."\n" ?>
       
   195 						<br />Size: <?php echo $total_size."\n" ?>
       
   196 <?php endif; endif; ?>					</dd>
       
   197 				</dl>
       
   198 			</div>
       
   199 		</div>
       
   200 	</div>
       
   201 	<div class="clearer"></div>
       
   202 </div>
       
   203 <?php
       
   204 
       
   205 require PUN_ROOT.'footer.php';