auth_apply.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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"] = 1;
  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"] = 1;
  21. }
  22. if (empty($_POST["n_enabled"])) {
  23. $_POST["n_enabled"] = 0;
  24. }
  25. if (empty($_POST["n_link"])) {
  26. $_POST["n_link"] = 0;
  27. }
  28. if (empty($_POST["a_bind_mac"])) {
  29. $_POST["a_bind_mac"] = 0;
  30. }
  31. if (empty($_POST["a_bind_ip"])) {
  32. $_POST["a_bind_ip"] = 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_bind_mac = $_POST["a_bind_mac"]*1;
  41. $a_bind_ip = $_POST["a_bind_ip"]*1;
  42. $n_enabled = $_POST["n_enabled"] * 1;
  43. $n_link = $_POST["n_link"] * 1;
  44. $n_handler = $_POST["n_handler"];
  45. $msg = "Massive User change!";
  46. LOG_WARNING($db_link, $msg);
  47. $all_ok = 1;
  48. foreach ($auth_id as $key => $val) {
  49. if ($val) {
  50. unset($auth);
  51. if (isset($_POST["e_enabled"])) {
  52. //check user state
  53. if ($a_enabled) {
  54. $cur_auth = get_record_sql($db_link, "User_auth", "id=" . $val);
  55. if (!empty($cur_auth)) {
  56. $user_info = get_record_sql($db_link, "User_list", 'id=' . $cur_auth["user_id"]);
  57. if (!empty($user_info)) {
  58. $a_enabled = $user_info["enabled"];
  59. }
  60. }
  61. }
  62. $auth['enabled'] = $a_enabled;
  63. }
  64. if (isset($_POST["e_group_id"])) {
  65. $auth['filter_group_id'] = $a_group;
  66. }
  67. if (isset($_POST["e_queue_id"])) {
  68. $auth['queue_id'] = $a_queue;
  69. }
  70. if (isset($_POST["e_dhcp"])) {
  71. $auth['dhcp'] = $a_dhcp;
  72. }
  73. if (isset($_POST["e_dhcp_acl"])) {
  74. $auth['dhcp_acl'] = $a_dhcp_acl;
  75. }
  76. if (isset($_POST["e_traf"])) {
  77. $auth['save_traf'] = $a_traf;
  78. }
  79. //nagios
  80. if (isset($_POST["e_nag_enabled"])) {
  81. $auth['nagios'] = $n_enabled;
  82. }
  83. if (isset($_POST["e_nag_link"])) {
  84. $auth['link_check'] = $n_link;
  85. }
  86. if (isset($_POST["e_nag_handler"])) {
  87. $auth['nagios_handler'] = $n_handler;
  88. }
  89. if (!empty($auth)) {
  90. $ret = update_record($db_link, "User_auth", "id='" . $val . "'", $auth);
  91. if (!$ret) { $all_ok = 0; }
  92. }
  93. //bind mac rule
  94. if (isset($_POST["e_bind_mac"])) {
  95. $first_auth = get_record_sql($db_link,"SELECT user_id,mac FROM User_auth WHERE id=".$val);
  96. if (!empty($first_auth) and !empty($first_auth['mac'])) {
  97. if ($a_bind_mac) {
  98. $auth_rules_user = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE user_id=".$first_auth['user_id']." AND type=2");
  99. $auth_rules_mac = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE rule='".$first_auth['mac']."' AND type=2");
  100. if (empty($auth_rules_user) and empty($auth_rules_mac)) {
  101. $new['user_id']=$first_auth['user_id'];
  102. $new['type']=2;
  103. $new['rule']=$first_auth['mac'];
  104. insert_record($db_link,"auth_rules",$new);
  105. LOG_INFO($db_link,"Created auto rule for user_id: ".$first_auth['user_id']." and mac ".$first_auth['mac']);
  106. } else {
  107. LOG_INFO($db_link,"Auto rule for user_id: ".$first_auth['user_id']." and mac ".$first_auth['mac']." already exists");
  108. }
  109. } else {
  110. run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$first_auth['user_id']." AND type=2");
  111. LOG_INFO($db_link,"Remove auto rule for user_id: ".$first_auth['user_id']." and mac ".$first_auth['mac']);
  112. }
  113. } else {
  114. LOG_ERROR($db_link,"Auto rule for user_id: ".$first_auth['user_id']." not created. Record not found or empty mac.");
  115. }
  116. }
  117. //bind ip rule
  118. if (isset($_POST["e_bind_ip"])) {
  119. $first_auth = get_record_sql($db_link,"SELECT user_id,ip FROM User_auth WHERE id=".$val);
  120. if (!empty($first_auth) and !empty($first_auth['ip'])) {
  121. if ($a_bind_ip) {
  122. $auth_rules_user = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE user_id=".$first_auth['user_id']." AND type=1");
  123. $auth_rules_ip = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE rule='".$first_auth['ip']."' AND type=1");
  124. if (empty($auth_rules_user) and empty($auth_rules_ip)) {
  125. $new['user_id']=$first_auth['user_id'];
  126. $new['type']=1;
  127. $new['rule']=$first_auth['ip'];
  128. insert_record($db_link,"auth_rules",$new);
  129. LOG_INFO($db_link,"Created auto rule for user_id: ".$first_auth['user_id']." and ip ".$first_auth['ip']);
  130. } else {
  131. LOG_INFO($db_link,"Auto rule for user_id: ".$first_auth['user_id']." and ip ".$first_auth['ip']." already exists");
  132. }
  133. } else {
  134. run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$first_auth['user_id']." AND type=1");
  135. LOG_INFO($db_link,"Remove auto rule for user_id: ".$first_auth['user_id']." and ip ".$first_auth['ip']);
  136. }
  137. } else {
  138. LOG_ERROR($db_link,"Auto rule for user_id: ".$first_auth['user_id']." not created. Record not found or empty ip.");
  139. }
  140. }
  141. }
  142. }
  143. if ($all_ok) {
  144. print "Success!";
  145. } else {
  146. print "Fail!";
  147. }
  148. }