Code

Updated client dns handling
[gosa.git] / include / class_log.inc
index 3b8a56c1aac24837cccb12a355c0b8126338769d..462be2892e3b53566e64def61b51400c6afe14ca 100644 (file)
@@ -45,9 +45,20 @@ class log {
    */
   function log($action,$objecttype,$object,$changes_array = array(),$result = TRUE)
   {
-    global $config;
-    $this->config = $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  ="";
@@ -57,30 +68,38 @@ class log {
     $changes = preg_replace("/,$/","",$changes );
     
     /* 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;
+
+    if(!isset($this->config->current['LOGGING']) && empty($entry['user'])){
+      $entry['user']  = "unknown";
+    }
  
     /* 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);
+        print_red("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);
+      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'])){
+          $this->log_into_db($entry);
+        }
       }
     }
   }
@@ -89,11 +108,11 @@ class log {
   function check($entry = array())
   {
     $msgs = array();
-    if(!isset($entry['user']) || empty($entry['user'])){
-      $msgs[] = "Currently active user is empty.";
-    }
+  #  if(!isset($entry['user']) || empty($entry['user'])){
+  #    $msgs[] = "Currently active user is empty.";
+  #  }
 
-    if(!isset($entry['action']) || !in_array($entry['action'],array("modify","create","remove","copy","snapshot","view"))){
+    if(!isset($entry['action']) || !in_array($entry['action'],array("modify","create","remove","copy","snapshot","view","security","debug"))){
       $msgs[] = "Invalid option specified '".$entry['action']."'";
     }
 
@@ -108,7 +127,7 @@ class log {
   /* 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);
   }
 
@@ -124,14 +143,14 @@ class log {
     }
 
     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){
-        print_red(sprintf(_("Could not connect to logging server %s."),$server['SERVER']));
+        print_red(sprintf(_("Could not connect to logging server %s."),$server_name));
       }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)));
         }else{
 
           /* Create mysql syntax */
@@ -154,6 +173,7 @@ class log {
             
           } 
         }
+        mysql_close($con);
       }
     }
   }