1
0

doubles.php 6.7 KB

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