summaryrefslogblamecommitdiffstats
path: root/modules/syslog.inc.php
blob: f8d99de3401e9dda98509260121e44cbd8ce1820 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13

     

                                     








                                       




                                                                
                                               









                                                                                                          
 

                                                   
                         

                                                                                                                                                
                                                      


                                                           
                                       
                                                
                                         
                 
                                                                     


                                
                                               




                                                    

 
<?php

require_once('inc/paginate.inc.php');

User::load();

if (!User::isLoggedIn()) {
	Util::redirect('?do=main');
}

function render_module()
{
	Render::setTitle('Client Log');
	
	$filter = '';
	$not = '';
	if (isset($_POST['filter'])) $filter = $_POST['filter'];
	if (!empty($filter)) {
		$parts = explode(',', $filter);
		$opt = array();
		foreach ($parts as $part) {
			$part = preg_replace('/[^a-z0-9_\-]/', '', trim($part));
			if (empty($part) || in_array($part, $opt)) continue;
			$opt[] = "'$part'";
		}
		if (isset($_POST['not'])) $not = 'NOT';
		if (!empty($opt)) $opt = ' WHERE logtypeid ' . $not . ' IN (' . implode(', ', $opt) . ')';
	}
	if (!isset($opt) || empty($opt)) $opt = '';

	$today = date('d.m.Y');
	$yesterday = date('d.m.Y', time() - 86400);
	$lines = array();
	$paginate = new Paginate("SELECT logid, dateline, logtypeid, clientip, description, extra FROM clientlog $opt ORDER BY logid DESC", 50);
	$res = $paginate->exec();
	while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
		$day = date('d.m.Y', $row['dateline']);
		// TODO: No output strings in source files!
		if ($day === $today) {
			$day = 'Heute';
		} elseif ($day === $yesterday) {
			$day = 'Gestern';
		}
		$row['date'] = $day . date(' H:i', $row['dateline']);
		$lines[] = $row;
	}
	
	$paginate->render('page-syslog', array(
		'token'    => Session::get('token'),
		'filter'   => $filter,
		'not'      => $not,
		'list'     => $lines
	));
}