Location: PHPKode > projects > XennoBB > xennobb/admin/index.php
<?php
/*

  Copyright (C) 2005-2011 UserDot
  Visit XennoBB at www.userdot.net/projects/xennobb
  Originally based on PunBB www.punbb.org

  XennoBB is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  XennoBB is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  MA 02110-1301 USA

 */
define('IN_FORUM_ADMIN', 1);
require dirname(__FILE__) . '/../include/init.php';
if ($forum_user['g_id'] > USER_MOD && !$forum_user['g_global_moderation'])
    BB_Functions::Message($lang['No permission'], true, 1);
$action = isset($_GET['action']) ? $_GET['action'] : null;
$page = isset($_GET['Page']) ? BB_Input::Htmlspecialchars($_GET['Page']) : null;
$submenu = array($lang['Index'] => 'index.php?Page=Intro', $lang['Statistics'] => 'index.php?Page=Statistics', $lang['Update'] => 'index.php?Page=Update');
if ($action == 'phpinfo' && $forum_user['g_id'] == USER_ADMIN)
{
    if (strpos(strtolower((string) @ini_get('disable_functions')), 'phpinfo') !== false)
        BB_Functions::Message($lang['no_phpinfo']);
    phpinfo();
    exit;
}
if ($action == 'check_software_upgrade')
{
    if (!ini_get('allow_url_fopen'))
        BB_Functions::Message($lang['no_allow_url_fopen']);
    if (!$fp = fopen('http://www.xennobb.com/xennose_current_version', 'r'))
        BB_Functions::Message($lang['no_update_file']);
    $latest_version = trim(@fread($fp, 16));
    @fclose($fp);
    if ($latest_version == '')
        BB_Functions::Message('Check for upgrade failed for unknown reasons.');
    $cur_version = str_replace(array('.', 'dev', 'beta', ' '), '', strtolower(bb_cur_version));
    $cur_version = (strlen($cur_version) == 2) ? intval($cur_version) * 10 : intval($cur_version);
    $latest_version = str_replace('.', '', strtolower($latest_version));
    $latest_version = (strlen($latest_version) == 2) ? intval($latest_version) * 10 : intval($latest_version);
    if ($cur_version >= $latest_version)
        BB_Functions::Message($lang['up_to_date']);
    else
        BB_Functions::Message($lang['new_version_released']);
}
if (@file_exists('/proc/loadavg') && is_readable('/proc/loadavg'))
{
    $fh = @fopen('/proc/loadavg', 'r');
    $load_averages = @fread($fh, 64);
    @fclose($fh);
    $load_averages = @explode(' ', $load_averages);
    $server_load = isset($load_averages[2]) ? $load_averages[0] . ' ' . $load_averages[1] . ' ' . $load_averages[2] : $lang['Not available'];
}
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))
    $server_load = $load_averages[1] . ' ' . $load_averages[2] . ' ' . $load_averages[3];
else
    $server_load = $lang['Not available'];
$result = $db->query('SELECT COUNT(user_id) FROM ' . $db->prefix . 'online WHERE idle=0') or BB_Functions::Error($lang['error_10'], __FILE__, __LINE__, $db->error());
$num_online = $db->result($result);
switch ($db_type)
{
    case 'sqlite':
        $db_version = 'SQLite ' . sqlite_libversion();
        break;
    default:
        $result = $db->query('SELECT VERSION()') or BB_Functions::Error($lang['error_78'], __FILE__, __LINE__, $db->error());
        $db_version = $db->result($result);
        break;
}
if ($db_type == 'mysql' || $db_type == 'mysqli')
{
    $db_version = 'MySQL ' . $db_version;
    $result = $db->query('SHOW TABLE STATUS FROM `' . $db_name . '`') or BB_Functions::Error($lang['error_79'], __FILE__, __LINE__, $db->error());
    $total_records = $total_size = 0;
    while ($status = $db->fetch_assoc($result))
    {
        $total_records += $status['Rows'];
        $total_size += $status['Data_length'] + $status['Index_length'];
    }
    $total_size = $total_size / 1024;
    if ($total_size > 1024)
        $total_size = round($total_size / 1024, 2) . ' MB';
    else
        $total_size = round($total_size, 2) . ' KB';
}
if (function_exists('mmcache'))
    $php_accelerator = '<a href="http://turck-mmcache.sourceforge.net/">Turck MMCache</a>';
else if (isset($_PHPA))
    $php_accelerator = '<a href="http://www.php-accelerator.co.uk/">ionCube PHP Accelerator</a>';
else if (function_exists('zend_version'))
    $php_accelerator = '<a href="http://www.zend.com/">Zend Optimizer</a> : ' . zend_version();
