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