public function initContent() { if ((empty($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'off') && Configuration::get('PS_SSL_ENABLED')) { // You can uncomment these lines if you want to force https even from localhost and automatically redirect // header('HTTP/1.1 301 Moved Permanently'); // header('Location: '.Tools::getShopDomainSsl(true).$_SERVER['REQUEST_URI']); // exit(); $clientIsMaintenanceOrLocal = in_array(Tools::getRemoteAddr(), array_merge(array('127.0.0.1'), explode(',', Configuration::get('PS_MAINTENANCE_IP')))); // If ssl is enabled, https protocol is required. Exception for maintenance and local (127.0.0.1) IP if ($clientIsMaintenanceOrLocal) { $this->errors[] = Tools::displayError('SSL is activated. However, your IP is allowed to use unsecure mode (Maintenance or local IP).'); } else { $warningSslMessage = Tools::displayError('SSL is activated. Please connect using the following url to log in in secure mode (https).'); $warningSslMessage .= '<a href="https://' . Tools::safeOutput(Tools::getServerName()) . Tools::safeOutput($_SERVER['REQUEST_URI']) . '">https://' . Tools::safeOutput(Tools::getServerName()) . Tools::safeOutput($_SERVER['REQUEST_URI']) . '</a>'; $this->context->smarty->assign(array('warningSslMessage' => $warningSslMessage)); } } if (file_exists(_PS_ADMIN_DIR_ . '/../install') || file_exists(_PS_ADMIN_DIR_ . '/../admin')) { $this->context->smarty->assign(array('randomNb' => rand(100, 999), 'wrong_folder_name' => true)); } // Redirect to admin panel if (Tools::isSubmit('redirect') && Validate::isControllerName(Tools::getValue('redirect'))) { $this->context->smarty->assign('redirect', Tools::getValue('redirect')); } else { $tab = new Tab((int) $this->context->employee->default_tab); $this->context->smarty->assign('redirect', $this->context->link->getAdminLink($tab->class_name)); } if ($nb_errors = count($this->errors)) { $this->context->smarty->assign(array('errors' => $this->errors, 'nbErrors' => $nb_errors, 'shop_name' => Tools::safeOutput(Configuration::get('PS_SHOP_NAME')), 'disableDefaultErrorOutPut' => true)); } $this->setMedia(); $this->initHeader(); parent::initContent(); $this->initFooter(); }
public function initContent() { if (!Tools::usingSecureMode() && Configuration::get('PS_SSL_ENABLED')) { // You can uncomment these lines if you want to force https even from localhost and automatically redirect // header('HTTP/1.1 301 Moved Permanently'); // header('Location: '.Tools::getShopDomainSsl(true).$_SERVER['REQUEST_URI']); // exit(); $clientIsMaintenanceOrLocal = in_array(Tools::getRemoteAddr(), array_merge(array('127.0.0.1'), explode(',', Configuration::get('PS_MAINTENANCE_IP')))); // If ssl is enabled, https protocol is required. Exception for maintenance and local (127.0.0.1) IP if ($clientIsMaintenanceOrLocal) { $warningSslMessage = Tools::displayError('SSL is activated. However, your IP is allowed to enter unsecure mode for maintenance or local IP issues.'); } else { $url = 'https://' . Tools::safeOutput(Tools::getServerName()) . Tools::safeOutput($_SERVER['REQUEST_URI']); $warningSslMessage = sprintf(Translate::ppTags(Tools::displayError('SSL is activated. Please connect using the following link to [1]log into secure mode (https://)[/1]', false), array('<a href="%s">')), $url); } $this->context->smarty->assign('warningSslMessage', $warningSslMessage); } if (file_exists(_PS_ADMIN_DIR_ . '/../install')) { $this->context->smarty->assign('wrong_install_name', true); } if (basename(_PS_ADMIN_DIR_) == 'admin' && file_exists(_PS_ADMIN_DIR_ . '/../admin/')) { $rand = 'admin' . sprintf('%03d', rand(0, 999)) . Tools::strtolower(Tools::passwdGen(6)) . '/'; if (@rename(_PS_ADMIN_DIR_ . '/../admin/', _PS_ADMIN_DIR_ . '/../' . $rand)) { Tools::redirectAdmin('../' . $rand); } else { $this->context->smarty->assign(array('wrong_folder_name' => true)); } } else { $rand = basename(_PS_ADMIN_DIR_) . '/'; } $this->context->smarty->assign(array('randomNb' => $rand, 'adminUrl' => Tools::getCurrentUrlProtocolPrefix() . Tools::getShopDomain() . __PS_BASE_URI__ . $rand)); // Redirect to admin panel if (Tools::isSubmit('redirect') && Validate::isControllerName(Tools::getValue('redirect'))) { $this->context->smarty->assign('redirect', Tools::getValue('redirect')); } else { $tab = new Tab((int) $this->context->employee->default_tab); $this->context->smarty->assign('redirect', $this->context->link->getAdminLink($tab->class_name)); } if ($nb_errors = count($this->errors)) { $this->context->smarty->assign(array('errors' => $this->errors, 'nbErrors' => $nb_errors, 'shop_name' => Tools::safeOutput(Configuration::get('PS_SHOP_NAME')), 'disableDefaultErrorOutPut' => true)); } if ($email = Tools::getValue('email')) { $this->context->smarty->assign('email', $email); } if ($password = Tools::getValue('password')) { $this->context->smarty->assign('password', $password); } $this->setMedia(); $this->initHeader(); parent::initContent(); $this->initFooter(); //force to disable modals $this->context->smarty->assign('modals', null); }
/** * Secure an URL referrer * * @param string $referrer URL referrer * * @return string secured referrer */ public static function secureReferrer($referrer) { if (preg_match('/^http[s]?:\\/\\/' . Tools::getServerName() . '(:' . _PS_SSL_PORT_ . ')?\\/.*$/Ui', $referrer)) { return $referrer; } return __PS_BASE_URI__; }
/** * 判断是否本站链接 * * @param $referrer * * @return string */ public static function secureReferrer($referrer) { if (preg_match('/^http[s]?:\\/\\/' . Tools::getServerName() . '(:443)?\\/.*$/Ui', $referrer)) { return $referrer; } return '/'; }
ob_start(); define('PS_ADMIN_DIR', getcwd()); include PS_ADMIN_DIR . '/../config/config.inc.php'; include PS_ADMIN_DIR . '/functions.php'; $clientIsMaintenanceOrLocal = in_array(Tools::getRemoteAddr(), array_merge(array('127.0.0.1'), explode(',', Configuration::get('PS_MAINTENANCE_IP')))); $errors = array(); if ((empty($_SERVER['HTTPS']) or strtolower($_SERVER['HTTPS']) == 'off') and Configuration::get('PS_SSL_ENABLED')) { // You can uncomment theses lines if you want to force https even from localhost and automatically redirect // header('HTTP/1.1 301 Moved Permanently'); // header('Location: '.Tools::getShopDomainSsl(true).$_SERVER['REQUEST_URI']); // exit(); // If ssl is enabled, https protocol is required. Exception for maintenance and local (127.0.0.1) IP if ($clientIsMaintenanceOrLocal) { $errors[] = translate('SSL is activated. However, your IP is allowed to use unsecure mode (Maintenance or local IP).') . '<br/>'; } else { $warningSslMessage = translate('SSL is activated. Please connect using the following url to log in in secure mode (https).') . '<br/><br/><a href="https://' . Tools::getServerName() . $_SERVER['REQUEST_URI'] . '">https://' . Tools::getServerName() . $_SERVER['REQUEST_URI'] . '</a>'; } } $cookie = new Cookie('psAdmin', substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__), -10)); if (!isset($cookie->id_lang)) { $cookie->id_lang = Configuration::get('PS_LANG_DEFAULT'); } $iso = strtolower(Language::getIsoById((int) $cookie->id_lang)); include _PS_TRANSLATIONS_DIR_ . $iso . '/admin.php'; include _PS_TRANSLATIONS_DIR_ . $iso . '/errors.php'; /* Cookie creation and redirection */ if (Tools::isSubmit('Submit')) { /* Check fields validity */ $passwd = trim(Tools::getValue('passwd')); $email = trim(Tools::getValue('email')); if (empty($email)) {
public function init() { global $useSSL, $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files; if (self::$initialized) { return; } self::$initialized = true; $css_files = array(); $js_files = array(); if ($this->ssl and !Tools::usingSecureMode() and Configuration::get('PS_SSL_ENABLED')) { header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . Tools::getShopDomainSsl(true) . $_SERVER['REQUEST_URI']); exit; } else { if (Configuration::get('PS_SSL_ENABLED') and Tools::usingSecureMode() and !$this->ssl) { header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . Tools::getShopDomain(true) . $_SERVER['REQUEST_URI']); exit; } } ob_start(); /* Loading default country */ $defaultCountry = new Country((int) Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT')); $cookieLifetime = time() + ((int) Configuration::get('PS_COOKIE_LIFETIME_FO') > 0 ? (int) Configuration::get('PS_COOKIE_LIFETIME_FO') : 1) * 3600; $cookie = new Cookie('ps', '', $cookieLifetime); $link = new Link(); if ($this->auth and !$cookie->isLogged($this->guestAllowed)) { Tools::redirect('authentication.php' . ($this->authRedirection ? '?back=' . $this->authRedirection : '')); } /* Theme is missing or maintenance */ if (!is_dir(_PS_THEME_DIR_)) { die(Tools::displayError('Current theme unavailable. Please check your theme directory name and permissions.')); } elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' and !(int) Configuration::get('PS_SHOP_ENABLE')) { $this->maintenance = true; } elseif (Configuration::get('PS_GEOLOCATION_ENABLED')) { $this->geolocationManagement(); } // Switch language if needed and init cookie language if ($iso = Tools::getValue('isolang') and Validate::isLanguageIsoCode($iso) and $id_lang = (int) Language::getIdByIso($iso)) { $_GET['id_lang'] = $id_lang; } Tools::switchLanguage(); Tools::setCookieLanguage(); /* attribute id_lang is often needed, so we create a constant for performance reasons */ if (!defined('_USER_ID_LANG_')) { define('_USER_ID_LANG_', (int) $cookie->id_lang); } if (isset($_GET['logout']) or $cookie->logged and Customer::isBanned((int) $cookie->id_customer)) { $cookie->logout(); Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL); } elseif (isset($_GET['mylogout'])) { $cookie->mylogout(); Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL); } global $currency; $currency = Tools::setCurrency(); /* Cart already exists */ if ((int) $cookie->id_cart) { $cart = new Cart((int) $cookie->id_cart); if ($cart->OrderExists()) { unset($cookie->id_cart, $cart, $cookie->checkedTOS); } elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) and !in_array(strtoupper($cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) and $cart->nbProducts() and intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 and !self::isInWhitelistForGeolocation()) { unset($cookie->id_cart, $cart); } elseif ($cookie->id_customer != $cart->id_customer or $cookie->id_lang != $cart->id_lang or $cookie->id_currency != $cart->id_currency) { if ($cookie->id_customer) { $cart->id_customer = (int) $cookie->id_customer; } $cart->id_lang = (int) $cookie->id_lang; $cart->id_currency = (int) $cookie->id_currency; $cart->update(); } /* Select an address if not set */ if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 || !isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $cookie->id_customer) { $to_update = false; if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0) { $to_update = true; $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer); } if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) { $to_update = true; $cart->id_address_invoice = (int) Address::getFirstCustomerAddressId($cart->id_customer); } if ($to_update) { $cart->update(); } } } if (!isset($cart) or !$cart->id) { $cart = new Cart(); $cart->id_lang = (int) $cookie->id_lang; $cart->id_currency = (int) $cookie->id_currency; $cart->id_guest = (int) $cookie->id_guest; if ($cookie->id_customer) { $cart->id_customer = (int) $cookie->id_customer; $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer); $cart->id_address_invoice = $cart->id_address_delivery; } else { $cart->id_address_delivery = 0; $cart->id_address_invoice = 0; } } if (!$cart->nbProducts()) { $cart->id_carrier = NULL; } $locale = strtolower(Configuration::get('PS_LOCALE_LANGUAGE')) . '_' . strtoupper(Configuration::get('PS_LOCALE_COUNTRY') . '.UTF-8'); setlocale(LC_COLLATE, $locale); setlocale(LC_CTYPE, $locale); setlocale(LC_TIME, $locale); setlocale(LC_NUMERIC, 'en_US.UTF-8'); if (Validate::isLoadedObject($currency)) { $smarty->ps_currency = $currency; } if (Validate::isLoadedObject($ps_language = new Language((int) $cookie->id_lang))) { $smarty->ps_language = $ps_language; } /* get page name to display it in body id */ $page_name = isset($this->php_self) ? preg_replace('/\\.php$/', '', $this->php_self) : ''; if (preg_match('#^' . __PS_BASE_URI__ . 'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m)) { $page_name = 'module-' . $m[1] . '-' . str_replace(array('.php', '/'), array('', '-'), $m[2]); } $smarty->assign(Tools::getMetaTags($cookie->id_lang, $page_name)); $smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); /* Breadcrumb */ $navigationPipe = Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>'; $smarty->assign('navigationPipe', $navigationPipe); $protocol_link = (Configuration::get('PS_SSL_ENABLED') or Tools::usingSecureMode()) ? 'https://' : 'http://'; $useSSL = (isset($this->ssl) and $this->ssl and Configuration::get('PS_SSL_ENABLED') or Tools::usingSecureMode()) ? true : false; $protocol_content = $useSSL ? 'https://' : 'http://'; if (!defined('_PS_BASE_URL_')) { define('_PS_BASE_URL_', Tools::getShopDomain(true)); } if (!defined('_PS_BASE_URL_SSL_')) { define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true)); } $link->preloadPageLinks(); $this->canonicalRedirection(); Product::initPricesComputation(); $display_tax_label = $defaultCountry->display_tax_label; if ($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) { $infos = Address::getCountryAndState((int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $country = new Country((int) $infos['id_country']); if (Validate::isLoadedObject($country)) { $display_tax_label = $country->display_tax_label; } } $smarty->assign(array('link' => $link, 'cart' => $cart, 'currency' => $currency, 'cookie' => $cookie, 'page_name' => $page_name, 'base_dir' => _PS_BASE_URL_ . __PS_BASE_URI__, 'base_dir_ssl' => $protocol_link . Tools::getShopDomainSsl() . __PS_BASE_URI__, 'content_dir' => $protocol_content . Tools::getServerName() . __PS_BASE_URI__, 'tpl_dir' => _PS_THEME_DIR_, 'modules_dir' => _MODULE_DIR_, 'mail_dir' => _MAIL_DIR_, 'lang_iso' => $ps_language->iso_code, 'come_from' => Tools::getHttpHost(true, true) . Tools::htmlentitiesUTF8(str_replace('\'', '', urldecode($_SERVER['REQUEST_URI']))), 'cart_qties' => (int) $cart->nbProducts(), 'currencies' => Currency::getCurrencies(), 'languages' => Language::getLanguages(), 'priceDisplay' => Product::getTaxCalculationMethod(), 'add_prod_display' => (int) Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'roundMode' => (int) Configuration::get('PS_PRICE_ROUND_MODE'), 'use_taxes' => (int) Configuration::get('PS_TAX'), 'display_tax_label' => (bool) $display_tax_label, 'vat_management' => (int) Configuration::get('VATNUMBER_MANAGEMENT'), 'opc' => (bool) Configuration::get('PS_ORDER_PROCESS_TYPE'), 'PS_CATALOG_MODE' => (bool) Configuration::get('PS_CATALOG_MODE'))); // Deprecated $smarty->assign(array('id_currency_cookie' => (int) $currency->id, 'logged' => $cookie->isLogged(), 'customerName' => $cookie->logged ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : false)); // TODO for better performances (cache usage), remove these assign and use a smarty function to get the right media server in relation to the full ressource name $assignArray = array('img_ps_dir' => _PS_IMG_, 'img_cat_dir' => _THEME_CAT_DIR_, 'img_lang_dir' => _THEME_LANG_DIR_, 'img_prod_dir' => _THEME_PROD_DIR_, 'img_manu_dir' => _THEME_MANU_DIR_, 'img_sup_dir' => _THEME_SUP_DIR_, 'img_ship_dir' => _THEME_SHIP_DIR_, 'img_store_dir' => _THEME_STORE_DIR_, 'img_col_dir' => _THEME_COL_DIR_, 'img_dir' => _THEME_IMG_DIR_, 'css_dir' => _THEME_CSS_DIR_, 'js_dir' => _THEME_JS_DIR_, 'pic_dir' => _THEME_PROD_PIC_DIR_); foreach ($assignArray as $assignKey => $assignValue) { if (substr($assignValue, 0, 1) == '/' or $protocol_content == 'https://') { $smarty->assign($assignKey, $protocol_content . Tools::getMediaServer($assignValue) . $assignValue); } else { $smarty->assign($assignKey, $assignValue); } } // setting properties from global var self::$cookie = $cookie; self::$cart = $cart; self::$smarty = $smarty; self::$link = $link; if ($this->maintenance) { $this->displayMaintenancePage(); } if ($this->restrictedCountry) { $this->displayRestrictedCountryPage(); } //live edit if (Tools::isSubmit('live_edit') and $ad = Tools::getValue('ad') and Tools::getValue('liveToken') == sha1(Tools::getValue('ad') . _COOKIE_KEY_)) { if (!is_dir(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $ad)) { die(Tools::displayError()); } } $this->iso = $iso; $this->setMedia(); }