Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezaudit.php
Go to the documentation of this file.
1 <?php
11 class eZAudit
12 {
13 const DEFAULT_LOG_DIR = 'log/audit';
14
21 static function fetchAuditNameSettings()
22 {
23 $ini = eZINI::instance( 'audit.ini' );
24
25 $auditNames = $ini->hasVariable( 'AuditSettings', 'AuditFileNames' )
26 ? $ini->variable( 'AuditSettings', 'AuditFileNames' )
27 : array();
28 $varDir = eZINI::instance()->variable( 'FileSettings', 'VarDir' );
29 // concat varDir setting with LogDir setting
30 $logDir = $varDir . '/';
31 $logDir .= $ini->hasVariable( 'AuditSettings', 'LogDir' ) ? $ini->variable( 'AuditSettings', 'LogDir' ): self::DEFAULT_LOG_DIR;
32
33 $resultArray = array();
34 foreach ( array_keys( $auditNames ) as $auditNameKey )
35 {
36 $auditNameValue = $auditNames[$auditNameKey];
37 $resultArray[$auditNameKey] = array( 'dir' => $logDir,
38 'file_name' => $auditNameValue );
39 }
40 return $resultArray;
41 }
42
51 static function writeAudit( $auditName, $auditAttributes = array() )
52 {
53 $enabled = eZAudit::isAuditEnabled();
54 if ( !$enabled )
55 return false;
56
57 $auditNameSettings = eZAudit::auditNameSettings();
58
59 if ( !isset( $auditNameSettings[$auditName] ) )
60 return false;
61
62 $ip = eZSys::clientIP();
63 if ( !$ip )
64 $ip = eZSys::serverVariable( 'HOSTNAME', true );
65
66 $user = eZUser::currentUser();
67 $userID = $user->attribute( 'contentobject_id' );
68 $userLogin = $user->attribute( 'login' );
69
70 $message = "[$ip] [$userLogin:$userID]\n";
71
72 foreach ( array_keys( $auditAttributes ) as $attributeKey )
73 {
74 $attributeValue = $auditAttributes[$attributeKey];
75 $message .= "$attributeKey: $attributeValue\n";
76 }
77
78 $logName = $auditNameSettings[$auditName]['file_name'];
79 $dir = $auditNameSettings[$auditName]['dir'];
80 eZLog::write( $message, $logName, $dir );
81
82 return true;
83 }
84
90 static function isAuditEnabled()
91 {
92 if ( isset( $GLOBALS['eZAuditEnabled'] ) )
93 {
94 return $GLOBALS['eZAuditEnabled'];
95 }
96 $enabled = eZAudit::fetchAuditEnabled();
97 $GLOBALS['eZAuditEnabled'] = $enabled;
98 return $enabled;
99 }
100
107 static function fetchAuditEnabled()
108 {
109 $ini = eZINI::instance( 'audit.ini' );
110 $auditEnabled = $ini->hasVariable( 'AuditSettings', 'Audit' )
111 ? $ini->variable( 'AuditSettings', 'Audit' )
112 : 'disabled';
113 $enabled = $auditEnabled == 'enabled';
114 return $enabled;
115 }
116
122 static function auditNameSettings()
123 {
124 if ( isset( $GLOBALS['eZAuditNameSettings'] ) )
125 {
126 return $GLOBALS['eZAuditNameSettings'];
127 }
128 $nameSettings = eZAudit::fetchAuditNameSettings();
129 $GLOBALS['eZAuditNameSettings'] = $nameSettings;
130 return $nameSettings;
131 }
132 }
133 ?>
eZAudit
Definition: ezaudit.php:12
eZAudit\DEFAULT_LOG_DIR
const DEFAULT_LOG_DIR
Definition: ezaudit.php:13
eZAudit\isAuditEnabled
static isAuditEnabled()
Definition: ezaudit.php:90
eZAudit\writeAudit
static writeAudit( $auditName, $auditAttributes=array())
Definition: ezaudit.php:51
eZAudit\fetchAuditNameSettings
static fetchAuditNameSettings()
Definition: ezaudit.php:21
eZAudit\auditNameSettings
static auditNameSettings()
Definition: ezaudit.php:122
eZAudit\fetchAuditEnabled
static fetchAuditEnabled()
Definition: ezaudit.php:107
eZLog\write
static write( $message, $logName='common.log', $dir='var/log')
Definition: ezlog.php:29
eZSys\serverVariable
static serverVariable( $variableName, $quiet=false)
Definition: ezsys.php:856
eZSys\clientIP
static clientIP()
Definition: ezsys.php:714
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.