auto_rules.php 4.7 KB

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