editauth.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
  5. global $default_user_id;
  6. global $hotspot_user_id;
  7. $msg_error = "";
  8. $sSQL = "SELECT * FROM User_auth WHERE id=$id";
  9. $old_auth_info = get_record_sql($db_link, $sSQL);
  10. if (isset($_POST["editauth"]) and !$old_auth_info[deleted]) {
  11. $ip = trim($_POST["f_ip"]);
  12. if (checkValidIp($ip)) {
  13. $mac=mac_dotted($_POST["f_mac"]);
  14. $mac_exists=find_mac_in_subnet($db_link,$ip,$mac);
  15. if (isset($mac_exists) and $mac_exists['count']==1 and $mac_exists['1']!=$id) {
  16. LOG_ERROR($db_link, "Mac $mac already exists in this subnet! Skip creating $ip [$mac] auth_id: ".$mac_exists['1']);
  17. header("Location: " . $_SERVER["REQUEST_URI"]);
  18. exit;
  19. }
  20. if (isset($mac_exists) and $mac_exists['count']>1) {
  21. LOG_ERROR($db_link, "Mac $mac already exists in this subnet! Skip creating $ip [$mac] auth_id: ".$mac_exists['2']);
  22. header("Location: " . $_SERVER["REQUEST_URI"]);
  23. exit;
  24. }
  25. $range = cidrToRange($ip);
  26. $first_user_ip = $range[0];
  27. $last_user_ip = $range[1];
  28. $cidr = $range[2][1];
  29. if (isset($cidr) and $cidr < 32) {
  30. $ip = $first_user_ip . '/' . $cidr;
  31. } else {
  32. $ip = $first_user_ip;
  33. }
  34. $ip_aton = ip2long($first_user_ip);
  35. $ip_aton_end = ip2long($last_user_ip);
  36. list ($parent_id) = mysqli_fetch_array(mysqli_query($db_link, "Select user_id from User_auth where id=$id"));
  37. list ($lid) = mysqli_fetch_array(mysqli_query($db_link, "Select user_id from User_auth where ($ip_aton BETWEEN ip_int and ip_int_end) and id<>$id and deleted=0"));
  38. if (isset($lid) and ($lid != $parent_id)) {
  39. list ($lname) = mysqli_fetch_array(mysqli_query($db_link, "Select login from User_list where id=$lid"));
  40. $msg_error = "$ip $msg_exists Принадлежит пользователю $lname.";
  41. unset($_POST);
  42. } else {
  43. $new[ip] = $ip;
  44. $new[ip_int] = $ip_aton;
  45. $new[ip_int_end] = $ip_aton_end;
  46. $new[mac] = mac_dotted($_POST["f_mac"]);
  47. $new[clientid] = $_POST["f_clientid"];
  48. $new[comments] = $_POST["f_comments"];
  49. $f_dnsname=trim($_POST["f_dns_name"]);
  50. if (!empty($f_dnsname) and checkValidHostname($f_dnsname) and checkUniqHostname($db_link,$id,$f_dnsname)) { $new[dns_name] = $f_dnsname; }
  51. if (empty($f_dnsname)) { $new[dns_name] = ''; }
  52. $new[host_model] = $_POST["f_host_model"];
  53. $new[save_traf] = $_POST["f_save_traf"] * 1;
  54. $new[dhcp_acl] = trim($_POST["f_acl"]);
  55. if ($default_user_id == $parent_id or $hotspot_user_id == $parent_id) {
  56. $new[nagios_handler] = '';
  57. $new[enabled] = 0;
  58. $new[link_check] = 0;
  59. $new[nagios] = 0;
  60. $new[blocked] = 0;
  61. $new[day_quota] = 0;
  62. $new[month_quota] = 0;
  63. $new[queue_id] = 0;
  64. $new[filter_group_id] = 0;
  65. } else {
  66. $new[nagios_handler] = $_POST["f_handler"];
  67. $new[enabled] = $_POST["f_enabled"] * 1;
  68. $new[link_check] = $_POST["f_link"] * 1;
  69. $new[nagios] = $_POST["f_nagios"] * 1;
  70. $new[dhcp] = $_POST["f_dhcp"] * 1;
  71. $new[blocked] = $_POST["f_blocked"] * 1;
  72. $new[day_quota] = $_POST["f_day_q"] * 1;
  73. $new[month_quota] = $_POST["f_month_q"] * 1;
  74. $new[queue_id] = $_POST["f_queue_id"] * 1;
  75. $new[filter_group_id] = $_POST["f_group_id"] * 1;
  76. }
  77. $changes = get_diff_rec($db_link,"User_auth","id='$id'", $new, 1);
  78. if (!empty($changes)) { LOG_WARNING($db_link,"Изменен адрес доступа! Список изменений: $changes"); }
  79. update_record($db_link, "User_auth", "id='$id'", $new);
  80. }
  81. } else {
  82. $msg_error = "$msg_ip_error xxx.xxx.xxx.xxx/xx";
  83. }
  84. header("Location: " . $_SERVER["REQUEST_URI"]);
  85. }
  86. if (isset($_POST["moveauth"]) and !$old_auth_info[deleted]) {
  87. $new[user_id] = $_POST["new_parent"];
  88. $changes = get_diff_rec($db_link,"User_auth","id='$id'", $new, 1);
  89. if (!empty($changes)) { LOG_WARNING($db_link,"Адрес доступа перемещён к другому пользователю! Применено: $changes"); }
  90. update_record($db_link, "User_auth", "id='$id'", $new);
  91. header("Location: " . $_SERVER["REQUEST_URI"]);
  92. }
  93. if (isset($_POST["recovery"])) {
  94. $ip = trim($_POST["f_ip"]);
  95. if (checkValidIp($ip)) {
  96. $range = cidrToRange($ip);
  97. $first_user_ip = $range[0];
  98. $last_user_ip = $range[1];
  99. $cidr = $range[2][1];
  100. if (isset($cidr) and $cidr < 32) {
  101. $ip = $first_user_ip . '/' . $cidr;
  102. } else {
  103. $ip = $first_user_ip;
  104. }
  105. $ip_aton = ip2long($first_user_ip);
  106. $ip_aton_end = ip2long($last_user_ip);
  107. list ($parent_id) = mysqli_fetch_array(mysqli_query($db_link, "Select user_id from User_auth where id=$id"));
  108. list ($lid) = mysqli_fetch_array(mysqli_query($db_link, "Select user_id from User_auth where ($ip_aton BETWEEN ip_int and ip_int_end) and id<>$id and deleted=0"));
  109. if (isset($lid) and ($lid != $parent_id)) {
  110. list ($lname) = mysqli_fetch_array(mysqli_query($db_link, "Select login from User_list where id=$lid"));
  111. $msg_error = "$ip $msg_exists Принадлежит пользователю $lname.";
  112. unset($_POST);
  113. } else {
  114. $new[deleted] = 0;
  115. if ($default_user_id == $parent_id or $hotspot_user_id == $parent_id) {
  116. $new[nagios_handler] = '';
  117. $new[enabled] = 0;
  118. $new[link_check] = 0;
  119. $new[nagios] = 0;
  120. $new[blocked] = 0;
  121. $new[day_quota] = 0;
  122. $new[month_quota] = 0;
  123. $new[queue_id] = 0;
  124. $new[filter_group_id] = 0;
  125. } else {
  126. $new[nagios_handler] = $_POST["f_handler"];
  127. $new[enabled] = $_POST["f_enabled"] * 1;
  128. $new[link_check] = $_POST["f_link"] * 1;
  129. $new[nagios] = $_POST["f_nagios"] * 1;
  130. $new[dhcp] = $_POST["f_dhcp"] * 1;
  131. $new[blocked] = $_POST["f_blocked"] * 1;
  132. $new[day_quota] = $_POST["f_day_q"] * 1;
  133. $new[month_quota] = $_POST["f_month_q"] * 1;
  134. $new[queue_id] = $_POST["f_queue_id"] * 1;
  135. $new[filter_group_id] = $_POST["f_group_id"] * 1;
  136. }
  137. $changes = get_diff_rec($db_link,"User_auth","id='$id'", $new, 1);
  138. if (!empty($changes)) { LOG_WARNING($db_link,"Восстановлен адрес доступа! Применено: $changes"); }
  139. update_record($db_link, "User_auth", "id='$id'", $new);
  140. }
  141. } else {
  142. $msg_error = "$msg_ip_error xxx.xxx.xxx.xxx/xx";
  143. }
  144. header("Location: " . $_SERVER["REQUEST_URI"]);
  145. }
  146. unset($_POST);
  147. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  148. $sSQL = "SELECT * FROM User_auth WHERE id=$id";
  149. $auth_info = get_record_sql($db_link, $sSQL);
  150. $parent_name = get_login($db_link, $auth_info[user_id]);
  151. if ($auth_info[dhcp_time] == '0000-00-00 00:00:00') { $dhcp_str = ''; } else { $dhcp_str = $auth_info[dhcp_time] . " (" . $auth_info[dhcp_action] . ")"; }
  152. if ($auth_info[last_found] == '0000-00-00 00:00:00') { $auth_info[last_found] = ''; }
  153. ?>
  154. <div id="cont">
  155. <?
  156. print "<b> Адрес доступа пользователя <a href=/admin/users/edituser.php?id=$auth_info[user_id]>$parent_name</a> <b>";
  157. ?>
  158. <form name="def" action="editauth.php?id=<? echo $id; ?>" method="post">
  159. <input type="hidden" name="id" value=<? echo $id; ?>>
  160. <table class="data">
  161. <tr>
  162. <td width=200><?php print $cell_dns_name." &nbsp | &nbsp "; print_url("Альясы","/admin/users/edit_alias.php?id=$id"); ?></td>
  163. <td width=200><?php print $cell_comment; ?></td>
  164. <td width=70><?php print $cell_enabled; ?></td>
  165. <td width=70><?php print $cell_blocked; ?></td>
  166. <td width=70><?php print $cell_perday; ?></td>
  167. <td width=70><?php print $cell_permonth; ?></td>
  168. <td width=70><?php print $cell_connection; ?></td>
  169. </tr>
  170. <tr>
  171. <td><input type="text" name="f_dns_name" value="<? echo $auth_info[dns_name]; ?>" pattern="^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$"></td>
  172. <td><input type="text" name="f_comments" value="<? echo $auth_info[comments]; ?>"></td>
  173. <td><?php print_qa_select('f_enabled', $auth_info[enabled]); ?></td>
  174. <td><?php print_qa_select('f_blocked', $auth_info[blocked]); ?></td>
  175. <td><input type="text" name="f_day_q" value="<? echo $auth_info[day_quota]; ?>" size=5></td>
  176. <td><input type="text" name="f_month_q" value="<? echo $auth_info[month_quota]; ?>" size=5></td>
  177. <td><?php print get_connection($db_link, $id); ?></td>
  178. </tr>
  179. <tr>
  180. <td><?php print $cell_ip; ?></td>
  181. <td><?php print $cell_mac; ?></td>
  182. <td><?php print $cell_clientid; ?></td>
  183. <td><?php print $cell_dhcp; ?></td>
  184. <td><?php print $cell_filter; ?></td>
  185. <td><?php print $cell_shaper; ?></td>
  186. <td></td>
  187. <tr>
  188. <td><input type="text" name="f_ip" value="<? echo $auth_info[ip]; ?>" pattern="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"></td>
  189. <td><input type="text" name="f_mac" value="<? echo $auth_info[mac]; ?>"></td>
  190. <td><input type="text" name="f_clientid" value="<? echo $auth_info[clientid]; ?>"></td>
  191. <td><?php print_qa_select('f_dhcp', $auth_info[dhcp]); ?></td>
  192. <td><?php print_group_select($db_link, 'f_group_id', $auth_info[filter_group_id]); ?> </td>
  193. <td><?php print_queue_select($db_link, 'f_queue_id', $auth_info[queue_id]); ?> </td>
  194. <td></td>
  195. </tr>
  196. <tr>
  197. <td><?php print $cell_host_model; ?></td>
  198. <td><?php print $cell_nagios_handler; ?></td>
  199. <td><?php print $cell_acl; ?></td>
  200. <td><?php print $cell_nagios; ?></td>
  201. <td><?php print $cell_link; ?></td>
  202. <td><?php print $cell_traf; ?></td>
  203. <td></td>
  204. <tr>
  205. <td><input type="text" name="f_host_model" value="<? echo $auth_info[host_model]; ?>"></td>
  206. <td><input type="text" name="f_handler" value="<? echo $auth_info[nagios_handler]; ?>"></td>
  207. <td><input type="text" name="f_acl" value="<? echo $auth_info[dhcp_acl]; ?>"></td>
  208. <td><?php print_qa_select('f_nagios', $auth_info[nagios]); ?></td>
  209. <td><?php print_qa_select('f_link', $auth_info[link_check]); ?></td>
  210. <td><?php print_qa_select('f_save_traf', $auth_info[save_traf]); ?></td>
  211. <td></td>
  212. </tr>
  213. <tr>
  214. <td><?php print "Created: " . $auth_info[timestamp]; ?> </td>
  215. <td colspan=2><?php print "Dhcp status: " . $dhcp_str; ?></td>
  216. <td colspan=2><?php print "Dhcp hostname: " . $auth_info[dhcp_hostname]; ?></td>
  217. <td colspan=2><?php print "Last found: " . $auth_info[last_found]; ?></td>
  218. <td></td>
  219. </tr>
  220. <tr>
  221. <td colspan=2><input type="submit" name="moveauth" value=<?php print $btn_move; ?>><?php print_login_select($db_link, 'new_parent', $auth_info[user_id]); ?></td>
  222. <td><a href=/admin/logs/authlog.php?auth_id=<?php print $id; ?>>Лог</a></td>
  223. <?php
  224. if ($auth_info[deleted]) {
  225. print "<td colspan=2>Deleted: " . $auth_info[changed_time]."</td>";
  226. print "<td colspan=2 align=right><input type=\"submit\" name=\"recovery\" value=\"Восстановить\"></td>";
  227. } else {
  228. print "<td colspan=2></td>";
  229. print "<td colspan=2 align=right><input type=\"submit\" name=\"editauth\" value=\"$btn_save\"></td>";
  230. }
  231. ?>
  232. </tr>
  233. </table>
  234. <?
  235. if ($msg_error) {
  236. print "<div id='msg'><b>$msg_error</b></div><br>\n";
  237. }
  238. ?>
  239. </form>
  240. <?
  241. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  242. ?>