diff --git a/datamodels/2.x/itop-hub-connector/launch.php b/datamodels/2.x/itop-hub-connector/launch.php index 5e042c734a..2bca313f09 100644 --- a/datamodels/2.x/itop-hub-connector/launch.php +++ b/datamodels/2.x/itop-hub-connector/launch.php @@ -27,7 +27,7 @@ /** * Collect the configuration information to be posted to the hub - * + * * @return string[][] */ @@ -104,17 +104,18 @@ * Return a cleaned (i.e. * properly truncated) versin number from * a very long version number like "7.0.18-0unbuntu0-16.04.1" - * + * * @param string $sString + * * @return string */ function CleanVersionNumber($sString) { $aMatches = array(); - if (preg_match("|^([0-9\\.]+)-|", $sString, $aMatches)) - { + if (preg_match("|^([0-9\\.]+)-|", $sString, $aMatches)) { return $aMatches[1]; } + return $sString; } @@ -123,260 +124,234 @@ function collect_configuration() $aConfiguration = array( 'php' => array(), 'mysql' => array(), - 'apache' => array() + 'apache' => array(), ); - + // Database information $m_oMysqli = CMDBSource::GetMysqli(); - $aConfiguration['database_settings']['server'] = (string) $m_oMysqli->server_version; - $aConfiguration['database_settings']['client'] = (string) $m_oMysqli->client_version; - + $aConfiguration['database_settings']['server'] = (string)$m_oMysqli->server_version; + $aConfiguration['database_settings']['client'] = (string)$m_oMysqli->client_version; + /** @var mysqli_result $resultSet */ $result = CMDBSource::Query('SHOW VARIABLES LIKE "%max_allowed_packet%"'); - if ($result) - { + if ($result) { $row = $result->fetch_object(); - $aConfiguration['database_settings']['max_allowed_packet'] = (string) $row->Value; + $aConfiguration['database_settings']['max_allowed_packet'] = (string)$row->Value; } - + /** @var mysqli_result $resultSet */ $result = CMDBSource::Query('SHOW VARIABLES LIKE "%version_comment%"'); - if ($result) - { + if ($result) { $row = $result->fetch_object(); - if (preg_match('/mariadb/i', $row->Value)) - { + if (preg_match('/mariadb/i', $row->Value)) { $aConfiguration['database_name'] = 'MariaDB'; } } - + // Web server information - if (function_exists('apache_get_version')) - { + if (function_exists('apache_get_version')) { $aConfiguration['web_server_name'] = 'apache'; $aConfiguration['web_server_version'] = apache_get_version(); - } - else - { + } else { // The format of the variable $_SERVER["SERVER_SOFTWARE"] seems to be the following: // PHP 7 FPM with Apache on Ubuntu: "Apache/2.4.18 (Ubuntu)" // IIS 7.5 on Windows 7: "Microsoft-IIS/7.5" // Nginx with PHP FPM on Ubuntu: "nginx/1.10.0" $aConfiguration['web_server_name'] = substr($_SERVER["SERVER_SOFTWARE"], 0, strpos($_SERVER["SERVER_SOFTWARE"], '/')); - $sWebServerVersion = trim(substr($_SERVER["SERVER_SOFTWARE"], 1+strpos($_SERVER["SERVER_SOFTWARE"], '/'))); - if ($sWebServerVersion == '') - { + $sWebServerVersion = trim(substr($_SERVER["SERVER_SOFTWARE"], 1 + strpos($_SERVER["SERVER_SOFTWARE"], '/'))); + if ($sWebServerVersion == '') { $sWebServerVersion = 'Unknown'; } $aConfiguration['web_server_version'] = $sWebServerVersion; } - + // PHP extensions - if (!MetaModel::GetConfig()->GetModuleSetting('itop-hub-connector', 'php_extensions_enable', true)) - { + if (!MetaModel::GetConfig()->GetModuleSetting('itop-hub-connector', 'php_extensions_enable', true)) { $aConfiguration['php_extensions'] = array(); - } - else - { - foreach (get_loaded_extensions() as $extension) - { + } else { + foreach (get_loaded_extensions() as $extension) { $aConfiguration['php_extensions'][$extension] = $extension; } } - + // Collect some PHP settings having a known impact on iTop $aIniGet = MetaModel::GetConfig()->GetModuleSetting('itop-hub-connector', 'php_settings_array', array()); // by default, on the time of the writting, it values are : array('post_max_size', 'upload_max_filesize', 'apc.enabled', 'timezone', 'memory_limit', 'max_execution_time'); $aConfiguration['php_settings'] = array(); - foreach ($aIniGet as $iniGet) - { - $aConfiguration['php_settings'][$iniGet] = (string) ini_get($iniGet); + foreach ($aIniGet as $iniGet) { + $aConfiguration['php_settings'][$iniGet] = (string)ini_get($iniGet); } - + // iTop modules $oConfig = MetaModel::GetConfig(); $sLatestInstallationDate = CMDBSource::QueryToScalar("SELECT max(installed) FROM ".$oConfig->Get('db_subname')."priv_module_install"); // Get the latest installed modules, without the "root" ones (iTop version and datamodel version) $aInstalledModules = CMDBSource::QueryToArray("SELECT * FROM ".$oConfig->Get('db_subname')."priv_module_install WHERE installed = '".$sLatestInstallationDate."' AND parent_id != 0"); - - foreach ($aInstalledModules as $aDBInfo) - { + + foreach ($aInstalledModules as $aDBInfo) { $aConfiguration['itop_modules'][$aDBInfo['name']] = $aDBInfo['version']; } - + // iTop Installation Options, i.e. "Extensions" $oExtensionMap = new iTopExtensionsMap(); $oExtensionMap->LoadChoicesFromDatabase($oConfig); $aConfiguration['itop_extensions'] = array(); - foreach ($oExtensionMap->GetChoices() as $oExtension) - { - switch ($oExtension->sSource) - { + foreach ($oExtensionMap->GetChoices() as $oExtension) { + switch ($oExtension->sSource) { case iTopExtension::SOURCE_MANUAL: case iTopExtension::SOURCE_REMOTE: - $aConfiguration['itop_extensions'][$oExtension->sCode] = array( - 'label' => $oExtension->sLabel, - 'value' => $oExtension->sInstalledVersion - ); - break; - + $aConfiguration['itop_extensions'][$oExtension->sCode] = array( + 'label' => $oExtension->sLabel, + 'value' => $oExtension->sInstalledVersion, + ); + break; + default: - $aConfiguration['itop_installation_options'][$oExtension->sCode] = array( - 'label' => $oExtension->sLabel, - 'value' => true - ); + $aConfiguration['itop_installation_options'][$oExtension->sCode] = array( + 'label' => $oExtension->sLabel, + 'value' => true, + ); } } + return $aConfiguration; } function MakeDataToPost($sTargetRoute) { - if (MetaModel::GetConfig()->Get('demo_mode')) - { + if (MetaModel::GetConfig()->Get('demo_mode')) { // Don't expose such information in demo mode $aDataToPost = array('disabled' => true, 'reason' => 'demo_mode'); - } - else - { + } else { $aConfiguration = collect_configuration(); - + $aDataToPost = array( 'itop_hub_target_route' => $sTargetRoute, 'itop_stack' => array( - "uuidBdd" => (string) trim(DBProperty::GetProperty('database_uuid', ''), '{}'), // TODO check if empty and... regenerate a new UUID ?? - "uuidFile" => (string) trim(@file_get_contents(APPROOT."data/instance.txt"), "{} \n"), // TODO check if empty and... regenerate a new UUID ?? - 'instance_friendly_name' => (string) $_SERVER['SERVER_NAME'], - 'instance_host' => (string) utils::GetAbsoluteUrlAppRoot(), - 'application_name' => (string) ITOP_APPLICATION, - 'application_version' => (string) ITOP_VERSION, - 'application_version_full' => (string) Dict::Format('UI:iTopVersion:Long', ITOP_APPLICATION, ITOP_VERSION, ITOP_REVISION, ITOP_BUILD_DATE), - 'itop_user_id' => (string) (UserRights::GetUserId()===null) ? "1" : UserRights::GetUserId(), - 'itop_user_lang' => (string) UserRights::GetUserLanguage(), - 'itop_modules' => (object) $aConfiguration['itop_modules'], - 'itop_extensions' => (object) $aConfiguration['itop_extensions'], - 'itop_installation_options' => (object) $aConfiguration['itop_installation_options'] + "uuidBdd" => (string)trim(DBProperty::GetProperty('database_uuid', ''), '{}'), // TODO check if empty and... regenerate a new UUID ?? + "uuidFile" => (string)trim(@file_get_contents(APPROOT."data/instance.txt"), "{} \n"), // TODO check if empty and... regenerate a new UUID ?? + 'instance_friendly_name' => (string)$_SERVER['SERVER_NAME'], + 'instance_host' => (string)utils::GetAbsoluteUrlAppRoot(), + 'application_name' => (string)ITOP_APPLICATION, + 'application_version' => (string)ITOP_VERSION, + 'application_version_full' => (string)Dict::Format('UI:iTopVersion:Long', ITOP_APPLICATION, ITOP_VERSION, ITOP_REVISION, ITOP_BUILD_DATE), + 'itop_user_id' => (string)(UserRights::GetUserId() === null) ? "1" : UserRights::GetUserId(), + 'itop_user_lang' => (string)UserRights::GetUserLanguage(), + 'itop_modules' => (object)$aConfiguration['itop_modules'], + 'itop_extensions' => (object)$aConfiguration['itop_extensions'], + 'itop_installation_options' => (object)$aConfiguration['itop_installation_options'], ), 'server_stack' => array( - 'os_name' => (string) PHP_OS, - 'web_server_name' => (string) $aConfiguration['web_server_name'], - 'web_server_version' => (string) $aConfiguration['web_server_version'], - 'database_name' => (string) isset($aConfiguration['database_name']) ? $aConfiguration['database_name'] : 'MySQL', // if we do not detect MariaDB, we assume this is mysql - 'database_version' => (string) CMDBSource::GetDBVersion(), - 'database_settings' => (object) $aConfiguration['database_settings'], - 'php_version' => (string) CleanVersionNumber(phpversion()), - 'php_settings' => (object) $aConfiguration['php_settings'], - 'php_extensions' => (object) $aConfiguration['php_extensions'] - ) + 'os_name' => (string)PHP_OS, + 'web_server_name' => (string)$aConfiguration['web_server_name'], + 'web_server_version' => (string)$aConfiguration['web_server_version'], + 'database_name' => (string)isset($aConfiguration['database_name']) ? $aConfiguration['database_name'] : 'MySQL', // if we do not detect MariaDB, we assume this is mysql + 'database_version' => (string)CMDBSource::GetDBVersion(), + 'database_settings' => (object)$aConfiguration['database_settings'], + 'php_version' => (string)CleanVersionNumber(phpversion()), + 'php_settings' => (object)$aConfiguration['php_settings'], + 'php_extensions' => (object)$aConfiguration['php_extensions'], + ), ); } + return $aDataToPost; } -try -{ - require_once (APPROOT.'/application/application.inc.php'); - require_once (APPROOT.'/application/itopwebpage.class.inc.php'); - require_once (APPROOT.'/setup/extensionsmap.class.inc.php'); - require_once ('hubconnectorpage.class.inc.php'); - - require_once (APPROOT.'/application/startup.inc.php'); - +try { + require_once(APPROOT.'/application/application.inc.php'); + require_once(APPROOT.'/application/itopwebpage.class.inc.php'); + require_once(APPROOT.'/setup/extensionsmap.class.inc.php'); + require_once('hubconnectorpage.class.inc.php'); + + require_once(APPROOT.'/application/startup.inc.php'); + $sTargetRoute = utils::ReadParam('target', ''); // ||browse_extensions|deploy_extensions| - - if ($sTargetRoute != 'inform_after_setup') - { - require_once (APPROOT.'/application/loginwebpage.class.inc.php'); + + if ($sTargetRoute != 'inform_after_setup') { + require_once(APPROOT.'/application/loginwebpage.class.inc.php'); LoginWebPage::DoLoginEx(null, true /* $bMustBeAdmin */); // Check user rights and prompt if needed } - + $sHubUrlStateless = MetaModel::GetModuleSetting('itop-hub-connector', 'url').MetaModel::GetModuleSetting('itop-hub-connector', 'route_landing_stateless'); $sHubUrl = MetaModel::GetModuleSetting('itop-hub-connector', 'url').MetaModel::GetModuleSetting('itop-hub-connector', 'route_landing'); - + // Display... or not... the page - - switch ($sTargetRoute) - { + + switch ($sTargetRoute) { case 'inform_after_setup': - // Hidden IFRAME at the end of the setup - require_once (APPROOT.'/application/ajaxwebpage.class.inc.php'); - $oPage = new NiceWebPage(''); - $aDataToPost = MakeDataToPost($sTargetRoute); - $oPage->add('