/** * @see \Ableron\Core\Controller\AbstractController::init() */ protected function init() { parent::init(); // by default authentication is required for controllers of the backend $this->setAuthenticationRequired(true); // set login URL $this->setAuthenticationLoginUrl(EnvironmentUtil::getInternalUrl('/login')); // set permissions required by default for backend controllers $this->getRequiredPermissions()->add('Core.System.Backend.canAccessBackend'); // indicate backend responses to not be cachable Application::getResponseHandler()->getResponse()->setCachable(false); }
/** * Returns the name of the web server. * * Returns 'n/a' in case the web server could not be determined. * * @return string */ public static function getWebServer() { // get server information as array $serverSoftware = StringUtil::split('/', strip_tags(EnvironmentUtil::getEnvironmentVariable('SERVER_SOFTWARE')), 2); // check for web server name if (isset($serverSoftware[0])) { // try to get web server version if (isset($serverSoftware[1])) { // get web server version $webServerVersion = StringUtil::split(' ', $serverSoftware[1], 2)[0]; // append web server version to web server name if ($webServerVersion !== '') { return $serverSoftware[0] . ' ' . $webServerVersion; } } // return web server return $serverSoftware[0]; } // unable to determine web server return 'n/a'; }
/** * @see \Ableron\Core\Controller\AbstractController::run() */ protected function run() { // check for valid CSRF token before executing action if ($this->checkCsrfToken()) { try { $this->readParameters(); $this->readData(); $this->execute(); $this->onExecuteSuccessful(); } catch (ExecutionFailedException $e) { $this->onExecuteFailed(); } } else { $this->setFlashMessage(Application::getI18nHandler()->getTranslator()->translate('core.security.csrf.actionNotExecuted'), null, ControllerInterface::MESSAGE_TYPE_ERROR); } // if we are here, no redirect has been sent during execution; so redirect to action source URL if (($encodedActionSourceUrl = $this->getQueryParameter(ABLERON_PARAM_ACTION_SOURCE_URL, false)) !== false && ($actionSourceUrl = StringUtil::base64UrlDecode($encodedActionSourceUrl)) !== false) { $this->redirectTo(new Uri($actionSourceUrl)); } else { $this->redirectTo(EnvironmentUtil::getInternalUrl('/')); } }
/** * @see \Ableron\Core\Template\Plugins\Interfaces\CompilerPluginInterface::compileOpeningTag() */ public function compileOpeningTag(TemplateCompiler $templateCompiler) { return sprintf('%s/%s', EnvironmentUtil::getAssetBaseUrl()->toString(), ltrim($this->getArgument('url'), '/')); }
/** * @see \Ableron\Core\Session\Validators\ValidatorInterface::setValidationData() */ public function setValidationData(SessionEntity $session) { $session->setData('sessionValidation.lastAccessUserAgent', EnvironmentUtil::getEnvironmentVariable('HTTP_USER_AGENT')); }
/** * @see \Ableron\Core\Controller\Action\ActionInterface::onExecuteSuccessful() */ public function onExecuteSuccessful() { Application::getResponseHandler()->sendRedirect(EnvironmentUtil::getInternalUrl('/')); }
/** * Sends cookies. * * @return void */ private function sendCookies() { if (!$this->getResponse()->getCookies()->isEmpty()) { // get default path $defaultPath = EnvironmentUtil::getSitePath(); // get default domain (prepend dot (.) to make cookie available at sub-domains) $defaultDomain = sprintf('.%s', EnvironmentUtil::getSiteUrl()->getHost()); // set all the cookies /** @var \Ableron\Lib\Http\HttpCookie $cookie */ foreach ($this->getResponse()->getCookies() as $cookie) { // make sure cookie path is at least the site path if ($cookie->getPath() === '/') { $cookie->setPath($defaultPath); } // make sure domain is set (do not set localhost as domain as this causes cookies not to be set in Opera/Chrome/IE) if ($cookie->getDomain() === '' && $defaultDomain !== '.localhost') { $cookie->setDomain($defaultDomain); } // set cookie setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpirationTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); } } }
/** * Adjusts the apache configuration file (.htaccess). * * @return void */ private function adjustApacheConfigurationFile() { // set htaccess.txt path $htaccessFile = ABLERON_ROOT_DIR . '/htaccess.txt'; // set rewrite base file_put_contents($htaccessFile, str_replace('{{rewriteBase}}', EnvironmentUtil::getSitePath(), file_get_contents($htaccessFile))); // rename htaccess.txt to .htaccess rename($htaccessFile, ABLERON_ROOT_DIR . '/.htaccess'); }
/** * @see \Ableron\Core\Session\Validators\ValidatorInterface::setValidationData() */ public function setValidationData(SessionEntity $session) { $session->setData('sessionValidation.lastAccessIpAddress', EnvironmentUtil::getEnvironmentVariable('REMOTE_ADDR')); }
/** * Returns the request URI. * * @return \Ableron\Lib\Net\Uri */ private function getRequestUri() { return (new Uri(sprintf('%s://%s/%s', EnvironmentUtil::getRequestProtocol(), EnvironmentUtil::getEnvironmentVariable('HTTP_HOST', ''), isset($_SERVER['REQUEST_URI']) ? ltrim($_SERVER['REQUEST_URI'], '/') : ltrim(EnvironmentUtil::getScriptName(), '/') . (($queryString = EnvironmentUtil::getEnvironmentVariable('QUERY_STRING')) !== null ? '?' . $queryString : ''))))->normalize(); }
/** * Redirects the user to the index page. * * @see \Ableron\Core\Controller\Page\AbstractPage::onProcessFormSuccessful() */ public function onProcessFormSuccessful() { parent::onProcessFormSuccessful(); // fire event: login attempt succeeded Application::getEventManager()->fireEvent(new LoginAttemptSuccessfulEvent($this->username, $this->password)); // redirect to index page $this->redirectTo(EnvironmentUtil::getInternalUrl('/')); }
/** * Returns the request handler. * * @return \Ableron\Core\Request\WebRequestHandler */ public static final function getRequestHandler() { if (self::$requestHandler === null) { self::$requestHandler = EnvironmentUtil::isCliRequest() ? new DummyWebRequestHandler() : new WebRequestHandler(); } return self::$requestHandler; }