File indexing completed on 2024-12-22 05:33:31
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class ErrorController extends Local_Controller_Action_DomainSwitch 0024 { 0025 0026 protected $error_401_msg = "<p>Sorry, but you are not authorized to view this page. 0027 Either no authentication was provided, it was invalid, or this page is not meant for your eyes. 0028 0029 Still no luck? Search for whatever is missing, or take a look around the rest of our site. </p>"; 0030 0031 protected $error_403_msg = "<p>Sorry, but you cannot access this page. 0032 Even if you have authentication, you are still not allowed to access this page. It's not meant for your eyes - ever!</p> 0033 0034 <p>Still no luck? Search for whatever is missing, or take a look around the rest of our site. </p>"; 0035 0036 0037 protected $error_404_msg = "<p>We're sorry. 0038 0039 Unfortunately the page you were looking for could not be found. It may be temporarily unavailable, moved or no longer exist. 0040 0041 Check the URL you entered for any mistakes and try again. Still no luck? Search for whatever is missing, or take a look around the rest of our site. </p>"; 0042 0043 0044 protected $error_500_msg = "<p>We're sorry. 0045 0046 Unfortunately the page you were looking for could not be found. It may be temporarily unavailable, moved or no longer exist. 0047 0048 Check the URL you entered for any mistakes and try again. Still no luck? Search for whatever is missing, or take a look around the rest of our site. </p>"; 0049 0050 0051 protected $error_503_msg = "<p>Sorry, but our servers are currently unavailable. 0052 We're probably overloaded or down for maintenance.</p> 0053 0054 <p>Refresh the page or try again later - this is only temporary. 0055 Still no luck? Search for whatever is missing, or take a look around the rest of our site. </p>"; 0056 0057 public function errorAction() 0058 { 0059 $errors = $this->getParam('error_handler'); 0060 $this->getResponse()->clearBody(); 0061 0062 switch ($errors->type) { 0063 case Default_Plugin_ErrorHandler::EXCEPTION_NO_ACL_RULE: 0064 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: 0065 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: 0066 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: 0067 // 404 error -- controller or action or route not found 0068 $this->getResponse()->setHttpResponseCode(404); 0069 $this->view->message = $this->error_404_msg; 0070 break; 0071 default: 0072 // application error 0073 $this->getResponse()->setHttpResponseCode(500); 0074 $this->view->message = $this->error_500_msg; 0075 break; 0076 } 0077 0078 if ($this->getInvokeArg('displayExceptions') == true) { 0079 $this->view->exception = $errors->exception; 0080 $this->view->request = $errors->request; 0081 } 0082 0083 $errorLog = Zend_Registry::get('logger'); 0084 0085 $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'undefined'; 0086 $storeHost = Zend_Registry::isRegistered('store_host') ? Zend_Registry::get('store_host') : 'undefined'; 0087 0088 if ($errors->exception->getCode() == 404) { 0089 $errorInfo = array( 0090 'REQUEST_URI' => $_SERVER['REQUEST_URI'], 0091 'MESSAGES' => $errors->exception->getMessage(), 0092 'HOST' => $_SERVER['HTTP_HOST'], 0093 'STORE_HOST' => Zend_Registry::isRegistered('store_host') ? Zend_Registry::get('store_host') : 'undefined', 0094 'USER_AGENT' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'undefined', 0095 'ENVIRONMENT' => APPLICATION_ENV, 0096 'REMOTE_ADDR' => $_SERVER['REMOTE_ADDR'], 0097 'FORWARDED_IP' => isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : 'undefined', 0098 0099 ); 0100 $errorLog->err(__METHOD__ . ' - ' . json_encode($errorInfo)); 0101 0102 return; 0103 } 0104 0105 $errorMsg = '' . PHP_EOL; 0106 $errorMsg .= 'MESSAGE:: ' . $errors->exception->getMessage() . PHP_EOL; 0107 $errorMsg .= 'HOST:: ' . $_SERVER['HTTP_HOST'] . PHP_EOL; 0108 $errorMsg .= 'USER_AGENT:: ' . $userAgent . PHP_EOL; 0109 $errorMsg .= 'REQUEST_URI:: ' . $_SERVER['REQUEST_URI'] . PHP_EOL; 0110 $errorMsg .= 'ENVIRONMENT:: ' . APPLICATION_ENV . PHP_EOL; 0111 $errorMsg .= 'STORE_HOST:: ' . $storeHost . PHP_EOL; 0112 if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { 0113 $errorMsg .= 'FORWARDED_IP::' . $_SERVER['HTTP_X_FORWARDED_FOR'] . PHP_EOL; 0114 } else { 0115 $errorMsg .= 'REMOTE_ADDR:: ' . $_SERVER['REMOTE_ADDR'] . PHP_EOL; 0116 } 0117 0118 if (isset($errors->exception->xdebug_message)) { 0119 $errorMsg .= 'XDEBUG_MESSAGE::' . $errors->exception->xdebug_message . PHP_EOL; 0120 } else { 0121 $errorMsg .= 'TRACE_STRING::' . $errors->exception->getTraceAsString() . PHP_EOL; 0122 } 0123 $errorLog->err(__METHOD__ . ' - ' . $errorMsg . PHP_EOL); 0124 } 0125 0126 public function privilegesAction() 0127 { 0128 $this->getResponse()->setHttpResponseCode(403); 0129 } 0130 0131 public function loginAction() 0132 { 0133 $this->getResponse() 0134 ->setHttpResponseCode(401); 0135 /** @var Zend_Controller_Request_Http $request */ 0136 $request = $this->getRequest(); 0137 if ($request->isXmlHttpRequest()) { 0138 $loginUri = $request->getParam('redirect') ? '/login/redirect/' . $request->getParam('redirect') : '/login'; 0139 $this->_helper->json(array( 0140 'status' => 'error', 0141 'title' => '', 0142 'message' => 'Login Required', 0143 'code' => 401, 0144 'login_url' => $loginUri 0145 )); 0146 } 0147 } 0148 0149 protected function _initResponseHeader() 0150 { 0151 parent::_initResponseHeader(); // TODO: Change the autogenerated stub 0152 $this->getResponse() 0153 ->clearHeaders(array('Expires', 'Pragma', 'Cache-Control')) 0154 ->setHeader('Pragma', 'no-cache', true) 0155 ->setHeader('Cache-Control', 'private, no-cache, must-revalidate', true); 0156 } 0157 0158 }