diff --git a/include/class_log.inc b/include/class_log.inc
index 032254bb81dc7c11692dfccf19d9f5d01c28d5a8..af687c39e605b2c64bcdc03cd0d0f0bc9ed97470 100644 (file)
--- a/include/class_log.inc
+++ b/include/class_log.inc
*/
*/
-/*! \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.
+/*! \brief The logging base class
+ \author Fabian Hickert <hickert@gonicus.de>
+ \version 2.6
+ \date 11.04.2007
+
+ This is the base class for the GOsa logging functionality.
+ All logging should lead to this class.
*/
class log {
var $LOG_TO_MYSQL = FALSE;
var $LOG_TO_SYSLOG= FALSE;
*/
class log {
var $LOG_TO_MYSQL = FALSE;
var $LOG_TO_SYSLOG= FALSE;
-
+ var $config;
- /*! \brief plugin constructor
+ /*! \brief logging constructor
- If 'dn' is set, the node loads the given 'dn' from LDAP
+ \param action One of these values (modify|create|remove|snapshot|copy)
+ \param objecttype represents the current edited objecttype, like users/user
+ \param object represents the current edited object dn
+ \param changes_array An array containing names of all touched attributes
+ \param result A status message, containing errors or success messages
- \param dn Distinguished name to initialize plugin from
- \sa plugin()
+ \sa log()
*/
function log($action,$objecttype,$object,$changes_array = array(),$result = TRUE)
{
*/
function log($action,$objecttype,$object,$changes_array = array(),$result = TRUE)
{
- global $config;
+ 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{
- $ui = get_userinfo();
+ $this->config = &$_SESSION['config'];
+ $ui = get_userinfo();
+ $entry['user']= @$ui->dn;
+ }
+ /* Create string out of changes */
$changes ="";
foreach($changes_array as $str ){
$changes .= $str.",";
}
$changes ="";
foreach($changes_array as $str ){
$changes .= $str.",";
}
- $changes = preg_replace("/,$/","",$str);
-
+ $changes = preg_replace("/,$/","",$changes );
- $entry = array();
+ /* Create data object */
$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";
+ }
-
+ /* 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{
- 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);
+ /* 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);
+ }
+ }
}
}
}
}
+
+ function check($entry = array())
+ {
+ $msgs = array();
+ # 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","security","debug"))){
+ $msgs[] = "Invalid option specified '".$entry['action']."'";
+ }
+
+ 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)
{
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);
}
+ /* Log into configured logging databses.*/
function log_into_db($entry)
{
if(isset($this->config->data['SERVERS']['LOGGING'])){
function log_into_db($entry)
{
if(isset($this->config->data['SERVERS']['LOGGING'])){
}
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));
}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)));
}else{
/* Create mysql syntax */
}else{
/* Create mysql syntax */
}
}
}
}
+ mysql_close($con);
}
}
}
}
}
}
}
}
-
-
-
-
-
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>