doubles.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  5. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/cidrfilter.php");
  6. // Удаление записей авторизации
  7. if (getPOST("removeauth") !== null) {
  8. $auth_id = getPOST("f_auth_id", null, []);
  9. if (!empty($auth_id) && is_array($auth_id)) {
  10. foreach ($auth_id as $val) {
  11. $val = trim($val);
  12. if ($val !== '') {
  13. delete_user_auth($db_link, (int)$val);
  14. }
  15. }
  16. }
  17. header("Location: " . $_SERVER["REQUEST_URI"]);
  18. exit;
  19. }
  20. // Фильтрация по CIDR
  21. $params = [];
  22. if (!empty($rcidr)) {
  23. $cidr_range = cidrToRange($rcidr);
  24. if (!empty($cidr_range) && isset($cidr_range[0], $cidr_range[1])) {
  25. $cidr_filter = " AND (U.ip_int >= ? AND U.ip_int <= ?)";
  26. $params[] = ip2long($cidr_range[0]);
  27. $params[] = ip2long($cidr_range[1]);
  28. } else {
  29. $cidr_filter = '';
  30. }
  31. } else {
  32. $cidr_filter = '';
  33. }
  34. print_ip_submenu($page_url);
  35. ?>
  36. <div id="cont">
  37. <br>
  38. <form name="def" action="doubles.php" method="post">
  39. <b><?php print WEB_network_subnet; ?> - </b><?php print_subnet_select_office_splitted($db_link, 'cidr', $rcidr); ?>
  40. <input id="btn_filter" name="btn_filter" type="submit" value="<?php echo WEB_btn_show; ?>">
  41. <table class="data">
  42. <tr>
  43. <td class="data"><input type="checkbox" onClick="checkAll(this.checked);"></td>
  44. <td align=Center><?php print WEB_cell_login; ?></td>
  45. <td align=Center><?php print WEB_cell_ip; ?></td>
  46. <td align=Center><?php print WEB_cell_mac ; ?></td>
  47. <td align=Center><?php print WEB_cell_description; ?></td>
  48. <td align=Center><?php print WEB_cell_dns_name; ?></td>
  49. <td align=Center><?php print WEB_cell_created; ?></td>
  50. <td align=Center><?php print WEB_cell_last_found; ?></td>
  51. <td align=right><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="removeauth" value="<?php echo WEB_btn_delete; ?>"></td>
  52. </tr>
  53. <?php
  54. $sSQL = "SELECT U.id, U.ip, U.mac, U.arp_found, S.subnet as net FROM user_auth U, subnets S WHERE (U.mac IS NOT NULL AND U.mac<>'')
  55. AND (U.ip_int BETWEEN S.ip_int_start AND S.ip_int_stop) $cidr_filter AND S.office=1 AND U.deleted=0 ORDER BY net,mac,arp_found";
  56. $users = get_records_sql($db_link,$sSQL, $params);
  57. $f_subnet=NULL;
  58. $f_mac=NULL;
  59. $f_id=NULL;
  60. $printed = NULL;
  61. $f_index = 0;
  62. $f_count = 0;
  63. foreach ($users as $row) {
  64. //инициализируем перебор по первой записи
  65. if (empty($f_subnet)) {
  66. //сохраняем для обработки
  67. $f_subnet = $row['net'];
  68. $f_mac=$row['mac'];
  69. $f_id=$row['id'];
  70. $f_index=0;
  71. continue;
  72. }
  73. //начинаем перебор - проверяем
  74. if ($row['net'] === $f_subnet and $row['mac']===$f_mac) {
  75. //если первая запись не выводилась - выводим на печать
  76. $d_params = $params;
  77. if (!isset($printed[$f_id])) {
  78. //считаем сколько у нас дублей
  79. $dSQL = "SELECT U.id, U.ip, U.mac, U.arp_found FROM user_auth U WHERE U.deleted=0 AND U.mac=? $cidr_filter";
  80. $d_params[]= $f_mac;
  81. $doubles = get_records_sql($db_link,$dSQL, $d_params);
  82. $f_count = count($doubles);
  83. $f_index++;
  84. $user = get_record_sql($db_link,"SELECT * FROM user_auth WHERE id=?", [$f_id]);
  85. if (empty($user['arp_found']) || is_empty_datetime($user['arp_found'])) { $user['arp_found'] = ''; }
  86. if (empty($user['ts']) || is_empty_datetime($user['ts'])) { $user['ts'] = ''; }
  87. if (empty($user['changed_time']) || is_empty_datetime($user['changed_time'])) { $user['changed_time'] = ''; }
  88. print "<tr align=center>\n";
  89. $cl = "data";
  90. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_auth_id[] value=".$user["id"];
  91. if ($f_index != $f_count) { print " checked"; }
  92. print "></td>\n";
  93. print "<td class=\"$cl\" ><a href=/admin/users/edituser.php?id=".$user['user_id'].">" . get_login($db_link,$user['user_id']) . "</a></td>\n";
  94. print "<td class=\"$cl\" ><a href=/admin/users/editauth.php?id=".$user['id'].">" . $user['ip'] . "</a></td>\n";
  95. print "<td class=\"$cl\" >" . expand_mac($db_link,$user['mac']) . "</td>\n";
  96. if (isset($user['dhcp_hostname']) and strlen($user['dhcp_hostname']) > 0) {
  97. print "<td class=\"$cl\" >".$user['description']." [" . $user['dhcp_hostname'] . "]</td>\n";
  98. } else {
  99. print "<td class=\"$cl\" >".$user['description']."</td>\n";
  100. }
  101. print "<td class=\"$cl\" >".$user['dns_name']."</td>\n";
  102. print "<td class=\"$cl\" >".$user['ts']."</td>\n";
  103. print "<td class=\"$cl\" >".$user['last_found']."</td>\n";
  104. print "</tr>\n";
  105. $printed[$f_id] = 1;
  106. }
  107. //проверяем текущую запись
  108. if (!isset($printed[$row['id']])) {
  109. $f_index++;
  110. $user = get_record_sql($db_link,"SELECT * FROM user_auth WHERE id=?", [$row['id']]);
  111. if (empty($user['arp_found']) || is_empty_datetime($user['arp_found'])) { $user['arp_found'] = ''; }
  112. if (empty($user['ts']) || is_empty_datetime($user['ts'])) { $user['ts'] = ''; }
  113. if (empty($user['changed_time']) || is_empty_datetime($user['changed_time'])) { $user['changed_time'] = ''; }
  114. print "<tr align=center>\n";
  115. $cl = "data";
  116. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_auth_id[] value=".$user["id"];
  117. if ($f_index != $f_count) { print " checked"; }
  118. print " ></td>\n";
  119. print "<td class=\"$cl\" ><a href=/admin/users/edituser.php?id=".$user['user_id'].">" . get_login($db_link,$user['user_id']) . "</a></td>\n";
  120. print "<td class=\"$cl\" ><a href=/admin/users/editauth.php?id=".$user['id'].">" . $user['ip'] . "</a></td>\n";
  121. print "<td class=\"$cl\" >" . expand_mac($db_link,$user['mac']) . "</td>\n";
  122. if (isset($user['dhcp_hostname']) and strlen($user['dhcp_hostname']) > 0) {
  123. print "<td class=\"$cl\" >".$user['description']." [" . $user['dhcp_hostname'] . "]</td>\n";
  124. } else {
  125. print "<td class=\"$cl\" >".$user['description']."</td>\n";
  126. }
  127. print "<td class=\"$cl\" >".$user['dns_name']."</td>\n";
  128. print "<td class=\"$cl\" >".$user['ts']."</td>\n";
  129. print "<td class=\"$cl\" >".$user['last_found']."</td>\n";
  130. print "</tr>\n";
  131. $printed[$row['id']] = 1;
  132. }
  133. } else {
  134. $f_subnet = $row['net'];
  135. $f_mac = $row['mac'];
  136. $f_id = $row['id'];
  137. $f_index = 0;
  138. }
  139. }
  140. print "</table>\n";
  141. ?>
  142. </form>
  143. <br>
  144. <?php
  145. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  146. ?>