getDomain(); return $domain == '' ? $this->getIp() : $domain; } //----------------------------------------- public function getDomain() { $backupDomain = Mage::helper('M2ePro/Module')->getCacheConfig()->getGroupValue('/location_info/', 'domain'); if (!is_null($backupDomain)) { strpos($backupDomain,'www.') === 0 && $backupDomain = substr($backupDomain,4); return strtolower(trim($backupDomain)); } $serverDomain = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : NULL; if (!is_null($serverDomain)) { strpos($serverDomain,'www.') === 0 && $serverDomain = substr($serverDomain,4); return strtolower(trim($serverDomain)); } throw new Exception('Server domain is not defined'); } public function getIp() { $backupIp = Mage::helper('M2ePro/Module')->getCacheConfig()->getGroupValue('/location_info/', 'ip'); if (!is_null($backupIp)) { return strtolower(trim($backupIp)); } $serverIp = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : NULL; is_null($serverIp) && $serverIp = isset($_SERVER['LOCAL_ADDR']) ? $_SERVER['LOCAL_ADDR'] : NULL; if (!is_null($serverIp)) { return strtolower(trim($serverIp)); } throw new Exception('Server IP is not defined'); } public function getBaseDirectory() { $backupDirectory = Mage::helper('M2ePro/Module')->getCacheConfig() ->getGroupValue('/location_info/', 'directory'); if (!is_null($backupDirectory)) { return $backupDirectory; } return Mage::getBaseDir(); } public function isBrowserIE() { if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) { return true; } return false; } //----------------------------------------- public function updateBackupConnectionData($forceUpdate = false) { $dateLastCheck = Mage::helper('M2ePro/Module')->getCacheConfig() ->getGroupValue('/location_info/', 'date_last_check'); if (is_null($dateLastCheck)) { $dateLastCheck = Mage::helper('M2ePro')->getCurrentGmtDate(true)-60*60*365; } else { $dateLastCheck = strtotime($dateLastCheck); } if (!$forceUpdate && Mage::helper('M2ePro')->getCurrentGmtDate(true) < $dateLastCheck + 60*60*24) { return; } $domainBackup = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '127.0.0.1'; strpos($domainBackup,'www.') === 0 && $domainBackup = substr($domainBackup,4); Mage::helper('M2ePro/Module')->getCacheConfig() ->setGroupValue('/location_info/', 'domain', $domainBackup); $ipBackup = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : NULL; is_null($ipBackup) && $ipBackup = isset($_SERVER['LOCAL_ADDR']) ? $_SERVER['LOCAL_ADDR'] : '127.0.0.1'; Mage::helper('M2ePro/Module')->getCacheConfig() ->setGroupValue('/location_info/', 'ip', $ipBackup); $directoryBackup = Mage::getBaseDir(); Mage::helper('M2ePro/Module')->getCacheConfig() ->setGroupValue('/location_info/', 'directory', $directoryBackup); Mage::helper('M2ePro/Module')->getCacheConfig()->setGroupValue( '/location_info/', 'date_last_check', Mage::helper('M2ePro')->getCurrentGmtDate() ); } // ######################################## public function getSystem() { return php_uname(); } // ---------------------------------------- public function getPhpVersion() { return @phpversion(); } public function getPhpApiName() { return @php_sapi_name(); } public function getPhpSettings() { return array( 'memory_limit' => $this->getMemoryLimit(), 'max_execution_time' => @ini_get('max_execution_time'), 'phpinfo' => $this->getPhpInfoArray() ); } public function getPhpInfoArray() { try { ob_start(); phpinfo(INFO_ALL); $pi = preg_replace( array( '#^.*(.*).*$#m', '#

PHP License

.*$#ms', '#

Configuration

#', "#\r?\n#", "##", '# +<#', "#[ \t]+#", '# #', '# +#', '# class=".*?"#', '%'%', '#(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" />

PHP Version (.*?)

(?:\n+?)#', '#

PHP Credits

