diff options
Diffstat (limited to 'modules-available/syslog')
-rw-r--r-- | modules-available/syslog/hooks/cron.inc.php | 21 | ||||
-rw-r--r-- | modules-available/syslog/hooks/statistics/machine-replace.inc.php | 5 | ||||
-rw-r--r-- | modules-available/syslog/lang/de/messages.json | 4 | ||||
-rw-r--r-- | modules-available/syslog/lang/de/template-tags.json | 7 | ||||
-rw-r--r-- | modules-available/syslog/lang/en/messages.json | 4 | ||||
-rw-r--r-- | modules-available/syslog/lang/en/template-tags.json | 7 | ||||
-rw-r--r-- | modules-available/syslog/page.inc.php | 17 | ||||
-rw-r--r-- | modules-available/syslog/templates/page-syslog.html | 28 |
8 files changed, 84 insertions, 9 deletions
diff --git a/modules-available/syslog/hooks/cron.inc.php b/modules-available/syslog/hooks/cron.inc.php index bae882a9..62516648 100644 --- a/modules-available/syslog/hooks/cron.inc.php +++ b/modules-available/syslog/hooks/cron.inc.php @@ -1,7 +1,28 @@ <?php if (mt_rand(1, 10) === 1) { + // Prune old entries Database::exec("DELETE FROM clientlog WHERE (UNIX_TIMESTAMP() - 86400 * 190) > dateline"); + // Anonymize if requested + $days = Property::get('syslog.anon-days', 0); + if ($days > 0) { + $cutoff = time() - ($days * 86400); + Database::exec("UPDATE clientlog SET description = '[root] User logged in' + WHERE $cutoff > dateline AND logtypeid = 'session-open' AND description NOT LIKE '[root] User %'"); + Database::exec("UPDATE clientlog SET description = '[root] User logged out' + WHERE $cutoff > dateline AND logtypeid = 'session-close' AND description NOT LIKE '[root] User %'"); + Database::exec("UPDATE clientlog SET description = '-', extra = '' + WHERE $cutoff > dateline AND description NOT LIKE '-' + AND logtypeid NOT IN ('session-open', 'session-close', 'idleaction-busy', 'partition-temp', + 'partition-swap', 'smartctl-realloc', 'vmware-netifup', 'vmware-insmod', 'firewall-script-apply', + 'mount-vm-tmp-fail')"); + if (Module::get('statistics') !== false) { + Database::exec("UPDATE statistic SET username = 'anonymous' + WHERE $cutoff > dateline AND username NOT LIKE 'anonymous' AND username NOT LIKE ''"); + Database::exec("UPDATE machine SET currentuser = NULL + WHERE $cutoff > lastseen AND currentuser IS NOT NULL"); + } + } if (mt_rand(1, 100) === 1) { Database::exec("OPTIMIZE TABLE clientlog"); } diff --git a/modules-available/syslog/hooks/statistics/machine-replace.inc.php b/modules-available/syslog/hooks/statistics/machine-replace.inc.php new file mode 100644 index 00000000..6be0dd76 --- /dev/null +++ b/modules-available/syslog/hooks/statistics/machine-replace.inc.php @@ -0,0 +1,5 @@ +<?php + +foreach ($list as $entry) { + Database::exec('UPDATE IGNORE clientlog SET machineuuid = :new WHERE machineuuid = :old AND dateline < :datelimit', $entry); +} diff --git a/modules-available/syslog/lang/de/messages.json b/modules-available/syslog/lang/de/messages.json new file mode 100644 index 00000000..eec31c2f --- /dev/null +++ b/modules-available/syslog/lang/de/messages.json @@ -0,0 +1,4 @@ +{ + "anon-days-out-of-range": "Tage muss zwischen 0 und 180 liegen (war {{0}})", + "anon-days-saved": "Anonymisierungszeitraum gespeichert" +}
\ No newline at end of file diff --git a/modules-available/syslog/lang/de/template-tags.json b/modules-available/syslog/lang/de/template-tags.json index c8b2bb45..b5c6f8c7 100644 --- a/modules-available/syslog/lang/de/template-tags.json +++ b/modules-available/syslog/lang/de/template-tags.json @@ -1,11 +1,12 @@ { + "lang_anonDaysDescription": "Nach wie vielen Tagen sollen Logeintr\u00e4ge anonymisiert werden? Auf 0 setzen, um Funktion zu deaktivieren.", + "lang_applyFilter": "Filter anwenden", "lang_client": "Client", "lang_clientLog": "Client Log", "lang_details": "Details", "lang_event": "Ereignis", "lang_filter": "Filter", - "lang_go": "Go", "lang_not": "not", - "lang_when": "Wann", - "lang_applyFilter": "Filter anwenden" + "lang_settings": "Einstellungen", + "lang_when": "Wann" }
\ No newline at end of file diff --git a/modules-available/syslog/lang/en/messages.json b/modules-available/syslog/lang/en/messages.json new file mode 100644 index 00000000..5578d7b9 --- /dev/null +++ b/modules-available/syslog/lang/en/messages.json @@ -0,0 +1,4 @@ +{ + "anon-days-out-of-range": "Days have to be between 0 and 180 (was {{0}})", + "anon-days-saved": "Anonymization delay saved" +}
\ No newline at end of file diff --git a/modules-available/syslog/lang/en/template-tags.json b/modules-available/syslog/lang/en/template-tags.json index 7dae52d9..1aae1fe9 100644 --- a/modules-available/syslog/lang/en/template-tags.json +++ b/modules-available/syslog/lang/en/template-tags.json @@ -1,11 +1,12 @@ { + "lang_anonDaysDescription": "After how many days should log messages be anonymized? Set to 0 to disable this feature.", + "lang_applyFilter": "Apply Filter", "lang_client": "Client", "lang_clientLog": "Client Log", "lang_details": "Details", "lang_event": "Event", "lang_filter": "Filter", - "lang_go": "Go", "lang_not": "not", - "lang_when": "When", - "lang_applyFilter": "Apply Filter" + "lang_settings": "Settings", + "lang_when": "When" }
\ No newline at end of file diff --git a/modules-available/syslog/page.inc.php b/modules-available/syslog/page.inc.php index a34ceb53..a26ed9be 100644 --- a/modules-available/syslog/page.inc.php +++ b/modules-available/syslog/page.inc.php @@ -3,6 +3,9 @@ class Page_SysLog extends Page { + const PROP_ANON_DAYS = 'syslog.anon-days'; // Copy in cronjob + + protected function doPreprocess() { User::load(); @@ -11,6 +14,15 @@ class Page_SysLog extends Page Message::addError('main.no-permission'); Util::redirect('?do=Main'); } + if (($days = Request::post('anondays', false, 'int')) !== false) { + if ($days < 0 || $days > 180) { + Message::addError('anon-days-out-of-range', $days); + } else { + Property::set(self::PROP_ANON_DAYS, $days); + Message::addSuccess('anon-days-saved'); + } + Util::redirect('?do=syslog'); + } } protected function doRender() @@ -68,7 +80,7 @@ class Page_SysLog extends Page $allowedLocations = User::getAllowedLocations("view"); $joinClause = ""; if (!in_array(0, $allowedLocations)) { - $joinClause = "INNER JOIN machine ON machine.machineuuid = clientlog.machineuuid"; + $joinClause = "INNER JOIN machine USING (machineuuid)"; if (empty($whereClause)) $whereClause .= ' WHERE '; else @@ -78,7 +90,7 @@ class Page_SysLog extends Page } $lines = array(); - $paginate = new Paginate("SELECT logid, dateline, logtypeid, clientlog.clientip as clientip, description, extra FROM clientlog $joinClause $whereClause ORDER BY logid DESC", 50); + $paginate = new Paginate("SELECT logid, dateline, logtypeid, clientlog.clientip, clientlog.machineuuid, description, extra FROM clientlog $joinClause $whereClause ORDER BY logid DESC", 50); $res = $paginate->exec(array("allowedLocations" => $allowedLocations)); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $row['date'] = Util::prettyTime($row['dateline']); @@ -92,6 +104,7 @@ class Page_SysLog extends Page 'list' => $lines, 'types' => json_encode(array_values($types)), 'machineuuid' => Request::get('machineuuid'), + 'anondays' => Property::get(self::PROP_ANON_DAYS, 0), )); } diff --git a/modules-available/syslog/templates/page-syslog.html b/modules-available/syslog/templates/page-syslog.html index 9062dbaa..7ab81067 100644 --- a/modules-available/syslog/templates/page-syslog.html +++ b/modules-available/syslog/templates/page-syslog.html @@ -1,3 +1,6 @@ +<button type="button" class="btn btn-default pull-right" data-toggle="modal" data-target="#modal-settings"> + <span class="glyphicon glyphicon-cog"></span> {{lang_settings}} +</button> <style type="text/css"> .selectize-dropdown { max-width: 500px; @@ -44,7 +47,7 @@ <tr> <td><span class="type-button glyphicon {{icon}}" title="{{logtypeid}}"></span></td> <td class="text-center" nowrap="nowrap">{{date}}</td> - <td class="text-left">{{clientip}}</td> + <td class="text-left"><a href="?do=statistics&uuid={{machineuuid}}">{{clientip}}</a></td> <td>{{description}}</td> <td class="text-center">{{#extra}} <a class="btn btn-default btn-xs" onclick="$('#details-body').html($('#extra-{{logid}}').html())" @@ -73,6 +76,29 @@ </div> </div> +<div id="modal-settings" class="modal fade" role="dialog"> + <div class="modal-dialog"> + <div class="modal-content"> + <form method="post" action="?do=syslog"> + <input type="hidden" name="token" value="{{token}}"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal">×</button> + <h4 class="modal-title"><b>{{lang_settings}}</b></h4> + </div> + <div class="modal-body"> + <p>{{lang_anonDaysDescription}}</p> + <input type="number" name="anondays" value="{{anondays}}" min="0" max="180"> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal">{{lang_cancel}}</button> + <button type="submit" class="btn btn-primary">{{lang_save}}</button> + </div> + </form> + </div> + + </div> +</div> + <script type="application/javascript"><!-- document.addEventListener('DOMContentLoaded', function () { |