1
0

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