Exemplo n.º 1
0
 public function createRequestParser()
 {
     $parser = new ezpRestHttpRequestParser();
     if (strpos($_SERVER['SCRIPT_NAME'], self::INDEX_FILE) !== false) {
         // In non-vhost mode we need to build the prefix to be removed from URI
         $parser->prefix = eZSys::indexDir(true);
     }
     return $parser;
 }
 /**
  * Handles redirection to the mobile optimized interface
  *
  */
 public function redirect()
 {
     $http = eZHTTPTool::instance();
     $currentSiteAccess = eZSiteAccess::current();
     if ($http->hasGetVariable('notmobile')) {
         setcookie('eZMobileDeviceDetect', 1, time() + (int) eZINI::instance()->variable('SiteAccessSettings', 'MobileDeviceDetectCookieTimeout'), '/');
         $http->redirect(eZSys::indexDir());
         eZExecution::cleanExit();
     }
     if (!isset($_COOKIE['eZMobileDeviceDetect']) && !in_array($currentSiteAccess['name'], eZINI::instance()->variable('SiteAccessSettings', 'MobileSiteAccessList'))) {
         $http->redirect(eZINI::instance()->variable('SiteAccessSettings', 'MobileSiteAccessURL'));
         eZExecution::cleanExit();
     }
 }
Exemplo n.º 3
0
 function createRedirectionUrl($process)
 {
     //__DEBUG__
     $this->logger->writeTimedString("createRedirectionUrl");
     //___end____
     $paypalINI = eZINI::instance('paypal.ini');
     $paypalServer = $paypalINI->variable('ServerSettings', 'ServerName');
     $requestURI = $paypalINI->variable('ServerSettings', 'RequestURI');
     $business = urlencode($paypalINI->variable('PaypalSettings', 'Business'));
     $processParams = $process->attribute('parameter_list');
     $orderID = $processParams['order_id'];
     $indexDir = eZSys::indexDir();
     $localHost = eZSys::serverURL();
     $localURI = eZSys::serverVariable('REQUEST_URI');
     $order = eZOrder::fetch($orderID);
     $amount = urlencode($order->attribute('total_inc_vat'));
     $currency = urlencode($order->currencyCode());
     //        include_once( 'lib/ezlocale/classes/ezlocale.php' );
     $locale = eZLocale::instance();
     $countryCode = urlencode($locale->countryCode());
     $maxDescLen = $paypalINI->variable('PaypalSettings', 'MaxDescriptionLength');
     $itemName = urlencode($this->createShortDescription($order, $maxDescLen));
     $accountInfo = $order->attribute('account_information');
     $first_name = urlencode($accountInfo['first_name']);
     $last_name = urlencode($accountInfo['last_name']);
     $street = urlencode($accountInfo['street2']);
     $zip = urlencode($accountInfo['zip']);
     $state = urlencode($accountInfo['state']);
     $place = urlencode($accountInfo['place']);
     $image_url = "{$localHost}" . urlencode($paypalINI->variable('PaypalSettings', 'LogoURI'));
     $background = urlencode($paypalINI->variable('PaypalSettings', 'BackgroundColor'));
     $pageStyle = urlencode($paypalINI->variable('PaypalSettings', 'PageStyle'));
     $noNote = urlencode($paypalINI->variable('PaypalSettings', 'NoNote'));
     $noteLabel = $noNote == 1 ? '' : urlencode($paypalINI->variable('PaypalSettings', 'NoteLabel'));
     $noShipping = 1;
     $url = $paypalServer . $requestURI . "?cmd=_ext-enter" . "&redirect_cmd=_xclick" . "&business={$business}" . "&item_name={$itemName}" . "&custom={$orderID}" . "&amount={$amount}" . "&currency_code={$currency}" . "&first_name={$first_name}" . "&last_name={$last_name}" . "&address1={$street}" . "&zip={$zip}" . "&state={$state}" . "&city={$place}" . "&image_url={$image_url}" . "&cs={$background}" . "&page_style={$pageStyle}" . "&no_shipping={$noShipping}" . "&cn={$noteLabel}" . "&no_note={$noNote}" . "&lc={$countryCode}" . "&notify_url={$localHost}" . $indexDir . "/paypal/notify_url/" . "&return={$localHost}" . $indexDir . "/shop/checkout/" . "&cancel_return={$localHost}" . $indexDir . "/shop/basket/";
     //__DEBUG__
     $this->logger->writeTimedString("business       = {$business}");
     $this->logger->writeTimedString("item_name      = {$itemName}");
     $this->logger->writeTimedString("custom         = {$orderID}");
     $this->logger->writeTimedString("no_shipping    = {$noShipping}");
     $this->logger->writeTimedString("localHost      = {$localHost}");
     $this->logger->writeTimedString("amount         = {$amount}");
     $this->logger->writeTimedString("currency_code  = {$currency}");
     $this->logger->writeTimedString("notify_url     = {$localHost}" . $indexDir . "/paypal/notify_url/");
     $this->logger->writeTimedString("return         = {$localHost}" . $indexDir . "/shop/checkout/");
     $this->logger->writeTimedString("cancel_return  = {$localHost}" . $indexDir . "/shop/basket/");
     //___end____
     return $url;
 }
 function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters)
 {
     $redirectUri = $namedParameters['url'];
     // if $redirectUri is not starting with scheme://
     if (!preg_match('#^\\w+://#', $redirectUri)) {
         // path to eZ Publish index
         $indexDir = eZSys::indexDir();
         /* We need to make sure we have one
            and only one slash at the concatenation point
            between $indexDir and $redirectUri. */
         $redirectUri = rtrim($indexDir, '/') . '/' . ltrim($redirectUri, '/');
     }
     // Redirect to $redirectUri by returning status code 301 and exit.
     eZHTTPTool::redirect($redirectUri, array(), 301);
     eZExecution::cleanExit();
 }
