/**
  * Initializes this exception.
  *
  * @param array $fieldNames Names of the form fields which caused the exception
  * @param string $messageKey Message key of the error message to display
  * @param array $messageParameters List of parameters used in the error message
  */
 public function __construct(array $fieldNames, string $messageKey, array $messageParameters = array())
 {
     // init exception and set message
     parent::__construct(Application::getI18nHandler()->getTranslator()->translate($messageKey, $messageParameters));
     // set field names
     $this->fieldNames = $fieldNames;
 }
Example #2
0
 /**
  * Initializes the form.
  *
  * By default the action URL of the form is the current request URL, the form
  * method is POST and CSRF protection will be enabled.
  *
  * @param string $actionUrl Action URL the form will be sent to
  * @param string $method Method of the form
  * @param bool $csrfProtectionEnabled Whether to enable CSRF protection for the form
  */
 public function __construct($actionUrl = null, $method = HttpRequest::METHOD_POST, $csrfProtectionEnabled = true)
 {
     $this->attributes = new OrderedMap();
     $this->setAction($actionUrl === null ? Application::getRequestHandler()->getRequest()->getUri()->toString() : $actionUrl);
     $this->setMethod($method);
     $this->setCsrfProtectionEnabled($csrfProtectionEnabled);
 }
 /**
  * @see \Ableron\Core\Session\SessionHandlerInterface::runGarbageCollector()
  */
 public function runGarbageCollector(DateInterval $inactivityTimeout)
 {
     //TODO tblasche: Implement correctly und use it
     $query = Application::getPersistenceManager()->getEntityManager()->createQuery('DELETE Core:SessionEntity s WHERE s.lastActivityTime < ?1');
     $query->setParameter(1, DateUtil::getCurrentUtcDateTime()->sub($inactivityTimeout)->format('Y-m-d H:i:s'));
     $query->execute();
 }
