PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/www/include/configuration/configServers/listServers.php

https://gitlab.com/florianocomercial/centreon
PHP | 283 lines | 188 code | 25 blank | 70 comment | 27 complexity | 6d2fc5cb0c02c7a0062b62073c7bc033 MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright 2005-2015 Centreon
  4. * Centreon is developped by : Julien Mathis and Romain Le Merlus under
  5. * GPL Licence 2.0.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU General Public License as published by the Free Software
  9. * Foundation ; either version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT ANY
  12. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  13. * PARTICULAR PURPOSE. See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, see <http://www.gnu.org/licenses>.
  17. *
  18. * Linking this program statically or dynamically with other modules is making a
  19. * combined work based on this program. Thus, the terms and conditions of the GNU
  20. * General Public License cover the whole combination.
  21. *
  22. * As a special exception, the copyright holders of this program give Centreon
  23. * permission to link this program with independent modules to produce an executable,
  24. * regardless of the license terms of these independent modules, and to copy and
  25. * distribute the resulting executable under terms of Centreon choice, provided that
  26. * Centreon also meet, for each linked independent module, the terms and conditions
  27. * of the license of that module. An independent module is a module which is not
  28. * derived from this program. If you modify this program, you may extend this
  29. * exception to your version of the program, but you are not obliged to do so. If you
  30. * do not wish to do so, delete this exception statement from your version.
  31. *
  32. * For more information : contact@centreon.com
  33. *
  34. */
  35. if (!isset($centreon)) {
  36. exit();
  37. }
  38. include("./include/common/autoNumLimit.php");
  39. /*
  40. * Init GMT class
  41. */
  42. $centreonGMT = new CentreonGMT($pearDB);
  43. $centreonGMT->getMyGMTFromSession(session_id(), $pearDB);
  44. $LCASearch = "";
  45. $search = '';
  46. if (isset($_POST['searchP']) && $_POST['searchP']) {
  47. $search = $_POST['searchP'];
  48. $LCASearch = " name LIKE '%".htmlentities($search, ENT_QUOTES, "UTF-8")."%'";
  49. }
  50. /*
  51. * nagios servers comes from DB
  52. */
  53. $nagios_servers = array();
  54. $nagios_restart = array();
  55. foreach ($serverResult as $nagios_server) {
  56. $nagios_servers[$nagios_server["id"]] = $nagios_server["name"];
  57. $nagios_restart[$nagios_server["id"]] = $nagios_server["last_restart"];
  58. }
  59. $pollerstring = implode(',', array_keys($nagios_servers));
  60. /*
  61. * Get information info RTM
  62. */
  63. $nagiosInfo = array();
  64. $DBRESULT = $pearDBO->query("SELECT start_time AS program_start_time, running AS is_currently_running, pid AS process_id, instance_id, name AS instance_name , last_alive FROM instances WHERE deleted = 0");
  65. while ($info = $DBRESULT->fetchRow()) {
  66. $nagiosInfo[$info["instance_name"]] = $info;
  67. }
  68. $DBRESULT->free();
  69. /*
  70. * Get Scheduler version
  71. */
  72. $DBRESULT = $pearDBO->query("SELECT DISTINCT instance_id, version AS program_version, engine AS program_name, name AS instance_name FROM instances WHERE deleted = 0 ");
  73. while ($info = $DBRESULT->fetchRow()) {
  74. if (isset($nagiosInfo[$info["instance_name"]])) {
  75. $nagiosInfo[$info["instance_name"]]["version"] = $info["program_name"] . " " . $info["program_version"];
  76. }
  77. }
  78. $DBRESULT->free();
  79. /*
  80. * Smarty template Init
  81. */
  82. $tpl = new Smarty();
  83. $tpl = initSmartyTpl($path, $tpl);
  84. /* Access level */
  85. ($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r';
  86. $tpl->assign('mode_access', $lvl_access);
  87. $generatePageId = 60902;
  88. $tpl->assign('mode_generate', $centreon->user->access->page($generatePageId));
  89. /*
  90. * start header menu
  91. */
  92. $tpl->assign("headerMenu_icone", "<img src='./img/icones/16x16/pin_red.gif'>");
  93. $tpl->assign("headerMenu_name", _("Name"));
  94. $tpl->assign("headerMenu_ip_address", _("IP Address"));
  95. $tpl->assign("headerMenu_localisation", _("Localhost"));
  96. $tpl->assign("headerMenu_is_running", _("Is running ?"));
  97. $tpl->assign("headerMenu_hasChanged", _("Conf Changed"));
  98. $tpl->assign("headerMenu_pid", _("PID"));
  99. $tpl->assign("headerMenu_version", _("Version"));
  100. $tpl->assign("headerMenu_startTime", _("Start time"));
  101. $tpl->assign("headerMenu_lastUpdateTime", _("Last Update"));
  102. $tpl->assign("headerMenu_status", _("Status"));
  103. $tpl->assign("headerMenu_default", _("Default"));
  104. $tpl->assign("headerMenu_options", _("Options"));
  105. /*
  106. * Poller list
  107. */
  108. $ACLString = $centreon->user->access->queryBuilder('WHERE', 'id', $pollerstring);
  109. $rq = "SELECT SQL_CALC_FOUND_ROWS id, name, ns_activate, ns_ip_address, localhost, is_default
  110. FROM `nagios_server` ".$ACLString." ".($LCASearch != '' ? ($ACLString != "" ? "AND " : "WHERE " ).$LCASearch : "")." ORDER BY name
  111. LIMIT ".$num * $limit.", ".$limit;
  112. $DBRESULT = $pearDB->query($rq);
  113. $rows = $pearDB->numberRows();
  114. include("./include/common/checkPagination.php");
  115. $form = new HTML_QuickForm('select_form', 'POST', "?p=".$p);
  116. /*
  117. * Different style between each lines
  118. */
  119. $style = "one";
  120. /*
  121. * Fill a tab with a mutlidimensionnal Array we put in $tpl
  122. */
  123. $elemArr = array();
  124. for ($i = 0; $config = $DBRESULT->fetchRow(); $i++) {
  125. $moptions = "";
  126. $selectedElements = $form->addElement('checkbox', "select[".$config['id']."]", null, '', array('id' => 'poller_' . $config['id']));
  127. if ($config["ns_activate"]) {
  128. $moptions .= "<a href='main.php?p=".$p."&server_id=".$config['id']."&o=u&limit=".$limit."&num=".$num."&search=".$search."'><img src='img/icons/disabled.png' class='ico-14 margin_right' border='0' alt='"._("Disabled")."'></a>";
  129. } else {
  130. $moptions .= "<a href='main.php?p=".$p."&server_id=".$config['id']."&o=s&limit=".$limit."&num=".$num."&search=".$search."'><img src='img/icons/enabled.png' class='ico-14 margin_right' border='0' alt='"._("Enabled")."'></a>";
  131. }
  132. $moptions .= "<input onKeypress=\"if(event.keyCode > 31 && (event.keyCode < 45 || event.keyCode > 57)) event.returnValue = false; if(event.which > 31 && (event.which < 45 || event.which > 57)) return false;\" maxlength=\"3\" size=\"3\" value='1' style=\"margin-bottom:0px;\" name='dupNbr[".$config['id']."]'></input>";
  133. if (!isset($nagiosInfo[$config["name"]]["is_currently_running"])) {
  134. $nagiosInfo[$config["name"]]["is_currently_running"] = 0;
  135. }
  136. /*
  137. * Manage flag for changes
  138. */
  139. $hasChanged = checkChangeState($config['id'], $nagios_restart[$config['id']]);
  140. /*
  141. * Manage flag for update time
  142. */
  143. $lastUpdateTimeFlag = 0;
  144. if (!isset($nagiosInfo[$config["name"]]["last_alive"])) {
  145. $lastUpdateTimeFlag = 0;
  146. } else if (time() - $nagiosInfo[$config["name"]]["last_alive"] > 10 * 60) {
  147. $lastUpdateTimeFlag = 1;
  148. }
  149. /*
  150. * Get cfg_id
  151. */
  152. $request = "SELECT nagios_id FROM cfg_nagios WHERE nagios_server_id = ".$config["id"]."";
  153. $DBRESULT2 = $pearDB->query($request);
  154. if ($DBRESULT2->numRows()) {
  155. $cfg_id = $DBRESULT2->fetchRow();
  156. } else {
  157. $cfg_id = -1;
  158. }
  159. $elemArr[$i] = array(
  160. "MenuClass" => "list_".$style,
  161. "RowMenu_select" => $selectedElements->toHtml(),
  162. "RowMenu_name" => $config["name"],
  163. "RowMenu_ip_address" => $config["ns_ip_address"],
  164. "RowMenu_link" => "?p=".$p."&o=c&server_id=".$config['id'],
  165. "RowMenu_localisation" => $config["localhost"] ? _("Yes") : "-",
  166. "RowMenu_is_running" => (isset($nagiosInfo[$config["name"]]["is_currently_running"]) && $nagiosInfo[$config["name"]]["is_currently_running"] == 1) ? _("Yes") : _("No"),
  167. "RowMenu_is_runningFlag" => $nagiosInfo[$config["name"]]["is_currently_running"],
  168. "RowMenu_is_default" => $config["is_default"] ? _("Yes") : _("No"),
  169. "RowMenu_hasChanged" => $hasChanged ? _("Yes") : _("No"),
  170. "RowMenu_hasChangedFlag" => $hasChanged,
  171. "RowMenu_version" => (isset($nagiosInfo[$config["name"]]["version"]) ? $nagiosInfo[$config["name"]]["version"] : _("N/A")),
  172. "RowMenu_startTime" => (isset($nagiosInfo[$config["name"]]["is_currently_running"]) && $nagiosInfo[$config["name"]]["is_currently_running"] == 1) ? $centreonGMT->getDate(_("d/m/Y H:i:s"), $nagiosInfo[$config["name"]]["program_start_time"]) : "-",
  173. "RowMenu_lastUpdateTime" => (isset($nagiosInfo[$config["name"]]["last_alive"]) && $nagiosInfo[$config["name"]]["last_alive"]) ? $centreonGMT->getDate(_("d/m/Y H:i:s"), $nagiosInfo[$config["name"]]["last_alive"]) : "-",
  174. "RowMenu_lastUpdateTimeFlag" => $lastUpdateTimeFlag,
  175. "RowMenu_pid" => (isset($nagiosInfo[$config["name"]]["is_currently_running"]) && $nagiosInfo[$config["name"]]["is_currently_running"] == 1) ? $nagiosInfo[$config["name"]]["process_id"] : "-",
  176. "RowMenu_status" => $config["ns_activate"] ? _("Enabled") : _("Disabled"),
  177. "RowMenu_statusVal" => $config["ns_activate"],
  178. "RowMenu_cfg_id" => ($cfg_id == -1) ? "" : $cfg_id['nagios_id'],
  179. "RowMenu_options" => $moptions);
  180. $style != "two" ? $style = "two" : $style = "one";
  181. }
  182. $tpl->assign("elemArr", $elemArr);
  183. $tpl->assign("notice", _("Only services and hosts are taken in account in order to calculate this status. If you modify a template, it won't tell you the configuration had changed."));
  184. /*
  185. * Different messages we put in the template
  186. */
  187. $tpl->assign('msg', array ("addL"=>"?p=".$p."&o=a", "addT"=>_("Add"), "delConfirm"=>_("Do you confirm the deletion ?")));
  188. /*
  189. $tpl->assign(
  190. 'applyConfiguration',
  191. array(
  192. "link" => "?p=60902",
  193. "label" => _("Apply configuration"),
  194. "js" => "console.log('toto');"
  195. )
  196. );
  197. */
  198. /*
  199. * Toolbar select
  200. */
  201. ?>
  202. <script type="text/javascript">
  203. function setO(_i) {
  204. document.forms['form'].elements['o'].value = _i;
  205. }
  206. </SCRIPT>
  207. <?php
  208. $attrs = array(
  209. 'onchange'=>"javascript: " .
  210. " var bChecked = isChecked(); ".
  211. " if (this.form.elements['o1'].selectedIndex != 0 && !bChecked) {".
  212. " alert('"._("Please select one or more items")."'); return false;} " .
  213. " if (this.form.elements['o1'].selectedIndex == 1 && confirm('"._("Do you confirm the duplication ?")."')) {" .
  214. " setO(this.form.elements['o1'].value); submit();} " .
  215. "else if (this.form.elements['o1'].selectedIndex == 2 && confirm('"._("Do you confirm the deletion ?")."')) {" .
  216. " setO(this.form.elements['o1'].value); submit();} " .
  217. "else if (this.form.elements['o1'].selectedIndex == 3) {" .
  218. " setO(this.form.elements['o1'].value); submit();} " .
  219. "");
  220. $form->addElement('select', 'o1', NULL, array(NULL=>_("More actions..."), "m"=>_("Duplicate"), "d"=>_("Delete"), "i"=>_("Update informations")), $attrs);
  221. $form->setDefaults(array('o1' => NULL));
  222. $o1 = $form->getElement('o1');
  223. $o1->setValue(NULL);
  224. # Apply configuration button
  225. $form->addElement('button', 'apply_configuration', _("Apply configuration"), array('onClick' => 'applyConfiguration();', 'class' => 'btc bt_info'));
  226. $attrs = array(
  227. 'onchange'=>"javascript: " .
  228. " var bChecked = isChecked(); ".
  229. " if (this.form.elements['o2'].selectedIndex != 0 && !bChecked) {".
  230. " alert('"._("Please select one or more items")."'); return false;} " .
  231. "if (this.form.elements['o2'].selectedIndex == 1 && confirm('"._("Do you confirm the duplication ?")."')) {" .
  232. " setO(this.form.elements['o2'].value); submit();} " .
  233. "else if (this.form.elements['o2'].selectedIndex == 2 && confirm('"._("Do you confirm the deletion ?")."')) {" .
  234. " setO(this.form.elements['o2'].value); submit();} " .
  235. "else if (this.form.elements['o2'].selectedIndex == 3) {" .
  236. " setO(this.form.elements['o2'].value); submit();} " .
  237. "");
  238. $form->addElement('select', 'o2', NULL, array(NULL=>_("More actions..."), "m"=>_("Duplicate"), "d"=>_("Delete"), "i"=>_("Update informations")), $attrs);
  239. $form->setDefaults(array('o2' => NULL));
  240. $o2 = $form->getElement('o2');
  241. $o2->setValue(NULL);
  242. $tpl->assign('limit', $limit);
  243. $tpl->assign('searchP', $search);
  244. /*
  245. * Apply a template definition
  246. */
  247. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
  248. $form->accept($renderer);
  249. $tpl->assign('form', $renderer->toArray());
  250. $tpl->display("listServers.ihtml");