| 
									
										
										
										
											2015-04-24 14:34:06 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | $where = '1'; | 
					
						
							| 
									
										
										
										
											2015-04-24 14:34:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | if (!empty($_POST['searchPhrase'])) { | 
					
						
							|  |  |  |     $where .= ' AND S.msg LIKE "%'.mres($_POST['searchPhrase']).'%"'; | 
					
						
							| 
									
										
										
										
											2015-04-24 14:34:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | if ($_POST['program']) { | 
					
						
							|  |  |  |     $where  .= ' AND S.program = ?'; | 
					
						
							|  |  |  |     $param[] = $_POST['program']; | 
					
						
							| 
									
										
										
										
											2015-04-24 14:34:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | if (is_numeric($_POST['device'])) { | 
					
						
							|  |  |  |     $where  .= ' AND S.device_id = ?'; | 
					
						
							|  |  |  |     $param[] = $_POST['device']; | 
					
						
							| 
									
										
										
										
											2015-04-24 14:34:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | if (!empty($_POST['from'])) { | 
					
						
							|  |  |  |     $where  .= ' AND timestamp >= ?'; | 
					
						
							|  |  |  |     $param[] = $_POST['from']; | 
					
						
							| 
									
										
										
										
											2015-04-24 14:34:06 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | if (!empty($_POST['to'])) { | 
					
						
							|  |  |  |     $where  .= ' AND timestamp <= ?'; | 
					
						
							|  |  |  |     $param[] = $_POST['to']; | 
					
						
							| 
									
										
										
										
											2015-04-24 14:34:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | if ($_SESSION['userlevel'] >= '5') { | 
					
						
							|  |  |  |     $sql  = 'FROM syslog AS S'; | 
					
						
							|  |  |  |     $sql .= ' WHERE '.$where; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | else { | 
					
						
							|  |  |  |     $sql   = 'FROM syslog AS S, devices_perms AS P'; | 
					
						
							|  |  |  |     $sql  .= 'WHERE S.device_id = P.device_id AND P.user_id = ?'; | 
					
						
							|  |  |  |     $sql  .= $where; | 
					
						
							|  |  |  |     $param = array_merge(array($_SESSION['user_id']), $param); | 
					
						
							| 
									
										
										
										
											2015-04-24 14:34:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $count_sql = "SELECT COUNT(timestamp) $sql"; | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | $total     = dbFetchCell($count_sql, $param); | 
					
						
							| 
									
										
										
										
											2015-04-24 14:34:06 +00:00
										 |  |  | if (empty($total)) { | 
					
						
							|  |  |  |     $total = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (!isset($sort) || empty($sort)) { | 
					
						
							|  |  |  |     $sort = 'timestamp DESC'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $sql .= " ORDER BY $sort"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (isset($current)) { | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     $limit_low  = (($current * $rowCount) - ($rowCount)); | 
					
						
							| 
									
										
										
										
											2015-04-24 14:34:06 +00:00
										 |  |  |     $limit_high = $rowCount; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ($rowCount != -1) { | 
					
						
							|  |  |  |     $sql .= " LIMIT $limit_low,$limit_high"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-22 13:38:52 +01:00
										 |  |  | $sql = "SELECT S.*, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date $sql"; | 
					
						
							| 
									
										
										
										
											2015-04-24 14:34:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | foreach (dbFetchRows($sql, $param) as $syslog) { | 
					
						
							|  |  |  |     $dev        = device_by_id_cache($syslog['device_id']); | 
					
						
							|  |  |  |     $response[] = array( | 
					
						
							|  |  |  |         'timestamp' => $syslog['date'], | 
					
						
							|  |  |  |         'device_id' => generate_device_link($dev, shorthost($dev['hostname'])), | 
					
						
							|  |  |  |         'program'   => $syslog['program'], | 
					
						
							|  |  |  |         'msg'       => htmlspecialchars($syslog['msg']), | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2015-04-24 14:34:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | $output = array( | 
					
						
							|  |  |  |     'current'  => $current, | 
					
						
							|  |  |  |     'rowCount' => $rowCount, | 
					
						
							|  |  |  |     'rows'     => $response, | 
					
						
							|  |  |  |     'total'    => $total, | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2015-04-24 14:34:06 +00:00
										 |  |  | echo _json_encode($output); |