Example #4
0
 /**
  * Performs the bootstrapping.
  */
 public function __construct()
 {
     // define root directories
     define('ABLERON_ROOT_DIR', str_replace('//', '/', str_replace('\\', '/', dirname(__DIR__) . '/src')));
     define('ABLERON_APP_DIR', ABLERON_ROOT_DIR . '/app');
     define('ABLERON_CONFIG_DIR', ABLERON_ROOT_DIR . '/config');
     define('ABLERON_VENDOR_DIR', ABLERON_ROOT_DIR . '/vendor');
     define('ABLERON_TESTS_DIR', str_replace('//', '/', str_replace('\\', '/', __DIR__)));
     define('ABLERON_INSTALL_DIR', ABLERON_ROOT_DIR . '/install');
     // init composer class loader
     /** @var \Composer\Autoload\ClassLoader $classLoader */
     $classLoader = (require ABLERON_VENDOR_DIR . '/autoload.php');
     $classLoader->addPsr4('Ableron\\', ABLERON_TESTS_DIR . '/unittests/');
     $classLoader->addPsr4('Ableron\\Tests\\Helper\\', ABLERON_TESTS_DIR . '/helper/');
     // install system if necessary
     if (file_exists(ABLERON_INSTALL_DIR . '/app/Installer.php')) {
         // load Installer
         require ABLERON_INSTALL_DIR . '/app/Installer.php';
         // execute installer
         new Installer(include ABLERON_INSTALL_DIR . '/config/automaticInstallation.config.php');
     } else {
         // init Ableron
         Application::init($classLoader, include ABLERON_CONFIG_DIR . '/context.php');
     }
 }
 /**
  * @see \Ableron\Core\Template\Plugins\Interfaces\CompilerPluginInterface::compileOpeningTag()
  */
 public function compileOpeningTag(TemplateCompiler $templateCompiler)
 {
     // get translation
     $translation = Application::getI18nHandler()->getTranslator()->translate($this->getArgument('key'));
     // return translation
     return $this->getArgument('htmlEncode') ? StringUtil::encodeHtml($translation) : $translation;
 }
 /**
  * Installs the given extension.
  *
  * This operation is transaction save. The extension is either installed
  * completely or not at all.
  *
  * Throws an exception in case the extension could not be installed.
  *
  * @param \Ableron\Core\Extension\ExtensionInterface $extension The extension to install
  * @param string $extensionDirectory Directory of the extension
  * @throws \Ableron\Core\Exception\SystemException
  * @return void
  */
 protected function installExtension(ExtensionInterface $extension, $extensionDirectory)
 {
     // get entity manager
     $entityManager = Application::getPersistenceManager()->getEntityManager();
     try {
         // begin transaction
         $entityManager->beginTransaction();
         // set up database schema (generate proxies + database schema)
         $this->setUpDatabaseSchema($extension::getNamespace(), sprintf('%s/Model/Entities', $extensionDirectory), $entityManager);
         // write initial database entities to database
         foreach ($extension->getInitialDatabaseEntities() as $entity) {
             $entityManager->persist($entity);
         }
         // flush entity manager and commit transaction
         $entityManager->flush();
         $entityManager->commit();
     } catch (Exception $e) {
         // rollback transaction
         $entityManager->rollback();
         // throw exception
         throw new SystemException(sprintf('Unable to install extension "%s"', $extension::getNamespace()), 0, E_USER_WARNING, __FILE__, __LINE__, $e);
     }
     // close global entity manager because of possible schema changes (necessary to prevent problems)
     Application::getPersistenceManager()->closeEntityManager();
 }
 /**
  * Checks whether the maximum inactivity time has been exceeded.
  *
  * Returns TRUE in case the maximum inactivity time has not been exceeded.
  * Otherwise returns FALSE.
  *
  * @see \Ableron\Core\Session\Validators\ValidatorInterface::isValid()
  */
 public function isValid(SessionEntity $session)
 {
     // get setting key for the timeout to use
     $settingKeySessionInactivityTimeout = Application::getRequestHandler()->isFrontendRequest() ? 'session.frontend.inactivityTimeoutValidator.timeout' : 'session.backend.inactivityTimeoutValidator.timeout';
     // return whether session has timed out
     return $session->getLastActivityTime() > DateUtil::getCurrentUtcDateTime()->sub(Application::getConfig()->get($settingKeySessionInactivityTimeout));
 }
 /**
  * Returns whether the content of the given internet media type is binary.
  *
  * Returns TRUE in case the content of the given internet media type is
  * binary or the given internet media type is not known by this library.
  * Otherwise returns FALSE.
  *
  * @param \Ableron\Lib\Net\InternetMediaType $internetMediaType The internet media type to check
  * @return bool
  */
 public static function hasBinaryContent(InternetMediaType $internetMediaType)
 {
     if (!self::isKnown($internetMediaType)) {
         Application::getLogManager()->warning(sprintf('Unable to check whether internet media type "%s" has binary content: Unknown internet media type', $internetMediaType->getBaseType()));
         return true;
     }
     return self::$internetMediaTypes[$internetMediaType->getPrimaryType()][$internetMediaType->getSubType()]['isBinary'];
 }
 /**
  * @see \Ableron\Core\Controller\AbstractController::init()
  */
 protected function init()
 {
     parent::init();
     // set template
     $this->setTemplateFile('/Core/Pages/Frontend/Templates/ResourceNotFoundPage.tpl');
     // set HTTP response status code
     Application::getResponseHandler()->getResponse()->setStatusCode(404);
 }
 /**
  * Returns the value of the context setting with the given name.
  *
  * Returns NULL in case the requested setting does not exist.
  *
  * @param string $settingName Name of the setting to return the value of
  * @return mixed
  */
 public function getSetting(string $settingName)
 {
     if (!array_key_exists($settingName, $this->contextSettings)) {
         Application::getLogManager()->warning(sprintf('Unable to read context setting "%s": Setting does not exist!', $settingName));
         return null;
     }
     return $this->contextSettings[$settingName];
 }
