user_apply.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
  3. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
  4. if (!defined("CONFIG")) die("Not defined");
  5. if (isset($_POST["ApplyForAll"])) {
  6. $auth_id = $_POST["fid"];
  7. if (empty($_POST["a_enabled"])) {
  8. $_POST["a_enabled"] = 0;
  9. }
  10. if (empty($_POST["a_dhcp"])) {
  11. $_POST["a_dhcp"] = 0;
  12. }
  13. if (empty($_POST["a_queue_id"])) {
  14. $_POST["a_queue_id"] = 0;
  15. }
  16. if (empty($_POST["a_group_id"])) {
  17. $_POST["a_group_id"] = 0;
  18. }
  19. if (empty($_POST["a_traf"])) {
  20. $_POST["a_traf"] = 0;
  21. }
  22. if (empty($_POST["a_day_q"])) {
  23. $_POST["a_day_q"] = 0;
  24. }
  25. if (empty($_POST["a_month_q"])) {
  26. $_POST["a_month_q"] = 0;
  27. }
  28. if (empty($_POST["a_new_ou"])) {
  29. $_POST["a_new_ou"] = 0;
  30. }
  31. if (empty($_POST["a_bind_mac"])) {
  32. $_POST["a_bind_mac"] = 0;
  33. }
  34. $a_enabled = $_POST["a_enabled"] * 1;
  35. $a_dhcp = $_POST["a_dhcp"] * 1;
  36. $a_dhcp_acl = $_POST["a_dhcp_acl"];
  37. $a_queue = $_POST["a_queue_id"] * 1;
  38. $a_group = $_POST["a_group_id"] * 1;
  39. $a_traf = $_POST["a_traf"] * 1;
  40. $a_day = $_POST["a_day_q"] * 1;
  41. $a_month = $_POST["a_month_q"] * 1;
  42. $a_ou_id = $_POST["a_new_ou"] * 1;
  43. $a_bind_mac = $_POST["a_bind_mac"] * 1;
  44. $msg = "Massive User change!";
  45. LOG_WARNING($db_link, $msg);
  46. $all_ok = 1;
  47. foreach ($auth_id as $key => $val) {
  48. if ($val) {
  49. unset($auth);
  50. unset($user);
  51. if (isset($_POST["e_enabled"])) {
  52. $auth['enabled'] = $a_enabled;
  53. $user['enabled'] = $a_enabled;
  54. }
  55. if (isset($_POST["e_group_id"])) {
  56. $auth['filter_group_id'] = $a_group;
  57. }
  58. if (isset($_POST["e_queue_id"])) {
  59. $auth['queue_id'] = $a_queue;
  60. }
  61. if (isset($_POST["e_dhcp"])) {
  62. $auth['dhcp'] = $a_dhcp;
  63. }
  64. if (isset($_POST["e_dhcp_acl"])) {
  65. $auth['dhcp_acl'] = $a_dhcp_acl;
  66. }
  67. if (isset($_POST["e_traf"])) {
  68. $auth['save_traf'] = $a_traf;
  69. }
  70. if (isset($_POST["e_day_q"])) {
  71. $user['day_quota'] = $a_day;
  72. }
  73. if (isset($_POST["e_month_q"])) {
  74. $user['month_quota'] = $a_month;
  75. }
  76. if (isset($_POST["e_new_ou"])) {
  77. $user['ou_id'] = $a_ou_id;
  78. $auth['ou_id'] = $a_ou_id;
  79. }
  80. $login = get_record($db_link, "User_list", "id='$val'");
  81. $msg .= " For all ip user id: " . $val . " login: " . $login['login'] . " set: ";
  82. $msg .= get_diff_rec($db_link, "User_list", "id='$val'", $user, 1);
  83. $ret = update_record($db_link, "User_list", "id='" . $val . "'", $user);
  84. if (!$ret) {
  85. $all_ok = 0;
  86. }
  87. $auth_list = get_records_sql($db_link, "SELECT id, mac FROM User_auth WHERE deleted=0 AND user_id=" . $val);
  88. $b_mac = '';
  89. if (!empty($auth)) {
  90. foreach ($auth_list as $row) {
  91. if (empty($row)) {
  92. continue;
  93. }
  94. if (empty($b_mac) and !empty($row["mac"])) {
  95. $b_mac = $row["mac"];
  96. }
  97. $ret = update_record($db_link, "User_auth", "id='" . $row["id"] . "'", $auth);
  98. if (!$ret) {
  99. $all_ok = 0;
  100. }
  101. }
  102. }
  103. //bind mac rule
  104. if (isset($_POST["e_bind_mac"])) {
  105. if ($a_bind_mac and !empty($b_mac)) {
  106. $auth_rules_user = get_record_sql($db_link, "SELECT * FROM auth_rules WHERE user_id=" . $val . " AND type=2");
  107. $auth_rules_mac = get_record_sql($db_link, "SELECT * FROM auth_rules WHERE rule='" . $b_mac . "' AND type=2");
  108. if (empty($auth_rules_user) and empty($auth_rules_mac)) {
  109. $new['user_id'] = $val;
  110. $new['type'] = 2;
  111. $new['rule'] = $b_mac;
  112. insert_record($db_link, "auth_rules", $new);
  113. LOG_INFO($db_link, "Created auto rule for user_id: " . $val . " and mac " . $b_mac);
  114. } else {
  115. LOG_INFO($db_link, "Auto rule for user_id: " . $val . " and mac " . $mac . " already exists");
  116. }
  117. } else {
  118. run_sql($db_link, "DELETE FROM auth_rules WHERE user_id=" . $val . " AND type=2");
  119. LOG_INFO($db_link, "Remove auto rule for user_id: " . $val . " and mac " . $b_mac);
  120. }
  121. }
  122. }
  123. }
  124. if ($all_ok) {
  125. print "Success!";
  126. } else {
  127. print "Fail!";
  128. }
  129. }