Odyssey
hcuErrorReport.i
1 <?php
2 
3  // SET THE ERROR HANDLER FOR FUTURE ERRORS
4 
5  error_reporting (E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
6 
7  $old_error_handler = set_error_handler("myErrorHandler");
8  // error handler function
9  function myErrorHandler ($errno, $errstr, $errfile, $errline) {
10 
11  static $errList = Array();
12 
13  $duplicateError = false;
14  // *errList - Array of errors tracked by file/{line number} to track if this is a duplicate error
15  if (isset($errList["$errfile:$errline"])) {
16  $duplicateError = true;
17  } else {
18  $errList["$errfile:$errline"] = $errstr;
19  }
20 
21 
22  $save_log = false; // When set to true, the log file will save this information
23  $send_mail = false; // When true an email will be sent for this error
24  $show_pg = false; // When true the browser will be redirected to a new page
25  $ignoreDupErrors = true; // {true, false}, true do not eMail duplicate errors, always write to log: false, email all errors
26 
27  $error_type = "";
28 
29  $err_constants = Array (
30  "1" => "[E_ERROR]",
31  "2" => "[E_WARNING]",
32  "4" => "[E_PARSE]",
33  "8" => "[E_NOTICE]",
34  "16" => "[E_CORE_ERROR]",
35  "32" => "[E_CORE_WARNING]",
36  "64" => "[E_COMPILE_ERROR]",
37  "128" => "[E_COMPILE_WARNING]",
38  "256" => "[E_USER_ERROR]",
39  "512" => "[E_USER_WARNING]",
40  "1024" => "[E_USER_NOTICE]",
41  "2047" => "[E_ALL]"
42  );
43  $error_type = $err_constants[$errno];
44 
45 
46  // only report the error -- if error_reporting has been set for it
47  // This may backfire as each time an @ sign is used on the failing
48  // function error_reporting will by default return a 0 and not
49  // get returned to it's previous value
50 
51  switch ($errno) {
52  // Only report an error for the following types
53  // Do NOTHING FOR THESE TYPES
54  case E_USER_ERROR:
55  $save_log = true;
56  $send_mail = true;
57  $show_pg = true;
58  $error_type = "[REPORT ERROR]";
59  break;
60  case E_USER_WARNING:
61  $save_log = true;
62  $send_mail = true;
63  $error_type = "[REPORT WARNING]";
64  break;
65  case E_USER_NOTICE:
66  $save_log = true;
67  $error_type = "[REPORT NOTICE]";
68  break;
69  case E_WARNING:
70  if (strpos($errfile, "dbfunc") === FALSE && strpos($errfile, "packetdump") === FALSE && strpos($errfile, "db.postgres.i") === FALSE) {
71  // Don't log an error that comes from the dbfunc file, these
72  // are mostly expected -- but log others as they may include
73  // unexpected errors
74 
75  if (strpos($errstr, "file-get-contents") === FALSE && strpos($errstr, "SSL: fatal protocol") === FALSE) {
76  $save_log = true;
77 
78  // Here add logic for warning message of functions to NOT send an email for
79  if (strpos($errstr, "fopen") === FALSE) {
80  $send_mail = true;
81  }
82  $show_pg = false;
83  }
84  }
85  break;
86  default:
87  // For most of these choose to Ignore the error
88  }
89 
90 
91  $exec_script = $_SERVER['SCRIPT_FILENAME'];
92  if ($save_log) {
93  // PREPARE THE MESSAGE FOR LOG FILE
94  $log_msg = "[" . date("D M d H:i:s Y") . "] $error_type [{$_SERVER['REMOTE_ADDR']}] ";
95  $log_msg .= "[{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}] [$errfile] [Line $errline] [$errno] $errstr\n";
96 
97  error_log ($log_msg, 3, "/tmp/php_error.log");
98  }
99 
100  if ($send_mail && (!$duplicateError || !$ignoreDupErrors)) {
101 
102  // PREPARE THE MESSAGE FOR EMAIL
103  $mail_msg = "\t ERROR INFORMATION - {$_SERVER['SERVER_NAME']}\n\n";
104  $mail_msg .= "HCU Script: $errfile\n";
105  $mail_msg .= "Script Line Number: $errline\n";
106  $mail_msg .= "Error: {$err_constants[$errno]} $errstr\n\n";
107  $mail_msg .= "URI: {$_SERVER['REQUEST_URI']}\n";
108  $mail_msg .= "SCRIPT: {$_SERVER['SCRIPT_FILENAME']}\n";
109  $mail_msg .= "QUERY_STRING: {$_SERVER['QUERY_STRING']}\n";
110  $mail_msg .= "REMOTE_IP: {$_SERVER['REMOTE_ADDR']}\n";
111 /*
112  if (stripos($_SERVER['SERVER_NAME'],'www4.homecu.net') !== false) {
113  error_log ($mail_msg, 1, "miki@homecu.net,mark@homecu.net,mike@homecu.net,samuel@homecu.net", "");
114  } else {
115  error_log ($mail_msg, 1, "cuerror@homecu.net", "");
116  }
117 */
118 // ** ALWAYS SEND TO MARK ONLY
119  error_log ($mail_msg, 1, "mark@homecu.net", "");
120 
121  }
122 
123 
124  // MWS -- At this time don't do this, we actually may not need this
125  // When the function fails, we simply want the code to follow through
126  // and show empty tables???
127  if ($show_pg) {
128 
129  if (strpos($exec_script, "demobin") !== FALSE) {
130  header ("Location: /demobin/clientreflistd");
131  exit;
132  } elseif (strpos($exec_script, "admbin") !== FALSE) {
133 // // Do NOTHING for admin failure in database connection
134  } elseif ((strpos($exec_script, "hcubin7") !== FALSE) || (strpos($errfile, "hculive7") !== FALSE)) {
135 // header ("Location: http://devel.homecu.net/~mark/error_test/homecu_down.php");
136  header ("Location: /hcubin7/homecu_notice?cu={$_REQUEST['cu']}&Flang={$_REQUEST['Flang']}&speak={$_REQUEST['speak']}");
137  exit;
138  } else {
139  // Do Nothing as we arent POSITIVE WHERE WE ARE
140  }
141  }
142 
143 
144  }