Example #11
0
 /**
  * @see \Ableron\Core\Controller\AbstractController::init()
  */
 protected function init()
 {
     parent::init();
     // set template
     $this->setTemplateFile('/Core/Pages/Backend/Templates/AccessDeniedPage.tpl');
     // set HTTP response status code
     Application::getResponseHandler()->getResponse()->setStatusCode(403);
 }
 /**
  * @see \Ableron\Lib\Event\EventHandlerInterface::handle()
  */
 public function handle(EventInterface $event)
 {
     // clear failed login attempts
     /** @var \Ableron\Modules\Core\Events\LoginAttemptSuccessfulEvent $event */
     if (($loginAttemptsEntity = BruteForceProtectionService::getLoginAttemptsByUsername($event->getUsername())) !== null) {
         Application::getPersistenceManager()->getEntityManager()->remove($loginAttemptsEntity);
     }
 }
Example #13
0
 /**
  * @see \Ableron\Core\Extension\ExtensionInterface::getInitialDatabaseEntities()
  */
 public function getInitialDatabaseEntities()
 {
     $initialDatabaseEntities = array();
     // get relevant locales
     $localeDeDe = Application::getPersistenceManager()->getRepository('LocaleEntity')->findOneBy(array('localeCode' => 'de-DE'));
     $localeEnUs = Application::getPersistenceManager()->getRepository('LocaleEntity')->findOneBy(array('localeCode' => 'en-US'));
     // add messages
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.navTitle', 'System Informationen');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.navTitle', 'System Information');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.systemInfo.title', 'System');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.systemInfo.title', 'System');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.systemInfo.category.ableronCore', 'Ableron Core');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.systemInfo.category.ableronCore', 'Ableron Core');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.systemInfo.category.database', 'Datenbank');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.systemInfo.category.database', 'Database');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.systemInfo.category.php', 'PHP');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.systemInfo.category.php', 'PHP');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.systemInfo.category.server', 'Server');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.systemInfo.category.server', 'Server');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.systemInfo.label.ableronCore.version', 'Version');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.systemInfo.label.ableronCore.version', 'Version');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.systemInfo.label.ableronCore.installationTime', 'Installationszeitpunkt');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.systemInfo.label.ableronCore.installationTime', 'Installation Time');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.systemInfo.label.database.dbms', 'Datenbank Management System');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.systemInfo.label.database.dbms', 'Database Management System');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.systemInfo.label.php.serverApi', 'Server API');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.systemInfo.label.php.serverApi', 'Server API');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.systemInfo.label.php.version', 'PHP Version');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.systemInfo.label.php.version', 'PHP Version');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.systemInfo.label.php.zendEngineVersion', 'Zend Engine Version');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.systemInfo.label.php.zendEngineVersion', 'Zend Engine Version');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.systemInfo.label.server.operatingSystem', 'Betriebssystem');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.systemInfo.label.server.operatingSystem', 'Operating System');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.systemInfo.label.server.webServer', 'Webserver');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.systemInfo.label.server.webServer', 'Web Server');
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'sysInfo.phpInfo.title', 'PHP');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'sysInfo.phpInfo.title', 'PHP');
     // add backend menu items
     $initialDatabaseEntities[] = new BackendMenuItemEntity('', 'fa-cogs', 'sysInfo.navTitle', 2);
     $initialDatabaseEntities[] = new BackendMenuItemEntity('/sysinfo/system', 'fa-cogs', 'sysInfo.systemInfo.title', 1);
     $initialDatabaseEntities[] = new BackendMenuItemEntity('/sysinfo/php', 'fa-cogs', 'sysInfo.phpInfo.title', 2);
     // add module
     $initialDatabaseEntities[] = new ModuleEntity('Ableron System Information', 'System Information Module of Ableron', 'SysInfo', '/sysinfo', '/sysinfo', true, false);
     // add permissions
     $initialDatabaseEntities[] = $permissionCanViewSystemInfo = new PermissionEntity('SysInfo.System.Backend.canViewSystemInfo', 'Grants access to the system information overview of the backend.');
     //TODO tblasche: New permissions should be added to roles automatically
     // get default roles
     $roleRoot = Application::getPersistenceManager()->getRepository('RoleEntity')->findOneBy(array('name' => 'Root'));
     $roleBackendRoot = Application::getPersistenceManager()->getRepository('RoleEntity')->findOneBy(array('name' => 'Backend Root'));
     // add new permissions to default roles
     $roleRoot->getPermissions()->add($permissionCanViewSystemInfo);
     $roleBackendRoot->getPermissions()->add($permissionCanViewSystemInfo);
     // return initial database entities
     return $initialDatabaseEntities;
 }
 /**
  * @see \Ableron\Core\Template\Plugins\Interfaces\CompilerPluginInterface::compileOpeningTag()
  */
 public function compileOpeningTag(TemplateCompiler $templateCompiler)
 {
     // build base URL
     $actionUrl = new Uri(parent::compileOpeningTag($templateCompiler));
     // add URL of current request as action source URL
     $actionUrl->addQueryParameter(ABLERON_PARAM_ACTION_SOURCE_URL, StringUtil::base64UrlEncode(Application::getRequestHandler()->getRequest()->getUri()->toString()));
     // add CSRF token query parameter to URL
     $actionUrl->addQueryParameter(ABLERON_PARAM_CSRF_TOKEN, self::$actionUrlCsrfTokenPlaceholder);
     // return final URL
     return str_replace(self::$actionUrlCsrfTokenPlaceholder, '<?php echo $application::getSecurityHandler()->getCsrfProtector()->getCurrentToken(); ?>', $actionUrl->toString());
 }
