edit_rules.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
  5. global $default_user_id;
  6. global $hotspot_user_id;
  7. $msg_error = "";
  8. $sSQL = "SELECT * FROM User_list WHERE id=$id";
  9. $auth_info = get_record_sql($db_link, $sSQL);
  10. if (isset($_POST["s_remove"])) {
  11. $s_id = $_POST["s_id"];
  12. foreach ($s_id as $key => $val) {
  13. if (isset($val)) {
  14. LOG_INFO($db_link, "Remove rule id: $val");
  15. delete_record($db_link, "auth_rules", "id=" . $val);
  16. }
  17. }
  18. header("Location: " . $_SERVER["REQUEST_URI"]);
  19. }
  20. if (isset($_POST['s_save'])) {
  21. $len = is_array($_POST['s_save']) ? count($_POST['s_save']) : 0;
  22. for ($i = 0; $i < $len; $i ++) {
  23. $save_id = intval($_POST['s_save'][$i]);
  24. $len_all = is_array($_POST['n_id']) ? count($_POST['n_id']) : 0;
  25. for ($j = 0; $j < $len_all; $j ++) {
  26. if (intval($_POST['n_id'][$j]) != $save_id) { continue; }
  27. $new['type'] = $_POST['s_type'][$j];
  28. $new['rule'] = trim($_POST['s_rule'][$j]);
  29. update_record($db_link, "auth_rules", "id='{$save_id}'", $new);
  30. }
  31. }
  32. header("Location: " . $_SERVER["REQUEST_URI"]);
  33. }
  34. if (isset($_POST["s_create"])) {
  35. $new_rule = $_POST["s_new_rule"];
  36. if (isset($new_rule)) {
  37. $new['type'] = $_POST["s_new_type"];
  38. $new['rule'] = $new_rule;
  39. $new['user_id'] = $id;
  40. LOG_INFO($db_link, "Create new rule $new_rule");
  41. insert_record($db_link, "auth_rules", $new);
  42. }
  43. header("Location: " . $_SERVER["REQUEST_URI"]);
  44. }
  45. unset($_POST);
  46. global $default_user_id;
  47. global $hotspot_user_id;
  48. //cleanup hotspot subnet rules
  49. delete_record($db_link,"auth_rules","user_id=".$default_user_id);
  50. delete_record($db_link,"auth_rules","user_id=".$hotspot_user_id);
  51. $t_hotspot = get_records_sql($db_link,"subnets","hotspot=1");
  52. foreach ($t_hotspot as $row) { delete_record($db_link,"auth_rules","rule='".$row['subnet']."'"); }
  53. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  54. ?>
  55. <div id="cont">
  56. <br>
  57. <form name="def" action="edit_rules.php" method="post">
  58. <b>Правила автоназначения адресов в <?php print_url($auth_info['login'],"/admin/users/edituser.php?id=$id"); ?></b>
  59. <br>
  60. Порядок применения: hotspot => subnet => mac => hostname => default user
  61. <br><br>
  62. <table class="data">
  63. <tr align="center">
  64. <td></td>
  65. <td width=30><b>id</b></td>
  66. <td><b>Тип</b></td>
  67. <td><b>Правило</b></td>
  68. <td><input type="submit" name="s_remove" value="Удалить"></td>
  69. </tr>
  70. <?
  71. $t_auth_rules = get_records($db_link,'auth_rules',"user_id=$id ORDER BY id");
  72. foreach ( $t_auth_rules as $row ) {
  73. print "<tr align=center>\n";
  74. print "<td class=\"data\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
  75. print "<td class=\"data\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  76. print "<td class=\"data\">"; print_qa_rule_select("s_type[]","{$row['type']}"); print "</td>\n";
  77. print "<td class=\"data\"><input type=\"text\" name='s_rule[]' value='{$row['rule']}'></td>\n";
  78. print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>Сохранить</button></td>\n";
  79. print "</tr>\n";
  80. }
  81. ?>
  82. <tr>
  83. <td colspan=6>Новое правило :<?php print_qa_rule_select("s_new_type","1"); print "<input type=\"text\" name='s_new_rule' value=''>"; ?></td>
  84. <td><input type="submit" name="s_create" value="Добавить"></td>
  85. </tr>
  86. </table>
  87. </form>
  88. <?php
  89. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  90. ?>