else
    $php_accelerator = 'N/A';
$result = $db->query('SELECT COUNT(id) FROM ' . $db->prefix . 'users WHERE gid > 3') or BB_Functions::Error($lang['error_38'], __FILE__, __LINE__, $db->error());
$stats['total_reg_users'] = $db->result($result);
$result = $db->query('SELECT COUNT(id) FROM ' . $db->prefix . 'forums') or BB_Functions::Error($lang['error_80'], __FILE__, __LINE__, $db->error());
$stats['forums'] = $db->result($result);
$result = $db->query('SELECT COUNT(id) FROM ' . $db->prefix . 'categories') or BB_Functions::Error($lang['error_81'], __FILE__, __LINE__, $db->error());
$stats['categories'] = $db->result($result);
$result = $db->query('SELECT COUNT(id) FROM ' . $db->prefix . 'users WHERE gid = 1') or BB_Functions::Error($lang['error_38'], __FILE__, __LINE__, $db->error());
$stats['admin_users'] = $db->result($result);
$result = $db->query('SELECT COUNT(id) FROM ' . $db->prefix . 'users WHERE gid = 2') or BB_Functions::Error($lang['error_38'], __FILE__, __LINE__, $db->error());
$stats['mod_users'] = $db->result($result);
$result = $db->query('SELECT COUNT(id)-1 FROM ' . $db->prefix . 'users WHERE num_posts = 0') or BB_Functions::Error($lang['error_38'], __FILE__, __LINE__, $db->error());
$stats['inactive_users'] = $db->result($result);
$result = $db->query('SELECT id, username FROM ' . $db->prefix . 'users ORDER BY registered DESC LIMIT 1') or BB_Functions::Error($lang['error_39'], __FILE__, __LINE__, $db->error());
$stats['last_user'] = $db->fetch_assoc($result);
$result = $db->query('SELECT COUNT(id) FROM ' . $db->prefix . 'bans') or BB_Functions::Error($lang['error_38'], __FILE__, __LINE__, $db->error());
$stats['banned_users'] = $db->result($result);
$result = $db->query('SELECT COUNT(id) FROM ' . $db->prefix . 'messages') or BB_Functions::Error($lang['error_83'], __FILE__, __LINE__, $db->error());
$stats['total_messages'] = $db->result($result);
$result = $db->query('SELECT COUNT(g_id) FROM ' . $db->prefix . 'usergroups') or BB_Functions::Error($lang['error_82'], __FILE__, __LINE__, $db->error());
$stats['groups'] = $db->result($result);
$result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM ' . $db->prefix . 'forums') or BB_Functions::Error($lang['error_40'], __FILE__, __LINE__, $db->error());
list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);
$stats['total_users'] = $stats['total_reg_users'] + $stats['admin_users'] + $stats['mod_users'];
$page_title = BB_Input::Htmlspecialchars($lang['Admin'] . $lang['Index']);
require FORUM_ROOT . 'admin/header.php';
if ($page == 'Statistics')
{
    echo BB_Template::Generate_Menu($submenu);
    ?>
    <div class="blockform">
        <div class="inbox">
            <table border=0>
                <tr>
                    <td style="width:80%"><b><?php echo $lang['stats_topics'] ?></b></td>
                    <td><?php echo $stats['total_topics'] ?></td>
                </tr>
                <tr>
                    <td><b><?php echo $lang['stats_posts'] ?></b></td>
                    <td><?php echo $stats['total_posts'] ?></td>
                </tr>
                <tr>
                    <td><b><?php echo $lang['stats_forums_categories'] ?></b></td>
                    <td><?php echo $stats['forums'] ?> / <?php echo $stats['categories'] ?></td>
                </tr>
                <tr>
                    <td style="width:80%"><b><?php echo $lang['stats_normal_users'] ?></b></td>
                    <td><?php echo $stats['total_reg_users'] ?></td>
                </tr>
                <tr>
                    <td><b><?php echo $lang['stats_admins'] ?></b></td>
                    <td><?php echo $stats['admin_users'] ?></td>
                </tr>
                <tr>
                    <td><b><?php echo $lang['stats_mods'] ?></b></td>
                    <td><?php echo $stats['mod_users'] ?></td>
                </tr>
                <tr>
                    <td><b><?php echo $lang['stats_avg_posts'] ?></b></td>
                    <td><?php echo round($stats['total_posts'] / $stats['total_users'], 2); ?></td>
                </tr>
                <tr>
                    <td><b><?php echo $lang['stats_avg_topics'] ?></b></td>
                    <td><?php echo round($stats['total_topics'] / $stats['total_users'], 2); ?></td>
                </tr>
                <tr>
                    <td><b><?php echo $lang['inactive_users'] ?></b></td>
                    <td><?php echo $stats['inactive_users'] ?></td>
                </tr>
                <tr>
                    <td><b><?php echo $lang['stats_total_users'] ?></b></td>
                    <td><?php echo $stats['total_users'] ?></td>
                </tr>
                <tr>
                    <td><b><?php echo $lang['stats_banned_users'] ?></b></td>
                    <td><?php echo $stats['banned_users'] ?></td>
                </tr>
                <tr>
                    <td><b><?php echo $lang['stats_groups'] ?></b></td>
                    <td><?php echo $stats['groups'] ?></td>
                </tr>
                <tr>
                    <td style="width:80%"><b><?php echo $lang['stats_pm'] ?></b></td>
                    <td><?php echo $stats['total_messages'] ?></td>
                </tr>
            </table>
        </div>
    </div>
    <?php
}
else if ($page == 'Update')
{
    echo BB_Template::Generate_Menu($submenu);
    if ($forum_user['g_id'] == USER_ADMIN)
    {
        ?>
        <div class="blockform">
            <div class="inbox">
                <table width=100 border=0>
                    <tr>
                        <td><input type="reset" class="b1" style="width:150px" value="<?php echo $lang['CheckUpgrade'] ?>" onclick="window.location.href='index.php?action=check_software_upgrade'"></td>
                    </tr>
                </table>
            </div>
        </div>
        <?php
    }
}
else if ($page == 'Intro')
{
    echo BB_Template::Generate_Menu($submenu);
    if (is_dir('../install'))
    {
        ?>
        <div class="blockform">
            <div class="inbox">
                <p style="float:left"><img src="../include/templates/Default/img/misc/forbidden_bg.png"></p>
                <p style="font-size:14px;font-weight:bold;padding:20px;padding-top:40px;"><?php echo $lang['error_install_exists'] ?></p>
                <div class="clearer"></div>
            </div>
        </div>
        <?php
    }
    ?>
    <div class="blockform">
        <div id="adintro">
            <div class="inbox">
                <p>
    <?php echo $lang['h_1'] ?><br /><br />
                    - <?php echo $lang['h_2'] ?><br />
                    - <?php echo $lang['h_3'] ?><br />
                    - <?php echo $lang['h_4'] ?><br />
                    - <?php echo $lang['h_5'] ?><br />
                    - <?php echo $lang['h_6'] ?><br />
                    - <?php echo $lang['h_7'] ?><br />
                    - <?php echo $lang['h_8'] ?><br />
                    - <?php echo $lang['h_9'] ?><br />
                    - <?php echo $lang['h_10'] ?>
                </p>
            </div>
        </div>
        <div id="adstats">
            <div class="inbox">
                <dl>
                    <dt><b><?php echo $lang['Version']; ?></b></dt>
                    <dd>
                        <?php echo $lang['copy_1'] ?><br />
                        <?php echo $lang['copy_2'] ?><br />
                        <?php echo $lang['copy_3'] ?>
                    </dd>
                    <dt><b><?php echo $lang['Server load']; ?></b></dt>
                    <dd>
                        <?php echo $server_load ?> (<?php echo $num_online['COUNT(user_id)'] ?> <?php echo $lang['users online']; ?>)
                    </dd>
                        <?php
                        if ($forum_user['g_id'] == USER_ADMIN)
                        {
                            ?>
                        <dt><b><?php echo $lang['Environment'] ?></b></dt>
                        <dd>
                            <?php echo $lang['Operating system:'] ?> <?php echo PHP_OS ?><br />
                            <?php echo $lang['Http server:'] ?> <?php echo $HTTP_SERVER_VARS["SERVER_SOFTWARE"] ?><br/>
                            <?php echo $lang['PHP:'] ?> <?php echo phpversion() ?> - <a target="_blank" href="index.php?action=phpinfo"><?php echo $lang['Show info']; ?></a><br />
        <?php echo $lang['Accelerator:'] ?> <?php echo $php_accelerator . "\n" ?>
                        </dd>
                        <dt><b><?php echo $lang['Database']; ?></b></dt>
                        <dd>
        <?php echo $db_version . "\n" ?>
        <?php
        if (isset($total_records) && isset($total_size))
        {
            ?>
                                <br /><?php echo $lang['Rows:'] ?> <?php echo $total_records . "\n" ?>
                                <br /><?php echo $lang['Size:'] ?> <?php echo $total_size . "\n"; ?>
            <?php
        }
    }
    ?>
                    </dd>
                </dl>
            </div>
        </div>
    </div>
    <?php
}
else
    BB_Functions::Message($lang['Bad request']);
require FORUM_ROOT . 'admin/footer.php';
?>
Return current item: XennoBB