/** * Returns value by request * * @param string $name Type of value * * @return string */ public function get($name) { $return = ''; switch ($name) { case 'phpversion': $return = PHP_VERSION; break; case 'os_type': list($osType) = explode(' ', PHP_OS); $return = $osType; break; case 'mysql_server': $return = \Includes\Utils\Database::getDbVersion(); break; case 'innodb_support': $return = \Includes\Utils\Database::isInnoDBSupported(); break; case 'root_folder': $return = getcwd(); break; case 'web_server': if (isset($_SERVER['SERVER_SOFTWARE'])) { $return = $_SERVER['SERVER_SOFTWARE']; } else { $return = ''; } break; case 'xml_parser': ob_start(); phpinfo(INFO_MODULES); $phpInfo = ob_get_contents(); ob_end_clean(); if (preg_match('/EXPAT.+>([\\.\\d]+)/mi', $phpInfo, $m)) { $return = $m[1]; } else { $return = function_exists('xml_parser_create') ? 'found' : ''; } break; case 'gdlib': if (!$this->is('GDLibLoaded')) { $return = ''; } else { ob_start(); phpinfo(INFO_MODULES); $phpInfo = ob_get_contents(); ob_end_clean(); if (preg_match('/GD.+>([\\.\\d]+)/mi', $phpInfo, $m)) { $gdVersion = $m[1]; } else { $gdVersion = @gd_info(); if (is_array($gdVersion) && isset($gdVersion['GD Version'])) { $gdVersion = $gdVersion['GD Version']; } else { $gdVersion = 'unknown'; } } $return = 'found (' . $gdVersion . ')'; } break; case 'core_version': $return = \XLite::getInstance()->getVersion(); break; case 'libcurl': $libcurlVersion = curl_version(); if (is_array($libcurlVersion)) { $libcurlVersion = $libcurlVersion['version']; } $return = $libcurlVersion; break; case 'check_files': $result = array(); $files = array(); foreach ($files as $file) { $mode = $this->getFilePermission($file); $modeStr = $this->getFilePermissionStr($file); $res = array('file' => $file, 'error' => ''); if (!is_file($file)) { $res['error'] = 'does_not_exist'; $result[] = $res; continue; } $perm = substr(sprintf('%o', @fileperms($file)), -4); if ($perm != $modeStr) { if (!@chmod($file, $mode)) { $res['error'] = 'cannot_chmod'; $result[] = $res; continue; } } else { if ($this->getComplex('xlite.suMode') != 0) { if (!@chmod($file, $mode)) { $res['error'] = 'wrong_owner'; $result[] = $res; continue; } } } $result[] = $res; } $return = $result; break; // :FIXME: checng to the constants // :FIXME: checng to the constants case 'check_dirs': $result = array(); $dirs = array('var/run', 'var/log', 'var/html', 'var/backup', 'var/tmp', 'catalog', 'images', 'classes/modules', 'skins/default/en/modules', 'skins/admin/en/modules', 'skins/default/en/images/modules', 'skins/admin/en/images/modules', 'skins/mail/en/modules', 'skins/mail/en/images/modules'); foreach ($dirs as $dir) { $mode = $this->getDirPermission($dir); $modeStr = $this->getDirPermissionStr($dir); $res = array('dir' => $dir, 'error' => '', 'subdirs' => array()); if (!is_dir($dir)) { $fullPath = ''; $path = explode('/', $dir); foreach ($path as $sub) { $fullPath .= $sub . '/'; if (!is_dir($fullPath) && @mkdir($fullPath, $mode) !== true) { break; } } } if (!is_dir($dir)) { $res['error'] = 'cannot_create'; $result[] = $res; continue; } $perm = substr(sprintf('%o', @fileperms($dir)), -4); if ($perm != $modeStr) { if (!@chmod($dir, $mode)) { $res['error'] = 'cannot_chmod'; $result[] = $res; continue; } } else { if ($this->getComplex('xlite.suMode') != 0 || strpos($dir, 'var') !== false) { if (!@chmod($dir, $mode)) { $res['error'] = 'wrong_owner'; $result[] = $res; continue; } } } $subdirs = array(); if ('catalog' != $dir && 'images' != $dir) { $this->checkSubdirs($dir, $subdirs); } if (!empty($subdirs)) { $res['error'] = 'cannot_chmod_subdirs'; $res['subdirs'] = $subdirs; $result[] = $res; continue; } $result[] = $res; } $return = $result; break; default: $return = parent::get($name); } return $return; }
/** * Check MySQL version: returns false only if version is gathered and it isn't suit * * @param string $errorMsg Error message if checking failed * @param string $value Actual value of the checked parameter * @param resource $isConnected MySQL connection link OPTIONAL * * @return boolean */ function checkMysqlVersion(&$errorMsg, &$value, $isConnected = false) { global $isDBConnected; $result = true; $value = xtr('unknown'); $pdoErrorMsg = ''; $version = false; if (defined('DB_URL')) { // Connect via PDO and get DB version $data = unserialize(constant('DB_URL')); // Support of Drupal 6 $db_url if (!is_array($data)) { $data = parseDbURL(constant('DB_URL')); } $isConnected = dbConnect($data, $pdoErrorMsg); if (!$isConnected) { $errorMsg = xtr('Can\'t connect to MySQL server') . (!empty($pdoErrorMsg) ? ': ' . $pdoErrorMsg : ''); } } if ($isConnected || $isDBConnected) { try { $version = \Includes\Utils\Database::getDbVersion(); } catch (Exception $e) { $pdoErrorMsg = $e->getMessage(); } // Check version if ($version) { x_install_log(xtr('MySQL version: ' . $version)); if (version_compare($version, constant('LC_MYSQL_VERSION_MIN')) < 0) { $result = false; $errorMsg = xtr('MySQL version must be :minver as a minimum.', array(':minver' => constant('LC_MYSQL_VERSION_MIN'))); } else { // Check for InnoDb support if (!\Includes\Utils\Database::isInnoDBSupported()) { $result = false; $errorMsg = xtr('MySQL server doesn\'t support InnoDB engine. It is required for X-Cart operation'); } } } else { $errorMsg = xtr('Cannot get the MySQL server version') . (!empty($pdoErrorMsg) ? ' : ' . $pdoErrorMsg : '.'); } } $value = $version; return $result; }