index.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
  3. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
  4. // Создание нового фильтра
  5. if (getPOST("create") !== null) {
  6. $fname = trim(getPOST("newfilter", null, ''));
  7. $ftype = (int)getPOST("filter_type", null, 0);
  8. if ($fname !== '') {
  9. $new_id = insert_record($db_link, "filter_list", [
  10. 'name' => $fname,
  11. 'filter_type' => $ftype
  12. ]);
  13. if ($new_id) {
  14. header("Location: editfilter.php?id=$new_id");
  15. exit;
  16. }
  17. }
  18. header("Location: " . $_SERVER["REQUEST_URI"]);
  19. exit;
  20. }
  21. // Удаление фильтров
  22. if (getPOST("remove") !== null) {
  23. $fid = getPOST("fid", null, []);
  24. if (!empty($fid) && is_array($fid)) {
  25. foreach ($fid as $val) {
  26. $val = trim($val);
  27. if ($val === '') continue;
  28. // Удаляем из связей
  29. delete_records($db_link, "group_filters", "filter_id = ?", [(int)$val]);
  30. // Удаляем сам фильтр
  31. delete_record($db_link, "filter_list", "id = ?", [(int)$val]);
  32. }
  33. }
  34. header("Location: " . $_SERVER["REQUEST_URI"]);
  35. exit;
  36. }
  37. unset($_POST);
  38. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
  39. print_filters_submenu($page_url);
  40. ?>
  41. <div id="cont">
  42. <form name="def" action="index.php" method="post">
  43. <table class="data">
  44. <tr align="center">
  45. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  46. <td><b>id</b></td>
  47. <td><b><?php echo WEB_cell_forename; ?></b></td>
  48. <td><b><?php echo WEB_cell_type; ?></b></td>
  49. <td><b><?php echo WEB_traffic_proto; ?></b></td>
  50. <td><b><?php echo WEB_traffic_dest_address; ?></b></td>
  51. <td><b><?php echo WEB_traffic_dst_port; ?></b></td>
  52. <td><b><?php echo WEB_traffic_src_port; ?></b></td>
  53. <td><b><?php echo WEB_cell_description; ?></b></td>
  54. <td><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="remove" value="<?php echo WEB_btn_delete; ?>"></td>
  55. </tr>
  56. <?php
  57. // Запрос с подгрузкой имени IPSet через LEFT JOIN
  58. $filters = get_records_sql($db_link,
  59. 'SELECT f.*, i.name AS ipset_name
  60. FROM filter_list f
  61. LEFT JOIN ipset_list i ON f.ipset_id = i.id
  62. ORDER BY f.name');
  63. foreach ($filters as $row) {
  64. print "<tr align=center>\n";
  65. print "<td class=\"data\" style='padding:0'><input type=checkbox name=fid[] value=" . $row['id'] . "></td>\n";
  66. print "<td class=\"data\" ><input type=hidden name=\"id\" value=" . $row['id'] . ">" . $row['id'] . "</td>\n";
  67. print "<td class=\"data\" align=left><a href=editfilter.php?id=" . $row['id'] . ">" . htmlspecialchars($row['name']) . "</a></td>\n";
  68. // Инициализация пустых полей
  69. $row['description'] = $row['description'] ?? '';
  70. $row['proto'] = $row['proto'] ?? '';
  71. $row['dst'] = $row['dst'] ?? '';
  72. $row['dstport'] = $row['dstport'] ?? '';
  73. $row['srcport'] = $row['srcport'] ?? '';
  74. if ($row['filter_type'] == 0) {
  75. // === Формирование отображения dst / ipset ===
  76. $dst_display = '';
  77. if (!empty($row['ipset_id']) && !empty($row['ipset_name'])) {
  78. // Режим IPSet: показываем имя с ссылкой на редактирование
  79. $dst_display = '<span title="IPSet">' .
  80. '<a href="editipset.php?id=' . (int)$row['ipset_id'] . '" ' .
  81. 'style="color:#06c; text-decoration:none; font-weight:500">' .
  82. '📦 ' . htmlspecialchars($row['ipset_name']) . '</a></span>';
  83. } elseif (!empty($row['dst'])) {
  84. // Режим прямого IP: показываем dst
  85. $dst_display = htmlspecialchars($row['dst']);
  86. } else {
  87. // Пустое значение
  88. $dst_display = '<span style="color:#999">0/0</span>';
  89. }
  90. print "<td class=\"data\">IP фильтр</td>\n";
  91. print "<td class=\"data\">" . htmlspecialchars($row['proto']) . "</td>\n";
  92. print "<td class=\"data\" align=left>" . $dst_display . "</td>\n";
  93. print "<td class=\"data\">" . htmlspecialchars($row['dstport']) . "</td>\n";
  94. print "<td class=\"data\">" . htmlspecialchars($row['srcport']) . "</td>\n";
  95. print "<td class=\"data\">" . htmlspecialchars($row['description']) . "</td>\n";
  96. } else {
  97. // Name фильтр (упрощённый режим)
  98. $dst_display = '';
  99. if (!empty($row['ipset_id']) && !empty($row['ipset_name'])) {
  100. $dst_display = '<span title="IPSet">' .
  101. '<a href="editipset.php?id=' . (int)$row['ipset_id'] . '" ' .
  102. 'style="color:#06c; text-decoration:none; font-weight:500">' .
  103. '📦 ' . htmlspecialchars($row['ipset_name']) . '</a></span>';
  104. } elseif (!empty($row['dst'])) {
  105. $dst_display = htmlspecialchars($row['dst']);
  106. } else {
  107. $dst_display = '<span style="color:#999">—</span>';
  108. }
  109. print "<td class=\"data\">Name фильтр</td>\n";
  110. print "<td class=\"data\"></td>\n";
  111. print "<td class=\"data\" align=left>" . $dst_display . "</td>\n";
  112. print "<td class=\"data\"></td>\n";
  113. print "<td class=\"data\"></td>\n";
  114. print "<td class=\"data\">" . htmlspecialchars($row['description']) . "</td>\n";
  115. }
  116. print "<td></td></tr>";
  117. }
  118. ?>
  119. </table>
  120. <div>
  121. <?php echo WEB_cell_name; ?>
  122. <input type=text name=newfilter value="Unknown">
  123. <?php echo WEB_filter_type; ?>
  124. <select name="filter_type" disabled=true>
  125. <option value=0 selected>IP фильтр</option>
  126. <option value=1>Name фильтр</option>
  127. </select>
  128. <input type="submit" name="create" value="<?php echo WEB_btn_add; ?>">
  129. </form>
  130. <?php
  131. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php");
  132. ?>