diff --git a/application/modules/default/controllers/ErrorController.php b/application/modules/default/controllers/ErrorController.php index 116289f3af58a06f5e4c7d303ddd5c3c77ab8e3f..e8178eb8dc1826b6040c43d8d367d33cb6cd08be 100644 --- a/application/modules/default/controllers/ErrorController.php +++ b/application/modules/default/controllers/ErrorController.php @@ -2,20 +2,69 @@ /** * ErrorController - * + * * @author - * @version + * @version */ require_once 'Zend/Controller/Action.php'; -class ErrorController extends Unl_Controller_Action { - /** - * The default action - show the home page - */ +class ErrorController extends App_Controller_Action { + + protected $_exceptions; + public function errorAction() { - $exceptions = $this->getResponse()->getException(); - throw $exceptions[0]; + $this->_exceptions = $this->getResponse()->getException(); + + if ($_SERVER['REMOTE_ADDR'] == '129.93.39.17') { + header('Content-type: text/plain'); + print_r($this->_exceptions); + exit; + } + + $this->_sendEmail('tsteiner2@unl.edu'); + $this->view->exceptions = $this->_exceptions; } + protected function _sendEmail($address, $moreAddresses = '...') + { + $mail = new Zend_Mail('utf-8'); + $mail->setFrom('php@' . $_SERVER['SERVER_NAME'], $_SERVER['SERVER_NAME']); + $mail->setSubject('Exception Report'); + + foreach(func_get_args() as $address) + { + if(is_array($address)) { + $mail->addTo($address[0], $address[1]); + } else { + $mail->addTo($address); + } + } + + $date = date('Y-m-d'); + $time = date('H:i'); + $body = "The following exception occured on $date at $time.\n\n" + . print_r($this->_exceptions, true) + . "\nRequest URI: " . $_SERVER['REQUEST_URI'] . "\n" + . "User Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\n" + . "User IP Address :" . $_SERVER['REMOTE_ADDR'] ."\n"; + + if(count($_GET) > 0) { + $body .= "\nGET variables: \n" + . print_r($_GET, true); + } + if(count($_POST) > 0) { + $body .= "\nPOST variables: \n" + . print_r($_POST, true); + } + /* + if(session_id() && ($_SESSION) > 0) { + $body .= "\nSESSION variables: \n" + . print_r($_SESSION, true); + } + */ + + $mail->setBodyText($body); + $mail->send(); + } } diff --git a/application/modules/default/views/scripts/error/error.phtml b/application/modules/default/views/scripts/error/error.phtml index 6cc117df95e05cf7025179a3563e7ad005c334a3..928c154a188ed223f52941e4a4e2db20e6d76b86 100644 --- a/application/modules/default/views/scripts/error/error.phtml +++ b/application/modules/default/views/scripts/error/error.phtml @@ -1 +1,9 @@ -<h1>Error</h1> \ No newline at end of file +<h1>Unfortunately an unexpected error has occured.</h1> +<h2>Details have been mailed to the administrator for analysis.</h2> +<p> + The error message was: "<?php echo $this->exceptions[0]->getMessage(); ?>" +</p> +<p> + We appologize for the inconvience. + Please use the back button to return to your previous location +</p> \ No newline at end of file