<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2004 by Philippe Brunier   */
/*                                                                      */
/* Session and log Viewer Copyright (c) 2004 - Tribal-Dolphin           */
/*                                                                      */
/* 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.       */
/************************************************************************/
if (!eregi("admin.php", $PHP_SELF)) { Access_Error(); }
global $pdst; $pdst="0";

$result = mysql_query("select radminsuper from authors where aid='$aid'");
list($radminsuper) = mysql_fetch_row($result);
if ($radminsuper!=1) {
   Access_Error();
}
global $language, $ModPath, $ModStart;
$old_language=$language;
include_once("modules/upload/upload.conf.php");
if ($DOCUMENTROOT=="") {
   global $DOCUMENT_ROOT;
   if ($DOCUMENT_ROOT) {
      $DOCUMENTROOT=$DOCUMENT_ROOT;
   } else {
      $DOCUMENTROOT=$_SERVER['DOCUMENT_ROOT'];
   }
}
$FileSecure = $DOCUMENTROOT.$racine."/logs/security.log";
$FileUpload = $DOCUMENTROOT.$rep_log;
$RepTempFil = $DOCUMENT_ROOT.$rep_cache;

$language=$old_language;
include ("modules/$ModPath/lang/session-log-$language.php");
$ThisFile="admin.php?op=Extend-Admin-SubModule&amp;ModPath=".$ModPath."&amp;ModStart=".$ModStart;

function action_log($ThisFile,$classe) {
   echo "<BR>";
   echo "<center><a href=\"".$ThisFile."&amp;subop=vidlog&amp;log=$classe\" CLASS=\"NOIR\">".SessionLog_translate("Vider le fichier")."</a> | ";
   echo "<a href=\"".$ThisFile."&amp;subop=mailog&amp;log=$classe\" CLASS=\"NOIR\">".SessionLog_translate("Recevoir le fichier par mail")."</a> | ";
   echo "<a href=\"".$ThisFile."&amp;subop=vidtemp\" CLASS=\"NOIR\">".SessionLog_translate("Effacer les fichiers temporaires")."</a></center>";
}

