Commit 84c5a70b87df979f94d495eceaafe9c8a35b09aa
1 parent
bc69f4b9
KTS-2646
"Database exception handler needs to be fixed" Fixed. All database errors are now logged and the user is sent to an improved page. Committed By:Yusuf Davids Reviewed By:Jalaloedien Abrahams KTS-2645 " A general exception handler is required to deal with thrown exceptions not caught by the application" Fixed. Committed By:Yusuf Davids Reviewed By:Jalaloedien Abrahams git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7775 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
8 changed files
with
338 additions
and
0 deletions
config/config.ini
| @@ -362,3 +362,10 @@ warningThreshold=10 | @@ -362,3 +362,10 @@ warningThreshold=10 | ||
| 362 | ; the disk usage dashlet will will highlight the mount in RED | 362 | ; the disk usage dashlet will will highlight the mount in RED |
| 363 | urgentThreshold=5 | 363 | urgentThreshold=5 |
| 364 | 364 | ||
| 365 | +[CustomErrorMessages] | ||
| 366 | +;Turn custom error messages on or off here // account wide | ||
| 367 | +customerrormessages=on | ||
| 368 | +;name or url of custom error page | ||
| 369 | +customerrorpagepath=customerrorpage.php | ||
| 370 | +;Turn custom error handler on or off | ||
| 371 | +customerrorhandler=on | ||
| 365 | \ No newline at end of file | 372 | \ No newline at end of file |
config/dmsDefaults.php
| @@ -353,8 +353,20 @@ class KTInit { | @@ -353,8 +353,20 @@ class KTInit { | ||
| 353 | } | 353 | } |
| 354 | return false; | 354 | return false; |
| 355 | } | 355 | } |
| 356 | + | ||
| 356 | // }}} | 357 | // }}} |
| 357 | 358 | ||
| 359 | +function catchFatalErrors($p_OnOff='On'){ | ||
| 360 | + ini_set('display_errors','On'); | ||
| 361 | + $phperror='><div id="phperror" style="display:none">'; | ||
| 362 | + ini_set('error_prepend_string',$phperror); | ||
| 363 | + | ||
| 364 | + $phperror='</div>><form name="catcher" action="/customerrorpage.php" method="post" ><input type="hidden" name="fatal" value=""></form> | ||
| 365 | + <script> document.catcher.fatal.value = document.getElementById("phperror").innerHTML; document.catcher.submit();</script>'; | ||
| 366 | + ini_set('error_append_string',$phperror); | ||
| 367 | +} | ||
| 368 | + | ||
| 369 | + | ||
| 358 | 370 | ||
| 359 | // {{{ guessRootUrl() | 371 | // {{{ guessRootUrl() |
| 360 | function guessRootUrl() { | 372 | function guessRootUrl() { |
| @@ -595,6 +607,9 @@ require_once(KT_LIB_DIR . '/util/ktutil.inc'); | @@ -595,6 +607,9 @@ require_once(KT_LIB_DIR . '/util/ktutil.inc'); | ||
| 595 | 607 | ||
| 596 | require_once(KT_LIB_DIR . '/ktentity.inc'); | 608 | require_once(KT_LIB_DIR . '/ktentity.inc'); |
| 597 | 609 | ||
| 610 | +$KTInit->catchFatalErrors(); | ||
| 611 | + | ||
| 612 | + | ||
| 598 | require_once(KT_LIB_DIR . '/config/config.inc.php'); | 613 | require_once(KT_LIB_DIR . '/config/config.inc.php'); |
| 599 | require_once(KT_DIR . '/search2/indexing/indexerCore.inc.php'); | 614 | require_once(KT_DIR . '/search2/indexing/indexerCore.inc.php'); |
| 600 | 615 |
customerrorpage.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +if (array_key_exists('fatal', $_POST)) | ||
| 4 | +{ | ||
| 5 | + $posted = $_POST['fatal']; | ||
| 6 | + | ||
| 7 | +} | ||
| 8 | + | ||
| 9 | +if (array_key_exists('Error_MessageOne', $_POST) && array_key_exists('Error_MessageTwo', $_POST)) | ||
| 10 | +{ | ||
| 11 | + $sErrorMessage = $_POST['Error_MessageOne'].''.$_POST['Error_MessageTwo']; | ||
| 12 | + | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +?> | ||
| 16 | + | ||
| 17 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html> | ||
| 18 | + <head> | ||
| 19 | + <title>Knowledgetree - Desklet</title> | ||
| 20 | + <link rel="stylesheet" type="text/css" href="errors.css" /> | ||
| 21 | + | ||
| 22 | + <script type="text/javascript"> | ||
| 23 | + | ||
| 24 | +function Click() | ||
| 25 | +{ | ||
| 26 | +var open = document.getElementById('exp'); | ||
| 27 | +open.style.display = 'block'; | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +</script> | ||
| 31 | + | ||
| 32 | + </head> | ||
| 33 | + <body> | ||
| 34 | + | ||
| 35 | + <div id="error-container"> | ||
| 36 | + | ||
| 37 | + <div id="acc-error"> | ||
| 38 | + | ||
| 39 | + | ||
| 40 | + <h1>Error!! - You have encountered a problem starting your document management system.</h1> | ||
| 41 | + <p><h2>Please contact your systems administrator</h2></p> | ||
| 42 | + <p>For more details, click here <img src="/resources/graphics/info.gif" style="cursor: pointer;" onclick="Click()" /><div id ="exp" style="display: none; "> <?php if(isset($sErrorMessage)){ echo $sErrorMessage; }else if(isset($posted)){ echo $posted; } ?></div></p> | ||
| 43 | + | ||
| 44 | + </div> | ||
| 45 | + </div> | ||
| 46 | + | ||
| 47 | + </body> | ||
| 48 | +</html> | ||
| 0 | \ No newline at end of file | 49 | \ No newline at end of file |
error_01.gif
0 → 100644
2.09 KB
errors.css
0 → 100644
| 1 | +div#error-container { | ||
| 2 | + width: 500px; | ||
| 3 | + color: #555; | ||
| 4 | + font-size: 11px; | ||
| 5 | + font-family: Verdana, Arial, sans-serif; | ||
| 6 | +} | ||
| 7 | +div#error-container div { | ||
| 8 | + height: 140px; | ||
| 9 | +} | ||
| 10 | +div#error-container h1 { | ||
| 11 | + font-weight: lighter; | ||
| 12 | + font-size: 22px; | ||
| 13 | + margin-left: 100px; | ||
| 14 | +} | ||
| 15 | +div#error-container p { | ||
| 16 | + margin-left: 100px; | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | + div#acc-error { | ||
| 20 | + background: transparent url(error_01.gif) no-repeat top left; | ||
| 21 | + } | ||
| 22 | + div#acc-suspend { | ||
| 23 | + background: transparent url(error_02.gif) no-repeat top left; | ||
| 24 | + } | ||
| 25 | + div#acc-maint { | ||
| 26 | + background: transparent url(error_03.gif) no-repeat top left; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + | ||
| 38 | + | ||
| 39 | + | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + | ||
| 43 | + | ||
| 0 | \ No newline at end of file | 44 | \ No newline at end of file |
lib/dispatcher.inc.php
| @@ -538,6 +538,39 @@ class KTErrorDispatcher extends KTStandardDispatcher { | @@ -538,6 +538,39 @@ class KTErrorDispatcher extends KTStandardDispatcher { | ||
| 538 | 538 | ||
| 539 | function dispatch() { | 539 | function dispatch() { |
| 540 | require_once(KT_LIB_DIR . '/validation/errorviewer.inc.php'); | 540 | require_once(KT_LIB_DIR . '/validation/errorviewer.inc.php'); |
| 541 | + require_once(KT_LIB_DIR . '/validation/customerrorviewer.inc.php'); | ||
| 542 | + | ||
| 543 | + $oCustomViewer =& KTCustomErrorViewer::initCustomErrorViewer(); | ||
| 544 | + | ||
| 545 | + //if the custom error messages are set to 'on' in the config file | ||
| 546 | + //we check if the error page exists and redirect to it if it does. | ||
| 547 | + //if either the page doesn't exit or the custom error option is off in the config file | ||
| 548 | + //we carry out default error reporting | ||
| 549 | + if ($oCustomViewer->getCustomErrorConfigSetting() == 'on'){ | ||
| 550 | + $CustomErrorPage = $oCustomViewer->getCustomErrorRedirectPage(); | ||
| 551 | + if ( $CustomErrorPage != '0') //if an error is not returned from getCustomErrorRedirectPage(); | ||
| 552 | + { | ||
| 553 | + $sErrorHandler = $oCustomViewer->getCustomErrorHandlerSetting(); | ||
| 554 | + | ||
| 555 | + //redirect | ||
| 556 | + if ($sErrorHandler == 'on') | ||
| 557 | + { | ||
| 558 | + //if custom error handler is set to on inside config.ini then send error object with error page | ||
| 559 | + $oCustomViewer->doCustomErrorPageRedirect($CustomErrorPage, $this->oError); | ||
| 560 | + } | ||
| 561 | + else if ($sErrorHandler != 'on') | ||
| 562 | + { | ||
| 563 | + //if custom error handler is set to off inside config.ini then just send error page | ||
| 564 | + $oCustomViewer->doCustomErrorPageRedirect($CustomErrorPage); | ||
| 565 | + } | ||
| 566 | + | ||
| 567 | + //exit without errors | ||
| 568 | + exit(0); | ||
| 569 | + } | ||
| 570 | + } | ||
| 571 | + | ||
| 572 | + //if either customer error messages is off or the custom error page doesn't exist the function will run | ||
| 573 | + //the default error handling here | ||
| 541 | $oRegistry =& KTErrorViewerRegistry::getSingleton(); | 574 | $oRegistry =& KTErrorViewerRegistry::getSingleton(); |
| 542 | $oViewer =& $oRegistry->getViewer($this->oError); | 575 | $oViewer =& $oRegistry->getViewer($this->oError); |
| 543 | $this->oPage->setTitle($oViewer->view()); | 576 | $this->oPage->setTitle($oViewer->view()); |
lib/validation/customerrorhandler.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * | ||
| 4 | + * The contents of this file are subject to the KnowledgeTree Public | ||
| 5 | + * License Version 1.1.2 ("License"); You may not use this file except in | ||
| 6 | + * compliance with the License. You may obtain a copy of the License at | ||
| 7 | + * http://www.knowledgetree.com/KPL | ||
| 8 | + * | ||
| 9 | + * Software distributed under the License is distributed on an "AS IS" | ||
| 10 | + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. | ||
| 11 | + * See the License for the specific language governing rights and | ||
| 12 | + * limitations under the License. | ||
| 13 | + * | ||
| 14 | + * All copies of the Covered Code must include on each user interface screen: | ||
| 15 | + * (i) the "Powered by KnowledgeTree" logo and | ||
| 16 | + * (ii) the KnowledgeTree copyright notice | ||
| 17 | + * in the same form as they appear in the distribution. See the License for | ||
| 18 | + * requirements. | ||
| 19 | + * | ||
| 20 | + * The Original Code is: KnowledgeTree Open Source | ||
| 21 | + * | ||
| 22 | + * The Initial Developer of the Original Code is The Jam Warehouse Software | ||
| 23 | + * (Pty) Ltd, trading as KnowledgeTree. | ||
| 24 | + * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright | ||
| 25 | + * (C) 2007 The Jam Warehouse Software (Pty) Ltd; | ||
| 26 | + * All Rights Reserved. | ||
| 27 | + * Contributor( s): ______________________________________ | ||
| 28 | + * | ||
| 29 | + */ | ||
| 30 | + require_once('config/dmsDefaults.php'); | ||
| 31 | + require_once(KT_LIB_DIR.'/Log.inc'); | ||
| 32 | + | ||
| 33 | + class KTCustomErrorHandler | ||
| 34 | + { | ||
| 35 | + // {{{ initCustomErrorHandler() | ||
| 36 | + function initCustomErrorHandler () | ||
| 37 | + { | ||
| 38 | + return $oCustomErrorHandler =& new KTCustomErrorHandler; | ||
| 39 | + } | ||
| 40 | + // }}} | ||
| 41 | + | ||
| 42 | + // {{{ logError() | ||
| 43 | + function logError($oError) | ||
| 44 | + | ||
| 45 | + { | ||
| 46 | + global $default; | ||
| 47 | + | ||
| 48 | + $sErrorType = ''; | ||
| 49 | + if(substr($oError->toString(),1,2) == 'db') | ||
| 50 | + { | ||
| 51 | + $sErrorType = 'database_error'; | ||
| 52 | + } | ||
| 53 | + else | ||
| 54 | + { | ||
| 55 | + $sErrorType = 'unknown_error'; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + $default->log->error($oError->toString()); | ||
| 60 | + | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + ?> | ||
| 0 | \ No newline at end of file | 64 | \ No newline at end of file |
lib/validation/customerrorviewer.inc.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * | ||
| 4 | + * The contents of this file are subject to the KnowledgeTree Public | ||
| 5 | + * License Version 1.1.2 ("License"); You may not use this file except in | ||
| 6 | + * compliance with the License. You may obtain a copy of the License at | ||
| 7 | + * http://www.knowledgetree.com/KPL | ||
| 8 | + * | ||
| 9 | + * Software distributed under the License is distributed on an "AS IS" | ||
| 10 | + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. | ||
| 11 | + * See the License for the specific language governing rights and | ||
| 12 | + * limitations under the License. | ||
| 13 | + * | ||
| 14 | + * All copies of the Covered Code must include on each user interface screen: | ||
| 15 | + * (i) the "Powered by KnowledgeTree" logo and | ||
| 16 | + * (ii) the KnowledgeTree copyright notice | ||
| 17 | + * in the same form as they appear in the distribution. See the License for | ||
| 18 | + * requirements. | ||
| 19 | + * | ||
| 20 | + * The Original Code is: KnowledgeTree Open Source | ||
| 21 | + * | ||
| 22 | + * The Initial Developer of the Original Code is The Jam Warehouse Software | ||
| 23 | + * (Pty) Ltd, trading as KnowledgeTree. | ||
| 24 | + * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright | ||
| 25 | + * (C) 2007 The Jam Warehouse Software (Pty) Ltd; | ||
| 26 | + * All Rights Reserved. | ||
| 27 | + * Contributor( s): ______________________________________ | ||
| 28 | + * | ||
| 29 | + */ | ||
| 30 | + require_once(KT_LIB_DIR.'/validation/customerrorhandler.php'); | ||
| 31 | + | ||
| 32 | + class KTCustomErrorViewer | ||
| 33 | + { | ||
| 34 | + // {{{ initCustomErrorViewer() | ||
| 35 | + function initCustomErrorViewer() | ||
| 36 | + { | ||
| 37 | + return $oCustomViewer =& new KTCustomErrorViewer; | ||
| 38 | + } | ||
| 39 | + //}}} | ||
| 40 | + | ||
| 41 | + //{{{ getCustomErrorConfigSetting() | ||
| 42 | + function getCustomErrorConfigSetting() | ||
| 43 | + { | ||
| 44 | + $oKTConfig =& KTConfig::getSingleton(); | ||
| 45 | + $sCustomErrorCheck = $oKTConfig->get('CustomErrorMessages/customerrormessages'); | ||
| 46 | + return $sCustomErrorCheck; | ||
| 47 | + } | ||
| 48 | + //}}} | ||
| 49 | + | ||
| 50 | + //{{{ getCustomErrorHandlerSetting() | ||
| 51 | + function getCustomErrorHandlerSetting() | ||
| 52 | + { | ||
| 53 | + $oKTConfig =& KTConfig::getSingleton(); | ||
| 54 | + $sCustomErrorCheck = $oKTConfig->get('CustomErrorMessages/customerrorhandler'); | ||
| 55 | + return $sCustomErrorCheck; | ||
| 56 | + } | ||
| 57 | + //}}} | ||
| 58 | + | ||
| 59 | + // {{{ getCustomErrorRedirectPage() | ||
| 60 | + function getCustomErrorRedirectPage () | ||
| 61 | + { | ||
| 62 | + $oKTErrorConfig =& KTConfig::getSingleton(); | ||
| 63 | + $sCustomErrorPage = $oKTErrorConfig->get('CustomErrorMessages/customerrorpagepath'); | ||
| 64 | + | ||
| 65 | + //if a filname is specified in the config.ini file make it into a url | ||
| 66 | + if (substr($sCustomErrorPage, 0, 4) != 'http') | ||
| 67 | + { | ||
| 68 | + | ||
| 69 | + $sCustomErrorPage = 'http://'.$_SERVER['HTTP_HOST'].'/'.$sCustomErrorPage; | ||
| 70 | + | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + //checking if file exists | ||
| 74 | + //curl options will return the page header, we can then check for an http error | ||
| 75 | + $CurlSession = curl_init(); | ||
| 76 | + curl_setopt($CurlSession, CURLOPT_URL, $sCustomErrorPage); | ||
| 77 | + curl_setopt($CurlSession, CURLOPT_HEADER, true); | ||
| 78 | + curl_setopt($CurlSession, CURLOPT_NOBODY, true); | ||
| 79 | + curl_setopt($CurlSession, CURLOPT_RETURNTRANSFER, true); | ||
| 80 | + $data = curl_exec($CurlSession); | ||
| 81 | + curl_close($CurlSession); | ||
| 82 | + preg_match("/HTTP\/1\.[1|0]\s(\d{3})/",$data,$matches); | ||
| 83 | + | ||
| 84 | + //checking for http error - if the retunr code isn't 200 then we have an error | ||
| 85 | + //on an error we return 0 | ||
| 86 | + if ($matches[1] != '200') | ||
| 87 | + { | ||
| 88 | + //if file does not exist return error code of 0 | ||
| 89 | + return '0'; | ||
| 90 | + } | ||
| 91 | + else | ||
| 92 | + { | ||
| 93 | + //if file exists return error page address | ||
| 94 | + return $sCustomErrorPage; | ||
| 95 | + | ||
| 96 | + } | ||
| 97 | + } | ||
| 98 | + // }}} | ||
| 99 | + | ||
| 100 | + // {{{ customErrorPageRedirect() | ||
| 101 | + function doCustomErrorPageRedirect($CustomErrorPage, $oError = null) | ||
| 102 | + { | ||
| 103 | + $sErrorMessage = ''; | ||
| 104 | + if($oError != null) | ||
| 105 | + { | ||
| 106 | + //call error handler | ||
| 107 | + | ||
| 108 | + $aErrorMessage = array (); | ||
| 109 | + $aErrorMessage['Error_MessageOne'] = $oError->getMessage(); | ||
| 110 | + $aErrorMessage['Error_MessageTwo'] = $oError->getUserInfo(); | ||
| 111 | + //echo '<pre>'; | ||
| 112 | + //print_r($aErrorMessage); | ||
| 113 | + //echo '</pre>'; | ||
| 114 | + //exit; | ||
| 115 | + $customErrorHandler = KTCustomErrorHandler::initCustomErrorHandler(); | ||
| 116 | + $customErrorHandler->logError($oError); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + $ErrorPageCurlSession = curl_init($CustomErrorPage); | ||
| 120 | + //curl_setopt($ErrorPageCurlSession, CURLOPT_SSL_VERIFYPEER, false); | ||
| 121 | + curl_setopt($ErrorPageCurlSession, CURLOPT_POST, true); | ||
| 122 | + curl_setopt($ErrorPageCurlSession, CURLOPT_POSTFIELDS, $aErrorMessage); | ||
| 123 | + $ErrorPageSent = curl_exec($ErrorPageCurlSession); | ||
| 124 | + curl_close($ErrorPageCurlSession); | ||
| 125 | + | ||
| 126 | + } | ||
| 127 | + // }}} | ||
| 128 | + } | ||
| 129 | + ?> |