All pastes #1577388 Raw Edit

PHP error log scanner

public php v1 · immutable
#1577388 ·published 2009-09-24 02:49 UTC
rendered paste body
<?php/*                 By aldo of http://mschat.net/    What's this PHP script do? It scans the directories that are    inside the base directory you supply for any PHP error log files          and then allows you to display them, of course!*/# Where do you want to begin the search for error logs?# Default: current directory where this file is in.$base_dir = dirname(__FILE__);# What is the filename of the error log?# You can leave this blank if you want it to detect the global setting from the php.ini$log_filename = '';# Don't edit below this line!!!if(empty($log_filename))  $log_filename = @ini_get('error_log') ? @ini_get('error_log') : 'php_errors.log';if(!defined('PHP_EOL'))  define('PHP_EOL', "\r\n", true);$total_elements = 0;function scan_directory($dirname, $current_level = 0){  global $log_filename, $total_elements;  if(is_dir($dirname))  {    echo tabulate($current_level), '--&gt; Scanning "'. htmlspecialchars($dirname). '"... ';    $objects = scandir($dirname);    if(in_array($log_filename, $objects))    {      echo 'Found error log! (', round(filesize($dirname. '/'. $log_filename) / 1024, 2), 'kB)';      $error_log = @file_get_contents($dirname. '/'. $log_filename);      $errors = explode("\n", $error_log);      if(count($errors))      {        echo ' <a href="javascript:void(0);" onclick="toggle_element(this, \'errors_', ++$total_elements, '\');">Show errors</a>', PHP_EOL;        echo tabulate($current_level), '<div id="errors_', $total_elements, '" style="display: none;">', PHP_EOL;        foreach($errors as $error)          echo tabulate($current_level), trim($error), PHP_EOL;        echo tabulate($current_level), '</div>', PHP_EOL;      }      else        echo tabulate($current_level), PHP_EOL, 'No errors in the error log.', PHP_EOL;    }    else      echo 'No error log found.', PHP_EOL;    foreach($objects as $obj)      if(is_dir($dirname. '/'. $obj) && !in_array($obj, array('.', '..')))      {        echo PHP_EOL;        scan_directory($dirname. '/'. $obj, $current_level + 1);      }  }  else    echo tabulate($current_level), 'Error: "'. htmlspecialchars($dirname). '" is not a directory!', PHP_EOL;}function tabulate($current_level){  return str_repeat("\t", $current_level);}echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>  <title>PHP error log scanner</title>  <meta name="robots" content="noindex" />  <script type="text/javascript" language="JavaScript">    function toggle_element(callee, element_id)    {      if(document.getElementById(element_id))      {        var element = document.getElementById(element_id);        if(element.style.display == \'none\')        {          element.style.display = \'block\';          callee.innerHTML = \'Hide errors\';        }        else        {          element.style.display = \'none\';          callee.innerHTML = \'Show errors\';        }      }      else        alert(\'Could not toggle the element \\\'\' + element_id + \'\\\'\');    }  </script></head><body><pre>', PHP_EOL;scan_directory($base_dir);echo '</pre></body></html>';