protected function _getDownloadUrl() { $downloadTagVars = $this->_component->getData()->getChildComponent('-downloadTag')->getComponent()->getTemplateVars(); $domain = $this->_component->getData()->getDomain(); $protocol = Kwf_Util_Https::domainSupportsHttps($domain) ? 'https' : 'http'; return $protocol . '://' . $domain . $downloadTagVars['url']; }
public function preDispatch() { Kwf_Util_Https::ensureHttps(); if ($this->_getParam('applicationAssetsVersion') && $this->getHelper('ViewRenderer')->isJson()) { if (Kwf_Assets_Dispatcher::getAssetsVersion() != $this->_getParam('applicationAssetsVersion')) { $this->_forward('json-wrong-version', 'error', 'kwf_controller_action_error'); return; } } $this->_validateSessionToken(); $t = microtime(true); $allowed = $this->_isAllowedResource(); if ($allowed) { $allowed = $this->_isAllowed($this->_getAuthData()); } if (!$allowed) { $params = array('role' => $this->_getUserRole()); if ($this->getHelper('ViewRenderer')->isJson()) { $this->_forward('json-login', 'login', 'kwf_controller_action_user', $params); } else { $params = array('location' => $this->getRequest()->getBaseUrl() . '/' . ltrim($this->getRequest()->getPathInfo(), '/')); $this->_forward('index', 'login', 'kwf_controller_action_user', $params); } } Kwf_Benchmark::subCheckpoint('check acl', microtime(true) - $t); }
public static function afterStart() { static $validatorsRegistered = false; if (!$validatorsRegistered) { Kwf_Util_Https::ensureHttps(); if (isset($_SESSION['__KWF']['VALID'])) { self::_processValidators(); } //sessions timeout after 15-20 minutes of inactivity //this is in addition to gc_maxlifetime (which isn't reliable enough) $sessionTimeout = 20 * 60; if (!isset($_SESSION['kwfTimeout'])) { $_SESSION['kwfTimeout'] = time() + $sessionTimeout; } else { if ($_SESSION['kwfTimeout'] - time() < 0) { $_SESSION = array(); $_SESSION['kwfTimeout'] = time() + $sessionTimeout; Zend_Session::regenerateId(); } else { if ($_SESSION['kwfTimeout'] - time() < $sessionTimeout - 5 * 60) { //extend timeout every 5 minutes (not in every request for better performance) $_SESSION['kwfTimeout'] = time() + $sessionTimeout; } } } if (!isset($_SESSION['__KWF']['VALID'])) { Zend_Session::registerValidator(new Kwf_Session_Validator_HttpHost()); if (Kwf_Setup::getBaseUrl()) { Zend_Session::registerValidator(new Kwf_Session_Validator_BasePath()); } Zend_Session::registerValidator(new Kwf_Session_Validator_RemoteAddr()); } $validatorsRegistered = true; } }
public function indexAction() { $this->view->config = array('responsive' => Kwf_Config::getValue('kwc.responsive')); $this->view->xtype = 'kwf.component.preview'; $this->view->initialUrl = null; if (preg_match('#^https?://#', $this->_getParam('url'))) { $this->view->initialUrl = $this->_getParam('url'); } if (!$this->view->initialUrl) { $https = Kwf_Util_Https::domainSupportsHttps($_SERVER['HTTP_HOST']); $protocol = $https ? 'https://' : 'http://'; $this->view->initialUrl = $protocol . $_SERVER['HTTP_HOST'] . Kwf_Setup::getBaseUrl() . '/'; } }
/** * Create a .txt.tpl or .html.tpl file and set $template to the path. * @param string|Kwc_Abstract|Kwf_Component_Data $template: If it's a * string it should point to the template in /views/mails. It's * also possible to use a 'Kwc_Abstract' or 'Kwf_Component_Data' * (This is used when the template destination is in this component-folder). * There are no absolute paths allowed. * @param string $masterTemplate */ public function __construct($template, $masterTemplate = 'Master') { parent::__construct(); if (is_object($template) || in_array($template, Kwc_Abstract::getComponentClasses())) { if (is_object($template)) { if ($template instanceof Kwc_Abstract) { $template = $template->getData(); } if (!$template instanceof Kwf_Component_Data) { throw new Kwf_Exception("template must be instance of 'Kwc_Abstract' or 'Kwf_Component_Data'"); } $template = $template->componentClass; } $this->_txtTemplate = Kwc_Admin::getComponentFile($template, 'Component', 'txt.tpl'); if (!$this->_txtTemplate) { throw new Kwf_Exception("Component class '{$template}' needs at least a .txt.tpl mail template."); } $this->_htmlTemplate = Kwc_Admin::getComponentFile($template, 'Component', 'html.tpl'); } else { if (substr($template, 0, 1) == '/') { throw new Kwf_Exception("Absolute mail template paths are not allowed. You called '{$template}'."); } if (false === $this->getScriptPath("{$template}.txt.tpl")) { $template = "mails/{$template}"; if (false === $this->getScriptPath("{$template}.txt.tpl")) { throw new Kwf_Exception("There has to exist at least a .txt.tpl mail template for '{$template}'."); } } $this->_txtTemplate = "{$template}.txt.tpl"; if (false !== $this->getScriptPath("{$template}.html.tpl")) { $this->_htmlTemplate = "{$template}.html.tpl"; } } $this->_mailTplViewMasterTemplate = $masterTemplate; if (isset($_SERVER['HTTP_HOST'])) { $host = $_SERVER['HTTP_HOST']; } else { $host = Kwf_Registry::get('config')->server->domain; } $this->webUrl = (Kwf_Util_Https::supportsHttps() ? 'https' : 'http') . '://' . $host; $this->host = $host; $this->applicationName = Kwf_Registry::get('config')->application->name; }
public function sendContent($includeMaster) { $benchmarkEnabled = Kwf_Benchmark::isEnabled(); if (Kwf_Util_Https::supportsHttps()) { $foundRequestHttps = Kwf_Util_Https::doesComponentRequestHttps($this->_data); if (isset($_SERVER['HTTPS'])) { //we are on https if (!$foundRequestHttps && isset($_COOKIE['kwcAutoHttps']) && !Zend_Session::sessionExists() && !Zend_Session::isStarted()) { //we where auto-redirected to https but don't need https anymore setcookie('kwcAutoHttps', '', 0, '/'); //delete cookie Kwf_Util_Https::ensureHttp(); } } else { //we are on http if ($foundRequestHttps) { setcookie('kwcAutoHttps', '1', 0, '/'); Kwf_Util_Https::ensureHttps(); } } if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('check requestHttps'); } } if ($benchmarkEnabled) { $startTime = microtime(true); } $process = $this->_getProcessInputComponents($includeMaster); if ($benchmarkEnabled) { Kwf_Benchmark::subCheckpoint('getProcessInputComponents', microtime(true) - $startTime); } self::_callProcessInput($process); if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('processInput'); } $hasDynamicParts = false; $out = $this->_render($includeMaster, $hasDynamicParts); if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('render'); } header('Content-Type: text/html; charset=utf-8'); if (!$hasDynamicParts) { $lifetime = 60 * 60; header('Cache-Control: public, max-age=' . $lifetime); header('Expires: ' . gmdate("D, d M Y H:i:s \\G\\M\\T", time() + $lifetime)); header('Pragma: public'); } echo $out; self::_callPostProcessInput($process); if ($benchmarkEnabled) { Kwf_Benchmark::checkpoint('postProcessInput'); } }
public static function setCookies($authedUser) { $cookieValue = $authedUser->id . '.' . $authedUser->generateAutoLoginToken(); setcookie('feAutologin', $cookieValue, time() + 100 * 24 * 60 * 60, '/', null, Kwf_Util_Https::supportsHttps(), true); setcookie('hasFeAutologin', '1', time() + 100 * 24 * 60 * 60, '/', null, false, true); }
public static function callUtil($method, $params, $options = array()) { $outputType = ''; if (isset($params['type']) && $params['type'] == 'user') { $outputType = 'apc user'; } else { if (isset($params['type']) && $params['type'] == 'file') { $outputType = 'optcode'; } } $params['password'] = self::_getHttpPassword(); $config = Kwf_Registry::get('config'); $d = $config->server->domain; if (!$d) { if (isset($options['outputFn'])) { call_user_func($options['outputFn'], "error: {$outputType}: domain not set"); } return false; } $domains = array(array('domain' => $d)); if ($config->server->preliminaryDomain) { $domains[0]['alternative'] = $config->server->preliminaryDomain; } if (!isset($domains[0]['alternative']) && $config->server->noRedirectPattern) { $domains[0]['alternative'] = str_replace(array('^', '\\', '$'), '', $config->server->noRedirectPattern); } foreach ($domains as $d) { $s = microtime(true); if (Kwf_Util_Https::domainSupportsHttps($d['domain'])) { $urlPart = "https://"; } else { $urlPart = "http://"; } $baseUrl = Kwf_Setup::getBaseUrl(); $url = "{$urlPart}{$d['domain']}{$baseUrl}/kwf/util/apc/{$method}"; $config = array('timeout' => 60, 'keepalive' => true); if (extension_loaded('curl')) { $config['adapter'] = 'Zend_Http_Client_Adapter_Curl'; $config['curloptions'] = array(CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false); } $client = new Zend_Http_Client($url, $config); $client->setMethod(Zend_Http_Client::POST); $client->setParameterPost($params); $client->setConfig(array('timeout' => 60, 'keepalive' => true)); $body = null; $outputMessage = 'could not reach web per http'; try { $response = $client->request(); $result = !$response->isError() && substr($response->getBody(), 0, 2) == 'OK'; $body = $response->getBody(); $outputMessage = $body; } catch (Exception $e) { $result = false; } $url2 = null; if (!$result && isset($d['alternative'])) { $url2 = "{$urlPart}{$d['alternative']}{$baseUrl}/kwf/util/apc/{$method}"; $client = new Zend_Http_Client($url2, $config); $client->setMethod(Zend_Http_Client::POST); $client->setParameterPost($params); try { $response = $client->request(); $result = !$response->isError() && substr($response->getBody(), 0, 2) == 'OK'; $body = $response->getBody(); $outputMessage = $body; } catch (Exception $e) { $result = false; } } if (isset($options['outputFn'])) { $outputUrl = $url; if ($url2) { $outputUrl .= " / {$url2}"; } $time = round((microtime(true) - $s) * 1000); if ($result) { call_user_func($options['outputFn'], "{$outputUrl} ({$time}ms) {$outputMessage} "); } else { call_user_func($options['outputFn'], "error: {$outputType} {$outputUrl} {$outputMessage}\n\n"); } } } if (isset($options['returnBody']) && $options['returnBody']) { return $body; } else { return $result; } }
private function _getAbsoluteUrl($url) { if ($url && substr($url, 0, 1) == '/' && substr($url, 0, 2) != '//') { //can already be absolute, due to Event_CreateMediaUrl (eg. varnish cache) $domain = $this->getData()->getDomain(); $protocol = Kwf_Util_Https::domainSupportsHttps($domain) ? 'https' : 'http'; $url = "{$protocol}://{$domain}{$url}"; } return $url; }
/** * Returns absolute url including domain and protocol (http://) * * @return string */ public function getAbsoluteUrl() { $https = Kwf_Util_Https::domainSupportsHttps($this->getDomain()); $protocol = $https ? 'https' : 'http'; return $protocol . '://' . $this->getDomain() . $this->url; }
/** * Gibt den personalisierten HTML-Quelltext der Mail zurück */ public function getHtml(Kwc_Mail_Recipient_Interface $recipient = null, $addViewTracker = false) { $renderer = new Kwf_Component_Renderer_Mail(); $renderer->setRenderFormat(Kwf_Component_Renderer_Mail::RENDER_HTML); $renderer->setRecipient($recipient); $renderer->setHtmlStyles($this->getHtmlStyles()); $ret = $renderer->renderComponent($this->getData()); Kwf_Benchmark::checkpoint('html: render'); $ret = $this->_processPlaceholder($ret, $recipient); Kwf_Benchmark::checkpoint('html: placeholder'); $redirectComponent = $this->getData()->getChildComponent('_redirect'); if ($redirectComponent) { $redirectComponent = $redirectComponent->getComponent(); $ret = $redirectComponent->replaceLinks($ret, $recipient); } Kwf_Benchmark::checkpoint('html: replaceLinks'); if ($addViewTracker && $this->_getSetting('trackViews')) { $params = array(); if ($recipient->id) { $params['recipientId'] = urlencode($recipient->id); } if ($shortcut = $redirectComponent->getRecipientModelShortcut(get_class($recipient->getModel()))) { $params['recipientModelShortcut'] = urlencode($shortcut); } $https = Kwf_Util_Https::domainSupportsHttps($this->getData()->getDomain()); $protocol = $https ? 'https' : 'http'; $imgUrl = $protocol . '://' . $this->getData()->getDomain() . Kwf_Media::getUrl($this->getData()->componentClass, $this->getData()->componentId, 'views', 'blank.gif'); $imgUrl .= '?' . http_build_query($params); $ret .= '<img src="' . $imgUrl . '" width="1" height="1" />'; Kwf_Benchmark::checkpoint('html: view tracker'); } $ret = ltrim($this->_getSetting('docType') . "\n" . $ret); return $ret; }
public function getUserLoginUrl($row) { if (isset($_SERVER['HTTP_HOST'])) { $host = $_SERVER['HTTP_HOST']; } else { $host = Kwf_Registry::get('config')->server->domain; } $url = Kwf_Controller_Front_Component::getInstance()->getWebRouter()->getRoute('admin')->assemble(array('module' => 'index', 'controller' => 'index', 'action' => 'index')); $ret = (Kwf_Util_Https::domainSupportsHttps($host) ? 'https' : 'http') . '://' . $host . '/' . $url; $root = Kwf_Component_Data_Root::getInstance(); if ($root && $this->_allowFrontendUrls($row)) { $component = $root->getComponentByClass('Kwc_User_Login_Component', array('limit' => 1)); if ($component) { $ret = $component->getAbsoluteUrl(true); } } return $ret; }
/** * Returns preview url * * @return string */ public function getPreviewUrl() { if ($domain = $this->getBaseProperty('preliminaryDomain')) { $https = Kwf_Util_Https::domainSupportsHttps($domain); $protocol = $https ? 'https' : 'http'; $url = $protocol . '://' . $domain . $this->url; } else { $url = $this->getAbsoluteUrl(); } return Kwf_Setup::getBaseUrl() . '/admin/component/preview/?url=' . urlencode($url . '?kwcPreview'); }
/** * Returns absolute url including domain and protocol (http://) * * @return string */ public function getAbsoluteUrl($useHttps = false) { $https = Kwf_Util_Https::domainSupportsHttps($this->getDomain()); if ($https && !$useHttps) { //if component requests https use it even if $useHttps is false $https = Kwf_Util_Https::doesComponentRequestHttps($this); } $protocol = $https ? 'https' : 'http'; return $protocol . '://' . $this->getDomain() . $this->url; }