Exemplo n.º 5
0
 /**
  * Internal function to get current index dir
  *
  * @return string
  */
 protected static function getIndexDir()
 {
     static $cachedIndexDir = null;
     if ($cachedIndexDir === null) {
         $cachedIndexDir = eZSys::indexDir() . '/';
     }
     return $cachedIndexDir;
 }
Exemplo n.º 6
0
$pScope = getHTTPVariable('scope');
// @todo The spec mentions (FIXME:chapter) throwing an error if the request has extra parameters. Check this.
// Try loading the REST client based on the ID
$application = ezpRestClient::fetchByClientId($pClientId);
if (!$application instanceof ezpRestClient) {
    error($pRedirectUri, 'invalid_client');
}
// The client is found, validate the redirect_uri
if (!$application->isEndPointValid($pRedirectUri)) {
    error($pRedirectUri, 'redirect_uri_mismatch');
}
// authentication
$user = eZUser::currentUser();
// login is like REALLY required here. But we can't use the standard policy check, as it won't redirect w/ GET parameters
if (!$user->isRegistered()) {
    $redirectUri = str_replace(eZSys::indexDir(), '', $_SERVER['REQUEST_URI']);
    $tpl = eZTemplate::factory();
    $tpl->setVariable('redirect_uri', $redirectUri, 'User');
    $tpl->setVariable('site_access', array('allowed' => true));
    $result = array();
    $result['content'] = $tpl->fetch('design:user/login.tpl');
    $result['pagelayout'] = false;
    $result['path'] = array(array('text' => ezpI18n::tr('kernel/user', 'User'), 'url' => false), array('text' => ezpI18n::tr('kernel/user', 'Login'), 'url' => false));
    $result['pagelayout'] = 'oauthloginpagelayout.tpl';
    return $result;
}
// logged in, but no access to oauth/authorize
$access = $user->hasAccessTo('oauth', 'authorize');
if (!$access['accessWord'] == 'yes') {
    return $module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel');
}
 /**
  * Detects a possible/valid site-name in start of a path.
  *
  * From eZ Publish.
  *
  * @param string $path Eg. '/plain_site_user/Content/Folder1/file1.txt'
  * @return string The name of the site that was detected (eg. 'plain_site_user')
  *                or false if not site could be detected
  * @todo remove or move in another class?
  */
 public function currentSiteFromPath($path)
 {
     $indexDir = eZSys::indexDir();
     // Remove indexDir if used in non-virtualhost mode.
     if (preg_match("#^" . preg_quote($indexDir) . "(.+)\$#", $path, $matches)) {
         $path = $matches[1];
     }
     foreach ($this->availableSites as $site) {
         // Check if given path starts with this site-name, if so: return it.
         if (preg_match("#^/" . preg_quote($site) . "(.*)\$#", $path, $matches)) {
             return $site;
         }
     }
     return false;
 }
Exemplo n.º 8
0
    function processURL( $url )
    {
        $this->appendLogEntry( "start url: $url", 'CS:processURL' );
        $indexDir = eZSys::indexDir();
        $len = strlen( $indexDir );

        if ( $indexDir == substr( $url, 0, $len ) )
        {
            $url = substr( $url, $len );
        }

        // Remove the starting / if there is one
        // the rest of the operation code expects this to not be present
        if ( strlen( $url ) > 0 and $url[0] == '/' )
            $url = substr( $url, 1 );

        $this->appendLogEntry( "indexdir url: $url", 'CS:processURL' );
        return $url;
    }
