Code

23f6f01282db4e0ca7e21e57c683c6d6c8bc4022
[gosa.git] / include / class_log.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
22 /*! \brief   The plugin base class
23   \author  Cajus Pollmeier <pollmeier@gonicus.de>
24   \version 2.00
25   \date    24.07.2003
27   This is the base class for all plugins. It can be used standalone or
28   can be included by the tabs class. All management should be done
29   within this class. Extend your plugins from this class.
30  */
31 class log {
33   var $LOG_TO_MYSQL = FALSE;
34   var $LOG_TO_SYSLOG= FALSE;
35   
37  /*! \brief plugin constructor
39     If 'dn' is set, the node loads the given 'dn' from LDAP
41     \param dn Distinguished name to initialize plugin from
42     \sa plugin()
43    */
44   function log($action,$objecttype,$object,$changes_array = array(),$result = TRUE)
45   {
46     global $config;
48     $ui   = get_userinfo(); 
50     $changes  ="";
51     foreach($changes_array as $str ){
52       $changes .= $str.",";
53     }
54     $changes = preg_replace("/,$/","",$str);
55     
56     
57     $entry = array(); 
58     $entry['timestamp'] = time();
59     $entry['user']  =$ui->dn;
60     $entry['action'] = $action;
61     $entry['objecttype'] = $objecttype;
62     $entry['object'] = $object;
63     $entry['changes'] = $changes;
64     $entry['result'] = $result;
65  
66     if(isset($this->config->current['LOGGING']) && preg_match("/(^|,)syslog(,|$)/i",$this->config->current['LOGGING'])){
67       @log::log_into_syslog($entry);
68     }
69     if(isset($this->config->current['LOGGING']) && preg_match("/(^|,)mysql(,|$)/i",$this->config->current['LOGGING'])){
70       @log::log_into_db($entry);
71     }
72   }
74   
76   function log_into_syslog($entry)
77   {
78     $str = $entry['user']." ".$entry['action']." ".$entry['object']." from type ".$entry['objecttype']." ".$data." : Result was ".$entry['result'];
79     gosa_log($str);
80   }
83   function log_into_db($entry)
84   {
85     if(isset($this->config->data['SERVERS']['LOGGING'])){
86       $servers = $this->config->data['SERVERS']['LOGGING'];
87     }else{
88       print_red(_("You have enabled the logging into mysql databse, but there are no logging servers available."));
89       return(FALSE);
90     }
92     foreach($servers as $server_name => $server){
93   
94       $con = mysql_pconnect($server['SERVER'],$server['USER'],$server['PWD']);
95       if(!$con){
96         print_red(sprintf(_("Could not connect to logging server %s."),$server['SERVER']));
97       }else{
98         $db = mysql_select_db($server['DB'],$con);
99         if(!$db){
100           print_red(sprintf(_("Could not select database %s on server %s. Server ssys :%s"),$server['DB'],$server['SERVER'],mysql_error($con)));
101         }else{
103           /* Create mysql syntax */
104           $query ="INSERT INTO gosa_log 
105                     (timestamp,user,action,objecttype,object,changes,result)
106                    VALUES 
107                     (
108                         \"".addslashes($entry['timestamp'])."\", 
109                         \"".addslashes($entry['user'])."\", 
110                         \"".addslashes($entry['action'])."\", 
111                         \"".addslashes($entry['objecttype'])."\", 
112                         \"".addslashes($entry['object'])."\", 
113                         \"".addslashes($entry['changes'])."\", 
114                         \"".addslashes($entry['result'])."\" 
115                     );
116               ";
117           $res = mysql_query($query,$con);
118           if(!$res){
119             print_red(sprintf(_("Could not query database %s on server %s. Server ssys :%s"),$server['DB'],$server['SERVER'],mysql_error($con)));
120             
121           } 
122         }
123       }
124     }
125   }
133 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
134 ?>