Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
Cp7 m27 widgets related fixes (#6293)
Browse files Browse the repository at this point in the history
* fix(global): add checks to db functions and counts

* fix(global): fix PHP`s notifications and warnings

* fix(services): add monitoring fixes for warnings

* fix(global): Undefined variable: upgrade_infosTxt

in upgrade form was missing variable

Resolves CP7M-27

* fix(quickform): fix select2 default data
  • Loading branch information
v-radev authored and kduret committed Jun 5, 2018
1 parent be5c498 commit ba492fc
Show file tree
Hide file tree
Showing 39 changed files with 165 additions and 126 deletions.
7 changes: 3 additions & 4 deletions www/api/class/centreon_home_customview.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,8 @@ public function getPreferences()
require_once _CENTREON_PATH_ . "www/class/centreonWidget/Params/Compare.class.php";
require_once _CENTREON_PATH_ . "www/class/centreonWidget/Params/Sort.class.php";
require_once _CENTREON_PATH_ . "www/class/centreonWidget/Params/Date.class.php";
require_once __DIR__ . "/../../../GPL_LIB/Smarty/libs/Smarty.class.php";
require_once __DIR__ . "/../../lib/HTML/QuickForm.php";
require_once __DIR__ . "/../../lib/HTML/QuickForm/advmultiselect.php";
require_once __DIR__ . "/../../lib/HTML/QuickForm/Renderer/ArraySmarty.php";
$smartyDir = __DIR__ . '/../../../vendor/smarty/smarty/';
require_once $smartyDir . 'libs/Smarty.class.php';

global $centreon;

Expand Down Expand Up @@ -225,6 +223,7 @@ public function getPreferences()
$tpl->config_dir = $libDir . '/SmartyCache/config';
$tpl->cache_dir = $libDir . '/SmartyCache/cache';
$tpl->template_dir = _CENTREON_PATH_ . '/www/include/home/customViews/';
$tpl->plugins_dir[] = $libDir . '/smarty-plugins';
$tpl->caching = 0;
$tpl->compile_check = true;
$tpl->force_compile = true;
Expand Down
6 changes: 6 additions & 0 deletions www/class/centreonGraphService.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,16 @@ public function getData($rows = 200)
}

/* Transform XML to values */
$useXmlErrors = libxml_use_internal_errors(true);
$xml = simplexml_load_string($str);

if (false === $xml) {
throw new RuntimeException();
}

libxml_clear_errors();
libxml_use_internal_errors($useXmlErrors);

$rows = $xml->xpath("//xport/data/row");
foreach ($rows as $row) {
$time = null;
Expand Down
4 changes: 2 additions & 2 deletions www/class/centreonLDAP.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,8 @@ protected function updateLdapServers($arId)
if (isset($_REQUEST['address'])) {
$addressList = $_REQUEST['address'];
$portList = $_REQUEST['port'];
$sslList = $_REQUEST['ssl'];
$tlsList = $_REQUEST['tls'];
$sslList = isset($_REQUEST['ssl']) ? $_REQUEST['ssl'] : null;
$tlsList = isset($_REQUEST['tls']) ? $_REQUEST['tls'] : null;
$insertStr = "";
$i = 1;
foreach ($addressList as $key => $addr) {
Expand Down
6 changes: 3 additions & 3 deletions www/class/centreonTraps.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,9 @@ public function insert($ret = array())
$rq .= "'" . $this->db->escape($ret["manufacturer_id"]) . "',";
$rq .= "'" . $this->db->escape($ret["traps_log"]) . "', ";
$rq .= "'" . $this->db->escape($ret["traps_exec_interval"]) . "', ";
$rq .= "'" . $this->db->escape($ret["traps_exec_interval_type"]) . "', ";
$rq .= "'" . $this->db->escape($ret["traps_exec_method"]) . "', ";
$rq .= "'" . $this->db->escape($ret["traps_downtime"]) . "', ";
$rq .= "'" . $this->db->escape(isset($ret["traps_exec_interval_type"]) ? $ret["traps_exec_interval_type"] : '') . "', ";
$rq .= "'" . $this->db->escape(isset($ret["traps_exec_method"]) ? $ret["traps_exec_method"] : '') . "', ";
$rq .= "'" . $this->db->escape(isset($ret["traps_downtime"]) ? $ret["traps_downtime"] : '') . "', ";
$rq .= "'" . $this->db->escape($ret["traps_output_transform"]) . "', ";
$rq .= "'" . $this->db->escape($ret['traps_advanced_treatment_default']) . "', ";
$rq .= "'" . $this->db->escape($ret["traps_timeout"]) . "', ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</div>
{/if}
{/foreach}
{if count($io_infos.filters)}
{if $io_infos.filters && count($io_infos.filters)}
<div class="informations">
<span class="info_name">{$lang.filters}</span>
<p class="info_name" id="filters_{$io_name}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ function parseStatsFile($statfile)
}

if ((preg_match('/.*external commands.*/', $key) && $json_stats[$key]['state'] != "disconnected") || (!preg_match('/.*external commands.*/', $key))) {
$keySepByDash = explode('-', $key);
$keySepBySpace = explode(' ', $key);
$result['io'][$matches[1]] = createArrayStats($json_stats[$key]);
$result['io'][$matches[1]]['type'] = end(explode('-', $key));
$result['io'][$matches[1]]['id'] = end(explode(' ', $key));
$result['io'][$matches[1]]['type'] = end($keySepByDash);
$result['io'][$matches[1]]['id'] = end($keySepBySpace);
$result['io'][$matches[1]]['id'] = rtrim($result['io'][$matches[1]]['id'], ')');


Expand Down
2 changes: 1 addition & 1 deletion www/include/Administration/myAccount/formMyAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
$pages[$topo3["topology_page"]] = " " . _($topo1["topology_name"]) . " > " .
_($topo2["topology_name"]) . " > " . _($topo3["topology_name"]);
}
$query = "SELECT topology_name, topology_parent FROM topology " .
$query = "SELECT topology_name, topology_page, topology_parent FROM topology " .
"WHERE topology_parent = '" . $topo3["topology_page"] . "' " .
"AND topology_page IS NOT NULL AND topology_show = '1' ORDER BY topology_order";
$DBRESULT4 = $pearDB->query($query);
Expand Down
4 changes: 2 additions & 2 deletions www/include/Administration/parameters/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ function updateODSConfigData()
if (!isset($ret["autodelete_rrd_db"])) {
$ret["autodelete_rrd_db"] = 0;
}
if ($ret["purge_interval"] <= 20) {
if (!isset($ret["purge_interval"]) || $ret["purge_interval"] <= 20) {
$ret["purge_interval"] = 20;
}
if (!isset($ret["archive_log"])) {
Expand Down Expand Up @@ -829,7 +829,7 @@ function updateODSConfigData()
`archive_retention` = '".$ret["archive_retention"]."',
`reporting_retention` = '".$ret["reporting_retention"]."',
`audit_log_option` = '".$ret["audit_log_option"]."',
`storage_type` = '".$ret["storage_type"]."',
`storage_type` = '".(isset($ret["storage_type"]) ? $ret["storage_type"] : null)."',
`len_storage_downtimes` = '".$ret["len_storage_downtimes"]."',
`len_storage_comments` = '".$ret["len_storage_comments"]."' "
. " WHERE `id` = 1 LIMIT 1 ;";
Expand Down
4 changes: 2 additions & 2 deletions www/include/common/common-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ function getMyHostIDByAddress($host_address = null)
$query = "SELECT host_id, host_address, host_template_model_htm_id FROM host " .
"WHERE host_name = '" . CentreonDB::escape($host_address) . "' or host_address = '" .
CentreonDB::escape($host_address) . "' LIMIT 1";
$DBRESULT = &$pearDB->query($query);
$row = &$DBRESULT->fetchRow();
$DBRESULT = $pearDB->query($query);
$row = $DBRESULT->fetchRow();
if ($row["host_id"]) {
return html_entity_decode($row["host_id"], ENT_QUOTES, "UTF-8");
} elseif ($row["host_template_model_htm_id"]) {
Expand Down
2 changes: 1 addition & 1 deletion www/include/configuration/configKnowledge/pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function setL(_this) {
'GET',
"?p=" . $p . "&search_type_service=" . $search_type_service . "&search_type_host=" . $search_type_host
);
$selLim =& $form->addElement(
$selLim = $form->addElement(
'select',
'l',
_("Rows"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
unset($row);
$DBRESULT->closeCursor();

$availableConnectors_list = return_plugin($oreon->optGen["cengine_path_connectors"]);
$availableConnectors_list = return_plugin((isset($oreon->optGen["cengine_path_connectors"]) ? $oreon->optGen["cengine_path_connectors"] : null));

$form = new HTML_QuickFormCustom('Form', 'post', "?p=".$p);

Expand All @@ -105,8 +105,8 @@
'datasourceOrigin' => 'ajax',
'multiple' => true,
'defaultDatasetRoute' => './include/common/webServices/rest/internal.php?'
. 'object=centreon_configuration_command&action=defaultValues&target=connector&field=command_id&id='
. $connector_id,
. 'object=centreon_configuration_command&action=defaultValues&target=connector&field=command_id'
. (isset($connector_id) ? "&id={$connector_id}" : ''),
'availableDatasetRoute' => './include/common/webServices/rest/internal.php?'
. 'object=centreon_configuration_command&action=list',
'linkedObject' => 'centreonCommand'
Expand Down Expand Up @@ -175,7 +175,7 @@
$connectorValues['description'] = $tab['connector_description'];
$connectorValues['command_line'] = $tab['command_line'];
$connectorValues['enabled'] = (int)$tab['connector_status']['connector_status'];
$connectorValues['command_id'] = $tab['command_id'];
$connectorValues['command_id'] = isset($tab['command_id']) ? $tab['command_id'] : null;
$connectorId = $tab['connector_id'];

if ($form->getSubmitValue("submitA")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@
$redirect->setValue($o);

$init = $form->addElement('hidden', 'initialValues');
$init->setValue(serialize($initialValues));
if (isset($initialValues)) {
$init->setValue(serialize($initialValues));
}

#
## Form Rules
Expand Down
54 changes: 32 additions & 22 deletions www/include/configuration/configObject/host/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ function insertHostInDB($ret = array(), $macro_on_demand = null)
"type" => 'HOST',
'id' => $host_id,
"action" => "ADD",
"access_grp_id" => $ret["acl_groups"]
"access_grp_id" => (isset($ret["acl_groups"]) ? $ret["acl_groups"] : null),
));
insertHostExtInfos($host_id, $ret);
return ($host_id);
Expand Down Expand Up @@ -2142,7 +2142,7 @@ function updateHostNotifs($host_id = null, $ret = array())
$rq .= "host_notification_options = ";
isset($ret) && $ret != null ? $rq .= "'" . implode(",", array_keys($ret)) . "' " : $rq .= "NULL ";
$rq .= "WHERE host_id = '" . $host_id . "'";
$DBRESULT = &$pearDB->query($rq);
$DBRESULT = $pearDB->query($rq);
}

// For massive change. incremental mode
Expand Down Expand Up @@ -2193,7 +2193,7 @@ function updateHostNotifOptionInterval($host_id = null, $ret = array())
$rq .= "host_notification_interval = ";
isset($ret) && $ret != null ? $rq .= "'" . $ret . "' " : $rq .= "NULL ";
$rq .= "WHERE host_id = '" . $host_id . "'";
$DBRESULT = &$pearDB->query($rq);
$DBRESULT = $pearDB->query($rq);
}

/**
Expand All @@ -2213,7 +2213,7 @@ function updateHostNotifOptionInterval_MC($host_id = null)
$rq = "UPDATE host SET ";
$rq .= "host_notification_interval = '" . $ret . "' ";
$rq .= "WHERE host_id = '" . $host_id . "'";
$DBRESULT = &$pearDB->query($rq);
$DBRESULT = $pearDB->query($rq);
}
}

Expand All @@ -2235,7 +2235,7 @@ function updateHostNotifOptionTimeperiod($host_id = null, $ret = array())
$rq .= "timeperiod_tp_id2 = ";
isset($ret) && $ret != null ? $rq .= "'" . $ret . "' " : $rq .= "NULL ";
$rq .= "WHERE host_id = '" . $host_id . "'";
$DBRESULT = &$pearDB->query($rq);
$DBRESULT = $pearDB->query($rq);
}

/**
Expand All @@ -2255,7 +2255,7 @@ function updateHostNotifOptionTimeperiod_MC($host_id = null)
$rq = "UPDATE host SET ";
$rq .= "timeperiod_tp_id2 = '" . $ret . "' ";
$rq .= "WHERE host_id = '" . $host_id . "'";
$DBRESULT = &$pearDB->query($rq);
$DBRESULT = $pearDB->query($rq);
}
}

Expand All @@ -2278,7 +2278,7 @@ function updateHostNotifOptionFirstNotificationDelay($host_id = null, $ret = arr
$rq .= "host_first_notification_delay = ";
isset($ret) && $ret != null ? $rq .= "'" . $ret . "' " : $rq .= "NULL ";
$rq .= "WHERE host_id = '" . $host_id . "'";
$DBRESULT = &$pearDB->query($rq);
$DBRESULT = $pearDB->query($rq);
}

/**
Expand All @@ -2299,7 +2299,7 @@ function updateHostNotifOptionFirstNotificationDelay_MC($host_id = null)
$rq = "UPDATE host SET ";
$rq .= "host_first_notification_delay = '" . $ret . "' ";
$rq .= "WHERE host_id = '" . $host_id . "'";
$DBRESULT = &$pearDB->query($rq);
$DBRESULT = $pearDB->query($rq);
}
}

Expand Down Expand Up @@ -2367,13 +2367,16 @@ function updateHostHostGroup($host_id, $ret = array())
$DBRESULT = $pearDB->query($rq);
isset($ret["host_hgs"]) ? $ret = $ret["host_hgs"] : $ret = $form->getSubmitValue("host_hgs");
$hgsNEW = array();
for ($i = 0; $i < count($ret); $i++) {
$rq = "INSERT INTO hostgroup_relation ";
$rq .= "(hostgroup_hg_id, host_host_id) ";
$rq .= "VALUES ";
$rq .= "('" . $ret[$i] . "', '" . $host_id . "')";
$DBRESULT = $pearDB->query($rq);
$hgsNEW[$ret[$i]] = $ret[$i];

if ($ret) {
for ($i = 0; $i < count($ret); $i++) {
$rq = "INSERT INTO hostgroup_relation ";
$rq .= "(hostgroup_hg_id, host_host_id) ";
$rq .= "VALUES ";
$rq .= "('" . $ret[$i] . "', '" . $host_id . "')";
$DBRESULT = $pearDB->query($rq);
$hgsNEW[$ret[$i]] = $ret[$i];
}
}

// Special Case, delete relation between host/service,
Expand Down Expand Up @@ -2452,6 +2455,11 @@ function updateHostHostCategory($host_id, $ret = array())

$ret = isset($ret["host_hcs"]) ? $ret["host_hcs"] : $ret = $form->getSubmitValue("host_hcs");
$hcsNEW = array();

if (!$ret) {
return;
}

for ($i = 0; $i < count($ret); $i++) {
$rq = "INSERT INTO hostcategories_relation ";
$rq .= "(hostcategories_hc_id, host_host_id) ";
Expand Down Expand Up @@ -2575,13 +2583,15 @@ function updateHostTemplateService($host_id = null)
$DBRESULT2 = $pearDB->query($rq);
$ret = array();
$ret = $form->getSubmitValue("host_svTpls");
for ($i = 0; $i < count($ret); $i++) {
if (isset($ret[$i]) && $ret[$i] != "") {
$rq = "INSERT INTO host_service_relation ";
$rq .= "(hostgroup_hg_id, host_host_id, servicegroup_sg_id, service_service_id) ";
$rq .= "VALUES ";
$rq .= "(NULL, '" . $host_id . "', NULL, '" . $ret[$i] . "')";
$DBRESULT2 = $pearDB->query($rq);
if ($ret) {
for ($i = 0; $i < count($ret); $i++) {
if (isset($ret[$i]) && $ret[$i] != "") {
$rq = "INSERT INTO host_service_relation ";
$rq .= "(hostgroup_hg_id, host_host_id, servicegroup_sg_id, service_service_id) ";
$rq .= "VALUES ";
$rq .= "(NULL, '" . $host_id . "', NULL, '" . $ret[$i] . "')";
$DBRESULT2 = $pearDB->query($rq);
}
}
}
} elseif ($centreon->user->get_version() >= 3) {
Expand Down
16 changes: 8 additions & 8 deletions www/include/configuration/configObject/host/formHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,14 +603,14 @@ function allInSameInstance($hosts, $instanceId)

if ($o == "mc") {
$mc_mod_notifopt_first_notification_delay = array();
$mc_mod_notifopt_first_notification_delay[] = &$form->createElement(
$mc_mod_notifopt_first_notification_delay[] = $form->createElement(
'radio',
'mc_mod_notifopt_first_notification_delay',
null,
_("Incremental"),
'0'
);
$mc_mod_notifopt_first_notification_delay[] = &$form->createElement(
$mc_mod_notifopt_first_notification_delay[] = $form->createElement(
'radio',
'mc_mod_notifopt_first_notification_delay',
null,
Expand Down Expand Up @@ -697,14 +697,14 @@ function allInSameInstance($hosts, $instanceId)

if ($o == "mc") {
$mc_mod_notifopt_notification_interval = array();
$mc_mod_notifopt_notification_interval[] = &$form->createElement(
$mc_mod_notifopt_notification_interval[] = $form->createElement(
'radio',
'mc_mod_notifopt_notification_interval',
null,
_("Incremental"),
'0'
);
$mc_mod_notifopt_notification_interval[] = &$form->createElement(
$mc_mod_notifopt_notification_interval[] = $form->createElement(
'radio',
'mc_mod_notifopt_notification_interval',
null,
Expand All @@ -724,14 +724,14 @@ function allInSameInstance($hosts, $instanceId)

if ($o == "mc") {
$mc_mod_notifopt_timeperiod = array();
$mc_mod_notifopt_timeperiod[] = &$form->createElement(
$mc_mod_notifopt_timeperiod[] = $form->createElement(
'radio',
'mc_mod_notifopt_timeperiod',
null,
_("Incremental"),
'0'
);
$mc_mod_notifopt_timeperiod[] = &$form->createElement(
$mc_mod_notifopt_timeperiod[] = $form->createElement(
'radio',
'mc_mod_notifopt_timeperiod',
null,
Expand All @@ -751,8 +751,8 @@ function allInSameInstance($hosts, $instanceId)

if ($o == "mc") {
$mc_mod_notifopts = array();
$mc_mod_notifopts[] = &$form->createElement('radio', 'mc_mod_notifopts', null, _("Incremental"), '0');
$mc_mod_notifopts[] = &$form->createElement('radio', 'mc_mod_notifopts', null, _("Replacement"), '1');
$mc_mod_notifopts[] = $form->createElement('radio', 'mc_mod_notifopts', null, _("Incremental"), '0');
$mc_mod_notifopts[] = $form->createElement('radio', 'mc_mod_notifopts', null, _("Replacement"), '1');
$form->addGroup($mc_mod_notifopts, 'mc_mod_notifopts', _("Update mode"), '&nbsp;');
$form->setDefaults(array('mc_mod_notifopts' => '0'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,15 @@ function updateHostCategoriesHosts($hc_id, $ret = array())
? $ret = $ret["hc_hostsTemplate"]
: $ret = $form->getSubmitValue("hc_hostsTemplate");
$rq = "INSERT INTO hostcategories_relation (hostcategories_hc_id, host_host_id) VALUES ";
for ($i = 0; $i < count($ret); $i++) {
if ($i != 0) {
$rq .= ", ";
}
$rq .= " ('" . $hc_id . "', '" . $ret[$i] . "')";
if ($ret) {
for ($i = 0; $i < count($ret); $i++) {
if ($i != 0) {
$rq .= ", ";
}
$rq .= " ('" . $hc_id . "', '" . $ret[$i] . "')";

$hostsNEW[$ret[$i]] = $ret[$i];
$hostsNEW[$ret[$i]] = $ret[$i];
}
}
if ($i != 0) {
$DBRESULT = $pearDB->query($rq);
Expand Down
Loading

0 comments on commit ba492fc

Please sign in to comment.