public function log(Kwf_Exception_Abstract $exception, $type, $content) { $path = 'log/' . $type . '/' . date('Y-m-d'); $filename = date('H_i_s') . '_' . uniqid() . '.txt'; $exception->setLogId($type . ':' . $filename); if (!is_dir($path)) { @mkdir($path, 0777); } try { $fp = fopen("{$path}/{$filename}", 'a'); fwrite($fp, $content); fclose($fp); } catch (Exception $e) { $to = array(); if (Kwf_Registry::get('config')->developers) { foreach (Kwf_Registry::get('config')->developers as $dev) { if (isset($dev->sendException) && $dev->sendException) { $to[] = $dev->email; } } } if ($to) { mail(implode('; ', $to), 'Error while trying to write error file', $e->__toString() . "\n\n---------------------------\n\nOriginal Exception:\n\n" . $content); } } return true; }
public function testExceptions() { // Ohne Mail $exception = new Kwf_Exception(); $view = $this->_processException($exception); $this->assertEquals($view->message, $exception->getMessage()); $this->assertTrue($view->debug); $this->assertEquals($view->template, 'error.tpl'); // Mit Mail Kwf_Exception_Abstract::$logErrors = true; $exception = new Kwf_Exception(); $view = $this->_processException($exception); $this->assertEquals($view->message, $exception->getMessage()); $this->assertFalse($view->debug); $this->assertEquals($view->template, 'error.tpl'); // Nicht-Kwf_Exception mit Mail Kwf_Exception_Abstract::$logErrors = true; $e = new Zend_Exception(); $exception = new Kwf_Exception_Other($e); $view = $this->_processException($exception); $this->assertEquals($view->message, $e->getMessage()); $this->assertFalse($view->debug); $this->assertEquals($view->template, 'error.tpl'); Kwf_Exception_Abstract::$logErrors = null; // Kwf_Exception_NoLog mit Debug Kwf_Exception_Abstract::$logErrors = true; $exception = new Kwf_Exception_NoLog(); $view = $this->_processException($exception); $this->assertEquals($view->message, $exception->getMessage()); $this->assertFalse($view->debug); Kwf_Exception_Abstract::$logErrors = null; $this->assertEquals($view->template, 'error.tpl'); // Kwf_Exception_NoLog ohne Debug $exception = new Kwf_Exception_NoLog(); $view = $this->_processException($exception); $this->assertEquals($view->message, $exception->getMessage()); $this->assertTrue($view->debug); $this->assertEquals($view->template, 'error.tpl'); // Kwf_Exception_NotFound $exception = new Kwf_Exception_NotFound(); $view = $this->_processException($exception); $this->assertEquals($view->message, $exception->getMessage()); $this->assertEquals($view->template, 'error404.tpl'); // Nicht-Kwf_Exception $exception = new Exception(); $view = $this->_processException($exception); $this->assertEquals($view->message, $exception->getMessage()); $this->assertEquals($view->template, 'error.tpl'); // ClientException $exception = new Kwf_ClientException(); $view = $this->_processException($exception); $this->assertEquals($view->message, $exception->getMessage()); $this->assertEquals($view->template, 'error-client.tpl'); }
public function render($ignoreCli = false) { try { if (isset($_SERVER['REQUEST_URI']) && Kwf_Setup::hasDb() && Kwf_Registry::get('dao')->getDbConfig()) { $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; $target = Kwf_Model_Abstract::getInstance('Kwf_Util_Model_Redirects')->findRedirectUrl('path', $_SERVER['REQUEST_URI'], $host); if ($target) { header('Location: ' . $target, true, 301); exit; } } } catch (Exception $e) { Kwf_Debug::handleException($e); } parent::render($ignoreCli); }
public function preDispatch() { Kwf_Exception_Abstract::$logErrors = false; //don't call parent, no acl required if (!file_exists('build/assets')) { throw new Kwf_Exception_Client("Installation incomplete: 'build' folder does not exist. You can generate it by calling 'php bootstrap.php build' on commandline. On production servers you should upload locally generated build."); } if (file_exists('downloader.php')) { throw new Kwf_Exception_Client("downloader.php still exists, please delete before starting setup"); } if (file_exists('update')) { //for pre 3.3 webs, update file got replaced by kwf_update table throw new Kwf_Exception_Client("Application seems to be set up already. (update file exists)"); } if (file_exists('config.local.ini') && filesize('config.local.ini') > 0 && Kwf_Registry::get('config')->setupFinished) { if (strpos(file_get_contents('config.local.ini'), "\nsetupFinished = false\n") !== false) { throw new Kwf_Exception_Client("Application seems to be set up already. (config.local.ini file exists)"); } } $db = null; try { $db = Kwf_Registry::get('db'); } catch (Exception $e) { } if ($db) { try { $tables = Kwf_Registry::get('db')->fetchCol("SHOW TABLES"); } catch (Exception $e) { throw new Kwf_Exception_Client("Fetching Tables failed: " . $e->getMessage()); } if (in_array('kwf_update', $tables)) { throw new Kwf_Exception_Client("Application seems to be set up already. (kwf_update table exists)"); } if ($tables) { throw new Kwf_Exception_Client("Database not empty, kwf installation or other application already exists in this database."); } } }
public function __construct($message = "Access denied") { parent::__construct($message, 403); }
public function getPackageContents($mimeType, $language, $includeSourceMapComment = true) { if (!Kwf_Assets_BuildCache::getInstance()->building && !Kwf_Config::getValue('assets.lazyBuild')) { if (Kwf_Exception_Abstract::isDebug()) { //proper error message on development server throw new Kwf_Exception("Building assets is disabled (assets.lazyBuild). Please upload build contents."); } else { throw new Kwf_Exception_NotFound(); } } if (!isset($this->_packageContentsCache[$mimeType])) { $this->_packageContentsCache[$mimeType] = $this->_buildPackageContents($mimeType); } $packageMap = $this->_packageContentsCache[$mimeType]['contents']; $trlData = $this->_packageContentsCache[$mimeType]['trlData']; if (($mimeType == 'text/javascript' || $mimeType == 'text/javascript; defer') && $trlData) { $js = ""; $uniquePrefix = Kwf_Config::getValue('application.uniquePrefix'); if ($uniquePrefix) { $js = "if (typeof window.{$uniquePrefix} == 'undefined') window.{$uniquePrefix} = {};"; $uniquePrefix = "window.{$uniquePrefix}."; $js .= "if (!{$uniquePrefix}_kwfTrlData) {$uniquePrefix}_kwfTrlData={};"; } else { $js .= "if (!window._kwfTrlData) window._kwfTrlData={};"; } foreach ($trlData as $i) { $key = $i->type . '.' . $i->source; if (isset($i->context)) { $key .= '.' . $i->context; } $key .= '.' . str_replace("'", "\\'", $i->text); $method = $i->type; if ($i->source == 'kwf') { $method .= 'Kwf'; } if ($i->type == 'trl') { $trlText = Kwf_Trl::getInstance()->{$method}($i->text, array(), $language); $js .= "{$uniquePrefix}_kwfTrlData['{$key}']='" . str_replace("'", "\\'", $trlText) . "';"; } else { if ($i->type == 'trlc') { $trlText = Kwf_Trl::getInstance()->{$method}($i->context, $i->text, array(), $language); $js .= "{$uniquePrefix}_kwfTrlData['{$key}']='" . str_replace("'", "\\'", $trlText) . "';"; } else { if ($i->type == 'trlp') { $trlText = Kwf_Trl::getInstance()->getTrlpValues(null, $i->text, $i->plural, $i->source, $language); $js .= "{$uniquePrefix}_kwfTrlData['{$key}']='" . str_replace("'", "\\'", $trlText['single']) . "';"; $js .= "{$uniquePrefix}_kwfTrlData['{$key}.plural']='" . str_replace("'", "\\'", $trlText['plural']) . "';"; } else { if ($i->type == 'trlcp') { $trlText = Kwf_Trl::getInstance()->getTrlpValues($i->context, $i->text, $i->plural, $i->source, $language); $js .= "{$uniquePrefix}_kwfTrlData['{$key}']='" . str_replace("'", "\\'", $trlText['single']) . "';"; $js .= "{$uniquePrefix}_kwfTrlData['{$key}.plural']='" . str_replace("'", "\\'", $trlText['plural']) . "';"; } else { throw new Kwf_Exception("Unknown trl type"); } } } } } $map = Kwf_SourceMaps_SourceMap::createEmptyMap($js . "\n"); $map->concat($packageMap); $packageMap = $map; } if ($mimeType == 'text/javascript') { $ext = 'js'; } else { if ($mimeType == 'text/javascript; defer') { $ext = 'defer.js'; } else { if ($mimeType == 'text/css') { $ext = 'css'; } else { if ($mimeType == 'text/css; ie8') { $ext = 'ie8.css'; } else { throw new Kwf_Exception("Invalid mimeType: '{$mimeType}'"); } } } } $packageMap->setFile($this->getPackageUrl($ext, $language)); return $packageMap; }
public function __construct($message = "Unauthorized") { parent::__construct($message, 401); }
public function getPackageContents($mimeType, $language, $includeSourceMapComment = true) { if (!Kwf_Assets_BuildCache::getInstance()->building && !Kwf_Config::getValue('assets.lazyBuild')) { if (Kwf_Exception_Abstract::isDebug()) { //proper error message on development server throw new Kwf_Exception("Building assets is disabled (assets.lazyBuild). Please upload build contents."); } else { throw new Kwf_Exception_NotFound(); } } $packageMap = Kwf_SourceMaps_SourceMap::createEmptyMap(''); if ($mimeType == 'text/javascript') { $ext = 'js'; } else { if ($mimeType == 'text/javascript; defer') { $ext = 'defer.js'; } else { if ($mimeType == 'text/css') { $ext = 'css'; } else { if ($mimeType == 'text/css; media=print') { $ext = 'printcss'; } } } } $packageMap->setFile($this->getPackageUrl($ext, $language)); $maxMTime = 0; $commonJsData = array(); $commonJsDeps = array(); foreach ($this->_getFilteredUniqueDependencies($mimeType) as $i) { if ($i->getIncludeInPackage()) { if (($mimeType == 'text/javascript' || $mimeType == 'text/javascript') && $i->isCommonJsEntry()) { $c = $i->getContentsPacked($language)->getFileContentsInlineMap(false); $commonJsDeps = $this->_getCommonJsDeps($i, $language); $commonJsData[$i->__toString()] = array('id' => $i->__toString(), 'source' => $c, 'sourceFile' => $i->__toString(), 'deps' => $commonJsDeps['deps'], 'entry' => true); foreach ($commonJsDeps['data'] as $k => $j) { if (!isset($commonJsData[$k])) { $commonJsData[$k] = $j; } } } else { $map = $i->getContentsPacked($language); if (strpos($map->getFileContents(), "//@ sourceMappingURL=") !== false && strpos($map->getFileContents(), "//# sourceMappingURL=") !== false) { throw new Kwf_Exception("contents must not contain sourceMappingURL"); } foreach ($map->getMapContentsData(false)->sources as &$s) { $s = '/assets/' . $s; } // $ret .= "/* *** $i */\n"; // attention: commenting this in breaks source maps $packageMap->concat($map); } } $mTime = $i->getMTime(); if ($mTime) { $maxMTime = max($maxMTime, $mTime); } } if ($commonJsData) { if ($mimeType == 'text/javascript; defer') { //in defer.js don't include deps that are already loaded in non-defer foreach ($this->_getFilteredUniqueDependencies('text/javascript') as $i) { $commonJsDeps = $this->_getCommonJsDeps($i, $language); foreach (array_keys($commonJsDeps['data']) as $key) { if (isset($commonJsData[$key])) { unset($commonJsData[$key]); } } $c = $i->getContentsPacked($language)->getFileContentsInlineMap(false); $commonJsData[$i->__toString()] = array('id' => $i->__toString(), 'source' => $c, 'sourceFile' => $i->__toString(), 'deps' => $commonJsDeps['deps'], 'entry' => true); } } $contents = 'window.require = ' . Kwf_Assets_CommonJs_BrowserPack::pack(array_values($commonJsData)); $map = Kwf_SourceMaps_SourceMap::createFromInline($contents); $packageMap->concat($map); } if ($mimeType == 'text/javascript' || $mimeType == 'text/javascript; defer') { if ($uniquePrefix = Kwf_Config::getValue('application.uniquePrefix')) { $packageMap = Kwf_Assets_Package_Filter_UniquePrefix::filter($packageMap, $uniquePrefix); } } if ($includeSourceMapComment) { $contents = $packageMap->getFileContents(); if ($mimeType == 'text/javascript') { $ext = 'js'; } else { if ($mimeType == 'text/javascript; defer') { $ext = 'defer.js'; } else { if ($mimeType == 'text/css') { $ext = 'css'; } else { if ($mimeType == 'text/css; media=print') { $ext = 'printcss'; } else { throw new Kwf_Exception_NotYetImplemented(); } } } } if ($ext == 'js' || $ext == 'defer.js') { $contents .= "\n//# sourceMappingURL=" . $this->getPackageUrl($ext . '.map', $language) . "\n"; } else { if ($ext == 'css' || $ext == 'printcss') { $contents .= "\n/*# sourceMappingURL=" . $this->getPackageUrl($ext . '.map', $language) . " */\n"; } } $packageMap->setFileContents($contents); } return $packageMap; }
public static function process($logModel = 'Kwf_Util_Wirecard_LogModel', $secret = null) { Kwf_Exception_Abstract::$logErrors = true; //activate log always, because request comes from wirecard ignore_user_abort(true); if (!$secret) { $secret = Kwf_Registry::get('config')->wirecard->secret; } $paymentState = isset($_POST["paymentState"]) ? $_POST["paymentState"] : ""; if (strcmp($paymentState, "CANCEL") == 0) { /// the transaction was cancelled. $message = "Transaktion wurde abgebrochen."; } else { if (strcmp($paymentState, "FAILURE") == 0) { // there was something wrong with the initiation or an fatal error during the transaction processing occured $message = $_POST["message"]; $e = new Kwf_Exception('Wirecard Transaction Failed: ' . $message); $e->log(); $message = "Fehler bei der Initiierung: " . $message; } else { if (strcmp($paymentState, "SUCCESS") == 0) { $responseFingerprintOrder = $_POST["responseFingerprintOrder"]; $responseFingerprint = $_POST["responseFingerprint"]; $str4responseFingerprint = ""; $mandatoryFingerPrintFields = 0; $secretUsed = 0; $order = explode(",", $responseFingerprintOrder); for ($i = 0; $i < count($order); $i++) { $key = $order[$i]; // check if there are enough fields in den responsefingerprint if (strcmp($key, "paymentState") == 0 && strlen($_POST[$order[$i]]) > 0) { $mandatoryFingerPrintFields++; } if (strcmp($key, "orderNumber") == 0 && strlen($_POST[$order[$i]]) > 0) { $mandatoryFingerPrintFields++; } if (strcmp($key, "paymentType") == 0 && strlen($_POST[$order[$i]]) > 0) { $mandatoryFingerPrintFields++; } if (strcmp($key, "secret") == 0) { $str4responseFingerprint .= $secret; $secretUsed = 1; } else { $str4responseFingerprint .= $_POST[$order[$i]]; } } // recalc the fingerprint $responseFingerprintCalc = md5($str4responseFingerprint); if (strcmp($responseFingerprintCalc, $responseFingerprint) == 0 && $mandatoryFingerPrintFields == 3 && $secretUsed == 1) { // everything is ok. store the successfull payment somewhere // please store at least the paymentType and the orderNumber additional to the orderinformation, // otherwise you will never find the transaction again. $m = Kwf_Model_Abstract::getInstance($logModel); $row = $m->createRow(); foreach ($order as $i) { if ($i != 'secret') { $row->{$i} = $_POST[$i]; } } $row->custom = $_POST['custom']; $row->save(); // e.g. something like // checkBasketIntegrety($amount, $currency, $basketId); // storeAndCloseBasket($paymentType, $orderNumber, $basketId); $message = "Vielen Dank für Ihre Bestellung."; } else { // there is something strange. maybe an unauthorized call of this page or a wrong secret $e = new Kwf_Exception('Wirecard Transaction Failed: Can\'t verify'); $e->log(); } } else { // unauthorized call of this page $e = new Kwf_Exception('Wirecard Transaction Failed: Invalid Payment Status: ' . $paymentState); $e->log(); } } } echo 'Pfeift'; exit; }