]> andersk Git - sql-web.git/commitdiff
errors are emailed in
authorJoe Presbrey <presbrey@mit.edu>
Thu, 1 Dec 2005 09:17:43 +0000 (09:17 +0000)
committerJoe Presbrey <presbrey@mit.edu>
Thu, 1 Dec 2005 09:17:43 +0000 (09:17 +0000)
output buffering is enabled

git-svn-id: svn://presbrey.mit.edu/sql/mitsql@89 a142d4bd-2cfb-0310-9673-cb33a7e74f58

error.php [new file with mode: 0755]
lib/errorhandler.lib.php [new file with mode: 0644]
lib/mitsql.lib.php
lib/security.lib.php
mitsql.cfg.php
php.ini
tpl/error.php [new file with mode: 0755]

diff --git a/error.php b/error.php
new file mode 100755 (executable)
index 0000000..6446c24
--- /dev/null
+++ b/error.php
@@ -0,0 +1,11 @@
+<?php
+/*
+       (c) 2005 Joe Presbrey
+*/
+
+require_once('mitsql.cfg.php');
+require_once('mitsql.lib.php');
+
+include 'tpl/error.php';
+
+?>
diff --git a/lib/errorhandler.lib.php b/lib/errorhandler.lib.php
new file mode 100644 (file)
index 0000000..b7da5b1
--- /dev/null
@@ -0,0 +1,101 @@
+<?php
+
+function ErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
+       $error_halt = true;
+       $error_type = 'Error';
+       $error_msg = " $errstr occured in $errfile on $errline at ".date("D M j G:i:s T Y");
+       $email_to = 'sql@mit.edu';
+       $email_from = 'sql@sql.mit.edu';
+       switch($errno) {
+               case E_USER_NOTICE:
+               case E_NOTICE:
+                       $type = 'Notice';
+                       $error_halt = false;
+                       break;
+               case E_USER_WARNING:
+               case E_COMPILE_WARNING:
+               case E_CORE_WARNING:
+               case E_WARNING:
+                       $type = 'Warning';
+                       $error_halt = false;
+                       break;
+               case E_USER_ERROR:
+               case E_COMPILE_ERROR:
+               case E_CORE_ERROR:
+               case E_ERROR:
+                       $type = 'Fatal Error';
+                       break;
+               case E_PARSE:
+                       $type = 'Parse Error';
+                       break;
+               default:
+                       $type = 'Unknown Error';
+                       break;
+       }
+       $error_bt = ErrorBacktrace(debug_backtrace());
+       $error_msg = $type . ':' . $error_msg . "\n" . $error_bt . "\n\n";
+       if (DEVEL && 0) {
+               echo nl2br($error_msg);
+       } else {
+               $error_msg .= print_r($errcontext,1);
+               error_log($error_msg, 1, $email_to);
+               if ($error_halt) {
+                       while(ob_get_level()) { ob_end_clean(); }
+                       require_once('security.lib.php');
+                       redirect('error');
+                       exit -1;
+               }
+       }
+}
+
+function ErrorBacktrace($debug_backtrace) {
+       array_shift($debug_backtrace);
+       $output = '';
+   foreach ($debug_backtrace as $bt) {
+       $args = '';
+       foreach ($bt['args'] as $a) {
+           if (!empty($args)) {
+               $args .= ', ';
+           }
+           switch (gettype($a)) {
+           case 'integer':
+           case 'double':
+               $args .= $a;
+               break;
+           case 'string':
+               $a = htmlspecialchars(substr($a, 0, 64)).((strlen($a) > 64) ? '...' : '');
+               $args .= "\"$a\"";
+               break;
+           case 'array':
+               //$args .= 'Array('.count($a).')';
+               $args .= print_r($a,1);
+               break;
+           case 'object':
+               $args .= 'Object('.get_class($a).')';
+               break;
+           case 'resource':
+               $args .= 'Resource('.strstr($a, '#').')';
+               break;
+           case 'boolean':
+               $args .= $a ? 'True' : 'False';
+               break;
+           case 'NULL':
+               $args .= 'Null';
+               break;
+           default:
+               $args .= 'Unknown';
+           }
+       }
+          empty($bt['class']) && $bt['class'] = '';
+          empty($bt['type']) && $bt['type'] = '';
+          empty($bt['function']) && $bt['function'] = '';
+          $output .= "\n";
+       $output .= "file: {$bt['line']} - {$bt['file']}\n";
+       $output .= "call: {$bt['class']}{$bt['type']}{$bt['function']}($args)\n";
+   }
+       return $output;
+}
+
+set_error_handler('ErrorHandler');
+
+?>
index c59a4347e776573ff2d6e91dc6c19cc7badb9c69..0e9620d97a13bfcf176e93175cd5ddf30a0c01c8 100755 (executable)
@@ -10,6 +10,7 @@ require_once('dbaccess.lib.php');
 
 require_once('mitsql.cfg.php');
 require_once('security.lib.php');
