editfilter.php 6.4 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. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
  5. $filter = get_record($db_link, 'filter_list', 'id=?', [ $id ]);
  6. // ==================== СОХРАНЕНИЕ ФИЛЬТРА ====================
  7. if (getPOST("editfilter") !== null) {
  8. $use_ipset = (int)getPOST("f_use_ipset", null, 0);
  9. if ($use_ipset) {
  10. $ipset_id = (int)getPOST("f_ipset_id", null, 0);
  11. $dst = '';
  12. } else {
  13. $ipset_id = 0;
  14. $dst = trim(getPOST("f_dst", null, ''));
  15. }
  16. $new = [
  17. 'name' => trim(getPOST("f_name", null, $filter['name'])),
  18. 'dst' => $dst,
  19. 'ipset_id' => $ipset_id > 0 ? $ipset_id : 0,
  20. 'proto' => trim(getPOST("f_proto", null, '')),
  21. 'dstport' => str_replace(':', '-', trim(getPOST("f_dstport", null, ''))),
  22. 'srcport' => str_replace(':', '-', trim(getPOST("f_srcport", null, ''))),
  23. 'description' => trim(getPOST("f_description", null, ''))
  24. ];
  25. update_record($db_link, "filter_list", "id = ?", $new, [$id]);
  26. header("Location: " . $_SERVER["REQUEST_URI"]);
  27. exit;
  28. }
  29. unset($_POST);
  30. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  31. print_filters_submenu($page_url);
  32. print "<div id=cont>";
  33. print "<br><b>".WEB_title_filter."</b><br>";
  34. $ipsets = get_records_sql($db_link, "SELECT id, name, description FROM ipset_list ORDER BY name");
  35. $has_ipsets = !empty($ipsets);
  36. $current_ipset_id = $filter['ipset_id'] ?? 0;
  37. $use_ipset = ($current_ipset_id > 0) ? 1 : 0;
  38. ?>
  39. <form name="def" action="editfilter.php?id=<?php echo $id; ?>" method="post" id="filterForm">
  40. <input type="hidden" name="id" value="<?php echo $id; ?>">
  41. <input type="hidden" name="f_use_ipset" id="f_use_ipset" value="<?php echo $use_ipset; ?>">
  42. <table class="data" cellspacing="0" cellpadding="4">
  43. <tr>
  44. <td><b><?php echo WEB_cell_forename; ?></b></td>
  45. <td colspan="3"><b><?php echo WEB_cell_description; ?></b></td>
  46. </tr>
  47. <tr>
  48. <td align="left">
  49. <input type="text" name="f_name" value="<?php echo htmlspecialchars($filter['name']); ?>" size="30">
  50. </td>
  51. <td colspan="3">
  52. <input type="text" name="f_description" value="<?php echo htmlspecialchars($filter['description']); ?>" class="full-width" style="width:100%">
  53. </td>
  54. <td><input type="submit" name="editfilter" value="<?php echo WEB_btn_save; ?>"></td>
  55. </tr>
  56. <tr>
  57. <td><b><?php echo WEB_traffic_proto; ?></b></td>
  58. <td><b><?php echo WEB_traffic_dest_address; ?> (Dst / IPSet)</b></td>
  59. <td><b><?php echo WEB_traffic_dst_port; ?></b></td>
  60. <td><b><?php echo WEB_traffic_src_port; ?></b></td>
  61. </tr>
  62. <tr>
  63. <td>
  64. <input type="text" name="f_proto" value="<?php echo htmlspecialchars($filter['proto']); ?>" size="10">
  65. </td>
  66. <td>
  67. <div style="margin-bottom:8px">
  68. <label>
  69. <input type="radio" name="dst_mode" value="ip"
  70. <?php if (!$use_ipset) echo 'checked'; ?>
  71. onclick="toggleDstMode('ip')">
  72. <?php echo WEB_traffic_dst_subnet; ?>
  73. </label>
  74. <?php if ($has_ipsets): ?>
  75. <label style="margin-left:15px">
  76. <input type="radio" name="dst_mode" value="ipset"
  77. <?php if ($use_ipset) echo 'checked'; ?>
  78. onclick="toggleDstMode('ipset')">
  79. <?php echo WEB_traffic_dst_ipset; ?>
  80. </label>
  81. <?php endif; ?>
  82. </div>
  83. <div id="dst_ip_container" style="<?php echo $use_ipset ? 'display:none' : 'display:block'; ?>">
  84. <input type="text" name="f_dst" id="f_dst"
  85. value="<?php echo htmlspecialchars($filter['dst']); ?>"
  86. size="25" placeholder="192.168.1.0/24">
  87. </div>
  88. <div id="dst_ipset_container" style="<?php echo $use_ipset ? 'display:block' : 'display:none'; ?>">
  89. <select name="f_ipset_id" id="f_ipset_id" style="width:100%; max-width:300px">
  90. <option value="0">-- <?php echo WEB_traffic_select_ipset; ?> --</option>
  91. <?php foreach ($ipsets as $ipset): ?>
  92. <option value="<?php echo $ipset['id']; ?>"
  93. <?php if ($ipset['id'] == $current_ipset_id) echo 'selected'; ?>>
  94. <?php echo htmlspecialchars($ipset['name']); ?>
  95. <?php if (!empty($ipset['description'])): ?>
  96. (<?php echo htmlspecialchars(mb_substr($ipset['description'], 0, 40)); ?>...)
  97. <?php endif; ?>
  98. </option>
  99. <?php endforeach; ?>
  100. </select>
  101. </div>
  102. </td>
  103. <td>
  104. <input type="text" name="f_dstport" value="<?php echo htmlspecialchars(str_replace('-', ':', $filter['dstport'])); ?>" size="10">
  105. </td>
  106. <td>
  107. <input type="text" name="f_srcport" value="<?php echo htmlspecialchars(str_replace('-', ':', $filter['srcport'])); ?>" size="10">
  108. </td>
  109. </tr>
  110. </table>
  111. </form>
  112. <script>
  113. function toggleDstMode(mode) {
  114. const ipContainer = document.getElementById('dst_ip_container');
  115. const ipsetContainer = document.getElementById('dst_ipset_container');
  116. const useIpsetField = document.getElementById('f_use_ipset');
  117. const dstInput = document.getElementById('f_dst');
  118. const ipsetSelect = document.getElementById('f_ipset_id');
  119. if (mode === 'ipset') {
  120. ipContainer.style.display = 'none';
  121. ipsetContainer.style.display = 'block';
  122. useIpsetField.value = '1';
  123. dstInput.value = '';
  124. dstInput.removeAttribute('required');
  125. } else {
  126. ipContainer.style.display = 'block';
  127. ipsetContainer.style.display = 'none';
  128. useIpsetField.value = '0';
  129. ipsetSelect.value = '0';
  130. }
  131. };
  132. </script>
  133. <?php
  134. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  135. ?>