Code

Added initial logging class.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 11 May 2007 11:09:42 +0000 (11:09 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 11 May 2007 11:09:42 +0000 (11:09 +0000)
Not finished yet !!!!

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6360 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_config.inc
include/class_log.inc [new file with mode: 0644]
plugins/personal/generic/class_user.inc

index 762c6e0f91510fe01dc74e672eddb143d97d8df6..5f3d8ceb56b0c281fe144fbd073d6a04109b6c5d 100644 (file)
@@ -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 (file)
index 0000000..032254b
--- /dev/null
@@ -0,0 +1,137 @@
+<?php
+/*
+   This code is part of GOsa (https://gosa.gonicus.de)
+   Copyright (C) 2003  Cajus Pollmeier
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+/*! \brief   The plugin base class
+  \author  Cajus Pollmeier <pollmeier@gonicus.de>
+  \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:
+?>
index 5e45c80c8cdbced18415d01641c5728172387408..924b7cf8bbc3f264b64cb4ca8bf34ce3354557d6 100644 (file)
@@ -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