├── modman ├── src └── app │ ├── etc │ └── modules │ │ └── Webgriffe_Maintenance.xml │ └── code │ └── community │ └── Webgriffe │ └── Maintenance │ ├── controllers │ └── IndexController.php │ ├── Model │ └── System │ │ └── Config │ │ └── Source │ │ └── Show.php │ ├── etc │ ├── config.xml │ └── system.xml │ ├── Helper │ └── Data.php │ └── Controller │ └── Router.php ├── composer.json └── README.md /modman: -------------------------------------------------------------------------------- 1 | src/app/code/community/Webgriffe/Maintenance app/code/community/Webgriffe/Maintenance 2 | src/app/etc/modules/* app/etc/modules/ 3 | -------------------------------------------------------------------------------- /src/app/etc/modules/Webgriffe_Maintenance.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | community 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aleron75/webgriffe-maintenance", 3 | "type": "magento-module", 4 | "license":"OSL-3.0", 5 | "description":"Maintenance module for Magento.", 6 | "authors":[ 7 | { 8 | "name":"Alessandro Ronchi", 9 | "email":"aleron75@gmail.com" 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /src/app/code/community/Webgriffe/Maintenance/controllers/IndexController.php: -------------------------------------------------------------------------------- 1 | getCustomMessage(); 7 | $this->getResponse()->setBody($body); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Webgriffe_Maintenance 2 | ===================== 3 | 4 | A maintentance module for Magento 5 | 6 | [![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/) 7 | 8 | Installation 9 | ------------ 10 | Supposed you know what [modman](https://github.com/colinmollenhour/modman) is, you can simply install this module using the following commands: 11 | 12 | ``` 13 | modman init 14 | modman clone git@github.com:aleron75/Webgriffe_Maintenance.git 15 | ``` 16 | 17 | Once installed, clean your Magento cache and compilation (if active) and go to System > Configuration > Advanced > System > Maintenance Page. 18 | 19 | That's all for now. 20 | 21 | -------------------------------------------------------------------------------- /src/app/code/community/Webgriffe/Maintenance/Model/System/Config/Source/Show.php: -------------------------------------------------------------------------------- 1 | self::MODE_CMS, 'label'=>Mage::helper('wgmnt')->__('Cms Page')), 16 | array('value' => self::MODE_MSG, 'label'=>Mage::helper('wgmnt')->__('Custom Message')), 17 | ); 18 | } 19 | 20 | /** 21 | * Get options in "key-value" format 22 | * 23 | * @return array 24 | */ 25 | public function toArray() 26 | { 27 | return array( 28 | self::MODE_MSG => Mage::helper('wgmnt')->__('Custom Message'), 29 | self::MODE_CMS => Mage::helper('wgmnt')->__('Cms Page'), 30 | ); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/app/code/community/Webgriffe/Maintenance/etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 1.0.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | Webgriffe_Maintenance_Model 13 | 14 | 15 | 16 | 17 | 18 | Webgriffe_Maintenance_Helper 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | singleton 27 | Webgriffe_Maintenance_Controller_Router 28 | initControllerRouters 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | standard 39 | 40 | Webgriffe_Maintenance 41 | wgmnt 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 0 51 | msg 52 | Under maintenance 53 | 1 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/app/code/community/Webgriffe/Maintenance/Helper/Data.php: -------------------------------------------------------------------------------- 1 | getRequest()->getClientIp(); 10 | } 11 | 12 | public function isActive() { 13 | return Mage::getStoreConfig('system/wg_maintenance/active'); 14 | } 15 | 16 | public function bypassIp() { 17 | $bypassedIps = explode(',', Mage::getStoreConfig('system/wg_maintenance/bypassed_ips')); 18 | 19 | if ($bypassedIps && !empty($bypassedIps)) { 20 | for ($i = 0, $count = count($bypassedIps); $i < $count; $i ++) { 21 | $bypassedIps[$i] = trim($bypassedIps[$i]); 22 | } 23 | } 24 | 25 | return ($this->_check($this->_getCurrentIp(), $bypassedIps)); 26 | } 27 | 28 | protected function _check($ip, $arr_ip) { 29 | $this->_log(sprintf("Check incoming IP %s against following IPs: %s", $ip, implode(' - ', $arr_ip))); 30 | foreach ($arr_ip as $test_ip) { 31 | $test_ip = str_replace('\*','\d+',preg_quote($test_ip)); 32 | if (preg_match("/^".$test_ip."$/", $ip)) { 33 | $this->_log(sprintf('Matched "%s" against "%s"', $ip, $test_ip)); 34 | return true; 35 | } 36 | } 37 | return false; 38 | } 39 | 40 | public function getMaintenancePageId() { 41 | return Mage::getStoreConfig('system/wg_maintenance/cms_page'); 42 | } 43 | 44 | public function getCustomMessage() { 45 | return Mage::getStoreConfig('system/wg_maintenance/msg'); 46 | } 47 | 48 | public function getShowMode() { 49 | return Mage::getStoreConfig('system/wg_maintenance/show'); 50 | } 51 | 52 | public function isBasicAuthActive() 53 | { 54 | return Mage::getStoreConfig('system/wg_basicauth/active'); 55 | } 56 | 57 | public function getBasicAuthUsername() 58 | { 59 | return Mage::getStoreConfig('system/wg_basicauth/username'); 60 | } 61 | 62 | public function getBasicAuthPassword() 63 | { 64 | return Mage::getStoreConfig('system/wg_basicauth/password'); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/app/code/community/Webgriffe/Maintenance/Controller/Router.php: -------------------------------------------------------------------------------- 1 | getEvent()->getFront(); 13 | $front->addRouter('maintenance', $this); 14 | } 15 | 16 | public function match(Zend_Controller_Request_Http $request) { 17 | $helper = Mage::helper('wgmnt'); 18 | if ($helper->isActive() && !$helper->bypassIp()) { 19 | $adminFrontName = (string) Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName'); 20 | $str_pos = strpos($request->getPathInfo(), $adminFrontName); 21 | if (Mage::app()->getStore()->isAdmin() || $str_pos === 1) { 22 | return false; 23 | } 24 | 25 | $requestParams = array(); 26 | 27 | $show = Mage::helper('wgmnt')->getShowMode(); 28 | 29 | switch ($show) { 30 | 31 | case Webgriffe_Maintenance_Model_System_Config_Source_Show::MODE_CMS: 32 | $moduleName = 'cms'; 33 | $controllerName = 'page'; 34 | $actionName = 'view'; 35 | $pageId = $helper->getMaintenancePageId(); 36 | $requestParams['page_id'] = $pageId; 37 | break; 38 | 39 | case Webgriffe_Maintenance_Model_System_Config_Source_Show::MODE_MSG: 40 | $moduleName = 'wgmnt'; 41 | $controllerName = 'index'; 42 | $actionName = 'index'; 43 | break; 44 | 45 | } 46 | 47 | foreach ($requestParams as $paramKey => $paramVal) { 48 | $request->setParam($paramKey, $paramVal); 49 | } 50 | 51 | $request 52 | ->setModuleName($moduleName) 53 | ->setControllerName($controllerName) 54 | ->setActionName($actionName); 55 | 56 | $response = Mage::app()->getFrontController()->getResponse(); 57 | $response->setHeader('HTTP/1.1','503'); 58 | $response->setHeader('Status','503 Service Unavailable'); 59 | } 60 | return false; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/app/code/community/Webgriffe/Maintenance/etc/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | text 9 | 1000 10 | 1 11 | 1 12 | 1 13 | 14 | 15 | 16 | select 17 | adminhtml/system_config_source_yesno 18 | 10 19 | 1 20 | 1 21 | 1 22 | 23 | 24 | 25 | If enabled, force logging. 26 | select 27 | adminhtml/system_config_source_yesno 28 | 15 29 | 1 30 | 1 31 | 1 32 | 33 | 34 | 35 | select 36 | wgmnt/system_config_source_show 37 | 18 38 | 1 39 | 1 40 | 1 41 | 42 | 43 | cms 44 | 45 | select 46 | adminhtml/system_config_source_cms_page 47 | 20 48 | 1 49 | 1 50 | 1 51 | 52 | 53 | msg 54 | 55 | HTML is allowed 56 | textarea 57 | 25 58 | 1 59 | 1 60 | 1 61 | 62 | 63 | 64 | You can specify a comma separated list of IP addresses which bypass the maintenance page. You can also use wildcards, i.e. 192.168.1.* 65 | text 66 | 30 67 | 1 68 | 0 69 | 0 70 | 71 | 72 | 73 | 74 | 75 | text 76 | 1100 77 | 1 78 | 1 79 | 1 80 | 81 | 82 | 83 | select 84 | adminhtml/system_config_source_yesno 85 | 15 86 | 1 87 | 1 88 | 1 89 | 90 | If Maintenance page is enabled, then Basic Auth will be ignored. 91 | 92 | 93 | 94 | 95 | 16 96 | 1 97 | 1 98 | 1 99 | 100 | 101 | 102 | 17 103 | 1 104 | 1 105 | 1 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | --------------------------------------------------------------------------------