+require_once('errorhandler.lib.php');
 
 require_once('display.lib.php');
 
index d345e61bf3dbbf162b704a25bdcccfddf2bc38fc..5630ebb41a8c9d8e7024be47e2b91236399e2570 100644 (file)
@@ -87,7 +87,7 @@ class User {
        private $dblist;
     function User($userId) {
                $this->userId = $userId;
-        $sql = sprintf("SELECT User.UserId, Username, Password, Name, Email, UL, bEnabled, nBytesSoft, nBytesHard, nBytes, nDatabases, nDatabasesHard, IF(nBytes>nBytesHard,1,0) AS bOverQuota
+        $sql = sprintf("SELECT User.UserId, Username, Name, Email, UL, bEnabled, nBytesSoft, nBytesHard, nBytes, nDatabases, nDatabasesHard, IF(nBytes>nBytesHard,1,0) AS bOverQuota
                         FROM User
                                                INNER JOIN UserQuota ON User.UserId = UserQuota.UserId
                                                INNER JOIN UserStat ON User.UserId = UserStat.UserId
@@ -96,13 +96,12 @@ class User {
         $r = fetchRows(DBSelect($sql),'UserId');
         $this->info = count($r)?array_shift($r):$r;
                $this->dblist = $this->getDBList();
-//             $this->pass = base64_decode($this->info['Password']);
     }
        function refresh() {
                unset($this->dblist);
                $this->User($this->userId);
                /*
-        $sql = sprintf("SELECT UserId, Username, Password, Name, Email, UL, bEnabled
+        $sql = sprintf("SELECT UserId, Username, Name, Email, UL, bEnabled
                         FROM User
                         WHERE UserId = '%s'",
                         mysql_escape_string($this->userId));
index ddac11928afedcf558350c2d88fc78032d48e5d6..1c96be67d4ab44a887f6a930b20f4fcd6f54094b 100755 (executable)
@@ -37,6 +37,7 @@ define('THIS_PAGE', $THIS_PAGE);
 set_time_limit(0);
 ignore_user_abort(1);
 import_request_variables('cgp', 'i_');
+!DEVEL && ini_set('display_errors', 0);
 DEVEL && ini_set('display_errors', 1);
 error_reporting(E_ALL);
 set_include_path(get_include_path() . PATH_SEPARATOR . $BASE_PATH . 'lib/' . PATH_SEPARATOR . $BASE_PATH);
diff --git a/php.ini b/php.ini
index 629e3f417d9b38c5ed98e6e3fe8ff734418f6757..a55c8f345bbc22130237830a87dc1bde0ebc6e7a 100755 (executable)
--- a/php.ini
+++ b/php.ini
@@ -1,4 +1,4 @@
-display_errors = 0
 extension = mysql.so
 auto_append_file = "global.done.php"
 session.save_path = "/home/sql/tmp/"
+output_buffering = 4096
diff --git a/tpl/error.php b/tpl/error.php
new file mode 100755 (executable)
index 0000000..9b73460
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+include 'head.php';
+?>
+
+<h2>Page Error</h2>
+
+<p>
+The page you were trying to view experienced an error while loading.
+An email reporting this error has been sent to the Support Team.
+</p>
+<p>
+Please accept our apologies for this inconvenience.
+</p>
+<p>
+Return <a href="do/main">Home</a>.
+</p>
+
+<?php
+include 'foot.php';
+?>
This page took 0.04305 seconds and 5 git commands to generate.