Commit 2639524c authored by loiclau's avatar loiclau Committed by Loic Laurent
Browse files

fix(CLAPI) save user language encoding in db (#9361)

parent 0db06565
......@@ -793,7 +793,7 @@ LDAP;SETPARAM;test_configuration-LDAP;user_group;memberOf;
LDAP;SETPARAM;test_configuration-LDAP;user_lastname;sn;
LDAP;SETPARAM;test_configuration-LDAP;user_name;name;
LDAP;SETPARAM;test_configuration-LDAP;user_pager;mobile;
CONTACT;ADD;admin admin;admin;admin@centreon.com;md5__2f0a912f1c89b4f4fc9edd324d9d1c89;1;1;en_US;local
CONTACT;ADD;admin admin;admin;admin@centreon.com;md5__2f0a912f1c89b4f4fc9edd324d9d1c89;1;1;en_US.UTF-8;local
CONTACT;setparam;admin;hostnotifperiod;24x7
CONTACT;setparam;admin;svcnotifperiod;24x7
CONTACT;setparam;admin;hostnotifopt;n
......@@ -809,7 +809,7 @@ CONTACT;setparam;admin;contact_ldap_last_sync;0
CONTACT;setparam;admin;contact_ldap_required_sync;0
CONTACT;setparam;admin;hostnotifcmd;host-notify-by-email
CONTACT;setparam;admin;svcnotifcmd;service-notify-by-email
CONTACT;ADD;Guest;guest;guest@localhost;md5__d41d8cd98f00b204e9800998ecf8427e;0;0;en_US;local
CONTACT;ADD;Guest;guest;guest@localhost;md5__d41d8cd98f00b204e9800998ecf8427e;0;0;en_US.UTF-8;local
CONTACT;setparam;guest;hostnotifperiod;24x7
CONTACT;setparam;guest;svcnotifperiod;24x7
CONTACT;setparam;guest;hostnotifopt;n
......@@ -837,7 +837,7 @@ CONTACT;setparam;jeanpierre;contact_type_msg;txt
CONTACT;setparam;jeanpierre;contact_activate;1
CONTACT;setparam;jeanpierre;contact_ldap_last_sync;0
CONTACT;setparam;jeanpierre;contact_ldap_required_sync;0
CONTACT;ADD;test_contact;test_contact;test@localhost;md5__b0e52a1510c9012ebae9e9dc1ae0c46e;0;0;en_US;local
CONTACT;ADD;test_contact;test_contact;test@localhost;md5__b0e52a1510c9012ebae9e9dc1ae0c46e;0;0;en_US.UTF-8;local
CONTACT;setparam;test_contact;hostnotifopt;n
CONTACT;setparam;test_contact;servicenotifopt;n
CONTACT;setparam;test_contact;contact_js_effects;0
......@@ -849,7 +849,7 @@ CONTACT;setparam;test_contact;contact_type_msg;txt
CONTACT;setparam;test_contact;contact_activate;1
CONTACT;setparam;test_contact;contact_ldap_last_sync;0
CONTACT;setparam;test_contact;contact_ldap_required_sync;0
CONTACT;ADD;User;user;user@localhost;md5__d41d8cd98f00b204e9800998ecf8427e;0;0;en_US;local
CONTACT;ADD;User;user;user@localhost;md5__d41d8cd98f00b204e9800998ecf8427e;0;0;en_US.UTF-8;local
CONTACT;setparam;user;hostnotifperiod;24x7
CONTACT;setparam;user;svcnotifperiod;24x7
CONTACT;setparam;user;hostnotifopt;n
......
......@@ -199,15 +199,13 @@ class CentreonContact extends CentreonObject
if (!$locale || $locale == "") {
return true;
}
if (strtolower($locale) == "en_us" || strtolower($locale) == "browser") {
if (strtolower($locale) === "en_us.utf-8" || strtolower($locale) === "browser") {
return true;
}
$centreonDir = realpath(__DIR__ . "/../../../") . "/www/locale";
$dir = opendir($centreonDir) ;
while (false !== ($ssDir = readdir($dir))) {
if (($locale === substr($ssDir, 0, 5)) && is_dir($centreonDir . '/' . $ssDir)) {
return true;
}
$centreonDir = realpath(__DIR__ . "/../../../");
$dir = $centreonDir . "/www/locale/$locale";
if (is_dir($dir)) {
return true;
}
return false;
}
......@@ -297,10 +295,19 @@ class CentreonContact extends CentreonObject
if ($addParams['contact_oreon'] == '') {
$addParams['contact_oreon'] = '1';
}
if ($this->checkLang($params[self::ORDER_LANG]) == false) {
if (
empty($params[self::ORDER_LANG])
|| strtolower($params[self::ORDER_LANG]) === "browser"
|| strtoupper(substr($params[self::ORDER_LANG], -6)) === '.UTF-8'
) {
$completeLanguage = $params[self::ORDER_LANG];
} else {
$completeLanguage = $params[self::ORDER_LANG] . '.UTF-8';
}
if ($this->checkLang($completeLanguage) == false) {
throw new CentreonClapiException(self::UNKNOWN_LOCALE);
}
$addParams['contact_lang'] = $params[self::ORDER_LANG];
$addParams['contact_lang'] = $completeLanguage;
$addParams['contact_auth_type'] = $params[self::ORDER_AUTHTYPE];
$this->params = array_merge($this->params, $addParams);
$this->checkParameters();
......@@ -356,10 +363,20 @@ class CentreonContact extends CentreonObject
} elseif ($params[1] == "authtype") {
$params[1] = "auth_type";
} elseif ($params[1] == "lang" || $params[1] == "language" || $params[1] == "locale") {
if ($this->checkLang($params[2]) == false) {
if (
empty($params[2])
|| strtoupper(substr($params[2], -6)) === '.UTF-8'
|| strtolower($params[2]) === "browser"
) {
$completeLanguage = $params[2];
} else {
$completeLanguage = $params[2] . '.UTF-8';
}
if ($this->checkLang($completeLanguage) == false) {
throw new CentreonClapiException(self::UNKNOWN_LOCALE);
}
$params[1] = "lang";
$params[2] = $completeLanguage;
} elseif ($params[1] == "password") {
$params[1] = "passwd";
$params[2] = md5(trim($params[2]));
......
......@@ -8,9 +8,9 @@ INSERT INTO `informations` (`key` ,`value`) VALUES ('version', '19.10.19');
-- Contenu de la table `contact`
--
INSERT INTO `contact` (`contact_id`, `timeperiod_tp_id`, `timeperiod_tp_id2`, `contact_name`, `contact_alias`, `contact_passwd`, `contact_lang`, `contact_host_notification_options`, `contact_service_notification_options`, `contact_email`, `contact_pager`, `contact_comment`, `contact_oreon`, `contact_admin`, `contact_type_msg`, `contact_activate`, `contact_auth_type`, `contact_ldap_dn`, `contact_enable_notifications`) VALUES(1, 1, 1, '@firstname@ @lastname@', 'admin', MD5('@admin_password@'), 'en_US', 'n', 'n', '@email@', NULL, NULL, '1', '1', 'txt', '1', 'local', NULL, '1');
INSERT INTO `contact` (`contact_id`, `timeperiod_tp_id`, `timeperiod_tp_id2`, `contact_name`, `contact_alias`, `contact_passwd`, `contact_lang`, `contact_host_notification_options`, `contact_service_notification_options`, `contact_email`, `contact_pager`, `contact_comment`, `contact_oreon`, `contact_admin`, `contact_type_msg`, `contact_activate`, `contact_auth_type`, `contact_ldap_dn`) VALUES(17, 1, 1, 'Guest', 'guest', NULL, 'en_US', 'n', 'n', 'guest@localhost', NULL, NULL, '0', '0', 'txt', '0', 'local', NULL);
INSERT INTO `contact` (`contact_id`, `timeperiod_tp_id`, `timeperiod_tp_id2`, `contact_name`, `contact_alias`, `contact_passwd`, `contact_lang`, `contact_host_notification_options`, `contact_service_notification_options`, `contact_email`, `contact_pager`, `contact_comment`, `contact_oreon`, `contact_admin`, `contact_type_msg`, `contact_activate`, `contact_auth_type`, `contact_ldap_dn`) VALUES(18, 1, 1, 'User', 'user', NULL, 'en_US', 'n', 'n', 'user@localhost', NULL, NULL, '0', '0', 'txt', '0', 'local', NULL);
INSERT INTO `contact` (`contact_id`, `timeperiod_tp_id`, `timeperiod_tp_id2`, `contact_name`, `contact_alias`, `contact_passwd`, `contact_lang`, `contact_host_notification_options`, `contact_service_notification_options`, `contact_email`, `contact_pager`, `contact_comment`, `contact_oreon`, `contact_admin`, `contact_type_msg`, `contact_activate`, `contact_auth_type`, `contact_ldap_dn`, `contact_enable_notifications`) VALUES(1, 1, 1, '@firstname@ @lastname@', 'admin', MD5('@admin_password@'), 'en_US.UTF-8', 'n', 'n', '@email@', NULL, NULL, '1', '1', 'txt', '1', 'local', NULL, '1');
INSERT INTO `contact` (`contact_id`, `timeperiod_tp_id`, `timeperiod_tp_id2`, `contact_name`, `contact_alias`, `contact_passwd`, `contact_lang`, `contact_host_notification_options`, `contact_service_notification_options`, `contact_email`, `contact_pager`, `contact_comment`, `contact_oreon`, `contact_admin`, `contact_type_msg`, `contact_activate`, `contact_auth_type`, `contact_ldap_dn`) VALUES(17, 1, 1, 'Guest', 'guest', NULL, 'en_US.UTF-8', 'n', 'n', 'guest@localhost', NULL, NULL, '0', '0', 'txt', '0', 'local', NULL);
INSERT INTO `contact` (`contact_id`, `timeperiod_tp_id`, `timeperiod_tp_id2`, `contact_name`, `contact_alias`, `contact_passwd`, `contact_lang`, `contact_host_notification_options`, `contact_service_notification_options`, `contact_email`, `contact_pager`, `contact_comment`, `contact_oreon`, `contact_admin`, `contact_type_msg`, `contact_activate`, `contact_auth_type`, `contact_ldap_dn`) VALUES(18, 1, 1, 'User', 'user', NULL, 'en_US.UTF-8', 'n', 'n', 'user@localhost', NULL, NULL, '0', '0', 'txt', '0', 'local', NULL);
--
......
......@@ -19,6 +19,8 @@
*
*/
require_once __DIR__ . '/../../class/centreonLog.class.php';
// error specific content
$versionOfTheUpgrade = 'UPGRADE - 19.10.19 : ';
$errorMessage = '';
......@@ -59,7 +61,26 @@ try {
}
}
} catch (\Throwable $ex) {
require_once __DIR__ . '/../../class/centreonLog.class.php';
(new CentreonLog())->insertLog(
4,
$versionOfTheUpgrade . $errorMessage .
" - Code : " . $ex->getCode() .
" - Error : " . $ex->getMessage() .
" - Trace : " . $ex->getTraceAsString()
);
throw new \Exception($versionOfTheUpgrade . $errorMessage, $ex->getCode(), $ex);
}
// Contact language with transaction
try {
$pearDB->beginTransaction();
$errorMessage = "Unable to Update user language";
$pearDB->query(
"UPDATE contact SET contact_lang = CONCAT(contact_lang, '.UTF-8')
WHERE contact_lang NOT LIKE '%UTF-8' AND contact_lang <> 'browser' AND contact_lang <> ''"
);
$pearDB->commit();
} catch (\Throwable $ex) {
$pearDB->rollBack();
(new CentreonLog())->insertLog(
4,
$versionOfTheUpgrade . $errorMessage .
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment