edit_rules.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. $msg_error = "";
  6. $sSQL = "SELECT * FROM User_list WHERE id=$id";
  7. $auth_info = get_record_sql($db_link, $sSQL);
  8. if (isset($_POST["s_remove"])) {
  9. $s_id = $_POST["s_id"];
  10. foreach ($s_id as $key => $val) {
  11. if (isset($val)) {
  12. LOG_INFO($db_link, "Remove rule id: $val");
  13. delete_record($db_link, "auth_rules", "id=" . $val);
  14. }
  15. }
  16. header("Location: " . $_SERVER["REQUEST_URI"]);
  17. exit;
  18. }
  19. if (isset($_POST['s_save'])) {
  20. $len = is_array($_POST['s_save']) ? count($_POST['s_save']) : 0;
  21. for ($i = 0; $i < $len; $i ++) {
  22. $save_id = intval($_POST['s_save'][$i]);
  23. $len_all = is_array($_POST['n_id']) ? count($_POST['n_id']) : 0;
  24. for ($j = 0; $j < $len_all; $j ++) {
  25. if (intval($_POST['n_id'][$j]) != $save_id) { continue; }
  26. $new['type'] = $_POST['s_type'][$j];
  27. $new['rule'] = trim($_POST['s_rule'][$j]);
  28. if ($new['type'] ==2) {
  29. $new['rule'] = mac_dotted($new['rule']);
  30. }
  31. update_record($db_link, "auth_rules", "id='{$save_id}'", $new);
  32. }
  33. }
  34. header("Location: " . $_SERVER["REQUEST_URI"]);
  35. exit;
  36. }
  37. if (isset($_POST["s_create"])) {
  38. $new_rule = $_POST["s_new_rule"];
  39. if (isset($new_rule)) {
  40. $new['type'] = $_POST["s_new_type"];
  41. $new['rule'] = $new_rule;
  42. $new['user_id'] = $id;
  43. LOG_INFO($db_link, "Create new rule $new_rule");
  44. insert_record($db_link, "auth_rules", $new);
  45. }
  46. header("Location: " . $_SERVER["REQUEST_URI"]);
  47. exit;
  48. }
  49. unset($_POST);
  50. fix_auth_rules($db_link);
  51. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  52. ?>
  53. <div id="cont">
  54. <br>
  55. <form name="def" action="edit_rules.php?id=<?php echo $id; ?>" method="post">
  56. <b><?php print WEB_ou_rules_for_autoassigning."&nbsp"; print_url($auth_info['login'],"/admin/users/edituser.php?id=$id"); ?></b>
  57. <br>
  58. <?php echo WEB_ou_rules_order; ?>: hotspot => subnet => mac => hostname => default user
  59. <br><br>
  60. <table class="data">
  61. <tr align="center">
  62. <td></td>
  63. <td width=30><b>id</b></td>
  64. <td><b><?php echo WEB_cell_type; ?></b></td>
  65. <td><b><?php echo WEB_ou_rule; ?></b></td>
  66. <td><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="s_remove" value="<?php echo WEB_btn_delete; ?>"></td>
  67. </tr>
  68. <?php
  69. $t_auth_rules = get_records($db_link,'auth_rules',"user_id=$id ORDER BY id");
  70. foreach ( $t_auth_rules as $row ) {
  71. print "<tr align=center>\n";
  72. print "<td class=\"data\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
  73. print "<td class=\"data\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  74. print "<td class=\"data\">"; print_qa_rule_select("s_type[]","{$row['type']}"); print "</td>\n";
  75. print "<td class=\"data\"><input type=\"text\" name='s_rule[]' value='{$row['rule']}'></td>\n";
  76. print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>".WEB_btn_save."</button></td>\n";
  77. print "</tr>\n";
  78. }
  79. ?>
  80. </table>
  81. <div>
  82. <?php print WEB_ou_new_rule."&nbsp"; print_qa_rule_select("s_new_type","1");
  83. print "<input type=\"text\" name='s_new_rule' value=''>"; ?>
  84. <input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>">
  85. </div>
  86. </form>
  87. <?php
  88. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  89. ?>