punbb/admin_index.php
changeset 6 5e1f1e916419
parent 5 e3d7322305bf
child 7 98bbc533541c
equal deleted inserted replaced
5:e3d7322305bf 6:5e1f1e916419
     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 
       
    32 global $pun_db, $pun_user, $pun_config, $lang_common;
       
    33 
       
    34 require PUN_ROOT.'include/common_admin.php';
       
    35 
       
    36 
       
    37 if ($pun_user['g_id'] < PUN_MOD)
       
    38 	message($lang_common['No permission']);
       
    39 
       
    40 
       
    41 $action = isset($_GET['action']) ? $_GET['action'] : null;
       
    42 
       
    43 // Check for upgrade
       
    44 if ($action == 'check_upgrade')
       
    45 {
       
    46 	if (!ini_get('allow_url_fopen'))
       
    47 		message('Unable to check for upgrade since \'allow_url_fopen\' is disabled on this system.');
       
    48 
       
    49 	$fp = @fopen('http://www.punbb.org/latest_version', 'r');
       
    50 	$latest_version = trim(@fread($fp, 16));
       
    51 	@fclose($fp);
       
    52 
       
    53 	if ($latest_version == '')
       
    54 		message('Check for upgrade failed for unknown reasons.');
       
    55 
       
    56 	$cur_version = str_replace(array('.', 'dev', 'beta', ' '), '', strtolower($pun_config['o_cur_version']));
       
    57 	$cur_version = (strlen($cur_version) == 2) ? intval($cur_version) * 10 : intval($cur_version);
       
    58 
       
    59 	$latest_version = str_replace('.', '', strtolower($latest_version));
       
    60 	$latest_version = (strlen($latest_version) == 2) ? intval($latest_version) * 10 : intval($latest_version);
       
    61 
       
    62 	if ($cur_version >= $latest_version)
       
    63 		message('You are running the latest version of PunBB.');
       
    64 	else
       
    65 		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>.');
       
    66 }
       
    67 
       
    68 
       
    69 // Show phpinfo() output
       
    70 else if ($action == 'phpinfo' && $pun_user['g_id'] == PUN_ADMIN)
       
    71 {
       
    72 	// Is phpinfo() a disabled function?
       
    73 	if (strpos(strtolower((string)@ini_get('disable_functions')), 'phpinfo') !== false)
       
    74 		message('The PHP function phpinfo() has been disabled on this server.');
       
    75 
       
    76 	phpinfo();
       
    77 	exit;
       
    78 }
       
    79 
       
    80 
       
    81 // Get the server load averages (if possible)
       
    82 if (@file_exists('/proc/loadavg') && is_readable('/proc/loadavg'))
       
    83 {
       
    84 	// We use @ just in case
       
    85 	$fh = @fopen('/proc/loadavg', 'r');
       
    86 	$load_averages = @fread($fh, 64);
       
    87 	@fclose($fh);
       
    88 
       
    89 	$load_averages = @explode(' ', $load_averages);
       
    90 	$server_load = isset($load_averages[2]) ? $load_averages[0].' '.$load_averages[1].' '.$load_averages[2] : 'Not available';
       
    91 }
       
    92 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))
       
    93 	$server_load = $load_averages[1].' '.$load_averages[2].' '.$load_averages[3];
       
    94 else
       
    95 	$server_load = 'Not available';
       
    96 
       
    97 
       
    98 // Get number of current visitors
       
    99 $result = $pun_db->query('SELECT COUNT(user_id) FROM '.$pun_db->prefix.'online WHERE idle=0') or error('Unable to fetch online count', __FILE__, __LINE__, $pun_db->error());
       
   100 $num_online = $pun_db->result($result);
       
   101 
       
   102 
       
   103 // Get the database system version
       
   104 switch ($db_type)
       
   105 {
       
   106 	case 'sqlite':
       
   107 		$db_version = 'SQLite '.sqlite_libversion();
       
   108 		break;
       
   109 
       
   110 	default:
       
   111 		$result = $pun_db->query('SELECT VERSION()') or error('Unable to fetch version info', __FILE__, __LINE__, $pun_db->error());
       
   112 		$db_version = $pun_db->result($result);
       
   113 		break;
       
   114 }
       
   115 
       
   116 
       
   117 // Collect some additional info about MySQL
       
   118 if ($db_type == 'mysql' || $db_type == 'mysqli')
       
   119 {
       
   120 	$db_version = 'MySQL '.$db_version;
       
   121 
       
   122 	// Calculate total db size/row count
       
   123 	$result = $pun_db->query('SHOW TABLE STATUS FROM `'.$db_name.'`') or error('Unable to fetch table status', __FILE__, __LINE__, $pun_db->error());
       
   124 
       
   125 	$total_records = $total_size = 0;
       
   126 	while ($status = $pun_db->fetch_assoc($result))
       
   127 	{
       
   128 		$total_records += $status['Rows'];
       
   129 		$total_size += $status['Data_length'] + $status['Index_length'];
       
   130 	}
       
   131 
       
   132 	$total_size = $total_size / 1024;
       
   133 
       
   134 	if ($total_size > 1024)
       
   135 		$total_size = round($total_size / 1024, 2).' MB';
       
   136 	else
       
   137 		$total_size = round($total_size, 2).' KB';
       
   138 }
       
   139 
       
   140 
       
   141 // See if MMCache or PHPA is loaded
       
   142 if (function_exists('mmcache'))
       
   143 	$php_accelerator = '<a href="http://turck-mmcache.sourceforge.net/">Turck MMCache</a>';
       
   144 else if (isset($_PHPA))
       
   145 	$php_accelerator = '<a href="http://www.php-accelerator.co.uk/">ionCube PHP Accelerator</a>';
       
   146 else
       
   147 	$php_accelerator = 'N/A';
       
   148 
       
   149 
       
   150 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin';
       
   151 require PUN_ROOT.'header.php';
       
   152 
       
   153 generate_admin_menu('index');
       
   154 
       
   155 ?>
       
   156 	<div class="block">
       
   157 		<h2>Forum administration</h2>
       
   158 		<div id="adintro" class="box">
       
   159 			<div class="inbox">
       
   160 				<p>
       
   161 					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 />
       
   162 					&nbsp;- organize categories and forums.<br />
       
   163 					&nbsp;- set forum-wide options and preferences.<br />
       
   164 					&nbsp;- control permissions for users and guests.<br />
       
   165 					&nbsp;- view IP statistics for users.<br />
       
   166 					&nbsp;- ban users.<br />
       
   167 					&nbsp;- censor words.<br />
       
   168 					&nbsp;- set up user ranks.<br />
       
   169 					&nbsp;- prune old posts.<br />
       
   170 					&nbsp;- handle post reports.
       
   171 				</p>
       
   172 			</div>
       
   173 		</div>
       
   174 
       
   175 		<h2 class="block2"><span>Statistics</span></h2>
       
   176 		<div id="adstats" class="box">
       
   177 			<div class="inbox">
       
   178 				<dl>
       
   179 					<dt>PunBB version</dt>
       
   180 					<dd>
       
   181 						PunBB <?php echo $pun_config['o_cur_version'] ?> - <a href="admin_index.php?action=check_upgrade">Check for upgrade</a><br />
       
   182 						&copy; Copyright 2002, 2003, 2004, 2005 Rickard Andersson
       
   183 					</dd>
       
   184 					<dt>Server load</dt>
       
   185 					<dd>
       
   186 						<?php echo $server_load ?> (<?php echo $num_online ?> users online)
       
   187 					</dd>
       
   188 <?php if ($pun_user['g_id'] == PUN_ADMIN): ?>					<dt>Environment</dt>
       
   189 					<dd>
       
   190 						Operating system: <?php echo PHP_OS ?><br />
       
   191 						PHP: <?php echo phpversion() ?> - <a href="admin_index.php?action=phpinfo">Show info</a><br />
       
   192 						Accelerator: <?php echo $php_accelerator."\n" ?>
       
   193 					</dd>
       
   194 					<dt>Database</dt>
       
   195 					<dd>
       
   196 						<?php echo $db_version."\n" ?>
       
   197 <?php if (isset($total_records) && isset($total_size)): ?>						<br />Rows: <?php echo $total_records."\n" ?>
       
   198 						<br />Size: <?php echo $total_size."\n" ?>
       
   199 <?php endif; endif; ?>					</dd>
       
   200 				</dl>
       
   201 			</div>
       
   202 		</div>
       
   203 	</div>
       
   204 	<div class="clearer"></div>
       
   205 </div>
       
   206 <?php
       
   207 
       
   208 require PUN_ROOT.'footer.php';