doubles.php 6.7 KB

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