1
0

editauth.php 15 KB

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