2015-03-27 16:28:09 +00:00
< ? php
2015-07-13 20:10:26 +02:00
$where = '1' ;
2015-03-27 16:28:09 +00:00
2015-07-13 20:10:26 +02:00
if ( is_numeric ( $_POST [ 'device' ])) {
$where .= ' AND E.host = ?' ;
$param [] = $_POST [ 'device' ];
2015-03-27 16:28:09 +00:00
}
2015-07-13 20:10:26 +02:00
if ( $_POST [ 'string' ]) {
$where .= ' AND E.message LIKE ?' ;
$param [] = '%' . $_POST [ 'string' ] . '%' ;
2015-03-27 16:28:09 +00:00
}
if ( $_SESSION [ 'userlevel' ] >= '5' ) {
$sql = " FROM `eventlog` AS E LEFT JOIN `devices` AS `D` ON `E`.`host`=`D`.`device_id` WHERE $where " ;
2015-07-13 20:10:26 +02:00
}
else {
$sql = " FROM `eventlog` AS E, devices_perms AS P WHERE $where AND E.host = P.device_id AND P.user_id = ? " ;
2015-03-27 16:28:09 +00:00
$param [] = $_SESSION [ 'user_id' ];
}
if ( isset ( $searchPhrase ) && ! empty ( $searchPhrase )) {
$sql .= " AND (`D`.`hostname` LIKE '% $searchPhrase %' OR `E`.`datetime` LIKE '% $searchPhrase %' OR `E`.`message` LIKE '% $searchPhrase %' OR `E`.`type` LIKE '% $searchPhrase %') " ;
}
2015-03-27 16:47:26 +00:00
$count_sql = " SELECT COUNT(datetime) $sql " ;
2015-07-13 20:10:26 +02:00
$total = dbFetchCell ( $count_sql , $param );
2015-04-12 11:47:21 +01:00
if ( empty ( $total )) {
$total = 0 ;
}
2015-03-27 16:47:26 +00:00
2015-03-27 16:28:09 +00:00
if ( ! isset ( $sort ) || empty ( $sort )) {
$sort = 'datetime DESC' ;
}
$sql .= " ORDER BY $sort " ;
if ( isset ( $current )) {
2015-07-13 20:10:26 +02:00
$limit_low = (( $current * $rowCount ) - ( $rowCount ));
2015-03-27 16:28:09 +00:00
$limit_high = $rowCount ;
}
if ( $rowCount != - 1 ) {
$sql .= " LIMIT $limit_low , $limit_high " ;
}
2015-05-22 13:38:52 +01:00
$sql = " SELECT `E`.*,DATE_FORMAT(datetime, ' " . $config [ 'dateformat' ][ 'mysql' ][ 'compact' ] . " ') as humandate $sql " ;
2015-03-27 16:28:09 +00:00
2015-07-13 20:10:26 +02:00
foreach ( dbFetchRows ( $sql , $param ) as $eventlog ) {
2015-03-27 16:28:09 +00:00
$dev = device_by_id_cache ( $eventlog [ 'host' ]);
2015-07-13 20:10:26 +02:00
if ( $eventlog [ 'type' ] == 'interface' ) {
2015-03-27 16:28:09 +00:00
$this_if = ifLabel ( getifbyid ( $eventlog [ 'reference' ]));
2015-07-13 20:10:26 +02:00
$type = '<b>' . generate_port_link ( $this_if , makeshortif ( strtolower ( $this_if [ 'label' ]))) . '</b>' ;
}
else {
$type = 'System' ;
2015-03-27 16:28:09 +00:00
}
2015-07-13 20:10:26 +02:00
$response [] = array (
'datetime' => $eventlog [ 'humandate' ],
'hostname' => generate_device_link ( $dev , shorthost ( $dev [ 'hostname' ])),
'type' => $type ,
'message' => htmlspecialchars ( $eventlog [ 'message' ]),
);
2015-03-27 16:28:09 +00:00
}
2015-07-13 20:10:26 +02:00
$output = array (
'current' => $current ,
'rowCount' => $rowCount ,
'rows' => $response ,
'total' => $total ,
);
2015-03-27 16:28:09 +00:00
echo _json_encode ( $output );