nagios.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. $default_displayed=500;
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  5. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  6. $default_sort='ip_int';
  7. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/oufilter.php");
  8. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/subnetfilter.php");
  9. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/sortfilter.php");
  10. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/gatefilter.php");
  11. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/enabledfilter.php");
  12. if (isset($_POST["ApplyForAll"])) {
  13. $auth_id = $_POST["fid"];
  14. $n_enabled = $_POST["n_enabled"] * 1;
  15. $n_link = $_POST["n_link"] * 1;
  16. $n_handler = $_POST["n_handler"];
  17. $msg="Массовое изменение пользователей!";
  18. foreach ($auth_id as $key => $val) {
  19. if ($val) {
  20. unset($auth);
  21. $auth['nagios'] = $n_enabled;
  22. $auth['link_check'] = $n_link;
  23. $auth['nagios_handler'] = $n_handler;
  24. update_record($db_link, "User_auth", "id='" . $val . "'", $auth);
  25. }
  26. }
  27. LOG_WARNING($db_link,$msg);
  28. header("Location: " . $_SERVER["REQUEST_URI"]);
  29. exit;
  30. }
  31. $sort_table = 'User_auth';
  32. if ($sort_field == 'login') { $sort_table = 'User_list'; }
  33. if ($sort_field == 'fio') { $sort_table = 'User_list'; }
  34. $sort_url = "<a href=nagios.php?ou=" . $rou;
  35. if ($rou == 0) { $ou_filter = ''; } else { $ou_filter = " and User_list.ou_id=$rou "; }
  36. if ($rsubnet == 0) { $subnet_filter = ''; } else {
  37. $subnet_range = get_subnet_range($db_link,$rsubnet);
  38. if (!empty($subnet_range)) { $subnet_filter = " and User_auth.ip_int>=".$subnet_range['start']." and User_auth.ip_int<=".$subnet_range['stop']; }
  39. }
  40. $enabled_filter='';
  41. if ($enabled>0) {
  42. if ($enabled===2) { $enabled_filter = ' and User_auth.nagios=1'; }
  43. if ($enabled===1) { $enabled_filter = ' and User_auth.nagios=0'; }
  44. }
  45. $ip_list_filter = $ou_filter.$subnet_filter.$enabled_filter;
  46. print_ip_submenu($page_url);
  47. ?>
  48. <div id="cont">
  49. <form name="def" action="nagios.php" method="post">
  50. <table class="data">
  51. <tr>
  52. <td>
  53. <b><?php print WEB_cell_ou; ?> :</b><?php print_ou_select($db_link, 'ou', $rou); ?>
  54. <b><?php print WEB_network_subnet; ?> - </b><?php print_subnet_select_office($db_link, 'subnet', $rsubnet); ?>
  55. <b><?php print WEB_nagios; ?> :</b><?php print_enabled_select('enabled', $enabled); ?>
  56. <?php print WEB_rows_at_page."&nbsp"; print_row_at_pages('rows',$displayed); ?>
  57. <input type="submit" value="<?php print WEB_btn_show; ?>">
  58. </td>
  59. </tr>
  60. </table>
  61. <?php
  62. $countSQL="SELECT Count(*) FROM User_auth, User_list WHERE User_auth.user_id = User_list.id AND User_auth.deleted =0 $ip_list_filter";
  63. $res = mysqli_query($db_link, $countSQL);
  64. $count_records = mysqli_fetch_array($res);
  65. $total=ceil($count_records[0]/$displayed);
  66. if ($page>$total) { $page=$total; }
  67. if ($page<1) { $page=1; }
  68. $start = ($page * $displayed) - $displayed;
  69. print_navigation($page_url,$page,$displayed,$count_records[0],$total);
  70. ?>
  71. <br>
  72. <table class="data">
  73. <tr>
  74. <td><?php echo WEB_selection_title; ?>: Nagios&nbsp<?php print_qa_select('n_enabled', 1); ?></td>
  75. <td>Link&nbsp<?php print_qa_select('n_link', 0); ?></td>
  76. <td>Event-handler&nbsp<?php print_nagios_handler_select('n_handler', ''); ?></td>
  77. <td>&nbsp<input type="submit" onclick="return confirm('<?php echo WEB_msg_apply_selected; ?>?')" name="ApplyForAll" value="<?php echo WEB_btn_apply; ?>"></td>
  78. </tr>
  79. </table>
  80. <table class="data">
  81. <tr>
  82. <td align=Center><input type="checkbox" onClick="checkAll(this.checked);"></td>
  83. <td align=Center><?php print $sort_url . "&sort=login&order=$new_order>" . WEB_cell_login . "</a>"; ?></td>
  84. <td align=Center><?php print $sort_url . "&sort=ip_int&order=$new_order>" . WEB_cell_ip . "</a>"; ?></td>
  85. <td align=Center><?php print $sort_url . "&sort=mac&order=$new_order>" . WEB_cell_mac . "</a>"; ?></td>
  86. <td align=Center><?php print WEB_cell_comment; ?></td>
  87. <td align=Center><?php print WEB_cell_wikiname; ?></td>
  88. <td align=Center><?php print $sort_url . "&sort=nagios&order=$new_order>" . WEB_cell_nagios; ?></td>
  89. <td align=Center><?php print $sort_url . "&sort=link_check&order=$new_order>" . WEB_cell_link; ?></td>
  90. <td align=Center><?php print WEB_cell_nagios_handler; ?></td>
  91. <td align=Center><?php print $sort_url . "&sort=last_found&order=$new_order>Last</a>"; ?></td>
  92. <td align=Center><?php print WEB_cell_connection; ?></td>
  93. </tr>
  94. <?php
  95. $sSQL = "SELECT User_auth.*, User_list.login FROM User_auth, User_list
  96. WHERE User_auth.user_id = User_list.id AND User_auth.deleted =0 $ip_list_filter
  97. ORDER BY $sort_table.$sort_field $order LIMIT $start,$displayed";
  98. $users = get_records_sql($db_link,$sSQL);
  99. foreach ($users as $user) {
  100. if ($user['dhcp_time'] == '0000-00-00 00:00:00') {
  101. $dhcp_str = '';
  102. } else {
  103. $dhcp_str = $user['dhcp_time'] . " (" . $user['dhcp_action'] . ")";
  104. }
  105. if ($user['last_found'] == '0000-00-00 00:00:00') { $user['last_found'] = ''; }
  106. print "<tr align=center>\n";
  107. $cl = "data";
  108. if ($user['nagios_status'] == "UP") { $cl = "up"; }
  109. if ($user['nagios_status'] == "DOWN") { $cl = "down"; }
  110. if (!$user['nagios']) { $cl = "data"; }
  111. print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=fid[] value=".$user['id']."></td>\n";
  112. print "<td class=\"$cl\" ><a href=/admin/users/edituser.php?id=".$user['user_id'].">" . $user['login'] . "</a></td>\n";
  113. print "<td class=\"$cl\" ><a href=/admin/users/editauth.php?id=".$user['id'].">" . $user['ip'] . "</a></td>\n";
  114. print "<td class=\"$cl\" >" . expand_mac($db_link,$user['mac']) . "</td>\n";
  115. if (isset($user['dhcp_hostname']) and strlen($user['dhcp_hostname']) > 0) {
  116. print "<td class=\"$cl\" width=200>".$user['comments']." [" . $user['dhcp_hostname'] . "]</td>\n";
  117. } else {
  118. print "<td class=\"$cl\" width=200>".$user['comments']."</td>\n";
  119. }
  120. if (!empty($user['WikiName'])) {
  121. $wiki_url = rtrim(get_option($db_link, 60),'/');
  122. if (preg_match('/127.0.0.1/', $wiki_url)) { print "<td class=\"$cl\" ></td>\n"; } else {
  123. $wiki_web = rtrim(get_option($db_link, 63),'/');
  124. $wiki_web = ltrim($wiki_web,'/');
  125. $wiki_link = $wiki_url.'/'.$wiki_web.'/'.$user['WikiName'];
  126. print "<td class=\"$cl\" >"; print_url($user['WikiName'],$wiki_link); print "</td>\n";
  127. }
  128. } else {
  129. print "<td class=\"$cl\" ></td>\n";
  130. }
  131. if (!empty($user['nagios']) and $user['nagios']) {
  132. if (preg_match('/127.0.0.1/', get_const('nagios_url'))) { print "<td class=\"$cl\" >". get_qa($user['nagios']) ."</td>\n"; } else {
  133. $nagios_link = get_const('nagios_url').'/cgi-bin/status.cgi?host='.get_nagios_name($user);
  134. print "<td class=\"$cl\" >"; print_url(get_qa($user['nagios']),$nagios_link); print "</td>\n";
  135. }
  136. } else {
  137. print "<td class=\"$cl\" >" . get_qa($user['nagios']) . "</td>\n";
  138. }
  139. print "<td class=\"$cl\" >" . get_qa($user['link_check']) . "</td>\n";
  140. print "<td class=\"$cl\" >".$user['nagios_handler']."</td>\n";
  141. print "<td class=\"$cl\" >".$user['last_found']."</td>\n";
  142. print "<td class=\"$cl\" >" . get_connection($db_link, $user['id']) . "</td>\n";
  143. print "</tr>\n";
  144. }
  145. print "</table>\n";
  146. print_navigation($page_url,$page,$displayed,$count_records[0],$total);
  147. ?>
  148. <br>
  149. <table class="data">
  150. <tr><td><?php echo WEB_color_description; ?></td></tr>
  151. <tr>
  152. <td class="up"><?php echo WEB_nagios_host_up; ?></td>
  153. <td class="down"><?php echo WEB_nagios_host_down; ?></td>
  154. <td class="data"><?php echo WEB_nagios_host_unknown; ?></td>
  155. </table>
  156. <?php
  157. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  158. ?>