From: hickert Date: Fri, 11 May 2007 11:09:42 +0000 (+0000) Subject: Added initial logging class. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c90644e2298d8362789937e4c4e59b6be8ed26c4;p=gosa.git Added initial logging class. Not finished yet !!!! git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6360 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/class_config.inc b/include/class_config.inc index 762c6e0f9..5f3d8ceb5 100644 --- a/include/class_config.inc +++ b/include/class_config.inc @@ -420,6 +420,7 @@ class config { 'PASSWORD' => $attrs['goGlpiPassword'][0], 'DB' => $attrs['goGlpiDatabase'][0]); } + /* Get logdb server */ $ldap->cd ($this->current['BASE']); $ldap->search ("(objectClass=goLogDBServer)"); @@ -430,6 +431,20 @@ class config { 'PASSWORD' => $attrs['goLogPassword'][0]); } + /* Logging databases */ + $this->data['SERVERS']['LOGGING']= + array("testserver1" => + array( + "SERVER" => "localhost", + "USER" => "gosa_log", + "PWD" => "tester", + "DB" => "gosa_log" + ) + ); + + + + /* Get NFS server lists */ $tmp= array("default"); $ldap->cd ($this->current['BASE']); diff --git a/include/class_log.inc b/include/class_log.inc new file mode 100644 index 000000000..032254bb8 --- /dev/null +++ b/include/class_log.inc @@ -0,0 +1,137 @@ + + \version 2.00 + \date 24.07.2003 + + This is the base class for all plugins. It can be used standalone or + can be included by the tabs class. All management should be done + within this class. Extend your plugins from this class. + */ +class log { + + var $LOG_TO_MYSQL = FALSE; + var $LOG_TO_SYSLOG= FALSE; + + + /*! \brief plugin constructor + + If 'dn' is set, the node loads the given 'dn' from LDAP + + \param dn Distinguished name to initialize plugin from + \sa plugin() + */ + function log($action,$objecttype,$object,$changes_array = array(),$result = TRUE) + { + global $config; + + $ui = get_userinfo(); + + $changes =""; + foreach($changes_array as $str ){ + $changes .= $str.","; + } + $changes = preg_replace("/,$/","",$str); + + + $entry = array(); + $entry['timestamp'] = time(); + $entry['user'] =$ui->dn; + $entry['action'] = $action; + $entry['objecttype'] = $objecttype; + $entry['object'] = $object; + $entry['changes'] = $changes; + $entry['result'] = $result; + + + + + 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 log_into_syslog($entry) + { + $str = $entry['user']." ".$entry['action']." ".$entry['object']." from type ".$entry['objecttype']." ".$data." : Result was ".$entry['result']; + gosa_log($str); + } + + + function log_into_db($entry) + { + if(isset($this->config->data['SERVERS']['LOGGING'])){ + $servers = $this->config->data['SERVERS']['LOGGING']; + }else{ + print_red(_("You have enabled the logging into mysql databse, but there are no logging servers available.")); + return(FALSE); + } + + foreach($servers as $server_name => $server){ + + $con = mysql_pconnect($server['SERVER'],$server['USER'],$server['PWD']); + if(!$con){ + print_red(sprintf(_("Could not connect to logging server %s."),$server['SERVER'])); + }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))); + }else{ + + /* Create mysql syntax */ + $query ="INSERT INTO gosa_log + (timestamp,user,action,objecttype,object,changes,result) + VALUES + ( + \"".addslashes($entry['timestamp'])."\", + \"".addslashes($entry['user'])."\", + \"".addslashes($entry['action'])."\", + \"".addslashes($entry['objecttype'])."\", + \"".addslashes($entry['object'])."\", + \"".addslashes($entry['changes'])."\", + \"".addslashes($entry['result'])."\" + ); + "; + $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))); + + } + } + } + } + } +} + + + + + + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/personal/generic/class_user.inc b/plugins/personal/generic/class_user.inc index 5e45c80c8..924b7cf8b 100644 --- a/plugins/personal/generic/class_user.inc +++ b/plugins/personal/generic/class_user.inc @@ -113,6 +113,8 @@ class user extends plugin $this->attributes=array_merge($this->attributes,$this->govattrs); } + @log::log("view","users/user",$dn); + /* Load base attributes */ plugin::plugin ($config, $dn); @@ -936,8 +938,10 @@ class user extends plugin $ldap->cd ($this->dn); $ldap->$mode ($this->attrs); if (show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/generic account with dn '%s' failed."),$this->dn))){ + @log::log("modify","users/user",$this->dn,array_keys($this->attrs),$ldap->get_error()); return (1); } + @log::log("modify","users/user",$this->dn,array_keys($this->attrs),$ldap->get_error()); /* Remove cert? For some reason, the 'ldap' class doesn't want to remove binary entries, so I need