diff --git a/include/class_log.inc b/include/class_log.inc
index b46a5adc90bc5d6ba861d9be3073adefdfa06fe7..daad88908e19a8211f9338350e61f0021f146f40 100644 (file)
--- a/include/class_log.inc
+++ b/include/class_log.inc
var $LOG_TO_MYSQL = FALSE;
var $LOG_TO_SYSLOG= FALSE;
var $LOG_TO_MYSQL = FALSE;
var $LOG_TO_SYSLOG= FALSE;
-
+ var $config;
/*! \brief logging constructor
/*! \brief logging constructor
\sa log()
*/
\sa log()
*/
- function log($action,$objecttype,$object,$changes_array = array(),$result = TRUE)
+ function log($action,$objecttype,$object,$changes_array = array(),$result = "")
{
{
- global $config;
- $ui = get_userinfo();
+ if(!is_array($changes_array)){
+ trigger_error("log(string,string,string,array(),bool). Forth parameter must be an array.");
+ $changes_array = array();
+ }
+
+ $entry = array();
+ if(!isset($_SESSION['config'])){
+ $entry['user']= "unkown";
+ }else{
+
+ $this->config = &$_SESSION['config'];
+ $ui = get_userinfo();
+ $entry['user']= @$ui->dn;
+ }
/* Create string out of changes */
$changes ="";
/* Create string out of changes */
$changes ="";
$changes = preg_replace("/,$/","",$changes );
/* Create data object */
$changes = preg_replace("/,$/","",$changes );
/* Create data object */
- $entry = array();
$entry['timestamp'] = time();
$entry['timestamp'] = time();
- $entry['user'] =$ui->dn;
- $entry['action'] = $action;
- $entry['objecttype'] = $objecttype;
- $entry['object'] = $object;
- $entry['changes'] = $changes;
- $entry['result'] = $result;
+ $entry['action'] = $action;
+ $entry['objecttype']= $objecttype;
+ $entry['object'] = $object;
+ $entry['changes'] = $changes;
+ $entry['result'] = $result;
+
+ if(!isset($this->config->current['LOGGING']) && empty($entry['user'])){
+ $entry['user'] = "unknown";
+ }
- /* 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);
+ print_red("Logging failed, reason was: ".$msg);
+ }
+
+ }else{
+
+ if(!isset($this->config->current['LOGGING'])){
+ $this->log_into_syslog($entry);
+ }else{
+
+ /* Start logging for configured methods */
+ if(isset($this->config->current['LOGGING']) && preg_match("/(^|,)syslog(,|$)/i",$this->config->current['LOGGING'])){
+ $this->log_into_syslog($entry);
+ }
+ if(isset($this->config->current['LOGGING']) && preg_match("/(^|,)mysql(,|$)/i",$this->config->current['LOGGING'])){
+ $res = $this->log_into_db($entry);
+
+ if(!$res){
+ global $config;
+ $config->current['LOGGING'] = preg_replace("/(^|,)mysql(,|$)/",",",$config->current['LOGGING']);
+ msg_dialog::display(_("Logging to MySQL disabled"),_("The logging to a MySQL database is now disabled for this session of GOsa, due to communication errors with the specified logging database."), INFO_DIALOG);
+ }
+ }
+ }
+ }
+ }
+
+
+ function check($entry = array())
+ {
+ $msgs = array();
+
+ if(!isset($entry['action']) || !in_array($entry['action'],array("modify","create","remove","copy","snapshot","view","security","debug"))){
+ $msgs[] = "Invalid option specified '".$entry['action']."'";
}
}
- if(isset($this->config->current['LOGGING']) && preg_match("/(^|,)mysql(,|$)/i",$this->config->current['LOGGING'])){
- @log::log_into_db($entry);
+
+ if(!isset($entry['objecttype']) || empty($entry['objecttype'])){
+ $msgs[] = "Specified objectType is empty or invalid.";
}
}
+
+ return($msgs);
}
/* This function is used to into the systems syslog */
function log_into_syslog($entry)
{
}
/* This function is used to into the systems syslog */
function log_into_syslog($entry)
{
- $str = $entry['user']." ".$entry['action']." ".$entry['object']." from type ".$entry['objecttype']." ".$data." : Result was ".$entry['result'];
+ $str = $entry['user']." ".$entry['action']." ".$entry['object']." from type ".$entry['objecttype']." ".$entry['changes']." : Result was ".$entry['result'];
gosa_log($str);
}
gosa_log($str);
}
}
foreach($servers as $server_name => $server){
}
foreach($servers as $server_name => $server){
-
- $con = mysql_pconnect($server['SERVER'],$server['USER'],$server['PWD']);
+
+ $con = @mysql_pconnect($server_name,$server['USER'],$server['PWD']);
if(!$con){
if(!$con){
- print_red(sprintf(_("Could not connect to logging server %s."),$server['SERVER']));
+ print_red(sprintf(_("Could not connect to logging server %s."),$server_name));
+ return(FALSE);
}else{
$db = mysql_select_db($server['DB'],$con);
if(!$db){
}else{
$db = mysql_select_db($server['DB'],$con);
if(!$db){
- print_red(sprintf(_("Could not select database %s on server %s. Server ssys :%s"),$server['DB'],$server['SERVER'],mysql_error($con)));
+ print_red(sprintf(_("Could not select database %s on server %s. Server says :%s"),$server['DB'],$server['SERVER'],mysql_error($con)));
+ return(FALSE);
}else{
/* Create mysql syntax */
}else{
/* Create mysql syntax */
";
$res = mysql_query($query,$con);
if(!$res){
";
$res = mysql_query($query,$con);
if(!$res){
- print_red(sprintf(_("Could not query database %s on server %s. Server ssys :%s"),$server['DB'],$server['SERVER'],mysql_error($con)));
-
+ print_red(sprintf(_("Could not query database %s on server %s. Server says :%s"),$server['DB'],$server['SERVER'],mysql_error($con)));
+ return(FALSE);
}
}
}
}
+ mysql_close($con);
}
}
}
}
+ return(TRUE);
}
}
}
}