Example #15
0
 /**
  * Forwards a method call.
  *
  * @param string $settingType Type of the setting to forward the method call for
  * @param string $methodName Name of the method to call
  * @param array $methodParameters Parameters to pass along the method call
  * @param mixed $fallbackReturnValue Return value in case the method call could not be forwarded
  * @return mixed
  */
 private static function forwardMethodCall(string $settingType, string $methodName, array $methodParameters, $fallbackReturnValue)
 {
     // get setting class
     $settingClass = self::getSettingImplementationClass($settingType);
     // check whether setting class exists
     if (!class_exists($settingClass)) {
         Application::getLogManager()->warning(sprintf('Unable to forward method call for setting type "%s": Unknown setting type', $settingType));
         return $fallbackReturnValue;
     }
     // forward the method call
     return forward_static_call_array(array($settingClass, $methodName), $methodParameters);
 }
 /**
  * @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);
 }
Example #17
0
 /**
  * Returns the text with the given key for the currently set locale.
  *
  * TODO: Use MessageFormatter correctly (use object to get access to getErrorMessage()
  * TODO: Formatting messages may return FALSE on errors
  *
  * @param string $textKey Key of the text to return
  * @param array $parameters List of parameters to pass to the message formatter
  * @return string
  */
 public function translate($textKey, $parameters = array())
 {
     $query = Application::getPersistenceManager()->getEntityManager()->createQuery('SELECT t.text FROM Core:TranslationEntity t WHERE t.textKey = ?1 AND t.locale = ?2');
     $query->setParameter(1, $textKey);
     $query->setParameter(2, $this->getLocale());
     try {
         return MessageFormatter::formatMessage($this->getLocale()->getLocaleCode(), $query->getSingleScalarResult(), $parameters);
     } catch (NoResultException $e) {
         Application::getLogManager()->warning(sprintf('Unable to translate text key "%s": No translation found', $textKey));
         return '';
     }
 }
 /**
  * @see \Ableron\Lib\Event\EventHandlerInterface::handle()
  */
 public function handle(EventInterface $event)
 {
     // only take care of login attempts where both username and password are set
     /** @var \Ableron\Modules\Core\Events\LoginAttemptFailedEvent $event */
     if ($event->getUsername() !== '' && $event->getPassword() !== '') {
         // log failed login attempt
         if (($loginAttemptsEntity = BruteForceProtectionService::getLoginAttemptsByUsername($event->getUsername())) !== null) {
             $loginAttemptsEntity->addFailedAttempt();
         } else {
             Application::getPersistenceManager()->getEntityManager()->persist(new LoginAttemptsEntity($event->getUsername()));
         }
     }
 }
