user_apply.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. if (empty($_POST["a_bind_ip"])) {
  35. $_POST["a_bind_ip"] = 0;
  36. }
  37. $a_enabled = $_POST["a_enabled"] * 1;
  38. $a_dhcp = $_POST["a_dhcp"] * 1;
  39. $a_dhcp_acl = $_POST["a_dhcp_acl"];
  40. $a_queue = $_POST["a_queue_id"] * 1;
  41. $a_group = $_POST["a_group_id"] * 1;
  42. $a_traf = $_POST["a_traf"] * 1;
  43. $a_day = $_POST["a_day_q"] * 1;
  44. $a_month = $_POST["a_month_q"] * 1;
  45. $a_ou_id = $_POST["a_new_ou"] * 1;
  46. $a_bind_mac = $_POST["a_bind_mac"] * 1;
  47. $a_bind_ip = $_POST["a_bind_ip"] * 1;
  48. $msg = "Massive User change!";
  49. LOG_WARNING($db_link, $msg);
  50. $all_ok = 1;
  51. foreach ($auth_id as $key => $val) {
  52. if ($val) {
  53. unset($auth);
  54. unset($user);
  55. if (isset($_POST["e_enabled"])) {
  56. $auth['enabled'] = $a_enabled;
  57. $user['enabled'] = $a_enabled;
  58. }
  59. if (isset($_POST["e_group_id"])) {
  60. $auth['filter_group_id'] = $a_group;
  61. }
  62. if (isset($_POST["e_queue_id"])) {
  63. $auth['queue_id'] = $a_queue;
  64. }
  65. if (isset($_POST["e_dhcp"])) {
  66. $auth['dhcp'] = $a_dhcp;
  67. }
  68. if (isset($_POST["e_dhcp_acl"])) {
  69. $auth['dhcp_acl'] = $a_dhcp_acl;
  70. }
  71. if (isset($_POST["e_traf"])) {
  72. $auth['save_traf'] = $a_traf;
  73. }
  74. if (isset($_POST["e_day_q"])) {
  75. $user['day_quota'] = $a_day;
  76. }
  77. if (isset($_POST["e_month_q"])) {
  78. $user['month_quota'] = $a_month;
  79. }
  80. if (isset($_POST["e_new_ou"])) {
  81. $user['ou_id'] = $a_ou_id;
  82. $auth['ou_id'] = $a_ou_id;
  83. }
  84. $login = get_record($db_link, "User_list", "id='$val'");
  85. $msg .= " For all ip user id: " . $val . " login: " . $login['login'] . " set: ";
  86. $msg .= get_diff_rec($db_link, "User_list", "id='$val'", $user, 1);
  87. $ret = update_record($db_link, "User_list", "id='" . $val . "'", $user);
  88. if (!$ret) {
  89. $all_ok = 0;
  90. }
  91. $auth_list = get_records_sql($db_link, "SELECT id, mac, ip FROM User_auth WHERE deleted=0 AND user_id=" . $val);
  92. $b_mac = '';
  93. $b_ip = '';
  94. if (!empty($auth_list)) {
  95. foreach ($auth_list as $row) {
  96. if (empty($row)) {
  97. continue;
  98. }
  99. if (empty($b_mac) and !empty($row["mac"])) {
  100. $b_mac = $row["mac"];
  101. }
  102. if (empty($b_ip) and !empty($row["ip"])) {
  103. $b_ip = $row["ip"];
  104. }
  105. $ret = update_record($db_link, "User_auth", "id='" . $row["id"] . "'", $auth);
  106. if (!$ret) {
  107. $all_ok = 0;
  108. }
  109. }
  110. }
  111. //bind mac rule
  112. if (isset($_POST["e_bind_mac"])) {
  113. if ($a_bind_mac) {
  114. if (!empty($b_mac)) {
  115. $auth_rules_user = get_record_sql($db_link, "SELECT * FROM auth_rules WHERE user_id=" . $val . " AND type=2");
  116. $auth_rules_mac = get_record_sql($db_link, "SELECT * FROM auth_rules WHERE rule='" . $b_mac . "' AND type=2");
  117. if (empty($auth_rules_user) and empty($auth_rules_mac)) {
  118. $new['user_id'] = $val;
  119. $new['type'] = 2;
  120. $new['rule'] = $b_mac;
  121. insert_record($db_link, "auth_rules", $new);
  122. LOG_INFO($db_link, "Created auto rule for user_id: " . $val . " and mac " . $b_mac);
  123. } else {
  124. LOG_INFO($db_link, "Auto rule for user_id: " . $val . " and mac " . $mac . " already exists");
  125. }
  126. }
  127. } else {
  128. run_sql($db_link, "DELETE FROM auth_rules WHERE user_id=" . $val . " AND type=2");
  129. LOG_INFO($db_link, "Remove auto rule for user_id: " . $val . " and mac " . $b_mac);
  130. }
  131. }
  132. //bind ip rule
  133. if (isset($_POST["e_bind_ip"])) {
  134. if ($a_bind_ip) {
  135. if (!empty($b_ip)) {
  136. $auth_rules_user = get_record_sql($db_link, "SELECT * FROM auth_rules WHERE user_id=" . $val . " AND type=1");
  137. $auth_rules_ip = get_record_sql($db_link, "SELECT * FROM auth_rules WHERE rule='" . $b_ip . "' AND type=1");
  138. if (empty($auth_rules_user) and empty($auth_rules_ip)) {
  139. $new['user_id'] = $val;
  140. $new['type'] = 1;
  141. $new['rule'] = $b_ip;
  142. insert_record($db_link, "auth_rules", $new);
  143. LOG_INFO($db_link, "Created auto rule for user_id: " . $val . " and ip " . $b_ip);
  144. } else {
  145. LOG_INFO($db_link, "Auto rule for user_id: " . $val . " and ip " . $ip . " already exists");
  146. }
  147. }
  148. } else {
  149. run_sql($db_link, "DELETE FROM auth_rules WHERE user_id=" . $val . " AND type=1");
  150. LOG_INFO($db_link, "Remove auto rule for user_id: " . $val . " and ip " . $b_ip);
  151. }
  152. }
  153. }
  154. }
  155. if ($all_ok) {
  156. print "Success!";
  157. } else {
  158. print "Fail!";
  159. }
  160. }