syslog.php 3.2 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. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/logfilter.php");
  7. if (isset($_POST['device_show'])) { $f_id = $_POST['device_show']*1; }
  8. if (isset($_GET['device_show'])) { $f_id = $_GET['device_show']*1; }
  9. if (!isset($f_id) and isset($_SESSION[$page_url]['device_show'])) { $f_id=$_SESSION[$page_url]['device_show']*1; }
  10. if (!isset($f_id)) { $f_id=0; }
  11. $_SESSION[$page_url]['device_show']=$f_id;
  12. print_log_submenu($page_url);
  13. $params = [$date1, $date2];
  14. $conditions = [];
  15. // === Фильтр по IP (через IN с параметрами) ===
  16. if ($f_id > 0) {
  17. $dev_ips = get_device_ips($db_link, $f_id);
  18. if (!empty($dev_ips)) {
  19. // Создаём плейсхолдеры: ?, ?, ?
  20. $placeholders = str_repeat('?,', count($dev_ips) - 1) . '?';
  21. $conditions[] = "ip IN ($placeholders)";
  22. $params = array_merge($params, $dev_ips);
  23. }
  24. }
  25. if (!empty($fmessage)) {
  26. $conditions[] = "message LIKE ?";
  27. $params[] = '%' . $fmessage . '%';
  28. }
  29. $whereClause = !empty($conditions) ? ' AND ' . implode(' AND ', $conditions) : '';
  30. $countSQL = "SELECT COUNT(*) FROM remote_syslog WHERE ts >= ? AND ts < ?" . $whereClause;
  31. $count_records = (int)get_single_field($db_link, $countSQL, $params);
  32. $total = ceil($count_records / $displayed);
  33. $page = max(1, min($page, $total));
  34. $start = ($page - 1) * $displayed;
  35. print_navigation($page_url, $page, $displayed, $count_records, $total);
  36. $limit = (int)$displayed;
  37. $offset = (int)$start;
  38. $dataParams = array_merge($params, [$limit, $offset]);
  39. $sSQL = "
  40. SELECT * FROM remote_syslog
  41. WHERE ts >= ? AND ts < ?" . $whereClause . "
  42. ORDER BY ts DESC
  43. LIMIT ? OFFSET ?
  44. ";
  45. $syslog = get_records_sql($db_link, $sSQL, $dataParams);
  46. ?>
  47. <div id="cont">
  48. <br>
  49. <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  50. <?php print_date_fields($date1,$date2,$date_shift); ?>
  51. <?php echo WEB_log_report_by_device; ?>&nbsp <?php print_device_select($db_link, "device_show", $f_id); ?>
  52. <?php print WEB_rows_at_page."&nbsp"; print_row_at_pages('rows',$displayed); ?>
  53. <input type="submit" value="<?php echo WEB_btn_show; ?>"><br><br>
  54. <?php echo WEB_log_filter_event; ?>:<input name="message" value="<?php echo $fmessage; ?>" />
  55. </form>
  56. <br>
  57. <table class="data" width="90%">
  58. <tr align="center">
  59. <td class="data" width=150><b><?php echo WEB_date; ?></b></td>
  60. <td class="data"><b><?php echo WEB_cell_ip; ?></b></td>
  61. <td class="data"><b><?php echo WEB_log_event; ?></b></td>
  62. </tr>
  63. <?php
  64. if (!empty($syslog)) {
  65. foreach ($syslog as $row) {
  66. print "<tr align=center class=\"tr1\" onmouseover=\"className='tr2'\" onmouseout=\"className='tr1'\">\n";
  67. print "<td class=\"data\">" . $row['ts'] . "</td>\n";
  68. print "<td class=\"data\">" . $row['ip'] . "</td>\n";
  69. print "<td class=\"data\">" . $row['message'] . "</td>\n";
  70. print "</tr>\n";
  71. }
  72. }
  73. print "</table>\n";
  74. print_navigation($page_url,$page,$displayed,$count_records,$total);
  75. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  76. ?>