editauth.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. $parent_user = get_record_sql($db_link, "SELECT user_id FROM User_auth WHERE id=$id");
  37. $parent_id = $parent_user['user_id'];
  38. $locate_user = get_record_sql($db_link, "SELECT * FROM User_auth WHERE `ip_int`=$ip_aton AND id<>$id AND deleted=0");
  39. $lid = $locate_user['user_id'];
  40. if (isset($lid) and ($lid != $parent_id)) {
  41. $msg_error = "$ip $msg_exists Принадлежит пользователю ".$locate_user['login'];
  42. unset($_POST);
  43. } else {
  44. $new['ip'] = $ip;
  45. $new['ip_int'] = $ip_aton;
  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, 0);
  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, 0);
  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. $parent_user = get_record_sql($db_link, "SELECT user_id FROM User_auth WHERE id=$id");
  108. $parent_id = $parent_user['user_id'];
  109. $locate_user = get_record_sql($db_link, "SELECT * FROM User_auth WHERE `ip_int`=$ip_aton AND id<>$id AND deleted=0");
  110. $lid = $locate_user['user_id'];
  111. if (isset($lid) and ($lid != $parent_id)) {
  112. $msg_error = "$ip $msg_exists Принадлежит пользователю ".$locate_user['login'];
  113. unset($_POST);
  114. } else {
  115. $new['deleted'] = 0;
  116. if ($default_user_id == $parent_id or $hotspot_user_id == $parent_id) {
  117. $new['nagios_handler'] = '';
  118. $new['enabled'] = 0;
  119. $new['link_check'] = 0;
  120. $new['nagios'] = 0;
  121. $new['blocked'] = 0;
  122. $new['day_quota'] = 0;
  123. $new['month_quota'] = 0;
  124. $new['queue_id'] = 0;
  125. $new['filter_group_id'] = 0;
  126. } else {
  127. $new['nagios_handler'] = $_POST["f_handler"];
  128. $new['enabled'] = $_POST["f_enabled"] * 1;
  129. $new['link_check'] = $_POST["f_link"] * 1;
  130. $new['nagios'] = $_POST["f_nagios"] * 1;
  131. $new['dhcp'] = $_POST["f_dhcp"] * 1;
  132. $new['blocked'] = $_POST["f_blocked"] * 1;
  133. $new['day_quota'] = $_POST["f_day_q"] * 1;
  134. $new['month_quota'] = $_POST["f_month_q"] * 1;
  135. $new['queue_id'] = $_POST["f_queue_id"] * 1;
  136. $new['filter_group_id'] = $_POST["f_group_id"] * 1;
  137. }
  138. $changes = get_diff_rec($db_link,"User_auth","id='$id'", $new, 0);
  139. if (!empty($changes)) { LOG_WARNING($db_link,"Восстановлен адрес доступа! Применено: $changes"); }
  140. update_record($db_link, "User_auth", "id='$id'", $new);
  141. }
  142. } else {
  143. $msg_error = "$msg_ip_error xxx.xxx.xxx.xxx/xx";
  144. }
  145. header("Location: " . $_SERVER["REQUEST_URI"]);
  146. }
  147. unset($_POST);
  148. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  149. $sSQL = "SELECT * FROM User_auth WHERE id=$id";
  150. $auth_info = get_record_sql($db_link, $sSQL);
  151. $parent_name = get_login($db_link, $auth_info['user_id']);
  152. if ($auth_info['dhcp_time'] == '0000-00-00 00:00:00') { $dhcp_str = ''; } else { $dhcp_str = $auth_info['dhcp_time'] . " (" . $auth_info['dhcp_action'] . ")"; }
  153. if ($auth_info['last_found'] == '0000-00-00 00:00:00') { $auth_info['last_found'] = ''; }
  154. ?>
  155. <div id="cont">
  156. <?
  157. print "<b> Адрес доступа пользователя <a href=/admin/users/edituser.php?id=".$auth_info['user_id'].">".$parent_name."</a> <b>";
  158. ?>
  159. <form name="def" action="editauth.php?id=<? echo $id; ?>" method="post">
  160. <input type="hidden" name="id" value=<? echo $id; ?>>
  161. <table class="data">
  162. <tr>
  163. <td width=200><?php print $cell_dns_name." &nbsp | &nbsp "; print_url("Альясы","/admin/users/edit_alias.php?id=$id"); ?></td>
  164. <td width=200><?php print $cell_comment; ?></td>
  165. <td width=70><?php print $cell_enabled; ?></td>
  166. <td width=70><?php print $cell_blocked; ?></td>
  167. <td width=70><?php print $cell_perday; ?></td>
  168. <td width=70><?php print $cell_permonth; ?></td>
  169. <td width=70><?php print $cell_connection; ?></td>
  170. </tr>
  171. <tr>
  172. <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>
  173. <td><input type="text" name="f_comments" value="<? echo $auth_info['comments']; ?>"></td>
  174. <td><?php print_qa_select('f_enabled', $auth_info['enabled']); ?></td>
  175. <td><?php print_qa_select('f_blocked', $auth_info['blocked']); ?></td>
  176. <td><input type="text" name="f_day_q" value="<? echo $auth_info['day_quota']; ?>" size=5></td>
  177. <td><input type="text" name="f_month_q" value="<? echo $auth_info['month_quota']; ?>" size=5></td>
  178. <td><?php print get_connection($db_link, $id); ?></td>
  179. </tr>
  180. <tr>
  181. <td><?php print $cell_ip; ?></td>
  182. <td><?php print $cell_mac; ?></td>
  183. <td><?php print $cell_clientid; ?></td>
  184. <td><?php print $cell_dhcp; ?></td>
  185. <td><?php print $cell_filter; ?></td>
  186. <td><?php print $cell_shaper; ?></td>
  187. <td></td>
  188. <tr>
  189. <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>
  190. <td><input type="text" name="f_mac" value="<? echo $auth_info['mac']; ?>"></td>
  191. <td><input type="text" name="f_clientid" value="<? echo $auth_info['clientid']; ?>"></td>
  192. <td><?php print_qa_select('f_dhcp', $auth_info['dhcp']); ?></td>
  193. <td><?php print_group_select($db_link, 'f_group_id', $auth_info['filter_group_id']); ?> </td>
  194. <td><?php print_queue_select($db_link, 'f_queue_id', $auth_info['queue_id']); ?> </td>
  195. <td></td>
  196. </tr>
  197. <tr>
  198. <td><?php print $cell_host_model; ?></td>
  199. <td><?php print $cell_nagios_handler; ?></td>
  200. <td><?php print $cell_acl; ?></td>
  201. <td><?php print $cell_nagios; ?></td>
  202. <td><?php print $cell_link; ?></td>
  203. <td><?php print $cell_traf; ?></td>
  204. <td></td>
  205. <tr>
  206. <td><input type="text" name="f_host_model" value="<? echo $auth_info['host_model']; ?>"></td>
  207. <td><input type="text" name="f_handler" value="<? echo $auth_info['nagios_handler']; ?>"></td>
  208. <td><input type="text" name="f_acl" value="<? echo $auth_info['dhcp_acl']; ?>"></td>
  209. <td><?php print_qa_select('f_nagios', $auth_info['nagios']); ?></td>
  210. <td><?php print_qa_select('f_link', $auth_info['link_check']); ?></td>
  211. <td><?php print_qa_select('f_save_traf', $auth_info['save_traf']); ?></td>
  212. <td></td>
  213. </tr>
  214. <tr>
  215. <td><?php print "Created: " . $auth_info['timestamp']; ?> </td>
  216. <td colspan=2><?php print "Dhcp status: " . $dhcp_str; ?></td>
  217. <td colspan=2><?php print "Dhcp hostname: " . $auth_info['dhcp_hostname']; ?></td>
  218. <td colspan=2><?php print "Last found: " . $auth_info['last_found']; ?></td>
  219. <td></td>
  220. </tr>
  221. <tr>
  222. <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>
  223. <td><a href=/admin/logs/authlog.php?auth_id=<?php print $id; ?>>Лог</a></td>
  224. <?php
  225. if ($auth_info['deleted']) {
  226. print "<td colspan=2>Deleted: " . $auth_info['changed_time']."</td>";
  227. print "<td colspan=2 align=right><input type=\"submit\" name=\"recovery\" value=\"Восстановить\"></td>";
  228. } else {
  229. print "<td colspan=2></td>";
  230. print "<td colspan=2 align=right><input type=\"submit\" name=\"editauth\" value=\"$btn_save\"></td>";
  231. }
  232. ?>
  233. </tr>
  234. </table>
  235. <?
  236. if ($msg_error) {
  237. print "<div id='msg'><b>$msg_error</b></div><br>\n";
  238. }
  239. ?>
  240. </form>
  241. <?
  242. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  243. ?>