mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-25 08:20:11 +01:00
added audit wildcard search
This commit is contained in:
parent
46a6110d50
commit
160eb1321e
@ -99,23 +99,20 @@ class ControllerAuditHelper extends Controller {
|
||||
while(list($k, $v) = each($b)) {
|
||||
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("/\@/", $v)) { $this->a['user'] .= '*' . $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,}$/", $v)) { $this->a['ref'] .= '*' . $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("/(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'] .= "\t" . $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'] .= "\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)) {
|
||||
$ndate++;
|
||||
$this->a["date$ndate"] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->a['user'] = preg_replace("/^\*/", "", $this->a['user']);
|
||||
$this->a['ipaddr'] = preg_replace("/^\*/", "", $this->a['ipaddr']);
|
||||
$this->a['ref'] = preg_replace("/^\*/", "", $this->a['ref']);
|
||||
$this->a['action'] = preg_replace("/^\*/", "", $this->a['action']);
|
||||
|
||||
//if(isset($data['action'])) { $arr['action'] = $data['action']; }
|
||||
$this->a['user'] = preg_replace("/^\t/", "", $this->a['user']);
|
||||
$this->a['ipaddr'] = preg_replace("/^\t/", "", $this->a['ipaddr']);
|
||||
$this->a['ref'] = preg_replace("/^\t/", "", $this->a['ref']);
|
||||
$this->a['action'] = preg_replace("/^\t/", "", $this->a['action']);
|
||||
|
||||
if(isset($data['sort'])) { $this->a['sort'] = $data['sort']; }
|
||||
if(isset($data['order'])) { $this->a['order'] = $data['order']; }
|
||||
|
@ -24,20 +24,19 @@ class ModelAuditAudit extends Model {
|
||||
$sortorder = "ORDER BY `$sort` $order";
|
||||
|
||||
if(isset($data['action']) && $data['action'] != ACTION_ALL) {
|
||||
$where .= " AND action=?";
|
||||
array_push($arr, $data['action']);
|
||||
$where .= " AND ( " . $this->append_search_criteria("action", $data['action'], $arr) . " )";
|
||||
}
|
||||
|
||||
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']) {
|
||||
$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']) {
|
||||
$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) {
|
||||
@ -67,6 +66,7 @@ class ModelAuditAudit extends Model {
|
||||
|
||||
$from = $data['page_len'] * $data['page'];
|
||||
|
||||
|
||||
if($where) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS count FROM " . TABLE_AUDIT . " $where", $arr);
|
||||
$n = $query->row['count'];
|
||||
@ -126,21 +126,26 @@ class ModelAuditAudit extends Model {
|
||||
}
|
||||
|
||||
|
||||
private function append_search_criteria($s = '', &$arr = array()) {
|
||||
$q = "";
|
||||
private function append_search_criteria($var = '', $s = '', &$arr = array()) {
|
||||
$str = "";
|
||||
|
||||
$a = explode("*", $s);
|
||||
$a = explode("\t", $s);
|
||||
|
||||
for($i=0; $i<count($a); $i++) {
|
||||
if($a[$i]) {
|
||||
array_push($arr, $a[$i]);
|
||||
$q .= ",?";
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$q = substr($q, 1, strlen($q));
|
||||
|
||||
return $q;
|
||||
return substr($str, 2, strlen($str));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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($m == '*') { $m = 0; }
|
||||
if($d == '*') { $d = 0; }
|
||||
|
||||
$date1 = mktime(0, 0, 0, $m, $d, $y);
|
||||
|
||||
if($date1 > 0) { $date .= "$field >= $date1 "; }
|
||||
|
Loading…
Reference in New Issue
Block a user