From 46a6110d504d0a30d5b18aa0432d8665b7ad8498 Mon Sep 17 00:00:00 2001 From: SJ Date: Fri, 2 Aug 2013 16:33:14 +0200 Subject: [PATCH] download audit log in csv --- webui/config.php | 2 ++ webui/controller/audit/download.php | 35 +++++++++++++++++++ webui/index.php | 4 +++ webui/model/audit/audit.php | 21 +++++++++++ webui/system/request.php | 24 +++++++++++++ .../theme/default/templates/audit/helper.tpl | 5 +++ .../theme/mobile/templates/audit/helper.tpl | 30 ++++++++-------- 7 files changed, 105 insertions(+), 16 deletions(-) create mode 100644 webui/controller/audit/download.php diff --git a/webui/config.php b/webui/config.php index bd2352df..96d821e7 100644 --- a/webui/config.php +++ b/webui/config.php @@ -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', diff --git a/webui/controller/audit/download.php b/webui/controller/audit/download.php new file mode 100644 index 00000000..299b86b8 --- /dev/null +++ b/webui/controller/audit/download.php @@ -0,0 +1,35 @@ +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(); + } + + +} + +?> diff --git a/webui/index.php b/webui/index.php index 0115788c..d2339154 100644 --- a/webui/index.php +++ b/webui/index.php @@ -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')) { diff --git a/webui/model/audit/audit.php b/webui/model/audit/audit.php index 4cbbd076..933beffc 100644 --- a/webui/model/audit/audit.php +++ b/webui/model/audit/audit.php @@ -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 = ""; diff --git a/webui/system/request.php b/webui/system/request.php index f8761434..21ac2c34 100644 --- a/webui/system/request.php +++ b/webui/system/request.php @@ -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; } + + } + +} + + ?> diff --git a/webui/view/theme/default/templates/audit/helper.tpl b/webui/view/theme/default/templates/audit/helper.tpl index bb2a47ef..13482286 100644 --- a/webui/view/theme/default/templates/audit/helper.tpl +++ b/webui/view/theme/default/templates/audit/helper.tpl @@ -101,6 +101,11 @@     + + 0) { ?> +   + + diff --git a/webui/view/theme/mobile/templates/audit/helper.tpl b/webui/view/theme/mobile/templates/audit/helper.tpl index ef04f95d..9c0a3054 100644 --- a/webui/view/theme/mobile/templates/audit/helper.tpl +++ b/webui/view/theme/mobile/templates/audit/helper.tpl @@ -23,30 +23,28 @@ + +
- + + 0) { ?> + + + +
- -