FusionDirectory
 All Data Structures Files Functions Variables
class_logging.inc
Go to the documentation of this file.
1 <?php
2 
3 /*
4  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
5  Copyright (C) 2007 Fabian Hickert
6  Copyright (C) 2011-2016 FusionDirectory
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
36 class logging {
37  static $validActions = array('modify','create','remove','copy','snapshot','view','security','debug');
38 
52  static function log ($action, $objecttype, $object, array $changes_array = array(), $result = '')
53  {
54  global $config, $ui;
55 
56  if ($result === NULL) {
57  trigger_error('"Result" parameter should not be NULL');
58  $result = '';
59  }
60 
61  /* Create data object */
62  $entry = array(
63  'timestamp' => time(),
64  'action' => $action,
65  'objecttype' => $objecttype,
66  'object' => $object,
67  'changes' => $changes_array,
68  'result' => $result
69  );
70  if (isset($ui->dn) && !empty($ui->dn)) {
71  $entry['user'] = $ui->dn;
72  } else {
73  $entry['user'] = 'unknown';
74  }
75 
76  /* Check if all given values are valid */
77  $msgs = static::check($entry);
78  if (count($msgs)) {
79  foreach ($msgs as $msg) {
80  trigger_error('Logging failed, reason was: '.$msg);
81  msg_dialog::display(_('Internal error'), sprintf(_('Logging failed: %s'), $msg), ERROR_DIALOG);
82  }
83  } else {
84  if (is_object($config) && preg_match('/true/i', $config->get_cfg_value('logging', ''))) {
85  static::log_into_syslog($entry);
86  if (in_array($action, $config->get_cfg_value('auditActions', array()))) {
87  static::log_into_ldap($entry);
88  }
89  }
90  }
91  }
92 
98  static protected function check($entry = array())
99  {
100  $msgs = array();
101 
102  if (!isset($entry['action']) || !in_array($entry['action'], static::$validActions)) {
103  $msgs[] = sprintf(_('Invalid option "%s" specified!'), $entry['action']);
104  }
105 
106  if (!isset($entry['objecttype']) || empty($entry['objecttype'])) {
107  $msgs[] = _('Specified objectType is empty or invalid!');
108  }
109 
110  return $msgs;
111  }
112 
113  /*
114  * \brief This function is used to into the systems syslog
115  *
116  * \param Array $entry Entry to be loged
117  */
118  static protected function log_into_syslog($entry)
119  {
120  $str = '';
121  if (empty($entry['object']) && empty($entry['changes'])) {
122  $str = '('.$entry['action'].') '.$entry['objecttype'].': '.$entry['result'];
123  } else {
124  $str = '('.$entry['action'].') '.$entry['object'].' of type '.$entry['objecttype'].' '.implode(',', $entry['changes']).': '.$entry['result'];
125  }
126  fusiondirectory_log($str);
127  }
128 
129  /*
130  * \brief This function is used to into the ldap for audit plugin
131  *
132  * \param Array $entry Entry to be loged
133  */
134  static protected function log_into_ldap($entry)
135  {
136  global $config;
137  if ($entry['objecttype'] == 'plugin/auditEvent') {
138  /* Avoid infinite loop */
139  return;
140  }
141  if (empty($entry['object'])) {
142  $entry['object'] = 'none';
143  }
144  $tabObject = objects::create('auditEvent');
145  $baseObject = $tabObject->getBaseObject();
146  $baseObject->fdAuditDateTime = new DateTime('@'.$entry['timestamp']);
147  $baseObject->fdAuditAction = $entry['action'];
148  $baseObject->fdAuditAuthorDN = $entry['user'];
149  $baseObject->fdAuditObjectType = $entry['objecttype'];
150  $baseObject->fdAuditObject = $entry['object'];
151  $baseObject->fdAuditAttributes = $entry['changes'];
152  $baseObject->fdAuditResult = $entry['result'];
153  $baseObject->base = $config->current['BASE'];
154  $message = $tabObject->save();
155  if (!empty($message)) {
156  msg_dialog::displayChecks($message);
157  }
158  }
159 }
160 ?>
fusiondirectory_log($message)
Generate a system log info.
Definition: functions.inc:410
This is the base class for the FusionDirectory logging functionality. All logging should lead to this...
static check($entry=array())
Check the options.
static log($action, $objecttype, $object, array $changes_array=array(), $result= '')
logging method
static display($s_title, $s_message, $i_type=INFO_DIALOG)
Display a message dialog.