summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2013-12-17 15:22:57 +0100
committerSimon Rettberg2013-12-17 15:22:57 +0100
commit4981c766a8a1b74e119e9f3d5cc38c3b8210568a (patch)
tree595cb32b215a0b719f7f401e6e7ddb12ee8efbb6
parentAdded client log feature/view (diff)
downloadslx-admin-4981c766a8a1b74e119e9f3d5cc38c3b8210568a.tar.gz
slx-admin-4981c766a8a1b74e119e9f3d5cc38c3b8210568a.tar.xz
slx-admin-4981c766a8a1b74e119e9f3d5cc38c3b8210568a.zip
Remote client logging
-rw-r--r--DB_SCRIBBLE12
-rw-r--r--modules/syslog.inc.php36
-rw-r--r--templates/page-syslog.html16
3 files changed, 59 insertions, 5 deletions
diff --git a/DB_SCRIBBLE b/DB_SCRIBBLE
index 4f26bf52..2e3ba1ee 100644
--- a/DB_SCRIBBLE
+++ b/DB_SCRIBBLE
@@ -82,4 +82,16 @@ CREATE TABLE IF NOT EXISTS `user` (
UNIQUE KEY `login` (`login`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+CREATE TABLE `clientlog` (
+ `logid` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `dateline` int(10) unsigned NOT NULL,
+ `logtypeid` varchar(30) NOT NULL,
+ `clientip` varchar(40) NOT NULL,
+ `description` varchar(255) NOT NULL,
+ `extra` text NOT NULL,
+ PRIMARY KEY (`logid`),
+ KEY `dateline` (`dateline`),
+ KEY `logtypeid` (`logtypeid`,`dateline`),
+ KEY `clientip` (`clientip`,`dateline`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
diff --git a/modules/syslog.inc.php b/modules/syslog.inc.php
index ccbf1b32..348c40bd 100644
--- a/modules/syslog.inc.php
+++ b/modules/syslog.inc.php
@@ -9,14 +9,44 @@ if (!User::isLoggedIn()) {
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();
- $res = Database::simpleQuery('SELECT logid, dateline, logtypeid, clientip, description, extra FROM clientlog ORDER BY logid DESC LIMIT 200');
+ $res = Database::simpleQuery("SELECT logid, dateline, logtypeid, clientip, description, extra FROM clientlog $opt ORDER BY logid DESC LIMIT 200");
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $row['date'] = date('d.m.Y H:i', $row['dateline']);
+ $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;
}
- Render::addTemplate('page-syslog', array('token' => Session::get('token'), 'list' => $lines));
+ Render::addTemplate('page-syslog', array(
+ 'token' => Session::get('token'),
+ 'filter' => $filter,
+ 'not' => $not,
+ 'list' => $lines
+ ));
}
diff --git a/templates/page-syslog.html b/templates/page-syslog.html
index b7e4c98e..c741ab6b 100644
--- a/templates/page-syslog.html
+++ b/templates/page-syslog.html
@@ -1,6 +1,18 @@
<div class="container">
<h1>Client Log</h1>
- <table class="table table-striped">
+ <form method="post" action="?do=syslog">
+ <div class="input-group">
+ <span class="input-group-addon">Filter</span>
+ <input id="filterstring" type="text" class="form-control" placeholder="event-id" value="{{filter}}" name="filter">
+ <span class="input-group-addon">
+ <input type="checkbox" name="not" {{#not}}checked="checked"{{/not}}> not
+ </span>
+ <span class="input-group-btn">
+ <button class="btn btn-default" type="submit">Los</button>
+ </span>
+ </div>
+ </form>
+ <table class="table table-striped table-condensed">
<thead>
<th></th>
<th>Wann</th>
@@ -11,7 +23,7 @@
<tbody>
{{#list}}
<tr>
- <td><span class="glyphicon glyphicon-off"></span></td>
+ <td><span class="glyphicon glyphicon-off" title="{{logtypeid}}" onclick="$('#filterstring').val($('#filterstring').val() + ' {{logtypeid}}')"></span></td>
<td class="text-right" nowrap="nowrap">{{date}}</td>
<td>{{clientip}}</td>
<td>{{description}}</td>