editauth.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. $new['WikiName'] = $_POST["f_wiki"];
  50. $f_dnsname=trim($_POST["f_dns_name"]);
  51. if (!empty($f_dnsname) and checkValidHostname($f_dnsname) and checkUniqHostname($db_link,$id,$f_dnsname)) { $new['dns_name'] = $f_dnsname; }
  52. if (empty($f_dnsname)) { $new['dns_name'] = ''; }
  53. $new['host_model'] = $_POST["f_host_model"];
  54. $new['save_traf'] = $_POST["f_save_traf"] * 1;
  55. $new['dhcp_acl'] = trim($_POST["f_acl"]);
  56. if ($default_user_id == $parent_id or $hotspot_user_id == $parent_id) {
  57. $new['nagios_handler'] = '';
  58. $new['enabled'] = 0;
  59. $new['link_check'] = 0;
  60. $new['nagios'] = 0;
  61. $new['blocked'] = 0;
  62. $new['day_quota'] = 0;
  63. $new['month_quota'] = 0;
  64. $new['queue_id'] = 0;
  65. $new['filter_group_id'] = 0;
  66. } else {
  67. $new['nagios_handler'] = $_POST["f_handler"];
  68. $new['enabled'] = $_POST["f_enabled"] * 1;
  69. $new['link_check'] = $_POST["f_link"] * 1;
  70. $new['nagios'] = $_POST["f_nagios"] * 1;
  71. $new['dhcp'] = $_POST["f_dhcp"] * 1;
  72. $new['blocked'] = $_POST["f_blocked"] * 1;
  73. $new['day_quota'] = $_POST["f_day_q"] * 1;
  74. $new['month_quota'] = $_POST["f_month_q"] * 1;
  75. $new['queue_id'] = $_POST["f_queue_id"] * 1;
  76. $new['filter_group_id'] = $_POST["f_group_id"] * 1;
  77. }
  78. $changes = get_diff_rec($db_link,"User_auth","id='$id'", $new, 0);
  79. if (!empty($changes)) { LOG_WARNING($db_link,"Изменен адрес доступа! Список изменений: $changes"); }
  80. update_record($db_link, "User_auth", "id='$id'", $new);
  81. }
  82. } else {
  83. $msg_error = "$msg_ip_error xxx.xxx.xxx.xxx/xx";
  84. }
  85. header("Location: " . $_SERVER["REQUEST_URI"]);
  86. }
  87. if (isset($_POST["moveauth"]) and !$old_auth_info['deleted']) {
  88. $new['user_id'] = $_POST["new_parent"];
  89. $changes = get_diff_rec($db_link,"User_auth","id='$id'", $new, 0);
  90. if (!empty($changes)) { LOG_WARNING($db_link,"Адрес доступа перемещён к другому пользователю! Применено: $changes"); }
  91. update_record($db_link, "User_auth", "id='$id'", $new);
  92. header("Location: " . $_SERVER["REQUEST_URI"]);
  93. }
  94. if (isset($_POST["recovery"])) {
  95. $ip = trim($_POST["f_ip"]);
  96. if (checkValidIp($ip)) {
  97. $range = cidrToRange($ip);
  98. $first_user_ip = $range[0];
  99. $last_user_ip = $range[1];
  100. $cidr = $range[2][1];
  101. if (isset($cidr) and $cidr < 32) {
  102. $ip = $first_user_ip . '/' . $cidr;
  103. } else {
  104. $ip = $first_user_ip;
  105. }
  106. $ip_aton = ip2long($first_user_ip);
  107. $ip_aton_end = ip2long($last_user_ip);
  108. $parent_user = get_record_sql($db_link, "SELECT user_id FROM User_auth WHERE id=$id");
  109. $parent_id = $parent_user['user_id'];
  110. $locate_user = get_record_sql($db_link, "SELECT * FROM User_auth WHERE `ip_int`=$ip_aton AND id<>$id AND deleted=0");
  111. $lid = $locate_user['user_id'];
  112. if (isset($lid) and ($lid != $parent_id)) {
  113. $msg_error = "$ip $msg_exists Принадлежит пользователю ".$locate_user['login'];
  114. unset($_POST);
  115. } else {
  116. $new['deleted'] = 0;
  117. if ($default_user_id == $parent_id or $hotspot_user_id == $parent_id) {
  118. $new['nagios_handler'] = '';
  119. $new['enabled'] = 0;
  120. $new['link_check'] = 0;
  121. $new['nagios'] = 0;
  122. $new['blocked'] = 0;
  123. $new['day_quota'] = 0;
  124. $new['month_quota'] = 0;
  125. $new['queue_id'] = 0;
  126. $new['filter_group_id'] = 0;
  127. } else {
  128. $new['nagios_handler'] = $_POST["f_handler"];
  129. $new['enabled'] = $_POST["f_enabled"] * 1;
  130. $new['link_check'] = $_POST["f_link"] * 1;
  131. $new['nagios'] = $_POST["f_nagios"] * 1;
  132. $new['dhcp'] = $_POST["f_dhcp"] * 1;
  133. $new['blocked'] = $_POST["f_blocked"] * 1;
  134. $new['day_quota'] = $_POST["f_day_q"] * 1;
  135. $new['month_quota'] = $_POST["f_month_q"] * 1;
  136. $new['queue_id'] = $_POST["f_queue_id"] * 1;
  137. $new['filter_group_id'] = $_POST["f_group_id"] * 1;
  138. }
  139. $changes = get_diff_rec($db_link,"User_auth","id='$id'", $new, 0);
  140. if (!empty($changes)) { LOG_WARNING($db_link,"Восстановлен адрес доступа! Применено: $changes"); }
  141. update_record($db_link, "User_auth", "id='$id'", $new);
  142. }
  143. } else {
  144. $msg_error = "$msg_ip_error xxx.xxx.xxx.xxx/xx";
  145. }
  146. header("Location: " . $_SERVER["REQUEST_URI"]);
  147. }
  148. unset($_POST);
  149. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  150. $sSQL = "SELECT * FROM User_auth WHERE id=$id";
  151. $auth_info = get_record_sql($db_link, $sSQL);
  152. $parent_name = get_login($db_link, $auth_info['user_id']);
  153. if ($auth_info['dhcp_time'] == '0000-00-00 00:00:00') { $dhcp_str = ''; } else { $dhcp_str = $auth_info['dhcp_time'] . " (" . $auth_info['dhcp_action'] . ")"; }
  154. if ($auth_info['last_found'] == '0000-00-00 00:00:00') { $auth_info['last_found'] = ''; }
  155. ?>
  156. <div id="cont">
  157. <?
  158. print "<b> Адрес доступа пользователя <a href=/admin/users/edituser.php?id=".$auth_info['user_id'].">".$parent_name."</a> <b>";
  159. ?>
  160. <form name="def" action="editauth.php?id=<? echo $id; ?>" method="post">
  161. <input type="hidden" name="id" value=<? echo $id; ?>>
  162. <table class="data">
  163. <tr>
  164. <td width=200><?php print $cell_dns_name." &nbsp | &nbsp "; print_url("Альясы","/admin/users/edit_alias.php?id=$id"); ?></td>
  165. <td width=200><?php print $cell_comment; ?></td>
  166. <td width=200><?php print $cell_wikiname; ?></td>
  167. <td width=70><?php print $cell_enabled; ?></td>
  168. <td width=70><?php print $cell_blocked; ?></td>
  169. <td width=70><?php print $cell_perday; ?></td>
  170. <td width=70><?php print $cell_permonth; ?></td>
  171. </tr>
  172. <tr>
  173. <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>
  174. <td><input type="text" name="f_comments" value="<? echo $auth_info['comments']; ?>"></td>
  175. <td><input type="text" name="f_wiki" value="<? echo $auth_info['WikiName']; ?>"></td>
  176. <td><?php print_qa_select('f_enabled', $auth_info['enabled']); ?></td>
  177. <td><?php print_qa_select('f_blocked', $auth_info['blocked']); ?></td>
  178. <td><input type="text" name="f_day_q" value="<? echo $auth_info['day_quota']; ?>" size=5></td>
  179. <td><input type="text" name="f_month_q" value="<? echo $auth_info['month_quota']; ?>" size=5></td>
  180. </tr>
  181. <tr>
  182. <td><?php print $cell_ip; ?></td>
  183. <td><?php print $cell_mac; ?></td>
  184. <td><?php print $cell_clientid; ?></td>
  185. <td><?php print $cell_dhcp; ?></td>
  186. <td><?php print $cell_filter; ?></td>
  187. <td><?php print $cell_shaper; ?></td>
  188. <td></td>
  189. <tr>
  190. <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>
  191. <td><input type="text" name="f_mac" value="<? echo $auth_info['mac']; ?>"></td>
  192. <td><input type="text" name="f_clientid" value="<? echo $auth_info['clientid']; ?>"></td>
  193. <td><?php print_qa_select('f_dhcp', $auth_info['dhcp']); ?></td>
  194. <td><?php print_group_select($db_link, 'f_group_id', $auth_info['filter_group_id']); ?> </td>
  195. <td><?php print_queue_select($db_link, 'f_queue_id', $auth_info['queue_id']); ?> </td>
  196. <td></td>
  197. </tr>
  198. <tr>
  199. <td><?php print $cell_host_model; ?></td>
  200. <td><?php print $cell_nagios_handler; ?></td>
  201. <td><?php print $cell_acl; ?></td>
  202. <td><?php print $cell_nagios; ?></td>
  203. <td><?php print $cell_link; ?></td>
  204. <td><?php print $cell_traf; ?></td>
  205. <td></td>
  206. <tr>
  207. <td><input type="text" name="f_host_model" value="<? echo $auth_info['host_model']; ?>"></td>
  208. <td><input type="text" name="f_handler" value="<? echo $auth_info['nagios_handler']; ?>"></td>
  209. <td><input type="text" name="f_acl" value="<? echo $auth_info['dhcp_acl']; ?>"></td>
  210. <td><?php print_qa_select('f_nagios', $auth_info['nagios']); ?></td>
  211. <td><?php print_qa_select('f_link', $auth_info['link_check']); ?></td>
  212. <td><?php print_qa_select('f_save_traf', $auth_info['save_traf']); ?></td>
  213. <td></td>
  214. </tr>
  215. <tr>
  216. <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>
  217. <td><a href=/admin/logs/authlog.php?auth_id=<?php print $id; ?>>Лог</a></td>
  218. <?php
  219. print "<td>"; print_url("Трафик за день","/admin/reports/authday.php?id=$id"); print "</td>";
  220. if ($auth_info['deleted']) {
  221. print "<td colspan=2>Deleted: " . $auth_info['changed_time']."</td>";
  222. print "<td colspan=1 align=right><input type=\"submit\" name=\"recovery\" value=\"Восстановить\"></td>";
  223. } else {
  224. print "<td colspan=2></td>";
  225. print "<td colspan=1 align=right><input type=\"submit\" name=\"editauth\" value=\"$btn_save\"></td>";
  226. }
  227. ?>
  228. </tr>
  229. <tr >
  230. <td class="data" colspan=7>
  231. <?php
  232. print "Created: " . $auth_info['timestamp'];
  233. print "&nbsp Dhcp: " . $dhcp_str;
  234. print "&nbsp hostname: " . $auth_info['dhcp_hostname'];
  235. print "&nbsp Last: " . $auth_info['last_found'];
  236. print "&nbsp ".get_connection($db_link, $id);
  237. ?>
  238. </td>
  239. </tr>
  240. </table>
  241. <?
  242. if ($msg_error) {
  243. print "<div id='msg'><b>$msg_error</b></div><br>\n";
  244. }
  245. ?>
  246. </form>
  247. <br>
  248. <?
  249. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  250. ?>