1
0

doubles.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.*, S.subnet as net FROM user_auth U, subnets S
  55. 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
  56. ORDER BY net,mac,arp_found,id";
  57. $auth_list = get_records_sql($db_link,$sSQL, $params);
  58. $f_subnet=NULL;
  59. $f_mac=NULL;
  60. $f_id=NULL;
  61. $f_index = 0;
  62. $f_count = 0;
  63. foreach ($auth_list as $row) {
  64. if (empty($row['mac'])) { continue; }
  65. if (empty($row['net'])) { continue; }
  66. //инициализируем перебор по первой записи
  67. if (empty($f_subnet)) {
  68. $d_params = $params;
  69. //считаем сколько у нас дублей
  70. $dSQL = "SELECT U.*, S.subnet as net FROM user_auth U, subnets S WHERE S.office=1 AND U.deleted=0 AND (U.ip_int BETWEEN S.ip_int_start AND S.ip_int_stop) $cidr_filter AND U.mac=? AND S.subnet=?";
  71. $d_params[]= $row['mac'];
  72. $d_params[]= $row['net'];
  73. $doubles = get_records_sql($db_link,$dSQL, $d_params);
  74. $f_count = count($doubles);
  75. if ($f_count > 1) {
  76. //сохраняем для обработки
  77. $f_subnet = $row['net'];
  78. $f_mac=$row['mac'];
  79. $f_id=$row['id'];
  80. $f_index = 0;
  81. } else { continue; }
  82. }
  83. //начинаем перебор - проверяем
  84. if ($row['net'] === $f_subnet and $row['mac']===$f_mac) {
  85. $f_index++;
  86. if (empty($row['arp_found']) || is_empty_datetime($row['arp_found'])) { $row['arp_found'] = ''; }
  87. if (empty($row['ts']) || is_empty_datetime($row['ts'])) { $row['ts'] = ''; }
  88. if (empty($row['changed_time']) || is_empty_datetime($row['changed_time'])) { $row['changed_time'] = ''; }
  89. print "<tr align=center>\n";
  90. $cl = "data";
  91. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_auth_id[] value=".$row["id"];
  92. if ($f_index >1) {
  93. $checked = true;
  94. $mac_simplified = mac_simplify($row['mac']);
  95. $mac_rules = get_records_sql($db_link, "SELECT * FROM auth_rules WHERE rule_type = 2 AND LENGTH(rule) > 0 AND user_id = ?", [ $row['user_id'] ]);
  96. foreach ($mac_rules as $rule_row) {
  97. if (!empty($rule_row['rule'])) {
  98. $pattern = '/^' . preg_quote(mac_simplify($rule_row['rule']), '/') . '/';
  99. if (preg_match($pattern, $mac_simplified)) { $checked = false; break; }
  100. }
  101. }
  102. if ($checked) { print " checked"; }
  103. }
  104. print "></td>\n";
  105. print "<td class=\"$cl\" ><a href=/admin/users/edituser.php?id=".$row['user_id'].">" . get_login($db_link,$row['user_id']) . "</a></td>\n";
  106. print "<td class=\"$cl\" ><a href=/admin/users/editauth.php?id=".$row['id'].">" . $row['ip'] . "</a></td>\n";
  107. print "<td class=\"$cl\" >" . expand_mac($db_link,$row['mac']) . "</td>\n";
  108. if (isset($row['dhcp_hostname']) and strlen($row['dhcp_hostname']) > 0) {
  109. print "<td class=\"$cl\" >".$row['description']." [" . $row['dhcp_hostname'] . "]</td>\n";
  110. } else {
  111. print "<td class=\"$cl\" >".$row['description']."</td>\n";
  112. }
  113. print "<td class=\"$cl\" >".$row['dns_name']."</td>\n";
  114. print "<td class=\"$cl\" >".$row['ts']."</td>\n";
  115. print "<td class=\"$cl\" >".$row['last_found']."</td>\n";
  116. print "<td class=\"$cl\" ></td>\n";
  117. print "</tr>\n";
  118. } else {
  119. $f_subnet = NULL;
  120. $f_mac = NULL;
  121. $f_id = NULL;
  122. $f_index = 0;
  123. $f_count = 0;
  124. }
  125. }
  126. print "</table>\n";
  127. ?>
  128. </form>
  129. <br>
  130. <?php
  131. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  132. ?>