From: hickert Date: Mon, 14 May 2007 12:35:47 +0000 (+0000) Subject: Added some checks to logging class X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=393402bd6f7875b422726b00aad7c69bdaca55e7;p=gosa.git Added some checks to logging class git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6370 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/class_log.inc b/include/class_log.inc index b46a5adc9..2a9810f38 100644 --- a/include/class_log.inc +++ b/include/class_log.inc @@ -58,20 +58,48 @@ class log { /* Create data object */ $entry = array(); $entry['timestamp'] = time(); - $entry['user'] =$ui->dn; - $entry['action'] = $action; - $entry['objecttype'] = $objecttype; - $entry['object'] = $object; - $entry['changes'] = $changes; - $entry['result'] = $result; + $entry['user'] = $ui->dn; + $entry['action'] = $action; + $entry['objecttype']= $objecttype; + $entry['object'] = $object; + $entry['changes'] = $changes; + $entry['result'] = $result; - /* Start logging for configured methods */ - if(isset($this->config->current['LOGGING']) && preg_match("/(^|,)syslog(,|$)/i",$this->config->current['LOGGING'])){ - @log::log_into_syslog($entry); + /* Check if all given values are valid */ + $msgs = @log::check($entry); + if(count($msgs)){ + foreach($msgs as $msg){ + trigger_error("Logging failed, reason was: ".$msg); + } + }else{ + + /* Start logging for configured methods */ + if(isset($this->config->current['LOGGING']) && preg_match("/(^|,)syslog(,|$)/i",$this->config->current['LOGGING'])){ + @log::log_into_syslog($entry); + } + if(isset($this->config->current['LOGGING']) && preg_match("/(^|,)mysql(,|$)/i",$this->config->current['LOGGING'])){ + @log::log_into_db($entry); + } + } + } + + + function check($entry = array()) + { + $msgs = array(); + if(!isset($entry['user']) || empty($entry['user'])){ + $msgs[] = "Currently active user is empty."; } - if(isset($this->config->current['LOGGING']) && preg_match("/(^|,)mysql(,|$)/i",$this->config->current['LOGGING'])){ - @log::log_into_db($entry); + + if(!isset($entry['action']) || !in_array($entry['action'],array("modify","create","remove","copy","snapshot"))){ + $msgs[] = "Invalid option specified '".$entry['action']."'"; } + + if(!isset($entry['objecttype']) || empty($entry['objecttype'])){ + $msgs[] = "Specified objectType is empty or invalid."; + } + + return($msgs); }