예제 #1
0
 public function jsonErrorAction()
 {
     $errors = $this->getRequest()->getParam('error_handler');
     $exception = $errors->exception;
     if ($exception instanceof Kwf_Exception_Abstract) {
         $this->getResponse()->setRawHeader($exception->getHeader());
     } else {
         $this->getResponse()->setRawHeader('HTTP/1.1 500 Internal Server Error');
     }
     if ($exception instanceof Kwf_Exception_Client) {
         $this->view->error = $exception->getMessage();
     } else {
         if (!$exception instanceof Kwf_Exception_Abstract) {
             $exception = new Kwf_Exception_Other($exception);
         }
         $this->view->error = $exception->getMessage();
         if (!$this->view->error) {
             $this->view->error = 'An error occurred';
         }
         if (Kwf_Exception::isDebug()) {
             $this->view->exception = explode("\n", $exception->getException()->__toString());
         }
     }
     $exception->log();
 }
예제 #2
0
 public function log()
 {
     if (Kwf_Exception::isDebug()) {
         return false;
     }
     $body = $this->_getLogBody();
     return Kwf_Exception_Logger_Abstract::getInstance()->log($this, 'error', $body);
 }
 public function log()
 {
     if (Kwf_Exception::isDebug()) {
         return false;
     }
     $body = '';
     $body .= $this->_format('REQUEST_URI', isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '(none)');
     $body .= $this->_format('HTTP_REFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '(none)');
     $body .= $this->_format('Time', date('H:i:s'));
     $body .= $this->_format('_GET', print_r($_GET, true));
     $body .= $this->_format('_POST', print_r($_POST, true));
     Kwf_Exception_Logger_Abstract::getInstance()->log($this, 'accessdenied', $body);
 }
예제 #4
0
 public function log()
 {
     if (Kwf_Exception::isDebug()) {
         return false;
     }
     $requestUri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '(none)';
     $ignore = array('/favicon.ico', '/robots.txt');
     if (in_array($requestUri, $ignore)) {
         return false;
     }
     if (substr($requestUri, 0, 7) == '/files/' || substr($requestUri, 0, 12) == '/monitoring/') {
         //TODO: don't hardcode here
         return false;
     }
     $body = '';
     $body .= $this->_format('REQUEST_URI', isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '(none)');
     $body .= $this->_format('HTTP_REFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '(none)');
     $body .= $this->_format('Time', date('H:i:s'));
     Kwf_Exception_Logger_Abstract::getInstance()->log($this, 'notfound', $body);
 }
예제 #5
0
 public function render($ignoreCli = false)
 {
     try {
         $exception = $this->getException();
         $msg = $exception->__toString();
         if ($exception instanceof Zend_Db_Adapter_Exception) {
             try {
                 foreach (Kwf_Registry::get('config')->database as $db) {
                     $msg = str_replace($db->password, 'xxxxxx', $msg);
                 }
             } catch (Exception $e) {
             }
         }
         if (!$ignoreCli && PHP_SAPI == 'cli') {
             $this->log();
             file_put_contents('php://stderr', $msg . "\n");
             exit(1);
         }
         class_exists('Kwf_Trl');
         //eventually trigger autoloader
         $view = Kwf_Debug::getView();
         $view->exception = $msg;
         $view->message = $exception->getMessage();
         $view->requestUri = isset($_SERVER['REQUEST_URI']) ? htmlspecialchars($_SERVER['REQUEST_URI']) : '';
         $view->debug = Kwf_Exception::isDebug() || !Kwf_Registry::get('config')->setupFinished;
         try {
             if (Kwf_Registry::get('userModel') && Kwf_Registry::get('userModel')->getAuthedUserRole() == 'admin') {
                 $view->debug = true;
             }
         } catch (Exception $e) {
         }
         if (Kwf_Component_Data_Root::getComponentClass()) {
             $data = null;
             if (isset($_SERVER['HTTP_HOST'])) {
                 //try to get the page of current domain to get correct language
                 $acceptLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null;
                 try {
                     $data = Kwf_Component_Data_Root::getInstance()->getPageByUrl('http://' . $_SERVER['HTTP_HOST'] . '/', $acceptLanguage);
                 } catch (Exception $e) {
                 }
             }
             if (!$data) {
                 $data = Kwf_Component_Data_Root::getInstance();
             }
             $view->data = $data;
             //can be used for trl
         } else {
             //no components used, use Kwf_Trl object that also has trl() methods
             //HACK, but will work if only trl is used in template
             $view->data = Kwf_Trl::getInstance();
         }
         $header = $this->getHeader();
         $template = $this->getTemplate();
         $template = strtolower(Zend_Filter::filterStatic($template, 'Word_CamelCaseToDash') . '.tpl');
         $this->log();
         if (!headers_sent()) {
             header($header);
             header('Content-Type: text/html; charset=utf-8');
         }
         echo $view->render($template);
     } catch (Exception $e) {
         echo '<pre>';
         echo $this->getException()->__toString();
         echo "\n\n\nError happened while handling exception:";
         echo $e->__toString();
         echo '</pre>';
     }
 }
예제 #6
0
 public static function generateCode()
 {
     $preloadIncludePaths = array();
     $namespaces = (require VENDOR_PATH . '/composer/autoload_namespaces.php');
     $ret = array();
     foreach ($namespaces as $ns => $dirs) {
         $preloadIncludePaths = array_merge($preloadIncludePaths, $dirs);
     }
     $ret = "<?php\n";
     $ret .= "\$cwd = getcwd();\n";
     $preloadClasses = array('Kwf_Benchmark', 'Kwf_Loader', 'Kwf_Debug');
     $ret .= "if (!class_exists('Kwf_Loader', false)) {\n";
     $ret .= self::_generatePreloadClassesCode($preloadClasses, $preloadIncludePaths);
     $ret .= "}\n";
     $ret .= "Kwf_Benchmark::\$startTime = microtime(true);\n";
     $ret .= "\n";
     //override the default cache (/tmp) dir used by Zend_Cache_Backend to have the cache per web
     $ret .= "\$_SERVER['TMP'] = 'cache/zend';\n";
     //only replace configured value to avoid spoofing
     //required eg. behind load balancers
     if (Kwf_Config::getValueArray('server.replaceVars.remoteAddr')) {
         $a = Kwf_Config::getValueArray('server.replaceVars.remoteAddr');
         if (substr($a['if'], -2) == '.*') {
             $comparison = "substr(\$_SERVER['REMOTE_ADDR'], 0, " . (strlen($a['if']) - 1) . ") == '" . substr($a['if'], 0, -1) . "'";
         } else {
             $comparison = "\$_SERVER['REMOTE_ADDR'] == '{$a['if']}'";
         }
         $ret .= "\nif (isset(\$_SERVER['REMOTE_ADDR']) && {$comparison} && isset(\$_SERVER['{$a['replace']}'])) {\n";
         $ret .= "    \$_SERVER['REMOTE_ADDR'] = \$_SERVER['{$a['replace']}'];\n";
         if (isset($a['removeTrailing'])) {
             $ret .= "    if (substr(\$_SERVER['REMOTE_ADDR'], -" . strlen($a['removeTrailing']) . ") == '" . $a['removeTrailing'] . "') {\n";
             $ret .= "        \$_SERVER['REMOTE_ADDR'] = substr(\$_SERVER['REMOTE_ADDR'], 0, -" . strlen($a['removeTrailing']) . ");\n";
             $ret .= "    }\n";
         }
         if (isset($a['removePattern'])) {
             $ret .= "    \$_SERVER['REMOTE_ADDR'] = preg_replace('/" . $a['removePattern'] . "/', '', \$_SERVER['REMOTE_ADDR']);\n";
         }
         $ret .= "}\n";
     }
     //try different values, if one spoofs this this is no security issue
     $ret .= "if (isset(\$_SERVER['HTTP_SSL_SESSION_ID'])) \$_SERVER['HTTPS'] = 'on';\n";
     $ret .= "if (isset(\$_SERVER['HTTP_SESSION_ID_TAG'])) \$_SERVER['HTTPS'] = 'on';\n";
     $ret .= "if (isset(\$_SERVER['HTTP_X_FORWARDED_PROTO']) && \$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {\n";
     $ret .= "    \$_SERVER['HTTPS'] = 'on';\n";
     $ret .= "}\n";
     if (VENDOR_PATH == '../vendor') {
         $kwfPath = '..';
     } else {
         $kwfPath = VENDOR_PATH . '/koala-framework/koala-framework';
     }
     $ret .= "if (!defined('KWF_PATH')) define('KWF_PATH', '{$kwfPath}');\n";
     $ret .= "if (!defined('VENDOR_PATH')) define('VENDOR_PATH', 'vendor');\n";
     $ip = array();
     foreach (include VENDOR_PATH . '/composer/include_paths.php' as $p) {
         if (VENDOR_PATH == '../vendor') {
             $cwd = getcwd();
             $cwd = substr($cwd, 0, strrpos($cwd, '/'));
             self::_verifyPathInParentPath($p, $cwd);
             $p = '../' . substr($p, strlen($cwd) + 1);
         } else {
             self::_verifyPathInParentPath($p, getcwd());
             $p = substr($p, strlen(getcwd()) + 1);
         }
         $ip[] = "'.\$cwd.'/" . $p;
     }
     $ip[] = '.';
     foreach (Kwf_Config::getValueArray('includepath') as $t => $p) {
         if ($p) {
             $ip[] = $p;
         }
     }
     $ip = array_unique($ip);
     $ret .= "Kwf_Loader::setIncludePath('" . implode(PATH_SEPARATOR, $ip) . "');\n";
     $ret .= "\n";
     $ret .= "\n";
     if (Kwf_Exception::isDebug()) {
         $ret .= "error_reporting(E_ALL | E_STRICT | E_DEPRECATED);\n";
         $ret .= "set_error_handler(array('Kwf_Debug', 'handleError'), E_ALL | E_STRICT | E_DEPRECATED);\n";
     } else {
         $ret .= "error_reporting(E_ALL & ~E_STRICT);\n";
         $ret .= "set_error_handler(array('Kwf_Debug', 'handleError'), E_ALL & ~E_STRICT);\n";
     }
     $ret .= "set_exception_handler(array('Kwf_Debug', 'handleException'));\n";
     $ret .= "\n";
     $ret .= "\$requestUri = isset(\$_SERVER['REQUEST_URI']) ? \$_SERVER['REQUEST_URI'] : null;\n";
     if (Kwf_Setup::getBaseUrl()) {
         $ret .= "if (\$requestUri !== null) {\n";
         $ret .= "    if (substr(\$requestUri, 0, " . strlen(Kwf_Setup::getBaseUrl()) . ") != '" . Kwf_Setup::getBaseUrl() . "') {\n";
         $ret .= "        echo 'Invalid baseUrl, expected \\'" . Kwf_Setup::getBaseUrl() . "\\'';\n";
         $ret .= "        exit;\n";
         $ret .= "    }\n";
         $ret .= "    \$requestUri = substr(\$requestUri, " . strlen(Kwf_Setup::getBaseUrl()) . ");\n";
         $ret .= "}\n";
     }
     $ret .= "\n";
     if (Kwf_Config::getValue('debug.benchmark') || Kwf_Config::getValue('debug.benchmarklog')) {
         //vor registerAutoload aufrufen damit wir dort benchmarken können
         $ret .= "Kwf_Benchmark::enable();\n";
     } else {
         $ret .= "if (isset(\$_REQUEST['KWF_BENCHMARK'])) {\n";
         foreach (Kwf_Config::getValueArray('debug.benchmarkActivatorIp') as $activatorIp) {
             $ret .= "    if (\$_SERVER['REMOTE_ADDR'] == '{$activatorIp}') Kwf_Benchmark::enable();\n";
         }
         $ret .= "}\n";
     }
     $ret .= "Kwf_Loader::registerAutoload();\n";
     $ret .= "\n";
     $configSection = call_user_func(array(Kwf_Setup::$configClass, 'getDefaultConfigSection'));
     $ret .= "Kwf_Setup::\$configSection = '" . $configSection . "';\n";
     $ret .= "//here to be as fast as possible (and have no session)\n";
     $ret .= "if (\$requestUri == '/kwf/json-progress-status'\n";
     $ret .= ") {\n";
     $ret .= "    Kwf_Util_ProgressBar_DispatchStatus::dispatch();\n";
     $ret .= "}\n";
     $ret .= "\n";
     $ret .= "//here to have less dependencies\n";
     $ret .= "if (\$requestUri == '/kwf/check-config'\n";
     $ret .= ") {\n";
     $ret .= "    Kwf_Util_Check_Config::dispatch();\n";
     $ret .= "}\n";
     $ret .= "if (PHP_SAPI == 'cli' && isset(\$_SERVER['argv'][1]) && \$_SERVER['argv'][1] == 'check-config') {\n";
     $ret .= "    Kwf_Util_Check_Config::dispatch();\n";
     $ret .= "}\n";
     $ret .= "\$ml = ini_get('memory_limit');\n";
     $ret .= "if (strtoupper(substr(\$ml, -1)) == 'M') {\n";
     $ret .= "    if ((int)substr(\$ml, 0, -1) < 128) {\n";
     $ret .= "        ini_set('memory_limit', '128M');\n";
     $ret .= "    }\n";
     $ret .= "}\n";
     if (Kwf_Config::getValue('debug.error.log')) {
         $ret .= "ini_set('display_errors', false);\n";
     }
     if (function_exists('mb_internal_encoding')) {
         $ret .= "mb_internal_encoding('UTF-8');\n";
     }
     $ret .= "ini_set('default_charset', 'UTF-8');\n";
     $ret .= "umask(000); //nicht 002 weil wwwrun und kwcms in unterschiedlichen gruppen\n";
     //this is *NOT* recommended but still works somehow
     $ret .= "if (get_magic_quotes_gpc()) Kwf_Util_UndoMagicQuotes::undoMagicQuotes();\n";
     if (Kwf_Config::getValue('debug.firephp') || Kwf_Config::getValue('debug.querylog')) {
         $ret .= "if (PHP_SAPI != 'cli') {\n";
         if (Kwf_Config::getValue('debug.firephp')) {
             $ret .= "    require_once '" . Kwf_Config::getValue('externLibraryPath.firephp') . "/FirePHPCore/FirePHP.class.php';\n";
             $ret .= "    FirePHP::init();\n";
             $ret .= "    ob_start();\n";
         }
         $ret .= "}\n";
     }
     $ret .= "register_shutdown_function(array('Kwf_Setup', 'shutDown'));\n";
     $ret .= "if (!class_exists('Kwf_Config', false)) {\n";
     $preloadClasses = array('Kwf_Config', 'Kwf_Cache_Simple', 'Kwf_Cache_SimpleStatic');
     $ret .= self::_generatePreloadClassesCode($preloadClasses, $preloadIncludePaths);
     $ret .= "    if (substr(\$requestUri, 0, 8) != '/assets/') {\n";
     $preloadClasses = array();
     $preloadClasses[] = 'Zend_Registry';
     $preloadClasses[] = 'Kwf_Registry';
     $preloadClasses[] = 'Kwf_Trl';
     $preloadClasses[] = 'Kwf_Util_SessionHandler';
     $preloadClasses[] = 'Zend_Session';
     $preloadClasses[] = 'Kwf_Benchmark_Counter';
     $preloadClasses[] = 'Kwf_Benchmark_Counter_Apc';
     if (Kwf_Component_Data_Root::getComponentClass()) {
         //only load component related classes if it is a component web
         $preloadClasses[] = 'Kwf_Component_Data';
         $preloadClasses[] = 'Kwf_Component_Data_Root';
         $preloadClasses[] = 'Kwf_Component_Settings';
         $preloadClasses[] = 'Kwf_Component_Renderer_Abstract';
         $preloadClasses[] = 'Kwf_Component_Renderer';
         $preloadClasses[] = 'Kwf_Component_Cache';
         $preloadClasses[] = 'Kwf_Component_Cache_Mysql';
         $preloadClasses[] = 'Kwf_Component_Cache_Memory';
         $preloadClasses[] = 'Kwf_Component_Abstract_ContentSender_Abstract';
         $preloadClasses[] = 'Kwf_Component_Abstract_ContentSender_Default';
     }
     $ret .= self::_generatePreloadClassesCode($preloadClasses, $preloadIncludePaths);
     $ret .= "    } else {\n";
     $preloadClasses = array();
     $preloadClasses[] = 'Kwf_Assets_Loader';
     $preloadClasses[] = 'Kwf_Media_Output';
     $ret .= self::_generatePreloadClassesCode($preloadClasses, $preloadIncludePaths);
     $ret .= "    }\n";
     $ret .= "}\n";
     Kwf_Cache_Simple::$backend = null;
     //unset to re-calculate
     $ret .= "Kwf_Cache_Simple::\$backend = '" . Kwf_Cache_Simple::getBackend() . "';\n";
     $cacheUniquePrefix = Kwf_Config::getValue('cachePrefix');
     //can be '' when only a single web runs in memcache instance
     if ($cacheUniquePrefix === null) {
         $cacheUniquePrefix = getcwd() . '-' . Kwf_Setup::getConfigSection() . '-';
     }
     $ret .= "Kwf_Cache_Simple::\$uniquePrefix = '" . $cacheUniquePrefix . "';\n";
     if (Kwf_Config::getValue('cacheSimpleNamespace')) {
         $ret .= "Kwf_Cache_Simple::\$namespace = '" . Kwf_Config::getValue('cacheSimpleNamespace') . "';\n";
     }
     unset($cacheUniquePrefix);
     if (Kwf_Config::getValue('server.memcache.host')) {
         $host = Kwf_Config::getValue('server.memcache.host');
         $ret .= "Kwf_Cache_Simple::\$memcacheHost = '" . $host . "';\n";
         $ret .= "Kwf_Cache_Simple::\$memcachePort = '" . Kwf_Config::getValue('server.memcache.port') . "';\n";
     }
     if (Kwf_Config::getValue('server.redis.host')) {
         $host = Kwf_Config::getValue('server.redis.host');
         $ret .= "Kwf_Cache_Simple::\$redisHost = '" . $host . "';\n";
         $ret .= "Kwf_Cache_Simple::\$redisPort = '" . Kwf_Config::getValue('server.redis.port') . "';\n";
     }
     $ret .= "if (substr(\$requestUri, 0, 8) == '/assets/') {\n";
     $ret .= "    \$url = \$requestUri;\n";
     $ret .= "    if (strpos(\$url, '?') !== false) {\n";
     $ret .= "        \$url = substr(\$url, 0, strpos(\$url, '?'));\n";
     $ret .= "    }\n";
     $dispatcherClass = Kwf_Config::getValue('assets.dispatcherClass');
     if (!$dispatcherClass) {
         $dispatcherClass = 'Kwf_Assets_Dispatcher';
     }
     $ret .= "    \$dispatcher = new " . $dispatcherClass . "();\n";
     $ret .= "    \$dispatcher->dispatch(\$url);\n";
     $ret .= "    Kwf_Assets_Loader::load(\$url);\n";
     $ret .= "}\n";
     if (Kwf_Config::getValue('debug.benchmarkCounter')) {
         //vor registerAutoload aufrufen damit wir dort benchmarken können
         $ret .= "Kwf_Benchmark::enableLog();\n";
     }
     $ret .= "Zend_Registry::setClassName('Kwf_Registry');\n";
     $ret .= "\$host = isset(\$_SERVER['HTTP_HOST']) ? \$_SERVER['HTTP_HOST'] : null;\n";
     $ret .= "session_name('SESSION_" . Kwf_Config::getValue('application.id') . "');\n";
     //up here to have less dependencies or broken redirect
     $ret .= "\n";
     $ret .= "if (substr(\$requestUri, 0, 14) == '/kwf/util/apc/'\n";
     $ret .= ") {\n";
     $ret .= "    Kwf_Util_Apc::dispatchUtils();\n";
     $ret .= "}\n";
     $ret .= "\n";
     $ret .= "if (\$requestUri == '/kwf/check') {\n";
     $ret .= "    Kwf_Util_Check::dispatch();\n";
     $ret .= "}\n";
     $ret .= "\n";
     $ret .= "session_set_cookie_params(\n";
     $ret .= " 0,";
     //lifetime
     $ret .= " '" . Kwf_Setup::getBaseUrl() . "/',";
     //path
     $ret .= " null,";
     //domain
     $ret .= " isset(\$_SERVER['HTTPS']),";
     //secure
     $ret .= " true";
     //httponly
     $ret .= ");\n";
     $ret .= "\n";
     //store session data in memcache if avaliable
     if (Kwf_Config::getValue('server.redis.host')) {
         $ret .= "\nif (PHP_SAPI != 'cli') {\n";
         $ret .= "    ini_set('session.save_handler', 'redis');\n";
         $ret .= "    ini_set('session.save_path', 'tcp://" . Kwf_Config::getValue('server.redis.host') . ":" . Kwf_Config::getValue('server.redis.port') . "?prefix=" . substr(md5(Kwf_Cache_Simple::getUniquePrefix()), 0, 10) . "');\n";
         $ret .= "}\n";
     } else {
         if (Kwf_Config::getValue('server.memcache.host') && Kwf_Setup::hasDb()) {
             $ret .= "\nif (PHP_SAPI != 'cli') Kwf_Util_SessionHandler::init();\n";
         }
     }
     $ret .= "\n\$preLogin = false;\n";
     // Falls redirectToDomain eingeschalten ist, umleiten
     if (Kwf_Config::getValue('server.redirectToDomain')) {
         $ret .= "if (\$host && substr(\$requestUri, 0, 8) != '/assets/') {\n";
         $ret .= "    \$redirect = false;\n";
         if ($domains = Kwf_Config::getValueArray('kwc.domains')) {
             $ret .= "    \$domainMatches = false;\n";
             foreach ($domains as $domain) {
                 $ret .= "    if ('{$domain['domain']}' == \$host) \$domainMatches = true;\n";
                 if (isset($domain['preliminaryDomain'])) {
                     $ret .= "    if ('{$domain['preliminaryDomain']}' == \$host) {\n";
                     $ret .= "        \$domainMatches = true;\n";
                     if (isset($domain['preliminaryDomainPreLogin'])) {
                         //preliminaryDomainPreLogin set for this domain
                         if ($domain['preliminaryDomainPreLogin']) {
                             $ret .= "        \$preLogin = true;\n";
                         }
                     } else {
                         if (Kwf_Config::getValue('server.preliminaryDomainPreLogin')) {
                             //as default use global
                             $ret .= "        \$preLogin = true;\n";
                         }
                     }
                     $ret .= "    }\n";
                 }
             }
             $ret .= "    if (!\$domainMatches) {\n";
             foreach ($domains as $domain) {
                 if (isset($domain['pattern'])) {
                     $ret .= "\n";
                     $ret .= "        //pattern\n";
                     $ret .= "        if (!\$domainMatches && preg_match('/{$domain['pattern']}/', \$host)) {\n";
                     $ret .= "            \$domainMatches = true;\n";
                     if (isset($domain['noRedirectPattern'])) {
                         $ret .= "\n";
                         $ret .= "            //noRedirectPattern\n";
                         $ret .= "            if (!preg_match('/{$domain['noRedirectPattern']}/', \$host)) {\n";
                         $ret .= "                \$redirect = '{$domain['domain']}';\n";
                         $ret .= "            }\n";
                     } else {
                         $ret .= "            \$redirect = '{$domain['domain']}';\n";
                     }
                     $ret .= "        }\n";
                 }
             }
             $ret .= "    }\n";
             $ret .= "    if (!\$domainMatches) {\n";
             $ret .= "        \$redirect = '" . Kwf_Config::getValue('server.domain') . "';\n";
             $ret .= "    }\n";
         } else {
             if (Kwf_Config::getValue('server.domain')) {
                 $ret .= "    if (\$host == '" . Kwf_Config::getValue('server.domain') . "') {\n";
                 $ret .= "        //noop\n";
                 if (Kwf_Config::getValue('server.preliminaryDomain')) {
                     $ret .= "    } else if (\$host == '" . Kwf_Config::getValue('server.preliminaryDomain') . "') {\n";
                     if (Kwf_Config::getValue('server.preliminaryDomainPreLogin')) {
                         $ret .= "        \$preLogin = true;\n";
                     }
                 }
                 $ret .= "    } else {\n";
                 if (Kwf_Config::getValue('server.noRedirectPattern')) {
                     $ret .= "        if (!preg_match('/" . Kwf_Config::getValue('server.noRedirectPattern') . "/', \$host)) {\n";
                     $ret .= "            \$redirect = '" . Kwf_Config::getValue('server.domain') . "';\n";
                     $ret .= "        }\n";
                 } else {
                     $ret .= "        \$redirect = '" . Kwf_Config::getValue('server.domain') . "';\n";
                 }
                 $ret .= "    }\n";
             }
         }
         $ret .= "    if (\$redirect) {\n";
         $ret .= "        \$target = Kwf_Model_Abstract::getInstance('Kwf_Util_Model_Redirects')\n";
         $ret .= "            ->findRedirectUrl('domainPath', \$host.\$_SERVER['REQUEST_URI']);\n";
         $ret .= "        if (!\$target) {\n";
         $ret .= "            \$target = Kwf_Model_Abstract::getInstance('Kwf_Util_Model_Redirects')\n";
         $ret .= "                ->findRedirectUrl('domain', \$host);\n";
         $ret .= "        }\n";
         $ret .= "        if (\$target) {\n";
         $ret .= "            header('Location: '.\$target, true, 301);\n";
         $ret .= "        } else {\n";
         $ret .= "            //redirect to main domain (server.domain)\n";
         $ret .= "            header('Location: http://'.\$redirect.\$_SERVER['REQUEST_URI'], true, 301);\n";
         $ret .= "        }\n";
         $ret .= "        exit;\n";
         $ret .= "    }\n";
         $ret .= "}\n";
     }
     if (Kwf_Config::getValue('server.https') !== 'unknown') {
         $redirectHttpsCode = "    if (\$_SERVER['REQUEST_METHOD'] != 'GET') {\n";
         $redirectHttpsCode .= "        header('HTTP/1.1 400 Bad Request');\n";
         $redirectHttpsCode .= "        echo 'Invalid protocol, https required';\n";
         $redirectHttpsCode .= "        exit;\n";
         $redirectHttpsCode .= "    }\n";
         $redirectHttpsCode .= "    \$redirect = 'https://'.\$_SERVER['HTTP_HOST'].\$_SERVER['REQUEST_URI'];\n";
         $redirectHttpsCode .= "    header('Location: '.\$redirect, true, 301);\n";
         $redirectHttpsCode .= "    Kwf_Benchmark::shutDown();\n";
         $redirectHttpsCode .= "    exit;\n";
         $redirectHttpCode = str_replace('https', 'http', $redirectHttpsCode);
         $ret .= "if (PHP_SAPI != 'cli' && isset(\$_SERVER['HTTP_HOST']) && substr(\$requestUri, 0, 7) != '/media/') {\n";
         if (!Kwf_Config::getValue('server.https')) {
             $ret .= "if (isset(\$_SERVER['HTTPS'])) {\n";
             $ret .= "    {$redirectHttpCode}";
             $ret .= "}\n";
         } else {
             if ($domains = Kwf_Config::getValueArray('server.httpsDomains')) {
                 $ret .= "\$domains = array(";
                 foreach ($domains as $d) {
                     if (substr($d, 0, 2) != '*.') {
                         $ret .= "'" . $d . "'=>true, ";
                     }
                 }
                 $ret .= ");\n";
                 $ret .= "\$supportsHttps = isset(\$domains[\$_SERVER['HTTP_HOST']]);\n";
                 foreach ($domains as $d) {
                     if (substr($d, 0, 2) == '*.') {
                         $ret .= "    if (!\$supportsHttps && '" . substr($d, 1) . "' == substr(\$_SERVER['HTTP_HOST'], strpos(\$_SERVER['HTTP_HOST'], '.'))) {\n";
                         $ret .= "        \$supportsHttps = true;\n";
                         $ret .= "    }\n";
                     }
                 }
                 $ret .= "if (\$supportsHttps != isset(\$_SERVER['HTTPS'])) {\n";
                 $ret .= "    if (\$supportsHttps) {\n";
                 $ret .= "        {$redirectHttpsCode}";
                 $ret .= "    } else {\n";
                 $ret .= "        {$redirectHttpCode}";
                 $ret .= "    }\n";
                 $ret .= "}\n";
             } else {
                 $ret .= "if (!isset(\$_SERVER['HTTPS'])) {\n";
                 $ret .= "{$redirectHttpsCode}";
                 $ret .= "}\n";
             }
         }
         $ret .= "}\n";
     }
     if (Kwf_Config::getValue('preLogin')) {
         $ret .= "if (PHP_SAPI != 'cli' && Kwf_Setup::getRequestPath()!==false) {\n";
         $ret .= "    \$preLogin = true;\n";
         $ret .= "}\n";
     }
     $ret .= "if (\$preLogin) {\n";
     $ret .= "    \$ignore = false;\n";
     foreach (Kwf_Config::getValueArray('preLoginIgnore') as $i) {
         $ret .= "    if (substr(\$_SERVER['REDIRECT_URL'], 0, " . strlen($i) . ") == '{$i}') \$ignore = true;\n";
     }
     foreach (Kwf_Config::getValueArray('preLoginIgnoreIp') as $i) {
         if (substr($i, -1) == '*') {
             $i = substr($i, 0, -1);
             $ret .= "    if (substr(\$_SERVER['REMOTE_ADDR'], 0, " . strlen($i) . ") == '{$i}') \$ignore = true;\n";
         } else {
             if (substr($i, 0, 1) == '*') {
                 $i = substr($i, 1);
                 $ret .= "    if (substr(\$_SERVER['REMOTE_ADDR'], -" . strlen($i) . ") == '{$i}') \$ignore = true;\n";
             } else {
                 $ret .= "    if (\$_SERVER['REMOTE_ADDR'] == '{$i}') \$ignore = true;\n";
             }
         }
     }
     $ret .= "    if (!\$ignore) {\n";
     $ret .= "        Kwf_Setup::checkPreLogin('" . Kwf_Config::getValue('preLoginUser') . "', '" . Kwf_Config::getValue('preLoginPassword') . "');\n";
     $ret .= "    }\n";
     $ret .= "}\n";
     if ($parameters = Kwf_Config::getValueArray('parameterToCookie')) {
         foreach ($parameters as $parameter) {
             $ret .= "if (isset(\$_GET['" . $parameter . "'])) setcookie('" . $parameter . "', \$_GET['" . $parameter . "'], 0, '/');\n";
         }
     }
     if ($tl = Kwf_Config::getValue('debug.timeLimit')) {
         $ret .= "set_time_limit({$tl});\n";
     }
     $ret .= "if (isset(\$_GET['kwcPreview'])) {\n";
     $ret .= "    \$role = Kwf_Registry::get('userModel')->getAuthedUserRole();\n";
     $ret .= "    if (!Kwf_Registry::get('acl')->isAllowed(\$role, 'kwf_component_preview', 'view')) {\n";
     $ret .= "        header('Location: /admin/component/preview/redirect/?url='.urlencode(\$_SERVER['REQUEST_URI']));\n";
     $ret .= "        exit;\n";
     $ret .= "    }\n";
     $ret .= "    Kwf_Component_Data_Root::setShowInvisible(true);\n";
     $ret .= "}\n";
     return $ret;
 }
예제 #7
0
 protected function _renderJson($exception, $msg)
 {
     $data = array('error' => array('code' => $exception->code, 'errorId' => $exception->getLogId(), 'message' => 'An Error occured. Please try again later'));
     if (Kwf_Exception::isDebug()) {
         $data = array('error' => array('code' => $exception->code, 'errorId' => $exception->getLogId(), 'message' => $exception->message, 'exception' => array(array('message' => $exception->message, 'class' => get_class($exception), 'trace' => $exception->getTrace()))));
     }
     return json_encode($data);
 }
예제 #8
0
 public static function handleError($errno, $errstr, $errfile, $errline)
 {
     if (error_reporting() == 0) {
         return;
     }
     // error unterdrückt mit @foo()
     if (!Kwf_Exception::isDebug() && defined('E_STRICT') && $errno == E_STRICT) {
         return;
     }
     //in non-debug mode ignore strict errors
     if (defined('E_DEPRECATED') && $errno == E_DEPRECATED) {
         if (substr($errstr, 0, 17) == 'Non-static method') {
             //ignore Non-static method called statically E_DEPRECATED errors for compatibility of older code with newer php versions
             return;
         } else {
             if (strpos($errfile, '/usr/share/php/') !== false) {
                 return;
             } else {
                 if (strpos($errstr, 'iconv_set_encoding') !== false) {
                     return;
                 }
             }
         }
     }
     //ignore notice from iconv like "Detected an incomplete multibyte character in input string"
     if ($errno == E_NOTICE && substr($errstr, 0, 15) == 'iconv_strlen():') {
         return;
     }
     throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
 }