#', '#(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)#', "# +#", '##', '##'), array( '$1', '', '', '', '' . "\n", '<', ' ', ' ', ' ', '', ' ', '

PHP Configuration

'."\n".'PHP Version$2'. "\n".'PHP Egg$1', 'PHP Credits Egg$1', 'Zend Engine$2' . "\n" . 'Zend Egg$1', ' ', '%S%', '%E%' ), ob_get_clean() ); $sections = explode('

', strip_tags($pi, '

')); unset($sections[0]); $pi = array(); foreach ($sections as $section) { $n = substr($section, 0, strpos($section, '

')); preg_match_all( '#%S%(?:(.*?))?(?:(.*?))?(?:(.*?))?%E%#', $section, $askapache, PREG_SET_ORDER ); foreach ($askapache as $m) { if (!isset($m[0]) || !isset($m[1]) || !isset($m[2])) { continue; } $pi[$n][$m[1]]=(!isset($m[3])||$m[2]==$m[3])?$m[2]:array_slice($m,2); } } } catch (Exception $exception) { return array(); } return $pi; } // ---------------------------------------- public function getMysqlVersion() { return Mage::getSingleton('core/resource')->getConnection('core_read')->getServerVersion(); } public function getMysqlApiName() { $connection = Mage::getSingleton('core/resource')->getConnection('core_read')->getConnection(); return $connection instanceof PDO ? $connection->getAttribute(PDO::ATTR_CLIENT_VERSION) : 'N/A'; } public function getMysqlSettings() { $sqlQuery = "SHOW VARIABLES WHERE `Variable_name` IN ('connect_timeout','wait_timeout')"; $settingsArray = Mage::getSingleton('core/resource') ->getConnection('core_read') ->fetchAll($sqlQuery); $settings = array(); foreach ($settingsArray as $settingItem) { $settings[$settingItem['Variable_name']] = $settingItem['Value']; } $phpInfo = $this->getPhpInfoArray(); $settings = array_merge($settings,isset($phpInfo['mysql'])?$phpInfo['mysql']:array()); return $settings; } public function getMysqlTotals() { $moduleTables = Mage::helper('M2ePro/Module_Database')->getMySqlTables(); $magentoTables = Mage::helper('M2ePro/Magento')->getMySqlTables(); /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read'); $totalRecords = 0; foreach ($moduleTables as $moduleTable) { $moduleTable = Mage::getSingleton('core/resource')->getTableName($moduleTable); if (!in_array($moduleTable, $magentoTables)) { continue; }; $dbSelect = $connRead->select()->from($moduleTable,new Zend_Db_Expr('COUNT(*)')); $totalRecords += (int)$connRead->fetchOne($dbSelect); } return array( 'magento_tables' => count($magentoTables), 'module_tables' => count($moduleTables), 'module_records' => $totalRecords ); } // ######################################## public function getMemoryLimit($inMegabytes = true) { $memoryLimit = trim(ini_get('memory_limit')); if ($memoryLimit == '') { return 0; } $lastMemoryLimitLetter = strtolower(substr($memoryLimit, -1)); switch($lastMemoryLimitLetter) { case 'g': $memoryLimit *= 1024; case 'm': $memoryLimit *= 1024; case 'k': $memoryLimit *= 1024; } if ($inMegabytes) { $memoryLimit /= 1024 * 1024; } return $memoryLimit; } public function setMemoryLimit($maxSize = 512) { $minSize = 32; $currentMemoryLimit = $this->getMemoryLimit(); if ($maxSize < $minSize || (int)$currentMemoryLimit >= $maxSize) { return false; } for ($i=$minSize; $i<=$maxSize; $i*=2) { if (@ini_set('memory_limit',"{$i}M") === false) { if ($i == $minSize) { return false; } else { return $i/2; } } } return true; } // ---------------------------------------- public function updateMySqlConnection() { /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read'); try { $connRead->query('SELECT 1'); } catch (Exception $exception) { $connRead->closeConnection(); } } // ######################################## }