ip.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/datetimefilter.php");
  6. $f_ip = getParam('ip', $page_url, '');
  7. $_SESSION[$page_url]['ip'] = $f_ip;
  8. print_log_submenu($page_url);
  9. ?>
  10. <div id="cont">
  11. <br>
  12. <?php echo WEB_log_mac_history_hint; ?>
  13. <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  14. <?php print_date_fields($date1,$date2,$date_shift); ?>
  15. <?php echo WEB_log_select_ip_mac; ?>:&nbsp<input type="text" name="ip" value="<?php echo $f_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])|([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})$"/>
  16. <?php print WEB_rows_at_page."&nbsp"; print_row_at_pages('rows',$displayed); ?>
  17. <input type="submit" value="<?php echo WEB_btn_show; ?>">
  18. </form>
  19. <?php
  20. $params = [$date1, $date2];
  21. $conditions = [];
  22. if (!empty($f_ip)) {
  23. if (checkValidIp($f_ip)) {
  24. $ip_long = sprintf('%u', ip2long($f_ip));
  25. $conditions[] = "ip_int = ?";
  26. $params[] = $ip_long;
  27. } elseif (checkValidMac($f_ip)) {
  28. $conditions[] = "mac = ?";
  29. $params[] = mac_dotted($f_ip);
  30. }
  31. }
  32. $whereClause = !empty($conditions) ? ' AND ' . implode(' AND ', $conditions) : '';
  33. $countSQL = "SELECT COUNT(*) FROM user_auth WHERE ts >= ? AND ts < ?" . $whereClause;
  34. $count_records = (int)get_single_field($db_link, $countSQL, $params);
  35. $total = ceil($count_records / $displayed);
  36. $page = max(1, min($page, $total));
  37. $start = ($page - 1) * $displayed;
  38. print_navigation($page_url, $page, $displayed, $count_records, $total);
  39. $dataParams = array_merge($params, [$displayed, $start]);
  40. $sSQL = "
  41. SELECT * FROM user_auth
  42. WHERE ts >= ? AND ts < ?" . $whereClause . "
  43. ORDER BY id DESC
  44. LIMIT ? OFFSET ?
  45. ";
  46. $iplog = get_records_sql($db_link, $sSQL, $dataParams);
  47. ?>
  48. <br>
  49. <table class="data">
  50. <tr align="center">
  51. <td class="data"><b>id</b></td>
  52. <td class="data" width=150><b><?php echo WEB_cell_created; ?></b></td>
  53. <td class="data" width=150><b><?php echo WEB_cell_last_found; ?></b></td>
  54. <td class="data"><b><?php echo WEB_cell_ip; ?></b></td>
  55. <td class="data"><b><?php echo WEB_cell_mac; ?></b></td>
  56. <td class="data"><b><?php echo WEB_cell_dhcp_hostname; ?></b></td>
  57. <td class="data"><b><?php echo WEB_cell_dns_name; ?></b></td>
  58. </tr>
  59. <?php
  60. foreach ($iplog as $row) {
  61. print "<tr align=center class=\"tr1\" onmouseover=\"className='tr2'\" onmouseout=\"className='tr1'\">\n";
  62. print "<td class=\"data\">" . $row['id'] . "</td>\n";
  63. print "<td class=\"data\">" . get_datetime_display($row['ts']) . "</td>\n";
  64. print "<td class=\"data\">" . get_datetime_display($row['last_found']) . "</td>\n";
  65. if (isset($row['id']) and $row['id'] > 0) {
  66. print "<td class=\"data\"><a href=/admin/users/editauth.php?id=".$row['id'].">" . $row['ip'] . "</a></td>\n";
  67. } else {
  68. print "<td class=\"data\">" . $row['ip'] . "</td>\n";
  69. }
  70. print "<td class=\"data\">" . expand_mac($db_link,mac_dotted($row['mac'])) . "</td>\n";
  71. print "<td class=\"data\">" . $row['dhcp_hostname'] . "</td>\n";
  72. print "<td class=\"data\">" . $row['dns_name'] . "</td>\n";
  73. print "</tr>\n";
  74. }
  75. print "</table>\n";
  76. print_navigation($page_url,$page,$displayed,$count_records,$total);
  77. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  78. ?>