editauth.php 13 KB

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