'Fatal Error', E_WARNING => 'Warning', E_PARSE => 'Parsing Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Strict Notice', E_RECOVERABLE_ERROR => 'Recoverable Error', E_DEPRECATED => 'Deprecated', E_USER_DEPRECATED => 'User Deprecated', ); function __construct($args){ parent::__construct($args); $sub_page = ''; $parts = explode('/',$this->page->requested); if( count($parts) > 2 ){ $sub_page = $parts[2]; } switch($sub_page){ case 'Log': $this->ErrorLog(); return; default: $this->FatalErrors(); return; } } /** * Display a list of fatal errors * */ function FatalErrors(){ global $dataDir; echo '

'; echo 'Fatal Errors'; echo ' | '; echo \gp\tool::Link('Admin/Errors/Log','Error Log'); echo '

'; //actions $cmd = \gp\tool::GetCommand(); switch($cmd){ case 'ClearError': self::ClearError($_REQUEST['hash']); break; case 'ClearAll': self::ClearAll(); break; } //get unique errors $dir = $dataDir.'/data/_site'; $files = scandir($dir); $errors = array(); foreach($files as $file){ if( strpos($file,'fatal_') === false ){ continue; } $full_path = $dir.'/'.$file; $md5 = md5_file($full_path); $errors[$md5] = $full_path; } echo '

'; if( count($errors) ){ echo 'Found '.count($errors).' Unique Error(s) - '; echo \gp\tool::Link('Admin/Errors','Clear All Errors','cmd=ClearAll','data-cmd="cnreq"','ClearErrors'); }else{ echo 'Hooray! No fatal errors found'; } echo '

'; echo '
'; //display errors foreach($errors as $md5 => $error_file){ self::DisplayFatalError($error_file); } } /** * Display details about a single fatal error * */ public static function DisplayFatalError($error_file){ global $langmessage; $hash = substr(basename($error_file),6); //modified time echo '

'; $filemtime = filemtime($error_file); $elapsed = \gp\admin\Tools::Elapsed( time() - $filemtime ); echo sprintf($langmessage['_ago'],$elapsed); echo ' - '; echo \gp\tool::Link('Admin/Errors','Clear Error','cmd=ClearError&hash='.$hash,array('data-cmd'=>'postlink')); echo '

'; //get info $contents = file_get_contents($error_file); if( $contents[0] == '{' && $error_info = json_decode($contents,true) ){ //continue below }else{ echo '
';
			echo $contents;
			echo '
'; return; } //display details $error_info = array_diff_key($error_info,array('file_modified'=>'','file_size'=>'')); echo '
';
		foreach($error_info as $key => $value){

			echo "\n".str_pad($key,'20',' ');

			switch($key){

				case 'request':
				echo ''.$value.'';
				break;

				case 'type':
				echo self::$types[$value].' ('.$value.')';
				break;

				default:
				echo $value;
				break;
			}
		}
		echo '
'; } /** * Display the error log * */ function ErrorLog(){ global $langmessage; $error_log = ini_get('error_log'); echo '

'; echo \gp\tool::Link('Admin/Errors','Fatal Errors'); echo ' | '; echo ' Error Log'; echo '

'; if( !self::ReadableLog() ){ echo '

Sorry, an error log could not be found or could not be read.

'; echo '

Log File: '.$error_log.'

'; return; } echo '

Please Note: The following errors are not limited to your installation of '.CMS_NAME.'.'; echo '

'; $lines = file($error_log); $lines = array_reverse($lines); $time = null; $displayed = array(); foreach($lines as $line){ $line = trim($line); if( empty($line) ){ continue; } preg_match('#^\[[a-zA-Z0-9:\- ]*\]#',$line,$date); if( count($date) ){ $date = $date[0]; $line = substr($line,strlen($date)); $date = trim($date,'[]'); $new_time = strtotime($date); if( $new_time !== $time ){ if( $time ){ echo ''; } echo '

'; $elapsed = \gp\admin\Tools::Elapsed( time() - $new_time ); echo sprintf($langmessage['_ago'],$elapsed); echo ' ('.$date.')'; echo '

'; echo '
';
					$time = $new_time;
					$displayed = array();
				}
			}


			$line_hash = md5($line);
			if( in_array($line_hash,$displayed) ){
				continue;
			}
			echo $line;
			$displayed[] = $line_hash;
			echo "\n";
		}
		echo '
'; } /** * Clear an error * */ public static function ClearError($hash){ global $dataDir; if( !preg_match('#^[a-zA-Z0-9_]+$#',$hash) ){ message('Invalid Request'); return; } $dir = $dataDir.'/data/_site'; $file = $dir.'/fatal_'.$hash; if( !file_exists($file) ){ return; } $hash = md5_file($file); unlink($file); //remove matching errors $files = scandir($dir); foreach($files as $file){ if( strpos($file,'fatal_') !== 0 ){ continue; } $full_path = $dir.'/'.$file; if( $hash == md5_file($full_path) ){ unlink($full_path); } } } /** * Clear all fatal errors * */ public static function ClearAll(){ global $dataDir; if( !\gp\tool::verify_nonce( 'ClearErrors' ) ){ return; } $dir = $dataDir.'/data/_site'; //remove matching errors $files = scandir($dir); foreach($files as $file){ if( strpos($file,'fatal_') !== 0 ){ continue; } $full_path = $dir.'/'.$file; unlink($full_path); } } public static function ReadableLog(){ $error_log = ini_get('error_log'); if( empty($error_log) || !file_exists($error_log) ){ return false; } if( !is_readable($error_log) ){ return false; } return true; } }