Exemplo n.º 9
0
 /**
  * Performs a redirection
  */
 protected function redirect()
 {
     $GLOBALS['eZRedirection'] = true;
     $ini = eZINI::instance();
     $automaticRedirect = true;
     if ($GLOBALS['eZDebugAllowed'] && ($redirUri = $ini->variable('DebugSettings', 'DebugRedirection')) !== 'disabled') {
         if ($redirUri == "enabled") {
             $automaticRedirect = false;
         } else {
             $uri = eZURI::instance(eZSys::requestURI());
             $uri->toBeginning();
             foreach ($ini->variableArray("DebugSettings", "DebugRedirection") as $redirUri) {
                 $redirUri = new eZURI($redirUri);
                 if ($redirUri->matchBase($uri)) {
                     $automaticRedirect = false;
                     break;
                 }
             }
         }
     }
     $redirectURI = eZSys::indexDir();
     $moduleRedirectUri = $this->module->redirectURI();
     if ($ini->variable('URLTranslator', 'Translation') === 'enabled' && eZURLAliasML::urlTranslationEnabledByUri(new eZURI($moduleRedirectUri))) {
         $translatedModuleRedirectUri = $moduleRedirectUri;
         if (eZURLAliasML::translate($translatedModuleRedirectUri, true)) {
             $moduleRedirectUri = $translatedModuleRedirectUri;
             if (strlen($moduleRedirectUri) > 0 && $moduleRedirectUri[0] !== '/') {
                 $moduleRedirectUri = '/' . $moduleRedirectUri;
             }
         }
     }
     if (preg_match('#^(\\w+:)|^//#', $moduleRedirectUri)) {
         $redirectURI = $moduleRedirectUri;
     } else {
         $leftSlash = strlen($redirectURI) > 0 && $redirectURI[strlen($redirectURI) - 1] === '/';
         $rightSlash = strlen($moduleRedirectUri) > 0 && $moduleRedirectUri[0] === '/';
         if (!$leftSlash && !$rightSlash) {
             // Both are without a slash, so add one
             $moduleRedirectUri = '/' . $moduleRedirectUri;
         } else {
             if ($leftSlash && $rightSlash) {
                 // Both are with a slash, so we remove one
                 $moduleRedirectUri = substr($moduleRedirectUri, 1);
             }
         }
         $redirectURI .= $moduleRedirectUri;
     }
     eZStaticCache::executeActions();
     eZDB::checkTransactionCounter();
     if ($automaticRedirect) {
         eZHTTPTool::redirect($redirectURI, array(), $this->module->redirectStatus());
     } else {
         // Make sure any errors or warnings are reported
         if ($ini->variable('DebugSettings', 'DisplayDebugWarnings') === 'enabled') {
             if (isset($GLOBALS['eZDebugError']) && $GLOBALS['eZDebugError']) {
                 eZAppendWarningItem(array('error' => array('type' => 'error', 'number' => 1, 'count' => $GLOBALS['eZDebugErrorCount']), 'identifier' => 'ezdebug-first-error', 'text' => ezpI18n::tr('index.php', 'Some errors occurred, see debug for more information.')));
             }
             if (isset($GLOBALS['eZDebugWarning']) && $GLOBALS['eZDebugWarning']) {
                 eZAppendWarningItem(array('error' => array('type' => 'warning', 'number' => 1, 'count' => $GLOBALS['eZDebugWarningCount']), 'identifier' => 'ezdebug-first-warning', 'text' => ezpI18n::tr('index.php', 'Some general warnings occured, see debug for more information.')));
             }
         }
         $tpl = eZTemplate::factory();
         $tpl->setVariable('site', $this->site);
         $tpl->setVariable('warning_list', !empty($this->warningList) ? $this->warningList : false);
         $tpl->setVariable('redirect_uri', eZURI::encodeURL($redirectURI));
         $templateResult = $tpl->fetch('design:redirect.tpl');
         eZDebug::addTimingPoint("Script end");
         eZDisplayResult($templateResult);
     }
     eZExecution::cleanExit();
 }
