PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/www/menu/Menu.php

https://gitlab.com/florianocomercial/centreon
PHP | 362 lines | 232 code | 35 blank | 95 comment | 51 complexity | 140bc56f7ddeb27220b8de8dded2acc3 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. /*
  39. * Path to the configuration dir
  40. */
  41. $path = "./menu/templates";
  42. $user_update_pref = "./menu/userMenuPreferences.php";
  43. /*
  44. * Smarty template Init
  45. */
  46. $tpl = new Smarty();
  47. $tpl = initSmartyTpl($path, $tpl);
  48. /*
  49. * Var init
  50. */
  51. $sep = NULL;
  52. $elemArr = array(1 => array(), 2 => array(), 3 => array(), 4 => array());
  53. /*
  54. * Special Case
  55. * Put the authentication in the URL
  56. */
  57. $auth = NULL;
  58. require_once("./menu/MenuJS.php");
  59. require_once _CENTREON_PATH_ . 'www/class/centreonMenu.class.php';
  60. require_once _CENTREON_PATH_ . 'www/class/centreonLang.class.php';
  61. $centreonMenu = new CentreonMenu(new CentreonLang(_CENTREON_PATH_, $centreon));
  62. /*
  63. * block headerHTML
  64. */
  65. $version = $centreon->user->get_version();
  66. $fileStatus = $centreon->Nagioscfg["status_file"];
  67. $fileCentreonConf = $centreon->optGen["oreon_path"];
  68. $color = array();
  69. $color["OK"] = $centreon->optGen["color_ok"];
  70. $color["CRITICAL"] = $centreon->optGen["color_critical"];
  71. $color["WARNING"] = $centreon->optGen["color_warning"];
  72. $color["PENDING"] = $centreon->optGen["color_pending"];
  73. $color["UNKNOWN"] = $centreon->optGen["color_unknown"];
  74. $color["UP"] = $centreon->optGen["color_up"];
  75. $color["DOWN"] = $centreon->optGen["color_down"];
  76. $color["UNREACHABLE"] = $centreon->optGen["color_unreachable"];
  77. $tpl->assign("urlLogo", 'img/centreon.png');
  78. /**
  79. * ACL
  80. */
  81. if ($centreon->user->access->admin == 0) {
  82. $tabActionACL = $centreon->user->access->getActions();
  83. if (isset($tabActionACL["top_counter"])) {
  84. $tpl->assign("displayTopCounter", 1);
  85. } else {
  86. $tpl->assign("displayTopCounter", 0);
  87. }
  88. if (isset($tabActionACL["poller_stats"])) {
  89. $tpl->assign("displayPollerStats", 1);
  90. } else {
  91. $tpl->assign("displayPollerStats", 0);
  92. }
  93. } else {
  94. $tpl->assign("displayTopCounter", 1);
  95. $tpl->assign("displayPollerStats", 1);
  96. }
  97. $tpl->assign("Ok", _("Ok"));
  98. $tpl->assign("Warning", _("Warning"));
  99. $tpl->assign("Critical", _("Critical"));
  100. $tpl->assign("Unknown", _("Unknown"));
  101. $tpl->assign("Pending", _("Pending"));
  102. $tpl->assign("Up", _("Up"));
  103. $tpl->assign("Down", _("Down"));
  104. $tpl->assign("Unreachable", _("Unreachable"));
  105. $tpl->assign("Hosts", _("Hosts"));
  106. $tpl->assign("Services", _("Services"));
  107. $tpl->assign("ndoState", _("Poller States"));
  108. $tpl->assign("Logout", _("Logout"));
  109. $tpl->assign("Help", _("Help"));
  110. $tpl->assign("Documentation", _("Documentation"));
  111. $tpl->assign("p", $p);
  112. $tpl->assign("color", $color);
  113. $tpl->assign("version", $version);
  114. $tpl->assign("fileStatus", $fileStatus);
  115. $tpl->assign("fileOreonConf", $fileCentreonConf);
  116. $tpl->assign("sound_status", isset($_SESSION['disable_sound']) ? 'off' : 'on');
  117. $tpl->assign("sound_action", isset($_SESSION['disable_sound']) ? 'jQuery().centreon_notify_start();' : 'jQuery().centreon_notify_stop();');
  118. $tpl->assign("date_time_format_status", _("d/m/Y H:i:s"));
  119. /*
  120. * Display Login
  121. */
  122. $tpl->assign("user_login", $centreon->user->get_alias());
  123. $tpl->assign("loggedlabel", _("Welcome"));
  124. /*
  125. * Fixe ACL
  126. */
  127. $lcaSTR = "";
  128. if (!$is_admin) {
  129. $lcaSTR = "AND topology_page IN (".$centreon->user->access->getTopologyString().")";
  130. }
  131. /*
  132. * Grab elements for level 1
  133. */
  134. $rq = "SELECT * FROM topology WHERE topology_parent IS NULL $lcaSTR AND topology_show = '1' ORDER BY topology_order";
  135. $DBRESULT = $pearDB->query($rq);
  136. for ($i = 0; $DBRESULT->numRows() && ($elem = $DBRESULT->fetchRow()); $i++) {
  137. $pageAccess = $centreon->user->access->page($elem["topology_page"]);
  138. if (($pageAccess == "1") || ($pageAccess == "2"))
  139. {
  140. $elemArr[1][$i] = array("Menu1ClassImg" => $level1 == $elem["topology_page"] ? "menu1_bgimg" : "id_".$elem["topology_id"],
  141. "Menu1Page" => $elem["topology_page"] ,
  142. "Menu1Url" => "main.php?p=".$elem["topology_page"].$elem["topology_url_opt"],
  143. "Menu1UrlPopup" => $elem["topology_popup"],
  144. "Menu1UrlPopupOpen" => $elem["topology_url"],
  145. "Menu1Name" => $centreonMenu->translate($elem['topology_modules'], $elem['topology_url'], $elem["topology_name"]),
  146. "Menu1Popup" => $elem["topology_popup"] ? true : false);
  147. }
  148. }
  149. $DBRESULT->free();
  150. $userUrl = "main.php?p=50104&o=c";
  151. $logDate = $centreon->CentreonGMT->getDate(_("Y/m/d G:i"), time(), $centreon->user->getMyGMT());
  152. $logOut = _("Logout");
  153. $logOutUrl = "index.php?disconnect=1";
  154. /*
  155. * Define autologin URL
  156. */
  157. if (isset($centreon->optGen["display_autologin_shortcut"])) {
  158. $userAlias = $centreon->user->get_alias();
  159. if ($centreon->optGen["enable_autologin"] && $centreon->optGen["display_autologin_shortcut"]) {
  160. $tpl->assign("autoLoginEnable", 1);
  161. } else {
  162. $tpl->assign("autoLoginEnable", 0);
  163. }
  164. if ($centreon->user->getToken()) {
  165. $autoLoginUrl = "";
  166. if (!strstr($_SERVER['REQUEST_URI'], '?')) {
  167. $root_menu = get_my_first_allowed_root_menu($centreon->user->access->topologyStr);
  168. $autoLoginUrl .= "?p=".$root_menu["topology_page"];
  169. }
  170. $autoLoginUrl .= "&autologin=1&useralias=$userAlias&token=".$centreon->user->getToken();
  171. $prefix = '';
  172. if (!strncmp($_SERVER["SERVER_PROTOCOL"], "HTTP/", 5)) {
  173. $prefix .= "http://";
  174. } else {
  175. $prefix .= "https://";
  176. }
  177. $prefix .= $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  178. $prefix = str_replace("main.php", "index.php", $prefix);
  179. $msg = _("Right Click here to add an autologin link directly to your bookmarks");
  180. $tpl->assign("autoLoginUrl", $prefix.$autoLoginUrl);
  181. } else {
  182. $msg = _("Please define autologin authentication key in your profile.");
  183. $tpl->assign("autoLoginUrl", '#');
  184. }
  185. $tpl->assign("CentreonAutologin", $msg);
  186. }
  187. /*
  188. * Grab elements for level 2
  189. */
  190. $rq = "SELECT topology_page, topology_url_opt, topology_popup, topology_url, topology_name, topology_modules FROM topology WHERE topology_parent = '".$level1."' $lcaSTR AND topology_show = '1' ORDER BY topology_group, topology_order";
  191. $DBRESULT = $pearDB->query($rq);
  192. $firstP = NULL;
  193. $sep = "&nbsp;";
  194. for ($i = 0; $DBRESULT->numRows() && ($elem = $DBRESULT->fetchRow()); $i++) {
  195. $firstP ? null : $firstP = $elem["topology_page"];
  196. $pageAccess = $centreon->user->access->page($elem["topology_page"]);
  197. if (($pageAccess == "1") || ($pageAccess == "2")) {
  198. $elemArr[2][$i] = array("Menu2Sep" => $sep,
  199. "Menu2Url" => "main.php?p=".$elem["topology_page"].$elem["topology_url_opt"],
  200. "Menu2UrlPopup" => $elem["topology_popup"],
  201. "Menu2UrlPopupOpen" => $elem["topology_url"].$auth,
  202. "Menu2Name" => $centreonMenu->translate($elem['topology_modules'], $elem['topology_url'], $elem["topology_name"]),
  203. "Menu2Popup" => $elem["topology_popup"] ? true : false);
  204. }
  205. $sep = "&nbsp;|&nbsp;";
  206. }
  207. /*
  208. * Grab elements for level 3
  209. */
  210. $request = "SELECT * FROM topology WHERE topology_parent = '".($level2 ? $level1.$level2 : $firstP)."' $lcaSTR AND topology_show = '1' AND topology_page is not null ORDER BY topology_group, topology_order";
  211. $DBRESULT = $pearDB->query($request);
  212. for ($i = 0; $elem = $DBRESULT->fetchRow();$i++) {
  213. # grab menu title for each group
  214. $DBRESULT_title = $pearDB->query("SELECT topology_name FROM topology WHERE topology_parent = '".$elem["topology_parent"]."' AND topology_show = '1' AND topology_page IS NULL AND topology_group = '".$elem["topology_group"]."' LIMIT 1");
  215. $title = "";
  216. $topoName = $DBRESULT_title->fetchRow();
  217. if ($DBRESULT_title->numRows()) {
  218. $title = _($topoName['topology_name']);
  219. } else {
  220. $title = _("Main Menu");
  221. }
  222. $pageAccess = $centreon->user->access->page($elem["topology_page"]);
  223. if (($pageAccess == "1") || ($pageAccess == "2")) {
  224. $Menu3Url = "main.php?p=".$elem["topology_page"].$elem["topology_url_opt"];
  225. $elemArr[3][$elem["topology_group"]]["title"] = $title;
  226. $elemArr[3][$elem["topology_group"]]["tab"][$i] = array("Menu3Url" => $Menu3Url,
  227. "Menu3ID" => $elem["topology_page"],
  228. "MenuStyleClass" => $elem["topology_style_class"],
  229. "MenuStyleID" => $elem["topology_style_id"],
  230. "MenuOnClick" => $elem["topology_OnClick"],
  231. "MenuIsOnClick" => $elem["topology_OnClick"] ? true : false,
  232. "Menu3UrlPopup" => $elem["topology_url"],
  233. "Menu3Name" => $centreonMenu->translate($elem['topology_modules'], $elem['topology_url'], $elem["topology_name"]),
  234. "Menu3Popup" => $elem["topology_popup"] ? true : false);
  235. }
  236. }
  237. unset($elem);
  238. /*
  239. * Grab elements for level 4
  240. */
  241. if ($level1 && $level2 && $level3){
  242. $request = "SELECT topology_icone, topology_page, topology_url_opt, topology_url, topology_OnClick, topology_name, topology_popup, topology_modules FROM topology WHERE topology_parent = '".$level1.$level2.$level3."' $lcaSTR AND topology_show = '1' ORDER BY topology_order";
  243. $DBRESULT = $pearDB->query($request);
  244. for ($i = 0; $elem = $DBRESULT->fetchRow(); $i++) {
  245. $pageAccess = $centreon->user->access->page($elem["topology_page"]);
  246. if (($pageAccess == "1") || ($pageAccess == "2")) {
  247. $elemArr[4][$level1.$level2.$level3][$i] = array( "Menu4Icone" => $elem["topology_icone"],
  248. "Menu4Url" => "main.php?p=".$elem["topology_page"].$elem["topology_url_opt"],
  249. "Menu4UrlPopup" => $elem["topology_url"],
  250. "MenuOnClick" => $elem["topology_OnClick"],
  251. "MenuIsOnClick" => $elem["topology_OnClick"] ? true : false,
  252. "Menu4Name" => $centreonMenu->translate($elem['topology_modules'], $elem['topology_url'], $elem["topology_name"]),
  253. "Menu4Popup" => $elem["topology_popup"] ? true : false);
  254. }
  255. $centreonLang->bindLang();
  256. }
  257. }
  258. /*
  259. * Create Menu Level 1-2-3-4
  260. */
  261. $tpl->assign("PageID", $p);
  262. $tpl->assign("UserInfoUrl", $userUrl);
  263. $tpl->assign("UserName", $centreon->user->get_alias());
  264. $tpl->assign("Date", $logDate);
  265. $tpl->assign("LogOut", $logOut);
  266. $tpl->assign("LogOutUrl", $logOutUrl);
  267. $tpl->assign("Menu1Color", "menu_1");
  268. $tpl->assign("Menu1ID", "menu1_bgcolor");
  269. $tpl->assign("Menu2Color", "menu_2");
  270. $tpl->assign("Menu2ID", "menu2_bgcolor");
  271. $tpl->assign("Menu3Color", "menu_3");
  272. $tpl->assign("Menu3ID", "menu3_bgcolor");
  273. $tpl->assign("Menu4Color", "menu_4");
  274. $tpl->assign("Menu4ID", "menu4_bgcolor");
  275. $tpl->assign("connected_users", _("Connected Users"));
  276. $tpl->assign("main_menu", _("Main Menu"));
  277. /*
  278. * Send ACL Topology in template
  279. */
  280. $tpl->assign("topology", $centreon->user->access->topology);
  281. /*
  282. * Assign for Smarty Template
  283. */
  284. $tpl->assign("elemArr1", $elemArr[1]);
  285. count($elemArr[2]) ? $tpl->assign("elemArr2", $elemArr[2]) : NULL;
  286. count($elemArr[3]) ? $tpl->assign("elemArr3", $elemArr[3]) : NULL;
  287. count($elemArr[4]) ? $tpl->assign("elemArr4", $elemArr[4]) : NULL;
  288. $tpl->assign("idParent", $level1.$level2.$level3);
  289. /*
  290. * Legend icon
  291. */
  292. $tpl->assign("legend1", _("Help"));
  293. $tpl->assign("legend2", _("Legend"));
  294. /*
  295. * User's preference
  296. */
  297. $tpl->assign("user_update_pref_header", $user_update_pref . "?uid=".$centreon->user->user_id."&div=header");
  298. $tpl->assign("user_update_pref_menu_3", $user_update_pref . "?uid=".$centreon->user->user_id."&div=menu_3");
  299. /*
  300. * User Online
  301. */
  302. if ($is_admin){
  303. $tab_user = array();
  304. $tab_user_admin = array();
  305. $tab_user_non_admin = array();
  306. $DBRESULT = $pearDB->query("SELECT session.session_id, contact.contact_alias, contact.contact_admin, session.user_id, session.ip_address FROM session, contact WHERE contact.contact_id = session.user_id
  307. ORDER BY contact.contact_alias");
  308. while ($session = $DBRESULT->fetchRow()) {
  309. if ($session["contact_admin"] == 1) {
  310. $tab_user_admin[$session["user_id"]] = array("ip"=>$session["ip_address"], "id"=>$session["user_id"], "alias"=>$session["contact_alias"], "admin"=>$session["contact_admin"]);
  311. } else {
  312. $tab_user_non_admin[$session["user_id"]] = array("ip"=>$session["ip_address"], "id"=>$session["user_id"], "alias"=>$session["contact_alias"], "admin"=>$session["contact_admin"]);
  313. }
  314. }
  315. $tab_user = array_merge($tab_user_admin, $tab_user_non_admin);
  316. unset($tab_user_admin);
  317. unset($tab_user_non_admin);
  318. $DBRESULT->free();
  319. $tpl->assign("tab_user", $tab_user);
  320. }
  321. $tpl->assign('amIadmin', $centreon->user->admin);
  322. /*
  323. * Display
  324. */
  325. $tpl->display("BlockHeader.ihtml");
  326. $tpl->display("menu.ihtml");
  327. count($elemArr[3]) ? $tpl->display("BlockMenuType3.ihtml") : $tpl->display("noLeftMenu.ihtml");