1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: class Mage_Adminhtml_Block_Notification_Security extends Mage_Adminhtml_Block_Template
28: {
29: // Cache kay for saving verification result
30: const VERIFICATION_RESULT_CACHE_KEY = 'configuration_files_access_level_verification';
31:
32: /**
33: * File path for verification
34: * @var string
35: */
36: private $_filePath = 'app/etc/local.xml';
37:
38: /**
39: * Time out for HTTP verification request
40: * @var int
41: */
42: private $_verificationTimeOut = 2;
43:
44: /**
45: * Check verification result and return true if system must to show notification message
46: *
47: * @return bool
48: */
49: private function _canShowNotification()
50: {
51: if (Mage::app()->loadCache(self::VERIFICATION_RESULT_CACHE_KEY)) {
52: return false;
53: }
54: if ($this->_isFileAccessible()) {
55: return true;
56: }
57: $adminSessionLifetime = (int)Mage::getStoreConfig('admin/security/session_cookie_lifetime');
58: Mage::app()->saveCache(true, self::VERIFICATION_RESULT_CACHE_KEY, array(), $adminSessionLifetime);
59: return false;
60: }
61:
62: /**
63: * If file is accessible return true or false
64: *
65: * @return bool
66: */
67: private function _isFileAccessible()
68: {
69: $defaultUnsecureBaseURL = (string) Mage::getConfig()->getNode('default/' . Mage_Core_Model_Store::XML_PATH_UNSECURE_BASE_URL);
70:
71: $http = new Varien_Http_Adapter_Curl();
72: $http->setConfig(array('timeout' => $this->_verificationTimeOut));
73: $http->write(Zend_Http_Client::POST, $defaultUnsecureBaseURL . $this->_filePath);
74: $responseBody = $http->read();
75: $responseCode = Zend_Http_Response::extractCode($responseBody);
76: $http->close();
77:
78: return $responseCode == 200;
79: }
80:
81: /**
82: * Prepare html output
83: *
84: * @return string
85: */
86: protected function _toHtml()
87: {
88: if (!$this->_canShowNotification()) {
89: return '';
90: }
91: return parent::_toHtml();
92: }
93: }
94: