edit_l3int.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT'] . "/inc/idfilter.php");
  5. $device = get_record($db_link, 'devices', "id = ?", [$id]);
  6. $snmp = getSnmpAccess($device);
  7. $user_info = get_record_sql($db_link, "SELECT * FROM user_list WHERE id = ?", [$device['user_id']]);
  8. $int_list = getIpAdEntIfIndex($db_link, $device['ip'], $snmp);
  9. // Удаление L3-интерфейсов
  10. if (getPOST("s_remove") !== null) {
  11. $s_id = getPOST("s_id", null, []);
  12. if (!empty($s_id) && is_array($s_id)) {
  13. foreach ($s_id as $val) {
  14. $val = trim($val);
  15. if ($val === '') continue;
  16. delete_record($db_link, "device_l3_interfaces", "id = ?", [(int)$val]);
  17. }
  18. }
  19. header("Location: " . $_SERVER["REQUEST_URI"]);
  20. exit;
  21. }
  22. // Сохранение ОТМЕЧЕННЫХ L3-интерфейсов
  23. if (getPOST("s_save") !== null) {
  24. $selected_ids = getPOST("s_id", null, []); // отмеченные чекбоксы
  25. $all_ids = getPOST("n_id", null, []); // все ID
  26. $types = getPOST("s_type", null, []);
  27. $bandwidth = getPOST("s_band",null,[]);
  28. if (!empty($selected_ids) && is_array($selected_ids)) {
  29. $selected_ids = array_map('intval', $selected_ids);
  30. $selected_set = array_flip($selected_ids);
  31. foreach ($all_ids as $i => $id) {
  32. $id = (int)$id;
  33. if ($id <= 0 || !isset($selected_set[$id])) continue;
  34. $new = [
  35. 'interface_type' => (int)($types[$i] ?? 0),
  36. 'bandwidth' => bitrate_to_kbps($bandwidth[$i] ?? '0k')
  37. ];
  38. update_record($db_link, "device_l3_interfaces", "id = ?", $new, [$id]);
  39. }
  40. }
  41. header("Location: " . $_SERVER["REQUEST_URI"]);
  42. exit;
  43. }
  44. // Создание нового L3-интерфейса
  45. if (getPOST("s_create") !== null) {
  46. $create_name = trim(getPOST("s_create_name", null, ''));
  47. if ($create_name !== '') {
  48. $parts = explode(";", $create_name);
  49. if (count($parts) >= 3) {
  50. $new = [
  51. 'name' => preg_replace('/"/', '', trim($parts[0])),
  52. 'snmpin' => trim($parts[1]),
  53. 'interface_type' => (int)trim($parts[2]),
  54. 'bandwidth' => (int)trim($parts[3] ?? 0),
  55. 'device_id' => $id
  56. ];
  57. insert_record($db_link, "device_l3_interfaces", $new);
  58. }
  59. }
  60. header("Location: " . $_SERVER["REQUEST_URI"]);
  61. exit;
  62. }
  63. unset($_POST);
  64. // Автоисправление интерфейсов
  65. $t_l3_interface = get_records_sql($db_link, "SELECT * FROM device_l3_interfaces WHERE device_id = ? ORDER BY name", [$id]);
  66. $int_by_name = [];
  67. foreach ($int_list as $row) {
  68. $row['name'] = preg_replace('/"/', '', $row['name']);
  69. $int_by_name[$row['name']] = $row;
  70. }
  71. $fixed = 0;
  72. // Исправление snmpin по имени
  73. foreach ($t_l3_interface as $row) {
  74. if (empty($row['snmpin']) && !empty($int_by_name[$row['name']])) {
  75. update_record($db_link, 'device_l3_interfaces', 'id = ?', ['snmpin' => $int_by_name[$row['name']]['index']], [$row['id']]);
  76. $fixed = 1;
  77. }
  78. }
  79. // Обновление имени по snmpin
  80. foreach ($t_l3_interface as $row) {
  81. if (!empty($int_list[$row['snmpin']]) && $int_list[$row['snmpin']]['name'] !== $row['name']) {
  82. update_record($db_link, 'device_l3_interfaces', 'id = ?', ['name' => $int_list[$row['snmpin']]['name']], [$row['id']]);
  83. $fixed = 1;
  84. }
  85. }
  86. if ($fixed) {
  87. $t_l3_interface = get_records_sql($db_link, "SELECT * FROM device_l3_interfaces WHERE device_id = ? ORDER BY name", [$id]);
  88. }
  89. require_once ($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
  90. print_device_submenu($page_url);
  91. print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['login']);
  92. ?>
  93. <div id="contsubmenu">
  94. <br>
  95. <form name="def" action="edit_l3int.php?id=<?php echo $id; ?>" method="post">
  96. <?php echo WEB_list_l3_interfaces . "<b>"; print_url($device['device_name'], "/admin/devices/editdevice.php?id=$id"); ?></b> <br>
  97. <table class="data">
  98. <tr align="center">
  99. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  100. <td width=30><b>id</b></td>
  101. <td><b><?php echo WEB_cell_name; ?></b></td>
  102. <td><b><?php echo WEB_cell_type; ?></b></td>
  103. <td><b><?php echo WEB_l3_interface_bandwidth; ?></b></td>
  104. <td>
  105. <!-- Кнопки управления справа -->
  106. <div style="text-align: right; white-space: nowrap;">
  107. <input type="submit" name="s_save" value="<?php echo WEB_btn_save; ?>">
  108. <input type="submit"
  109. onclick="return confirm('<?php echo WEB_msg_delete; ?>?')"
  110. name="s_remove"
  111. value="<?php echo WEB_btn_remove; ?>"
  112. style="margin-left: 8px;">
  113. </div>
  114. </td>
  115. </tr>
  116. <?php
  117. foreach ($t_l3_interface as $row) {
  118. print "<tr align=center>\n";
  119. print "<td class=\"data\" style='padding:0'><input type=\"checkbox\" name=\"s_id[]\" value=\"{$row['id']}\"></td>\n";
  120. print "<td class=\"data\"><input type=\"hidden\" name=\"n_id[]\" value=\"{$row['id']}\">{$row['snmpin']}</td>\n";
  121. print "<td class=\"data\">" . htmlspecialchars($row['name']) . '/' . htmlspecialchars($int_list[$row['snmpin']]['ip'] ?? '') . "</td>\n";
  122. print "<td class=\"data\">";
  123. print_qa_l3int_select('s_type[]', $row['interface_type']);
  124. print "</td>\n";
  125. print "<td class=\"data\"><input type='text' style='text-align: center;' name=\"s_band[]\" value='".kbps_to_bitrate($row['bandwidth'])."'></td>\n";
  126. print "<td class=\"data\"></td>\n";
  127. print "</tr>\n";
  128. }
  129. ?>
  130. <tr>
  131. <td colspan=4>
  132. <?php
  133. echo WEB_l3_interface_add;
  134. print_add_dev_interface($db_link, $id, $int_list, 's_create_name');
  135. ?>
  136. </td>
  137. <td>
  138. <input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>">
  139. </td>
  140. </tr>
  141. </table>
  142. </form>
  143. <?php
  144. require_once ($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php");
  145. ?>