diff --git a/doc/API/Logs.md b/doc/API/Logs.md index 673adbece9..91d4c4b2b1 100644 --- a/doc/API/Logs.md +++ b/doc/API/Logs.md @@ -11,8 +11,8 @@ Input: - start: The page number to request. - limit: The limit of results to be returned. -- from: The date and time to search from. -- to: The data and time to search to. +- from: The date and time or the event id to search from. +- to: The data and time or the event id to search to. ### `list_eventlog` diff --git a/includes/html/api_functions.inc.php b/includes/html/api_functions.inc.php index c4252a52d9..f8af86f2f4 100644 --- a/includes/html/api_functions.inc.php +++ b/includes/html/api_functions.inc.php @@ -2235,18 +2235,22 @@ function list_logs(Illuminate\Http\Request $request, Router $router) $query = ' FROM eventlog LEFT JOIN `devices` ON `eventlog`.`device_id`=`devices`.`device_id` WHERE 1'; $full_query = 'SELECT `devices`.`hostname`, `devices`.`sysName`, `eventlog`.`device_id` as `host`, `eventlog`.*'; // inject host for backward compat $timestamp = 'datetime'; + $id_field = 'event_id'; } elseif ($type === 'list_syslog') { $query = ' FROM syslog LEFT JOIN `devices` ON `syslog`.`device_id`=`devices`.`device_id` WHERE 1'; $full_query = 'SELECT `devices`.`hostname`, `devices`.`sysName`, `syslog`.*'; $timestamp = 'timestamp'; + $id_field = 'seq'; } elseif ($type === 'list_alertlog') { $query = ' FROM alert_log LEFT JOIN `devices` ON `alert_log`.`device_id`=`devices`.`device_id` WHERE 1'; $full_query = 'SELECT `devices`.`hostname`, `devices`.`sysName`, `alert_log`.*'; $timestamp = 'time_logged'; + $id_field = 'id'; } elseif ($type === 'list_authlog') { $query = ' FROM authlog WHERE 1'; $full_query = 'SELECT `authlog`.*'; $timestamp = 'datetime'; + $id_field = 'id'; } else { $query = ' FROM eventlog LEFT JOIN `devices` ON `eventlog`.`device_id`=`devices`.`device_id` WHERE 1'; $full_query = 'SELECT `devices`.`hostname`, `devices`.`sysName`, `eventlog`.*'; @@ -2264,12 +2268,20 @@ function list_logs(Illuminate\Http\Request $request, Router $router) } if ($from) { - $query .= " AND $timestamp >= ?"; + if (is_numeric($from)) { + $query .= " AND $id_field >= ?"; + } else { + $query .= " AND $timestamp >= ?"; + } $param[] = $from; } if ($to) { - $query .= " AND $timestamp <= ?"; + if (is_numeric($to)) { + $query .= " AND $id_field <= ?"; + } else { + $query .= " AND $timestamp <= ?"; + } $param[] = $to; }