Preparing for the integration of the version 2.0 of the setup.

Some changes to the application layout: logs now go to the ./log folder ./data should be used to store application's data.

SVN:trunk[2189]
This commit is contained in:
Denis Flaven
2012-09-18 19:55:56 +00:00
parent 93791255e6
commit e463bd8b48
15 changed files with 2680 additions and 145 deletions

View File

@@ -28,11 +28,11 @@ class CheckResult
const ERROR = 0;
const WARNING = 1;
const INFO = 2;
public $iSeverity;
public $sLabel;
public $sDescription;
public function __construct($iSeverity, $sLabel, $sDescription = '')
{
$this->iSeverity = $iSeverity;
@@ -56,7 +56,7 @@ class SetupUtils
const MYSQL_MIN_VERSION = '5.0.0';
const MIN_MEMORY_LIMIT = 33554432; // = 32*1024*1024 Beware: Computations are not allowed in defining constants
const SUHOSIN_GET_MAX_VALUE_LENGTH = 2048;
/**
* Check the version of PHP, the needed PHP extension and a number
* of configuration parameters (memory_limit, max_upload_file_size, etc...)
@@ -66,18 +66,15 @@ class SetupUtils
static function CheckPHPVersion()
{
$aResult = array();
$aErrors = array();
$aWarnings = array();
$aOk = array();
SetupPage::log('Info - CheckPHPVersion');
if (version_compare(phpversion(), self::PHP_MIN_VERSION, '>='))
{
$aResult[] = new CheckResult(CheckResult::INFO, "The current PHP Version (".phpversion().") is greater than the minimum required version (".self::PHP_MIN_VERSION.")");
$aResult[] = new CheckResult(CheckResult::INFO, "The current PHP Version (".phpversion().") is greater than the minimum version required to run ".ITOP_APPLICATION.", which is (".self::PHP_MIN_VERSION.")");
}
else
{
$aResult[] = new CheckResult(CheckResult::ERROR, "Error: The current PHP Version (".phpversion().") is lower than the minimum required version (".self::PHP_MIN_VERSION.")");
$aResult[] = new CheckResult(CheckResult::ERROR, "Error: The current PHP Version (".phpversion().") is lower than the minimum version required to run ".ITOP_APPLICATION.", which is (".self::PHP_MIN_VERSION.")");
}
$aMandatoryExtensions = array('mysqli', 'iconv', 'simplexml', 'soap', 'hash', 'json', 'session', 'pcre', 'dom');
$aOptionalExtensions = array('mcrypt' => 'Strong encryption will not be used.',
@@ -140,15 +137,15 @@ class SetupUtils
// Other included/scanned files
if ($sFileList = php_ini_scanned_files())
{
if (strlen($sFileList) > 0)
{
$aFiles = explode(',', $sFileList);
foreach ($aFiles as $sFile)
{
$sPhpIniFile .= ', '.trim($sFile);
}
}
if (strlen($sFileList) > 0)
{
$aFiles = explode(',', $sFileList);
foreach ($aFiles as $sFile)
{
$sPhpIniFile .= ', '.trim($sFile);
}
}
}
SetupPage::log("Info - php.ini file(s): '$sPhpIniFile'");
}
@@ -156,26 +153,26 @@ class SetupUtils
{
$sPhpIniFile = 'php.ini';
}
if (!ini_get('file_uploads'))
{
if (!ini_get('file_uploads'))
{
$aResult[] = new CheckResult(CheckResult::ERROR, "Files upload is not allowed on this server (file_uploads = ".ini_get('file_uploads').").");
}
$sUploadTmpDir = self::GetUploadTmpDir();
if (empty($sUploadTmpDir))
{
$sUploadTmpDir = '/tmp';
$sUploadTmpDir = '/tmp';
$aResult[] = new CheckResult(CheckResult::WARNING, "Temporary directory for files upload is not defined (upload_tmp_dir), assuming that $sUploadTmpDir is used.");
}
// check that the upload directory is indeed writable from PHP
if (!empty($sUploadTmpDir))
{
if (!file_exists($sUploadTmpDir))
{
if (!empty($sUploadTmpDir))
{
if (!file_exists($sUploadTmpDir))
{
$aResult[] = new CheckResult(CheckResult::ERROR, "Temporary directory for files upload ($sUploadTmpDir) does not exist or cannot be read by PHP.");
}
else if (!is_writable($sUploadTmpDir))
{
else if (!is_writable($sUploadTmpDir))
{
$aResult[] = new CheckResult(CheckResult::ERROR, "Temporary directory for files upload ($sUploadTmpDir) is not writable.");
}
else
@@ -183,49 +180,49 @@ class SetupUtils
SetupPage::log("Info - Temporary directory for files upload ($sUploadTmpDir) is writable.");
}
}
if (!ini_get('upload_max_filesize'))
{
if (!ini_get('upload_max_filesize'))
{
$aResult[] = new CheckResult(CheckResult::ERROR, "File upload is not allowed on this server (upload_max_filesize = ".ini_get('upload_max_filesize').").");
}
}
$iMaxFileUploads = ini_get('max_file_uploads');
if (!empty($iMaxFileUploads) && ($iMaxFileUploads < 1))
{
if (!empty($iMaxFileUploads) && ($iMaxFileUploads < 1))
{
$aResult[] = new CheckResult(CheckResult::ERROR, "File upload is not allowed on this server (max_file_uploads = ".ini_get('max_file_uploads').").");
}
$iMaxUploadSize = utils::ConvertToBytes(ini_get('upload_max_filesize'));
$iMaxPostSize = utils::ConvertToBytes(ini_get('post_max_size'));
if ($iMaxPostSize <= $iMaxUploadSize)
{
$aResult[] = new CheckResult(CheckResult::WARNING, "post_max_size (".ini_get('post_max_size').") must be bigger than upload_max_filesize (".ini_get('upload_max_filesize')."). You may want to check the PHP configuration file(s): '$sPhpIniFile'. Be aware that this setting can also be overridden in the apache configuration.");
$aResult[] = new CheckResult(CheckResult::WARNING, "post_max_size (".ini_get('post_max_size').") in php.ini should be bigger than upload_max_filesize (".ini_get('upload_max_filesize').") otherwise you cannot upload files of the maximun size.");
}
SetupPage::log("Info - upload_max_filesize: ".ini_get('upload_max_filesize'));
SetupPage::log("Info - post_max_size: ".ini_get('post_max_size'));
SetupPage::log("Info - max_file_uploads: ".ini_get('max_file_uploads'));
// Check some more ini settings here, needed for file upload
if (function_exists('get_magic_quotes_gpc'))
{
if (@get_magic_quotes_gpc())
{
$aResult[] = new CheckResult(CheckResult::ERROR, "'magic_quotes_gpc' is set to On. Please turn it Off before continuing. You may want to check the PHP configuration file(s): '$sPhpIniFile'. Be aware that this setting can also be overridden in the apache configuration.");
if (@get_magic_quotes_gpc())
{
$aResult[] = new CheckResult(CheckResult::ERROR, "'magic_quotes_gpc' is set to On. Please turn it Off in php.ini before continuing.");
}
}
if (function_exists('magic_quotes_runtime'))
{
if (@magic_quotes_runtime())
{
$aResult[] = new CheckResult(CheckResult::ERROR, "'magic_quotes_runtime' is set to On. Please turn it Off before continuing. You may want to check the PHP configuration file(s): '$sPhpIniFile'. Be aware that this setting can also be overridden in the apache configuration.");
if (@magic_quotes_runtime())
{
$aResult[] = new CheckResult(CheckResult::ERROR, "'magic_quotes_runtime' is set to On. Please turn it Off in php.ini before continuing.");
}
}
$sMemoryLimit = trim(ini_get('memory_limit'));
if (empty($sMemoryLimit))
{
@@ -240,40 +237,58 @@ class SetupUtils
//
$iMemoryLimit = utils::ConvertToBytes($sMemoryLimit);
if ($iMemoryLimit < self::MIN_MEMORY_LIMIT)
{
{
$aResult[] = new CheckResult(CheckResult::ERROR, "memory_limit ($iMemoryLimit) is too small, the minimum value to run the application is ".self::MIN_MEMORY_LIMIT.".");
}
else
{
SetupPage::log("Info - memory_limit is $iMemoryLimit, ok.");
SetupPage::log("Info - memory_limit is $iMemoryLimit, ok.");
}
}
// Special case for APC
if (extension_loaded('apc'))
{
$sAPCVersion = phpversion('apc');
$aResult[] = new CheckResult(CheckResult::INFO, "APC detected (version $sAPCVersion). The APC cache will be used to speed-up the application.");
$aResult[] = new CheckResult(CheckResult::INFO, "APC detected (version $sAPCVersion). The APC cache will be used to speed-up ".ITOP_APPLICATION.".");
}
// Special case Suhosin extension
if (extension_loaded('suhosin'))
{
$sSuhosinVersion = phpversion('suhosin');
$aOk[] = "Suhosin extension detected (version $sSuhosinVersion).";
$iGetMaxValueLength = ini_get('suhosin.get.max_value_length');
if ($iGetMaxValueLength < self::SUHOSIN_GET_MAX_VALUE_LENGTH)
{
$aResult[] = new CheckResult(CheckResult::INFO, "suhosin.get.max_value_length ($iGetMaxValueLength) is too small, the minimum value to run the application is ".self::SUHOSIN_GET_MAX_VALUE_LENGTH.". This value is set by the PHP configuration file(s): '$sPhpIniFile'. Be aware that this setting can also be overridden in the apache configuration.");
{
$aResult[] = new CheckResult(CheckResult::WARNING, "suhosin.get.max_value_length ($iGetMaxValueLength) is too small, the minimum value recommended to run the application is ".self::SUHOSIN_GET_MAX_VALUE_LENGTH.".");
}
else
{
SetupPage::log("Info - suhosin.get.max_value_length = $iGetMaxValueLength, ok.");
SetupPage::log("Info - suhosin.get.max_value_length = $iGetMaxValueLength, ok.");
}
}
return $aResult;
if (function_exists('php_ini_loaded_file')) // PHP >= 5.2.4
{
$sPhpIniFile = php_ini_loaded_file();
// Other included/scanned files
if ($sFileList = php_ini_scanned_files())
{
if (strlen($sFileList) > 0)
{
$aFiles = explode(',', $sFileList);
foreach ($aFiles as $sFile)
{
$sPhpIniFile .= ', '.trim($sFile);
}
}
}
$aResult[] = new CheckResult(CheckResult::INFO, "Loaded php.ini files: $sPhpIniFile");
}
return $aResult;
}
/**
@@ -293,7 +308,7 @@ class SetupUtils
$sMissingExtensionLink = "<a href=\"http://www.php.net/manual/en/book.zip.php\" target=\"_blank\">zip</a>";
$aResult[] = new CheckResult(CheckResult::ERROR, "Missing PHP extension: zip", $sMissingExtensionLink);
}
// availability of exec()
//
$aDisabled = explode(', ', ini_get('disable_functions'));
@@ -342,55 +357,55 @@ class SetupUtils
// Example of query (DB without a suffix)
//$sDBSize = "SELECT SUM(ROUND(DATA_LENGTH/1024/1024, 2)) AS size_mb FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = `$sDBName`";
return $aResult;
return $aResult;
}
/**
* Helper function to retrieve the system's temporary directory
* Emulates sys_get_temp_dir if neeed (PHP < 5.2.1)
* @return string Path to the system's temp directory
* Emulates sys_get_temp_dir if neeed (PHP < 5.2.1)
* @return string Path to the system's temp directory
*/
static function GetTmpDir()
{
// try to figure out what is the temporary directory
// prior to PHP 5.2.1 the function sys_get_temp_dir
// did not exist
if ( !function_exists('sys_get_temp_dir'))
{
if( $temp=getenv('TMP') ) return realpath($temp);
if( $temp=getenv('TEMP') ) return realpath($temp);
if( $temp=getenv('TMPDIR') ) return realpath($temp);
$temp=tempnam(__FILE__,'');
if (file_exists($temp))
{
unlink($temp);
return realpath(dirname($temp));
}
return null;
}
else
{
return realpath(sys_get_temp_dir());
}
// try to figure out what is the temporary directory
// prior to PHP 5.2.1 the function sys_get_temp_dir
// did not exist
if ( !function_exists('sys_get_temp_dir'))
{
if( $temp=getenv('TMP') ) return realpath($temp);
if( $temp=getenv('TEMP') ) return realpath($temp);
if( $temp=getenv('TMPDIR') ) return realpath($temp);
$temp=tempnam(__FILE__,'');
if (file_exists($temp))
{
unlink($temp);
return realpath(dirname($temp));
}
return null;
}
else
{
return realpath(sys_get_temp_dir());
}
}
/**
* Helper function to retrieve the directory where files are to be uploaded
* @return string Path to the temp directory used for uploading files
* @return string Path to the temp directory used for uploading files
*/
static function GetUploadTmpDir()
{
$sPath = ini_get('upload_tmp_dir');
if (empty($sPath))
{
$sPath = self::GetTmpDir();
}
return $sPath;
$sPath = ini_get('upload_tmp_dir');
if (empty($sPath))
{
$sPath = self::GetTmpDir();
}
return $sPath;
}
/**
* Helper to recursively remove a directory
*/
*/
public static function rrmdir($dir)
{
if ((strlen(trim($dir)) == 0) || ($dir == '/') || ($dir == '\\'))
@@ -403,7 +418,7 @@ class SetupUtils
/**
* Helper to recursively cleanup a directory
*/
*/
public static function tidydir($dir)
{
if ((strlen(trim($dir)) == 0) || ($dir == '/') || ($dir == '\\'))
@@ -427,7 +442,7 @@ class SetupUtils
/**
* Helper to build the full path of a new directory
*/
*/
public static function builddir($dir)
{
$parent = dirname($dir);
@@ -444,7 +459,7 @@ class SetupUtils
/**
* Helper to copy a directory to a target directory, skipping .SVN files (for developer's comfort!)
* Returns true if successfull
*/
*/
public static function copydir($sSource, $sDest)
{
if (is_dir($sSource))
@@ -463,7 +478,7 @@ class SetupUtils
// Skip
continue;
}
if (is_dir($sSource.'/'.$sFile))
{
// Recurse
@@ -486,4 +501,389 @@ class SetupUtils
return false;
}
}
static function GetPreviousInstance($sDir)
{
$bFound = false;
$sSourceDir = '';
$sSourceEnvironement = '';
$sConfigFile = '';
$aResult = array(
'found' => false,
);
if (file_exists($sDir.'/config-itop.php'))
{
$sSourceDir = $sDir;
$sSourceEnvironment = '';
$sConfigFile = $sDir.'/config-itop.php';
$aResult['found'] = true;
}
else if (file_exists($sDir.'/conf/production/config-itop.php'))
{
$sSourceDir = $sDir;
$sSourceEnvironment = 'production';
$sConfigFile = $sDir.'/conf/production/config-itop.php';
$aResult['found'] = true;
}
if ($aResult['found'])
{
$oPrevConf = new Config($sConfigFile);
$aResult = array(
'found' => true,
'source_dir' => $sSourceDir,
'source_environment' => $sSourceEnvironment,
'configuration_file' => $sConfigFile,
'db_server' => $oPrevConf->GetDBHost(),
'db_user' => $oPrevConf->GetDBUser(),
'db_pwd' => $oPrevConf->GetDBPwd(),
'db_name' => $oPrevConf->GetDBName(),
'db_prefix' => $oPrevConf->GetDBSubname(),
);
}
return $aResult;
}
static function CheckDiskSpace($sDir)
{
while(($f = @disk_free_space($sDir)) == false)
{
if ($sDir == dirname($sDir)) break;
if ($sDir == '.') break;
$sDir = dirname($sDir);
}
return $f;
}
static function HumanReadableSize($fBytes)
{
$aSizes = array('bytes', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Hb');
$index = 0;
while (($fBytes > 1000) && ($index < count($aSizes)))
{
$index++;
$fBytes = $fBytes / 1000;
}
return sprintf('%.2f %s', $fBytes, $aSizes[$index]);
}
static function DisplayDBParameters($oPage, $bAllowDBCreation, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sNewDBName = '')
{
$oPage->add('<tr><td colspan="2">');
$oPage->add('<fieldset><legend>Database Server Connection</legend>');
$oPage->add('<table>');
$oPage->add('<tr><td>Server Name:</td><td><input id="db_server" type="text" name="db_server" value="'.htmlentities($sDBServer, ENT_QUOTES, 'UTF-8').'" size="15"/></td><td>E.g. "localhost", "dbserver.mycompany.com" or "192.142.10.23"</td></tr>');
$oPage->add('<tr><td>Login:</td><td><input id="db_user" type="text" name="db_user" value="'.htmlentities($sDBUser, ENT_QUOTES, 'UTF-8').'" size="15"/></td><td rowspan="2" style="vertical-align:top">The account must have the following privileges on the database: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, CREATE VIEW, SUPER, TRIGGER</td></tr>');
$oPage->add('<tr><td>Password:</td><td><input id="db_pwd" type="password" name="db_pwd" value="'.htmlentities($sDBPwd, ENT_QUOTES, 'UTF-8').'" size="15"/></td></tr>');
$oPage->add('</table>');
$oPage->add('</fieldset>');
$oPage->add('</td></tr>');
$oPage->add('<tr><td colspan="2"><span id="db_info"></span></td></tr>');
$oPage->add('<tr><td colspan="2">');
$oPage->add('<fieldset><legend>Database</legend>');
$oPage->add('<table>');
if ($bAllowDBCreation)
{
$oPage->add('<tr><td><input type="radio" id="existing_db" name="create_db" value="no"/><label for="existing_db">&nbsp;Use the existing database:</label></td>');
$oPage->add('<td id="db_name_container"><input id="db_name" name="db_name" size="15" maxlen="32" value="'.htmlentities($sDBName, ENT_QUOTES, 'UTF-8').'"/><span style="width:20px;" id="v_db_name"></span></td></tr>');
$oPage->add('<tr><td><input type="radio" id="create_db" name="create_db" value="yes"/><label for="create_db">&nbsp;Create a new database:</label></td>');
$oPage->add('<td><input id="db_new_name" type="text" name="db_new_name" value="'.htmlentities($sNewDBName, ENT_QUOTES, 'UTF-8').'" size="15" maxlength="32"/><span style="width:20px;" id="v_db_new_name"></span></td></tr>');
$oPage->add('<tr><td>Use a prefix for the tables:</td><td><input id="db_prefix" type="text" name="db_prefix" value="'.htmlentities($sDBPrefix, ENT_QUOTES, 'UTF-8').'" size="15" maxlength="32"/><span style="width:20px;" id="v_db_prefix"></span></td></tr>');
}
else
{
$oPage->add('<tr><td>Database Name:</td><td id="db_name_container"><input id="db_name" name="db_name" size="15" maxlen="32" value="'.htmlentities($sDBName, ENT_QUOTES, 'UTF-8').'"/><span style="width:20px;" id="v_db_name"></span></td></tr>');
$oPage->add('<tr><td>Use a prefix for the tables:</td><td><input id="db_prefix" type="text" name="db_prefix" value="'.htmlentities($sDBPrefix, ENT_QUOTES, 'UTF-8').'" size="15"/><span style="width:20px;" id="v_db_prefix"></span></td></tr>');
}
$oPage->add('</table>');
$oPage->add('</fieldset>');
$oPage->add('<tr><td colspan="2"><span id="table_info">&nbsp;</span></td></tr>');
$oPage->add('</td></tr>');
$oPage->add_script(
<<<EOF
var iCheckDBTimer = null;
var oXHRCheckDB = null;
function CheckDBConnection()
{
// Don't call the server too often...
if (iCheckDBTimer !== null)
{
clearTimeout(iCheckDBTimer);
iCheckDBTimer = null;
}
iCheckDBTimer = setTimeout(DoCheckDBConnection, 500);
}
function DoCheckDBConnection()
{
iCheckDBTimer = null;
var oParams = {
'db_server': $("#db_server").val(),
'db_user': $("#db_user").val(),
'db_pwd': $("#db_pwd").val(),
'db_name': $("#db_name").val()
}
if (oXHRCheckDB !== null)
{
oXHRCheckDB.abort();
oXHRCheckDB = null;
}
oXHRCheckDB = WizardAsyncAction("check_db", oParams);
}
function ValidateField(sFieldId, bUsed)
{
var sValue = new String($("#"+sFieldId).val());
var bMandatory = false;
if (bUsed)
{
if (sFieldId == 'db_name')
{
bUsed = ($("#existing_db").attr("checked") == "checked");
bMandatory = true;
}
if (sFieldId == 'db_new_name')
{
bUsed = ($("#create_db").attr("checked") == "checked");
bMandatory = true;
}
}
if (!bUsed)
{
$("#v_"+sFieldId).html("");
return true;
}
else
{
if (sValue != "")
{
if (sValue.match(/^[A-Za-z][A-Za-z0-9_]*$/))
{
$("#v_"+sFieldId).html("");
return true;
}
else
{
$("#v_"+sFieldId).html('<img src="../images/validation_error.png" title="Only the characters [A-Za-z0-9_] are allowed"/>');
return false;
}
}
else if (bMandatory)
{
$("#v_"+sFieldId).html('<img src="../images/validation_error.png" title="This field cannot be empty"/>');
return false;
}
else
{
$("#v_"+sFieldId).html("");
return true;
}
}
}
EOF
);
$oPage->add_ready_script(
<<<EOF
DoCheckDBConnection(); // Validate the initial values immediately
$("#db_server").bind("keyup change", function() { CheckDBConnection(); });
$("#db_user").bind("keyup change", function() { CheckDBConnection(); });
$("#db_pwd").bind("keyup change", function() { CheckDBConnection(); });
$("#db_new_name").bind("click", function() { $("#create_db").attr("checked", "checked"); });
$("#db_new_name").bind("keyup change", function() { WizardUpdateButtons(); });
$("#db_name").bind("keyup change", function() { WizardUpdateButtons(); });
$("#db_prefix").bind("keyup change", function() { WizardUpdateButtons(); });
$("#db_name").bind("click", function() { $("#existing_db").attr("checked", "checked"); WizardUpdateButtons(); });
$("#existing_db").bind("click change", function() { WizardUpdateButtons(); });
$("#create_db").bind("click change", function() { WizardUpdateButtons(); });
EOF
);
}
/**
* Helper function check the connection to the database, verify a few conditions (minimum version, etc...) and (if connected)
* enumerate the existing databases (if possible)
* @return mixed false if the connection failed or array('checks' => Array of CheckResult, 'databases' => Array of database names (as strings) or null if not allowed)
*/
static function CheckServerConnection($sDBServer, $sDBUser, $sDBPwd)
{
$aResult = array('checks' => array(), 'databases' => null);
try
{
$oDBSource = new CMDBSource;
$oDBSource->Init($sDBServer, $sDBUser, $sDBPwd);
$aResult['checks'][] = new CheckResult(CheckResult::INFO, "Connection to '$sDBServer' as '$sDBUser' successful.");
$aResult['checks'][] = new CheckResult(CheckResult::INFO, "Info - User privileges: ".($oDBSource->GetRawPrivileges()));
$sDBVersion = $oDBSource->GetDBVersion();
if (version_compare($sDBVersion, self::MYSQL_MIN_VERSION, '>='))
{
$aResult['checks'][] = new CheckResult(CheckResult::INFO, "Current MySQL version ($sDBVersion), greater than minimum required version (".self::MYSQL_MIN_VERSION.")");
// Check some server variables
$iMaxAllowedPacket = $oDBSource->GetServerVariable('max_allowed_packet');
$iMaxUploadSize = utils::ConvertToBytes(ini_get('upload_max_filesize'));
if ($iMaxAllowedPacket >= (500 + $iMaxUploadSize)) // Allow some space for the query + the file to upload
{
$aResult['checks'][] = new CheckResult(CheckResult::INFO, "MySQL server's max_allowed_packet ($iMaxAllowedPacket) is big enough compared to upload_max_filesize ($iMaxUploadSize).");
}
else if($iMaxAllowedPacket < $iMaxUploadSize)
{
$aResult['checks'][] = new CheckResult(CheckResult::WARNING, "MySQL server's max_allowed_packet ($iMaxAllowedPacket) is not big enough. Please, consider setting it to at least ".(500 + $iMaxUploadSize).".");
}
$iMaxConnections = $oDBSource->GetServerVariable('max_connections');
if ($iMaxConnections < 5)
{
$aResult['checks'][] = new CheckResult(CheckResult::WARNING, "MySQL server's max_connections ($iMaxConnections) is not enough. Please, consider setting it to at least 5.");
}
else
{
$aResult['checks'][] = new CheckResult(CheckResult::INFO, "MySQL server's max_connections is set to $iMaxConnections.");
}
}
else
{
$aResult['checks'][] = new CheckResult(CheckResult::ERROR, "Error: Current MySQL version is ($sDBVersion), minimum required version (".self::MYSQL_MIN_VERSION.")");
}
try
{
$aResult['databases'] = $oDBSource->ListDB();
}
catch(Exception $e)
{
$aResult['databases'] = null;
}
}
catch(Exception $e)
{
return false;
}
return $aResult;
}
static public function AsyncCheckDB($oPage, $aParameters)
{
$sDBServer = $aParameters['db_server'];
$sDBUser = $aParameters['db_user'];
$sDBPwd = $aParameters['db_pwd'];
$sDBName = $aParameters['db_name'];
$oPage->add_ready_script('oXHRCheckDB = null;');
$checks = SetupUtils::CheckServerConnection($sDBServer, $sDBUser, $sDBPwd);
if ($checks === false)
{
// Connection failed, disable the "Next" button
$oPage->add_ready_script('$("#wiz_form").data("db_connection", "error");');
$oPage->add_ready_script('$("#db_info").html("No connection to the database...");');
}
else
{
$aErrors = array();
$aWarnings = array();
foreach($checks['checks'] as $oCheck)
{
if ($oCheck->iSeverity == CheckResult::ERROR)
{
$aErrors[] = $oCheck->sLabel;
}
else if ($oCheck->iSeverity == CheckResult::WARNING)
{
$aWarnings[] = $oCheck->sLabel;
}
}
if (count($aErrors) > 0)
{
$oPage->add_ready_script('$("#wiz_form").data("db_connection", "error");');
$oPage->add_ready_script('$("#db_info").html(\'<img src="../images/validation_error.png"/>&nbsp;<b>Error:</b> '.htmlentities(implode('<br/>', $aErrors), ENT_QUOTES, 'UTF-8').'\');');
}
else if (count($aWarnings) > 0)
{
$oPage->add_ready_script('$("#wiz_form").data("db_connection", "");');
$oPage->add_ready_script('$("#db_info").html(\'<img src="../images/error.png"/>&nbsp;<b>Warning:</b> '.htmlentities(implode('<br/>', $aWarnings), ENT_QUOTES, 'UTF-8').'\');');
}
else
{
$oPage->add_ready_script('$("#wiz_form").data("db_connection", "");');
$oPage->add_ready_script('$("#db_info").html(\'<img src="../images/validation_ok.png"/>&nbsp;Database server connection Ok.\');');
}
if ($checks['databases'] == null)
{
$sDBNameInput = '<input id="db_name" name="db_name" size="15" maxlen="32" value="'.htmlentities($sDBName, ENT_QUOTES, 'UTF-8').'"/><span style="width:20px;" id="v_db_name"></span>';
$oPage->add_ready_script('$("#table_info").html(\'<img src="../images/error.png"/>&nbsp;Not enough rights to enumerate the databases\');');
}
else
{
$sDBNameInput = '<select id="db_name" name="db_name">';
foreach($checks['databases'] as $sDatabaseName)
{
if ($sDatabaseName != 'information_schema')
{
$sEncodedName = htmlentities($sDatabaseName, ENT_QUOTES, 'UTF-8');
$sSelected = ($sDatabaseName == $sDBName) ? ' selected ' : '';
$sDBNameInput .= '<option value="'.$sEncodedName.'"'.$sSelected.'>'.$sEncodedName.'</option>';
}
}
$sDBNameInput .= '</select>';
}
$oPage->add_ready_script('$("#db_name_container").html("'.addslashes($sDBNameInput).'");');
$oPage->add_ready_script('$("#db_name").bind("click", function() { $("#existing_db").attr("checked", "checked"); WizardUpdateButtons(); });');
$oPage->add_ready_script('$("#db_name").bind("keyup change", function() { WizardUpdateButtons(); });');
}
$oPage->add_ready_script('WizardUpdateButtons();');
}
/**
* Helper function to get the available languages from the given directory
* @param $sDir Path to the dictionary
* @return an array of language code => description
*/
static public function GetAvailableLanguages($sDir)
{
require_once(APPROOT.'/core/coreexception.class.inc.php');
require_once(APPROOT.'/core/dict.class.inc.php');
$aFiles = scandir($sDir);
foreach($aFiles as $sFile)
{
if ($sFile == '.' || $sFile == '..' || $sFile == '.svn')
{
// Skip
continue;
}
$sFilePath = $sDir.'/'.$sFile;
if (is_file($sFilePath) && preg_match('/^.+\.dict.*\.php$/i', $sFilePath, $aMatches))
{
require_once($sFilePath);
}
}
return Dict::GetLanguages();
}
static public function GetLanguageSelect($sSourceDir, $sInputName, $sDefaultLanguageCode)
{
$sHtml = '<select id="'.$sInputName.'" name="'.$sInputName.'">';
$sSourceDir = APPROOT.'dictionaries/';
$aLanguages = SetupUtils::GetAvailableLanguages($sSourceDir);
foreach($aLanguages as $sCode => $aInfo)
{
$sSelected = ($sCode == $sDefaultLanguageCode) ? ' selected ' : '';
$sHtml .= '<option value="'.$sCode.'"'.$sSelected.'>'.htmlentities($aInfo['description'], ENT_QUOTES, 'UTF-8').' ('.htmlentities($aInfo['localized_description'], ENT_QUOTES, 'UTF-8').')</option>';
}
$sHtml .= '</select></td></tr>';
return $sHtml;
}
}