1
0

auth_apply.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_new_ou"])) {
  8. $_POST["a_new_ou"] = 0;
  9. }
  10. if (empty($_POST["a_enabled"])) {
  11. $_POST["a_enabled"] = 0;
  12. }
  13. if (empty($_POST["a_dhcp"])) {
  14. $_POST["a_dhcp"] = 0;
  15. }
  16. if (empty($_POST["a_queue_id"])) {
  17. $_POST["a_queue_id"] = 0;
  18. }
  19. if (empty($_POST["a_group_id"])) {
  20. $_POST["a_group_id"] = 0;
  21. }
  22. if (empty($_POST["a_traf"])) {
  23. $_POST["a_traf"] = 0;
  24. }
  25. if (empty($_POST["n_enabled"])) {
  26. $_POST["n_enabled"] = 0;
  27. }
  28. if (empty($_POST["n_link"])) {
  29. $_POST["n_link"] = 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_ou_id = $_POST["a_new_ou"] * 1;
  38. $a_enabled = $_POST["a_enabled"] * 1;
  39. $a_dhcp = $_POST["a_dhcp"] * 1;
  40. $a_dhcp_acl = trim($_POST["a_dhcp_acl"]);
  41. $a_dhcp_option_set = trim($_POST["a_dhcp_option_set"]);
  42. $a_queue = $_POST["a_queue_id"] * 1;
  43. $a_group = $_POST["a_group_id"] * 1;
  44. $a_traf = $_POST["a_traf"] * 1;
  45. $a_bind_mac = $_POST["a_bind_mac"]*1;
  46. $a_bind_ip = $_POST["a_bind_ip"]*1;
  47. $n_enabled = $_POST["n_enabled"] * 1;
  48. $n_link = $_POST["n_link"] * 1;
  49. $n_handler = $_POST["n_handler"];
  50. $msg = "Massive User change!";
  51. LOG_WARNING($db_link, $msg);
  52. $all_ok = 1;
  53. foreach ($auth_id as $key => $val) {
  54. if ($val) {
  55. unset($auth);
  56. //check user state
  57. $cur_auth = get_record_sql($db_link, "SELECT * FROM User_auth WHERE `id`=" . $val);
  58. if (!empty($cur_auth)) { $user_info = get_record_sql($db_link, "SELECT * FROM User_list WHERE `id`=" . $cur_auth["user_id"]); }
  59. if (isset($_POST["e_enabled"])) {
  60. if (!empty($user_info)) { $a_enabled = $user_info["enabled"] * $a_enabled; }
  61. $auth['enabled'] = $a_enabled;
  62. }
  63. if (isset($_POST["e_group_id"])) {
  64. $auth['filter_group_id'] = $a_group;
  65. }
  66. if (isset($_POST["e_queue_id"])) {
  67. $auth['queue_id'] = $a_queue;
  68. }
  69. if (isset($_POST["e_dhcp"])) {
  70. $auth['dhcp'] = $a_dhcp;
  71. }
  72. if (isset($_POST["e_dhcp_acl"])) {
  73. $auth['dhcp_acl'] = $a_dhcp_acl;
  74. }
  75. if (isset($_POST["e_dhcp_option_set"])) {
  76. $auth['dhcp_option_set'] = $a_dhcp_option_set;
  77. }
  78. if (isset($_POST["e_traf"])) {
  79. $auth['save_traf'] = $a_traf;
  80. }
  81. //nagios
  82. if (isset($_POST["e_nag_enabled"])) {
  83. $auth['nagios'] = $n_enabled;
  84. }
  85. if (isset($_POST["e_nag_link"])) {
  86. $auth['link_check'] = $n_link;
  87. }
  88. if (isset($_POST["e_nag_handler"])) {
  89. $auth['nagios_handler'] = $n_handler;
  90. }
  91. if (!empty($auth)) {
  92. $ret = update_record($db_link, "User_auth", "id='" . $val . "'", $auth);
  93. if (!$ret) { $all_ok = 0; }
  94. }
  95. //change user group
  96. if (isset($_POST["e_new_ou"]) and !empty($a_ou_id) and !empty($user_info)) {
  97. $user['ou_id'] = $a_ou_id;
  98. $u_auth['ou_id'] = $a_ou_id;
  99. //change user group
  100. $msg = " For user id: " . $cur_auth['user_id'] . " login: " . $user_info['login'] . " set: ou_id = ".$a_ou_id;
  101. LOG_INFO($db_link,$msg);
  102. $ret = update_record($db_link, "User_list", "id='" . $cur_auth['user_id'] . "'", $user);
  103. if (!$ret) { $all_ok = 0; }
  104. //change user ip
  105. $auth_list = get_records_sql($db_link, "SELECT * FROM User_auth WHERE user_id=" . $cur_auth['user_id']);
  106. if (!empty($auth_list)) {
  107. foreach ($auth_list as $row) {
  108. if (empty($row)) { continue; }
  109. $ret = update_record($db_link, "User_auth", "id='" . $row["id"] . "'", $u_auth);
  110. if (!$ret) { $all_ok = 0; }
  111. }
  112. }
  113. unset($user);
  114. }
  115. //bind mac rule
  116. if (isset($_POST["e_bind_mac"])) {
  117. $first_auth = get_record_sql($db_link,"SELECT user_id,mac FROM User_auth WHERE id=".$val);
  118. if (!empty($first_auth) and !empty($first_auth['mac'])) {
  119. if ($a_bind_mac) {
  120. $auth_rules_user = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE user_id=".$first_auth['user_id']." AND type=2");
  121. $auth_rules_mac = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE rule='".$first_auth['mac']."' AND type=2");
  122. if (empty($auth_rules_user) and empty($auth_rules_mac)) {
  123. $new['user_id']=$first_auth['user_id'];
  124. $new['type']=2;
  125. $new['rule']=$first_auth['mac'];
  126. insert_record($db_link,"auth_rules",$new);
  127. LOG_INFO($db_link,"Created auto rule for user_id: ".$first_auth['user_id']." and mac ".$first_auth['mac']);
  128. } else {
  129. LOG_INFO($db_link,"Auto rule for user_id: ".$first_auth['user_id']." and mac ".$first_auth['mac']." already exists");
  130. }
  131. } else {
  132. run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$first_auth['user_id']." AND type=2");
  133. LOG_INFO($db_link,"Remove auto rule for user_id: ".$first_auth['user_id']." and mac ".$first_auth['mac']);
  134. }
  135. } else {
  136. LOG_ERROR($db_link,"Auto rule for user_id: ".$first_auth['user_id']." not created. Record not found or empty mac.");
  137. }
  138. }
  139. //bind ip rule
  140. if (isset($_POST["e_bind_ip"])) {
  141. $first_auth = get_record_sql($db_link,"SELECT user_id,ip FROM User_auth WHERE id=".$val);
  142. if (!empty($first_auth) and !empty($first_auth['ip'])) {
  143. if ($a_bind_ip) {
  144. $auth_rules_user = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE user_id=".$first_auth['user_id']." AND type=1");
  145. $auth_rules_ip = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE rule='".$first_auth['ip']."' AND type=1");
  146. if (empty($auth_rules_user) and empty($auth_rules_ip)) {
  147. $new['user_id']=$first_auth['user_id'];
  148. $new['type']=1;
  149. $new['rule']=$first_auth['ip'];
  150. insert_record($db_link,"auth_rules",$new);
  151. LOG_INFO($db_link,"Created auto rule for user_id: ".$first_auth['user_id']." and ip ".$first_auth['ip']);
  152. } else {
  153. LOG_INFO($db_link,"Auto rule for user_id: ".$first_auth['user_id']." and ip ".$first_auth['ip']." already exists");
  154. }
  155. } else {
  156. run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$first_auth['user_id']." AND type=1");
  157. LOG_INFO($db_link,"Remove auto rule for user_id: ".$first_auth['user_id']." and ip ".$first_auth['ip']);
  158. }
  159. } else {
  160. LOG_ERROR($db_link,"Auto rule for user_id: ".$first_auth['user_id']." not created. Record not found or empty ip.");
  161. }
  162. }
  163. }
  164. }
  165. if ($all_ok) {
  166. print "Success!";
  167. } else {
  168. print "Fail!";
  169. }
  170. }