1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-05 14:17:49 +02:00

admin log code formatting, small improvement

This commit is contained in:
secretr
2009-09-10 19:08:36 +00:00
parent f3d41194be
commit 4fb453dd46

View File

@@ -1,5 +1,4 @@
<?php <?php
/* /*
+ ----------------------------------------------------------------------------+ + ----------------------------------------------------------------------------+
| e107 website system | e107 website system
@@ -12,35 +11,34 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_handlers/admin_log_class.php,v $ | $Source: /cvs_backup/e107_0.8/e107_handlers/admin_log_class.php,v $
| $Revision: 1.14 $ | $Revision: 1.15 $
| $Date: 2008-12-21 22:17:05 $ | $Date: 2009-09-10 19:08:36 $
| $Author: e107steved $ | $Author: secretr $
To do: To do:
1. Do we need to check for presence of elements of debug_backtrace() to avoid notices? 1. Do we need to check for presence of elements of debug_backtrace() to avoid notices?
2. Reflect possible DB structure changes once finalised 2. Reflect possible DB structure changes once finalised
3. Ad user audit trail 3. Ad user audit trail
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
if (!defined('e107_INIT')) { exit; } if (!defined('e107_INIT'))
{
exit;
}
/** /**
* Admin logging class. * Admin logging class.
* *
*/ */
class e_admin_log { class e_admin_log
{
/** /**
* Contains default class options, plus any that are overidden by the constructor * Contains default class options, plus any that are overidden by the constructor
* *
* @var array * @var array
*/ */
var $_options = array( var $_options = array('log_level'=>2, 'backtrace'=>false, );
'log_level' => 2,
'backtrace' => false,
);
var $rldb = NULL; // Database used by logging routine var $rldb = NULL; // Database used by logging routine
/** /**
@@ -49,7 +47,7 @@ class e_admin_log {
* @param array $options * @param array $options
* @return e_admin_log * @return e_admin_log
*/ */
function e_admin_log ($options = array()) function __construct($options = array())
{ {
foreach ($options as $key=>$val) foreach ($options as $key=>$val)
{ {
@@ -82,15 +80,16 @@ class e_admin_log {
} }
/** /**
* Log an event to the core table * Alternative admin log entry point - compatible with legacy calls, and a bit simpler to use than the generic entry point.
* ($eventcode has been added - give it a reference to identify the source module, such as 'NEWS_12' or 'ECAL_03')
* We also log everything (unlike 0.7, where admin log and debug stuff were all mixed up together)
* *
* @param string $event_title * @param string $event_title
* @param string $event_detail * @param mixed $event_detail
* @param int $event_type Log level * @param integer $event_type [optional] Log level
* @param unknown $event_code [optional]
* @return e_admin_log
*/ */
// Alternative admin log entry point - compatible with legacy calls, and a bit simpler to use than the generic entry point.
// ($eventcode has been added - give it a reference to identify the source module, such as 'NEWS_12' or 'ECAL_03')
// We also log everything (unlike 0.7, where admin log and debug stuff were all mixed up together)
function log_event($event_title, $event_detail, $event_type = E_LOG_INFORMATIVE , $event_code = '') function log_event($event_title, $event_detail, $event_type = E_LOG_INFORMATIVE , $event_code = '')
{ {
global $e107,$tp; global $e107,$tp;
@@ -106,11 +105,28 @@ class e_admin_log {
$event_code = 'ADMIN'; $event_code = 'ADMIN';
} }
} }
//SecretR - now supports DB array as event_detail (see e.g. db::db_Insert())
if (is_array($event_detail))
{
$tmp = array();
if (isset($event_detail['data']))
{
foreach ($event_detail as $v)
{
$tmp[] = $v;
}
}
$event_detail = implode(', ', $tmp);
unset($tmp);
}
if ($this->_options['backtrace'] == true) if ($this->_options['backtrace'] == true)
{ {
$event_detail .= "\n\n".debug_backtrace(); $event_detail .= "\n\n".debug_backtrace();
} }
$this->e_log_event($event_type, -1, $event_code, $event_title, $event_detail, FALSE, LOG_TO_ADMIN); $this->e_log_event($event_type, -1, $event_code, $event_title, $event_detail, FALSE, LOG_TO_ADMIN);
return $this;
} }
/* /*
@@ -145,7 +161,8 @@ Generic log entry point
list($time_usec, $time_sec) = explode(" ", microtime()); // Log event time immediately to minimise uncertainty list($time_usec, $time_sec) = explode(" ", microtime()); // Log event time immediately to minimise uncertainty
$time_usec = $time_usec * 1000000; $time_usec = $time_usec * 1000000;
if ($this->rldb == NULL) $this->rldb = new db; // Better use our own db - don't know what else is going on if ($this->rldb == NULL)
$this->rldb = new db; // Better use our own db - don't know what else is going on
if (is_bool($target_logs)) if (is_bool($target_logs))
{ // Handle the legacy stuff for now - some old code used a boolean to select admin or rolling logs { // Handle the legacy stuff for now - some old code used a boolean to select admin or rolling logs
@@ -177,7 +194,6 @@ Generic log entry point
$explain = mysql_real_escape_string($tp->toDB($explain, true, false, 'no_html')); $explain = mysql_real_escape_string($tp->toDB($explain, true, false, 'no_html'));
$event_title = $tp->toDB($event_title, true, false, 'no_html'); $event_title = $tp->toDB($event_title, true, false, 'no_html');
//--------------------------------------- //---------------------------------------
// Admin Log // Admin Log
//--------------------------------------- //---------------------------------------
@@ -187,13 +203,11 @@ Generic log entry point
$this->rldb->db_Insert("admin_log", $qry); $this->rldb->db_Insert("admin_log", $qry);
} }
//--------------------------------------- //---------------------------------------
// Audit Log // Audit Log
//--------------------------------------- //---------------------------------------
// Add in audit log here // Add in audit log here
//--------------------------------------- //---------------------------------------
// Rolling Log // Rolling Log
//--------------------------------------- //---------------------------------------
@@ -214,7 +228,6 @@ Generic log entry point
} }
} }
if (is_array($source_call)) if (is_array($source_call))
{ // Print the debug_backtrace() array { // Print the debug_backtrace() array
while ($i < $back_count) while ($i < $back_count)
@@ -227,10 +240,13 @@ Generic log entry point
$explain .= "[!br!]".$k."=".$v; $explain .= "[!br!]".$k."=".$v;
} }
$i++; $i++;
if ($i < $back_count) $explain .= "[!br!]-------------------"; if ($i < $back_count)
if (!isset($tmp1)) $tmp1 = $tmp; // Pick off the immediate caller as the source $explain .= "[!br!]-------------------";
if (!isset($tmp1))
$tmp1 = $tmp; // Pick off the immediate caller as the source
} }
if (isset($tmp1)) $source_call = $tmp1; else $source_call = 'Root level'; if (isset($tmp1)) $source_call = $tmp1;
else $source_call = 'Root level';
} }
else else
{ {
@@ -247,10 +263,10 @@ Generic log entry point
$this->rldb->db_Delete("dblog", "dblog_datestamp < '".intval(time() - (varset($pref['roll_log_days'], 7) * 86400))."' "); $this->rldb->db_Delete("dblog", "dblog_datestamp < '".intval(time() - (varset($pref['roll_log_days'], 7) * 86400))."' ");
} }
if ($finished) exit; // Optional abort for all logs if ($finished)
exit; // Optional abort for all logs
} }
//-------------------------------------- //--------------------------------------
// USER AUDIT ENTRY // USER AUDIT ENTRY
//-------------------------------------- //--------------------------------------
@@ -265,13 +281,16 @@ Generic log entry point
// See whether we should log this // See whether we should log this
$user_logging_opts = array_flip(explode(',', varset($pref['user_audit_opts'], ''))); $user_logging_opts = array_flip(explode(',', varset($pref['user_audit_opts'], '')));
if (!isset($user_logging_opts[$event_type])) return; // Finished if not set to log this event type if (!isset($user_logging_opts[$event_type]))
return; // Finished if not set to log this event type
if ($this->rldb == NULL)
$this->rldb = new db; // Better use our own db - don't know what else is going on
if ($this->rldb == NULL) $this->rldb = new db; // Better use our own db - don't know what else is going on if ($id) $userid = $id;
else $userid = (USER === TRUE) ? USERID : 0;
if ($id) $userid = $id; else $userid = (USER === TRUE) ? USERID : 0; if ($u_name) $userstring = $u_name;
if ($u_name) $userstring = $u_name; else $userstring = ( USER === true ? USERNAME : "LAN_ANONYMOUS"); else $userstring = (USER === true ? USERNAME : "LAN_ANONYMOUS");
$userIP = $e107->getip(); $userIP = $e107->getip();
$eventcode = 'USER_'.$event_type; $eventcode = 'USER_'.$event_type;
@@ -286,7 +305,6 @@ Generic log entry point
$this->rldb->db_Insert("audit_log", "0, ".intval($time_sec).', '.intval($time_usec).", '{$eventcode}', {$userid}, '{$userstring}', '{$userIP}', '{$title}', '{$detail}' "); $this->rldb->db_Insert("audit_log", "0, ".intval($time_sec).', '.intval($time_usec).", '{$eventcode}', {$userid}, '{$userstring}', '{$userIP}', '{$title}', '{$detail}' ");
} }
function get_log_events($count = 15, $offset) function get_log_events($count = 15, $offset)
{ {
global $sql; global $sql;
@@ -294,7 +312,6 @@ Generic log entry point
return "Not implemented yet"; return "Not implemented yet";
} }
/** /**
* Removes all events older than $days, or truncates the table if $days == false * Removes all events older than $days, or truncates the table if $days == false
* *
@@ -342,7 +359,6 @@ Generic log entry point
return FALSE; return FALSE;
} }
// Logs an entry with all the data from an array, one field per line. // Logs an entry with all the data from an array, one field per line.
// If $extra is non-empty, it goes on the first line. // If $extra is non-empty, it goes on the first line.
// Normally data is in the format keyname=>value, one per line. // Normally data is in the format keyname=>value, one per line.