<?
/*
PTK - DFLabs
Copyright (C) 2008 - DFLabs srl - All rights reserved
hide@address.com
*/
include("check_session.php");
include("../config/conf.php");
include("sanitize.php");
include("loggerClass.php");
if (isset($_SESSION['log_token']) && strcmp($_SESSION['log_token'],$_GET['tk'])==0 && strcmp($_SESSION['user'],"admin")==0){
$token = sanitize($_GET['tk'],PARANOID);
$path = $_GET['path'];
$path = charset_decode_utf_8($path);
$path = preg_replace("/[^a-zA-Z0-9\.]/", "", $path);
$type = sanitize($_GET['type'],PARANOID);
if (file_exists("$INSTALLDIR/log/$path")) {
if($type=='export'){
if(($path!='')&&($_SESSION['user']=='admin')){
header('Content-Type: application/octet-stream');
header("Content-Description: PTK file export");
header('Content-Length: ' . filesize("$INSTALLDIR/log/$path"));
header('Content-Disposition: attachment; filename=' . $path);
readfile("$INSTALLDIR/log/$path");
}
}else{
$sort = $_GET['sort'];
if($_SESSION['log_verse']==SORT_DESC){
$verse = SORT_ASC;
$sort_img = "../img/sort_asc.png";
}else{
$verse = SORT_DESC;
$sort_img = "../img/sort_desc.png";
}
$_SESSION['log_verse'] = $verse;
$_SESSION['log_sort'] = $sort;
$log = array();
$fp = fopen("../log/$path", 'r');
while(!feof($fp)){
$line = fgets($fp);
if($line!=''){
$out = preg_split("/\s,\s/", $line);
array_push($log, $out);
}
}
fclose($fp);
if (sizeof($log)!=0){
foreach ($log as $key => $row) {
$sort_date[$key] = $row[0];
$sort_time[$key] = $row[1];
$sort_user[$key] = $row[2];
$sort_ip[$key] = $row[3];
$sort_action[$key] = $row[4];
}
switch($sort){
case '0': array_multisort($sort_date, $verse, $log); break;
case '1': array_multisort($sort_time, $verse, $log); break;
case '2': array_multisort($sort_user, $verse, $log); break;
case '3': array_multisort($sort_ip, $verse, $log); break;
case '4': array_multisort($sort_action, $verse, $log); break;
}
?>
<table class="timeline" style="width: 99.5%;margin:0px;">
<th onclick="ajax_request('get_log.php?tk=<?=$token?>&path=<?=$path;?>&sort=0', 'log_content')">Date<?if($sort==0){?> <img src="<?=$sort_img;?>"><?}?></th>
<th onclick="ajax_request('get_log.php?tk=<?=$token?>&path=<?=$path;?>&sort=1', 'log_content')">Time<?if($sort==1){?> <img src="<?=$sort_img;?>"><?}?></th>
<th onclick="ajax_request('get_log.php?tk=<?=$token?>&path=<?=$path;?>&sort=2', 'log_content')">Username<?if($sort==2){?> <img src="<?=$sort_img;?>"><?}?></th>
<th onclick="ajax_request('get_log.php?tk=<?=$token?>&path=<?=$path;?>&sort=3', 'log_content')">IP source<?if($sort==3){?> <img src="<?=$sort_img;?>"><?}?></th>
<th onclick="ajax_request('get_log.php?tk=<?=$token?>&path=<?=$path;?>&sort=4', 'log_content')">Message<?if($sort==4){?> <img src="<?=$sort_img;?>"><?}?></th>
<?
foreach($log as $log){
echo "<tr>";
echo "<td>".$log[0]."</td>";
echo "<td>".$log[1]."</td>";
echo "<td>".$log[2]."</td>";
echo "<td>".$log[3]."</td>";
echo "<td>".$log[4]."</td>";
echo "</tr>";
}
}else{
?>
<table class="timeline" style="width: 99.5%;margin:0px;">
<th>Date</th>
<th>Time</th>
<th>Username</th>
<th>IP source</th>
<th>Message</th>
<tr>
<td align="center" colspan="5"><b>Empty file log</b></td>
</tr>
</table>
<?}
}
?>
</table>
<?
}else{
echo "Log not found";
}
}else{
new AuditLog('Unauthorized access to get_log ');
header("location: goto_home.php");
}?>