opentable();
   echo "<TABLE WIDTH=\"100%\" CELLSPACING=\"2\" CELLPADDING=\"2\" BORDER=\"0\"><TR><TD CLASS=\"HEADER\" WIDTH=\"30%\">\n";
   echo SessionLog_translate("Gestion des Logs");
   echo "</TD><TD CLASS=\"HEADER\">";
   echo "&nbsp;<a href=\"".$ThisFile."&subop=session\" class=\"BOX\">".SessionLog_translate("Liste des Sessions")."</a> | ";
   echo "<a href=\"".$ThisFile."&subop=security\" class=\"BOX\">".SessionLog_translate("Liste des Logs")." : ".SessionLog_translate("SECURITE")."</a>";
   if ($FileUpload!=$FileSecure) {
      echo " | <a href=\"".$ThisFile."&subop=upload\" class=\"BOX\">".SessionLog_translate("Liste des Logs")." : ".SessionLog_translate("TELECHARGEMENT")."</a>";
   }
   echo "</TD></TR></TABLE>\n";
   echo "<BR>\n";

   // Voir les sessions
   if ($subop=="session") {
      echo "<TABLE WIDTH=\"100%\" CELLSPACING=\"2\" CELLPADDING=\"2\" BORDER=\"0\"><TR><TD CLASS=\"HEADER\">\n";
      echo SessionLog_translate("Liste des Sessions");
      echo "</TD></TR></TABLE>\n";
      echo "<BR>\n";
      echo "<TABLE WIDTH=\"100%\" CELLSPACING=\"2\" CELLPADDING=\"2\" BORDER=\"0\">";
      echo "<TR CLASS=\"HEADER\"><TD width=\"30%\">".SessionLog_translate("Nom")."</TD><TD WIDTH=\"5%\">".SessionLog_translate("@ IP")."</TD><TD>".SessionLog_translate("@ IP résolue")."</TD></TR>";
      $result=mysql_query("SELECT username, host_addr, guest FROM session");
      while (list($username, $host_addr, $guest)=mysql_fetch_array($result)) {
         $rowcolor=tablos();
         if ($username==$host_addr) {global $anonymous; $username=$anonymous;}
         echo "<TR $rowcolor><TD>".$username."</TD><TD>".$host_addr."</TD><TD>".gethostbyaddr($host_addr)."</TD></TR>";
      }
      echo "</TABLE>\n";
   }

   // Détails @IP
   if ($subop=="info") {
      echo "<center><h3>".SessionLog_translate("Informations sur l'IP")." <i>".$theip."</i></h3>";
      $hostname = gethostbyaddr($theip);
      if ($theip != $hostname) {
         $domfai = split("[.]",$hostname);
         $prov = $domfai[count($domfai)-2].'.'.$domfai[count($domfai)-1];
         if ($prov == "co.jp" or $prov == "co.uk" ) {
            $provider = $domfai[sizeof($domfai)-3].".".$prov;
         } else {
            $provider = $prov;
         }
      } else {
         $hostname = "";
      }
      OpenTable2();
      echo SessionLog_translate("@ IP")."</td>";
      echo "<td align=center>".SessionLog_translate("@ IP résolue")."</td>";
      echo "<td align=center>".SessionLog_translate("Fournisseur")."</td>";
      $rowcolor=tablos();
      echo "</tr><tr $rowcolor>";
      echo "<td align=center>".$theip."</td>";
      echo "<td align=center>".$hostname."</td>";
      echo "<td align=center>".$provider;
      CloseTable2();
      $subop="security";
      echo "<BR>";
   }

   // Vider les Logs
   if ($subop=="vidlog") {
      if ($log=="security") {
         if (file_exists($FileSecure)) {
            @fopen($FileSecure, "w");
            @fclose($FileSecure);
         }
      }
      if ($log=="upload") {
         if (file_exists($FileUpload)) {
            @fopen($FileUpload, "w");
            @fclose($FileUpload);
         }
      }
   }

   // Email du contenu des Logs
   if ($subop=="mailog") {
      if ($log=="security") {
         if (file_exists($FileSecure)) {
            $fd = fopen($FileSecure, "r");
            while (!feof ($fd)) {
               $Mylog .= fgets($fd, 4096);
            }
            @fclose($FileSecure);
         }
      }
      if ($log=="upload") {
         if (file_exists($FileUpload)) {
            $fd = fopen($FileUpload, "r");
            while (!feof ($fd)) {
               $Mylog .= fgets($fd, 4096);
            }
            @fclose($FileUpload);
         }
      }
      $subject = SessionLog_translate("Fichier de Log de")." ".$sitename;
      send_email($adminmail, $subject, $Mylog, "", true, "text");
   }

   // Vider le répertoire temporaire
   if ($subop=="vidtemp") {
      if (is_dir($RepTempFil)) {
         $dh = opendir($RepTempFil);
         $i = 0;
         while($filename = readdir($dh)) {
            if ($filename === '.' OR $filename === '..' OR $filename === 'index.html') continue;
            @unlink($RepTempFil.$filename);
         }
      }
   }

   // Voir le contenu du fichier security.log
   if ($subop=="security") {
      if (file_exists($FileSecure)) {
         if (filesize($FileSecure) != 0) {
            $fd = fopen($FileSecure, "r");
            while (!feof ($fd)) {
               $rowcolor=tablos();
               $buffer = fgets($fd, 4096);
               if (strlen($buffer)>10) {
                  if (eregi("Upload", $buffer)) {
                     $UpLog.="<TR $rowcolor><TD>".$buffer."</TD></TR>";
                  } else {
                    $ip=substr(strrchr($buffer,"=>"),2);
                    $SecLog.="<TR $rowcolor><TD>".$buffer."</TD><TD><a href=\"".$ThisFile."&amp;subop=info&amp;theip=".$ip."\" CLASS=\"NOIR\">".SessionLog_translate("Infos")."</a></TD></TR>";
                  }
               }
            }
            fclose($fd);
         }
      }
      echo "<TABLE WIDTH=\"100%\" CELLSPACING=\"2\" CELLPADDING=\"2\" BORDER=\"0\"><TR><TD CLASS=\"HEADER\">\n";
      echo SessionLog_translate("Liste des Logs")." ".SessionLog_translate("SECURITE")." : <i>security.log</i>";
      echo "</TD></TR></TABLE>\n";
      opentable();
      echo $SecLog;
      closetable();
      echo "<BR><BR>";
      echo "<TABLE WIDTH=\"100%\" CELLSPACING=\"2\" CELLPADDING=\"2\" BORDER=\"0\"><TR><TD CLASS=\"HEADER\">\n";
      echo SessionLog_translate("Liste des Logs")." ".SessionLog_translate("TELECHARGEMENT")." : <i>security.log</i>";
      echo "</TD></TR></TABLE>\n";
      opentable();
      echo $UpLog;
      closetable();
      action_log($ThisFile,"security");
   }

   // Voir le contenu du fichier d'upload si différent de security.log (upload.conf.php)
   if ($subop=="upload") {
      if ($FileUpload!=$FileSecure) {
         if (file_exists($FileUpload)) {
            if (filesize($FileUpload) != 0) {
               $fd = fopen($FileUpload, "r");
               while (!feof ($fd)) {
                  $rowcolor=tablos();
                  $buffer = fgets($fd, 4096);
                  $UpLog.="<TR $rowcolor><TD>".$buffer."</TD></TR>";
               }
               fclose($fd);
            }
         }
         echo "<TABLE WIDTH=\"100%\" CELLSPACING=\"2\" CELLPADDING=\"2\" BORDER=\"0\"><TR><TD CLASS=\"HEADER\">\n";
         echo SessionLog_translate("Liste des Logs")." ".SessionLog_translate("TELECHARGEMENT")." : <i>$FileUpload</i>";
         echo "</TD></TR></TABLE>\n";
         opentable();
         echo $UpLog;
         closetable();
         action_log($ThisFile,"upload");
      }
   }
closetable();
?>