diff --git a/config/wiki.conf.php b/config/wiki.conf.php new file mode 100644 index 0000000000000000000000000000000000000000..bca6c5bc3380819d1396e3ce387d77cd34c9833a --- /dev/null +++ b/config/wiki.conf.php @@ -0,0 +1,20 @@ +<?php + + /* + * MySQL Database Connexion + */ + $db_name = "wikidb"; + $db_user = "centreon"; + $db_password = "password"; + $db_host = "localhost"; + $db_prefix = ""; + + /* + * Wiki URL without a / at the end + */ + $WikiURL = "http://wiki.localhost/mediawiki"; + $CentreonURL = "http://localhost/centreon"; + + $etc_centreon = "/etc/centreon/"; + $log_centreon = "/var/log/centreon/"; +?> \ No newline at end of file diff --git a/cron/centKnowledgeSynchronizer.php b/cron/centKnowledgeSynchronizer.php new file mode 100644 index 0000000000000000000000000000000000000000..23ae70a4135f34612a992c361c04c12be49e7d76 --- /dev/null +++ b/cron/centKnowledgeSynchronizer.php @@ -0,0 +1,231 @@ +<?php +/** + * + */ + +// 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 . "config/wiki.conf.php"; +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"; + +// Define cron constants +define('_WIKIURL_', $WikiURL); +define('_CENTREONURL_', $CentreonURL); + +// Last time the cron has been executed +$startTimestamp = time() - (3600*24); +define('_STARTDATE_', date('Y-m-d', $startTimestamp).'T00:00:00Z'); + + +/** + * + * @return array + */ +function getCreatedPages() +{ + return getChangedPages('new'); +} + +/** + * + * @return array + */ +function getEditedPages() +{ + return getChangedPages('edit'); +} + +/** + * + * @param string $type + * @return array + */ +function getChangedPages($type) +{ + // Connecting to Mediawiki API + $apiUrl = _WIKIURL_.'/api.php?format=json&action=query&list=recentchanges&rclimit=50&rcprop=title&rctype='.$type; + + // Sending request + $result = json_decode(file_get_contents($apiUrl)); + return $result->query->recentchanges; +} + +/** + * + * @param array $pages + * @return array + */ +function detectCentreonObjects($pages) +{ + $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; +} + +/** + * + * @param CentreonDB $dbConnector + * @param array $listOfObjects + */ +function synchronizeWithCentreon($dbConnector, $listOfObjects) +{ + 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; + } + } +} + +/** + * + * @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 = _CENTREONURL_.'/../proxy/proxyKB.php?host_name=$HOSTNAME$'; + $queryUpdate = "UPDATE extended_host_information " + ."SET ehi_notes_url = '$valueToAdd' " + ."WHERE host_host_id = '".$tuple['host_id']."'"; + $dbConnector->query($queryUpdate); +} + +/** + * + * @param CentreonDB $dbConnector + * @param string $serviceName + */ +function editLinkForService($dbConnector, $objName) +{ + if (is_array($objName)) + { + $serviceName = str_replace(' ', '_', $objName[count($objName) - 1]); + unset($objName[count($objName) - 1]); + $hostName = substr(implode('_', $objName), 8); + $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 = _CENTREONURL_.'/../proxy/proxyKB.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 ***** + ************************* + */ + +// Initiate connexion +$dbConnector = new CentreonDB(); +// Get all pages title that where changed +$allPagesModificationInMediaWiki = array_merge(getCreatedPages(), getEditedPages()); +$centreonObjects = detectCentreonObjects($allPagesModificationInMediaWiki); + +// Synchro with Centreon +synchronizeWithCentreon($dbConnector, $centreonObjects); + +?> diff --git a/proxy/proxyKB.php b/proxy/proxyKB.php new file mode 100644 index 0000000000000000000000000000000000000000..fd96e5a42d1a00a7e7a18371ec8ea90b69e44dff --- /dev/null +++ b/proxy/proxyKB.php @@ -0,0 +1,81 @@ +<?php +/* + * Copyright 2005-2009 MERETHIS + * 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 MERETHIS + * 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 MERETHIS choice, provided that + * MERETHIS 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 + * + * SVN : $URL: http://svn.centreon.com/trunk/centreon/www/include/monitoring/status/Services/service.php $ + * SVN : $Id: service.php 8549 2009-07-01 16:20:26Z shotamchay $ + * + */ + + ini_set("display_errors", "On"); + + require_once "../config/wiki.conf.php"; + global $etc_centreon, $db_prefix; + + require_once $etc_centreon."/centreon.conf.php"; + + set_include_path(get_include_path() . PATH_SEPARATOR . $centreon_path . "www/class/centreon-knowledge/".PATH_SEPARATOR . $centreon_path."www/"); + + require_once "DB.php"; + require_once "include/common/common-Func.php"; + require_once "class/centreonLog.class.php"; + require_once "class/centreonDB.class.php"; + require_once "class/centreon-knowledge/procedures.class.php"; + require_once "class/centreon-knowledge/procedures_DB_Connector.class.php"; + require_once "class/centreon-knowledge/procedures_Proxy.class.php"; + + /* + * DB connexion + */ + $pearDB = new CentreonDB(); + /* + * Check if user want host or service procedures + */ + if (isset($_GET["host_name"]) && isset($_GET["service_description"])) { + $proxy = new procedures_Proxy($pearDB, $db_prefix, $_GET["host_name"], $_GET["service_description"]); + } else if (isset($_GET["host_name"])) { + $proxy = new procedures_Proxy($pearDB, $db_prefix, $_GET["host_name"]); + } + + + 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"]); + else + header ("Location: $WikiURL/?title=Host:".$_GET["host_name"]); + } + exit(); + +?> \ No newline at end of file diff --git a/www/class/centreon-knowledge/procedures.class.php b/www/class/centreon-knowledge/procedures.class.php new file mode 100644 index 0000000000000000000000000000000000000000..7521564ad0403e32cbd6274e94027ea830c8d21e --- /dev/null +++ b/www/class/centreon-knowledge/procedures.class.php @@ -0,0 +1,509 @@ +<?php +/* + * Copyright 2005-2011 MERETHIS + * 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 MERETHIS + * 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 MERETHIS choice, provided that + * MERETHIS 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 + * + */ + +define("PROCEDURE_SIMPLE_MODE", 0); +define("PROCEDURE_INHERITANCE_MODE", 1); + +class procedures +{ + private $procList; + public $DB; + public $centreon_DB; + public $db_prefix; + public $hostList; + public $hosttplList; + public $serviceList; + public $serviceTplList; + public $hostIconeList; + public $diff; + + /** + * Constructor + * + * @param int $retry + * @param string $db_name + * @param string $db_user + * @param string $db_host + * @param string $db_password + * @param CentreonDB $pearDB + * @param string $db_prefix + */ + public function __construct($retry, $db_name, $db_user, $db_host, $db_password, $pearDB, $db_prefix) + { + $this->DB = new procedures_DB_Connector($retry, $db_name, $db_user, $db_host, $db_password); + $this->centreon_DB = $pearDB; + $this->hostList = array(); + $this->hosttplList = array(); + $this->serviceList = array(); + $this->serviceTplList = array(); + $this->db_prefix = $db_prefix; + $this->setProcedures(); + } + + /** + * Set procedures + * + * @return void + */ + private function setProcedures() + { + $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"]; + } + $DBRESULT->free(); + } + + /** + * Get Procedures + * + * @return array + */ + public function getProcedures() + { + return $this->procList; + } + + /** + * Get Icon List + * + * @return array + */ + public function getIconeList() + { + return $this->hostIconeList; + } + + /** + * + */ + public function getDiff($selection, $type = null) + { + $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:"; + } + foreach ($selection as $key => $value) { + if (!isset($wikiContent[$prefix.trim($key)])) { + $diff[$key] = 0; + } else { + $diff[$key] = 1; + } + } + return $diff; + } + + /** + * Get Host Id + * + * @param string $host_name + * @param CentreonDB $pearDB + * @return int + */ + function getMyHostID($host_name = null) + { + $DBRESULT = $this->centreon_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"]; + } + } + + /** + * Get Service Id + * + * @param int $host_id + * @param string $service_description + * @return int + */ + 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 + * + * @param int $service_id + * @return array + */ + public function getMyServiceTemplateModels($service_id = null) + { + $tplArr = array(); + + $DBRESULT = $this->centreon_DB->query("SELECT service_description, service_template_model_stm_id + FROM service + 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(); + $service_id = $row["service_template_model_stm_id"]; + if ($row["service_description"]) { + $tplArr[$service_id] = html_entity_decode($row["service_description"], ENT_QUOTES); + } + while (1) { + $DBRESULT = $this->centreon_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] = html_entity_decode($row["service_description"], ENT_QUOTES); + } else { + break; + } + if ($row["service_template_model_stm_id"]) { + $service_id = $row["service_template_model_stm_id"]; + } else { + break; + } + } + } + return ($tplArr); + } + + /** + * Get host template models + * + * @param int $host_id + * @return void + */ + public function getMyHostMultipleTemplateModels($host_id = null) + { + if (!$host_id) { + return; + } + + $tplArr = array(); + $DBRESULT = $this->centreon_DB->query("SELECT host_tpl_id + FROM `host_template_relation` + 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"); + $hTpl = $DBRESULT2->fetchRow(); + $tplArr[$row['host_tpl_id']] = html_entity_decode($hTpl["host_name"], ENT_QUOTES); + } + unset($row); + unset($hTpl); + return ($tplArr); + } + + /** + * Set host information + * + * @return void + */ + public function setHostInformations() + { + /* + * Get Host Informations + */ + $DBRESULT = $this->centreon_DB->query("SELECT host_name, host_id, host_register, ehi_icon_image + FROM host, extended_host_information ehi + WHERE host.host_id = ehi.host_host_id + ORDER BY host_name"); + while ($data = $DBRESULT->fetchRow()) { + if ($data["host_register"] == 1) { + $this->hostList[$data["host_name"]] = $data["host_id"]; + } else { + $this->hostTplList[$data["host_name"]] = $data["host_id"]; + } + $this->hostIconeList["Host:".$data["host_name"]] = "./img/media/" . $this->getImageFilePath($data["ehi_icon_image"]); + } + $DBRESULT->free(); + unset($data); + } + + /** + * Get image file path + * + * @param int $image_id + * @return string + */ + public function getImageFilePath($image_id) + { + 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." + 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"]; + } + $DBRESULT2->free(); + unset($row2); + } else { + return "../icones/16x16/server_network.gif"; + } + } + + /** + * Set service information + * + * @return void + */ + public function setServiceInformations() + { + $DBRESULT = $this->centreon_DB->query("SELECT service_description, service_id, service_register + FROM service WHERE service_register = '0' + ORDER BY service_description"); + while ($data = $DBRESULT->fetchRow()) + { + $this->serviceTplList["Service:".$data["service_description"]] = $data["service_id"]; + } + $DBRESULT->free(); + unset($data); + } + + /** + * Duplicate + * + * @param string $template + * @param string $object + * @param int $type + * @return void + */ + public function duplicate($template, $object, $type) + { + $debug = 0; + + if (isset($template)) { + /* + * Get Template + */ + if ($type == 2) { + $template = "H-TPL-".$template; + } + if ($type == 3) { + $template = "S-TPL-".$template; + } + $DBRESULT = $this->DB->query("SELECT * FROM ".$this->db_prefix."page WHERE page_title LIKE '$template'"); + $data = $DBRESULT->fetchRow(); + $DBRESULT->free(); + + if ($debug) { + print "SELECT * FROM ".$this->db_prefix."revision WHERE rev_page LIKE '".$data['page_id']."' ORDER BY rev_text_id DESC LIMIT 1"; + } + $DBRESULT = $this->DB->query("SELECT * FROM ".$this->db_prefix."revision WHERE ".$this->db_prefix."rev_page LIKE '".$data['page_id']."' ORDER BY rev_text_id DESC LIMIT 1"); + $revision = $DBRESULT->fetchRow(); + $DBRESULT->free(); + + if ($debug) { + print "SELECT * FROM ".$this->db_prefix."text WHERE old_id = '".$data['page_id']."' ORDER BY old_id DESC LIMIT 1"; + } + $DBRESULT = $this->DB->query("SELECT * FROM ".$this->db_prefix."text WHERE old_id = '".$data['page_id']."' ORDER BY old_id DESC LIMIT 1"); + $text = $DBRESULT->fetchRow(); + $DBRESULT->free(); + + if ($type == 0) { + $object = "Host:".$object; + } + if ($type == 2) { + $object = "Service:".$object; + } + if ($type == 2) { + $object = "Host-Template:".$object; + } + if ($type == 3) { + $object = "Service-Template:".$object; + } + + if ($debug) { + print ("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', '1', '', '".$data["page_touched"]."', '".$data["page_latest"]."', '".$data["page_len"]."')"); + } + $dateTouch = date("YmdHis"); + $this->DB->query("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"]."')"); + $DBRESULT = $this->DB->query("SELECT MAX(page_id) FROM ".$this->db_prefix."page"); + $id = $DBRESULT->fetchRow(); + + if ($debug) { + print("INSERT INTO `".$this->db_prefix."text` (old_id, old_text, old_flags) VALUE (NULL, '".$text["old_text"]."', '".$text["old_flags"]."')"); + print("INSERT INTO `".$this->db_prefix."revision` (rev_page, rev_text_id, rev_comment, rev_user_text, rev_timestamp) VALUE ('".$id["MAX(page_id)"]."', (SELECT MAX(old_id) FROM text), '".$revision["rev_comment"]."', 'Centreon','".$dateTouch."')"); + } + + $this->DB->query("INSERT INTO `text` (old_id, old_text, old_flags) VALUE (NULL, '".$text["old_text"]."', '".$text["old_flags"]."')"); + $this->DB->query("INSERT INTO `revision` (rev_page, rev_text_id, rev_comment, rev_user_text, rev_timestamp, rev_len) VALUE ('".$id["MAX(page_id)"]."', (SELECT MAX(old_id) FROM text), '".$revision["rev_comment"]."', '".$revision["rev_user_text"]."','".$dateTouch."','".$revision["rev_len"]."')"); + + } else { + ; + } + } + + /** + * Check if Service has procedure + * + * @param string $key + * @param array $templates + * @param int $mode + * @return bool + */ + public function serviceHasProcedure($key, $templates = array(), $mode = PROCEDURE_SIMPLE_MODE) + { + if (isset($this->procList["Service:".$key])) { + return true; + } + if ($mode == PROCEDURE_SIMPLE_MODE) { + return false; + } elseif ($mode == PROCEDURE_INHERITANCE_MODE) { + foreach ($templates as $templateId => $templateName) { + $res = $this->serviceTemplateHasProcedure($templateName, null, PROCEDURE_SIMPLE_MODE); + if ($res == true) { + return true; + } + } + } + return false; + } + + /** + * Check if Host has procedure + * + * @param string $key + * @param array $templates + * @param int $mode + * @return bool + */ + public function hostHasProcedure($key, $templates = array(), $mode = PROCEDURE_SIMPLE_MODE) + { + if (isset($this->procList["Host:".$key])) { + return true; + } + if ($mode == PROCEDURE_SIMPLE_MODE) { + return false; + } elseif ($mode == PROCEDURE_INHERITANCE_MODE) { + foreach ($templates as $templateId => $templateName) { + $res = $this->hostTemplateHasProcedure($templateName, null, PROCEDURE_SIMPLE_MODE); + if ($res == true) { + return true; + } + } + } + return false; + } + + /** + * Check if Service template has procedure + * + * @param string $key + * @param array $templates + * @param int $mode + * @return bool + */ + public function serviceTemplateHasProcedure($key = "", $templates = array(), $mode = PROCEDURE_SIMPLE_MODE) + { + 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])) { + return true; + } + } + } + return false; + } + + /** + * Check if Host template has procedures + * + * @param string $key + * @param array $templates + * @return bool + */ + public function hostTemplateHasProcedure($key = "", $templates = array(), $mode = PROCEDURE_SIMPLE_MODE) + { + 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])) { + return true; + } + } + } + return false; + } +} + +?> \ No newline at end of file diff --git a/www/class/centreon-knowledge/procedures_DB_Connector.class.php b/www/class/centreon-knowledge/procedures_DB_Connector.class.php new file mode 100644 index 0000000000000000000000000000000000000000..b3a94594cbe1a276f0d41aa7e0a42fb75e86738c --- /dev/null +++ b/www/class/centreon-knowledge/procedures_DB_Connector.class.php @@ -0,0 +1,125 @@ +<?php +/* + * Copyright 2005-2009 MERETHIS + * 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 MERETHIS + * 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 MERETHIS choice, provided that + * MERETHIS 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 + * + */ + +class procedures_DB_Connector { + private $db_type = "mysql"; + private $retry; + private $privatePearDB; + private $dsn; + private $options; + private $log; + public $debug; + + /* + * Constructor only accepts 1 parameter which can be : + * - centreon or NULL + * - centstorage + * - ndo + */ + function procedures_DB_Connector($retry = 3, $db_name, $db_user, $db_host, $db_password) { + $this->retry = $retry; + $this->options = array('debug' => 2, 'portability' => DB_PORTABILITY_ALL ^ DB_PORTABILITY_LOWERCASE); + $this->log = new CentreonLog(); + $this->connectToWiki($db_name, $db_user, $db_host, $db_password); + $this->connect(); + $this->debug = 0; + } + + private function displayConnectionErrorPage() { + echo "<center><b>" . _("Connection to Wiki database failed, please contact your administrator") . "</b></center>"; + exit; + } + + /* + * Get info to connect to Centreon DB + */ + private function connectToWiki($db_name, $db_user, $db_host, $db_password) { + $this->dsn = array( + 'phptype' => $this->db_type, + 'username' => $db_user, + 'password' => $db_password, + 'hostspec' => $db_host, + 'database' => $db_name, + ); + } + + /* + * The connection is established here + */ + public function connect() { + + $this->privatePearDB =& DB::connect($this->dsn, $this->options); + $i = 0; + while (PEAR::isError($this->privatePearDB) && ($i < $this->retry)) { + $this->privatePearDB =& DB::connect($this->dsn, $this->options); + $i++; + } + if ($i == $this->retry) { + $this->log->insertLog(2, $this->privatePearDB->getMessage() . " (retry : $i)"); + $this->displayConnectionErrorPage(); + } else { + $this->privatePearDB->setFetchMode(DB_FETCHMODE_ASSOC); + } + } + + /* + * Disconnection + */ + public function disconnect() { + $this->privatePearDB->disconnect(); + } + + public function toString() { + return $this->privatePearDB->toString(); + } + + /* + * Query + */ + public function query($query_string = NULL) { + + if ($this->debug) { + $query = str_replace("`", "", $query_string); + $query = str_replace("'", "\'", $query); + $query = str_replace("*", "\*", $query); + exec("echo '$query' >> $log_centreon/procedure.log"); + } + $DBRES = $this->privatePearDB->query($query_string); + if (PEAR::isError($DBRES)) + $this->log->insertLog(2, $DBRES->getMessage() . " QUERY : " . $query_string); + return $DBRES; + } +} +?> \ No newline at end of file diff --git a/www/class/centreon-knowledge/procedures_Proxy.class.php b/www/class/centreon-knowledge/procedures_Proxy.class.php new file mode 100644 index 0000000000000000000000000000000000000000..df83c02642d85e8d9c51164099e88a5a326e2491 --- /dev/null +++ b/www/class/centreon-knowledge/procedures_Proxy.class.php @@ -0,0 +1,169 @@ +<?php +/* + * MERETHIS + * + * Source Copyright 2005-2010 MERETHIS + * + * Unauthorized reproduction, copy and distribution + * are not allowed. + * + * For more information : contact@merethis.com + * + */ + +class procedures_Proxy { + var $DB; + var $hflag; + var $sflag; + var $proc; + var $url; + var $wikiUrl; + + public function procedures_Proxy($pearDB, $db_prefix, $host_name, $service_description = NULL) { + global $etc_centreon, $db_name, $db_user, $db_host, $db_password, $WikiURL; + + $this->DB = $pearDB; + $this->hflag = 0; + $this->sflag = 0; + + require_once "../../../config/wiki.conf.php"; + require_once "$etc_centreon/centreon.conf.php"; + + $this->wikiURL = $WikiURL; + $this->proc = new procedures(3, $db_name, $db_user, $db_host, $db_password, $this->DB, $db_prefix); + + 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)); + } + return; + } + + 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) { + if ($this->hflag != 0) + $this->proc->setHostInformations(); + $this->proc->setServiceInformations(); + $this->sflag; + + $procList = $this->proc->getProcedures(); + + /* + * Check Service + */ + 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) { + $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) { + /* + * Get Services attached to hosts + */ + $DBRESULT =& $this->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->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(); + } + + + 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) { + + $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); + } +} + +?> \ No newline at end of file diff --git a/www/include/configuration/configKnowledge/display-hostTemplates.php b/www/include/configuration/configKnowledge/display-hostTemplates.php new file mode 100644 index 0000000000000000000000000000000000000000..2a4c4e6bf805b98610153933c504efcc7354dbe6 --- /dev/null +++ b/www/include/configuration/configKnowledge/display-hostTemplates.php @@ -0,0 +1,211 @@ +<?php +/* + * Copyright 2005-2009 MERETHIS + * 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 MERETHIS + * 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 MERETHIS choice, provided that + * MERETHIS 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 + * + * SVN : $URL: http://svn.centreon.com/trunk/centreon/www/include/monitoring/status/Services/service.php $ + * SVN : $Id: service.php 8549 2009-07-01 16:20:26Z shotamchay $ + * + */ + + if (!isset($oreon)) + exit(); + + $modules_path = $centreon_path . "www/include/configuration/configKnowledge/"; + require_once $modules_path . 'header.php'; + require_once $modules_path . 'functions.php'; + + + if (!isset($limit) || !$limit) + $limit = $oreon->optGen["maxViewConfiguration"]; + + if (isset($_POST['num']) && $_POST['num'] == 0) { + $_GET['num'] = 0; + } + + if (isset($_POST['searchHostTemplate'])) { + if (!isset($_POST['searchHasNoProcedure']) && isset($_GET['searchHasNoProcedure'])) { + unset($_REQUEST['searchHasNoProcedure']); + } + if (!isset($_POST['searchTemplatesWithNoProcedure']) && isset($_GET['searchTemplatesWithNoProcedure'])) { + unset($_REQUEST['searchTemplatesWithNoProcedure']); + } + } + + $order = "ASC"; + $orderby = "host_name"; + if (isset($_REQUEST['order']) && $_REQUEST['order'] && isset($_REQUEST['orderby']) && $_REQUEST['orderby']) { + $order = $_REQUEST['order']; + $orderby = $_REQUEST['orderby']; + } + + require_once "./include/common/autoNumLimit.php"; + + /* + * Add paths + */ + set_include_path(get_include_path() . PATH_SEPARATOR . $modules_path ); + + /* + * Pear library + */ + require_once "HTML/QuickForm.php"; + require_once "HTML/QuickForm/advmultiselect.php"; + require_once "HTML/QuickForm/Renderer/ArraySmarty.php"; + + + require_once $centreon_path."/config/wiki.conf.php"; + require_once $centreon_path."/www/class/centreon-knowledge/procedures_DB_Connector.class.php"; + require_once $centreon_path."/www/class/centreon-knowledge/procedures.class.php"; + + /* + * Smarty template Init + */ + $tpl = new Smarty(); + $tpl = initSmartyTpl($modules_path, $tpl); + + $currentPage = "hostTemplates"; + require_once $modules_path . 'search.php'; + + /* + * Init Status Template + */ + $status = array(0=>"<font color='orange'> "._("No wiki page defined")." </font>", 1=>"<font color='green'> "._("Wiki page defined")." </font>"); + $line = array(0 => "list_one", 1 => "list_two"); + + $proc = new procedures(3, $db_name, $db_user, $db_host, $db_password, $pearDB, $db_prefix); + $proc->setHostInformations(); + $proc->setServiceInformations(); + + $query = "SELECT SQL_CALC_FOUND_ROWS host_name, host_id, host_register, ehi_icon_image + FROM host, extended_host_information ehi + WHERE host.host_id = ehi.host_host_id + AND host.host_register = '0' "; + if (isset($_REQUEST['searchHostTemplate']) && $_REQUEST['searchHostTemplate']) { + $query .= " AND host.host_name LIKE '%" .$_REQUEST['searchHostTemplate'] . "%' "; + } + $query .= " ORDER BY $orderby $order LIMIT ".$num * $limit.", ".$limit; + $DBRESULT = $pearDB->query($query); + + $res = $pearDB->query("SELECT FOUND_ROWS() as numrows"); + $row = $res->fetchRow(); + $rows = $row['numrows']; + + while ($data = $DBRESULT->fetchRow()) { + if ($data["host_register"] == 0) { + $selection[$data["host_name"]] = $data["host_id"]; + } + $proc->hostIconeList[$data["host_name"]] = "./img/media/" . $proc->getImageFilePath($data["ehi_icon_image"]); + } + $DBRESULT->free(); + unset($data); + + /* + * Create Diff + */ + + $tpl->assign("host_name", _("Hosts Templates")); + + $diff = array(); + $templateHostArray = array(); + foreach ($selection as $key => $value) { + $tplStr = ""; + $tplArr = $proc->getMyHostMultipleTemplateModels($value); + if ($proc->hostTemplateHasProcedure($key, $tplArr) == true) { + $diff[$key] = 1; + } else { + $diff[$key] = 0; + } + + if (isset($_REQUEST['searchTemplatesWithNoProcedure'])) { + if ($diff[$key] == 1 || $proc->hostTemplateHasProcedure($key, $tplArr, PROCEDURE_INHERITANCE_MODE) == true) { + $rows--; + unset($diff[$key]); + continue; + } + } elseif (isset($_REQUEST['searchHasNoProcedure'])) { + if ($diff[$key] == 1) { + $rows--; + unset($diff[$key]); + continue; + } + } + if (count($tplArr)) { + $firstTpl = 1; + foreach ($tplArr as $key1 => $value1) { + if ($firstTpl) { + $tplStr .= "<a href='".$WikiURL."/index.php?title=Host-Template:$value1' target='_blank'>".$value1."</a>"; + $firstTpl = 0; + } else + $tplStr .= " | <a href='".$WikiURL."/index.php?title=Host-Template:$value1' target='_blank'>".$value1."</a>"; + } + } + $templateHostArray[$key] = $tplStr; + unset($tplStr); + } + + include("./include/common/checkPagination.php"); + + if (isset($templateHostArray)) + $tpl->assign("templateHostArray", $templateHostArray); + $tpl->assign("WikiURL", $WikiURL); + $tpl->assign("content", $diff); + $tpl->assign("status", $status); + $tpl->assign("selection", 2); + $tpl->assign("icone", $proc->getIconeList()); + + /* + * Send template in order to open + */ + + /* + * translations + */ + $tpl->assign("status_trans", _("Status")); + $tpl->assign("actions_trans", _("Actions")); + $tpl->assign("template_trans", _("Template")); + + /* + * Template + */ + $tpl->assign("lineTemplate", $line); + $tpl->assign('limit', $limit); + + $tpl->assign('order', $order); + $tpl->assign('orderby', $orderby); + $tpl->assign('defaultOrderby', 'host_name'); + + /* + * Apply a template definition + */ + $tpl->display($modules_path . "templates/display.ihtml"); + +?> diff --git a/www/include/configuration/configKnowledge/display-hosts.php b/www/include/configuration/configKnowledge/display-hosts.php new file mode 100644 index 0000000000000000000000000000000000000000..e526856a6f59d704d4962d68439f18fc95ca2891 --- /dev/null +++ b/www/include/configuration/configKnowledge/display-hosts.php @@ -0,0 +1,224 @@ +<?php +/* + * Copyright 2005-2015 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 MERETHIS + * 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 MERETHIS choice, provided that + * MERETHIS 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 + * + * SVN : $URL: http://svn.centreon.com/trunk/centreon/www/include/monitoring/status/Services/service.php $ + * SVN : $Id: service.php 8549 2009-07-01 16:20:26Z shotamchay $ + * + */ + + if (!isset($oreon)) + exit(); + + $modules_path = $centreon_path . "www/include/configuration/configKnowledge/"; + require_once $modules_path . 'header.php'; + require_once $modules_path . 'functions.php'; + + + if (!isset($limit) || !$limit) + $limit = $oreon->optGen["maxViewConfiguration"]; + + if (isset($_POST['num']) && $_POST['num'] == 0) { + $_GET['num'] = 0; + } + + if (isset($_POST['searchHost'])) { + if (!isset($_POST['searchHasNoProcedure']) && isset($_GET['searchHasNoProcedure'])) { + unset($_REQUEST['searchHasNoProcedure']); + } + if (!isset($_POST['searchTemplatesWithNoProcedure']) && isset($_GET['searchTemplatesWithNoProcedure'])) { + unset($_REQUEST['searchTemplatesWithNoProcedure']); + } + } + + $order = "ASC"; + $orderby = "host_name"; + if (isset($_REQUEST['order']) && $_REQUEST['order'] && isset($_REQUEST['orderby']) && $_REQUEST['orderby']) { + $order = $_REQUEST['order']; + $orderby = $_REQUEST['orderby']; + } + + require_once "./include/common/autoNumLimit.php"; + + /* + * Add paths + */ + set_include_path(get_include_path() . PATH_SEPARATOR . $modules_path ); + + /* + * Pear library + */ + require_once "HTML/QuickForm.php"; + require_once "HTML/QuickForm/advmultiselect.php"; + require_once "HTML/QuickForm/Renderer/ArraySmarty.php"; + + require_once $centreon_path."/config/wiki.conf.php"; + require_once $centreon_path."/www/class/centreon-knowledge/procedures_DB_Connector.class.php"; + require_once $centreon_path."/www/class/centreon-knowledge/procedures.class.php"; + + /* + * Smarty template Init + */ + $tpl = new Smarty(); + $tpl = initSmartyTpl($modules_path, $tpl); + + $currentPage = "hosts"; + require_once $modules_path.'search.php'; + + /* + * Init Status Template + */ + $status = array(0=>"<font color='orange'> "._("No wiki page defined")." </font>", 1=>"<font color='green'> "._("Wiki page defined")." </font>"); + $line = array(0 => "list_one", 1 => "list_two"); + $proc = new procedures(3, $db_name, $db_user, $db_host, $db_password, $pearDB, $db_prefix); + $proc->setHostInformations(); + $proc->setServiceInformations(); + + $query = "SELECT SQL_CALC_FOUND_ROWS host_name, host_id, host_register, ehi_icon_image "; + $query .= " FROM extended_host_information ehi, host "; + if (isset($_REQUEST['searchPoller']) && $_REQUEST['searchPoller']) { + $query .= " JOIN ns_host_relation nhr ON nhr.host_host_id = host.host_id "; + } + if (isset($_REQUEST['searchHostgroup']) && $_REQUEST['searchHostgroup']) { + $query .= " JOIN hostgroup_relation hgr ON hgr.host_host_id = host.host_id "; + } + $query .= " WHERE host.host_id = ehi.host_host_id "; + if (isset($_REQUEST['searchPoller']) && $_REQUEST['searchPoller']) { + $query .= " AND nhr.nagios_server_id = " . $pearDB->escape($_REQUEST['searchPoller']); + } + $query .= " AND host.host_register = '1' "; + if (isset($_REQUEST['searchHostgroup']) && $_REQUEST['searchHostgroup']) { + $query .= " AND hgr.hostgroup_hg_id = " . $pearDB->escape($_REQUEST['searchHostgroup']); + } + if (isset($_REQUEST['searchHost']) && $_REQUEST['searchHost']) { + $query .= " AND host_name LIKE '%".$pearDB->escape($_REQUEST['searchHost'])."%'"; + } + $query .= " ORDER BY $orderby $order LIMIT ".$num * $limit.", ".$limit; + $DBRESULT = $pearDB->query($query); + + $res = $pearDB->query("SELECT FOUND_ROWS() as numrows"); + $row = $res->fetchRow(); + $rows = $row['numrows']; + + while ($data = $DBRESULT->fetchRow()) { + if ($data["host_register"] == 1) + $selection[$data["host_name"]] = $data["host_id"]; + $proc->hostIconeList[$data["host_name"]] = "./img/media/" . $proc->getImageFilePath($data["ehi_icon_image"]); + } + $DBRESULT->free(); + unset($data); + + /* + * Create Diff + */ + $tpl->assign("host_name", _("Hosts")); + + $diff = array(); + $templateHostArray = array(); + + foreach ($selection as $key => $value) { + $tplStr = ""; + $tplArr = $proc->getMyHostMultipleTemplateModels($value); + if ($proc->hostHasProcedure($key, $tplArr) == true) { + $diff[$key] = 1; + } else { + $diff[$key] = 0; + } + + if (isset($_REQUEST['searchTemplatesWithNoProcedure'])) { + if ($diff[$key] == 1 || $proc->hostHasProcedure($key, $tplArr, PROCEDURE_INHERITANCE_MODE) == true) { + $rows--; + unset($diff[$key]); + continue; + } + } elseif (isset($_REQUEST['searchHasNoProcedure'])) { + if ($diff[$key] == 1) { + $rows--; + unset($diff[$key]); + continue; + } + } + + if (count($tplArr)) { + $firstTpl = 1; + foreach ($tplArr as $key1 => $value1) { + if ($firstTpl) { + $tplStr .= "<a href='".$WikiURL."/index.php?title=Host:$value1' target='_blank'>".$value1."</a>"; + $firstTpl = 0; + } else + $tplStr .= " | <a href='".$WikiURL."/index.php?title=Host:$value1' target='_blank'>".$value1."</a>"; + } + } + $templateHostArray[$key] = $tplStr; + unset($tplStr); + } + + include("./include/common/checkPagination.php"); + + if (isset($templateHostArray)) { + $tpl->assign("templateHostArray", $templateHostArray); + } + + $tpl->assign("WikiURL", $WikiURL); + $tpl->assign("content", $diff); + $tpl->assign("status", $status); + $tpl->assign("selection", 0); + $tpl->assign("icone", $proc->getIconeList()); + + /* + * Send template in order to open + */ + + /* + * translations + */ + $tpl->assign("status_trans", _("Status")); + $tpl->assign("actions_trans", _("Actions")); + $tpl->assign("template_trans", _("Template")); + + /* + * Template + */ + $tpl->assign("lineTemplate", $line); + $tpl->assign('limit', $limit); + + $tpl->assign('order', $order); + $tpl->assign('orderby', $orderby); + $tpl->assign('defaultOrderby', 'host_name'); + + /* + * Apply a template definition + */ + + $tpl->display($modules_path."templates/display.ihtml"); + +?> diff --git a/www/include/configuration/configKnowledge/display-serviceTemplates.php b/www/include/configuration/configKnowledge/display-serviceTemplates.php new file mode 100644 index 0000000000000000000000000000000000000000..d5532678ca2a6b6630e49f0d26514d383dd3e600 --- /dev/null +++ b/www/include/configuration/configKnowledge/display-serviceTemplates.php @@ -0,0 +1,211 @@ +<?php +/* + * Copyright 2005-2009 MERETHIS + * 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 MERETHIS + * 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 MERETHIS choice, provided that + * MERETHIS 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 + * + * SVN : $URL: http://svn.centreon.com/trunk/centreon/www/include/monitoring/status/Services/service.php $ + * SVN : $Id: service.php 8549 2009-07-01 16:20:26Z shotamchay $ + * + */ + + if (!isset($oreon)) + exit(); + + $modules_path = $centreon_path . "www/include/configuration/configKnowledge/"; + require_once $modules_path . 'header.php'; + require_once $modules_path . 'functions.php'; + + if (!isset($limit) || !$limit) + $limit = $oreon->optGen["maxViewConfiguration"]; + + if (isset($_POST['num']) && $_POST['num'] == 0) { + $_GET['num'] = 0; + } + + if (isset($_POST['searchServiceTemplate'])) { + if (!isset($_POST['searchHasNoProcedure']) && isset($_GET['searchHasNoProcedure'])) { + unset($_REQUEST['searchHasNoProcedure']); + } + if (!isset($_POST['searchTemplatesWithNoProcedure']) && isset($_GET['searchTemplatesWithNoProcedure'])) { + unset($_REQUEST['searchTemplatesWithNoProcedure']); + } + } + + $order = "ASC"; + $orderby = "service_description"; + if (isset($_REQUEST['order']) && $_REQUEST['order'] && isset($_REQUEST['orderby']) && $_REQUEST['orderby']) { + $order = $_REQUEST['order']; + $orderby = $_REQUEST['orderby']; + } + + require_once "./include/common/autoNumLimit.php"; + + /* + * Add paths + */ + set_include_path(get_include_path() . PATH_SEPARATOR . $modules_path ); + + /* + * Pear library + */ + require_once "HTML/QuickForm.php"; + require_once "HTML/QuickForm/advmultiselect.php"; + require_once "HTML/QuickForm/Renderer/ArraySmarty.php"; + + require_once $centreon_path."/config/wiki.conf.php"; + require_once $centreon_path."/www/class/centreon-knowledge/procedures_DB_Connector.class.php"; + require_once $centreon_path."/www/class/centreon-knowledge/procedures.class.php"; + + /* + * Smarty template Init + */ + $tpl = new Smarty(); + $tpl = initSmartyTpl($path, $tpl); + + $currentPage = "serviceTemplates"; + require_once $modules_path . 'search.php'; + + /* + * Init Status Template + */ + $status = array(0=>"<font color='orange'> "._("No wiki page defined")." </font>", 1=>"<font color='green'> "._("Wiki page defined")." </font>"); + $line = array(0 => "list_one", 1 => "list_two"); + + $proc = new procedures(3, $db_name, $db_user, $db_host, $db_password, $pearDB, $db_prefix); + $proc->setHostInformations(); + $proc->setServiceInformations(); + + /* + * Get Services Template Informations + */ + $query = "SELECT SQL_CALC_FOUND_ROWS service_description, service_id + FROM service + WHERE service_register = '0' "; + if (isset($_REQUEST['searchServiceTemplate']) && $_REQUEST['searchServiceTemplate']) { + $query .= " AND service_description LIKE '%" .$_REQUEST['searchServiceTemplate'] . "%' "; + } + $query .= "ORDER BY $orderby $order LIMIT ".$num * $limit.", ".$limit; + $DBRESULT = $pearDB->query($query); + while ($data = $DBRESULT->fetchRow()) { + $data["service_description"] = str_replace("#S#", "/", $data["service_description"]); + $data["service_description"] = str_replace("#BS#", "\\", $data["service_description"]); + $selection[$data["service_description"]] = $data["service_id"]; + } + $DBRESULT->free(); + unset($data); + + $res = $pearDB->query("SELECT FOUND_ROWS() as numrows"); + $row = $res->fetchRow(); + $rows = $row['numrows']; + + /* + * Create Diff + */ + $tpl->assign("host_name", _("Services Templates")); + + $diff = array(); + $templateHostArray = array(); + foreach ($selection as $key => $value) { + $tplStr = ""; + $tplArr = $proc->getMyServiceTemplateModels($value); + if ($proc->serviceTemplateHasProcedure($key, $tplArr) == true) { + $diff[$key] = 1; + } else { + $diff[$key] = 0; + } + + if (isset($_REQUEST['searchTemplatesWithNoProcedure'])) { + if ($diff[$key] == 1 || $proc->serviceTemplateHasProcedure($key, $tplArr, PROCEDURE_INHERITANCE_MODE) == true) { + $rows--; + unset($diff[$key]); + continue; + } + } elseif (isset($_REQUEST['searchHasNoProcedure'])) { + if ($diff[$key] == 1) { + $rows--; + unset($diff[$key]); + continue; + } + } + + if (count($tplArr)) { + $firstTpl = 1; + foreach ($tplArr as $key1 => $value1) { + if ($firstTpl) { + $tplStr .= "<a href='".$WikiURL."/index.php?title=Service-Template:$value1' target='_blank'>".$value1."</a>"; + $firstTpl = 0; + } else { + $tplStr .= " | <a href='".$WikiURL."/index.php?title=Service-Template:$value1' target='_blank'>".$value1."</a>"; + } + } + } + $templateHostArray[$key] = $tplStr; + unset($tplStr); + } + + include("./include/common/checkPagination.php"); + + if (isset($templateHostArray)) + $tpl->assign("templateHostArray", $templateHostArray); + $tpl->assign("WikiURL", $WikiURL); + $tpl->assign("content", $diff); + $tpl->assign("status", $status); + $tpl->assign("selection", 3); + $tpl->assign("icone", $proc->getIconeList()); + + /* + * Send template in order to open + */ + + /* + * translations + */ + $tpl->assign("status_trans", _("Status")); + $tpl->assign("actions_trans", _("Actions")); + $tpl->assign("template_trans", _("Template")); + + /* + * Template + */ + $tpl->assign("lineTemplate", $line); + $tpl->assign('limit', $limit); + + $tpl->assign('order', $order); + $tpl->assign('orderby', $orderby); + $tpl->assign('defaultOrderby', 'service_description'); + + /* + * Apply a template definition + */ + + $tpl->display($modules_path . "templates/display.ihtml"); + +?> diff --git a/www/include/configuration/configKnowledge/display-services.php b/www/include/configuration/configKnowledge/display-services.php new file mode 100644 index 0000000000000000000000000000000000000000..24a53442702190cab2fe8480edbad36550fb9436 --- /dev/null +++ b/www/include/configuration/configKnowledge/display-services.php @@ -0,0 +1,286 @@ +<?php +/* + * Copyright 2005-2009 MERETHIS + * 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 MERETHIS + * 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 MERETHIS choice, provided that + * MERETHIS 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 + * + * SVN : $URL: http://svn.centreon.com/trunk/centreon/www/include/monitoring/status/Services/service.php $ + * SVN : $Id: service.php 8549 2009-07-01 16:20:26Z shotamchay $ + * + */ + +if (!isset($oreon)) { + exit(); +} + +$modules_path = $centreon_path . "www/include/configuration/configKnowledge/"; +require_once $modules_path . 'header.php'; +require_once $modules_path . 'functions.php'; + + +if (!isset($limit) || !$limit) { + $limit = $oreon->optGen["maxViewConfiguration"]; +} + +if (isset($_POST['search'])) { + $_GET['search'] = $_POST['search']; +} + +if (isset($_POST['num']) && $_POST['num'] == 0) { + $_GET['num'] = 0; +} + +if (isset($_POST['searchHost'])) { + if (!isset($_POST['searchHasNoProcedure']) && isset($_GET['searchHasNoProcedure'])) { + unset($_REQUEST['searchHasNoProcedure']); + } + if (!isset($_POST['searchTemplatesWithNoProcedure']) && isset($_GET['searchTemplatesWithNoProcedure'])) { + unset($_REQUEST['searchTemplatesWithNoProcedure']); + } +} + +$order = "ASC"; +$orderby = "host_name"; +if (isset($_REQUEST['order']) && $_REQUEST['order'] && isset($_REQUEST['orderby']) && $_REQUEST['orderby']) { + $order = $_REQUEST['order']; + $orderby = $_REQUEST['orderby']; +} + +require_once "./include/common/autoNumLimit.php"; + +/* + * Add paths + */ +set_include_path(get_include_path() . PATH_SEPARATOR . $modules_path ); + +/* + * Pear library + */ +require_once "HTML/QuickForm.php"; +require_once "HTML/QuickForm/advmultiselect.php"; +require_once "HTML/QuickForm/Renderer/ArraySmarty.php"; + +require_once $centreon_path."/config/wiki.conf.php"; +require_once $centreon_path."/www/class/centreon-knowledge/procedures_DB_Connector.class.php"; +require_once $centreon_path."/www/class/centreon-knowledge/procedures.class.php"; + +/* + * Smarty template Init + */ +$tpl = new Smarty(); +$tpl = initSmartyTpl($modules_path, $tpl); + +$currentPage = "services"; +require_once $modules_path.'search.php'; + +/* + * Init Status Template + */ +$status = array( + 0 => "<font color='orange'> " . _("No wiki page defined") . " </font>", + 1 => "<font color='green'> " . _("Wiki page defined") . " </font>" +); +$line = array(0 => "list_one", 1 => "list_two"); + +$proc = new procedures(3, $db_name, $db_user, $db_host, $db_password, $pearDB, $db_prefix); +$proc->setHostInformations(); +$proc->setServiceInformations(); + +$query = " SELECT SQL_CALC_FOUND_ROWS t1.* FROM ("; +$query .= " SELECT s.service_id, s.service_description, h.host_name, h.host_id "; +$query .= " FROM service s "; +$query .= " LEFT JOIN host_service_relation hsr ON hsr.service_service_id = s.service_id "; +$query .= " RIGHT JOIN host h ON h.host_id = hsr.host_host_id "; +$query .= " WHERE s.service_register = '1' "; +if (isset($_REQUEST['searchHost']) && $_REQUEST['searchHost']) { + $query .= " AND h.host_name LIKE '%" . $pearDB->escape($_REQUEST['searchHost']) . "%' "; +} +if (isset($_REQUEST['searchHostgroup']) && $_REQUEST['searchHostgroup']) { + $query .= " AND hsr.host_host_id IN "; + $query .= " (SELECT host_host_id FROM hostgroup_relation hgr + WHERE hgr.hostgroup_hg_id = " . $pearDB->escape($_REQUEST['searchHostgroup']) . ") "; +} +if (isset($_REQUEST['searchServicegroup']) && $_REQUEST['searchServicegroup']) { + $query .= " AND s.service_id IN "; + $query .= " (SELECT service_service_id FROM servicegroup_relation + WHERE servicegroup_sg_id = " . $pearDB->escape($_REQUEST['searchServicegroup']) . ") "; +} +if (isset($_REQUEST['searchPoller']) && $_REQUEST['searchPoller']) { + $query .= " AND hsr.host_host_id IN "; + $query .= " (SELECT host_host_id FROM ns_host_relation + WHERE nagios_server_id = " . $pearDB->escape($_REQUEST['searchPoller']) . ") "; +} +if (isset($_REQUEST['searchService']) && $_REQUEST['searchService']) { + $query .= "AND s.service_description LIKE '%" . $_REQUEST['searchService'] . "%' "; +} + +$query .= " UNION "; +$query .= " SELECT s2.service_id, s2.service_description, h2.host_name, h2.host_id "; +$query .= " FROM service s2 "; +$query .= " LEFT JOIN host_service_relation hsr2 ON hsr2.service_service_id = s2.service_id "; +$query .= " RIGHT JOIN hostgroup_relation hgr ON hgr.hostgroup_hg_id = hsr2.hostgroup_hg_id "; +$query .= " LEFT JOIN host h2 ON h2.host_id = hgr.host_host_id "; +$query .= " WHERE s2.service_register = '1' "; +if (isset($_REQUEST['searchHostgroup']) && $_REQUEST['searchHostgroup']) { + $query .= " AND (h2.host_id IN "; + $query .= " (SELECT host_host_id FROM hostgroup_relation hgr + WHERE hgr.hostgroup_hg_id = " . $pearDB->escape($_REQUEST['searchHostgroup']) . ") "; + $query .= " OR hgr.hostgroup_hg_id = " . $pearDB->escape($_REQUEST['searchHostgroup']) . ")"; +} +if (isset($_REQUEST['searchHost']) && $_REQUEST['searchHost']) { + $query .= " AND h2.host_name LIKE '%" . $pearDB->escape($_REQUEST['searchHost']) . "%' "; +} +if (isset($_REQUEST['searchServicegroup']) && $_REQUEST['searchServicegroup']) { + $query .= " AND s2.service_id IN "; + $query .= " (SELECT service_service_id FROM servicegroup_relation + WHERE servicegroup_sg_id = " . $pearDB->escape($_REQUEST['searchServicegroup']) . ") "; +} +if (isset($_REQUEST['searchPoller']) && $_REQUEST['searchPoller']) { + $query .= " AND h2.host_id IN "; + $query .= " (SELECT host_host_id FROM ns_host_relation + WHERE nagios_server_id = " . $pearDB->escape($_REQUEST['searchPoller']) . ") "; +} +if (isset($_REQUEST['searchService']) && $_REQUEST['searchService']) { + $query .= "AND s2.service_description LIKE '%" . $_REQUEST['searchService'] . "%' "; +} +$query .= " ) as t1 "; +$query .= " ORDER BY $orderby $order LIMIT " . $num * $limit . ", " . $limit; + +$res = $pearDB->query($query); + +$serviceList = array(); +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( + "id" => $row['service_id'], + "svc" => $row['service_description'], + "h" => $row['host_name'] + ); + } +} + +$res = $pearDB->query("SELECT FOUND_ROWS() as numrows"); +$row = $res->fetchRow(); +$rows = $row['numrows']; + +/* + * Create Diff + */ +$tpl->assign("host_name", _("Hosts")); +$tpl->assign("p", 61002); +$tpl->assign("service_description", _("Services")); +$selection = $proc->serviceList; + +$diff = array(); +$templateHostArray = array(); + +foreach ($serviceList as $key => $value) { + $tplStr = ""; + $tplArr = $proc->getMyServiceTemplateModels($value['id']); + if ($proc->serviceHasProcedure($key, $tplArr) == true) { + $diff[$key] = 1; + } else { + $diff[$key] = 0; + } + + if (isset($_REQUEST['searchTemplatesWithNoProcedure'])) { + if ($diff[$key] == 1 || $proc->serviceHasProcedure($key, $tplArr, PROCEDURE_INHERITANCE_MODE) == true) { + $rows--; + unset($diff[$key]); + unset($serviceList[$key]); + continue; + } + } elseif (isset($_REQUEST['searchHasNoProcedure'])) { + if ($diff[$key] == 1) { + $rows--; + unset($diff[$key]); + unset($serviceList[$key]); + continue; + } + } + + if (count($tplArr)) { + $firstTpl = 1; + foreach ($tplArr as $key1 => $value1) { + if ($firstTpl) { + $firstTpl = 0; + } else { + $tplStr .= " | "; + } + $tplStr .= "<a href='" . $WikiURL . "/index.php?title=Service:$value1' target='_blank'>" . $value1 . "</a>"; + } + } + $templateHostArray[$key] = $tplStr; + unset($tplStr); + $i++; +} + +include("./include/common/checkPagination.php"); + +if (isset($templateHostArray)) { + $tpl->assign("templateHostArray", $templateHostArray); +} +$tpl->assign("WikiURL", $WikiURL); +$tpl->assign("content", $diff); +$tpl->assign("services", $serviceList); +$tpl->assign("status", $status); +$tpl->assign("selection", 1); +$tpl->assign("icone", $proc->getIconeList()); + +/* + * Send template in order to open + */ + +/* + * translations + */ +$tpl->assign("status_trans", _("Status")); +$tpl->assign("actions_trans", _("Actions")); +$tpl->assign("template_trans", _("Template")); + +/* + * Template + */ +$tpl->assign("lineTemplate", $line); +$tpl->assign('limit', $limit); + +$tpl->assign('order', $order); +$tpl->assign('orderby', $orderby); +$tpl->assign('defaultOrderby', 'host_name'); + +/* + * Apply a template definition + */ + +$tpl->display($modules_path . "templates/display.ihtml"); + +?> diff --git a/www/include/configuration/configKnowledge/functions.php b/www/include/configuration/configKnowledge/functions.php new file mode 100644 index 0000000000000000000000000000000000000000..746623f2659695bad507525684ca34e17250d19a --- /dev/null +++ b/www/include/configuration/configKnowledge/functions.php @@ -0,0 +1,27 @@ +<?php +/** + * CENTREON + * + * Source Copyright 2005-2015 CENTREON + * + * Unauthorized reproduction, copy and distribution + * are not allowed. + * + * For more information : contact@centreon.com + * + */ + +function versionCentreon($pearDB) { + if (is_null($pearDB)) { + return; + } + + $query = 'SELECT `value` FROM `informations` WHERE `key` = "version"'; + $res = $pearDB->query($query); + if (PEAR::isError($res)) { + return null; + } + $row = $res->fetchRow(); + return $row['value']; +} + diff --git a/www/include/configuration/configKnowledge/header.php b/www/include/configuration/configKnowledge/header.php new file mode 100644 index 0000000000000000000000000000000000000000..871cc672cc9c1dbfdd432029b641b5cd51347df3 --- /dev/null +++ b/www/include/configuration/configKnowledge/header.php @@ -0,0 +1,11 @@ +<?php +if (zend_loader_file_encoded() == true) { + $licenseValidity = zend_loader_install_license ($centreon_path . "www/modules/centreon-knowledgebase/license/merethis_lic.zl", true); + if ($licenseValidity == false) { + echo "<div class='msg' align='center'>"._("The license is not valid. Please contact your administator for more information.")."</div>"; + echo "</td></tr></table></div>"; + include("./footer.php"); + exit(0); + } +} +?> \ No newline at end of file diff --git a/www/include/configuration/configKnowledge/pagination.php b/www/include/configuration/configKnowledge/pagination.php new file mode 100644 index 0000000000000000000000000000000000000000..e213d84bb444cad279dd1145c11a9c275db7d663 --- /dev/null +++ b/www/include/configuration/configKnowledge/pagination.php @@ -0,0 +1,231 @@ +<?php +/* + * Copyright 2005-2015 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 MERETHIS + * 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 MERETHIS choice, provided that + * MERETHIS 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 + * + * SVN : $URL: http://svn.centreon.com/branches/centreon-2.1/www/include/common/pagination.php $ + * SVN : $Id: pagination.php 10473 2010-05-19 21:25:56Z jmathis $ + * + */ + global $oreon; + + if (!isset($oreon)) { + exit(); + } + + global $bNewChart, $num, $limit, $search, $url, $pearDB, $search_type_service, $search_type_host, $host_name, $rows, $p, $gopt, $pagination, $poller, $order, $orderby; + + isset($_GET["type"]) ? $type = $_GET["type"] : $stype = NULL; + isset($_GET["o"]) ? $o = $_GET["o"] : $o = NULL; + + $searchString = ""; + if (isset($_REQUEST)) { + foreach ($_REQUEST as $key => $value) { + if (preg_match("/^search/", $key)) { + $searchString .= "&$key=$value"; + } + } + } + + + if (isset($_GET["num"])) { + $num = $_GET["num"]; + } else if (!isset($_GET["num"]) && isset($oreon->historyPage[$url]) && $oreon->historyPage[$url]) { + $num = $oreon->historyPage[$url]; + } else { + $num = 0; + } + + $num = mysql_real_escape_string($num); + + $tab_order = array("sort_asc" => "sort_desc", "sort_desc" => "sort_asc"); + + if (isset($_GET["search_type_service"])){ + $search_type_service = $_GET["search_type_service"]; + $oreon->search_type_service = $_GET["search_type_service"]; + } else if (isset($oreon->search_type_service)) { + $search_type_service = $oreon->search_type_service; + } else { + $search_type_service = NULL; + } + + if (isset($_GET["search_type_host"])){ + $search_type_host = $_GET["search_type_host"]; + $oreon->search_type_host = $_GET["search_type_host"]; + } else if (isset($oreon->search_type_host)) { + $search_type_host = $oreon->search_type_host; + } else { + $search_type_host = NULL; + } + + if (!isset($_GET["search_type_host"]) && !isset($oreon->search_type_host) && !isset($_GET["search_type_service"]) && !isset($oreon->search_type_service)){ + $search_type_host = 1; + $oreon->search_type_host = 1; + $search_type_service = 1; + $oreon->search_type_service = 1; + } + + $url_var = ""; + $url_var .= "&search_type_service=" . $search_type_service; + $url_var .= "&search_type_host=" . $search_type_host; + + if (isset($_GET["sort_types"])){ + $url_var .= "&sort_types=".$_GET["sort_types"]; + $sort_type = $_GET["sort_types"]; + } + + /* + * Smarty template Init + */ + $tpl = initSmartyTpl($path, new Smarty(), "./modules/centreon-knowledgebase/core/display/"); + + $page_max = ceil($rows / $limit); + if ($num >= $page_max && $rows) { + $num = $page_max - 1; + } + + $pageArr = array(); + $istart = 0; + for ($i = 5, $istart = $num; $istart && $i > 0; $i--) { + $istart--; + } + + for ($i2 = 0, $iend = $num; ( $iend < ($rows / $limit - 1)) && ( $i2 < (5 + $i)); $i2++) { + $iend++; + } + + + if ($rows != 0) { + + for ($i = $istart; $i <= $iend; $i++){ + $pageArr[$i] = array("url_page"=>"./main.php?p=".$p."&order=".$order."&orderby=".$orderby."&num=$i&limit=".$limit.$searchString."&type=".$type."&o=" . $o . $url_var, "label_page"=>"<b>".($i +1)."</b>","num"=> $i); + } + + + if ($i > 1) { + $tpl->assign("pageArr", $pageArr); + } + + $tpl->assign("num", $num); + $tpl->assign("first", _("First page")); + $tpl->assign("previous", _("Previous page")); + $tpl->assign("next", _("Next page")); + $tpl->assign("last", _("Last page")); + + if (($prev = $num - 1) >= 0) { + $tpl->assign('pagePrev', ("./main.php?p=".$p."&order=".$order."&orderby=".$orderby."&num=$prev&limit=".$limit.$searchString."&type=".$type."&o=" . $o .$url_var)); + } + + if (($next = $num + 1) < ($rows/$limit)) { + $tpl->assign('pageNext', ("./main.php?p=".$p."&order=".$order."&orderby=".$orderby."&num=$next&limit=".$limit.$searchString."&type=".$type."&o=" . $o .$url_var)); + } + + $pageNumber = ceil($rows / $limit); + if (($rows / $limit) > 0) { + $tpl->assign('pageNumber', ($num +1)."/".$pageNumber); + } else { + $tpl->assign('pageNumber', ($num)."/".$pageNumber); + } + + if ($page_max > 5 && $num != 0) { + $tpl->assign('firstPage', ("./main.php?p=".$p."&order=".$order."&orderby=".$orderby."&num=0&limit=".$limit.$searchString."&type=".$type."&o=" . $o .$url_var)); + } + + if ($page_max > 5 && $num != ($pageNumber-1)) { + $tpl->assign('lastPage', ("./main.php?p=".$p."&order=".$order."&orderby=".$orderby."&num=".($pageNumber-1)."&limit=".$limit.$searchString."&type=".$type."&o=" . $o .$url_var)); + } + + /* + * Select field to change the number of row on the page + */ + for ($i = 10; $i <= 100; $i = $i +10) { + $select[$i]=$i; + } + + if (isset($gopt[$pagination]) && $gopt[$pagination]) { + $select[$gopt[$pagination]] = $gopt[$pagination]; + } + + if (isset($rows) && $rows) { + $select[$rows] = $rows; + } + + ksort($select); + } + + ?><script type="text/javascript"> + function setL(_this){ + var _l = document.getElementsByName('l'); + document.forms['form'].elements['limit'].value = _this; + _l[0].value = _this; + _l[1].value = _this; + } + </SCRIPT> + <?php + $form = new HTML_QuickForm('select_form', 'GET', "?p=".$p."&search_type_service=" . $search_type_service."&search_type_host=" . $search_type_host); + $selLim =& $form->addElement('select', 'l', _("Rows"), $select, array("onChange" => "setL(this.value); this.form.submit()")); + $selLim->setSelected($limit); + + /* + * Element we need when we reload the page + */ + $form->addElement('hidden', 'p'); + $form->addElement('hidden', 'search'); + $form->addElement('hidden', 'num'); + $form->addElement('hidden', 'order'); + $form->addElement('hidden', 'type'); + $form->addElement('hidden', 'sort_types'); + $form->setDefaults(array("p" => $p, "search" => $search, "num"=>$num)); + + /* + * Init QuickForm + */ + $renderer =& new HTML_QuickForm_Renderer_ArraySmarty($tpl); + $form->accept($renderer); + + isset($_GET["host_name"]) ? $host_name = $_GET["host_name"] : $host_name = NULL; + isset($_GET["status"]) ? $status = $_GET["status"] : $status = NULL; + + $tpl->assign("host_name", $host_name); + $tpl->assign("status", $status); + $tpl->assign("limite", $limite); + $tpl->assign("begin", $num); + $tpl->assign("end", $limit); + $tpl->assign("pagin_page", _("Page")); + $tpl->assign("order", $_GET["order"]); + $tpl->assign("tab_order", $tab_order); + $tpl->assign('form', $renderer->toArray()); + if ($bNewChart) { + $tpl->display("templates/pagination-2.7.ihtml"); + } else { + $tpl->display("templates/pagination.ihtml"); + } +?> diff --git a/www/include/configuration/configKnowledge/popup.php b/www/include/configuration/configKnowledge/popup.php new file mode 100644 index 0000000000000000000000000000000000000000..51493ec0dcae634cb1c1fc0a3899ea3b44a855c5 --- /dev/null +++ b/www/include/configuration/configKnowledge/popup.php @@ -0,0 +1,72 @@ +<?php +/* + * Copyright 2005-2009 MERETHIS + * 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 MERETHIS + * 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 MERETHIS choice, provided that + * MERETHIS 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 + * + * SVN : $URL: http://svn.centreon.com/trunk/centreon/www/include/monitoring/status/Services/service.php $ + * SVN : $Id: service.php 8549 2009-07-01 16:20:26Z shotamchay $ + * + */ + + /* + * TODO Security + */ + + /* + * Add paths + */ + require_once "../../wiki.conf.php"; + require_once "$etc_centreon/centreon.conf.php"; + + require_once $centreon_path.'www/modules/centreon-knowledgebase/core/header.php'; + + set_include_path(get_include_path() . PATH_SEPARATOR . $centreon_path . "www/modules/centreon-knowledgebase/". PATH_SEPARATOR . $centreon_path."www/class/"); + + require_once "DB.php"; + + require_once "wiki.conf.php"; + require_once "core/class/procedures_DB_Connector.class.php"; + require_once "core/class/procedures.class.php"; + require_once "centreonLog.class.php"; + require_once "centreonDB.class.php"; + + /* + * Connect to centreon DB + */ + $pearDB = new CentreonDB(); + + $proc = new procedures(3, $db_name, $db_user, $db_host, $db_password, $pearDB, $db_prefix); + + if (isset($_GET["template"]) && $_GET["template"] != "") + $proc->duplicate(htmlentities($_GET["template"], ENT_QUOTES), htmlentities($_GET["object"], ENT_QUOTES), htmlentities($_GET["type"], ENT_QUOTES)); + + header("Location: $WikiURL/index.php?title=".htmlentities($_GET["object"], ENT_QUOTES)."&action=edit"); +?> \ No newline at end of file diff --git a/www/include/configuration/configKnowledge/popup_form.php b/www/include/configuration/configKnowledge/popup_form.php new file mode 100644 index 0000000000000000000000000000000000000000..959e397ff9773e9be04bf6ce09621d63aab9404a --- /dev/null +++ b/www/include/configuration/configKnowledge/popup_form.php @@ -0,0 +1,156 @@ +<?php +/* + * Copyright 2005-2009 MERETHIS + * 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 MERETHIS + * 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 MERETHIS choice, provided that + * MERETHIS 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 + * + * SVN : $URL: http://svn.centreon.com/trunk/centreon/www/include/monitoring/status/Services/service.php $ + * SVN : $Id: service.php 8549 2009-07-01 16:20:26Z shotamchay $ + * + */ + + require_once "../../wiki.conf.php"; + require_once "$etc_centreon/centreon.conf.php"; + + set_include_path(get_include_path() . PATH_SEPARATOR . $centreon_path . "www/modules/centreon-knowledgebase/".PATH_SEPARATOR . $centreon_path."www/"); + + require_once "DB.php"; + require_once "include/common/common-Func.php"; + + require_once "class/centreonLog.class.php"; + require_once "class/centreonDB.class.php"; + + $pearDB = new CentreonDB(); + if (isset($_GET["session_id"]) && $_GET["session_id"] != "") { + $path = "core/display/"; + require_once "wiki.conf.php"; + require_once "core/class/procedures_DB_Connector.class.php"; + require_once "core/class/procedures.class.php"; + + /* + * Init procedures Object + */ + $proc = new procedures(3, $db_name, $db_user, $db_host, $db_password, $pearDB); + $proc->setHostInformations(); + $proc->setServiceInformations(); + $wikiContent = $proc->getProcedures(); + + if ($_GET["type"] == 0) { + $diff = $proc->getDiff($proc->hostTplList, 2); + $hostTplListForAdd = array(NULL => NULL); + foreach ($diff as $key => $value) + if ($value) + $hostTplListForAdd[trim($key)] = $value; + + /* + * HTML + */ + print "<form method='GET' action='./popup.php'>"; + print "Based Template : "; + print "<select name='template'>"; + foreach ($hostTplListForAdd as $key => $value) { + print "<option value='$key'>$key</option>"; + } + print "</select>"; + print "<input type='hidden' name='object' value='".htmlentities($_GET["type"], ENT_QUOTES)."' />"; + print "<input type='hidden' name='object' value='".htmlentities($_GET["object"], ENT_QUOTES)."' />"; + print "<input type='submit' name='create' value='"._("Create wiki page")."' />"; + print "</form>"; + } else if ($_GET["type"] == 2) { + $diff = $proc->getDiff($proc->hostTplList, 2); + $hostTplListForAdd = array(NULL => NULL); + foreach ($diff as $key => $value) { + if ($value) + $hostTplListForAdd["H-TPL-".trim($key)] = $value; + } + /* + * HTML + */ + print "<form method='GET' action='./popup.php'>"; + print "Based Template : "; + print "<select name='template'>"; + foreach ($hostTplListForAdd as $key => $value) { + print "<option value='$key'>$key</option>"; + } + print "</select>"; + print "<input type='hidden' name='object' value='".htmlentities($_GET["type"], ENT_QUOTES)."' />"; + print "<input type='hidden' name='object' value='".htmlentities($_GET["object"], ENT_QUOTES)."' />"; + print "<input type='submit' name='create' value='"._("Create wiki page")."' />"; + print "</form>"; + } else if ($_GET["type"] == 1) { + $diff = $proc->getDiff($proc->serviceTplList, 3); + $svcListForAdd = array(NULL => NULL); + foreach ($diff as $key => $value) + if ($value) + $svcListForAdd[$key] = $value; + + /* + * HTML + */ + print "<form method='GET' action='./popup.php'>"; + print "Based Template : "; + print "<select name='template'>"; + foreach ($svcListForAdd as $key => $value) { + print "<option value='$key'>$key</option>"; + } + print "</select>"; + print "<input type='hidden' name='object' value='".htmlentities($_GET["type"], ENT_QUOTES)."' />"; + print "<input type='hidden' name='object' value='".htmlentities($_GET["object"], ENT_QUOTES)."' />"; + print "<input type='submit' name='create' value='"._("Create wiki page")."' />"; + print "</form>"; + + } else if ($_GET["type"] == 3) { + $diff = $proc->getDiff($proc->serviceTplList, 3); + $svcTplListForAdd = array(NULL => NULL); + foreach ($diff as $key => $value) + if ($value) + $svcTplListForAdd[$key] = $value; + + /* + * HTML + */ + print "<form method='GET' action='./popup.php'>"; + print "Based Template : "; + print "<select name='template'>"; + foreach ($svcTplListForAdd as $key => $value) { + print "<option value='$key'>$key</option>"; + } + print "</select>"; + print "<input type='hidden' name='object' value='".htmlentities($_GET["type"], ENT_QUOTES)."' />"; + print "<input type='hidden' name='object' value='".htmlentities($_GET["object"], ENT_QUOTES)."' />"; + print "<input type='submit' name='create' value='"._("Create wiki page")."' />"; + print "</form>"; + } + } else { + print "No session open or session id not known"; + exit(); + } + +?> \ No newline at end of file diff --git a/www/include/configuration/configKnowledge/search.php b/www/include/configuration/configKnowledge/search.php new file mode 100644 index 0000000000000000000000000000000000000000..7bfad2167f8397ffca7de27823fd9e5b34a1236b --- /dev/null +++ b/www/include/configuration/configKnowledge/search.php @@ -0,0 +1,157 @@ +<?php +/* + * Copyright 2005-2011 MERETHIS + * 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 MERETHIS + * 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 MERETHIS choice, provided that + * MERETHIS 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 + * + */ + +if (!isset($oreon)) { + exit; +} + +$searchOptions = array( 'host' => 0, + 'service' => 0, + 'hostTemplate' => 0, + 'serviceTemplate' => 0, + 'poller' => 0, + 'hostgroup' => 0, + 'servicegroup' => 0, + 'hasNoProcedure' => 0, + 'templatesWithNoProcedure' => 0 + ); + +$labels = array( 'host' => _("Host"), + 'service' => _("Service"), + 'hostTemplate' => _("Host Template"), + 'serviceTemplate' => _("Service Template"), + 'poller' => _("Poller"), + 'hostgroup' => _("Hostgroup"), + 'servicegroup' => _("Servicegroup"), + 'hasNoProcedure' => _("Show wiki pageless only"), + 'templatesWithNoProcedure' => _("Show wiki pageless only - inherited templates included"), + 'search' => _("Search") + ); + +if ($currentPage == "hosts") { + $searchOptions['host'] = 1; + $searchOptions['poller'] = 1; + $searchOptions['hostgroup'] = 1; + $searchOptions['hasNoProcedure'] = 1; + $searchOptions['templatesWithNoProcedure'] = 1; +} elseif ($currentPage == "services") { + $searchOptions['host'] = 1; + $searchOptions['service'] = 1; + $searchOptions['poller'] = 1; + $searchOptions['hostgroup'] = 1; + $searchOptions['servicegroup'] = 1; + $searchOptions['hasNoProcedure'] = 1; + $searchOptions['templatesWithNoProcedure'] = 1; +} elseif ($currentPage == "hostTemplates") { + $searchOptions['hostTemplate'] = 1; + $searchOptions['hasNoProcedure'] = 1; + $searchOptions['templatesWithNoProcedure'] = 1; +} elseif ($currentPage == "serviceTemplates") { + $searchOptions['serviceTemplate'] = 1; + $searchOptions['hasNoProcedure'] = 1; + $searchOptions['templatesWithNoProcedure'] = 1; +} + +$tpl->assign('searchHost', isset($_REQUEST['searchHost']) ? $_REQUEST['searchHost'] : ""); +$tpl->assign('searchService', isset($_REQUEST['searchService']) ? $_REQUEST['searchService'] : ""); +$tpl->assign('searchHostTemplate', isset($_REQUEST['searchHostTemplate']) ? $_REQUEST['searchHostTemplate'] : ""); +$tpl->assign('searchServiceTemplate', isset($_REQUEST['searchServiceTemplate']) ? $_REQUEST['searchServiceTemplate'] : ""); + +$checked = ""; +if (isset($_REQUEST['searchHasNoProcedure'])) { + $checked = 'checked'; +} +$tpl->assign('searchHasNoProcedure', $checked); + +$checked2 = ""; +if (isset($_REQUEST['searchTemplatesWithNoProcedure'])) { + $checked2 = 'checked'; +} +$tpl->assign('searchTemplatesWithNoProcedure', $checked2); + + +/** + * Get Poller List + */ +if ($searchOptions['poller']) { + $query = "SELECT id, name FROM nagios_server ORDER BY name"; + $res = $pearDB->query($query); + $searchPoller = "<option value='0'></option>"; + while ($row = $res->fetchRow()) { + if (isset($_REQUEST['searchPoller']) && $row['id'] == $_REQUEST['searchPoller']) { + $searchPoller .= "<option value='".$row['id']."' selected>" . $row['name'] . "</option>"; + } else { + $searchPoller .= "<option value='".$row['id']."'>" .$row['name']. "</option>"; + } + } + $tpl->assign('searchPoller', $searchPoller); +} + +/** + * Get Hostgroup List + */ +if ($searchOptions['hostgroup']) { + $query = "SELECT hg_id, hg_name FROM hostgroup ORDER BY hg_name"; + $res = $pearDB->query($query); + $searchHostgroup = "<option value='0'></option>"; + while ($row = $res->fetchRow()) { + if (isset($_REQUEST['searchHostgroup']) && $row['hg_id'] == $_REQUEST['searchHostgroup']) { + $searchHostgroup .= "<option value ='".$row['hg_id']."' selected>" . $row['hg_name'] . "</option>"; + } else { + $searchHostgroup .= "<option value ='".$row['hg_id']."'>" . $row['hg_name'] . "</option>"; + } + } + $tpl->assign('searchHostgroup', $searchHostgroup); +} + +/** + * Get Servicegroup List + */ +if ($searchOptions['servicegroup']) { + $query = "SELECT sg_id, sg_name FROM servicegroup ORDER BY sg_name"; + $res = $pearDB->query($query); + $searchServicegroup = "<option value='0'></option>"; + while ($row = $res->fetchRow()) { + if (isset($_REQUEST['searchServicegroup']) && $row['sg_id'] == $_REQUEST['searchServicegroup']) { + $searchServicegroup .= "<option value ='".$row['sg_id']."' selected>" . $row['sg_name'] . "</option>"; + } else { + $searchServicegroup .= "<option value ='".$row['sg_id']."'>" . $row['sg_name'] . "</option>"; + } + } + $tpl->assign('searchServicegroup', $searchServicegroup); +} + +$tpl->assign('labels', $labels); +$tpl->assign('searchOptions', $searchOptions); diff --git a/www/include/configuration/configKnowledge/templates/display.ihtml b/www/include/configuration/configKnowledge/templates/display.ihtml new file mode 100644 index 0000000000000000000000000000000000000000..c648943325a8114e450f1acd5c7238b3db5f6850 --- /dev/null +++ b/www/include/configuration/configKnowledge/templates/display.ihtml @@ -0,0 +1,199 @@ +<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('./modules/centreon-knowledgebase/core/display/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="./modules/centreon-knowledgebase/core/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="./modules/centreon-knowledgebase/core/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='./modules/centreon-knowledgebase/core/display/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'>View wiki page</a> + - + <a href="{$WikiURL}/index.php?title=Service:{$elem}&action=edit" target='_blank'>Edit wiki page</a> + - + <a href="{$WikiURL}/index.php?title=Service:{$elem}&action=history" target='_blank'>View History</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="./modules/centreon-knowledgebase/core/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='./modules/centreon-knowledgebase/core/display/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='./modules/centreon-knowledgebase/core/display/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='./modules/centreon-knowledgebase/core/display/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'>View wiki page</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> + + {elseif $selection == 2} + <a href="{$WikiURL}/index.php?title=Host-Template:{$elem}" target='_blank'>View wiki page</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> + + {else} + <a href="{$WikiURL}/index.php?title=Host:{$elem}" target='_blank'>View wiki page</a> + - + <a href="{$WikiURL}/index.php?title=Host:{$elem}&action=edit" target='_blank'>Edit wiki page</a> + - + <a href="{$WikiURL}/index.php?title=Host:{$elem}&action=history" target='_blank'>View History</a> + + {/if} + {/if} + </td> + </tr> + {php} $l++ ; {/php} + {/foreach} + {/if} + </table> + <table class="ToolbarTable table"> + <tr class="ToolbarTR"> + {php} + include('./modules/centreon-knowledgebase/core/display/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(); + } +</script> +{/literal} diff --git a/www/include/configuration/configKnowledge/templates/pagination-2.7.ihtml b/www/include/configuration/configKnowledge/templates/pagination-2.7.ihtml new file mode 100644 index 0000000000000000000000000000000000000000..eea67d5534cf4c50467facdb5037113ddc70262b --- /dev/null +++ b/www/include/configuration/configKnowledge/templates/pagination-2.7.ihtml @@ -0,0 +1,15 @@ +<td class="ToolbarPagination" align="center"> + {if $firstPage} <a href="{$firstPage}{if $host_name}&host_name={$host_name}{/if}"><img src="./img/icons/first_rewind.png" title='{$first}'></a>{/if} + {if $pagePrev} <a href="{$pagePrev}{if $host_name}&host_name={$host_name}{/if}"><img src="./img/icons/rewind.png" title='{$previous}'></a>{/if} + {foreach key=key item=item from=$pageArr } + {if $pageArr[$key].num != $num} + <a href="{$pageArr[$key].url_page}{if $host_name}&host_name={$host_name}{/if}" class="otherPageNumber">{$pageArr[$key].label_page}</a> + {else} + <b class="currentPageNumber">{$pageArr[$key].label_page}</b> + {/if} + {/foreach} + {if $pageNext} <a href="{$pageNext}{if $host_name}&host_name={$host_name}{/if}"><img src="./img/icons/fast_forward.png" title='{$next}'></a>{/if} + {if $lastPage} <a href="{$lastPage}{if $host_name}&host_name={$host_name}{/if}"><img src="./img/icons/end_forward.png" title='{$last}'></a>{/if} +</td> +<td class="Toolbar_pagelimit">{$form.l.html}</td> +{$form.hidden} diff --git a/www/include/configuration/configKnowledge/templates/pagination.ihtml b/www/include/configuration/configKnowledge/templates/pagination.ihtml new file mode 100644 index 0000000000000000000000000000000000000000..336eebf0a3ff547e776aa574b6132217d0ea39c8 --- /dev/null +++ b/www/include/configuration/configKnowledge/templates/pagination.ihtml @@ -0,0 +1,15 @@ +<td class="ToolbarPagination"> + {if $firstPage} <a href="{$firstPage}{if $host_name}&host_name={$host_name}{/if}"><img src="./img/icones/16x16/arrow_left_blue_double.gif" title='{$first}'></a>{/if} + {if $pagePrev} <a href="{$pagePrev}{if $host_name}&host_name={$host_name}{/if}"><img src="./img/icones/16x16/arrow_left_blue.gif" title='{$previous}'></a>{/if} + {foreach key=key item=item from=$pageArr } + {if $pageArr[$key].num != $num} + <a href="{$pageArr[$key].url_page}{if $host_name}&host_name={$host_name}{/if}" class="otherPageNumber">{$pageArr[$key].label_page}</a> + {else} + <b class="currentPageNumber">{$pageArr[$key].label_page}</b> + {/if} + {/foreach} + {if $pageNext} <a href="{$pageNext}{if $host_name}&host_name={$host_name}{/if}"><img src="./img/icones/16x16/arrow_right_blue.gif" title='{$next}'></a>{/if} + {if $lastPage} <a href="{$lastPage}{if $host_name}&host_name={$host_name}{/if}"><img src="./img/icones/16x16/arrow_right_blue_double.gif" title='{$last}'></a>{/if} +</td> +<td class="Toolbar_pagelimit">{$form.l.label}</b> {$form.l.html} {$pagin_page} {$pageNumber}</td> +{$form.hidden} \ No newline at end of file