editauth.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. if (is_auth_bind_changed($db_link,$id,$ip,$mac)) {
  80. $new_id = copy_auth($db_link,$id,$new);
  81. header("Location: /admin/users/editauth.php?id=".$new_id,TRUE, 302);
  82. exit;
  83. } else {
  84. update_record($db_link, "User_auth", "id='$id'", $new);
  85. }
  86. } else {
  87. $msg_error = "$msg_ip_error xxx.xxx.xxx.xxx";
  88. $_SESSION[$page_url]['msg'] = $msg_error;
  89. }
  90. header("Location: " . $_SERVER["REQUEST_URI"]);
  91. }
  92. if (isset($_POST["moveauth"]) and !$old_auth_info['deleted']) {
  93. $new['user_id'] = $_POST["new_parent"];
  94. $changes = get_diff_rec($db_link,"User_auth","id='$id'", $new, 0);
  95. if (!empty($changes)) { LOG_WARNING($db_link,"Адрес доступа перемещён к другому пользователю! Применено: $changes"); }
  96. update_record($db_link, "User_auth", "id='$id'", $new);
  97. header("Location: " . $_SERVER["REQUEST_URI"]);
  98. }
  99. if (isset($_POST["recovery"])) {
  100. $ip = trim($_POST["f_ip"]);
  101. if (checkValidIp($ip)) {
  102. $ip_aton = ip2long($ip);
  103. $mac=mac_dotted($_POST["f_mac"]);
  104. $parent_id = $old_auth_info['user_id'];
  105. //search mac
  106. $mac_exists=find_mac_in_subnet($db_link,$ip,$mac);
  107. if (isset($mac_exists) and $mac_exists['count']>=1 and !in_array($parent_id,$mac_exists['users_id'])) {
  108. $dup_sql = "SELECT * FROM User_list WHERE id=".$mac_exists['users_id']['0'];
  109. $dup_info = get_record_sql($db_link, $dup_sql);
  110. $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'];
  111. $_SESSION[$page_url]['msg'] = $msg_error;
  112. LOG_ERROR($db_link, $msg_error);
  113. header("Location: " . $_SERVER["REQUEST_URI"]);
  114. exit;
  115. }
  116. //disable dhcp for secondary ip
  117. $f_dhcp = $_POST["f_dhcp"] * 1;
  118. if (in_array($parent_id,$mac_exists['users_id'])) {
  119. if ($parent_id != $mac_exists['users_id'][0]) { $f_dhcp = 0; }
  120. }
  121. //search ip
  122. $dup_ip_record = get_record_sql($db_link, "SELECT * FROM User_auth WHERE `ip_int`=$ip_aton AND id<>$id AND deleted=0");
  123. if (!empty($dup_ip_record)) {
  124. $dup_info = get_record_sql($db_link, "SELECT * FROM User_list WHERE id=".$dup_ip_record['user_id']);
  125. $msg_error = "$ip already exists. Skip creating $ip [$mac].<br>Old user id: ".$dup_info['id']." login: ".$dup_info['login'];
  126. $_SESSION[$page_url]['msg'] = $msg_error;
  127. LOG_ERROR($db_link, $msg_error);
  128. header("Location: " . $_SERVER["REQUEST_URI"]);
  129. exit;
  130. }
  131. $new['deleted'] = 0;
  132. if ($default_user_id == $parent_id or $hotspot_user_id == $parent_id) {
  133. $new['nagios_handler'] = '';
  134. $new['enabled'] = 0;
  135. $new['link_check'] = 0;
  136. $new['nagios'] = 0;
  137. $new['blocked'] = 0;
  138. $new['day_quota'] = 0;
  139. $new['month_quota'] = 0;
  140. $new['queue_id'] = 0;
  141. $new['filter_group_id'] = 0;
  142. } else {
  143. $new['nagios_handler'] = $_POST["f_handler"];
  144. $new['enabled'] = $_POST["f_enabled"] * 1;
  145. $new['link_check'] = $_POST["f_link"] * 1;
  146. $new['nagios'] = $_POST["f_nagios"] * 1;
  147. $new['dhcp'] = $_POST["f_dhcp"] * 1;
  148. $new['blocked'] = $_POST["f_blocked"] * 1;
  149. $new['day_quota'] = $_POST["f_day_q"] * 1;
  150. $new['month_quota'] = $_POST["f_month_q"] * 1;
  151. $new['queue_id'] = $_POST["f_queue_id"] * 1;
  152. $new['filter_group_id'] = $_POST["f_group_id"] * 1;
  153. }
  154. $changes = get_diff_rec($db_link,"User_auth","id='$id'", $new, 0);
  155. if (!empty($changes)) { LOG_WARNING($db_link,"Восстановлен адрес доступа! Применено: $changes"); }
  156. update_record($db_link, "User_auth", "id='$id'", $new);
  157. } else {
  158. $msg_error = "$msg_ip_error xxx.xxx.xxx.xxx/xx";
  159. $_SESSION[$page_url]['msg'] = $msg_error;
  160. }
  161. header("Location: " . $_SERVER["REQUEST_URI"]);
  162. }
  163. unset($_POST);
  164. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  165. $sSQL = "SELECT * FROM User_auth WHERE id=$id";
  166. $auth_info = get_record_sql($db_link, $sSQL);
  167. $parent_name = get_login($db_link, $auth_info['user_id']);
  168. if ($auth_info['dhcp_time'] == '0000-00-00 00:00:00') { $dhcp_str = ''; } else { $dhcp_str = $auth_info['dhcp_time'] . " (" . $auth_info['dhcp_action'] . ")"; }
  169. if ($auth_info['last_found'] == '0000-00-00 00:00:00') { $auth_info['last_found'] = ''; }
  170. ?>
  171. <div id="cont">
  172. <?php
  173. if (!empty($_SESSION[$page_url]['msg'])) {
  174. print '<div id="msg">'.$_SESSION[$page_url]['msg'].'</div>';
  175. unset($_SESSION[$page_url]['msg']);
  176. }
  177. print "<b> Адрес доступа пользователя <a href=/admin/users/edituser.php?id=".$auth_info['user_id'].">".$parent_name."</a> </b>";
  178. ?>
  179. <form name="def" action="editauth.php?id=<? echo $id; ?>" method="post">
  180. <input type="hidden" name="id" value=<? echo $id; ?>>
  181. <table class="data">
  182. <tr>
  183. <td width=200><?php print $cell_dns_name." &nbsp | &nbsp "; print_url("Альясы","/admin/users/edit_alias.php?id=$id"); ?></td>
  184. <td width=200><?php print $cell_comment; ?></td>
  185. <td width=200>
  186. <?php
  187. if (!empty($auth_info['WikiName'])) {
  188. $wiki_url = rtrim(get_option($db_link, 60),'/');
  189. if (preg_match('/127.0.0.1/', $wiki_url)) { print $cell_wikiname; } else {
  190. $wiki_web = rtrim(get_option($db_link, 63),'/');
  191. $wiki_web = ltrim($wiki_web,'/');
  192. $wiki_link = $wiki_url.'/'.$wiki_web.'/'.$auth_info['WikiName'];
  193. print_url($cell_wikiname,$wiki_link);
  194. }
  195. } else {
  196. print $cell_wikiname;
  197. }
  198. $dev_id = get_device_by_auth($db_link,$auth_info['user_id']);
  199. if (isset($dev_id)) {
  200. print "&nbsp|&nbsp";
  201. print_url('Device','/admin/devices/editdevice.php?id='.$dev_id);
  202. }
  203. ?>
  204. </td>
  205. <td width=70><?php print $cell_enabled; ?></td>
  206. <td width=70><?php print $cell_blocked; ?></td>
  207. <td width=70><?php print $cell_perday; ?></td>
  208. <td width=70><?php print $cell_permonth; ?></td>
  209. </tr>
  210. <tr>
  211. <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>
  212. <td><input type="text" name="f_comments" value="<? echo $auth_info['comments']; ?>"></td>
  213. <td><input type="text" name="f_wiki" value="<? echo $auth_info['WikiName']; ?>"></td>
  214. <td><?php print_qa_select('f_enabled', $auth_info['enabled']); ?></td>
  215. <td><?php print_qa_select('f_blocked', $auth_info['blocked']); ?></td>
  216. <td><input type="text" name="f_day_q" value="<? echo $auth_info['day_quota']; ?>" size=5></td>
  217. <td><input type="text" name="f_month_q" value="<? echo $auth_info['month_quota']; ?>" size=5></td>
  218. </tr>
  219. <tr>
  220. <td><?php print $cell_ip; ?></td>
  221. <td><?php print $cell_mac; ?></td>
  222. <td><?php print $cell_acl; ?></td>
  223. <td><?php print $cell_dhcp; ?></td>
  224. <td><?php print $cell_filter; ?></td>
  225. <td><?php print $cell_shaper; ?></td>
  226. <td></td>
  227. <tr>
  228. <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>
  229. <td><input type="text" name="f_mac" value="<? echo $auth_info['mac']; ?>" pattern="^([0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}|([0-9a-fA-F]{4}[\\.-][0-9a-fA-F]{4}[\\.-][0-9a-fA-F]{4})|[0-9A-Fa-f]{12}$"></td>
  230. <td><input type="text" name="f_acl" value="<? echo $auth_info['dhcp_acl']; ?>"></td>
  231. <td><?php print_qa_select('f_dhcp', $auth_info['dhcp']); ?></td>
  232. <td><?php print_group_select($db_link, 'f_group_id', $auth_info['filter_group_id']); ?> </td>
  233. <td><?php print_queue_select($db_link, 'f_queue_id', $auth_info['queue_id']); ?> </td>
  234. <td></td>
  235. </tr>
  236. <tr>
  237. <td><?php print $cell_host_model; ?></td>
  238. <td><?php print $cell_host_firmware; ?></td>
  239. <td><?php print $cell_nagios_handler; ?></td>
  240. <td><?php print $cell_nagios; ?></td>
  241. <td><?php print $cell_link; ?></td>
  242. <td><?php print $cell_traf; ?></td>
  243. <td></td>
  244. <tr>
  245. <td><?php print_device_model_select($db_link,'f_device_model_id',$auth_info['device_model_id']); ?></td>
  246. <td><input type="text" name="f_firmware" value="<? echo $auth_info['firmware']; ?>"></td>
  247. <td><input type="text" name="f_handler" value="<? echo $auth_info['nagios_handler']; ?>"></td>
  248. <td><?php print_qa_select('f_nagios', $auth_info['nagios']); ?></td>
  249. <td><?php print_qa_select('f_link', $auth_info['link_check']); ?></td>
  250. <td><?php print_qa_select('f_save_traf', $auth_info['save_traf']); ?></td>
  251. <td></td>
  252. </tr>
  253. <tr>
  254. <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>
  255. <td><a href=/admin/logs/authlog.php?auth_id=<?php print $id; ?>>Лог</a></td>
  256. <td></td>
  257. <?php
  258. if ($auth_info['deleted']) {
  259. print "<td colspan=2>Deleted: " . $auth_info['changed_time']."</td>";
  260. print "<td colspan=1 align=right><input type=\"submit\" name=\"recovery\" value=\"Восстановить\"></td>";
  261. } else {
  262. print "<td colspan=2></td>";
  263. print "<td colspan=1 align=right><input type=\"submit\" name=\"editauth\" value=\"$btn_save\"></td>";
  264. }
  265. ?>
  266. </tr>
  267. <tr ><td class="data" colspan=7>Status:</td></tr>
  268. <tr >
  269. <td>
  270. <?php
  271. print "Created: " . $auth_info['timestamp']."<br>";
  272. ?>
  273. </td>
  274. <td colspan=2>
  275. <?php
  276. print "Dhcp event: " . $dhcp_str."<br>";
  277. print "Dhcp hostname: " . $auth_info['dhcp_hostname']."<br>";
  278. ?>
  279. </td>
  280. <td><?php print_url("Трафик за день","/admin/reports/authday.php?id=$id"); ?></td>
  281. <td colspan=3>
  282. <?php
  283. print "Last found: " . $auth_info['last_found']."<br>";
  284. print "Connected: ".get_connection($db_link, $id)."<br>";
  285. ?>
  286. </td>
  287. </tr>
  288. </table>
  289. <?
  290. if ($msg_error) {
  291. print "<div id='msg'><b>$msg_error</b></div><br>\n";
  292. }
  293. ?>
  294. </form>
  295. <br>
  296. <?
  297. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  298. ?>