editauth.php 13 KB

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