Ionut Ac Posted February 23, 2017 Share Posted February 23, 2017 Hy. Since now many internet providers work with dynamic IP's is very difficult for a developer to allow a client the changes that he made on his store and keep it in maintenance mode for visitor. Trying to solve this I found this solution so you can allow access via token and ip in the same time. This was tested on prestashop 1.6.1.11 Go to ./classes/controller/FrontController.php Line: 751 Replace: if (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP')))) { header('HTTP/1.1 503 temporarily overloaded'); $this->context->smarty->assign($this->initLogoAndFavicon()); $this->context->smarty->assign(array( 'HOOK_MAINTENANCE' => Hook::exec('displayMaintenance', array()), )); // If the controller is a module, then getTemplatePath will try to find the template in the modules, so we need to instanciate a real frontcontroller $front_controller = preg_match('/ModuleFrontController$/', get_class($this)) ? new FrontController() : $this; $this->smartyOutputContent($front_controller->getTemplatePath($this->getThemeDir().'maintenance.tpl')); exit; } with this: (where "passman" is the parameter that will be passed in url session_start(); if(isset($_GET['passman'])){$_SESSION['passman'] = $_GET['passman'];} if (isset($_SESSION['passman'])){ if(!in_array($_SESSION['passman'], explode(',', Configuration::get('PS_MAINTENANCE_IP')))){ header('HTTP/1.1 503 temporarily overloaded'); $this->context->smarty->assign($this->initLogoAndFavicon()); $this->context->smarty->assign(array( 'HOOK_MAINTENANCE' => Hook::exec('displayMaintenance', array()), )); // If the controller is a module, then getTemplatePath will try to find the template in the modules, so we need to instanciate a real frontcontroller $front_controller = preg_match('/ModuleFrontController$/', get_class($this)) ? new FrontController() : $this; $this->smartyOutputContent($front_controller->getTemplatePath($this->getThemeDir().'maintenance.tpl')); exit; } }else if (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP')))) { header('HTTP/1.1 503 temporarily overloaded'); $this->context->smarty->assign($this->initLogoAndFavicon()); $this->context->smarty->assign(array( 'HOOK_MAINTENANCE' => Hook::exec('displayMaintenance', array()), )); // If the controller is a module, then getTemplatePath will try to find the template in the modules, so we need to instanciate a real frontcontroller $front_controller = preg_match('/ModuleFrontController$/', get_class($this)) ? new FrontController() : $this; $this->smartyOutputContent($front_controller->getTemplatePath($this->getThemeDir().'maintenance.tpl')); exit; } At this point you can go to: Preferences>Maintenance and add to the list a token (string) that can be passed as a parameter and that allow you to pass the maintenance page. As showed int the picture below you can also add an IP to the list. So now you can pass maintenance mode by accessing: http://www.yoursorename.com/?passman=allowusertoken You can send this link to anyone and that person can see the live store skipping the maintenance page. Link to comment Share on other sites More sharing options...
Mercader Virtual Posted May 12, 2020 Share Posted May 12, 2020 For 1.7.5 and probably other 1.7.x versions: /** * Displays maintenance page if shop is closed. */ protected function displayMaintenancePage() { if ($this->maintenance == true || !(int) Configuration::get('PS_SHOP_ENABLE')) { $this->maintenance = true; session_start(); if(isset($_GET['passman'])){ $_SESSION['passman'] = $_GET['passman']; } if ( !in_array($_SESSION['passman'], explode(',', Configuration::get('PS_MAINTENANCE_IP'))) && !in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP')))) { header('HTTP/1.1 503 Service Unavailable'); header('Retry-After: 3600'); $this->registerStylesheet('theme-error', '/assets/css/error.css', ['media' => 'all', 'priority' => 50]); $this->context->smarty->assign(array( 'urls' => $this->getTemplateVarUrls(), 'shop' => $this->getTemplateVarShop(), 'HOOK_MAINTENANCE' => Hook::exec('displayMaintenance', array()), 'maintenance_text' => Configuration::get('PS_MAINTENANCE_TEXT', (int) $this->context->language->id), 'stylesheets' => $this->getStylesheets(), )); $this->smartyOutputContent('errors/maintenance.tpl'); exit; } } } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now