Changeset 568
- Timestamp:
- Aug 21, 2013, 9:27:56 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Error/Error.php
r565 r568 1 1 <?php 2 2 3 function Report($Backtrace) 3 class ModuleError extends AppModule 4 4 { 5 global $Config; 5 var $Encoding; 6 var $ShowError; 7 var $UserErrors; 8 var $OnError; 9 10 function __construct($System) 11 { 12 parent::__construct($System); 13 $this->Name = 'Error'; 14 $this->Version = '1.0'; 15 $this->Creator = 'Chronos'; 16 $this->License = 'GNU/GPLv3'; 17 $this->Description = 'Error logging and reporting'; 18 $this->Dependencies = array(); 19 20 $this->Encoding = 'utf-8'; 21 $this->ShowError = false; 22 $this->UserErrors = E_ALL; //E_ERROR | E_WARNING | E_PARSE; 23 $this->OnError = array(); 24 } 6 25 7 $Error = ''; 8 $Date = date('Y-m-d H:i:s'); 9 foreach($Backtrace as $Item) 26 function Install() 10 27 { 11 if(!array_key_exists('line', $Item)) $Item['line'] = ''; 12 if(!array_key_exists('file', $Item)) $Item['file'] = ''; 13 if(!array_key_exists('function', $Item)) $Item['function'] = ''; 14 $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function']; 15 $Arguments = ''; 16 if(array_key_exists('args', $Item) and is_array($Item['args'])) 17 foreach($Item['args'] as $Item) 18 { 19 if(is_array($Item)) $Arguments .= "'".serialize($Item)."',"; 20 else $Arguments .= "'".serialize($Item)."',"; 21 } 22 if(strlen($Arguments) > 0) $Error .= '('.substr($Arguments, 0, -1).')'; 23 $Error .= "\n"; 28 parent::Install(); 24 29 } 25 $Error .= "\n"; 26 //if($Config['Web']['ErrorLogFile'] != '') 27 //error_log($Error, 3, $Config['Web']['ErrorLogFile']); 28 // Pošli mi zprávu (pokud je to kritická chyba) 29 //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error); 30 // Show error message 31 if($Config['Web']['ShowPHPError'] == true) 30 31 function UnInstall() 32 32 { 33 echo('<?xml version="1.0" encoding="utf-8"?>'."\n". 34 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'. 35 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">'. 36 '<head>'. 37 '<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />'. 38 '</head><body>'. 39 'Došlo k vnitřní chybě!<br /> O chybě byl uvědoměn správce webu a chyba bude brzy odstraněna.<br /><br />'); 40 echo('<pre>'.$Error.'</pre><br />'); 41 echo('</body></html>'); 33 parent::UnInstall(); 34 } 35 36 function Start() 37 { 38 parent::Start(); 39 set_error_handler(array($this, 'ErrorHandler')); 40 set_exception_handler(array($this, 'ExceptionHandler')); 42 41 } 43 WriteLog($Error, LOG_TYPE_ERROR);44 }45 46 function ErrorHandler($Number, $Message, $FileName, $LineNumber, $Variables)47 {48 $UserErrors = E_ALL; //E_ERROR | E_WARNING | E_PARSE;49 $ErrorType = array50 (51 1 => 'Error',52 2 => 'Warning',53 4 => 'Parsing Error',54 8 => 'Notice',55 16 => 'Core Error',56 32 => 'Core Warning',57 64 => 'Compile Error',58 128 => 'Compile Warning',59 256 => 'User Error',60 512 => 'User Warning',61 1024 => 'User Notice'62 );63 42 64 if(($UserErrors & $Number))43 function Stop() 65 44 { 66 $Backtrace = debug_backtrace(); 67 $Backtrace[0]['function'] = $Message; 68 $Backtrace[0]['args'] = ''; 69 $Backtrace[0]['file'] = $FileName; 70 $Backtrace[0]['line'] = $LineNumber; 71 Report($Backtrace); 72 if((E_ERROR | E_PARSE) & $Number) die(); 45 restore_error_handler(); 46 restore_exception_handler(); 47 parent::Stop(); 48 } 49 50 function ErrorHandler($Number, $Message, $FileName, $LineNumber, $Variables) 51 { 52 $ErrorType = array 53 ( 54 1 => 'Error', 55 2 => 'Warning', 56 4 => 'Parsing Error', 57 8 => 'Notice', 58 16 => 'Core Error', 59 32 => 'Core Warning', 60 64 => 'Compile Error', 61 128 => 'Compile Warning', 62 256 => 'User Error', 63 512 => 'User Warning', 64 1024 => 'User Notice' 65 ); 66 67 if(($this->UserErrors & $Number)) 68 { 69 $Backtrace = debug_backtrace(); 70 $Backtrace[0]['function'] = $Message; 71 $Backtrace[0]['args'] = ''; 72 $Backtrace[0]['file'] = $FileName; 73 $Backtrace[0]['line'] = $LineNumber; 74 $this->Report($Backtrace); 75 if((E_ERROR | E_PARSE) & $Number) die(); 76 } 77 } 78 79 function ExceptionHandler(Exception $Exception) 80 { 81 $Backtrace = $Exception->getTrace(); 82 array_unshift($Backtrace, array( 83 'function' => $Exception->getMessage(), 84 'file' => $Exception->getFile(), 85 'line' => $Exception->getLine(), 86 )); 87 $this->Report($Backtrace); 88 die(); 89 } 90 91 function Report($Backtrace) 92 { 93 $Date = date('Y-m-d H:i:s'); 94 $Error = '# '.$Date."\n"; 95 foreach($Backtrace as $Item) 96 { 97 if(!array_key_exists('line', $Item)) $Item['line'] = ''; 98 if(!array_key_exists('file', $Item)) $Item['file'] = ''; 99 100 $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function']; 101 $Arguments = ''; 102 if(array_key_exists('args', $Item) and is_array($Item['args'])) 103 foreach($Item['args'] as $Item) 104 { 105 if(is_object($Item)) ; 106 else if(is_array($Item)) $Arguments .= "'".serialize($Item)."',"; 107 else $Arguments .= "'".$Item."',"; 108 } 109 if(strlen($Arguments) > 0) $Error .= '('.substr($Arguments, 0, -1).')'; 110 $Error .= "\n"; 111 } 112 $Error .= "\n"; 113 114 // Show error message 115 $Output = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n". 116 '<meta http-equiv="Content-Language" content="cs">'."\n". 117 '<meta http-equiv="Content-Type" content="text/html; charset='.$this->Encoding.'"></head><body>'."\n". 118 'Došlo k vnitřní chybě!<br/> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br/><br/>'; 119 if($this->ShowError == true) 120 $Output .= '<pre>'.$Error.'</pre><br/>'; 121 $Output .= '</body></html>'; 122 echo($Output); 123 foreach($this->OnError as $OnError) 124 $OnError[0]->$OnError[1]($Error); 73 125 } 74 126 } 75 76 function ExceptionHandler(Exception $Exception)77 {78 $Backtrace = $Exception->getTrace();79 array_unshift($Backtrace, array(80 'function' => $Exception->getMessage(),81 'file' => $Exception->getFile(),82 'line' => $Exception->getLine(),83 ));84 Report($Backtrace);85 die();86 } -
trunk/Modules/Log/Log.php
r567 r568 13 13 $this->License = 'GNU/GPL'; 14 14 $this->Description = 'Log various application events'; 15 $this->Dependencies = array( );15 $this->Dependencies = array('Error'); 16 16 17 17 $this->Excludes = array(); … … 21 21 { 22 22 $this->System->RegisterPage('log.php', 'PageLog'); 23 $this->System->ModuleManager->Modules['Error']->OnError[] = array($this, 'DoAddItem'); 23 24 } 25 26 function DoAddItem($Message) 27 { 28 WriteLog($Message, LOG_TYPE_ERROR); 29 } 24 30 } 25 31 … … 41 47 42 48 if(!isset($_SERVER['REMOTE_ADDR'])) $IP = 'Konzole'; 43 else $IP = addslashes($_SERVER['REMOTE_ADDR']);49 else $IP = addslashes($_SERVER['REMOTE_ADDR']); 44 50 45 51 if(!is_null($User->Id)) $UserId = $User->Id; 46 else $UserId = 'NULL';47 $Query = 'INSERT INTO `Log` ( `User` , `Type` , `Text` , `Date` , `IP`, `URL` ) 48 VALUES ('.$UserId.', '.$Type.', "'.addslashes($Text).'", NOW(), "'.$IP.'", "'.$_SERVER['REQUEST_URI'].'")';52 else $UserId = 'NULL'; 53 $Query = 'INSERT INTO `Log` ( `User` , `Type` , `Text` , `Date` , `IP`, `URL` ) '. 54 'VALUES ('.$UserId.', '.$Type.', "'.addslashes($Text).'", NOW(), "'.$IP.'", "'.$_SERVER['REQUEST_URI'].'")'; 49 55 $System->Database->query($Query); 56 echo($Query); 50 57 } 51 58 -
trunk/includes/Version.php
r567 r568 1 1 <?php 2 2 3 $Revision = 56 7; // Subversion revision3 $Revision = 568; // Subversion revision 4 4 $DatabaseRevision = 567; // Database structure revision 5 $ReleaseTime = '2013-08-2 0';5 $ReleaseTime = '2013-08-21'; -
trunk/includes/global.php
r567 r568 6 6 include_once(dirname(__FILE__).'/rss.php'); 7 7 include_once(dirname(__FILE__).'/Page.php'); 8 include_once(dirname(__FILE__).'/error.php');9 8 if(file_exists(dirname(__FILE__).'/config.php')) 10 9 include_once(dirname(__FILE__).'/config.php'); … … 14 13 // Include application modules 15 14 // TODO: Make modules configurable 15 include_once(dirname(__FILE__).'/../Modules/Error/Error.php'); 16 16 include_once(dirname(__FILE__).'/../Modules/Log/Log.php'); 17 17 include_once(dirname(__FILE__).'/../Modules/Translation/Translation.php'); … … 62 62 } 63 63 foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]); 64 65 set_error_handler('ErrorHandler'); 66 set_exception_handler('ExceptionHandler'); 67 64 68 65 // TODO: Global initialized variable should be removed 69 66 $TranslationTree = GetTranslationTree(); 70 67 71 68 // Initialize application modules 69 $System->ModuleManager->RegisterModule(new ModuleError($System)); 72 70 $System->ModuleManager->RegisterModule(new ModuleLog($System)); 73 71 $System->ModuleManager->RegisterModule(new ModuleUser($System));
Note:
See TracChangeset
for help on using the changeset viewer.