download audit log in csv

This commit is contained in:
SJ 2013-08-02 16:33:14 +02:00
parent a35ef4be57
commit 46a6110d50
7 changed files with 105 additions and 16 deletions

View File

@ -205,6 +205,8 @@ $memcached_servers = array(
$partitions_to_monitor = array('/', '/home', '/var', '/tmp');
$config['DATA_PARTITION'] = '/var';
$config['DELIMITER'] = "\t";
$langs = array(
'hu',
'en',

View File

@ -0,0 +1,35 @@
<?php
class ControllerAuditDownload extends Controller {
public function index(){
$this->id = "content";
$this->template = "message/headers.tpl";
$this->layout = "common/layout-empty";
$request = Registry::get('request');
$db = Registry::get('db');
$this->load->model('audit/audit');
if(Registry::get('admin_user') == 0 && Registry::get('auditor_user') == 0) {
die("go away");
}
$this->document->title = $this->data['text_message'];
header("Cache-Control: public, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=audit-" . time() . ".csv");
header("Content-Transfer-Encoding: binary\n");
$this->model_audit_audit->print_audit_to_csv();
}
}
?>

View File

@ -7,6 +7,9 @@ require_once("config.php");
require(DIR_SYSTEM . "/startup.php");
$session = new Session();
Registry::set("session", $session);
$request = new Request();
Registry::set("request", $request);
@ -63,6 +66,7 @@ Registry::set('letters', $letters);
Registry::set('ldap_types', array("AD", "iredmail", "lotus", "zimbra"));
Registry::set('health_smtp_servers', $health_smtp_servers);
Registry::set('partitions_to_monitor', $partitions_to_monitor);
Registry::set('actions', $actions);
if(Registry::get('username')) {

View File

@ -79,8 +79,11 @@ class ModelAuditAudit extends Model {
if($n > 0) {
if($n > MAX_AUDIT_HITS) { $n = MAX_AUDIT_HITS; }
$query = $this->db->query("SELECT * FROM " . TABLE_AUDIT . " $where $sortorder LIMIT $from," . $data['page_len'], $arr);
$this->session->set("audit_query", array('where' => $where, 'sortorder' => $sortorder, 'arr' => $arr));
if(ENABLE_SYSLOG == 1) { syslog(LOG_INFO, sprintf("audit query: '%s', param: '%s' in %.2f s, %d hits", $query->query, implode(' ', $arr), $query->exec_time, $query->num_rows)); }
if(isset($query->rows)) {
@ -105,6 +108,24 @@ class ModelAuditAudit extends Model {
}
public function print_audit_to_csv() {
$actions = array_flip(Registry::get('actions'));
$a = $this->session->get("audit_query");
if(isset($a['where']) && isset($a['sortorder']) && isset($a['arr'])) {
print "Date" . DELIMITER . "ID" . DELIMITER . "User" . DELIMITER . "IP-address" . DELIMITER . "Action" . DELIMITER . "Piler ID" . DELIMITER . "Description\n";
$query = $this->db->query("SELECT * FROM " . TABLE_AUDIT . " " . $a['where'] . " " . $a['sortorder'], $a['arr']);
foreach($query->rows as $q) {
if(DEMO_MODE == 1) { $q['ipaddr'] = anonimize_ip_addr($q['ipaddr']); }
print date(DATE_TEMPLATE . " H:i:s", $q['ts']) . DELIMITER . $q['id'] . DELIMITER . $q['email'] . DELIMITER . $q['ipaddr'] . DELIMITER . $actions[$q['action']] . DELIMITER . $q['piler_id'] . DELIMITER . $q['description'] . "\n";
}
}
}
private function append_search_criteria($s = '', &$arr = array()) {
$q = "";

View File

@ -23,4 +23,28 @@ class Request {
}
class Session {
public function __construct() {
//session_start();
}
public function get($s = '') {
if($s && isset($_SESSION[$s])) { return $_SESSION[$s]; }
return '';
}
public function set($k = '', $v = '') {
if($k) { $_SESSION[$k] = $v; }
}
}
?>

View File

@ -101,6 +101,11 @@
<?php if($page < $total_pages) { ?> &nbsp; <a href="#" class="navlink" onclick="Piler.navigation(<?php print $total_pages; ?>);"><i class="icon-double-angle-right icon-large"></i></a><?php } else { ?> <span class="navlink"><i class="icon-double-angle-right icon-large"></i></span><?php } ?>
&nbsp;
<?php } else { print $text_none_found; } ?>
<?php if($n > 0) { ?>
&nbsp; <a href="index.php?route=audit/download"><button class="btn btn-small btn-inverse">Export CSV</button></a>
<?php } ?>
</div>
</div>

View File

@ -23,30 +23,28 @@
</div>
</div>
<div class="boxfooter">
<div id="pagenav">
<div class="navrow">
<?php if($n >= $page_len){ ?>
<div id="pagingleft">
<?php if($page > 0) { ?><a href="#" class="navlink" onclick="Piler.navigation(0);">&lt;&lt;</a> &nbsp; <?php } else { ?><span class="navlink">&lt;&lt; &nbsp; </span><?php } ?>
<?php if($page > 0) { ?><a href="#" class="navlink" onclick="Piler.navigation(<?php print $prev_page; ?>);"> &lt; </a> <?php } else { ?><span class="navlink"> &lt; </span><?php } ?>
</div>
<span class="piler-right-margin">
<?php if($page > 0) { ?><a href="#" onclick="Piler.navigation(0);">&lt;&lt;</a> &nbsp; <?php } else { ?><span class="navlink">&lt;&lt; &nbsp; </span><?php } ?>
<?php if($page > 0) { ?><a href="#" onclick="Piler.navigation(<?php print $prev_page; ?>);"> &lt; </a> <?php } else { ?><span class="navlink"> &lt; </span><?php } ?>
<div id="pagingcenter">
<?php print $hits_from; ?>-<?php print $hits_to; ?>, <?php print $text_total; ?>: <?php print $n; ?>
</div>
<div id="pagingright">
<?php if($next_page <= $total_pages){ ?><a href="#" class="navlink" onclick="Piler.navigation(<?php print $next_page; ?>);">&gt; </a> <?php } else { ?><span class="navlink">&gt; </span><?php } ?>
<?php if($page < $total_pages) { ?> &nbsp; <a href="#" class="navlink" onclick="Piler.navigation(<?php print $total_pages; ?>);"> &gt;&gt; </a><?php } else { ?> <span class="navlink"> &nbsp; &gt;&gt;</span><?php } ?>
</div>
<?php if($next_page <= $total_pages){ ?><a href="#" onclick="Piler.navigation(<?php print $next_page; ?>);">&gt; </a> <?php } else { ?><span class="navlink">&gt; </span><?php } ?>
<?php if($page < $total_pages) { ?> &nbsp; <a href="#" onclick="Piler.navigation(<?php print $total_pages; ?>);"> &gt;&gt; </a><?php } else { ?> <span class="navlink"> &nbsp; &gt;&gt;</span><?php } ?>
</span>
<?php } else { ?>&nbsp;<?php } ?>
</div>
</div>
<?php if($n > 0) { ?>
<a href="index.php?route=audit/download"><button class="btn btn-medium btn-inverse">Export CSV</button>
<?php } ?>
</div>
</div>