The version of vichan running on lainchan.org
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

92 Zeilen
2.5KB

  1. <?PHP
  2. function error_handler($errno,$errstr,$errfile, $errline, $errcontext){
  3. if(error_reporting() & $errno){
  4. $config['debug']=true;
  5. error($errstr . ' in ' . $errfile . ' at line ' . $errline);
  6. }
  7. return false;
  8. }
  9. function exception_handler($e){
  10. error($e->getMessage());
  11. }
  12. set_exception_handler('exception_handler');
  13. function fatal_error_handler(){
  14. if (($error = error_get_last()) && $error['type'] == E_ERROR) {
  15. error('Caught fatal error: ' . $error['message'] . ' in ' . $error['file'] . ' at line ' . $error['line']);
  16. }
  17. }
  18. register_shutdown_function('fatal_error_handler');
  19. $error_recursion=false;
  20. function error($message, $priority = true, $debug_stuff = false) {
  21. global $board, $mod, $config, $db_error, $error_recursion;
  22. if($error_recursion!==false){
  23. die("Error recursion detected with " . $message . "<br>Original error:".$error_recursion);
  24. }
  25. $error_recursion=$message;
  26. if (defined('STDIN')) {
  27. // Running from CLI
  28. echo('Error: ' . $message . "\n");
  29. debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
  30. die();
  31. }
  32. if(!empty($config)){
  33. if ($config['syslog'] && $priority !== false) {
  34. // Use LOG_NOTICE instead of LOG_ERR or LOG_WARNING because most error message are not significant.
  35. _syslog($priority !== true ? $priority : LOG_NOTICE, $message);
  36. }
  37. if ($config['debug']) {
  38. $debug_stuff=array();
  39. if(isset($db_error)){
  40. $debug_stuff = array_combine(array('SQLSTATE', 'Error code', 'Error message'), $db_error);
  41. }
  42. $debug_stuff['backtrace'] = debug_backtrace();
  43. $pw = $config['db']['password'];
  44. $debug_callback = function(&$item) use (&$debug_callback, $pw) {
  45. if (is_array($item)) {
  46. return array_map($debug_callback, $item);
  47. }
  48. return ($item == $pw ? 'hunter2' : $item);
  49. };
  50. $debug_stuff = array_map($debug_callback, $debug_stuff);
  51. }
  52. }
  53. if (isset($_POST['json_response'])) {
  54. header('Content-Type: text/json; charset=utf-8');
  55. $data=array('error'=>$message);
  56. if(!empty($config) && $config['debug']){
  57. $data['debug']=$debug_stuff;
  58. }
  59. print json_encode($data);
  60. exit();
  61. }
  62. header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
  63. die(Element('page.html', array(
  64. 'config' => $config,
  65. 'title' => _('Error'),
  66. 'subtitle' => _('An error has occured.'),
  67. 'body' => Element('error.html', array(
  68. 'config' => $config,
  69. 'message' => $message,
  70. 'mod' => $mod,
  71. 'board' => isset($board) ? $board : false,
  72. 'debug' => str_replace("\n", '&#10;', utf8tohtml(print_r($debug_stuff, true)))
  73. ))
  74. )));
  75. }