<?php
/**
 * $Source: /home/cvs/nukescripts/admin/modules/cMax.php,v $
 * $Revision: 1.0.1-1 $
 * $Author: cyril $
 * $Date: 2006/08/22 12:49:01 $
 * Ajout 'vider journal de débug'
 */
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.org                                                  */
/*                                                                      */
/* This program 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.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
if (!defined('ADMIN_ALLOW') && !defined('ADMIN_MAX')) {
	die ("Access Denied");
}
global $admin_file;
$aid   = substr("$aid", 0,25);
$row   = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `radminsuper` FROM `".TABLE_AUTHORS."` WHERE `aid`='$aid'"));
$acces = $GLOBALS['db']->XMFbin($row['radminsuper']);
if ($acces == 1) {

get_adminlang("cmax");

global $admintheme;
if (is_file("admin/themes/$admintheme/index.php")) {include_once("admin/themes/$admintheme/index.php");}
$imgno = "<img src='images/no.png' alt='No' />";
$imgok = "<img src='images/ok.png' alt='Ok' />";
if (is_file("kernel/popup.php")) {
include_once ("kernel/popup.php");}


function ProgressBar($percent) {
    $percent = $GLOBALS['db']->XMFnum($percent);
    $bmimage = "images/bar_left.png";
    $bmprogress  = "<img src='$bmimage' width='1' height='7' alt='' />";
    if($percent == 0){
        $bmimage = "images/bar_center_red.png";
        $bmprogress .= "<img src='$bmimage' width='400' height='7' alt='$percent%' title='$percent%' />";
    } else {
        if($percent > 100){ $progress = 400; } else { $progress = $percent*4; }
        $bmimage = "images/bar_center_grn.png";
        $bmprogress .= "<img src='$bmimage' width='".$progress."' height='7' alt='$percent%' title='$percent%' />";
        if($progress < 400){
            $incomplete = 400 - $progress;
            $bmimage = "images/bar_center_red.png";
            $bmprogress .= "<img src='$bmimage' width='".$incomplete."' height='7' alt='$percent%' title='$percent%' />";
        }
    }
    $bmimage = "images/bar_right.png";
    $bmprogress .= "<img src='$bmimage' width='1' height='7' alt='' />";
    return($bmprogress);
}


function max_sessions($num) {
if (empty($num)) { incoh(); }
global $admin_file;
$sql = "SELECT `uname`, `time`, `host_addr`, `Wurl`, `Wname` FROM `".TABLE_SESSION."` WHERE `guest`='0'";
if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _session', '', __LINE__, __FILE__, $sql);}

$sql1 = "SELECT `uname`, `time`, `Wurl`, `Wname` FROM `".TABLE_SESSION."` WHERE `guest`='1'";
if ( !($result1 = $GLOBALS['db']->sql_query($sql1)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _session', '', __LINE__, __FILE__, $sql1);}


echo "<table width='100%' valign='top' colspan='2'><tr><td width='45%' align='left' valign='top'><table border='1' colspan='6' width='100%'>";
echo "<b>"._ADMINS."</b><br />";
 $sqlat = "SELECT `aid` from `".TABLE_AUTHORS."`";
if ( !($resultat = $GLOBALS['db']->sql_query($sqlat)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _authors', '', __LINE__, __FILE__, $sqlat);}
    while ($rowat = $GLOBALS['db']->sql_fetchrow($resultat)) {
	$a_aid = stripslashes($rowat['aid']);
$sql2 = "SELECT `uname`, `time`, `host_addr`, `Wurl`, `Wname` FROM ".TABLE_SESSION." WHERE `guest`='0' AND `uname`='$a_aid' ";
if ( !($result2 = $GLOBALS['db']->sql_query($sql2)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _session', '', __LINE__, __FILE__, $sql);}

$row2  = $GLOBALS['db']->sql_fetchrow($result2);
$uname     = stripslashes($row2['uname']);
$time      = stripslashes(date("d-m-Y H:i:s", $row2['time']));
$host_addr = stripslashes($row2['host_addr']);
$Wurl      = stripslashes($row2['Wurl']);
$Wname     = stripslashes($row2['Wname']);
if ( $Wname == "") { $Wname = "-"; }

if (!empty($uname)) {
echo "<tr><td width='25%'>&nbsp;<a href='modules.php?name=Your_Account&amp;op=userinfo&amp;username=$uname' target='new'>$uname</a> </td><td width='25%'>$host_addr</td><td width='25%'>$time</td><td width='25%'> <a href='$Wurl' target='new'>$Wurl</a></td><td> <a href='$Wurl' target='new'>$Wname</a></td></tr>";
}
}
echo "</table></td></tr></table>";

br('1');
echo "<table width='100%' valign='top' colspan='2'><tr><td width='45%' align='left' valign='top'><table border='1' colspan='5' width='100%'>"
    ."<b>"._GYAT."</b>";
br('1');
while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
$uname     = stripslashes($row['uname']);
$time      = stripslashes(date("d-m-Y H:i:s", $row['time']));
$host_addr = stripslashes($row['host_addr']);
$url_m     = stripslashes($row['Wurl']);
$Wname     = stripslashes($row['Wname']);
if ( $Wname == "") { $Wname = "-"; }
echo "<tr><td width='20%'>&nbsp;<a href='modules.php?name=Your_Account&amp;op=userinfo&amp;username=$uname' target='new'>$uname</a> </td><td>$host_addr</td><td>$time</td><td> <a href='$url_m' target='new'>$Wname</a></td><td><a href='$admin_file.php?op=max_sessionkill&amp;session=$uname'><img src='images/nukesentinel/delete.png' border='0' alt='Delete' title='Delete' /></a></td></tr>";

}

echo "</table></td><td width='45%' align='left' valign='top'><table border='1' colspan='3' width='100%' border='1' colspan='5'>"
    ."<b>"._VISITORS."</b>";
br('1');
while ($row1 = $GLOBALS['db']->sql_fetchrow($result1)) {
$uname     = stripslashes($row1['uname']);
$time      = stripslashes(date("d-m-Y H:i:s", $row1['time']));
$host_addr = stripslashes($row1['host_addr']);
$url_v     = stripslashes($row1['Wurl']);
$Wname     = stripslashes($row1['Wname']);
if ( $Wname == "") { $Wname = "-"; }
echo "<tr><td width='20%'>&nbsp;$uname</td><td>$host_addr</td><td>$time</td><td> <a href='$url_v' target='new'>$Wname</a></td><td><a href='$admin_file.php?op=max_sessionkill&amp;session=$uname'><img src='images/nukesentinel/delete.png' border='0' alt='Delete' title='Delete' /></td></tr>";

}
echo "</table></td></tr></table>";
if (empty($num)) { incof(); }
}

function max_sessionkill($session) {
global $admin_file;
$GLOBALS['db']->sql_query("DELETE FROM `".TABLE_SESSION."` WHERE `uname`='$session' ");
redirect_url("".$admin_file.".php?op=max_sessions");
}


function max_debug($num) {
if (empty($num)) { incoh(); }
global $admin_file, $bgcolor2, $textcolor2, $bgcolor1;
br('1');
echo "<center><img src='images/trashmini.png' alt='' />&nbsp;<a href='".$admin_file.".php?op=EmptyDebug'>"._EMPTY_MAXDEBUG."</a></center>";
br('1');
echo "<table width='100%' border='0' cellpadding='2' cellspacing='2'><tr>\n";
echo "<td bgcolor='$bgcolor2' align='center'><font color='$textcolor2'><b>"._ID."</b></font></td>\n";
echo "<td bgcolor='$bgcolor2' align='center'><font color='$textcolor2'><b>"._DATE."</b></font></td>\n";
echo "<td bgcolor='$bgcolor2' align='center'><font color='$textcolor2'><b>"._MESSAGE."</b></font></td>\n";
echo "<td bgcolor='$bgcolor2' align='center'><font color='$textcolor2'><b>"._NAME."</b></font></td>\n";
echo "<td bgcolor='$bgcolor2' align='center'><font color='$textcolor2'><b>"._URL."</b></font></td>\n";
echo "<td bgcolor='$bgcolor2' align='center'><font color='$textcolor2'><b>"._IP."</b></font></td>\n";
echo "<td bgcolor='$bgcolor2' align='center'><font color='$textcolor2'><b>"._ACTION."</b></font></td></tr>\n";
$dcolor_A = "WHITE";
$dcolor_B = "$bgcolor1";

$result = $GLOBALS['db']->sql_query("SELECT `eid`, `errors_date`, `errors_description`, `user_id`, `user_name`, `adresse`, `user_ip` FROM `".TABLE_ERRORS."` ORDER BY `eid` DESC");
 while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
$eid                = $GLOBALS['db']->XMFnum($row['eid']);
$errors_date        = formatTimestamp(stripslashes($row['errors_date']));
$errors_description = nl2br(stripslashes($row['errors_description']));
$user_id            = $GLOBALS['db']->XMFnum($row['user_id']);
$user_name          = stripslashes($row['user_name']);
$adresse            = stripslashes($row['adresse']);
$user_ip            = stripslashes($row['user_ip']);

$dcolor = ($a == 0 ? $dcolor_A : $dcolor_B);
echo "<tr><td bgcolor='$dcolor' align='center'>$eid</b></font></a></td>";
echo "<td bgcolor='$dcolor' align='center'>$errors_date</td>\n";
echo "<td bgcolor='$dcolor' align='center'>$errors_description</td>\n";
echo "<td bgcolor='$dcolor' align='center'>$user_name</td>\n";
echo "<td bgcolor='$dcolor' align='center'><a href='$adresse'>$adresse</a></td>\n";
echo "<td bgcolor='$dcolor' align='center'>$user_ip</td>\n";
echo "<td bgcolor='$dcolor' align='center'><a href='".$admin_file.".php?op=DelDebug&amp;eid=$eid'><img src='images/delete.png' border='0' alt='"._DELETE."' title='"._DELETE."' /></a></td></tr>\n";
$a = ($dcolor == $dcolor_A ? 1 : 0);
	}
echo "</table>\n";

$GLOBALS['db']->sql_freeresult($result);
if (empty($num)) { incof(); }
}

function max_LogAcessAdmin($num) {
if (empty($num)) { incoh(); }
global $cache, $admin_file;
Max_OpenTable();
echo "<center><a href='".$admin_file.".php?op=max_LogAcessAdmin'>"._ALLOWACCESSADMIN."</a> - <a href='".$admin_file.".php?op=max_LogAcessAdminDeny'>"._NOALLOWACCESSADMIN."</a></center>";
Max_CloseTable();
br('1');
echo "<center><textarea cols='120' rows='30' wrap='virtual'>";
$logfile = "".$cache."/logs/adminallow.log";
$fp = fopen($logfile, 'r');

$i = 1;
while (!feof($fp)) {
$ligne = fgets($fp,1024);
if (!feof($fp)) {
echo "$ligne";
$i++;
}
}
fclose($fp);

echo "</textarea></center>";
if (empty($num)) { incof(); }
}

function max_LogAcessAdminDeny($num) {
if (empty($num)) { incoh(); }
global $cache, $admin_file;
Max_OpenTable();
echo "<center><a href='".$admin_file.".php?op=max_LogAcessAdmin'>"._ALLOWACCESSADMIN."</a> - <a href='".$admin_file.".php?op=max_LogAcessAdminDeny'>"._NOALLOWACCESSADMIN."</a></center>";
Max_CloseTable();
br('1');
echo "<center><textarea cols='120' rows='30' wrap='virtual'>";
$logfile = "".$cache."/logs/admindeny.log";
$fp = fopen($logfile, 'r');

$i = 1;
while (!feof($fp)) {
$ligne = fgets($fp,1024);
if (!feof($fp)) {
echo "$ligne";
$i++;
}
}
fclose($fp);

echo "</textarea></center>";
if (empty($num)) { incof(); }
}

function menu_cache() {
global $admin_file;
echo "<table width='70%' align='center'><tr><td width='33%'>"
        ."<img src='images/blocks/cachebloc.png' alt='"._CACHEBLOCKS."' title='"._CACHEBLOCKS."' />&nbsp;<a href='".$admin_file.".php?op=cMaxCache_Blocks'>"._CACHEBLOCKS."</a></td><td>"
	."<img src='images/nukesentinel/delete.png' alt='' /> <a href='".$admin_file.".php?op=EmptyCache&amp;folder=Blocks'>"._EMPTYCACHEBLOCKS."</a></td><td width='33%'>"
	."<a href=\"".$admin_file.".php?op=ListingcMaxBlocks\" onclick=\"NewsReadWindow(this.href,'ListingcMaxBlocks','700','500','yes');return false;\"><img src='images/view.gif' alt='"._SHOW."' title='"._SHOW."' border='0' width='17' height='17' />&nbsp;"._LISTING_BLOCKS."</a>"
	."</td></tr><tr><td width='33%'>"
        ."<img src='images/blocks/cachemod.png' alt='"._CACHEMODULES."' title='"._CACHEMODULES."' />&nbsp;<a href='".$admin_file.".php?op=cMaxCache_Modules'>"._CACHEMODULES."</a></td><td>"
	."<img src='images/nukesentinel/delete.png' alt='' /> <a href='".$admin_file.".php?op=EmptyCache&amp;folder=Modules'>"._EMPTYCACHEMODULES."</a></td><td width='33%'>"
        ."<a href=\"".$admin_file.".php?op=ListingcMax\" onclick=\"NewsReadWindow(this.href,'ListingcMax','700','500','yes');return false;\"><img src='images/view.gif' alt='"._SHOW."' title='"._SHOW."' border='0' width='17' height='17' />&nbsp;"._LISTING_MODULES."</a>"
	."</td></tr><tr><td></td><td></td><td width='33%'>"
        ."<a href=\"".$admin_file.".php?op=ListingcMaxConfiguration\" onclick=\"NewsReadWindow(this.href,'ListingcMaxConfiguration','700','500','yes');return false;\"><img src='images/view.gif' alt='"._SHOW."' title='"._SHOW."' border='0' width='17' height='17' />&nbsp;"._LISTING_CONFIG."</a>"
	."</td></tr></table><br />";
}

if($admintest && $adminsecu)  {
switch($op) {

   case 'cMax':include_once('admin/modules/cMax/cMax.php');break;
   case 'cMaxCache_Modules':include_once('admin/modules/cMax/cMaxCache_Modules.php');break;
   case 'cMaxCache_Blocks':include_once('admin/modules/cMax/cMaxCache_Blocks.php');break;
   case 'max_LogAcessAdmin':max_LogAcessAdmin($num);break;
   case 'max_LogAcessAdminDeny':max_LogAcessAdminDeny($num);break;
   case 'max_debug':max_debug($num);break;
   case 'max_sessions':max_sessions($num);break;
   case 'max_sessionkill':max_sessionkill($session);break;
   case 'mini_dazibao':include_once('admin/modules/cMax/mini_dazibao.php');break;
   case 'Dazibao':include_once('admin/modules/cMax/Dazibao.php');break;
   case 'EnvoyerDazibao':include_once('admin/modules/cMax/EnvoyerDazibao.php');break;
   case 'ModDazibao':include_once('admin/modules/cMax/ModDazibao.php');break;
   case 'DelDazibao':include_once('admin/modules/cMax/DelDazibao.php');break;
   case 'UpdDazibao':include_once('admin/modules/cMax/UpdDazibao.php');break;
   case 'UpdatecMax':include_once('admin/modules/cMax/UpdatecMax.php');break;
   case 'UpdatecMaxBlocks':include_once('admin/modules/cMax/UpdatecMaxBlocks.php');break;
   case 'CreatecMax':include_once('admin/modules/cMax/CreatecMax.php');break;
   case 'DeactivecMax':include_once('admin/modules/cMax/DeactivecMax.php');break;
   case 'ReactivecMax':include_once('admin/modules/cMax/ReactivecMax.php');break;
   case 'DeleteFilecMax':include_once('admin/modules/cMax/DeleteFilecMax.php');break;
   case 'DeleteFilecMaxBlocks':include_once('admin/modules/cMax/DeleteFilecMaxBlocks.php');break;
   case 'DeleteFilecMaxConfiguration':include_once('admin/modules/cMax/DeleteFilecMaxConfiguration.php');break;
   case 'ViewFilecMax':include_once "".$cache."/Modules/".$filename."";die();break;
   case 'ViewFilecMaxBlocks':include_once "".$cache."/Blocks/".$filename."";die();break;
   case 'ViewPHPInfo':include_once('admin/modules/cMax/ViewPHPInfo.php');break;
   case 'ListingcMax':include_once('admin/modules/cMax/ListingcMax.php');break;
   case 'ListingcMaxBlocks':include_once('admin/modules/cMax/ListingcMaxBlocks.php');break;
   case 'ListingcMaxConfiguration':include_once('admin/modules/cMax/ListingcMaxConfiguration.php');break;
   case 'CacheSize':include_once('admin/modules/cMax/CacheSize.php');break;
   case 'cMaxSizeFolder':include_once('admin/modules/cMax/cMaxSizeFolder.php');break;
   case 'cMaxFolderKernel':include_once('admin/modules/cMax/cMaxFolderKernel.php');break;
   case 'cMaxSizeWebSpace':include_once('admin/modules/cMax/cMaxSizeWebSpace.php');break;
   case 'cMaxFolderBlocks':include_once('admin/modules/cMax/cMaxFolderBlocks.php');break;
   case 'cMaxFolderThemes':include_once('admin/modules/cMax/cMaxFolderThemes.php');break;
   case 'cMaxFolderIncludes':include_once('admin/modules/cMax/cMaxFolderIncludes.php');break;
   case 'cMaxFolderAbuse':include_once('admin/modules/cMax/cMaxFolderAbuse.php');break;
   case 'cMaxFolderLanguage':include_once('admin/modules/cMax/cMaxFolderLanguage.php');break;
   case 'cMaxFolderModules':include_once('admin/modules/cMax/cMaxFolderModules.php');break;
   case 'cMaxFolderImages':include_once('admin/modules/cMax/cMaxFolderImages.php');break;
   case 'cMaxFolderAdmin':include_once('admin/modules/cMax/cMaxFolderAdmin.php');break;
   case 'LicenceGPL':include_once('admin/modules/cMax/LicenceGPL.php');break;
   case 'Credits':include_once('admin/modules/cMax/Credits.php');break;
   case 'MentionsLegales':include_once('admin/modules/cMax/MentionsLegales.php');break;
   case 'MentionsLegales_Save':include_once('admin/modules/cMax/MentionsLegales_Save.php');break;
   case 'DelDebug':include_once('admin/modules/cMax/DelDebug.php');break;
   case 'EmptyCache':include_once('admin/modules/cMax/EmptyCache.php');break;
   case 'EmptyDebug':include_once('admin/modules/cMax/EmptyDebug.php');break;
   case 'ConfirmEmptyCache':include_once('admin/modules/cMax/ConfirmEmptyCache.php');break;
}

}
} else {
    echo "Access Denied";
}