dhcp.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/cidrfilter.php");
  7. if (isset($_POST['dhcp_show'])) { $f_dhcp = $_POST['dhcp_show']; }
  8. else {
  9. if (isset($_SESSION[$page_url]['f_dhcp'])) { $f_dhcp=$_SESSION[$page_url]['f_dhcp']; } else { $f_dhcp = 'all'; }
  10. }
  11. if (isset($_POST['ip'])) { $f_ip = $_POST['ip']; }
  12. if (!isset($f_ip) and isset($_SESSION[$page_url]['ip'])) { $f_ip=$_SESSION[$page_url]['ip']; }
  13. if (!isset($f_ip)) { $f_ip=''; }
  14. $_SESSION[$page_url]['f_dhcp']=$f_dhcp;
  15. $_SESSION[$page_url]['ip']=$f_ip;
  16. $dhcp_where = '';
  17. if ($f_dhcp != 'all') { $dhcp_where = " and action='$f_dhcp' "; }
  18. if (empty($rcidr)) { $cidr_filter = ''; } else {
  19. $cidr_range = cidrToRange($rcidr);
  20. if (!empty($cidr_range)) { $cidr_filter = " and (ip_int>=".ip2long($cidr_range[0])." and ip_int<=".ip2long($cidr_range[1]).")"; }
  21. }
  22. if (!empty($f_ip)) {
  23. if (checkValidIp($f_ip)) {
  24. $dhcp_where = " and ip_int=inet_aton('" . $f_ip . "') ";
  25. } else {
  26. if (checkValidMac($f_ip)) {
  27. $dhcp_where = " and mac='" . mac_dotted($f_ip) . "' ";
  28. } else { $dhcp_where = " and dhcp_hostname like '".$f_ip."%'"; }
  29. }
  30. }
  31. $dhcp_where .= $cidr_filter;
  32. print_log_submenu($page_url);
  33. ?>
  34. <div id="cont">
  35. <br>
  36. <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  37. <?php print_date_fields($date1,$date2,$date_shift); ?>
  38. <?php print WEB_rows_at_page."&nbsp"; print_row_at_pages('rows',$displayed); ?>
  39. <div><br>
  40. <?php echo WEB_network_subnet; ?>:&nbsp<?php print_subnet_select_office_splitted($db_link, 'cidr', $rcidr); ?>
  41. <?php echo WEB_log_event_type; ?>:&nbsp<?php print_dhcp_select('dhcp_show', $f_dhcp); ?>
  42. <input type="submit" value="<?php echo WEB_btn_show; ?>">
  43. <div><br>
  44. <?php echo WEB_log_select_ip_mac; ?>:&nbsp<input type="text" name="ip" value="<?php echo $f_ip; ?>" />
  45. </form>
  46. <?php
  47. $countSQL="SELECT Count(*) FROM dhcp_log WHERE `timestamp`>='$date1' AND `timestamp`<'$date2' $dhcp_where";
  48. $count_records = get_single_field($db_link,$countSQL);
  49. $total=ceil($count_records/$displayed);
  50. if ($page>$total) { $page=$total; }
  51. if ($page<1) { $page=1; }
  52. $start = ($page * $displayed) - $displayed;
  53. print_navigation($page_url,$page,$displayed,$count_records,$total);
  54. ?>
  55. <br>
  56. <table class="data" width="900">
  57. <tr align="center">
  58. <td class="data" width=150><b><?php echo WEB_log_time; ?></b></td>
  59. <td class="data"><b><?php echo WEB_cell_type; ?></b></td>
  60. <td class="data"><b><?php echo WEB_cell_mac; ?></b></td>
  61. <td class="data"><b><?php echo WEB_cell_ip; ?></b></td>
  62. <td class="data"><b><?php echo WEB_cell_dhcp_hostname; ?></b></td>
  63. </tr>
  64. <?php
  65. #speedup dhcp log paging
  66. $sSQL = "SELECT * FROM dhcp_log as D JOIN (SELECT id FROM dhcp_log WHERE `timestamp`>='$date1' and `timestamp`<'$date2' $dhcp_where ORDER BY `id` DESC LIMIT $start,$displayed) AS I ON D.id = I.id";
  67. $userlog = get_records_sql($db_link, $sSQL);
  68. foreach ($userlog as $row) {
  69. if ($row['action'] == "old") { $row['action'] = WEB_log_dhcp_old.": "; }
  70. if ($row['action'] == "add") { $row['action'] = WEB_log_dhcp_add.": "; }
  71. if ($row['action'] == "del") { $row['action'] = WEB_log_dhcp_del.": "; }
  72. $l_msg = $row['action'] . " " . $row['mac'] . " " . $row['ip'];
  73. print "<tr align=center class=\"tr1\" onmouseover=\"className='tr2'\" onmouseout=\"className='tr1'\">\n";
  74. print "<td class=\"data\">" . $row['timestamp'] . "</td>\n";
  75. print "<td class=\"data\">" . $row['action'] . "</td>\n";
  76. print "<td class=\"data\">" . $row['mac'] . "</td>\n";
  77. if (isset($row['auth_id']) and $row['auth_id'] > 0) {
  78. print "<td class=\"data\"><a href=/admin/users/editauth.php?id=".$row['auth_id'].">" . $row['ip'] . "</a></td>\n";
  79. } else {
  80. print "<td class=\"data\">" . $row['ip'] . "</td>\n";
  81. }
  82. print "<td class=\"data\">" . $row['dhcp_hostname'] . "</td>\n";
  83. print "</tr>\n";
  84. }
  85. print "</table>\n";
  86. print_navigation($page_url,$page,$displayed,$count_records[0],$total);
  87. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  88. ?>