auto_rules.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. $default_displayed=50;
  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. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/rulesfilter.php");
  7. if (getPOST("removeRule") !== null) {
  8. $r_id = getPOST("f_id", null, []);
  9. if (!empty($r_id) && is_array($r_id)) {
  10. foreach ($r_id as $val) {
  11. $val = trim($val);
  12. if ($val !== '') {
  13. delete_record($db_link, "auth_rules", "id = ?", [(int)$val]);
  14. }
  15. }
  16. }
  17. header("Location: " . $_SERVER["REQUEST_URI"]);
  18. exit;
  19. }
  20. print_ip_submenu($page_url);
  21. ?>
  22. <div id="cont">
  23. <br>
  24. <form name="def" action="auto_rules.php" method="post">
  25. <table>
  26. <tr>
  27. <td>
  28. <b><?php echo WEB_rules_search_target; ?> - </b><?php print_rule_target_select('rule_target', $rule_target); ?>
  29. </td>
  30. <td>
  31. <b><?php echo WEB_rules_search_type; ?> - </b><?php print_rule_type_select('rule_type', $rule_type); ?>
  32. </td>
  33. <td></td>
  34. </tr>
  35. <tr>
  36. <td colspan=2>
  37. <?php echo WEB_ips_search; ?>:&nbsp<input type="text" name="f_rule" value="<?php echo $f_rule; ?>"/>
  38. </td>
  39. <td>
  40. <?php print WEB_rows_at_page."&nbsp"; print_row_at_pages('rows',$displayed); ?>
  41. <input id="btn_filter" name="btn_filter" type="submit" value="<?php echo WEB_btn_show; ?>">
  42. </td>
  43. </tr>
  44. </table>
  45. <?php
  46. $target_filter='';
  47. $params=[];
  48. if ($rule_target>0) {
  49. if ($rule_target==1) { $target_filter = ' AND user_id>0'; }
  50. if ($rule_target==2) { $target_filter = ' AND ou_id>0'; }
  51. }
  52. $type_filter='';
  53. if ($rule_type>0) { $type_filter = ' AND type=?'; $params[]=$rule_type; }
  54. $rule_filter='';
  55. if (!empty($f_rule)) { $rule_filter = ' AND rule LIKE ?'; $params[]=$f_rule.'%'; }
  56. $rule_filters = '';
  57. if (!empty($target_filter) or !empty($type_filter) or !empty($rule_filter)) {
  58. $rule_filters='WHERE id '.$target_filter.$type_filter.$rule_filter;
  59. }
  60. fix_auth_rules($db_link);
  61. $countSQL="SELECT Count(*) FROM auth_rules $rule_filters";
  62. $count_records = get_single_field($db_link,$countSQL, $params);
  63. $total=ceil($count_records/$displayed);
  64. if ($page>$total) { $page=$total; }
  65. if ($page<1) { $page=1; }
  66. $start = ($page * $displayed) - $displayed;
  67. print_navigation($page_url,$page,$displayed,$count_records,$total);
  68. ?>
  69. <table class="data">
  70. <tr align="center">
  71. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  72. <td><b><?php echo WEB_cell_type; ?></b></td>
  73. <td><b><?php echo WEB_ou_rule; ?></b></td>
  74. <td colspan=2><b><?php echo WEB_rules_target; ?></b></td>
  75. <td><b><?php echo WEB_cell_description; ?></b></td>
  76. <td align=right><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="removeRule" value="<?php echo WEB_btn_delete; ?>"></td>
  77. </tr>
  78. <?php
  79. $rulesSQL = "SELECT * FROM auth_rules $rule_filters ORDER BY id LIMIT ? OFFSET ?";
  80. $params[]=$displayed;
  81. $params[]=$start;
  82. $t_auth_rules = get_records_sql($db_link,$rulesSQL, $params);
  83. foreach ( $t_auth_rules as $row ) {
  84. print "<tr align=center>\n";
  85. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value=".$row["id"]." ></td>\n";
  86. print "<td class=\"data\">";
  87. if ($row['type'] == 1) { print "Subnet"; }
  88. if ($row['type'] == 2) { print "Mac"; }
  89. if ($row['type'] == 3) { print "Hostname"; }
  90. print "</td>\n";
  91. print "<td class=\"data\">".$row['rule']."</td>\n";
  92. print "<td colspan=2 class=\"data\" align=left>";
  93. if (!empty($row['user_id'])) {
  94. $user_info=get_record_sql($db_link,"SELECT * FROM user_list WHERE id=?", [$row['user_id']]);
  95. if (!empty($user_info)) { print "User: &nbsp"; print_url($user_info['login'],'/admin/users/edituser.php?id='.$user_info['id']); }
  96. }
  97. if (!empty($row['ou_id'])) {
  98. $ou_info=get_record_sql($db_link,"SELECT * FROM ou WHERE id=?", [ $row['ou_id'] ]);
  99. if (!empty($ou_info)) { print "Group: &nbsp"; print_url($ou_info['ou_name'],'/admin/groups/edit_group.php?id='.$ou_info['id']); }
  100. }
  101. print "</td>";
  102. print "<td class=\"data\" colspan=2>".$row['description']."</td>\n";
  103. print "</tr>\n";
  104. }
  105. ?>
  106. </table>
  107. </form>
  108. <script>
  109. document.getElementById('rule_target').addEventListener('change', function(event) {
  110. const buttonApply = document.getElementById('btn_filter');
  111. buttonApply.click();
  112. });
  113. document.getElementById('rule_type').addEventListener('change', function(event) {
  114. const buttonApply = document.getElementById('btn_filter');
  115. buttonApply.click();
  116. });
  117. document.getElementById('rows').addEventListener('change', function(event) {
  118. const buttonApply = document.getElementById('btn_filter');
  119. buttonApply.click();
  120. });
  121. </script>
  122. <?php
  123. print_navigation($page_url,$page,$displayed,$count_records,$total);
  124. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  125. ?>