Commit 7d093402d26bdcc9d6f587a15dfd2fc4a285a75d

Authored by Jonathan Byrne
1 parent f88492af

KTS-3148

"Custom Error Page cannot be disabled."
Fixed. Cleaned up custom error page functionality.

Committed By: Jonathan Byrne
Reviewed By: Megan Watson

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8368 c91229c3-7414-0410-bfa2-8a42b809f60b
config/config.ini
@@ -398,9 +398,12 @@ warningThreshold=10 @@ -398,9 +398,12 @@ warningThreshold=10
398 urgentThreshold=5 398 urgentThreshold=5
399 399
400 [CustomErrorMessages] 400 [CustomErrorMessages]
401 -;Turn custom error messages on or off here // account wide  
402 -customerrormessages=on  
403 -;name or url of custom error page 401 +;Turn custom error messages on or off here.
  402 +customerrormessages=off
  403 +;name or url of custom error page.
404 customerrorpagepath=customerrorpage.php 404 customerrorpagepath=customerrorpage.php
405 -;Turn custom error handler on or off 405 +;Turn custom error handler on or off.
  406 +;The custom error handler will log any non php errors caught
  407 +;by the custom error handler if it is turned on.
  408 +;Php errors are always logged by php itself.
406 customerrorhandler=on 409 customerrorhandler=on
config/dmsDefaults.php
@@ -97,6 +97,7 @@ if (!defined('PATH_SEPARATOR')) { @@ -97,6 +97,7 @@ if (!defined('PATH_SEPARATOR')) {
97 } 97 }
98 98
99 require_once(KT_LIB_DIR . '/Log.inc'); 99 require_once(KT_LIB_DIR . '/Log.inc');
  100 +require_once(KT_LIB_DIR . '/validation/customerror.php');