Exemplo n.º 10
0
     if ($redirUri == "enabled") {
         $automatic_redir = false;
     } else {
         $redirUris = $ini->variableArray("DebugSettings", "DebugRedirection");
         $uri = eZURI::instance(eZSys::requestURI());
         $uri->toBeginning();
         foreach ($redirUris as $redirUri) {
             $redirUri = new eZURI($redirUri);
             if ($redirUri->matchBase($uri)) {
                 $automatic_redir = false;
                 break;
             }
         }
     }
 }
 $redirectURI = eZSys::indexDir();
 $moduleRedirectUri = $module->redirectURI();
 $redirectStatus = $module->redirectStatus();
 $translatedModuleRedirectUri = $moduleRedirectUri;
 if ($ini->variable('URLTranslator', 'Translation') == 'enabled' && eZURLAliasML::urlTranslationEnabledByUri(new eZURI($moduleRedirectUri))) {
     if (eZURLAliasML::translate($translatedModuleRedirectUri, true)) {
         $moduleRedirectUri = $translatedModuleRedirectUri;
         if (strlen($moduleRedirectUri) > 0 and $moduleRedirectUri[0] != '/') {
             $moduleRedirectUri = '/' . $moduleRedirectUri;
         }
     }
 }
 if (preg_match('#^(\\w+:)|^//#', $moduleRedirectUri)) {
     $redirectURI = $moduleRedirectUri;
 } else {
     $leftSlash = false;
 /**
  * Handles redirection to the mobile optimized interface
  *
  */
 public function redirect()
 {
     $http = eZHTTPTool::instance();
     $currentSiteAccess = eZSiteAccess::current();
     if ($http->hasGetVariable('notmobile')) {
         setcookie('eZMobileDeviceDetect', 1, time() + (int) eZINI::instance()->variable('SiteAccessSettings', 'MobileDeviceDetectCookieTimeout'), '/');
         $http->redirect(eZSys::indexDir());
         eZExecution::cleanExit();
     }
     if (!isset($_COOKIE['eZMobileDeviceDetect']) && !in_array($currentSiteAccess['name'], eZINI::instance()->variable('SiteAccessSettings', 'MobileSiteAccessList'))) {
         $currentUrl = eZSys::serverURL() . eZSys::requestURI();
         $redirectUrl = eZINI::instance()->variable('SiteAccessSettings', 'MobileSiteAccessURL');
         // Do not redirect if already on the redirect url
         if (strpos($currentUrl, $redirectUrl) !== 0) {
             // Default siteaccess name needs to be removed from the uri when redirecting
             $uri = explode('/', ltrim(eZSys::requestURI(), '/'));
             if (array_shift($uri) == $currentSiteAccess['name']) {
                 $http->redirect($redirectUrl . '/' . implode('/', $uri));
             } else {
                 $http->redirect($redirectUrl . eZSys::requestURI());
             }
         }
         eZExecution::cleanExit();
     }
 }
Exemplo n.º 12
0
 /**
  * \static
  * \param  $inSSL  The desired access mode.
  *
  * Change access mode (HTTP/HTTPS):
  * - If previous mode was HHTP but $inSSL is true, we switch to SSL.
  * - If previous mode was SSL  but $inSSL is false, we switch to HTTP.
  * - Otherwise no mode change is occured.
  *
  * Mode change is done by redirect to the same URL, but with changed
  * protocol (http/https) and TCP port.
  *
  * In case of mode change this method does not return (exit() is called).
  */
 static function switchIfNeeded($inSSL)
 {
     // if it's undefined whether we should redirect  we do nothing
     if (!isset($inSSL)) {
         return;
     }
     // $nowSSl is true if current access mode is HTTPS.
     $nowSSL = eZSys::isSSLNow();
     $requestURI = eZSys::requestURI();
     $indexDir = eZSys::indexDir(false);
     // If there are any $_GET parameters, those should be passed into the new URI
     $getString = eZSys::queryString();
     $sslZoneRedirectionURL = false;
     if ($nowSSL && !$inSSL) {
         // switch to plain HTTP
         $ini = eZINI::instance();
         $host = $ini->variable('SiteSettings', 'SiteURL');
         $port = parse_url("http://{$host}", PHP_URL_PORT);
         $host = eZSys::serverVariable('HTTP_HOST');
         $host = preg_replace('/:\\d+$/', '', $host);
         if ($port && $port != 80) {
             $host .= ":{$port}";
         }
         $sslZoneRedirectionURL = "http://" . $host . $indexDir . $requestURI . $getString;
     } elseif (!$nowSSL && $inSSL) {
         // switch to HTTPS
         $host = eZSys::serverVariable('HTTP_HOST');
         $host = preg_replace('/:\\d+$/', '', $host);
         $ini = eZINI::instance();
         $sslPort = $ini->variable('SiteSettings', 'SSLPort');
         $sslPortString = $sslPort == eZSSLZone::DEFAULT_SSL_PORT ? '' : ":{$sslPort}";
         $sslZoneRedirectionURL = "https://" . $host . $sslPortString . $indexDir . $requestURI . $getString;
     }
     if ($sslZoneRedirectionURL) {
         eZDebugSetting::writeDebug('kernel-ssl-zone', "redirecting to [{$sslZoneRedirectionURL}]");
         eZHTTPTool::redirect($sslZoneRedirectionURL, array(), false, false);
         eZExecution::cleanExit();
     }
 }
Exemplo n.º 13
0
    /**
     * \static
     * \param  $inSSL  The desired access mode.
     *
     * Change access mode (HTTP/HTTPS):
     * - If previous mode was HHTP but $inSSL is true, we switch to SSL.
     * - If previous mode was SSL  but $inSSL is false, we switch to HTTP.
     * - Otherwise no mode change is occured.
     *
     * Mode change is done by redirect to the same URL, but with changed
     * protocol (http/https) and TCP port.
     *
     * In case of mode change this method does not return (exit() is called).
     */
    static function switchIfNeeded( $inSSL )
    {
        // if it's undefined whether we should redirect  we do nothing
        if ( !isset( $inSSL ) )
            return;

        // $nowSSl is true if current access mode is HTTPS.
        $nowSSL = eZSys::isSSLNow();

        $requestURI = eZSys::requestURI();
        $indexDir = eZSys::indexDir( false );

        $sslZoneRedirectionURL = false;
        if ( $nowSSL && !$inSSL )
        {
            // switch to plain HTTP
            $ini = eZINI::instance();
            $host = $ini->variable( 'SiteSettings', 'SiteURL' );
            $sslZoneRedirectionURL = "http://" . $host . $indexDir . $requestURI;
        }
        elseif ( !$nowSSL && $inSSL )
        {
            // switch to HTTPS
            $host = eZSys::serverVariable( 'HTTP_HOST' );
            $host = preg_replace( '/:\d+$/', '', $host );

            $ini = eZINI::instance();
            $sslPort = $ini->variable( 'SiteSettings', 'SSLPort' );
            $sslPortString = ( $sslPort == eZSSLZone::DEFAULT_SSL_PORT ) ? '' : ":$sslPort";
            $sslZoneRedirectionURL = "https://" . $host  . $sslPortString . $indexDir . $requestURI;
        }

        if ( $sslZoneRedirectionURL ) // if a redirection URL is found
        {
            eZDebugSetting::writeDebug( 'kernel-ssl-zone', "redirecting to [$sslZoneRedirectionURL]" );
            eZHTTPTool::redirect( $sslZoneRedirectionURL, array(), false, false );
            eZExecution::cleanExit();
        }
    }
Exemplo n.º 14
0
 /**
  * @return array Urls to access user and admin siteaccesses
  */
 function siteaccessURLs()
 {
     $siteType = $this->chosenSiteType();
     $url = $siteType['url'];
     if (!preg_match("#^[a-zA-Z0-9]+://(.*)\$#", $url)) {
         $url = 'http://' . $url;
     }
     $currentURL = $url;
     $adminURL = $url;
     if ($siteType['access_type'] == 'url') {
         $ini = eZINI::instance();
         if ($ini->hasVariable('SiteSettings', 'DefaultAccess')) {
             $siteType['access_type_value'] = $ini->variable('SiteSettings', 'DefaultAccess');
         }
         $url .= '/' . $siteType['access_type_value'];
         $adminURL .= '/' . $siteType['admin_access_type_value'];
     } else {
         if ($siteType['access_type'] == 'hostname') {
             $url = $siteType['access_type_value'];
             $adminURL = $siteType['admin_access_type_value'];
             if (!preg_match("#^[a-zA-Z0-9]+://(.*)\$#", $url)) {
                 $url = 'http://' . $url;
             }
             if (!preg_match("#^[a-zA-Z0-9]+://(.*)\$#", $adminURL)) {
                 $adminURL = 'http://' . $adminURL;
             }
             $url .= eZSys::indexDir(false);
             $adminURL .= eZSys::indexDir(false);
         } else {
             if ($siteType['access_type'] == 'port') {
                 $url = eZHTTPTool::createRedirectURL($currentURL, array('override_port' => $siteType['access_type_value']));
                 $adminURL = eZHTTPTool::createRedirectURL($currentURL, array('override_port' => $siteType['admin_access_type_value']));
             }
         }
     }
     $siteaccessURL = array('url' => $url, 'admin_url' => $adminURL);
     return $siteaccessURL;
 }
Exemplo n.º 15
0
 /**
  * Goes trough the access matching rules and returns the access match.
  * The returned match is an associative array with:
  *  name     => string Name of the siteaccess (same as folder name)
  *  type     => int The constant that represent the matching used
  *  uri_part => array(string) List of path elements that was used in start of url for the match
  *
  * @since 4.4
  * @param eZURI $uri
  * @param string $host
  * @param string(numeric) $port
  * @param string $file Example '/index.php'
  * @return array
  */
 public static function match(eZURI $uri, $host, $port = 80, $file = '/index.php')
 {
     eZDebugSetting::writeDebug('kernel-siteaccess', array('uri' => $uri, 'host' => $host, 'port' => $port, 'file' => $file), __METHOD__);
     $ini = eZINI::instance();
     if ($ini->hasVariable('SiteAccessSettings', 'StaticMatch')) {
         $match = $ini->variable('SiteAccessSettings', 'StaticMatch');
         if ($match != '') {
             $access = array('name' => $match, 'type' => eZSiteAccess::TYPE_STATIC, 'uri_part' => array());
             return $access;
         }
     }
     list($siteAccessList, $order) = $ini->variableMulti('SiteAccessSettings', array('AvailableSiteAccessList', 'MatchOrder'));
     $access = array('name' => $ini->variable('SiteSettings', 'DefaultAccess'), 'type' => eZSiteAccess::TYPE_DEFAULT, 'uri_part' => array());
     if ($order == 'none') {
         return $access;
     }
     $order = $ini->variableArray('SiteAccessSettings', 'MatchOrder');
     // Change the default type to eZSiteAccess::TYPE_URI if we're using URI MatchOrder.
     // This is to keep backward compatiblity with the ezurl operator. ezurl has since
     // rev 4949 added default siteaccess to generated URLs, even when there is
     // no siteaccess in the current URL.
     if (in_array('uri', $order)) {
         $access['type'] = eZSiteAccess::TYPE_URI;
     }
     foreach ($order as $matchprobe) {
         $name = '';
         $type = '';
         $match_type = '';
         $uri_part = array();
         switch ($matchprobe) {
             case 'servervar':
                 if ($serversiteaccess = eZSys::serverVariable($ini->variable('SiteAccessSettings', 'ServerVariableName'), true)) {
                     $access['name'] = $serversiteaccess;
                     $access['type'] = eZSiteAccess::TYPE_SERVER_VAR;
                     return $access;
                 } else {
                     continue;
                 }
                 break;
             case 'port':
                 if ($ini->hasVariable('PortAccessSettings', $port)) {
                     $access['name'] = $ini->variable('PortAccessSettings', $port);
                     $access['type'] = eZSiteAccess::TYPE_PORT;
                     return $access;
                 } else {
                     continue;
                 }
                 break;
             case 'uri':
                 $type = eZSiteAccess::TYPE_URI;
                 $match_type = $ini->variable('SiteAccessSettings', 'URIMatchType');
                 if ($match_type == 'map') {
                     if ($ini->hasVariable('SiteAccessSettings', 'URIMatchMapItems')) {
                         $match_item = $uri->element(0);
                         $matchMapItems = $ini->variableArray('SiteAccessSettings', 'URIMatchMapItems');
                         foreach ($matchMapItems as $matchMapItem) {
                             $matchMapURI = $matchMapItem[0];
                             $matchMapAccess = $matchMapItem[1];
                             if ($access['name'] == $matchMapAccess and in_array($matchMapAccess, $siteAccessList)) {
                                 $uri_part = array($matchMapURI);
                             }
                             if ($matchMapURI == $match_item and in_array($matchMapAccess, $siteAccessList)) {
                                 $uri->increase(1);
                                 $uri->dropBase();
                                 $access['name'] = $matchMapAccess;
                                 $access['type'] = $type;
                                 $access['uri_part'] = array($matchMapURI);
                                 return $access;
                             }
                         }
                     }
                 } else {
                     if ($match_type == 'element') {
                         $match_index = $ini->variable('SiteAccessSettings', 'URIMatchElement');
                         $elements = $uri->elements(false);
                         $elements = array_slice($elements, 0, $match_index);
                         $name = implode('_', $elements);
                         $uri_part = $elements;
                     } else {
                         if ($match_type == 'text') {
                             $match_item = $uri->elements();
                             $matcher_pre = $ini->variable('SiteAccessSettings', 'URIMatchSubtextPre');
                             $matcher_post = $ini->variable('SiteAccessSettings', 'URIMatchSubtextPost');
                         } else {
                             if ($match_type == 'regexp') {
                                 $match_item = $uri->elements();
                                 $matcher = $ini->variable('SiteAccessSettings', 'URIMatchRegexp');
                                 $match_num = $ini->variable('SiteAccessSettings', 'URIMatchRegexpItem');
                             } else {
                                 continue;
                             }
                         }
                     }
                 }
                 break;
             case 'host':
                 $type = eZSiteAccess::TYPE_HTTP_HOST;
                 $match_type = $ini->variable('SiteAccessSettings', 'HostMatchType');
                 $match_item = $host;
                 if ($match_type == 'map') {
                     if ($ini->hasVariable('SiteAccessSettings', 'HostMatchMapItems')) {
                         $matchMapItems = $ini->variableArray('SiteAccessSettings', 'HostMatchMapItems');
                         foreach ($matchMapItems as $matchMapItem) {
                             $matchMapHost = $matchMapItem[0];
                             $matchMapAccess = $matchMapItem[1];
                             if ($matchMapHost == $host) {
                                 $access['name'] = $matchMapAccess;
                                 $access['type'] = $type;
                                 return $access;
                             }
                         }
                     }
                 } else {
                     if ($match_type == 'element') {
                         $match_index = $ini->variable('SiteAccessSettings', 'HostMatchElement');
                         $match_arr = explode('.', $match_item);
                         $name = $match_arr[$match_index];
                     } else {
                         if ($match_type == 'text') {
                             $matcher_pre = $ini->variable('SiteAccessSettings', 'HostMatchSubtextPre');
                             $matcher_post = $ini->variable('SiteAccessSettings', 'HostMatchSubtextPost');
                         } else {
                             if ($match_type == 'regexp') {
                                 $matcher = $ini->variable('SiteAccessSettings', 'HostMatchRegexp');
                                 $match_num = $ini->variable('SiteAccessSettings', 'HostMatchRegexpItem');
                             } else {
                                 continue;
                             }
                         }
                     }
                 }
                 break;
             case 'host_uri':
                 $type = eZSiteAccess::TYPE_HTTP_HOST_URI;
                 if ($ini->hasVariable('SiteAccessSettings', 'HostUriMatchMapItems')) {
                     $uriString = $uri->elements();
                     $matchMapItems = $ini->variableArray('SiteAccessSettings', 'HostUriMatchMapItems');
                     $defaultHostMatchMethod = $ini->variable('SiteAccessSettings', 'HostUriMatchMethodDefault');
                     foreach ($matchMapItems as $matchMapItem) {
                         $matchHost = $matchMapItem[0];
                         $matchURI = $matchMapItem[1];
                         $matchAccess = $matchMapItem[2];
                         $matchHostMethod = isset($matchMapItem[3]) ? $matchMapItem[3] : $defaultHostMatchMethod;
                         if ($matchURI !== '' && !preg_match("@^{$matchURI}\\b@", $uriString)) {
                             continue;
                         }
                         switch ($matchHostMethod) {
                             case 'strict':
                                 $hasHostMatch = $matchHost === $host;
                                 break;
                             case 'start':
                                 $hasHostMatch = strpos($host, $matchHost) === 0;
                                 break;
                             case 'end':
                                 $hasHostMatch = strstr($host, $matchHost) === $matchHost;
                                 break;
                             case 'part':
                                 $hasHostMatch = strpos($host, $matchHost) !== false;
                                 break;
                             default:
                                 $hasHostMatch = false;
                                 eZDebug::writeError("Unknown host_uri host match: {$matchHostMethod}", "access");
                                 break;
                         }
                         if ($hasHostMatch) {
                             if ($matchURI !== '') {
                                 $matchURIFolders = explode('/', $matchURI);
                                 $uri->increase(count($matchURIFolders));
                                 $uri->dropBase();
                                 $access['uri_part'] = $matchURIFolders;
                             }
                             $access['name'] = $matchAccess;
                             $access['type'] = $type;
                             return $access;
                         }
                     }
                 }
                 break;
             case 'index':
                 $type = eZSiteAccess::TYPE_INDEX_FILE;
                 $match_type = $ini->variable('SiteAccessSettings', 'IndexMatchType');
                 $match_item = $file;
                 if ($match_type == 'element') {
                     $match_index = $ini->variable('SiteAccessSettings', 'IndexMatchElement');
                     $match_pos = strpos($match_item, '.php');
                     if ($match_pos !== false) {
                         $match_item = substr($match_item, 0, $match_pos);
                         $match_arr = explode('_', $match_item);
                         $name = $match_arr[$match_index];
                     }
                 } else {
                     if ($match_type == 'text') {
                         $matcher_pre = $ini->variable('SiteAccessSettings', 'IndexMatchSubtextPre');
                         $matcher_post = $ini->variable('SiteAccessSettings', 'IndexMatchSubtextPost');
                     } else {
                         if ($match_type == 'regexp') {
                             $matcher = $ini->variable('SiteAccessSettings', 'IndexMatchRegexp');
                             $match_num = $ini->variable('SiteAccessSettings', 'IndexMatchRegexpItem');
                         } else {
                             continue;
                         }
                     }
                 }
                 break;
             default:
                 eZDebug::writeError("Unknown access match: {$matchprobe}", "access");
                 break;
         }
         if ($match_type == 'regexp') {
             $name = self::matchRegexp($match_item, $matcher, $match_num);
         } else {
             if ($match_type == 'text') {
                 $name = self::matchText($match_item, $matcher_pre, $matcher_post);
             }
         }
         if (isset($name) && $name != '') {
             $nameClean = self::washName($name);
             if (in_array($nameClean, $siteAccessList)) {
                 if ($nameClean !== $name) {
                     if (!$ini->hasVariable('SiteAccessSettings', 'NormalizeSANames') || $ini->variable('SiteAccessSettings', 'NormalizeSANames') == 'enabled') {
                         $name = $nameClean;
                         if ($ini->hasVariable('SiteAccessSettings', 'RedirectOnNormalize') && $ini->variable('SiteAccessSettings', 'RedirectOnNormalize') == 'enabled') {
                             header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently");
                             header("Status: 301 Moved Permanently");
                             $uriSlice = $uri->URIArray;
                             array_shift($uriSlice);
                             $newUri = $name . '/' . implode('/', $uriSlice);
                             $location = eZSys::indexDir() . "/" . eZURI::encodeIRI($newUri);
                             header("Location: " . $location);
                             eZExecution::cleanExit();
                         }
                     }
                 }
                 if ($type == eZSiteAccess::TYPE_URI) {
                     if ($match_type == 'element') {
                         $uri->increase($match_index);
                         $uri->dropBase();
                     } else {
                         if ($match_type == 'regexp') {
                             $uri->setURIString($match_item);
                         } else {
                             if ($match_type == 'text') {
                                 $uri->setURIString($match_item);
                             }
                         }
                     }
                 }
                 $access['type'] = $type;
                 $access['name'] = $name;
                 $access['uri_part'] = $uri_part;
                 return $access;
             }
         }
     }
     return $access;
 }
Exemplo n.º 16
0
 function display()
 {
     $config = eZINI::instance('setup.ini');
     $siteType = $this->chosenSiteType();
     $availableDatabaseList = false;
     if (isset($this->PersistenceList['database_info_available'])) {
         $availableDatabaseList = $this->PersistenceList['database_info_available'];
     }
     $databaseList = $availableDatabaseList;
     $databaseCounter = 0;
     if (!isset($siteType['title'])) {
         $siteType['title'] = $siteType['name'];
     }
     $siteType['errors'] = array();
     if (!isset($siteType['url'])) {
         $siteType['url'] = 'http://' . eZSys::hostName() . eZSys::indexDir(false);
     }
     if (!isset($siteType['site_access_illegal'])) {
         $siteType['site_access_illegal'] = false;
     }
     if (!isset($siteType['db_already_chosen'])) {
         $siteType['db_already_chosen'] = false;
     }
     if (!isset($siteType['db_not_empty'])) {
         $siteType['db_not_empty'] = 0;
     }
     if (!isset($siteType['database'])) {
         if (is_array($databaseList)) {
             $matchedDBName = false;
             // First try database name match
             foreach ($databaseList as $databaseName) {
                 $dbName = trim(strtolower($databaseName));
                 $identifier = trim(strtolower($siteType['identifier']));
                 if ($dbName == $identifier) {
                     $matchedDBName = $databaseName;
                     break;
                 }
             }
             if (!$matchedDBName) {
                 $matchedDBName = $databaseList[$databaseCounter++];
             }
             $databaseList = array_values(array_diff($databaseList, array($matchedDBName)));
             $siteType['database'] = $matchedDBName;
         } else {
             $siteType['database'] = '';
         }
     }
     if (!isset($siteType['existing_database'])) {
         $siteType['existing_database'] = eZStepInstaller::DB_DATA_APPEND;
     }
     $this->Tpl->setVariable('db_not_empty', 0);
     $this->Tpl->setVariable('db_already_chosen', 0);
     $this->Tpl->setVariable('db_charset_differs', 0);
     $this->Tpl->setVariable('site_access_illegal', 0);
     $this->Tpl->setVariable('site_access_illegal_name', 0);
     // TODO: remove sites error array
     if (isset($this->Error[0])) {
         $error = $this->Error[0];
         $type = 'site';
         if (is_array($error)) {
             $type = $error['type'];
             $error = $error['error_code'];
         }
         if ($type == 'site') {
             switch ($error) {
                 case eZStepInstaller::DB_ERROR_NOT_EMPTY:
                     $this->Tpl->setVariable('db_not_empty', 1);
                     $siteType['db_not_empty'] = 1;
                     break;
                 case eZStepInstaller::DB_ERROR_ALREADY_CHOSEN:
                     $this->Tpl->setVariable('db_already_chosen', 1);
                     $siteType['db_already_chosen'] = 1;
                     break;
                 case self::SITE_ACCESS_ILLEGAL:
                     $this->Tpl->setVariable('site_access_illegal', 1);
                     $siteType['site_access_illegal'] = 1;
                     break;
             }
         } else {
             if ($type == 'db') {
                 if ($error == eZStepInstaller::DB_ERROR_CHARSET_DIFFERS) {
                     $this->Tpl->setVariable('db_charset_differs', 1);
                 }
                 $siteType['errors'][] = $this->databaseErrorInfo(array('error_code' => $error, 'database_info' => $this->PersistenceList['database_info'], 'site_type' => $siteType));
             }
         }
     }
     $this->storeSiteType($siteType);
     $this->Tpl->setVariable('database_default', $config->variable('DatabaseSettings', 'DefaultName'));
     $this->Tpl->setVariable('database_available', $availableDatabaseList);
     $this->Tpl->setVariable('site_type', $siteType);
     // Return template and data to be shown
     $result = array();
     // Display template
     $result['content'] = $this->Tpl->fetch('design:setup/init/site_details.tpl');
     $result['path'] = array(array('text' => ezpI18n::tr('design/standard/setup/init', 'Site details'), 'url' => false));
     return $result;
 }
Exemplo n.º 17
0
if ($errorHandlerType != 'redirect') {
    // Set apache error headers if error.ini tells us to
    if ($errorINI->hasVariable('ErrorSettings-' . $errorType, 'HTTPError')) {
        $errorMap = $errorINI->variable('ErrorSettings-' . $errorType, 'HTTPError');
        if (isset($errorMap[$errorNumber])) {
            $httpErrorCode = $errorMap[$errorNumber];
            if ($errorINI->hasVariable('HTTPError-' . $httpErrorCode, 'HTTPName')) {
                $httpErrorName = $errorINI->variable('HTTPError-' . $httpErrorCode, 'HTTPName');
                $httpErrorString = "{$httpErrorCode} {$httpErrorName}";
                header(eZSys::serverVariable('SERVER_PROTOCOL') . " {$httpErrorString}");
                header("Status: {$httpErrorString}");
                if ($errorNumber == eZError::KERNEL_MOVED) {
                    // Set moved permanently headers.
                    header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently");
                    header("Status: 301 Moved Permanently");
                    $location = eZSys::indexDir() . "/" . eZURI::encodeIRI($extraErrorParameters['new_location']);
                    // Make sure it is encoded to IRI format
                    header("Location: " . $location);
                }
            }
        }
    }
}
if ($errorHandlerType == 'redirect') {
    $errorRedirectURL = $errorINI->variable('ErrorSettings', 'DefaultRedirectURL');
    if (isset($redirectURLList[$errorNumber])) {
        $errorRedirectURL = $redirectURLList[$errorNumber];
    }
    return $module->redirectTo($errorRedirectURL);
} else {
    if ($errorHandlerType == 'rerun') {