editauth.php 12 KB

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