100 101
101 // {{{ KTInit 102 // {{{ KTInit
102 class KTInit { 103 class KTInit {
@@ -388,18 +389,27 @@ class KTInit { @@ -388,18 +389,27 @@ class KTInit {
388 389
389 // }}} 390 // }}}
390 391
391 -function catchFatalErrors($p_OnOff='On'){  
392 - ini_set('display_errors','On');  
393 - $phperror='><div id="phperror" style="display:none">';  
394 - ini_set('error_prepend_string',$phperror);  
395 -  
396 - $sUrl = KTInit::guessRootUrl();  
397 - global $default;  
398 - $sRootUrl = ($default->sslEnabled ? 'https' : 'http') .'://'.$_SERVER['HTTP_HOST'].$sUrl;  
399 -  
400 - $phperror='</div>><form name="catcher" action="'.$sRootUrl.'/customerrorpage.php" method="post" ><input type="hidden" name="fatal" value=""></form>  
401 - <script> document.catcher.fatal.value = document.getElementById("phperror").innerHTML; document.catcher.submit();</script>';  
402 - ini_set('error_append_string',$phperror); 392 +function catchFatalErrors()
  393 +{
  394 +
  395 + $CustomErrorPage = KTCustomErrorViewer::getCustomErrorRedirectPage();
  396 + if($CustomErrorPage != '0')
  397 + {
  398 + ini_set('display_errors','On');
  399 + $phperror='><div id="phperror" style="display:none">';
  400 + ini_set('error_prepend_string',$phperror);
  401 +
  402 + $sUrl = KTInit::guessRootUrl();
  403 + global $default;
  404 + $sRootUrl = ($default->sslEnabled ? 'https' : 'http') .'://'.$_SERVER['HTTP_HOST'].$sUrl;
  405 +
  406 + $CustomErrorPage = basename($CustomErrorPage);
  407 +
  408 + $phperror='</div>><form name="catcher" action="'.$sRootUrl.'/'.$CustomErrorPage.'" method="post" ><input type="hidden" name="fatal" value=""></form>
  409 + <script> document.catcher.fatal.value = document.getElementById("phperror").innerHTML; document.catcher.submit();</script>';
  410 + ini_set('error_append_string',$phperror);
  411 + }
  412 +
403 } 413 }
404 414
405 415
@@ -704,21 +714,6 @@ require_once(KT_LIB_DIR . &#39;/util/ktutil.inc&#39;); @@ -704,21 +714,6 @@ require_once(KT_LIB_DIR . &#39;/util/ktutil.inc&#39;);
704 714
705 require_once(KT_LIB_DIR . '/ktentity.inc'); 715 require_once(KT_LIB_DIR . '/ktentity.inc');
706 716
707 -//$KTInit->catchFatalErrors();  
708 -  
709 -if (phpversion()<5){  
710 -  
711 - $sErrorPage = 'http://'.$_SERVER['HTTP_HOST'].'/'.'customerrorpage.php';  
712 -  
713 - session_start();  
714 -  
715 - $_SESSION['sErrorMessage'] = 'KnowledgeTree now requires that PHP version 5 is installed. PHP version 4 is no longer supported.';  
716 -  
717 -  
718 - header('location:'. $sErrorPage ) ;  
719 -  
720 -}  
721 -  
722 require_once(KT_LIB_DIR . '/config/config.inc.php'); 717 require_once(KT_LIB_DIR . '/config/config.inc.php');
723 require_once(KT_DIR . '/search2/indexing/indexerCore.inc.php'); 718 require_once(KT_DIR . '/search2/indexing/indexerCore.inc.php');
724 719
@@ -732,6 +727,24 @@ if (isset($GLOBALS[&#39;kt_test&#39;])) { @@ -732,6 +727,24 @@ if (isset($GLOBALS[&#39;kt_test&#39;])) {
732 } 727 }
733 728
734 $oKTConfig =& KTConfig::getSingleton(); 729 $oKTConfig =& KTConfig::getSingleton();
  730 +
  731 +if($oKTConfig->get('CustomErrorMessages/customerrormessages') == 'on')
  732 +{
  733 + $KTInit->catchFatalErrors();
  734 +}
  735 +
  736 +if (phpversion()<5){
  737 +
  738 + $sErrorPage = 'http://'.$_SERVER['HTTP_HOST'].'/'.'customerrorpage.php';
  739 +
  740 + session_start();
  741 +
  742 + $_SESSION['sErrorMessage'] = 'KnowledgeTree now requires that PHP version 5 is installed. PHP version 4 is no longer supported.';
  743 +
  744 +
  745 + header('location:'. $sErrorPage ) ;
  746 +
  747 +}
735 $KTInit->setupServerVariables(); 748 $KTInit->setupServerVariables();
736 749
737 // instantiate log 750 // instantiate log
customerrorpage.php
@@ -13,32 +13,39 @@ if (array_key_exists(&#39;Error_MessageOne&#39;, $_POST) &amp;&amp; array_key_exists(&#39;Error_Mess @@ -13,32 +13,39 @@ if (array_key_exists(&#39;Error_MessageOne&#39;, $_POST) &amp;&amp; array_key_exists(&#39;Error_Mess
13 } 13 }
14 14
15 session_start(); 15 session_start();
16 -require_once("config/dmsDefaults.php"); 16 +
17 17
18 if (array_key_exists('sErrorMessage', $_SESSION)) 18 if (array_key_exists('sErrorMessage', $_SESSION))
19 { 19 {
20 -$phperror = $_SESSION['sErrorMessage']; 20 + $phperror = $_SESSION['sErrorMessage'];
21 } 21 }
22 22
23 -global $default;  
24 -  
25 -$sUrl = $default->rootUrl; 23 +//Finding root Url
  24 +$sHost = $_SERVER['HTTP_HOST'];
  25 +$sScriptName = dirname($_SERVER['SCRIPT_NAME']);
  26 +$sRoot = $sHost.$sScriptName;
  27 +$bSSLEnabled = false;
  28 +if ($_SERVER['HTTPS'] === 'on')
  29 +{
  30 + $bSSLEnabled = true;
  31 +}
  32 +$sRootUrl = ($bSSLEnabled ? 'https://' : 'http://').$sRoot;
26 33
27 ?> 34 ?>
28 35
29 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html> 36 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
30 <head> 37 <head>
31 <title>Knowledgetree - Desklet</title> 38 <title>Knowledgetree - Desklet</title>
32 - <link rel="stylesheet" type="text/css" href="<?php echo $sUrl ?>/resources/css/errors.css" /> 39 + <link rel="stylesheet" type="text/css" href="<?php echo $sRootUrl ?>/resources/css/errors.css" />
33 40
34 <script type="text/javascript"> 41 <script type="text/javascript">
35 42
36 function Click() 43 function Click()
37 { 44 {
38 -var open = document.getElementById('exp');  
39 -open.style.display = 'block';  
40 -var border = document.getElementById('error-container');  
41 -border.style.height = '250px'; 45 + var open = document.getElementById('exp');
  46 + open.style.display = 'block';
  47 + var border = document.getElementById('error-container');
  48 + border.style.height = '250px';
42 } 49 }
43 50
44 </script> 51 </script>
@@ -53,7 +60,7 @@ border.style.height = &#39;250px&#39;; @@ -53,7 +60,7 @@ border.style.height = &#39;250px&#39;;
53 60
54 <h1>Error!! - You have encountered a problem starting your document management system.</h1> 61 <h1>Error!! - You have encountered a problem starting your document management system.</h1>
55 <p><h2>Please contact your systems administrator</h2></p> 62 <p><h2>Please contact your systems administrator</h2></p>
56 - <p>For more details, click here <img src="<?php echo $sUrl ?>/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; } else if($phperror){ echo $phperror; } ?></div></p> 63 + <p>For more details, click here <img src="<?php echo $sRootUrl ?>/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; } else if($phperror){ echo $phperror; } ?></div></p>
57 64
58 </div> 65 </div>
59 </div> 66 </div>
lib/dispatcher.inc.php
@@ -537,38 +537,17 @@ class KTErrorDispatcher extends KTStandardDispatcher { @@ -537,38 +537,17 @@ class KTErrorDispatcher extends KTStandardDispatcher {
537 } 537 }
538 538
539 function dispatch() { 539 function dispatch() {
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 - } 540 +
  541 + require_once(KT_LIB_DIR . '/validation/customerror.php');
  542 +
  543 + $bCustomCheck = KTCustomErrorCheck::customErrorInit($this->oError);
  544 +
  545 + if($bCustomCheck)
  546 + {
  547 + exit(0);
570 } 548 }
571 549
  550 +
572 //if either customer error messages is off or the custom error page doesn't exist the function will run 551 //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 552 //the default error handling here
574 $oRegistry =& KTErrorViewerRegistry::getSingleton(); 553 $oRegistry =& KTErrorViewerRegistry::getSingleton();
lib/validation/customerror.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * $Id: $
  4 + *
  5 + * KnowledgeTree Open Source Edition
  6 + * Document Management Made Simple
  7 + * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
  8 + *
  9 + * This program is free software; you can redistribute it and/or modify it under
  10 + * the terms of the GNU General Public License version 3 as published by the
  11 + * Free Software Foundation.
  12 + *
  13 + * This program is distributed in the hope that it will be useful, but WITHOUT
  14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  16 + * details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20 + *
  21 + * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
  22 + * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
  23 + *
  24 + * The interactive user interfaces in modified source and object code versions
  25 + * of this program must display Appropriate Legal Notices, as required under
  26 + * Section 5 of the GNU General Public License version 3.
  27 + *
  28 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  29 + * these Appropriate Legal Notices must retain the display of the "Powered by
  30 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  31 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  32 + * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * copyright notice.
  34 + * Contributor( s): ______________________________________
  35 + */
  36 +
  37 +require_once(KT_LIB_DIR . '/validation/errorviewer.inc.php');
  38 +require_once(KT_LIB_DIR . '/validation/customerrorviewer.inc.php');
  39 +
  40 +class KTCustomErrorCheck
  41 +{
  42 + function customErrorInit($error)
  43 + {
  44 + $oCustomViewer =& KTCustomErrorViewer::initCustomErrorViewer();
  45 +
  46 + //if the custom error messages are set to 'on' in the config file
  47 + //we check if the error page exists and redirect to it if it does.
  48 + //if either the page doesn't exit or the custom error option is off in the config file
  49 + //we carry out default error reporting
  50 + if ($oCustomViewer->getCustomErrorConfigSetting() == 'on')
  51 + {
  52 +
  53 + $CustomErrorPage = $oCustomViewer->getCustomErrorRedirectPage();
  54 + if ( $CustomErrorPage != '0') //if an error is not returned from getCustomErrorRedirectPage();
  55 + {
  56 +
  57 + $sErrorHandler = $oCustomViewer->getCustomErrorHandlerSetting();
  58 +
  59 +
  60 + if ($sErrorHandler == 'on')
  61 + {
  62 + $oErrorHandler = KTCustomErrorHandler::initCustomErrorHandler();
  63 + $oErrorHandler->logError($error);
  64 + }
  65 +
  66 + //redirect
  67 + $oCustomViewer->doCustomErrorPageRedirect($CustomErrorPage, $error);
  68 +
  69 +
  70 + //exit without errors
  71 + return true;
  72 + }
  73 + else
  74 + {
  75 + return false;
  76 + }
  77 + }
  78 + else
  79 + {
  80 + return false;
  81 + }
  82 + }
  83 +}
  84 +?>
0 \ No newline at end of file 85 \ No newline at end of file
lib/validation/customerrorhandler.php
@@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@
33 * copyright notice. 33 * copyright notice.
34 * Contributor( s): ______________________________________ 34 * Contributor( s): ______________________________________
35 */ 35 */
36 - require_once('config/dmsDefaults.php'); 36 + //require_once(KT_DIR.'config/dmsDefaults.php');
37 require_once(KT_LIB_DIR.'/Log.inc'); 37 require_once(KT_LIB_DIR.'/Log.inc');
38 38
39 class KTCustomErrorHandler 39 class KTCustomErrorHandler
lib/validation/customerrorviewer.inc.php
@@ -72,7 +72,11 @@ @@ -72,7 +72,11 @@
72 if (substr($sCustomErrorPage, 0, 4) != 'http') 72 if (substr($sCustomErrorPage, 0, 4) != 'http')
73 { 73 {
74 74
75 - $sCustomErrorPage = 'http://'.$_SERVER['HTTP_HOST'].'/'.$sCustomErrorPage; 75 + $sUrl = KTInit::guessRootUrl();
  76 + global $default;
  77 + $sRootUrl = ($default->sslEnabled ? 'https' : 'http') .'://'.$_SERVER['HTTP_HOST'].$sUrl;
  78 + $sCustomErrorPage = $sRootUrl.'/'.$sCustomErrorPage;
  79 +
76 80
77 } 81 }
78 82
@@ -106,7 +110,6 @@ @@ -106,7 +110,6 @@
106 // {{{ customErrorPageRedirect() 110 // {{{ customErrorPageRedirect()
107 function doCustomErrorPageRedirect($CustomErrorPage, $oError = null) 111 function doCustomErrorPageRedirect($CustomErrorPage, $oError = null)
108 { 112 {
109 - $sErrorMessage = '';  
110 if($oError != null) 113 if($oError != null)
111 { 114 {
112 //call error handler 115 //call error handler
@@ -114,22 +117,19 @@ @@ -114,22 +117,19 @@
114 $aErrorMessage = array (); 117 $aErrorMessage = array ();
115 $aErrorMessage['Error_MessageOne'] = $oError->getMessage(); 118 $aErrorMessage['Error_MessageOne'] = $oError->getMessage();
116 $aErrorMessage['Error_MessageTwo'] = $oError->getUserInfo(); 119 $aErrorMessage['Error_MessageTwo'] = $oError->getUserInfo();
117 - //echo '<pre>';  
118 - //print_r($aErrorMessage);  
119 - //echo '</pre>';  
120 - //exit;  
121 - $customErrorHandler = KTCustomErrorHandler::initCustomErrorHandler();  
122 - $customErrorHandler->logError($oError); 120 +
123 } 121 }
124 - 122 +
  123 +
125 $ErrorPageCurlSession = curl_init($CustomErrorPage); 124 $ErrorPageCurlSession = curl_init($CustomErrorPage);
126 - //curl_setopt($ErrorPageCurlSession, CURLOPT_SSL_VERIFYPEER, false); 125 + //curl_setopt($ErrorPageCurlSession, CURLOPT_SSL_VERIFYPEER, false);
127 curl_setopt($ErrorPageCurlSession, CURLOPT_POST, true); 126 curl_setopt($ErrorPageCurlSession, CURLOPT_POST, true);
128 curl_setopt($ErrorPageCurlSession, CURLOPT_POSTFIELDS, $aErrorMessage); 127 curl_setopt($ErrorPageCurlSession, CURLOPT_POSTFIELDS, $aErrorMessage);
129 $ErrorPageSent = curl_exec($ErrorPageCurlSession); 128 $ErrorPageSent = curl_exec($ErrorPageCurlSession);
130 - curl_close($ErrorPageCurlSession);  
131 - 129 + curl_close($ErrorPageCurlSession);
  130 +
132 } 131 }
133 // }}} 132 // }}}
  133 +
134 } 134 }
135 ?> 135 ?>