38 static $validActions = [
'modify',
'create',
'remove',
'copy',
'snapshot',
'security',
'error'];
53 static function log (
string $action,
string $objecttype,
string $object, array $changes = [],
string $result =
'')
59 'timestamp' => microtime(TRUE),
61 'objecttype' => $objecttype,
63 'changes' => $changes,
66 if (isset($ui->dn) && !empty($ui->dn)) {
67 $entry[
'user'] = $ui->dn;
68 } elseif (isset($_SERVER[
'REMOTE_ADDR'])) {
69 $entry[
'user'] = $_SERVER[
'REMOTE_ADDR'];
71 $entry[
'user'] =
'unknown';
75 $msgs = static::check($entry);
77 foreach ($msgs as $msg) {
78 trigger_error(
'Logging failed, reason was: '.$msg);
83 if (is_object($config) && preg_match(
'/true/i', $config->get_cfg_value(
'logging',
''))) {
84 static::log_into_syslog($entry);
85 if (in_array($action, $config->get_cfg_value(
'auditActions', []))) {
86 static::log_into_ldap($entry);
110 static function debug (
int $level,
int $line,
string $function,
string $file, $data,
string $info =
'')
114 static $first = TRUE;
119 $output .=
'<div id="debug-handling" class="notice">'.
120 '<img src="geticon.php?context=status&icon=dialog-information&size=22" alt="Information" style="vertical-align:middle;margin-right:.2em;"/>'.
121 'There is some debug output '.
122 '<button onClick="javascript:$$(\'div.debug_div\').each(function (a) { a.toggle(); });">Toggle</button>'.
126 $logline =
"DEBUG[$level] ";
127 if ($function !=
'') {
128 $logline .=
"($file:$function():$line) - $info: ";
130 $logline .=
"($file:$line) - $info: ";
132 $output .=
'<div class="debug_div">';
134 if (is_array($data)) {
135 $output .= print_a($data, TRUE);
136 $logline .= print_r($data, TRUE);
138 $output .=
"'$data'";
139 $logline .=
"'$data'";
141 $output .=
"</div>\n";
143 if (is_object($config) && preg_match(
'/true/i', $config->get_cfg_value(
'debugLogging',
''))) {
147 if (($_SERVER[
'REQUEST_METHOD'] ==
'POST') && preg_match(
'/index.php$/', $_SERVER[
'REQUEST_URI'])) {
160 static protected function check ($entry = [])
164 if (!isset($entry[
'action']) || !in_array($entry[
'action'], static::$validActions)) {
165 $msgs[] = sprintf(_(
'Invalid option "%s" specified!'), $entry[
'action']);
168 if (!isset($entry[
'objecttype']) || empty($entry[
'objecttype'])) {
169 $msgs[] = _(
'Specified objectType is empty or invalid!');
180 static protected function log_into_syslog ($entry)
183 if (empty($entry[
'object']) && empty($entry[
'changes'])) {
184 $str =
'('.$entry[
'action'].
') '.$entry[
'objecttype'].
': '.$entry[
'result'];
186 $str =
'('.$entry[
'action'].
') '.$entry[
'object'].
' of type '.$entry[
'objecttype'].
' '.implode(
',', $entry[
'changes']).
': '.$entry[
'result'];
196 static protected function log_into_ldap ($entry)
199 if ($entry[
'objecttype'] ==
'plugin/auditEvent') {
203 if (empty($entry[
'object'])) {
204 $entry[
'object'] =
'none';
207 $tabObject = objects::create(
'auditEvent');
208 $baseObject = $tabObject->getBaseObject();
209 $baseObject->fdAuditDateTime = DateTime::createFromFormat(
'U.u', number_format($entry[
'timestamp'], 6,
'.',
''));
210 $baseObject->fdAuditAction = $entry[
'action'];
211 $baseObject->fdAuditAuthorDN = $entry[
'user'];
212 $baseObject->fdAuditObjectType = $entry[
'objecttype'];
213 $baseObject->fdAuditObject = $entry[
'object'];
214 $baseObject->fdAuditAttributes = $entry[
'changes'];
215 $baseObject->fdAuditResult = $entry[
'result'];
216 $baseObject->base = $config->current[
'BASE'];
217 $errors = $tabObject->save();
218 if (!empty($errors)) {
219 msg_dialog::displayChecks($errors);
224 _(
'Failed to log event (%s - %s): %s'),
226 $entry[
'objecttype'],
htmlescape(string $str)
Escape string for HTML output.
static get($name)
Accessor of a session var.
static check($entry=[])
Check the options.
fusiondirectory_log($message)
Generate a system log info.
static log(string $action, string $objecttype, string $object, array $changes=[], string $result='')
logging method
This is the base class for the FusionDirectory logging functionality. All logging should lead to this...
static debug(int $level, int $line, string $function, string $file, $data, string $info='')
Debug output method.
Parent class for all exceptions thrown in FusionDirectory.
Parent class for all errors in FusionDirectory.