/** * @param string $username * @param string $password * * @return bool */ public function authCallback($username, $password) { try { $accessManager = AccessManager::singleton(); $authResult = $accessManager->checkLogin($username, $password); // module development must be enabled to login via WebDav $quota = new \Cms\Quota(); if (!$quota->getModuleQuota()->getEnableDev()) { Registry::getLogger()->log(__METHOD__, __LINE__, sprintf('DAV access denied: module development is disabled (%s)', $username), SbLog::ERR); return false; } // login success? if (!$accessManager->isAuthResultValid($authResult)) { Registry::getLogger()->log(__METHOD__, __LINE__, sprintf('DAV access denied: incorrect user credentials (%s)', $username), SbLog::NOTICE); return false; } // only superusers are allowed to login via webdav $identity = $authResult->getIdentity(); if (!is_array($identity) || !isset($identity['superuser']) || $identity['superuser'] != true) { Registry::getLogger()->log(__METHOD__, __LINE__, sprintf('DAV access denied: user is not a superuser (%s)', $username), SbLog::ERR); return false; } } catch (\Exception $e) { Registry::getLogger()->logException(__METHOD__, __LINE__, $e, SbLog::ERR); return false; } // authentication successful return true; }
/** * validate a request object on basis of function-name(action) * * @param string $function * @param \Cms\Request\Abstract $actionRequest * @param boolean $setHttpErrorCode * @return true * @throws Exception */ public function validate($function, Request $actionRequest, $abortExceptions = true) { $methodName = 'validateMethod' . $function; if (method_exists($this, $methodName)) { try { $this->{$methodName}($actionRequest); } catch (PropertyAccessException $e) { $message = str_replace('%name%', $e->getName(), $this->_('error.validation.missing_parameter')); $this->addError(new Error($e->getName(), null, array($message))); } if (count($this->getErrors()) > 0) { foreach ($this->getErrors() as $error) { \Cms\ExceptionStack::addException($error); } if (count(\Cms\ExceptionStack::getExceptions()) > 0) { // soll nur der Status-Code veraendert werden (Bsp: Rueckgabe Images) if ($abortExceptions == true) { // bisherige Fehler loggen und reset foreach (\Cms\ExceptionStack::getExceptions() as $exception) { \Seitenbau\Registry::getLogger()->logException(__METHOD__, __LINE__, $exception, \Seitenbau\Log::NOTICE); } //\Cms\ExceptionStack::reset(); return false; } else { \Cms\ExceptionStack::throwErrors(); } } } return true; } else { $data = array('method' => $methodName); throw new \Cms\Exception(-12, __METHOD__, __LINE__, $data); } }
public function getLog() { if (!Registry::getLogger()) { return false; } $log = Registry::getLogger(); return $log; }
/** * Erstellt ein Thumbnail der angegebenen Orginaldatei * * @param string $originFilePath * @param string $cacheFilePath * @param int $width * @param int $height * @return Thumbnail|false */ public function getThumbnail($originFilePath, $cacheFilePath, $width, $height) { try { return new Thumbnail($originFilePath, $cacheFilePath, $width, $height); } catch (\Exception $e) { Registry::getLogger()->logException(__METHOD__, __LINE__, $e, \Seitenbau\Log::ERR); return false; } }
protected function _initLogger() { // Falls Logger vorhanden, diesen zuerst entfernen $logger = Registry::getLogger(); if ($logger instanceof Seitenbau\Logger) { $logger = null; } parent::_initLogger(); }
/** * creates the publisher object * * @param string $publisherName * @return */ protected static function create($publisherName) { $publisherClassName = '\\Cms\\Publisher\\Type\\' . ucfirst($publisherName); if (!class_exists($publisherClassName)) { $errorMessage = 'Class ' . $publisherClassName . ' doesn\'t exist'; Registry::getLogger()->log(__METHOD__, __LINE__, $errorMessage, Log::ERR); throw new CmsException('1', __METHOD__, __LINE__); } return new $publisherClassName(); }
/** * creates the dao object * * @param string $daoName * @param string $daoType * * @throws \Cms\Exception * @return object */ protected static function create($daoName, $daoType) { $daoClassName = 'Cms\\Dao\\' . $daoName . '\\' . $daoType; if (!class_exists($daoClassName)) { $errorMessage = 'Class ' . $daoClassName . ' doesn\'t exist'; Registry::getLogger()->log(__METHOD__, __LINE__, $errorMessage, \Seitenbau\Log::ERR); throw new CmsException('1', __METHOD__, __LINE__); } return new $daoClassName(); }
/** * Gibt Uuids einer angegebenen Klasse zurueck * * @param string $dataClassName * @param integer $count * @throws Cms\Exception */ public function getUuids($dataClassName, $count) { $dataClass = sprintf("Orm\\Data\\%s", ucfirst($dataClassName)); if (!class_exists($dataClass)) { $errorMessage = sprintf("Data class '%s' does not exist", $dataClass); Registry::getLogger()->log(__METHOD__, __LINE__, $errorMessage, \Seitenbau\Log::ERR); throw new CmsException('1', __METHOD__, __LINE__); } $uuids = $this->generateUuids(new $dataClass(), $count); return $uuids; }
public function publisherstatuschangedAction() { try { $validatedRequest = $this->getValidatedRequest('Builder', 'PublisherStatusChanged'); $this->getBusiness()->checkUserRights('publisherStatusChanged', array('websiteId' => $validatedRequest->getWebsiteId())); $this->getBusiness()->getWebsiteBuildById($validatedRequest->getWebsiteId(), $validatedRequest->getBuildId()); } catch (\Exception $logOnly) { // log only to make hacking more complicating Registry::getLogger()->log(__METHOD__, __LINE__, $logOnly->getMessage(), Log::ERR); throw new CmsException('1', __METHOD__, __LINE__); } }
/** * Prueft die Rechte des angemeldeten Users fuer die aufgerufene Aktion im * Zusammenhang mit der Website-ID und Page-ID * Hat der User keine Rechte, so wird eine Exception geworfen * * @param string $rightname * @param mixed $check * @return boolean * @throws \Cms\Exception */ public final function checkUserRights($rightname, $check = null) { if (Registry::getConfig()->group->check->activ == true) { $identity = $this->getIdentityAsArray(); $userHaveRights = $this->hasUserRights($identity, $rightname, $check); if ($userHaveRights == false) { Registry::getLogger()->logData(__METHOD__, __LINE__, 'User has no privilege', array('check' => array('business' => get_class($this), 'right' => $rightname, 'data' => $check), 'identity' => array('id' => isset($identity['id']) ? $identity['id'] : 'n/a')), SbLog::ERR); throw new \Cms\Exception(7, __METHOD__, __LINE__); } } return true; }
/** * @param string $creatorName * * @return string * @throws CmsException */ protected static function getCreatorClassName($creatorName) { $fullCreatorName = ucfirst($creatorName) . 'Creator'; $creatorClassName = 'Cms\\Creator\\Adapter\\' . $fullCreatorName; $creatorFileName = __DIR__ . '/Adapter/' . $fullCreatorName . '.php'; if (file_exists($creatorFileName)) { if (class_exists($creatorClassName)) { return $creatorClassName; } } Registry::getLogger()->log(__METHOD__, __LINE__, 'Class ' . $creatorClassName . ' does not exist', Log::ERR); throw new CmsException('1', __METHOD__, __LINE__); }
/** * Gibt mehrere Media-Objekte anhand der uebergebenen Ids zurueck * * @param array $ids * @param string $websiteId * @param array */ public function findMultipleByIds(array $ids, $websiteId) { $dql = 'SELECT m FROM Orm\\Entity\\Media m' . ' WHERE m.id IN (:ids) ' . ' AND m.websiteid = :websiteid'; $query = $this->_em->createQuery($dql); $query->setParameters(array('ids' => $ids, 'websiteid' => $websiteId)); try { $result = $query->getResult(); } catch (\Exception $e) { \Seitenbau\Registry::getLogger()->logException(__METHOD__, __LINE__, $e, \Seitenbau\Log::NOTICE); $result = null; } return $result; }
/** * * @return Hashers\IPasswordHasher[] */ protected function getHasher() { if (is_null($this->hashers)) { $this->hashers = array(); foreach ($this->password_hashers as $h) { try { $this->hashers[] = new $h(); } catch (\Exception $e) { Registry::getLogger()->logException(__METHOD__, __LINE__, $e, Log::WARN); } } } return $this->hashers; }
/** * @return string */ public function get($useInternalUrl = false) { $config = Registry::getConfig(); $credential = null; if ($config->screens->accessticket->authentication) { $credential = array('username' => RandomGenerator::generateString(10), 'password' => RandomGenerator::generateString(10)); } $requestConfig = $this->getShootRequest(); \Seitenbau\Registry::getLogger()->logData(__METHOD__, __LINE__, "ShootRequest:", $requestConfig, \Seitenbau\Log::DEBUG); $ticketUrl = ''; if (isset($requestConfig) && !empty($requestConfig)) { $ticketBusiness = $this->newTicketInstance(); $ticketUrl = $ticketBusiness->createTicketUrl($this->websiteId, false, true, $requestConfig, $config->screens->accessticket->ticketLifetime, $config->screens->accessticket->remainingCalls, $config->screens->accessticket->sessionLifetime, $credential, $credential, $useInternalUrl); } return $ticketUrl; }
/** * creates the screenshot object * * @param string $adapterName * @param array $config * @return */ protected static function create($adapterName, array $config) { $screentoolClassName = '\\Seitenbau\\Screenshot\\Type\\' . ucfirst($adapterName); if (!class_exists($screentoolClassName)) { $errorMessage = 'Class ' . $screentoolClassName . ' doesn\'t exist'; Registry::getLogger()->log(__METHOD__, __LINE__, $errorMessage, SbLog::ERR); throw new CmsException('1', __METHOD__, __LINE__); } $screentool = new $screentoolClassName($config); if (!$screentool instanceof ScreenshotFiles\Screenshot) { $errorMessage = 'Type class ' . $screentoolClassName . ' does not extend \\Seitenbau\\Screenshot\\Screenshot'; Registry::getLogger()->log(__METHOD__, __LINE__, $errorMessage, SbLog::ERR); throw new CmsException('1', __METHOD__, __LINE__); } return $screentool; }
/** * Erstellt ein Bildverarbeitungs-Tool Seitenbau\Image\Base * * @param array $config */ public static function factory($config = null) { //set memory limit for large images if (!isset(self::$_memory_limit)) { self::setMemoryLimit(); } $imageAdapterName = null; if ($config instanceof \Zend_Config) { $config = $config->toArray(); } if (!is_array($config)) { $globalConfig = Registry::getConfig(); if (isset($globalConfig->imageAdapter) && !empty($globalConfig->imageAdapter)) { $config = $globalConfig->imageAdapter->toArray(); } } if (isset($config['adapter']) && !empty($config['adapter'])) { $imageAdapterName = (string) $config['adapter']; } else { // Default/Fallback $imageAdapterName = 'Phpgd'; } if (!is_string($imageAdapterName) || empty($imageAdapterName)) { throw new \Exception('Type name must be specified in a string'); } $imageAdapterName = ucfirst($imageAdapterName); if (!self::loadClass($imageAdapterName)) { throw new \Exception("Image adpater class '{$imageAdapterName}' couldn't be loaded"); } $imageAdapterClassName = '\\Seitenbau\\Image\\Adapter\\' . $imageAdapterName; if (!class_exists($imageAdapterClassName)) { $errorMessage = sprintf("Image processing class '%s' doesn't exist", $imageAdapterClassName); Registry::getLogger()->log(__METHOD__, __LINE__, $errorMessage, \Seitenbau\Log::ERR); throw new \Exception($errorMessage); } try { $config = is_array($config) ? $config : array(); $imageTool = new $imageAdapterClassName($config); } catch (\Exception $e) { Registry::getLogger()->logException(__METHOD__, __LINE__, $e, $e->getCode()); } if (!$imageTool instanceof ImageFiles\Image) { throw new \Exception("Type class '{$imagetoolName}' does not extend \\Seitenbau\\Image\\Image"); } return $imageTool; }
/** * @param string $websiteId * * @return PageTypeSource */ protected function getSource($websiteId) { $sources = array(); $defaultSource = $this->getDefaultSource(); if (!is_null($defaultSource)) { $sources[] = $defaultSource; } try { $packageService = $this->getPackageService(); $packages = $packageService->getAll($websiteId); foreach ($packages as $package) { $sources = array_merge($sources, $package->getPageTypesSource()); } } catch (Exception $logOnly) { Registry::getLogger()->logException(__METHOD__, __LINE__, $logOnly, SbLog::ERR); } return new PageTypeSource($websiteId, $sources); }
/** * @param string $identity - email address * @param mixed $credentials - e.g. password string * * @return \Cms\Access\Auth\Result */ public function checkLogin($identity, $credentials) { if (is_null($identity) || is_null($credentials) || !is_string($credentials)) { return null; } try { // get user object $userBusiness = new User('User'); $user = $userBusiness->getByEmail($identity); // check credentials $ph = new PasswordHasher(); if (!$ph->validate($credentials, $user->getPassword())) { return null; } // create auth result and return it return $this->createSuccessAuthResult($user); } catch (\Exception $e) { Registry::getLogger()->logException(__METHOD__, __LINE__, $e, \Seitenbau\Log::DEBUG); return null; } }
/** * Gibt einen Parameter aus dem Standard Request-Parameter zurueck * * @param \Zend_Controller_Request_Abstract $request * @param string $param * @return string|null */ protected function getParam(\Zend_Controller_Request_Abstract $request, $param) { $paramString = $request->getParam(\Cms\Request\Base::REQUEST_PARAMETER); try { $paramArray = \Zend_Json::decode($paramString); } catch (\Exception $e) { try { // Try to decode to UTF8 $paramArray = \Zend_Json::decode(utf8_encode($paramString)); } catch (\Exception $e) { \Seitenbau\Registry::getLogger()->logException(__METHOD__, __LINE__, $e, \Seitenbau\Log::DEBUG); return null; } } if (is_array($paramArray) && count($paramArray) > 0) { foreach ($paramArray as $paramName => $paramValue) { if (strtolower($paramName) == $param) { return $paramValue; } } } return null; }
/** * @param string $websiteId */ public function updateAllContentsOfWebsite($websiteId) { /** @var \Cms\Data\TemplateSnippet[] $allTemplateSnippets */ $allTemplateSnippets = $this->getTemplateSnippetBusiness()->getAll($websiteId); foreach ($allTemplateSnippets as $templateSnippet) { if ($templateSnippet->isReadonly()) { continue; } try { $this->updateTemplateSnippetContent($websiteId, $templateSnippet->getId()); } catch (\Exception $logOnly) { Registry::getLogger()->logException(__METHOD__, __LINE__, $logOnly, SbLog::ERR); } } /** @var string[] $allTemplateIds */ $allTemplateIds = $this->getTemplateBusiness()->getIdsByWebsiteId($websiteId); foreach ($allTemplateIds as $templateId) { try { $this->updateTemplateContent($websiteId, $templateId); } catch (\Exception $logOnly) { Registry::getLogger()->logException(__METHOD__, __LINE__, $logOnly, SbLog::ERR); } } }
/** * @param string $host * @param array $request * @param stringref $responseBody * @internal param array $serviceParams * @return string */ protected function callUrl($host, $request, &$responseBody) { $responseBody = $responseHeaders = null; $http = $this->getHttpClient(); $responseCode = $http->callUrl($host, $request, $responseHeaders, $responseBody, $http::METHOD_POST); if ($responseCode != 200 && !in_array($responseCode, $this->acceptedCodes)) { $logger = \Seitenbau\Registry::getLogger(); if ($logger instanceof \Seitenbau\Logger) { $output = preg_replace('#^.*<\\s*body.*?>\\s*#s', '', $responseBody); $output = preg_replace('#\\s*<\\s*/\\s*body\\s*>.*$#s', '', $output); if (mb_strlen($output) > 1024) { $output = mb_substr($output, 0, 1024) . "\n..."; } $logId = $logger->createLogId(); $logger->log(__METHOD__, __LINE__, sprintf("Url '%s%s' (Status: %s; Error: %s)", $host, $request['url'], $responseCode, $http->getLastError()), \Seitenbau\Log::WARN, $logId); $logger->log(__METHOD__, __LINE__, "Body:\n" . trim($output), \Seitenbau\Log::INFO, $logId); } } return $responseCode; }
/** * validiert den date parameter * * @param string $date * @return boolean */ private function validateDate($date) { // TODO: Validierung des Datums \Seitenbau\Registry::getLogger()->log(__METHOD__, __LINE__, 'TODO: Page Validierung Date', \Seitenbau\Log::DEBUG); return true; }
/** * @test * @group library */ public function setLoggerShouldSetLogger() { $this->assertInstanceOf('Seitenbau\\Logger', Registry::getLogger()); }
/** * Prueft, ob das Command fuer das Screenshot Tool definiert ist und * aufgerufen werden kann * * @return boolean */ private function isCommandUsable() { $screenCommand = $this->config[self::CONFIG_SELECTION][self::CONFIG_OPTION_COMMAND]; if (!\file_exists($screenCommand)) { Registry::getLogger()->log(__METHOD__, __LINE__, 'Screen Command "' . $screenCommand . '" not found', Log::NOTICE); return false; } $this->screenCommand = $screenCommand; return true; }
/** * set the json params from request * * @param Zend_Controller_Request_Abstract $request */ protected function setJsonRequestParams(\Zend_Controller_Request_Abstract $request) { $paramString = $request->getParam(self::REQUEST_PARAMETER); if (empty($paramString)) { return; } try { $incomingRequestParams = \Zend_Json::decode($paramString, \Zend_Json::TYPE_OBJECT); } catch (\Exception $e) { try { $incomingRequestParams = \Zend_Json::decode(utf8_encode($paramString), \Zend_Json::TYPE_OBJECT); } catch (\Exception $e) { Registry::getLogger()->logException(__METHOD__, __LINE__, $e, SbLog::DEBUG); return null; } } if (is_object($incomingRequestParams)) { $this->setRequestParams(get_object_vars($incomingRequestParams)); } }
/** * @return string The created FTP test directory */ protected function createTestFtpDirectory() { $config = Registry::getConfig(); $publishConfig = $config->publish; $testFtpDirectory = $config->publish->get('basedir') . FtpClient::FTP_DIRECTORY_SEPARATOR . 'test_dir_' . time(); $ftpClient = new FtpClient($publishConfig, Registry::getLogger()); $assertionMessageClient = sprintf("FTP connection to '%s' failed", $publishConfig->get('host')); $this->assertTrue($ftpClient->connect() !== null, $assertionMessageClient); $assertionMessageCreateDir = sprintf("FTP create directory '%s' failed", $testFtpDirectory); $this->assertTrue($ftpClient->createDirectory($testFtpDirectory), $assertionMessageCreateDir); $ftpClient->close(); return $testFtpDirectory; }
/** * @param string $host * @param array $request * @param stringref $responseBody * @return string */ protected function callUrl($host, $request, &$responseBody) { $responseBody = $responseHeaders = null; $http = $this->getHttpClient(); $responseCode = $http->callUrl($host, $request, $responseHeaders, $responseBody, $http::METHOD_POST); // check for content-type on success if ($responseCode == 200) { $responseCode = -1; if (isset($responseHeaders) && is_array($responseHeaders)) { foreach ($responseHeaders as $header) { if (preg_match('#Content-Type: image/.+#', $header)) { $responseCode = 200; break; } } } } if (isset($responseCode) && !in_array($responseCode, $this->acceptedCodes)) { $logger = \Seitenbau\Registry::getLogger(); if ($logger instanceof \Seitenbau\Logger) { $output = preg_replace('#^.*<\\s*body.*?>\\s*#s', '', $responseBody); $output = preg_replace('#\\s*<\\s*/\\s*body\\s*>.*$#s', '', $output); if (mb_strlen($output) > 1024) { $output = mb_substr($output, 0, 1024) . "\n..."; } $logId = $logger->createLogId(); $logger->log(__METHOD__, __LINE__, sprintf("Url '%s%s' (Status: %s; Error: %s)", $host, $request['url'], $responseCode, $http->getLastError()), \Seitenbau\Log::WARN, $logId); $logger->log(__METHOD__, __LINE__, "Body:\n" . $output, \Seitenbau\Log::INFO, $logId); } } return $responseCode; }
/** * Ermittelt die globaleb Variablen aus einem Page-Content * * @param string $websiteId * @param array $content * @param array $globalcontent * @param array $globalModuleVars * @param array $isTemplate * @param array */ protected function getGlobalContentFromContentRecursive($websiteId, array $content, array &$globalcontent, array &$globalModuleVars, $isTemplate = false) { if (is_array($content)) { foreach ($content as $unitData) { if (is_object($unitData)) { $unitData = get_object_vars($unitData); } // Modul-Id vorhanden? if (isset($unitData['moduleId'])) { // Muss noch die globalen Variablen-Namen dieses Moduls ermittelt werden? if (isset($unitData['moduleId']) && !empty($unitData['moduleId']) && !isset($globalModuleVars[$unitData['moduleId']])) { // Globale Variablen-Namen des Moduls ermitteln try { $variableNames = $this->getBusiness('Modul')->getGlobalVariableNamesByModulId($unitData['moduleId'], $websiteId); } catch (\Exception $logOnly) { Registry::getLogger()->logException(__METHOD__, __LINE__, $logOnly, SbLog::ERR); $variableNames = array(); } $globalModuleVars[$unitData['moduleId']] = $variableNames; } // Globale Felder vorhanden if (is_array($globalModuleVars[$unitData['moduleId']]) && count($globalModuleVars[$unitData['moduleId']]) > 0) { foreach ($globalModuleVars[$unitData['moduleId']] as $globalVarName => $globalVarField) { if (is_object($unitData['formValues'])) { $unitData['formValues'] = get_object_vars($unitData['formValues']); } // Unit-Variable ermitteln $isUnitValue = true; $unitGlobalData = null; if (isset($unitData['formValues']) && array_key_exists($globalVarName, $unitData['formValues'])) { $isUnitValue = true; $unitGlobalData = $unitData['formValues'][$globalVarName]; } else { // Module-Default Wert verwenden $isUnitValue = false; $unitGlobalData = $globalVarField['default']; } // Globale Varaibalen aufnehmen if (!isset($globalcontent[$globalVarName])) { $globalcontent[$globalVarName] = array(); } $globalcontent[$globalVarName][] = array('unitId' => $isTemplate ? null : $unitData['id'], 'templateUnitId' => $isTemplate ? $unitData['id'] : $unitData['templateUnitId'], 'moduleId' => $unitData['moduleId'], 'value' => $unitGlobalData, 'isUnitValue' => $isUnitValue); } } } // Children durchlaufen if (isset($unitData['children'])) { $this->getGlobalContentFromContentRecursive($websiteId, $unitData['children'], $globalcontent, $globalModuleVars, $isTemplate); } } } }
/** * returns the item type and item id for the website screenshot * * @param string $websiteId ID der Website * @return array array(type, id) */ private function getItemTypeAndIdForWebsiteScreenshot($websiteId) { try { $pageId = $this->getBusiness('Website')->getFirstPageFromWebsite($websiteId); if (!empty($pageId)) { return array(self::SCREEN_TYPE_PAGE, $pageId); } $templates = $this->getBusiness('Template')->getAll($websiteId); if (is_array($templates) && count($templates) > 0) { return array(self::SCREEN_TYPE_TEMPLATE, $templates[0]->getId()); } } catch (\Exception $e) { Registry::getLogger()->logException(__METHOD__, __LINE__, $e, SbLog::NOTICE); return false; } return false; }
/** * @param string $pageId * @return boolean */ private function validatePageId($pageId) { $pageIdValidator = new UniqueIdValidator(Unit\Page::ID_PREFIX, Unit\Page::ID_SUFFIX); if (!$pageIdValidator->isValid($pageId)) { Registry::getLogger()->logData(__METHOD__, __LINE__, 'No page id in page rights', $pageId, Log::ERR); return false; } return true; }