View file admin/error_log.php

File size: 8.87Kb
<?php

error_reporting(E_ALL);
session_name('ERROR_LOG_SESSION');
session_start();
$mt = microtime(true);

if($_SERVER['REMOTE_ADDR'] == '127.0.0.1')
 {
 $c['a_login'] = 'Admin';
 $c['a_password'] = '123';
 }else
 {
 $c['a_login'] = 'Morgan';
 $c['a_password'] = '5462467275';
 }

$c['filename'] = $_SERVER['DOCUMENT_ROOT'].'/admin/data/errors.dat';
$c['myname'] = basename($_SERVER['SCRIPT_NAME']);
$c['onpage'] = 10;

//=============================================\\
  function str($str,$do = 0)
 {
 $str = htmlspecialchars(trim($str),ENT_QUOTES);
 if($do > 0)$str = substr($str,0,$do);
  return $str;
 }

  function int($int){return abs(intval($int));}
  function dump($var){echo '<br />'.print_r($var).'<br />';}
//=============================================//

if(!isset($_SESSION['set']))
 {
 $_SESSION['set'] = array('type'=>'none','sort'=>'date','sort2'=>'desc');
 }

if(empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER'] != $c['a_login'] || $_SERVER['PHP_AUTH_PW'] != $c['a_password'])
{
header('WWW-Authenticate: Basic realm="Some Realm"');
header('HTTP/1.0 401 Unauthorized');
exit('<html><head><title>Unathorized</title></head><body>Unathorized</body></html>');
}

ob_start();

header('Content-Type: text/vnd.wap.wml;charset=utf-8');
header('Cache-Control: no-cache');

echo '<?xml version="1.0"?>';
echo '<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">';
echo '<wml><card id="hello" title="Просмотр логов ошибок">';

if(!file_exists($c['filename']) || !is_readable($c['filename']))
{
echo 'Файл <b>'.$c['filename'].'</b> не существует, или недоступен для чтения!';
if(!file_exists($c['filename']))file_put_contents($c['filename'],null);
chmod($c['filename'],0777);
}else
{

 switch($mode = !empty($_GET['mode']) ? $_GET['mode'] : null)
{
//============================
// ПРОСМОТР ЛОГОВ
//============================
default:

echo '<center><b>Просмотр логов</b></center>';

$file_content = file($c['filename']);
$count_errors = count($file_content);
$filesize = filesize($c['filename']);

echo '<b>'.basename($c['filename']).'</b>, размер - <b>'.($filesize >= 1024 ? round($filesize / 1024,1).'кб' : $filesize.'б').'</b>, записей - <b>'.$count_errors.'</b><br />
&#187;<a href="'.$c['myname'].'?mode=filtr">Настройть фильтр</a><br />
-----------------<br />';
if($count_errors > 0)
{

//-- идет обработка файла
if($_SESSION['set']['sort'] == 'date')
 {
 //-- если сортировка ненужна
# $errors = $file_content;
 if($_SESSION['set']['sort2']  == 'desc')$errors = array_reverse($file_content);
 else $errors = $file_content;
# $errors = array_reverse($errors);
# $errors = array_reverse($errors);
# $errors = array_reverse($errors);
# $errors = array_reverse($errors,true);
# $errors = array_reverse($errors,true);

# dump($errors);

# if($_SESSION['set']['sort2']  == 'desc')$errors = array_reverse($errors,true);

# dump($errors);

 }else
 {
 //-- а вот если нужна

$s['num'] = $s['str'] = $s['file'] = $s['line'] = array();

   for($i = 0;$i < $count_errors;$i++)
  {
  list($type,$num,$str,$file,$line,$date) = explode(':||:',trim($file_content[$i]));
  //-- убираем то что ненужно
  if($_SESSION['set']['type'] != 'none' && $_SESSION['set']['type'] != $type)continue;
#  echo '#'.$i.' : '.$file_content[$i].'<br />';
  //-- рассовываем значения
  $s['values'][$date] = $file_content[$i];
  $s['num'][$date] = $num;
  $s['str'][$date] = $str;
  $s['file'][$date] = $file;
  $s['line'][$date] = $line;
  }

 //-- Сортируем сопсно говоря
 asort($s[$_SESSION['set']['sort']]);
 if($_SESSION['set']['sort2'] == 'desc')arsort($s[$_SESSION['set']['sort']]);

# $count_elements = count($s[$_SESSION['set']['sort']]);

$errors = array();
   foreach($s[$_SESSION['set']['sort']] as $key => $value)
  {
#  echo $s[$_SESSION['set']['sort']][$key];
#  $errors[] = $s[$_SESSION['set']['sort']][$key];
  $errors[] = $s['values'][$key];
  }

 }


$count = count($errors);
if($count > 0)
{
$page = 1;
if(!empty($_GET['page']) && int($_GET['page']) > 0)$page = int($_GET['page']);

$str = ceil($count / $c['onpage']);
if($page > $str){ header('Location: '.$c['myname'].'?rand'.rand(100,999)); exit; }

$end = $page * $c['onpage'];
$start = $end - $c['onpage'];

if($end > $count)$end = $count;

echo 'Показываем записи с <u>'.$start.'</u>, по <u>'.$end.'</u><br />
'.($_SESSION['set']['type'] != 'none' ? 'Только <b>'.$_SESSION['set']['type'].'</b><br />' : null).'<br />';

echo '<hr/><u>№N</u>.'.($_SESSION['set']['type'] == 'none' ? ' <b>Тип</b>, ' : null).'<i>Дата</i>, <b>Ошибка</b>, <i>Файл</i><br />
<hr/>';

//-- Вывод данных
  for($i = $start;$i < $end; $i++)
 {
 if($i != $start && $i != $end)echo '<center>---------------------------</center><br />';
# list($type,$num,$string,$file,$line,$date) = explode(':||:',$errors[$i]);
list($type,$num,$string,$file,$line,$date) = explode(':||:',$errors[$i]);
# echo date('G:i:s',ceil($date)).'<br />';
 echo '<u>№'.($i + 1).'.</u>'.($_SESSION['set']['type'] == 'none' ? ' <b>'.strtoupper($type).'</b>,' : null).' <i>'.date('G:i:s d.m.Y',ceil($date)).'</i>, <b>"'.$num.' : '.str($string).'"</b>, <i>'.$file.' : '.$line.'</i><br />';
 }

if($str > 1)
 {
 echo '<center>--------<br />';
 if($page >= 3)echo '&#171;<a href="'.$c['myname'].'?page=1">В начало</a> '; else echo '&#171;Назад ';
 if($page > 1)echo '&lt;<a href="'.$c['myname'].'?page='.($page - 1).'">Назад</a> '; else echo '&lt;Назад ';
 echo '(<b>'.$page.'</b> из <b>'.$str.'</b>)';
 if($page < $str)echo ' <a href="'.$c['myname'].'?page='.($page + 1).'">Далее</a>&gt;'; else echo ' Далее&gt;';
 if(($str - $page) >= 2)echo ' <a href="'.$c['myname'].'?page='.($str).'">В конец</a>&#187;'; else echo ' В конец&#187;';
 echo '<br />--------</center>';
 }

}else echo '<b>После сортировки, данных нет</b>';

}else echo '<b>Файл пуст</b>';

break;
//============================
// ФИЛЬТР
//============================
 case 'filtr':

echo '<center><b>Настройка фильтра</b></center>';

if(!empty($_POST['type']) && !empty($_POST['sort']) && !empty($_POST['sort2']))
 {
 $type = str($_POST['type'],5);
 $sort = str($_POST['sort'],4);
 $sort2 = str($_POST['sort2'],4);
 if(($type == 'none' || $type == 'php' || $type == 'mysql') && ($sort == 'date' || $sort == 'num' || $sort == 'str' || $sort == 'file' || $sort == 'line') && ($sort2 == 'asc' || $sort2 == 'desc'))
  {
  $_SESSION['set'] = array('type'=>$type,'sort'=>$sort,'sort2'=>$sort2);
  header('Location: '.$c['myname'].'?rand'.rand(100,999));
  exit;
  }
 }

echo 'Показывать только : <br />';
echo '<select name="type"><option value="none"'.($_SESSION['set']['type'] == 'none' ? ' selected="selected"' : null).'>---</option><option value="php"'.($_SESSION['set']['type'] == 'php' ? ' selected="selected"' : null).'>Ошибки PHP</option><option value="mysql"'.($_SESSION['set']['type'] == 'mysql' ? ' selected="selected"' : null).'>Ошибки MySQL</option></select><br />';

echo 'Сортировка по : <br />';
echo '<select name="sort"><option value="date"'.($_SESSION['set']['sort'] == 'date' ? ' selected="selected"' : null).'>Дате</option><option value="num"'.($_SESSION['set']['sort'] == 'num' ? ' selected="selected"' : null).'>Коду ошибки</option><option value="str"'.($_SESSION['set']['sort'] == 'str' ? ' selected="selected"' : null).'>Содержанию ошибки</option><option value="file"'.($_SESSION['set']['sort'] == 'file' ? ' selected="selected"' : null).'>Файлу</option><option value="line"'.($_SESSION['set']['sort'] == 'line' ? ' selected="selected"' : null).'>Строке</option></select><br />';

echo 'В порядке : <br />';
echo '<select name="sort2"><option value="asc"'.($_SESSION['set']['sort2'] == 'asc' ? ' selected="selected"' : null).'>Возрастания</option><option value="desc"'.($_SESSION['set']['sort2'] == 'desc' ? ' selected="selected"' : null).'>Убывания</option></select><br />';

echo '<anchor>Сохранить<go href="'.$c['myname'].'?mode=filtr" method="POST"><postfield name="type" value="$(type)"/><postfield name="sort" value="$(sort)"/><postfield name="sort2" value="$(sort2)"/></go></anchor>';

# <postfield name="" value="$()"/>

break;
/*
//============================
//
//============================
 case '-':

break;
*/
}

}

echo '<br />
-------<br />
(c)<a href="/">Morgan</a><br />
<small>['.round(microtime(true) - $mt,4).' sec]</small></card></wml>';

ob_end_flush();
exit;

?>