From 87850f637a4d579efd0b52235e7f2928e5bb85b6 Mon Sep 17 00:00:00 2001 From: Kevin Duret <kduret@centreon.com> Date: Tue, 4 Apr 2017 16:06:30 +0200 Subject: [PATCH] improve centreon kb to work with spaces --- cron/centKnowledgeSynchronizer.php | 232 ++------- .../centreon-knowledge/procedures.class.php | 118 ++--- .../procedures_Proxy.class.php | 259 +++++----- www/class/centreon-knowledge/wiki.class.php | 110 ++++ .../centreon-knowledge/wikiApi.class.php | 226 +++++++++ .../configKnowledge/display-services.php | 4 +- .../configKnowledge/proxy/proxy.php | 8 +- .../configKnowledge/templates/display.ihtml | 469 +++++++++--------- 8 files changed, 783 insertions(+), 643 deletions(-) create mode 100644 www/class/centreon-knowledge/wiki.class.php create mode 100644 www/class/centreon-knowledge/wikiApi.class.php diff --git a/cron/centKnowledgeSynchronizer.php b/cron/centKnowledgeSynchronizer.php index 447f09fcc5..84ecf6a306 100644 --- a/cron/centKnowledgeSynchronizer.php +++ b/cron/centKnowledgeSynchronizer.php @@ -1,214 +1,38 @@ <?php -/** +/* + * Copyright 2005-2017 Centreon + * Centreon is developped by : Julien Mathis and Romain Le Merlus under + * GPL Licence 2.0. * - */ - -// Getting wiki configuration -require_once "/etc/centreon/centreon.conf.php"; -$centreon_path = "/usr/share/centreon/"; -$module_path = $centreon_path . "www/class/centreon-knowledge/"; -require_once $centreon_path . "www/class/centreonDB.class.php"; -require_once $module_path . "procedures.class.php"; -require_once $module_path . "procedures_DB_Connector.class.php"; - -$modules_path = $centreon_path . "www/include/configuration/configKnowledge/"; -require_once $modules_path . 'functions.php'; - -// Initiate connexion -$dbConnector = new CentreonDB(); -$conf = getWikiConfig($dbConnector); -$WikiURL = $conf['kb_wiki_url']; - -// Define cron constants -define('_WIKIURL_', $WikiURL); - -// Last time the cron has been executed -$startTimestamp = time() - (3600*24); -define('_STARTDATE_', date('Y-m-d', $startTimestamp).'T00:00:00Z'); - -/** + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation ; either version 2 of the License. * - * @param string $type - * @return array - */ -function getChangedPages() -{ - // Connecting to Mediawiki API - $apiUrl = _WIKIURL_ . '/api.php?format=json&action=query&list=recentchanges' . - '&rclimit=50&rcprop=title&rctype=new|edit'; - - // Sending request - $result = json_decode(file_get_contents($apiUrl)); - return $result->query->recentchanges; -} - -/** + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. * - * @param array $pages - * @return array - */ -function detectCentreonObjects() -{ - $pages = getChangedPages(); - - $hosts = array(); - $hostsTemplates = array(); - $services = array(); - $servicesTemplates = array(); - - $nbPages = count($pages); - for ($i=0; $i<$nbPages; $i++) - { - $objectFlag = explode(':', $pages[$i]->title); - switch($objectFlag[0]) - { - case 'Host': - if (!in_array($pages[$i]->title, $hosts)) - { - $hosts[] = $pages[$i]->title; - } - break; - - case 'Host-Template': - if (!in_array($pages[$i]->title, $hostsTemplates)) - { - $hostsTemplates[] = $pages[$i]->title; - } - break; - - case 'Service': - if (!in_array($pages[$i]->title, $services)) - { - $services[] = $pages[$i]->title; - } - break; - - case 'Service-Template': - if (!in_array($pages[$i]->title, $servicesTemplates)) - { - $servicesTemplates[] = $pages[$i]->title; - } - break; - - default: - continue; - break; - } - } - $centreonObjects = array( - 'hosts' => $hosts, - 'hostsTemplates' => $hostsTemplates, - 'services' => $services, - 'servicesTemplates' => $servicesTemplates, - ); - return $centreonObjects; -} - -/** + * You should have received a copy of the GNU General Public License along with + * this program; if not, see <http://www.gnu.org/licenses>. * - * @param CentreonDB $dbConnector - * @param array $listOfObjects - */ -function synchronizeWithCentreon($dbConnector) -{ - // Get all pages title that where changed - $listOfObjects = detectCentreonObjects(); - - foreach($listOfObjects as $categorie=>$object) - { - switch($categorie) - { - case 'hosts': - foreach($object as $entity) { - $objName = substr($entity, 5); - editLinkForHost($dbConnector, str_replace(' ', '_', $objName)); - } - break; - - case 'hostsTemplates': - foreach($object as $entity) { - $objName = substr($entity, 14); - editLinkForHost($dbConnector, str_replace(' ', '_', $objName)); - } - break; - - case 'services': - foreach($object as $entity) { - $objName = explode(' ', $entity); - editLinkForService($dbConnector, $objName); - } - break; - - case 'servicesTemplates': - foreach($object as $entity) { - $objName = substr($entity, 17); - editLinkForService($dbConnector, str_replace(' ', '_', $objName)); - } - break; - } - } -} - -/** + * Linking this program statically or dynamically with other modules is making a + * combined work based on this program. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. * - * @param CentreonDB $dbConnector - * @param string $hostName - */ -function editLinkForHost($dbConnector, $hostName) -{ - $querySelect = "SELECT host_id FROM host WHERE host_name='$hostName'"; - $resHost = $dbConnector->query($querySelect); - $tuple = $resHost->fetchRow(); - - $valueToAdd = './include/configuration/configKnowledge/proxy/proxy.php?host_name=$HOSTNAME$'; - $queryUpdate = "UPDATE extended_host_information " - ."SET ehi_notes_url = '$valueToAdd' " - ."WHERE host_host_id = '".$tuple['host_id']."'"; - $dbConnector->query($queryUpdate); -} - -/** + * As a special exception, the copyright holders of this program give Centreon + * permission to link this program with independent modules to produce an executable, + * regardless of the license terms of these independent modules, and to copy and + * distribute the resulting executable under terms of Centreon choice, provided that + * Centreon also meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module which is not + * derived from this program. If you modify this program, you may extend this + * exception to your version of the program, but you are not obliged to do so. If you + * do not wish to do so, delete this exception statement from your version. + * + * For more information : contact@centreon.com * - * @param CentreonDB $dbConnector - * @param string $serviceName - */ -function editLinkForService($dbConnector, $objName) -{ - if (is_array($objName)) - { - $temphostName = explode(':', array_shift($objName)); - $hostName = $temphostName[1]; - $serviceName = join(' ', $objName); - $querySelect = "SELECT service_id " - ."FROM service, host, host_service_relation " - ."WHERE service.service_description = '$serviceName' " - ."AND host.host_name='$hostName' " - ."AND host_service_relation.host_host_id = host.host_id " - ."AND host_service_relation.service_service_id = service.service_id"; - } - else - { - $querySelect = "SELECT service_id FROM service WHERE service_description='$objName'"; - } - - $resService = $dbConnector->query($querySelect); - $tuple = $resService->fetchRow(); - - $valueToAdd = './include/configuration/configKnowledge/proxy/proxy.php?host_name=$HOSTNAME$&service_description=$SERVICEDESC$'; - $queryUpdate = "UPDATE extended_service_information " - ."SET esi_notes_url = '$valueToAdd' " - ."WHERE service_service_id = '".$tuple['service_id']."'"; - $dbConnector->query($queryUpdate); -} - - -/** - ************************* - ****** MAIN ***** - ************************* */ -// Synchro with Centreon -synchronizeWithCentreon($dbConnector); +require_once realpath(dirname(__FILE__) . "/../www/class/centreon-knowledge/wikiApi.class.php"); -?> +(New WikiApi)->synchronize(); \ No newline at end of file diff --git a/www/class/centreon-knowledge/procedures.class.php b/www/class/centreon-knowledge/procedures.class.php index 550ee1682c..cad6f00c1b 100644 --- a/www/class/centreon-knowledge/procedures.class.php +++ b/www/class/centreon-knowledge/procedures.class.php @@ -79,7 +79,7 @@ class procedures */ private function setProcedures() { - $DBRESULT = $this->DB->query("SELECT page_title, page_id FROM ".$this->db_prefix."page"); + $DBRESULT = $this->DB->query("SELECT page_title, page_id FROM " . $this->db_prefix . "page"); while ($page = $DBRESULT->fetchRow()) { $this->procList[$page["page_title"]] = $page["page_id"]; } @@ -114,25 +114,29 @@ class procedures $wikiContent = $this->getProcedures(); $diff = array(); $prefix = ""; - if ($type == 0) { - $prefix = "Host:"; - } - if ($type == 1) { - $prefix = "Service:"; - } - if ($type == 2) { - $prefix = "Host-Template:"; - } - if ($type == 3) { - $prefix = "Service-Template:"; + switch ($type) { + case 0: + $prefix = "Host_:_"; + break; + case 1: + $prefix = "Service_:_"; + break; + case 2: + $prefix = "Host-Template_:_"; + break; + case 3: + $prefix = "Service-Template_:_"; + break; } + foreach ($selection as $key => $value) { - if (!isset($wikiContent[$prefix.trim($key)])) { + if (!isset($wikiContent[$prefix . trim($key)])) { $diff[$key] = 0; } else { $diff[$key] = 1; } } + return $diff; } @@ -145,50 +149,16 @@ class procedures */ public function getMyHostID($host_name = null) { - $DBRESULT = $this->centreon_DB->query("SELECT host_id FROM host WHERE host_name = '".$host_name."' LIMIT 1"); + $query = "SELECT host_id FROM host " . + "WHERE host_name = '" . $host_name . "' " . + "LIMIT 1 "; + $DBRESULT = $this->centreon_DB->query($query); $row = $DBRESULT->fetchRow(); if ($row["host_id"]) { return $row["host_id"]; } } - /** - * Get Service Id - * - * @param int $host_id - * @param string $service_description - * @return int - */ - public function getMyServicesID($host_id, $service_description) - { - /* - * Get Services attached to hosts - */ - $DBRESULT = $this->centreon_DB->query("SELECT service_id, service_description - FROM service, host_service_relation hsr - WHERE hsr.host_host_id = '".$host_id."' - AND hsr.service_service_id = service_id - AND service_description = '$service_description'"); - while ($elem = $DBRESULT->fetchRow()) { - return $elem["service_id"]; - } - $DBRESULT->free(); - - /* - * Get Services attached to hostgroups - */ - $DBRESULT = $this->centreon_DB->query("SELECT service_id, service_description - FROM hostgroup_relation hgr, service, host_service_relation hsr" . - " WHERE hgr.host_host_id = '".$host_id."' AND hsr.hostgroup_hg_id = hgr.hostgroup_hg_id" . - " AND service_id = hsr.service_service_id " . - " AND service_description = '$service_description'"); - while ($elem = $DBRESULT->fetchRow()) { - return $elem["service_id"]; - } - $DBRESULT->free(); - return 0; - } - /** * Get service template * @@ -201,7 +171,7 @@ class procedures $DBRESULT = $this->centreon_DB->query("SELECT service_description, service_template_model_stm_id FROM service - WHERE service_id = '".$service_id."' LIMIT 1"); + WHERE service_id = '" . $service_id . "' LIMIT 1"); $row = $DBRESULT->fetchRow(); if (isset($row['service_template_model_stm_id']) && $row['service_template_model_stm_id'] != "") { $DBRESULT->free(); @@ -212,7 +182,7 @@ class procedures while (1) { $DBRESULT = $this->centreon_DB->query("SELECT service_description, service_template_model_stm_id FROM service - WHERE service_id = '".$service_id."' LIMIT 1"); + WHERE service_id = '" . $service_id . "' LIMIT 1"); $row = $DBRESULT->fetchRow(); $DBRESULT->free(); if ($row["service_description"]) { @@ -245,12 +215,12 @@ class procedures $tplArr = array(); $DBRESULT = $this->centreon_DB->query("SELECT host_tpl_id FROM `host_template_relation` - WHERE host_host_id = '".$host_id."' + WHERE host_host_id = '" . $host_id . "' ORDER BY `order`"); while ($row = $DBRESULT->fetchRow()) { $DBRESULT2 = $this->centreon_DB->query("SELECT host_name FROM host - WHERE host_id = '".$row['host_tpl_id']."' LIMIT 1"); + WHERE host_id = '" . $row['host_tpl_id'] . "' LIMIT 1"); $hTpl = $DBRESULT2->fetchRow(); $tplArr[$row['host_tpl_id']] = html_entity_decode($hTpl["host_name"], ENT_QUOTES); } @@ -279,7 +249,7 @@ class procedures } else { $this->hostTplList[$data["host_name"]] = $data["host_id"]; } - $this->hostIconeList["Host:" . $data["host_name"]] = + $this->hostIconeList["Host_:_" . $data["host_name"]] = "./img/media/" . $this->getImageFilePath($data["ehi_icon_image"]); } $DBRESULT->free(); @@ -297,12 +267,12 @@ class procedures if (isset($image_id) && $image_id) { $DBRESULT2 = $this->centreon_DB->query("SELECT img_path, dir_alias FROM view_img vi, view_img_dir vid, view_img_dir_relation vidr - WHERE vi.img_id = ".$image_id." + WHERE vi.img_id = " . $image_id . " AND vidr.img_img_id = vi.img_id AND vid.dir_id = vidr.dir_dir_parent_id LIMIT 1"); $row2 = $DBRESULT2->fetchRow(); if (isset($row2["dir_alias"]) && isset($row2["img_path"]) && $row2["dir_alias"] && $row2["img_path"]) { - return $row2["dir_alias"]."/".$row2["img_path"]; + return $row2["dir_alias"] . "/" . $row2["img_path"]; } $DBRESULT2->free(); unset($row2); @@ -322,7 +292,7 @@ class procedures FROM service WHERE service_register = '0' ORDER BY service_description"); while ($data = $DBRESULT->fetchRow()) { - $this->serviceTplList["Service:".$data["service_description"]] = $data["service_id"]; + $this->serviceTplList["Service_:_" . $data["service_description"]] = $data["service_id"]; } $DBRESULT->free(); unset($data); @@ -345,13 +315,13 @@ class procedures * Get Template */ if ($type == 2) { - $template = "H-TPL-".$template; + $template = "H-TPL-" . $template; } if ($type == 3) { - $template = "S-TPL-".$template; + $template = "S-TPL-" . $template; } $DBRESULT = $this->DB->query( - "SELECT * FROM ".$this->db_prefix."page WHERE page_title LIKE '$template'" + "SELECT * FROM " . $this->db_prefix . "page WHERE page_title LIKE '$template'" ); $data = $DBRESULT->fetchRow(); $DBRESULT->free(); @@ -380,16 +350,16 @@ class procedures switch ($type) { case 0: - $object = "Host:" . $object; + $object = "Host_:_" . $object; break; case 1: - $object = "Service:" . $object; + $object = "Service_:_" . $object; break; case 2: - $object = "Host-Template:" . $object; + $object = "Host-Template_:_" . $object; break; case 3: - $object = "Service-Template:" . $object; + $object = "Service-Template_:_" . $object; break; } @@ -398,9 +368,9 @@ class procedures "INSERT INTO " . $this->db_prefix . "page (`page_namespace` ,`page_title`,`page_counter`, " . " `page_is_redirect`,`page_is_new`,`page_random` ,`page_touched`,`page_latest`,`page_len`) " . " VALUES ('0', '" . $object . "', '0', '0', '1', '" . $data["page_random"] . "', '" . - $dateTouch . "', '" . $data["page_latest"] . "', '" . $data["page_len"]."')" + $dateTouch . "', '" . $data["page_latest"] . "', '" . $data["page_len"] . "')" ); - $DBRESULT = $this->DB->query("SELECT MAX(page_id) FROM ".$this->db_prefix."page"); + $DBRESULT = $this->DB->query("SELECT MAX(page_id) FROM " . $this->db_prefix . "page"); $id = $DBRESULT->fetchRow(); $this->DB->query( @@ -428,7 +398,7 @@ class procedures */ public function serviceHasProcedure($key, $templates = array(), $mode = PROCEDURE_SIMPLE_MODE) { - if (isset($this->procList["Service:".$key])) { + if (isset($this->procList["Service_:_" . $key])) { return true; } if ($mode == PROCEDURE_SIMPLE_MODE) { @@ -454,7 +424,7 @@ class procedures */ public function hostHasProcedure($key, $templates = array(), $mode = PROCEDURE_SIMPLE_MODE) { - if (isset($this->procList["Host:".$key])) { + if (isset($this->procList["Host_:_" . $key])) { return true; } if ($mode == PROCEDURE_SIMPLE_MODE) { @@ -480,14 +450,14 @@ class procedures */ public function serviceTemplateHasProcedure($key = "", $templates = array(), $mode = PROCEDURE_SIMPLE_MODE) { - if (isset($this->procList["Service-Template:".$key])) { + if (isset($this->procList["Service-Template_:_" . $key])) { return true; } if ($mode == PROCEDURE_SIMPLE_MODE) { return false; } elseif ($mode == PROCEDURE_INHERITANCE_MODE) { foreach ($templates as $templateId => $templateName) { - if (isset($this->procList['Service-Template:'.$templateName])) { + if (isset($this->procList['Service-Template_:_' . $templateName])) { return true; } } @@ -504,14 +474,14 @@ class procedures */ public function hostTemplateHasProcedure($key = "", $templates = array(), $mode = PROCEDURE_SIMPLE_MODE) { - if (isset($this->procList["Host-Template:".$key])) { + if (isset($this->procList["Host-Template_:_" . $key])) { return true; } if ($mode == PROCEDURE_SIMPLE_MODE) { return false; } elseif ($mode == PROCEDURE_INHERITANCE_MODE) { foreach ($templates as $templateId => $templateName) { - if (isset($this->procList['Host-Template:'.$templateName])) { + if (isset($this->procList['Host-Template_:_' . $templateName])) { return true; } } diff --git a/www/class/centreon-knowledge/procedures_Proxy.class.php b/www/class/centreon-knowledge/procedures_Proxy.class.php index 6a7ffb64e1..0b678b5530 100644 --- a/www/class/centreon-knowledge/procedures_Proxy.class.php +++ b/www/class/centreon-knowledge/procedures_Proxy.class.php @@ -13,24 +13,25 @@ require_once _CENTREON_PATH_ . '/www/include/configuration/configKnowledge/functions.php'; -class procedures_Proxy { - private $DB; +class procedures_Proxy +{ + private $DB; private $hflag; private $sflag; private $proc; public $url; private $wikiUrl; - public function __construct($pearDB, $db_prefix, $host_name, $service_description = null) + public function __construct($pearDB, $db_prefix, $host_name, $service_description = null) { - $this->DB = $pearDB; - $this->hflag = 0; - $this->sflag = 0; - - $conf = getWikiConfig($this->DB); - $this->wikiUrl = $conf['kb_wiki_url']; - $this->proc = new procedures( - 3, + $this->DB = $pearDB; + $this->hflag = 0; + $this->sflag = 0; + + $conf = getWikiConfig($this->DB); + $this->wikiUrl = $conf['kb_wiki_url']; + $this->proc = new procedures( + 3, $conf['kb_db_name'], $conf['kb_db_user'], $conf['kb_db_host'], @@ -39,150 +40,150 @@ class procedures_Proxy { $conf['kb_db_prefix'] ); - if (isset($host_name)) { - if (isset($service_description)) { + if (isset($host_name)) { + if (isset($service_description)) { $this->returnServiceWikiUrl($this->DB->escape($host_name), $this->DB->escape($service_description)); } else { $this->returnHostWikiUrl($this->DB->escape($host_name)); } - } - } + } + } - private function returnHostWikiUrl($host_name) + private function returnHostWikiUrl($host_name) { - $this->proc->setHostInformations(); - - $procList = $this->proc->getProcedures(); - - /* - * Check if host has a procedure directly on Host - */ - if (isset($procList["Host:" . $host_name])) { - $this->url = $this->wikiUrl."/index.php?title=Host:".$host_name; - return ; - } - - /* - * Check if host can get a procedure on templates - */ - $templates = $this->getHostTemplateList($host_name); - foreach ($templates as $tpl) { - if (isset($procList["Host-Template:" . $tpl])) { - $this->url = $this->wikiUrl . "/index.php?title=Host-Template:".$tpl; - return; - } - } - } - - private function returnServiceWikiUrl($host_name, $service_description) + $this->proc->setHostInformations(); + + $procList = $this->proc->getProcedures(); + + /* + * Check if host has a procedure directly on Host + */ + if (isset($procList["Host_:_" . $host_name])) { + $this->url = $this->wikiUrl . "/index.php?title=Host_:_" . $host_name; + return; + } + + /* + * Check if host can get a procedure on templates + */ + $templates = $this->getHostTemplateList($host_name); + foreach ($templates as $tpl) { + if (isset($procList["Host-Template_:_" . $tpl])) { + $this->url = $this->wikiUrl . "/index.php?title=Host-Template_:_" . $tpl; + return; + } + } + } + + private function returnServiceWikiUrl($host_name, $service_description) { - if ($this->hflag != 0) { + if ($this->hflag != 0) { $this->proc->setHostInformations(); } - $this->proc->setServiceInformations(); - $this->sflag; + $this->proc->setServiceInformations(); + $this->sflag; - $procList = $this->proc->getProcedures(); + $procList = $this->proc->getProcedures(); - /* - * Check Service - */ + /* + * Check Service + */ $service_description = str_replace(' ', '_', $service_description); - if (isset($procList["Service:" . trim($host_name."_".$service_description)])) { - $this->url = $this->wikiUrl . "/index.php?title=Service:".$host_name."_".$service_description; + if (isset($procList["Service_:_" . trim($host_name . "_" . $service_description)])) { + $this->url = $this->wikiUrl . "/index.php?title=Service_:_" . $host_name . "_" . $service_description; return; - } - - /* - * Check service Template - */ - $host_id = $this->getMyHostID($host_name); - $templates = $this->getMyServiceTemplateModels($this->getMyServicesID($host_id, $service_description)); - foreach ($templates as $key => $value) { - if (isset($procList["Service-Template:".trim($value)])) { - $this->url = $this->wikiUrl . "/index.php?title=Service-Template:".$value; - return ; - } - } - $this->returnHostWikiUrl($host_name); - } - - function getMyHostID($host_name = NULL) + } + + /* + * Check service Template + */ + $host_id = $this->getMyHostID($host_name); + $templates = $this->getMyServiceTemplateModels($this->getMyServicesID($host_id, $service_description)); + foreach ($templates as $key => $value) { + if (isset($procList["Service-Template_:_" . trim($value)])) { + $this->url = $this->wikiUrl . "/index.php?title=Service-Template_:_" . $value; + return; + } + } + $this->returnHostWikiUrl($host_name); + } + + function getMyHostID($host_name = NULL) { - $DBRESULT =& $this->DB->query("SELECT host_id FROM host WHERE host_name = '".$host_name."' LIMIT 1"); - $row =& $DBRESULT->fetchRow(); - if ($row["host_id"]) - return $row["host_id"]; - } + $DBRESULT =& $this->DB->query("SELECT host_id FROM host WHERE host_name = '" . $host_name . "' LIMIT 1"); + $row =& $DBRESULT->fetchRow(); + if ($row["host_id"]) + return $row["host_id"]; + } - function getMyServicesID($host_id, $service_description) + function getMyServicesID($host_id, $service_description) { - /* - * Get Services attached to hosts - */ - $query = "SELECT service_id, service_description " . + /* + * Get Services attached to hosts + */ + $query = "SELECT service_id, service_description " . "FROM service, host_service_relation hsr " . "WHERE hsr.host_host_id = '" . $host_id . "' " . "AND hsr.service_service_id = service_id " . "AND service_description = '" . $service_description . "' "; - $DBRESULT =& $this->DB->query($query); - while ($elem =& $DBRESULT->fetchRow()) { - return $elem["service_id"]; - } - $DBRESULT->free(); - - /* - * Get Services attached to hostgroups - */ - $query = "SELECT service_id, service_description " . + $DBRESULT =& $this->DB->query($query); + while ($elem =& $DBRESULT->fetchRow()) { + return $elem["service_id"]; + } + $DBRESULT->free(); + + /* + * Get Services attached to hostgroups + */ + $query = "SELECT service_id, service_description " . "FROM hostgroup_relation hgr, service, host_service_relation hsr " . "WHERE hgr.host_host_id = '" . $host_id . "' AND hsr.hostgroup_hg_id = hgr.hostgroup_hg_id " . "AND service_id = hsr.service_service_id " . "AND service_description = '" . $service_description . "' "; - $DBRESULT =& $this->DB->query($query); - while ($elem =& $DBRESULT->fetchRow()){ - return $elem["service_id"]; - } - $DBRESULT->free(); - } + $DBRESULT =& $this->DB->query($query); + while ($elem =& $DBRESULT->fetchRow()) { + return $elem["service_id"]; + } + $DBRESULT->free(); + } - private function getHostTemplateList($host_name) + private function getHostTemplateList($host_name) { - $templates = array(); - - $DBRESULT =& $this->DB->query("SELECT host_tpl_id FROM `host_template_relation`, `host` WHERE host_host_id = host_id AND host_name = '".$host_name."' ORDER BY `order`"); - while($row =& $DBRESULT->fetchRow()) { - $DBRESULT2 =& $this->DB->query("SELECT host_name FROM host WHERE host_id = '".$row['host_tpl_id']."' LIMIT 1"); - $hTpl =& $DBRESULT2->fetchRow(); - $templates[$row['host_tpl_id']] = html_entity_decode($hTpl["host_name"], ENT_QUOTES); - } - return $templates; - } - - private function getMyServiceTemplateModels($service_id) + $templates = array(); + + $DBRESULT =& $this->DB->query("SELECT host_tpl_id FROM `host_template_relation`, `host` WHERE host_host_id = host_id AND host_name = '" . $host_name . "' ORDER BY `order`"); + while ($row =& $DBRESULT->fetchRow()) { + $DBRESULT2 =& $this->DB->query("SELECT host_name FROM host WHERE host_id = '" . $row['host_tpl_id'] . "' LIMIT 1"); + $hTpl =& $DBRESULT2->fetchRow(); + $templates[$row['host_tpl_id']] = html_entity_decode($hTpl["host_name"], ENT_QUOTES); + } + return $templates; + } + + private function getMyServiceTemplateModels($service_id) { - $tplArr = array(); - - $DBRESULT =& $this->DB->query("SELECT service_description, service_template_model_stm_id FROM service WHERE service_id = '".$service_id."' LIMIT 1"); - $row =& $DBRESULT->fetchRow(); - $DBRESULT->free(); - $service_id = $row["service_template_model_stm_id"]; - if ($row["service_description"]) - $tplArr[$service_id] = $row["service_description"]; - while (1) { - $DBRESULT =& $this->DB->query("SELECT service_description, service_template_model_stm_id FROM service WHERE service_id = '".$service_id."' LIMIT 1"); - $row =& $DBRESULT->fetchRow(); - $DBRESULT->free(); - if ($row["service_description"]) - $tplArr[$service_id] = $row["service_description"]; - else - break; - if ($row["service_template_model_stm_id"]) - $service_id = $row["service_template_model_stm_id"]; - else - break; - } - return ($tplArr); - } + $tplArr = array(); + + $DBRESULT =& $this->DB->query("SELECT service_description, service_template_model_stm_id FROM service WHERE service_id = '" . $service_id . "' LIMIT 1"); + $row =& $DBRESULT->fetchRow(); + $DBRESULT->free(); + $service_id = $row["service_template_model_stm_id"]; + if ($row["service_description"]) + $tplArr[$service_id] = $row["service_description"]; + while (1) { + $DBRESULT =& $this->DB->query("SELECT service_description, service_template_model_stm_id FROM service WHERE service_id = '" . $service_id . "' LIMIT 1"); + $row =& $DBRESULT->fetchRow(); + $DBRESULT->free(); + if ($row["service_description"]) + $tplArr[$service_id] = $row["service_description"]; + else + break; + if ($row["service_template_model_stm_id"]) + $service_id = $row["service_template_model_stm_id"]; + else + break; + } + return ($tplArr); + } } diff --git a/www/class/centreon-knowledge/wiki.class.php b/www/class/centreon-knowledge/wiki.class.php new file mode 100644 index 0000000000..7039fd02fa --- /dev/null +++ b/www/class/centreon-knowledge/wiki.class.php @@ -0,0 +1,110 @@ +<?php +/* + * Copyright 2005-2017 Centreon + * Centreon is developped by : Julien Mathis and Romain Le Merlus under + * GPL Licence 2.0. + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation ; either version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, see <http://www.gnu.org/licenses>. + * + * Linking this program statically or dynamically with other modules is making a + * combined work based on this program. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this program give Centreon + * permission to link this program with independent modules to produce an executable, + * regardless of the license terms of these independent modules, and to copy and + * distribute the resulting executable under terms of Centreon choice, provided that + * Centreon also meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module which is not + * derived from this program. If you modify this program, you may extend this + * exception to your version of the program, but you are not obliged to do so. If you + * do not wish to do so, delete this exception statement from your version. + * + * For more information : contact@centreon.com + * + */ + +require_once realpath(dirname(__FILE__) . "/../../../config/centreon.config.php"); +require_once _CENTREON_PATH_ . "/www/class/centreonDB.class.php"; + +class Wiki +{ + private $db; + private $config; + + /** + * WikiApi constructor. + */ + public function __construct() + { + $this->db = new CentreonDB(); + $this->config = $this->getWikiConfig(); + } + + public function getWikiConfig() + { + $res = $this->db->query("SELECT * FROM `options` WHERE options.key LIKE 'kb_%'"); + while ($opt = $res->fetchRow()) { + $gopt[$opt["key"]] = html_entity_decode($opt["value"], ENT_QUOTES, "UTF-8"); + } + + $pattern = '#^http://|https://#'; + $WikiURL = $gopt['kb_wiki_url']; + $checkWikiUrl = preg_match($pattern, $WikiURL); + + if (!$checkWikiUrl) { + $gopt['kb_wiki_url'] = 'http://' . $WikiURL; + } + + $res->free(); + + return $gopt; + } + + public function getWikiUrl() + { + return $this->config['kb_wiki_url']; + } + + + function getWikiVersion() + { + $post = array( + 'action' => 'query', + 'meta' => 'siteinfo', + 'format' => 'json', + ); + + $data = http_build_query($post); + + $httpOpts = array( + 'http' => array( + 'method' => 'POST', + 'header' => "Content-type: application/x-www-form-urlencoded", + 'content' => $data, + ) + ); + + /* Create context */ + $httpContext = stream_context_create($httpOpts); + + /* Get contents */ + $content = @file_get_contents($this->config['kb_wiki_url'], false, $httpContext); + $content = json_decode($content); + + $wikiStringVersion = $content->query->general->generator; + $wikiDataVersion = explode(' ', $wikiStringVersion); + $wikiVersion = (float)$wikiDataVersion[1]; + + return $wikiVersion; + } +} diff --git a/www/class/centreon-knowledge/wikiApi.class.php b/www/class/centreon-knowledge/wikiApi.class.php new file mode 100644 index 0000000000..bdab07abdd --- /dev/null +++ b/www/class/centreon-knowledge/wikiApi.class.php @@ -0,0 +1,226 @@ +<?php +/* + * Copyright 2005-2017 Centreon + * Centreon is developped by : Julien Mathis and Romain Le Merlus under + * GPL Licence 2.0. + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation ; either version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, see <http://www.gnu.org/licenses>. + * + * Linking this program statically or dynamically with other modules is making a + * combined work based on this program. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this program give Centreon + * permission to link this program with independent modules to produce an executable, + * regardless of the license terms of these independent modules, and to copy and + * distribute the resulting executable under terms of Centreon choice, provided that + * Centreon also meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module which is not + * derived from this program. If you modify this program, you may extend this + * exception to your version of the program, but you are not obliged to do so. If you + * do not wish to do so, delete this exception statement from your version. + * + * For more information : contact@centreon.com + * + */ + +require_once realpath(dirname(__FILE__) . "/../../../config/centreon.config.php"); +require_once _CENTREON_PATH_ . "/www/class/centreonDB.class.php"; +require_once _CENTREON_PATH_ . "/www/class/centreon-knowledge/wiki.class.php"; +require_once _CENTREON_PATH_ . "/www/class/centreon-knowledge/procedures.class.php"; + +class WikiApi +{ + private $db; + private $wikiObj; + private $wikiUrl; + + /** + * WikiApi constructor. + */ + public function __construct() + { + $this->db = new CentreonDB(); + $this->wikiObj = new Wiki(); + $this->wikiUrl = $this->wikiObj->getWikiUrl(); + } + + /** + * @param int $count + * @return mixed + */ + public function getChangedPages($count = 50) + { + // Connecting to Mediawiki API + $apiUrl = $this->wikiUrl . '/api.php?format=json&action=query&list=recentchanges' . + '&rclimit=' . $count . '&rcprop=title&rctype=new|edit'; + + // Sending request + $result = json_decode(file_get_contents($apiUrl)); + + return $result->query->recentchanges; + } + + /** + * @return array + */ + public function detectCentreonObjects() + { + $pages = $this->getChangedPages(); + + $hosts = array(); + $hostsTemplates = array(); + $services = array(); + $servicesTemplates = array(); + + $count = count($pages); + for ($i = 0; $i < $count; $i++) { + $objectFlag = explode(':', $pages[$i]->title); + $type = trim($objectFlag[0]); + switch ($type) { + case 'Host': + if (!in_array($pages[$i]->title, $hosts)) { + $hosts[] = $pages[$i]->title; + } + break; + + case 'Host-Template': + if (!in_array($pages[$i]->title, $hostsTemplates)) { + $hostsTemplates[] = $pages[$i]->title; + } + break; + + case 'Service': + if (!in_array($pages[$i]->title, $services)) { + $services[] = $pages[$i]->title; + } + break; + + case 'Service-Template': + if (!in_array($pages[$i]->title, $servicesTemplates)) { + $servicesTemplates[] = $pages[$i]->title; + } + break; + } + } + + return array( + 'hosts' => $hosts, + 'hostTemplates' => $hostsTemplates, + 'services' => $services, + 'serviceTemplates' => $servicesTemplates, + ); + } + + /** + * + */ + public function synchronize() + { + // Get all pages title that where changed + $listOfObjects = $this->detectCentreonObjects(); + + foreach ($listOfObjects as $categorie => $object) { + switch ($categorie) { + case 'hosts': + foreach ($object as $entity) { + $objName = str_replace('Host : ', '', $entity); + $objName = str_replace(' ', '_', $objName); + $this->updateLinkForHost($objName); + } + break; + + case 'hostTemplates': + foreach ($object as $entity) { + $objName = str_replace('Host-Template : ', '', $entity); + $objName = str_replace(' ', '_', $objName); + $this->updateLinkForHost($objName); + } + break; + + case 'services': + foreach ($object as $entity) { + $objName = str_replace('Service : ', '', $entity); + $objName = str_replace(' ', '_', $objName); + if (preg_match('#(.+)_/_(.+)#', $objName, $matches)) { + $this->updateLinkForService($matches[1], $matches[2]); + } + } + break; + + case 'serviceTemplates': + foreach ($object as $entity) { + $objName = str_replace('Service-Template : ', '', $entity); + $objName = str_replace(' ', '_', $objName); + $this->updateLinkForServiceTemplate($objName); + } + break; + } + } + } + + /** + * @param $hostName + */ + public function updateLinkForHost($hostName) + { + $querySelect = "SELECT host_id FROM host WHERE host_name LIKE '" . $hostName . "'"; + $resHost = $this->db->query($querySelect); + $tuple = $resHost->fetchRow(); + + $valueToAdd = './include/configuration/configKnowledge/proxy/proxy.php?host_name=$HOSTNAME$'; + $queryUpdate = "UPDATE extended_host_information " + . "SET ehi_notes_url = '" . $valueToAdd . "' " + . "WHERE host_host_id = '" . $tuple['host_id'] . "'"; + $this->db->query($queryUpdate); + } + + /** + * @param $hostName + * @param $serviceDescription + */ + public function updateLinkForService($hostName, $serviceDescription) + { + $query = "SELECT service_id " . + "FROM service, host, host_service_relation " . + "WHERE host.host_name LIKE '" . $hostName . "' " . + "AND service.service_description LIKE '" . $serviceDescription . "' " . + "AND host_service_relation.host_host_id = host.host_id " . + "AND host_service_relation.service_service_id = service.service_id "; + $resService = $this->db->query($query); + $tuple = $resService->fetchRow(); + + $valueToAdd = './include/configuration/configKnowledge/proxy/proxy.php?' . + 'host_name=$HOSTNAME$&service_description=$SERVICEDESC$'; + $queryUpdate = "UPDATE extended_service_information " . + "SET esi_notes_url = '" . $valueToAdd . "' " . + "WHERE service_service_id = '" . $tuple['service_id'] . "' "; + $this->db->query($queryUpdate); + } + + /** + * @param $serviceName + */ + public function updateLinkForServiceTemplate($serviceName) + { + $query = "SELECT service_id FROM service WHERE service_description LIKE '" . $serviceName . "' "; + $resService = $this->db->query($query); + $tuple = $resService->fetchRow(); + + $valueToAdd = './include/configuration/configKnowledge/proxy/proxy.php?' . + 'host_name=$HOSTNAME$&service_description=$SERVICEDESC$'; + $queryUpdate = "UPDATE extended_service_information " . + "SET esi_notes_url = '" . $valueToAdd . "' " . + "WHERE service_service_id = '" . $tuple['service_id'] . "' "; + $this->db->query($queryUpdate); + } +} diff --git a/www/include/configuration/configKnowledge/display-services.php b/www/include/configuration/configKnowledge/display-services.php index f1995e78df..acee50e837 100644 --- a/www/include/configuration/configKnowledge/display-services.php +++ b/www/include/configuration/configKnowledge/display-services.php @@ -189,7 +189,7 @@ while ($row = $res->fetchRow()) { $row['service_description'] = str_replace("#S#", "/", $row['service_description']); $row['service_description'] = str_replace("#BS#", "\\", $row['service_description']); if (isset($row['host_id']) && $row['host_id']) { - $serviceList[$row['host_name'] . '_' . $row['service_description']] = array( + $serviceList[$row['host_name'] . '_/_' . $row['service_description']] = array( "id" => $row['service_id'], "svc" => $row['service_description'], "h" => $row['host_name'] @@ -246,7 +246,7 @@ foreach ($serviceList as $key => $value) { } else { $tplStr .= " | "; } - $tplStr .= "<a href='" . $WikiURL . "/index.php?title=Service:$value1' target='_blank'>" . $value1 . "</a>"; + $tplStr .= "<a href='" . $WikiURL . "/index.php?title=Service_:_$value1' target='_blank'>" . $value1 . "</a>"; } } $templateHostArray[$key] = $tplStr; diff --git a/www/include/configuration/configKnowledge/proxy/proxy.php b/www/include/configuration/configKnowledge/proxy/proxy.php index f1570ae131..cd2c33a895 100644 --- a/www/include/configuration/configKnowledge/proxy/proxy.php +++ b/www/include/configuration/configKnowledge/proxy/proxy.php @@ -41,7 +41,7 @@ ini_set("display_errors", "On"); $centreon_path = realpath(dirname(__FILE__) . '/../../../../../'); global $etc_centreon, $db_prefix; -require_once $centreon_path."/config/centreon.config.php"; +require_once $centreon_path . "/config/centreon.config.php"; set_include_path( get_include_path() . @@ -74,16 +74,16 @@ $WikiURL = $conf['kb_wiki_url']; if (isset($_GET["host_name"]) && isset($_GET["service_description"])) { $proxy = new procedures_Proxy($pearDB, $conf['kb_db_prefix'], $_GET["host_name"], $_GET["service_description"]); } elseif (isset($_GET["host_name"])) { - $proxy = new procedures_Proxy($pearDB, $conf['kb_db_prefix'], $_GET["host_name"]); + $proxy = new procedures_Proxy($pearDB, $conf['kb_db_prefix'], $_GET["host_name"], null); } if ($proxy->url != "") { header("Location: " . $proxy->url); } else { if (isset($_GET["host_name"]) && isset($_GET["service_description"])) { - header("Location: $WikiURL/?title=Service:".$_GET["host_name"]."_".$_GET["service_description"]); + header("Location: $WikiURL/?title=Service_:_" . $_GET["host_name"] . "_/_" . $_GET["service_description"]); } else { - header("Location: $WikiURL/?title=Host:".$_GET["host_name"]); + header("Location: $WikiURL/?title=Host_:_" . $_GET["host_name"]); } } exit(); diff --git a/www/include/configuration/configKnowledge/templates/display.ihtml b/www/include/configuration/configKnowledge/templates/display.ihtml index 3a65cf9c03..8b2e4cfc88 100644 --- a/www/include/configuration/configKnowledge/templates/display.ihtml +++ b/www/include/configuration/configKnowledge/templates/display.ihtml @@ -1,240 +1,249 @@ <script type="text/javascript" src="./include/common/javascript/tool.js"></script> <form name='form' method="POST"> - <table class="ajaxOption table"> - <tr> - <th><h5>{t}Filters{/t}</h5></th> - </tr> - <tr> - {if $searchOptions.host == 1} - <td><h4>{$labels.host}</h4></td> - {/if} - {if $searchOptions.hostTemplate == 1} - <td><h4>{$labels.hostTemplate}</h4></td> - {/if} - {if $searchOptions.serviceTemplate == 1} - <td><h4>{$labels.serviceTemplate}</h4></td> - {/if} - {if $searchOptions.hostgroup == 1} - <td><h4>{$labels.hostgroup}</h4></td> - {/if} - {if $searchOptions.poller == 1} - <td><h4>{$labels.poller}</h4></td> - {/if} - </tr> - <tr> - {if $searchOptions.host == 1} - <td><input type='text' name='searchHost' value="{$searchHost}"/></td> - {/if} - {if $searchOptions.hostTemplate == 1} - <td><input type='text' name='searchHostTemplate' value="{$searchHostTemplate}"/></td> - {/if} - {if $searchOptions.serviceTemplate == 1} - <td><input type='text' name='searchServiceTemplate' value="{$searchServiceTemplate}"/></td> - {/if} - {if $searchOptions.hostgroup == 1} - <td><select name='searchHostgroup'>{$searchHostgroup}</select></td> - {/if} - {if $searchOptions.poller == 1} - <td><select name='searchPoller'>{$searchPoller}</select></td> - {/if} - {if $searchOptions.hasNoProcedure == 1 || $searchOptionsTemplateWithNoProcedure == 1} - <td> - {if $searchOptions.hasNoProcedure == 1} - <p><input name='searchHasNoProcedure' type='checkbox' {$searchHasNoProcedure}/> {$labels.hasNoProcedure} - </p> - {/if} - {if $searchOptions.templatesWithNoProcedure == 1} - <p><input name='searchTemplatesWithNoProcedure' type='checkbox' {$searchTemplatesWithNoProcedure}/> - {$labels.templatesWithNoProcedure}</p> - {/if} - </td> - {/if} - <td><input type='submit' name='SearchB' value='{$labels.search}' class="btc bt_success"/></td> - </tr> - <tr> - {if $searchOptions.service == 1} - <td><h4>{$labels.service}</h4></td> - {/if} - {if $searchOptions.servicegroup == 1} - <td><h4>{$labels.servicegroup}</h4></td> - {/if} - </tr> - <tr> - {if $searchOptions.service == 1} - <td><input type='text' name='searchService' value="{$searchService}"/></td> - {/if} - {if $searchOptions.servicegroup == 1} - <td><select name='searchServicegroup'>{$searchServicegroup}</select></td> - {/if} - </tr> - </table> - <table class="ToolbarTable table"> - <tr class="ToolbarTR"> - {php} - include('./include/configuration/configKnowledge/pagination.php'); - {/php} - </tr> - </table> - <table class="ListTable"> - <tr class="ListHeader"> - <td class="ListColHeaderLeft" style="width:18px;"> </td> - <td class="ListColHeaderLeft" style="width:250px;"> - {$host_name} - <img src='img/icones/7x7/sort_asc.gif' onClick="sortColumns('{$defaultOrderby}', 'ASC');"/> - <img src='img/icones/7x7/sort_desc.gif' onClick="sortColumns('{$defaultOrderby}', 'DESC');"/> - </td> - {if $selection == 1} - <td class="ListColHeaderLeft" style="width:250px;"> - {$service_description} - <img src='img/icones/7x7/sort_asc.gif' onClick="sortColumns('service_description', 'ASC');"/> - <img src='img/icones/7x7/sort_desc.gif' onClick="sortColumns('service_description', 'DESC');"/> - </td> - {/if} - <td class="ListColHeaderCenter" style="width:250px;">{$template_trans}</td> - <td class="ListColHeaderCenter" style="width:170px;">{$status_trans}</td> - <td class="ListColHeaderCenter">{$actions_trans} </td> - </tr> - {assign var=$line value=0} - {if $selection == 1} - {foreach key=elem from=$content item=stt} - <tr class="{php} global $line; print $line[$l%2]; {/php}"> - <td class="ListColCenter"><img class="ico-14" src="./img/icons/service.png"></td> - <td class="ListColLeft"><a - href="./include/configuration/configKnowledge/proxy/proxy.php?host_name={$services.$elem.h}" - target="_blank" title="Show Wiki Page"><img class="ico-14" src="./img/icons/link.png"></a> {if - $services.$elem.h != $hostname}{$services.$elem.h}{else} {/if} - </td> - <td class="ListColLeft"><a - href="./include/configuration/configKnowledge/proxy/proxy.php?host_name={$services.$elem.h}&service_description={$services.$elem.svc}" - target="_blank" title="Show Wiki Page"><img class="ico-14" src="./img/icons/link.png"></a> {$services.$elem.svc} - </td> - <td class="ListColRight">{$templateHostArray.$elem}</td> - <td class="ListColCenter">{$status[$stt]}</td> - <td class="ListColCenter"> - {if $stt == 0} - <a name="Create wiki page" - href='./include/configuration/configKnowledge/popup.php?session_id={php}print session_id();{/php}&object=Service:{$elem}&type={$selection}' - target='_blank'>Create wiki page</a> - {$line} - {/if} - {if $stt == 1} - <a href="{$WikiURL}/index.php?title=Service:{$elem}" target='_blank'>{t}View wiki page{/t}</a> - - - <a href="{$WikiURL}/index.php?title=Service:{$elem}&action=edit" target='_blank'>{t}Edit wiki page{/t}</a> - - - <a href="{$WikiURL}/index.php?title=Service:{$elem}&action=history" target='_blank'>{t}View History{/t}</a> - - - <a style="cursor:pointer" onclick="deleteWiki('Service:{$elem}')">{t}Delete wiki page{/t}</a> - - {/if} - </td> - </tr> - {php} $l++ ; {/php} - {/foreach} - {else} - {php} $l = 0; {/php} - {foreach key=elem from=$content item=stt} - <tr class="{php} global $line; print $line[$l%2]; {/php}"> - <td class="ListColCenter"> - {if $selection == 3} - <img class="ico-14" src="./img/icons/service.png"></td> - {else} - <img class="ico-14" src="{$icone[$elem]}"></td> - {/if} - <td class="ListColLeft">{if $selection == 0}<a - href="./include/configuration/configKnowledge/proxy/proxy.php?host_name={$elem}" target="_blank" - title="Show Wiki Page"><img class="ico-14" src="./img/icons/link.png"></a> {/if}{$elem} - </td> - {if $selection == 1} - <td class="ListColLeft">{$content[$elem].svc}</td> - {/if} - <td class="ListColRight">{$templateHostArray[$elem]}</td> - <td class="ListColCenter">{$status[$stt]}</td> - <td class="ListColCenter"> - {if $stt == 0} - {if $selection == 3} - <a name="Create wiki page" - href='./include/configuration/configKnowledge/popup.php?session_id={php}print session_id();{/php}&object=Service-Template:{$elem}&type={$selection}' - target='_blank'>Create wiki page</a> - {elseif $selection == 2} - <a name="Create wiki page" - href='./include/configuration/configKnowledge/popup.php?session_id={php}print session_id();{/php}&object=Host-Template:{$elem}&type={$selection}' - target='_blank'>Create wiki page</a> - {else} - <a name="Create wiki page" - href='./include/configuration/configKnowledge/popup.php?session_id={php}print session_id();{/php}&object=Host:{$elem}&type={$selection}' - target='_blank'>Create wiki page</a> - {/if} - {/if} - {if $stt == 1} - {if $selection == 3} - <a href="{$WikiURL}/index.php?title=Service-Template:{$elem}" target='_blank'>{t}View wiki page{/t}</a> - - - <a href="{$WikiURL}/index.php?title=Service-Template:{$elem}&action=edit" target='_blank'>Edit wiki page</a> - - - <a href="{$WikiURL}/index.php?title=Service-Template:{$elem}&action=history" target='_blank'>View history</a> - - - <a style="cursor:pointer" onclick="deleteWiki('Service-Template:{$elem}')">{t}Delete wiki page{/t}</a> - - {elseif $selection == 2} - <a href="{$WikiURL}/index.php?title=Host-Template:{$elem}" target='_blank'>{t}View wiki page{/t}</a> - - - <a href="{$WikiURL}/index.php?title=Host-Template:{$elem}&action=edit" target='_blank'>Edit wiki page</a> - - - <a href="{$WikiURL}/index.php?title=Host-Template:{$elem}&action=history" target='_blank'>View history</a> - - - <a style="cursor:pointer" onclick="deleteWiki('Host-Template:{$elem}')">{t}Delete wiki page{/t}</a> - - {else} - <a href="{$WikiURL}/index.php?title=Host:{$elem}" target='_blank'>{t}View wiki page{/t}</a> - - - <a href="{$WikiURL}/index.php?title=Host:{$elem}&action=edit" target='_blank'>{t}Edit wiki page{/t}</a> - - - <a href="{$WikiURL}/index.php?title=Host:{$elem}&action=history" target='_blank'>{t}View History{/t}</a> - - - <a style="cursor:pointer" onclick="deleteWiki('Host:{$elem}')">{t}Delete wiki page{/t}</a> + <table class="ajaxOption table"> + <tr> + <th><h5>{t}Filters{/t}</h5></th> + </tr> + <tr> + {if $searchOptions.host == 1} + <td><h4>{$labels.host}</h4></td> + {/if} + {if $searchOptions.hostTemplate == 1} + <td><h4>{$labels.hostTemplate}</h4></td> + {/if} + {if $searchOptions.serviceTemplate == 1} + <td><h4>{$labels.serviceTemplate}</h4></td> + {/if} + {if $searchOptions.hostgroup == 1} + <td><h4>{$labels.hostgroup}</h4></td> + {/if} + {if $searchOptions.poller == 1} + <td><h4>{$labels.poller}</h4></td> + {/if} + </tr> + <tr> + {if $searchOptions.host == 1} + <td><input type='text' name='searchHost' value="{$searchHost}"/></td> + {/if} + {if $searchOptions.hostTemplate == 1} + <td><input type='text' name='searchHostTemplate' value="{$searchHostTemplate}"/></td> + {/if} + {if $searchOptions.serviceTemplate == 1} + <td><input type='text' name='searchServiceTemplate' value="{$searchServiceTemplate}"/></td> + {/if} + {if $searchOptions.hostgroup == 1} + <td><select name='searchHostgroup'>{$searchHostgroup}</select></td> + {/if} + {if $searchOptions.poller == 1} + <td><select name='searchPoller'>{$searchPoller}</select></td> + {/if} + {if $searchOptions.hasNoProcedure == 1 || $searchOptionsTemplateWithNoProcedure == 1} + <td> + {if $searchOptions.hasNoProcedure == 1} + <p><input name='searchHasNoProcedure' type='checkbox' {$searchHasNoProcedure}/> {$labels.hasNoProcedure} + </p> + {/if} + {if $searchOptions.templatesWithNoProcedure == 1} + <p><input name='searchTemplatesWithNoProcedure' type='checkbox' {$searchTemplatesWithNoProcedure}/> + {$labels.templatesWithNoProcedure}</p> + {/if} + </td> + {/if} + <td><input type='submit' name='SearchB' value='{$labels.search}' class="btc bt_success"/></td> + </tr> + <tr> + {if $searchOptions.service == 1} + <td><h4>{$labels.service}</h4></td> + {/if} + {if $searchOptions.servicegroup == 1} + <td><h4>{$labels.servicegroup}</h4></td> + {/if} + </tr> + <tr> + {if $searchOptions.service == 1} + <td><input type='text' name='searchService' value="{$searchService}"/></td> + {/if} + {if $searchOptions.servicegroup == 1} + <td><select name='searchServicegroup'>{$searchServicegroup}</select></td> + {/if} + </tr> + </table> + <table class="ToolbarTable table"> + <tr class="ToolbarTR"> + {php} + include('./include/configuration/configKnowledge/pagination.php'); + {/php} + </tr> + </table> + <table class="ListTable"> + <tr class="ListHeader"> + <td class="ListColHeaderLeft" style="width:18px;"> </td> + <td class="ListColHeaderLeft" style="width:250px;"> + {$host_name} + <img src='img/icones/7x7/sort_asc.gif' onClick="sortColumns('{$defaultOrderby}', 'ASC');"/> + <img src='img/icones/7x7/sort_desc.gif' onClick="sortColumns('{$defaultOrderby}', 'DESC');"/> + </td> + {if $selection == 1} + <td class="ListColHeaderLeft" style="width:250px;"> + {$service_description} + <img src='img/icones/7x7/sort_asc.gif' onClick="sortColumns('service_description', 'ASC');"/> + <img src='img/icones/7x7/sort_desc.gif' onClick="sortColumns('service_description', 'DESC');"/> + </td> + {/if} + <td class="ListColHeaderCenter" style="width:250px;">{$template_trans}</td> + <td class="ListColHeaderCenter" style="width:170px;">{$status_trans}</td> + <td class="ListColHeaderCenter">{$actions_trans} </td> + </tr> + {assign var=$line value=0} + {if $selection == 1} + {foreach key=elem from=$content item=stt} + <tr class="{php} global $line; print $line[$l%2]; {/php}"> + <td class="ListColCenter"><img class="ico-14" src="./img/icons/service.png"></td> + <td class="ListColLeft"><a + href="./include/configuration/configKnowledge/proxy/proxy.php?host_name={$services.$elem.h}" + target="_blank" title="Show Wiki Page"><img class="ico-14" src="./img/icons/link.png"></a> {if + $services.$elem.h != $hostname}{$services.$elem.h}{else} {/if} + </td> + <td class="ListColLeft"><a + href="./include/configuration/configKnowledge/proxy/proxy.php?host_name={$services.$elem.h}&service_description={$services.$elem.svc}" + target="_blank" title="Show Wiki Page"><img class="ico-14" src="./img/icons/link.png"></a> {$services.$elem.svc} + </td> + <td class="ListColRight">{$templateHostArray.$elem}</td> + <td class="ListColCenter">{$status[$stt]}</td> + <td class="ListColCenter"> + {if $stt == 0} + <a name="Create wiki page" + href='./include/configuration/configKnowledge/popup.php?session_id={php}print session_id();{/php}&object=Service_:_{$elem}&type={$selection}' + target='_blank'>{t}Create wiki page{/t}</a> + {$line} + {/if} + {if $stt == 1} + <a href="{$WikiURL}/index.php?title=Service_:_{$elem}" target='_blank'>{t}View wiki page{/t}</a> + - + <a href="{$WikiURL}/index.php?title=Service_:_{$elem}&action=edit" target='_blank'>{t}Edit wiki + page{/t}</a> + - + <a href="{$WikiURL}/index.php?title=Service_:_{$elem}&action=history" target='_blank'>{t}View + History{/t}</a> + - + <a style="cursor:pointer" onclick="deleteWiki('Service_:_{$elem}')">{t}Delete wiki page{/t}</a> + + {/if} + </td> + </tr> + {php} $l++ ; {/php} + {/foreach} + {else} + {php} $l = 0; {/php} + {foreach key=elem from=$content item=stt} + <tr class="{php} global $line; print $line[$l%2]; {/php}"> + <td class="ListColCenter"> + {if $selection == 3} + <img class="ico-14" src="./img/icons/service.png"></td> + {else} + <img class="ico-14" src="{$icone[$elem]}"></td> + {/if} + <td class="ListColLeft">{if $selection == 0}<a + href="./include/configuration/configKnowledge/proxy/proxy.php?host_name={$elem}" target="_blank" + title="Show Wiki Page"><img class="ico-14" src="./img/icons/link.png"></a> {/if}{$elem} + </td> + {if $selection == 1} + <td class="ListColLeft">{$content[$elem].svc}</td> + {/if} + <td class="ListColRight">{$templateHostArray[$elem]}</td> + <td class="ListColCenter">{$status[$stt]}</td> + <td class="ListColCenter"> + {if $stt == 0} + {if $selection == 3} + <a name="Create wiki page" + href='./include/configuration/configKnowledge/popup.php?session_id={php}print session_id();{/php}&object=Service-Template_:_{$elem}&type={$selection}' + target='_blank'>{t}Create wiki page{/t}</a> + {elseif $selection == 2} + <a name="Create wiki page" + href='./include/configuration/configKnowledge/popup.php?session_id={php}print session_id();{/php}&object=Host-Template_:_{$elem}&type={$selection}' + target='_blank'>{t}Create wiki page{/t}</a> + {else} + <a name="Create wiki page" + href='./include/configuration/configKnowledge/popup.php?session_id={php}print session_id();{/php}&object=Host_:_{$elem}&type={$selection}' + target='_blank'>{t}Create wiki page{/t}</a> + {/if} + {/if} + {if $stt == 1} + {if $selection == 3} + <a href="{$WikiURL}/index.php?title=Service-Template_:_{$elem}" target='_blank'>{t}View wiki + page{/t}</a> + - + <a href="{$WikiURL}/index.php?title=Service-Template_:_{$elem}&action=edit" target='_blank'>{t}Edit wiki + page{/t}</a> + - + <a href="{$WikiURL}/index.php?title=Service-Template_:_{$elem}&action=history" target='_blank'>{t}View + history{/t}</a> + - + <a style="cursor:pointer" onclick="deleteWiki('Service-Template_:_{$elem}')">{t}Delete wiki page{/t}</a> + + {elseif $selection == 2} + <a href="{$WikiURL}/index.php?title=Host-Template_:_{$elem}" target='_blank'>{t}View wiki page{/t}</a> + - + <a href="{$WikiURL}/index.php?title=Host-Template_:_{$elem}&action=edit" target='_blank'>{t}Edit wiki + page{/t}</a> + - + <a href="{$WikiURL}/index.php?title=Host-Template_:_{$elem}&action=history" target='_blank'>{t}View + history{/t}</a> + - + <a style="cursor:pointer" onclick="deleteWiki('Host-Template_:_{$elem}')">{t}Delete wiki page{/t}</a> + + {else} + <a href="{$WikiURL}/index.php?title=Host_:_{$elem}" target='_blank'>{t}View wiki page{/t}</a> + - + <a href="{$WikiURL}/index.php?title=Host_:_{$elem}&action=edit" target='_blank'>{t}Edit wiki + page{/t}</a> + - + <a href="{$WikiURL}/index.php?title=Host_:_{$elem}&action=history" target='_blank'>{t}View + History{/t}</a> + - + <a style="cursor:pointer" onclick="deleteWiki('Host_:_{$elem}')">{t}Delete wiki page{/t}</a> - {/if} - {/if} - </td> - </tr> - {php} $l++ ; {/php} - {/foreach} - {/if} - </table> - <table class="ToolbarTable table"> - <tr class="ToolbarTR"> - {php} - include('./include/configuration/configKnowledge/pagination.php'); - {/php} - </tr> - </table> - <input type='hidden' name='o' id='o' value='42'> - <input type='hidden' id='limit' name='limit' value='{$limit}'> - <input type='hidden' id='num' name='num' value='0'> - <input type='hidden' id='orderby' name='orderby' value='{$orderby}'> - <input type='hidden' id='order' name='order' value='{$order}'> + {/if} + {/if} + </td> + </tr> + {php} $l++ ; {/php} + {/foreach} + {/if} + </table> + <table class="ToolbarTable table"> + <tr class="ToolbarTR"> + {php} + include('./include/configuration/configKnowledge/pagination.php'); + {/php} + </tr> + </table> + <input type='hidden' name='o' id='o' value='42'> + <input type='hidden' id='limit' name='limit' value='{$limit}'> + <input type='hidden' id='num' name='num' value='0'> + <input type='hidden' id='orderby' name='orderby' value='{$orderby}'> + <input type='hidden' id='order' name='order' value='{$order}'> </form> {literal} <script type='text/javascript'> - function sortColumns(orderby, order) { - document.getElementById('orderby').value = orderby; - document.getElementById('order').value = order; - document.forms['form'].submit(); - } + function sortColumns(orderby, order) { + document.getElementById('orderby').value = orderby; + document.getElementById('order').value = order; + document.forms['form'].submit(); + } - function deleteWiki(title) { - jQuery.ajax({ - type : "POST", - url : "./include/common/webServices/rest/internal.php?object=centreon_wiki&action=deletePage", - data : JSON.stringify({ - title: title - }), - success : function(data) { - location.reload() - } - }); - } + function deleteWiki(title) { + jQuery.ajax({ + type: "POST", + url: "./include/common/webServices/rest/internal.php?object=centreon_wiki&action=deletePage", + data: JSON.stringify({ + title: title + }), + success: function (data) { + location.reload() + } + }); + } </script> {/literal} -- GitLab