Example #19
0
 /**
  * @see \Ableron\Core\Extension\ExtensionInterface::getInitialDatabaseEntities()
  */
 public function getInitialDatabaseEntities()
 {
     $initialDatabaseEntities = array();
     // get relevant locales
     $localeDeDe = Application::getPersistenceManager()->getRepository('LocaleEntity')->findOneBy(array('localeCode' => 'de-DE'));
     $localeEnUs = Application::getPersistenceManager()->getRepository('LocaleEntity')->findOneBy(array('localeCode' => 'en-US'));
     // add messages
     $initialDatabaseEntities[] = new TranslationEntity($localeDeDe, 'bruteForceProtector.backend.message.possibleBruteForceDetected', 'Für diesen Benutzer wurde mehrfach ein falsches Passwort angegeben. Aus Sicherheitsgründen ist ein erneuter Login-Versuch erst in 2min wieder möglich.');
     $initialDatabaseEntities[] = new TranslationEntity($localeEnUs, 'bruteForceProtector.backend.message.possibleBruteForceDetected', 'An invalid password has been provided for this user multiple times. For security reasons further login attempts are not possible for a period of 2 minutes.');
     // register event handlers
     $initialDatabaseEntities[] = new EventHandlerEntity('core-login-attemptFailed', 'Ableron\\Plugins\\BruteForceProtector\\EventHandlers\\LoginAttemptFailedEventHandler');
     $initialDatabaseEntities[] = new EventHandlerEntity('core-login-attemptSuccessful', 'Ableron\\Plugins\\BruteForceProtector\\EventHandlers\\LoginAttemptSuccessfulEventHandler');
     $initialDatabaseEntities[] = new EventHandlerEntity('core-login-validatingData', 'Ableron\\Plugins\\BruteForceProtector\\EventHandlers\\LoginValidatingDataEventHandler');
     // return initial database entities
     return $initialDatabaseEntities;
 }
 /**
  * @see \Ableron\Modules\Core\Services\Authentication\AuthenticationInterface::authenticateManually()
  */
 public static function authenticateManually($username, $password)
 {
     // get user in case username exists
     $user = Application::getPersistenceManager()->getRepository('UserEntity')->findByUsername($username);
     // check password
     if ($user !== null && Password::verify($password, $user->getPasswordHash())) {
         // rehash password if necessary
         if (Password::needsRehash($user->getPasswordHash())) {
             $user->setPasswordHash(Password::hash($password));
         }
         // return the user object
         return $user;
     }
     // credentials invalid
     return null;
 }
 /**
  * Tests whether findByUsername works as expected.
  *
  * @return void
  */
 public function testFindByUsername()
 {
     // define username
     $username = '******';
     // create user entity
     $user = new UserEntity($username, '', '', '', '');
     // verify user does not exist
     $this->assertNull(Application::getPersistenceManager()->getRepository('UserEntity')->findByUsername($user->getUsername()));
     // create user
     Application::getPersistenceManager()->getEntityManager()->persist($user);
     Application::getPersistenceManager()->getEntityManager()->flush();
     // verify user exist
     $userFromDb = Application::getPersistenceManager()->getRepository('UserEntity')->findByUsername($user->getUsername());
     $this->assertNotNull($userFromDb);
     $this->assertSame($username, $userFromDb->getUsername());
     $this->assertNotNull($username, $userFromDb->getId());
     // remove user
     Application::getPersistenceManager()->getEntityManager()->remove($user);
     Application::getPersistenceManager()->getEntityManager()->flush();
 }
