/** * Reloads extensions and changes siteaccess globally * If you only want changes on a instance of ini, use {@link eZSiteAccess::getIni()} * * - clears all in-memory caches used by the INI system * - re-builds the list of paths where INI files are searched for * - runs {@link eZSiteAccess::change()} * - re-searches module paths {@link eZModule::setGlobalPathList()} * * @since 4.4 * @param array $access An associative array with 'name' (string), 'type' (int) and 'uri_part' (array). * See {@link eZSiteAccess::match()} for array structure definition * @param eZINI|null $siteINI Optional parameter to be able to only do change on specific instance of site.ini * If set, then global siteacceess will not be changed as well. * @return array The $access parameter */ static function load( array $access, eZINI $siteINI = null ) { $currentSiteAccess = $GLOBALS['eZCurrentAccess']; unset( $GLOBALS['eZCurrentAccess'] ); // Clear all ini override dirs if ( $siteINI instanceof eZINI ) { $siteINI->resetOverrideDirs(); } else { eZINI::resetAllInstances(); eZExtension::clearActiveExtensionsMemoryCache(); eZTemplateDesignResource::clearInMemoryCache(); } // Reload extensions, siteaccess and access extensions eZExtension::activateExtensions( 'default', $siteINI ); $access = self::change( $access, $siteINI ); eZExtension::activateExtensions( 'access', $siteINI ); // Restore current (old) siteacces if changes where only to be applied to locale instance of site.ini if ( $siteINI instanceof eZINI ) { $GLOBALS['eZCurrentAccess'] = $currentSiteAccess; } else { $moduleRepositories = eZModule::activeModuleRepositories(); eZModule::setGlobalPathList( $moduleRepositories ); } return $access; }
eZExtension::activateExtensions( 'access' ); $db = eZDB::instance(); if ( $db->isConnected() ) { eZSession::start(); } else { exitWithInternalError(); return; } $moduleINI = eZINI::instance( 'module.ini' ); $globalModuleRepositories = $moduleINI->variable( 'ModuleSettings', 'ModuleRepositories' ); eZModule::setGlobalPathList( $globalModuleRepositories ); $module = eZModule::exists( 'content' ); if ( !$module ) { exitWithInternalError(); return; } $function_name = 'treemenu'; $uri->increase(); $uri->increase(); $currentUser = eZUser::currentUser(); $siteAccessResult = $currentUser->hasAccessTo( 'user', 'login' ); $hasAccessToSite = false;
function initialize() { if (ob_get_length() != 0) { ob_end_clean(); } $debugINI = eZINI::instance('debug.ini'); eZDebugSetting::setDebugINI($debugINI); // Initialize text codec settings $this->updateTextCodecSettings(); // Initialize debug settings $this->updateDebugSettings($this->UseDebugOutput); // Set the different permissions/settings. $ini = eZINI::instance(); $iniFilePermission = $ini->variable('FileSettings', 'StorageFilePermissions'); $iniDirPermission = $ini->variable('FileSettings', 'StorageDirPermissions'); $iniVarDirectory = eZSys::cacheDirectory(); eZCodePage::setPermissionSetting(array('file_permission' => octdec($iniFilePermission), 'dir_permission' => octdec($iniDirPermission), 'var_directory' => $iniVarDirectory)); eZExecution::addCleanupHandler('eZDBCleanup'); eZExecution::addFatalErrorHandler('eZFatalError'); eZDebug::setHandleType(eZDebug::HANDLE_FROM_PHP); if ($this->UseExtensions) { // Check for extension eZExtension::activateExtensions('default'); // Extension check end } else { if (!$this->isQuiet()) { $cli = eZCLI::instance(); $cli->output("Notice: This script uses 'use-extensions' => false, meaning extension settings are not loaded!"); } } $siteaccess = $this->SiteAccess; if ($siteaccess) { $access = array('name' => $siteaccess, 'type' => eZSiteAccess::TYPE_STATIC); } else { $ini = eZINI::instance(); $siteaccess = $ini->variable('SiteSettings', 'DefaultAccess'); $access = array('name' => $siteaccess, 'type' => eZSiteAccess::TYPE_DEFAULT); } $access = eZSiteAccess::change($access); if ($this->UseExtensions) { // Check for siteaccess extension eZExtension::activateExtensions('access'); // Extension check end } // Now that all extensions are activated and siteaccess has been changed, reset // all eZINI instances as they may not take into account siteaccess specific settings. eZINI::resetAllInstances(false); // Set the global setting which is read by the session lib $GLOBALS['eZSiteBasics']['session-required'] = $this->UseSession; if ($this->UseSession) { $db = eZDB::instance(); if ($db->isConnected()) { eZSession::start(); } else { $this->setIsInitialized(false); $this->InitializationErrorMessage = 'database error: ' . $db->errorMessage(); return; } } if ($this->User) { $userLogin = $this->User['login']; $userPassword = $this->User['password']; if ($userLogin and $userPassword) { $userID = eZUser::loginUser($userLogin, $userPassword); if (!$userID) { $cli = eZCLI::instance(); if ($this->isLoud()) { $cli->warning('Failed to login with user ' . $userLogin); } eZExecution::cleanup(); eZExecution::setCleanExit(); } } } // Initialize module handling if ($this->UseModules) { $moduleRepositories = eZModule::activeModuleRepositories($this->UseExtensions); eZModule::setGlobalPathList($moduleRepositories); } $this->setIsInitialized(true); }
eZWebDAVContentBackend::appendLogEntry("****************************************"); // $templateResult = null; // eZDisplayResult( $templateResult ); } // Check and proceed only if WebDAV functionality is enabled: if ($enable === 'true') { eZExecution::addCleanupHandler('eZDBCleanup'); eZExecution::addFatalErrorHandler('eZFatalError'); eZDebug::setHandleType(eZDebug::HANDLE_FROM_PHP); if (!isset($_SERVER['REQUEST_URI']) or !isset($_SERVER['REQUEST_METHOD'])) { // We stop the script if these are missing // e.g. if run from the shell eZExecution::cleanExit(); } include_once "access.php"; eZModule::setGlobalPathList(array("kernel")); eZWebDAVContentBackend::appendLogEntry("========================================"); eZWebDAVContentBackend::appendLogEntry("Requested URI is: " . $_SERVER['REQUEST_URI'], 'webdav.php'); $ini = eZINI::instance('site.ini'); // Initialize/set the index file. eZSys::init('webdav.php', $ini->variable('SiteAccessSettings', 'ForceVirtualHost') === 'true'); // @as 2009-03-04 - added cleaning up of the REQUEST_URI and HTTP_DESTINATION $_SERVER['REQUEST_URI'] = urldecode($_SERVER['REQUEST_URI']); if (isset($_SERVER['HTTP_DESTINATION'])) { $_SERVER['HTTP_DESTINATION'] = urldecode($_SERVER['HTTP_DESTINATION']); } eZWebDAVContentBackend::appendLogEntry("Used (cleaned) URI is: " . $_SERVER['REQUEST_URI'], 'webdav.php'); // The top/root folder is publicly available (without auth): if ($_SERVER['REQUEST_URI'] == '' or $_SERVER['REQUEST_URI'] == '/' or $_SERVER['REQUEST_URI'] == '/webdav.php/' or $_SERVER['REQUEST_URI'] == '/webdav.php') { // $requestUri = $_SERVER['REQUEST_URI']; // if ( $requestUri == '' )
protected function requestInit() { if ($this->isInitialized) { return; } eZExecution::setCleanExit(false); $scriptStartTime = microtime(true); $GLOBALS['eZRedirection'] = false; $this->access = eZSiteAccess::current(); eZDebug::setScriptStart($scriptStartTime); eZDebug::addTimingPoint("Script start"); $this->uri = eZURI::instance(eZSys::requestURI()); $GLOBALS['eZRequestedURI'] = $this->uri; // Be able to do general events early in process ezpEvent::getInstance()->notify('request/preinput', array($this->uri)); // Initialize module loading $this->siteBasics['module-repositories'] = eZModule::activeModuleRepositories(); eZModule::setGlobalPathList($this->siteBasics['module-repositories']); // make sure we get a new $ini instance now that it has been reset $ini = eZINI::instance(); // start: eZCheckValidity // pre check, setup wizard related so needs to be before session/db init // TODO: Move validity check in the constructor? Setup is not meant to be launched at each (sub)request is it? if ($ini->variable('SiteAccessSettings', 'CheckValidity') === 'true') { $this->check = array('module' => 'setup', 'function' => 'init'); // Turn off some features that won't bee needed yet $this->siteBasics['policy-check-omit-list'][] = 'setup'; $this->siteBasics['show-page-layout'] = $ini->variable('SetupSettings', 'PageLayout'); $this->siteBasics['validity-check-required'] = true; $this->siteBasics['session-required'] = $this->siteBasics['user-object-required'] = false; $this->siteBasics['db-required'] = $this->siteBasics['no-cache-adviced'] = $this->siteBasics['url-translator-allowed'] = false; $this->siteBasics['site-design-override'] = $ini->variable('SetupSettings', 'OverrideSiteDesign'); $this->access = eZSiteAccess::change(array('name' => 'setup', 'type' => eZSiteAccess::TYPE_URI)); eZTranslatorManager::enableDynamicTranslations(); } // stop: eZCheckValidity if ($this->siteBasics['session-required']) { // Check if this should be run in a cronjob if ($ini->variable('Session', 'BasketCleanup') !== 'cronjob') { eZSession::addCallback('destroy_pre', function (eZDBInterface $db, $key, $escapedKey) { $basket = eZBasket::fetch($key); if ($basket instanceof eZBasket) { $basket->remove(); } }); eZSession::addCallback('gc_pre', function (eZDBInterface $db, $time) { eZBasket::cleanupExpired($time); }); eZSession::addCallback('cleanup_pre', function (eZDBInterface $db) { eZBasket::cleanup(); }); } // addCallBack to update session id for shop basket on session regenerate eZSession::addCallback('regenerate_post', function (eZDBInterface $db, $escNewKey, $escOldKey) { $db->query("UPDATE ezbasket SET session_id='{$escNewKey}' WHERE session_id='{$escOldKey}'"); }); // TODO: Session starting should be made only once in the constructor $this->sessionInit(); } // if $this->siteBasics['db-required'], open a db connection and check that db is connected if ($this->siteBasics['db-required'] && !eZDB::instance()->isConnected()) { $this->warningList[] = array('error' => array('type' => 'kernel', 'number' => eZError::KERNEL_NO_DB_CONNECTION), 'text' => 'No database connection could be made, the system might not behave properly.'); } // eZCheckUser: pre check, RequireUserLogin & FORCE_LOGIN related so needs to be after session init if (!isset($this->check)) { $this->check = eZUserLoginHandler::preCheck($this->siteBasics, $this->uri); } ezpEvent::getInstance()->notify('request/input', array($this->uri)); // Initialize with locale settings // TODO: Move to constructor? Is it relevant to init the locale/charset for each (sub)requests? $this->languageCode = eZLocale::instance()->httpLocaleCode(); $phpLocale = trim($ini->variable('RegionalSettings', 'SystemLocale')); if ($phpLocale != '') { setlocale(LC_ALL, explode(',', $phpLocale)); } $this->httpCharset = eZTextCodec::httpCharset(); // TODO: are these parameters supposed to vary across potential sub-requests? $this->site = array('title' => $ini->variable('SiteSettings', 'SiteName'), 'design' => $ini->variable('DesignSettings', 'SiteDesign'), 'http_equiv' => array('Content-Type' => 'text/html; charset=' . $this->httpCharset, 'Content-language' => $this->languageCode)); // Read role settings $this->siteBasics['policy-check-omit-list'] = array_merge($this->siteBasics['policy-check-omit-list'], $ini->variable('RoleSettings', 'PolicyOmitList')); $this->isInitialized = true; }
public function __construct($action, $request) { $moduleRepositories = eZModule::activeModuleRepositories(); eZModule::setGlobalPathList($moduleRepositories); parent::__construct($action, $request); }
/** * Reloads extensions and changes siteaccess globally * If you only want changes on a instance of ini, use {@link eZSiteAccess::getIni()} * * - clears all in-memory caches used by the INI system * - re-builds the list of paths where INI files are searched for * - runs {@link eZSiteAccess::change()} * - re-searches module paths {@link eZModule::setGlobalPathList()} * * @since 4.4 * @param array $access An associative array with 'name' (string), 'type' (int) and 'uri_part' (array). * See {@link eZSiteAccess::match()} for array structure definition * @param eZINI|null $siteINI Optional parameter to be able to only do change on specific instance of site.ini * If set, then global siteacceess will not be changed as well. * @return array The $access parameter */ static function load( array $access, eZINI $siteINI = null ) { $currentSiteAccess = $GLOBALS['eZCurrentAccess']; unset( $GLOBALS['eZCurrentAccess'] ); // Clear all ini override dirs if ( $siteINI instanceof eZINI ) { $siteINI->resetOverrideDirs(); } else { eZINI::resetAllInstances(); eZExtension::clearActiveExtensionsMemoryCache(); eZTemplateDesignResource::clearInMemoryCache(); } // Reload extensions, siteaccess and access extensions eZExtension::activateExtensions( 'default', $siteINI ); $access = self::change( $access, $siteINI ); eZExtension::activateExtensions( 'access', $siteINI ); // Reload Extenion ordering to reorder eZINI Global Override Dirs. // @TODO : Améliorer la gestion globale (éviter des appels multiples !!!) if ( $siteINI instanceof eZINI && $siteINI->variable( 'ExtensionSettings', 'ExtensionOrdering' ) === 'enabled' ) { eZINI::removeGlobalOverrideDirsByScope( 'sa-extension' ); eZINI::removeGlobalOverrideDirsByScope( 'extension' ); eZExtension::activateExtensions( false ); } // Restore current (old) siteacces if changes where only to be applied to locale instance of site.ini if ( $siteINI instanceof eZINI ) { $GLOBALS['eZCurrentAccess'] = $currentSiteAccess; } else { $moduleRepositories = eZModule::activeModuleRepositories(); eZModule::setGlobalPathList( $moduleRepositories ); } return $access; }
/** * Execution point for controller actions. * Returns false if not supported * * @return ezpKernelResult */ public function run() { $db = eZDB::instance(); if ($db->isConnected()) { $this->sessionInit(); } else { return $this->exitWithInternalError(ezpI18n::tr('kernel/content/treemenu', 'Database is not connected')); } $moduleINI = eZINI::instance('module.ini'); $globalModuleRepositories = $moduleINI->variable('ModuleSettings', 'ModuleRepositories'); eZModule::setGlobalPathList($globalModuleRepositories); $module = eZModule::exists('content'); if (!$module) { return $this->exitWithInternalError(ezpI18n::tr('kernel/content/treemenu', '"content" module could not be found.')); } $function_name = 'treemenu'; $this->uri->increase(); $this->uri->increase(); $currentUser = eZUser::currentUser(); $siteAccessResult = $currentUser->hasAccessTo('user', 'login'); $hasAccessToSite = false; if ($siteAccessResult['accessWord'] == 'limited') { $policyChecked = false; foreach ($siteAccessResult['policies'] as $policy) { if (isset($policy['SiteAccess'])) { $policyChecked = true; $crc32AccessName = eZSys::ezcrc32($this->access['name']); if (in_array($crc32AccessName, $policy['SiteAccess'])) { $hasAccessToSite = true; break; } } if ($hasAccessToSite) { break; } } if (!$policyChecked) { $hasAccessToSite = true; } } else { if ($siteAccessResult['accessWord'] == 'yes') { $hasAccessToSite = true; } } if (!$hasAccessToSite) { return $this->exitWithInternalError(ezpI18n::tr('kernel/content/treemenu', 'Insufficient permissions to display the treemenu.'), 403); } $GLOBALS['eZRequestedModule'] = $module; $content = $module->run($function_name, $this->uri->elements(false), false, array('use-cache-headers' => $this->settings['use-cache-headers'])); $attributes = isset($content['lastModified']) ? array('lastModified' => $content['lastModified']) : array(); $this->shutdown(); return new ezpKernelResult($content['content'], $attributes); }
/** * Runs the $file (.request file from $this->files) as a PHPUnit test. * * Steps performed: * - setUp() is called automatically before this function * - skip the test $file if declared. See {@link skip()} * - identify test files attached to the .request file $file (.expected, .body) * - initialize various global variables (together with $GLOBALS from setUp()) * - create an eZ Publish folder with the name $file * - include $file (the .request file) as PHP code. $GLOBALS and $_SERVER values set in there * will be used further on * - initialize the WebDAV system like in webdav.php (it does NOT go through webdav.php) * - create an eZWebDAVContentBackend object and use ezcWebdavServer to handle the * WebDAV request specified in the .request file $file (through $_SERVER variables * 'REQUEST_METHOD' and 'REQUEST_URI' and others. * - the output from the WebDAV system is collected in $GLOBALS['ezc_response_body'] * (through hacks in wrappers.php). * - append the .body file contents to the $GLOBALS['ezc_response_body'] if it exists * - clean the response and the .expected file with cleanForCompare() (eg. creation date, etags etc) * - compare the response and the .expected file with assertEquals(). Same contents means the test passed. * - tearDown() is called automatically after this function * * See doc/specifications/trunk/webdav/testing.txt for detailed information * about each $GLOBALS and $_SERVER variables. * * @param string $file */ public function testRunRegression($file) { // 'ezc' = use eZWebDAVContentBackend (new eZ Publish WebDAV based on ezcWebdav) // 'ezp' = use eZWebDAVContentServer (old eZ Publish WebDAV) // Only 'ezc' is supported for now $system = 'ezc'; // uncomment the tests that you want to skip in the skip() function $this->skip($file); $error = ''; $response = null; $outFile = $this->outFileName($file, '.request', '.expected'); $bodyFile = $this->outFileName($file, '.request', '.body'); $parts = pathinfo($file); $GLOBALS['ezc_webdav_testfolder'] = $parts['filename']; // Create an eZ Publish folder for each test with the name of the test // $GLOBALS['ezc_webdav_testfolderid'] can be used in the .request file // to create file, image, folder etc under the test folder. $folder = new ezpObject("folder", 2); $folder->name = $GLOBALS['ezc_webdav_testfolder']; $folder->publish(); $GLOBALS['ezc_webdav_testfolderobject'] = $folder; $GLOBALS['ezc_webdav_testfolderid'] = $folder->mainNode->node_id; // var_dump( $GLOBALS['ezc_webdav_testfolder'] . ' (' . $GLOBALS['ezc_webdav_testfolderid'] . ')' ); eZExtension::activateExtensions('default'); eZModule::setGlobalPathList(array("kernel")); eZUser::logoutCurrent(); eZSys::init('webdav.php'); // include the .request file. $GLOBALS and $_SERVER defined in the file // will be used in the test include $file; // var_dump( '--- After include' ); // These values can be overwritten in the included $file which contains the WebDAV request $username = $GLOBALS['ezc_webdav_username']; $password = $GLOBALS['ezc_webdav_password']; // Set the HTTP_AUTHORIZATION header $_SERVER['HTTP_AUTHORIZATION'] = 'Basic ' . base64_encode("{$username}:{$password}"); // var_dump( 'Default REQUEST_URI: ' . $_SERVER['REQUEST_URI'] ); // var_dump( 'Cleaned REQUEST_URI: ' . $_SERVER['REQUEST_URI'] ); if ($system === 'ezc') { // Use eZ Components // clean the REQUEST_URI and HTTP_DESTINATION $_SERVER['REQUEST_URI'] = urldecode($_SERVER['REQUEST_URI']); if (isset($_SERVER['HTTP_DESTINATION'])) { $_SERVER['HTTP_DESTINATION'] = urldecode($_SERVER['HTTP_DESTINATION']); } $server = ezcWebdavServer::getInstance(); $backend = new eZWebDAVContentBackend(); $server->configurations = new ezcWebdavServerConfigurationManagerWrapper(); $server->init(new ezcWebdavBasicPathFactory($GLOBALS['ezc_webdav_url']), new ezcWebdavXmlTool(), new ezcWebdavPropertyHandler(), new ezcWebdavHeaderHandler(), new ezcWebdavTransportWrapper()); $server->auth = new eZWebDAVContentBackendAuth(); } else { // Use the previous WebDAV system in eZ Publish $backend = new eZWebDAVContentServerWrapper(); } $currentSite = $backend->currentSiteFromPath($_SERVER['REQUEST_URI']); if ($currentSite) { $backend->setCurrentSite($currentSite); } if ($system === 'ezc') { $server->handle($backend); } else { $backend->processClientRequest(); } // This value comes from the included $file which contains the WebDAV request $response = trim($GLOBALS['ezc_response_body']); $expected = trim(file_get_contents($outFile)); $body = null; if (file_exists($bodyFile)) { $body = trim(file_get_contents($bodyFile)); } // replace dynamic text (eg. ETag) with static text // $body = optional body content (eg. for binary files) to be appended to $expected $expected = $this->cleanForCompare($expected, $body); $response = $this->cleanForCompare($response); $this->assertEquals($expected, $response, "The expected response " . basename($outFile) . " (" . strlen($expected) . ") is not the same as the response got from request " . basename($file) . " (" . strlen($response) . "). {$error}"); }