added audit wildcard search

This commit is contained in:
SJ 2013-08-02 20:59:56 +02:00
parent 46a6110d50
commit 160eb1321e
3 changed files with 30 additions and 25 deletions

View File

@ -99,23 +99,20 @@ class ControllerAuditHelper extends Controller {
while(list($k, $v) = each($b)) { while(list($k, $v) = each($b)) {
if($v == '') { continue; } if($v == '') { continue; }
if(preg_match("/(login|loginfailed|logout|view|download|search|restore|journal)$/", $v) && isset($actions[$v])) { $this->a['action'] .= '*' . $actions[$v]; } if(preg_match("/(login|loginfailed|logout|view|download|search|restore|journal)$/", $v) && isset($actions[$v])) { $this->a['action'] .= "\t" . $actions[$v]; }
if(preg_match("/\@/", $v)) { $this->a['user'] .= '*' . $v; } if(preg_match("/\@/", $v)) { $this->a['user'] .= "\t" . $v; }
if(preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $v)) { $this->a['ipaddr'] .= '*' . $v; } if(preg_match("/\d{1,3}\.\d{1,3}\.(\d{1,3}|\*)\.(\d{1,3}|\*)/", $v)) { $this->a['ipaddr'] .= "\t" . $v; }
if(preg_match("/^\d{1,}$/", $v)) { $this->a['ref'] .= '*' . $v; } if(preg_match("/^\d{1,}$/", $v)) { $this->a['ref'] .= "\t" . $v; }
if(preg_match("/\d{4}(\-|\.)\d{1,2}(\-|\.)\d{1,2}/", $v) || preg_match("/\d{1,2}\/\d{1,2}\/\d{4}/", $v)) { if(preg_match("/\d{4}(\-|\.)(\d{1,2}|\*)(\-|\.)(\d{1,2}|\*)/", $v) || preg_match("/(\d{1,2}|\*)\/(\d{1,2}|\*)\/\d{4}/", $v)) {
$ndate++; $ndate++;
$this->a["date$ndate"] = $v; $this->a["date$ndate"] = $v;
} }
} }
$this->a['user'] = preg_replace("/^\t/", "", $this->a['user']);
$this->a['user'] = preg_replace("/^\*/", "", $this->a['user']); $this->a['ipaddr'] = preg_replace("/^\t/", "", $this->a['ipaddr']);
$this->a['ipaddr'] = preg_replace("/^\*/", "", $this->a['ipaddr']); $this->a['ref'] = preg_replace("/^\t/", "", $this->a['ref']);
$this->a['ref'] = preg_replace("/^\*/", "", $this->a['ref']); $this->a['action'] = preg_replace("/^\t/", "", $this->a['action']);
$this->a['action'] = preg_replace("/^\*/", "", $this->a['action']);
//if(isset($data['action'])) { $arr['action'] = $data['action']; }
if(isset($data['sort'])) { $this->a['sort'] = $data['sort']; } if(isset($data['sort'])) { $this->a['sort'] = $data['sort']; }
if(isset($data['order'])) { $this->a['order'] = $data['order']; } if(isset($data['order'])) { $this->a['order'] = $data['order']; }

View File

@ -24,20 +24,19 @@ class ModelAuditAudit extends Model {
$sortorder = "ORDER BY `$sort` $order"; $sortorder = "ORDER BY `$sort` $order";
if(isset($data['action']) && $data['action'] != ACTION_ALL) { if(isset($data['action']) && $data['action'] != ACTION_ALL) {
$where .= " AND action=?"; $where .= " AND ( " . $this->append_search_criteria("action", $data['action'], $arr) . " )";
array_push($arr, $data['action']);
} }
if(isset($data['ipaddr']) && $data['ipaddr']) { if(isset($data['ipaddr']) && $data['ipaddr']) {
$where .= " AND ipaddr IN (" . $this->append_search_criteria($data['ipaddr'], $arr) . ")"; $where .= " AND ( " . $this->append_search_criteria("ipaddr", $data['ipaddr'], $arr) . " )";
} }
if(isset($data['user']) && $data['user']) { if(isset($data['user']) && $data['user']) {
$where .= " AND email IN (" . $this->append_search_criteria($data['user'], $arr) . ")"; $where .= " AND ( " . $this->append_search_criteria("email", $data['user'], $arr) . " )";
} }
if(isset($data['ref']) && $data['ref']) { if(isset($data['ref']) && $data['ref']) {
$where .= " AND meta_id IN (" . $this->append_search_criteria($data['ref'], $arr) . ")"; $where .= " AND ( " . $this->append_search_criteria("meta_id", $data['ref'], $arr) . " )";
} }
if(Registry::get('admin_user') == 0) { if(Registry::get('admin_user') == 0) {
@ -67,6 +66,7 @@ class ModelAuditAudit extends Model {
$from = $data['page_len'] * $data['page']; $from = $data['page_len'] * $data['page'];
if($where) { if($where) {
$query = $this->db->query("SELECT COUNT(*) AS count FROM " . TABLE_AUDIT . " $where", $arr); $query = $this->db->query("SELECT COUNT(*) AS count FROM " . TABLE_AUDIT . " $where", $arr);
$n = $query->row['count']; $n = $query->row['count'];
@ -126,21 +126,26 @@ class ModelAuditAudit extends Model {
} }
private function append_search_criteria($s = '', &$arr = array()) { private function append_search_criteria($var = '', $s = '', &$arr = array()) {
$q = ""; $str = "";
$a = explode("*", $s); $a = explode("\t", $s);
for($i=0; $i<count($a); $i++) { for($i=0; $i<count($a); $i++) {
if($a[$i]) { if($a[$i]) {
$p = strchr($a[$i], '*');
if($p) {
$str .= "OR $var LIKE ? ";
array_push($arr, preg_replace("/\*.{0,}/", "%", $a[$i]));
}
else {
$str .= "OR $var = ? ";
array_push($arr, $a[$i]); array_push($arr, $a[$i]);
$q .= ",?"; }
} }
} }
$q = substr($q, 1, strlen($q)); return substr($str, 2, strlen($str));
return $q;
} }

View File

@ -407,6 +407,9 @@ function fixup_date_condition($field = '', $date1 = 0, $date2 = 0) {
if(DATE_TEMPLATE == 'd/m/Y') { $a = $y; $y = $d; $d = $a; } if(DATE_TEMPLATE == 'd/m/Y') { $a = $y; $y = $d; $d = $a; }
if($m == '*') { $m = 0; }
if($d == '*') { $d = 0; }
$date1 = mktime(0, 0, 0, $m, $d, $y); $date1 = mktime(0, 0, 0, $m, $d, $y);
if($date1 > 0) { $date .= "$field >= $date1 "; } if($date1 > 0) { $date .= "$field >= $date1 "; }