Example #22
0
 /**
  * @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('/'));
     }
 }
 /**
  * Initializes the request handler.
  */
 public function __construct()
 {
     // set request object
     $this->setRequest(new HttpRequest($this->getRequestUri(), EnvironmentUtil::getEnvironmentVariable('REQUEST_METHOD'), $this->getRequestHttpVersion(), $this->getRequestHeaders(), $_GET, $_POST, $this->getRequestCookies()));
     // get the URLs we need
     $frontendBaseUrl = new Uri(rtrim(rtrim(EnvironmentUtil::getSiteUrl()->toString(), '/') . Application::getConfig()->get('frontend.basePath'), '/'));
     $backendBaseUrl = new Uri(rtrim(rtrim(EnvironmentUtil::getSiteUrl()->toString(), '/') . Application::getConfig()->get('backend.basePath'), '/'));
     $requestPath = $this->getRequest()->getUri()->getPath();
     // set whether we have a frontend request
     $this->isFrontendRequest = $this->checkIsFrontendRequest($frontendBaseUrl, $backendBaseUrl, $this->getRequest()->getUri()->getHost(), $requestPath);
     // determine module base path
     $this->moduleBasePath = '/' . explode('/', trim(StringUtil::getSubstring($requestPath, StringUtil::getLength($this->isFrontendRequest ? $frontendBaseUrl->getPath() : $backendBaseUrl->getPath())), '/'), 2)[0];
     // get requested module
     $this->requestedModule = Application::getModuleManager()->findModuleByBasePath($this->moduleBasePath, $this->isFrontendRequest);
     // make sure module base path points to an existing module
     if ($this->requestedModule === null || !$this->requestedModule->isActive()) {
         $this->moduleBasePath = '/';
         $this->requestedModule = Application::getModuleManager()->findModuleByBasePath($this->moduleBasePath, $this->isFrontendRequest);
     }
     // set module request URI
     $this->setModuleRequestUri(new Uri('/' . ltrim(StringUtil::getSubstring($requestPath, StringUtil::getLength($this->isFrontendRequest ? $frontendBaseUrl->getPath() : $backendBaseUrl->getPath()) + StringUtil::getLength($this->moduleBasePath)), '/')));
     $this->getModuleRequestUri()->setQuery($this->getRequest()->getUri()->getQuery());
 }
 /**
  * Returns the login attempts for the given username.
  *
  * Returns NULL in case there are no current failed login attempts for the given user.
  *
  * @param string $username Username to return the login attempts for
  * @return \Ableron\Plugins\BruteForceProtector\Model\Entities\LoginAttemptsEntity|null
  */
 public static function getLoginAttemptsByUsername($username)
 {
     return Application::getPersistenceManager()->getRepository('LoginAttemptsEntity', BruteForceProtectorPlugin::getNamespace())->findOneBy(array('username' => $username));
 }
