index.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/devtypesfilter.php");
  5. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/buildingfilter.php");
  6. $default_sort='device_name';
  7. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/sortfilter.php");
  8. if (isset($_POST["create"])) {
  9. $fname = $_POST["newswitches"];
  10. if ($fname) {
  11. global $snmp_default_version;
  12. global $snmp_default_community;
  13. $new['device_name'] = $fname;
  14. $new['community'] = $snmp_default_community;
  15. $new['snmp_version'] = $snmp_default_version;
  16. $new_id=insert_record($db_link, "devices", $new);
  17. LOG_INFO($db_link, "Created new device device_name=$fname");
  18. unset($_POST);
  19. header("location: editdevice.php?id=$new_id");
  20. }
  21. }
  22. if (isset($_POST["remove"])) {
  23. $fid = $_POST["fid"];
  24. foreach ($fid as $key => $val) {
  25. if ($val) {
  26. LOG_INFO($db_link, "Delete device id: $val");
  27. unbind_ports($db_link, $val);
  28. delete_record($db_link, "connections", "device_id=$val");
  29. delete_record($db_link, "device_ports", "device_id=$val");
  30. $new['deleted'] = 1;
  31. update_record($db_link, "devices", "id='$val'", $new);
  32. }
  33. }
  34. header("Location: " . $_SERVER["REQUEST_URI"]);
  35. }
  36. unset($_POST);
  37. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  38. print_device_submenu($page_url);
  39. $sort_sql=" ORDER BY device_name";
  40. if (!empty($sort_field) and !empty($order)) { $sort_sql = " ORDER BY $sort_field $order"; }
  41. ?>
  42. <div id="cont">
  43. <br>
  44. <form name="def" action="index.php" method="post">
  45. <table class="data">
  46. <tr class="info" align="center">
  47. <td class="info" colspan=3 > Тип оборудования: </td>
  48. <td class="info" colspan=2 > <?php print_devtypes_select($db_link, "devtypes", $f_devtype_id); ?>
  49. <td class="info" >Показать оборудование из</td>
  50. <td class="info" > <?php print_building_select($db_link, "building_id", $f_building_id); ?></td>
  51. <td class="info" colspan=3> <input type="submit" name="apply" value="Показать"></td>
  52. </tr>
  53. <tr align="center">
  54. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  55. <td><b><a href=index.php?sort=id&order=<?php print $new_order; ?>>id</a></b></td>
  56. <td><b><a href=index.php?sort=device_type&order=<?php print $new_order; ?>>Тип</a></b></td>
  57. <td><b><a href=index.php?sort=device_name&order=<?php print $new_order; ?>>Название</a></b></td>
  58. <td><b><a href=index.php?sort=ip&order=<?php print $new_order; ?>>IP</a></b></td>
  59. <td><b><a href=index.php?sort=device_model_id&order=<?php print $new_order; ?>>Модель</a></b></td>
  60. <td><b><a href=index.php?sort=building_id&order=<?php print $new_order; ?>>Расположен</a></b></td>
  61. <td><b>Портов</b></td>
  62. <td><b>Nagios</b></td>
  63. <td><b>Discavery</b></td>
  64. </tr>
  65. <?
  66. $filter = '';
  67. if ($f_building_id > 0) { $filter .= ' and building_id=' . $f_building_id; }
  68. if ($f_devtype_id > 0) { $filter .= ' and device_type=' . $f_devtype_id; }
  69. $dSQL = 'SELECT * FROM devices WHERE deleted=0 '.$filter.' '.$sort_sql;
  70. $switches = get_records_sql($db_link,$dSQL);
  71. foreach ($switches as $row) {
  72. print "<tr align=center>\n";
  73. $cl = "data";
  74. if (isset($row['nagios_status'])) {
  75. $cl = 'shutdown';
  76. if ($row['nagios_status'] == 'UP') { $cl = 'up'; }
  77. }
  78. print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=fid[] value=".$row['id']."></td>\n";
  79. print "<td class=\"$cl\"><input type=hidden name=\"id\" value=".$row['id'].">".$row['id']."</td>\n";
  80. print "<td class=\"$cl\">".get_devtype_name($db_link,$row['device_type'])."</td>\n";
  81. print "<td class=\"$cl\" align=left><a href=editdevice.php?id=".$row['id'].">" . $row['device_name'] . "</a></td>\n";
  82. if (isset($row['user_id']) and $row['user_id']>0) {
  83. print "<td class=\"$cl\"><a href=/admin/users/edituser.php?id=".$row['user_id'].">".$row['ip']."</a></td>\n";
  84. } else {
  85. print "<td class=\"$cl\">".$row['ip']."</td>\n";
  86. }
  87. print "<td class=\"$cl\">" . get_vendor_name($db_link, $row['vendor_id']) . " " . get_device_model($db_link,$row['device_model_id']) . "</td>\n";
  88. print "<td class=\"$cl\">" . get_building($db_link, $row['building_id']) . "(" . $row['comment'] . ")</td>\n";
  89. print "<td class=\"$cl\">".$row['port_count']."</td>\n";
  90. print "<td class=\"$cl\">" . get_qa($row['nagios']) . "</td>\n";
  91. print "<td class=\"$cl\">" . get_qa($row['discovery']) . "</td>\n";
  92. }
  93. ?>
  94. </table>
  95. <table class="data">
  96. <tr align=left>
  97. <td>Название <input type=text name=newswitches value="Unknown"></td>
  98. <td><input type="submit" name="create" value="Добавить"></td>
  99. <td align="right"><input type="submit" onclick="return confirm('Удалить?')" name="remove" value="Удалить"></td>
  100. </tr>
  101. </table>
  102. </form>
  103. <table class="data">
  104. <tr>
  105. <td>Device status</td>
  106. </tr>
  107. <tr>
  108. <td class="shutdown">Down</td>
  109. <td class="up">Online</td>
  110. <tr>
  111. </table>
  112. <?
  113. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  114. ?>