Example #25
0
 /**
  * Returns an internal URL based on the current base URL and the given
  * module namespace.
  *
  * E.g. EnvironmentUtil::getInternalUrl('/foo', 'Bar') -> http://example.com/acp/Bar/foo
  *
  * @param string $moduleInternalPath Path within the module
  * @param string $moduleNamespace Namespace of the module to return the URL for
  * @return \Ableron\Lib\Net\Uri
  */
 public static function getInternalUrl(string $moduleInternalPath, string $moduleNamespace = null)
 {
     // get module repository
     /** @var \Ableron\Modules\Core\Model\Repositories\ModuleRepository $moduleRepository */
     $moduleRepository = Application::getPersistenceManager()->getRepository('ModuleEntity');
     // get module
     $module = $moduleRepository->findModuleByNamespace($moduleNamespace === null ? CoreModule::getNamespace() : $moduleNamespace);
     // build and return URL
     return new Uri(rtrim(self::getBaseUrl()->toString() . (Application::getRequestHandler()->isFrontendRequest() ? $module->getFrontendBasePath() : $module->getBackendBasePath()), '/') . $moduleInternalPath);
 }
 /**
  * Creates the global entity manager.
  *
  * @return \Doctrine\ORM\EntityManager
  */
 private function createEntityManager()
 {
     // find all modules and plugins that should be handled by the entity manager
     $managedModules = Application::getModuleManager()->getModules();
     $managedPlugins = Application::getPluginManager()->getPlugins();
     // initialize Doctrine configuration
     //TODO: Implement caching correctly (APC, memcached, XCache, ...); see \Doctrine\ORM\Tools\Setup::createConfiguration()
     $config = Setup::createAnnotationMetadataConfiguration($this->getEntityDirectories($managedModules, $managedPlugins), false, ABLERON_DOCTRINE_PROXY_DIR, null);
     // register namespace aliases for managed modules
     foreach ($managedModules as $managedModule) {
         $config->addEntityNamespace($managedModule->getNamespace(), sprintf('Ableron\\Modules\\%s\\Model\\Entities', $managedModule->getNamespace()));
     }
     // register namespace aliases for managed plugins
     foreach ($managedPlugins as $managedPlugin) {
         $config->addEntityNamespace($managedPlugin->getNamespace(), sprintf('Ableron\\Plugins\\%s\\Model\\Entities', $managedPlugin->getNamespace()));
     }
     // configure event manager
     $eventManager = new EventManager();
     // handle table prefix
     if (Application::getContext()->getSetting('doctrine.tablePrefix') !== '') {
         $eventManager->addEventListener(Events::loadClassMetadata, new TablePrefixDoctrineExtension(Application::getContext()->getSetting('doctrine.tablePrefix')));
     }
     // set up Doctrine's EntityManager
     return EntityManager::create(Application::getContext()->getSetting('doctrine.dbConnectionParameters'), $config, $eventManager);
 }
Example #27
0
 /**
  * Tests whether translate() works as expected with unknown message key.
  *
  * @return void
  */
 public function testTranslateWithUnknownMessageKey()
 {
     $this->assertSame('', Application::getI18nHandler()->getTranslator()->translate('unknown.message.key'));
     $this->assertSystemLogFileContainsMessage('Unable to translate text key "unknown.message.key": No translation found');
 }
Example #28
0
 /**
  * @see \Ableron\Core\Controller\Page\PageInterface::assignVariables()
  */
 public function assignVariables()
 {
     parent::assignVariables();
     Application::getTemplateHandler()->getVariables()->setAll(array('documentTitle' => Application::getI18nHandler()->getTranslator()->translate('sysInfo.systemInfo.title'), 'ableronCoreVersion' => Application::getVersion(), 'ableronInstallationTime' => StringUtil::formatDateTime(Application::getInstallationTime()), 'databaseManagementSystem' => SystemInformation::getDatabaseManagementSystem(), 'operatingSystem' => SystemInformation::getOperatingSystem(), 'phpVersion' => SystemInformation::getPhpVersion(), 'phpServerApi' => SystemInformation::getPhpServerApi(), 'webServer' => SystemInformation::getWebServer(), 'zendEngineVersion' => SystemInformation::getZendEngineVersion()));
 }
Example #29
0
 /**
  * Returns the ModuleEntity of the module with the given base path.
  *
  * Returns NULL in case no module has been found with the given criteria.
  *
  * @param string $basePath Base path of the module
  * @param bool $isFrontendBasePath Whether base path is a frontend or a backend base path
  * @return \Ableron\Modules\Core\Model\Entities\ModuleEntity
  */
 public function findModuleByBasePath($basePath, $isFrontendBasePath)
 {
     return Application::getPersistenceManager()->getRepository('ModuleEntity')->findModuleByBasePath($basePath, $isFrontendBasePath);
 }
 /**
  * Initializes the entity.
  */
 public function __construct()
 {
     $this->setOccurrenceTime(DateUtil::getCurrentUtcDateTime());
     $this->setRequestMethod(Application::getRequestHandler()->getRequest()->getMethod());
     $this->setRequestUri(Application::getRequestHandler()->getRequest()->getUri());
 }