From b2642bf3b37ef9814889f3f56da335caa3acb99b Mon Sep 17 00:00:00 2001 From: e107steved Date: Sat, 29 Dec 2007 22:07:49 +0000 Subject: [PATCH] System logging updates --- e107_admin/admin_log.php | 113 +++++++++++++----- e107_handlers/admin_log_class.php | 21 ++-- .../English/admin/lan_admin_log.php | 16 +-- .../English/admin/lan_log_messages.php | 25 ++-- 4 files changed, 108 insertions(+), 67 deletions(-) diff --git a/e107_admin/admin_log.php b/e107_admin/admin_log.php index 9ec04b78b..767cf0e3f 100644 --- a/e107_admin/admin_log.php +++ b/e107_admin/admin_log.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_admin/admin_log.php,v $ -| $Revision: 1.6 $ -| $Date: 2007-12-26 15:12:59 $ +| $Revision: 1.7 $ +| $Date: 2007-12-29 22:07:42 $ | $Author: e107steved $ | | Preferences: @@ -32,7 +32,8 @@ Todo: require_once("../class2.php"); if (!getperms("S")) { - header("location:".e_BASE."index.php"); + header("location:".e_BASE."index.php"); + exit; } // Main language file should automatically be loaded @@ -69,17 +70,30 @@ $action = varset($qs[0],'adminlog'); include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_log_messages.php'); + + // ****************** MAINTENANCE ****************** +unset($back_count); if (isset($_POST['deleteoldadmin']) && isset($_POST['rolllog_clearadmin'])) { $back_count = $_POST['rolllog_clearadmin']; + $next_action = 'confdel'; +} +elseif (isset($_POST['deleteoldaudit']) && isset($_POST['rolllog_clearaudit'])) +{ + $back_count = $_POST['rolllog_clearaudit']; + $next_action = 'auditdel'; +} + +if (isset($back_count) && isset($next_action)) +{ if (($back_count >= 1) && ($back_count <= 90)) { $temp_date = getdate(); $old_date = intval(mktime(0,0,0,$temp_date['mon'],$temp_date['mday']-$back_count,$temp_date['year'])); $old_string = strftime("%d %B %Y",$old_date); // $message = "Back delete ".$back_count." days. Oldest date = ".$old_string; - $action = "confdel"; + $action = $next_action; $qs[1] = $old_date; $qs[2] = $back_count; } @@ -87,23 +101,40 @@ if (isset($_POST['deleteoldadmin']) && isset($_POST['rolllog_clearadmin'])) $message = RL_LAN_050; } + + if (!isset($admin_log)) $message .= " Admin Log not valid"; -// Actually delete back events -if ($action == "backdel") +// Actually delete back events - admin or user audit log +if (($action == "backdel") && isset($_POST['backdeltype'])) { -if (isset($_POST['confirmdeleteold'])) + if (isset($_POST['confirmdeleteold'])) { $old_date = intval($qs[1]); $old_string = strftime("%d %B %Y",$old_date); - $qry = "dblog_datestamp < ".$old_date; + $qry = "dblog_datestamp < ".$old_date; // Same field for both logs + switch ($_POST['backdeltype']) + { + case 'confdel' : + $db_table = 'admin_log'; + $db_name = RL_LAN_052; + $db_msg = 'LAN_ADMIN_LOG_002'; + break; + case 'auditdel' : + $db_table = 'audit_log'; + $db_name = RL_LAN_053; + $db_msg = 'LAN_ADMIN_LOG_003'; + break; + default : + exit; // Someone fooling around! + } // $message = "Back delete, oldest date = {$old_string} Query = {$qry}"; - if ($del_count = $sql -> db_Delete("admin_log",$qry)) + if ($del_count = $sql -> db_Delete($db_table,$qry)) { // Add in a log event - $admin_log->log_event ("db_Delete - earlier than {$old_string} (past {$qs[2]} days)", $qry, 4); - $message = RL_LAN_052.$old_string.RL_LAN_057.$del_count.RL_LAN_053; + $message = $db_name.str_replace(array('--OLD--','--NUM--'),array($old_string,$del_count),RL_LAN_057); + $admin_log->log_event($db_msg,"db_Delete - earlier than {$old_string} (past {$qs[2]} days)
".$message.'
'.$db_table.' '.$qry, 4,'LOG_01'); } else { @@ -140,15 +171,19 @@ if (varsettrue($message)) $ns->tablerender("", "
$message
"); } + + // Prompt to delete back events -if($action == "confdel") +if (($action == "confdel") || ($action == "auditdel")) { $old_string = strftime("%d %B %Y",$qs[1]); $text = "
+ - + @@ -157,6 +192,8 @@ if($action == "confdel") $ns->tablerender("
".RL_LAN_051."
", $text); } + + // Arrays of options for the various logs $log_db_table = array('adminlog' => 'admin_log', 'auditlog' => 'audit_log', 'rolllog' => 'dblog'); $back_day_count = array('adminlog' => 30, 'auditlog' => 30, 'rolllog' => max(intval($pref['roll_log_days']),1)); @@ -281,6 +318,20 @@ if($action == "config") $ns->tablerender("
".RL_LAN_064."
", $text); +function gen_log_delete($selectname) +{ + $values = array(90,60,30,21,20,14,10,7,6,5,4,3,2,1); + $ret = "\n"; + return $ret; +} + // Admin log options //================== @@ -289,24 +340,7 @@ if($action == "config")

".RL_LAN_047.$old_string."


"; + $text .= (($action == "confdel") ? RL_LAN_047 : RL_LAN_065).$old_string."

- \n
".RL_LAN_045." - - ".RL_LAN_046." + ".gen_log_delete('rolllog_clearadmin').RL_LAN_046."
@@ -383,6 +417,23 @@ $audit_checkboxes = array( $ns->tablerender("
".RL_LAN_007."
", $text); +// Audit Trail maintenance + $text = " + + + + + + \n + \n +
".RL_LAN_066." ".gen_log_delete('rolllog_clearaudit').RL_LAN_046." +
+ +
\n
"; + + $ns->tablerender("
".RL_LAN_003."
", $text); + + // Rolling log options //==================== $text = "
diff --git a/e107_handlers/admin_log_class.php b/e107_handlers/admin_log_class.php index 780c9d7a6..e8489d524 100644 --- a/e107_handlers/admin_log_class.php +++ b/e107_handlers/admin_log_class.php @@ -12,8 +12,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_handlers/admin_log_class.php,v $ -| $Revision: 1.6 $ -| $Date: 2007-12-18 20:57:37 $ +| $Revision: 1.7 $ +| $Date: 2007-12-29 22:07:42 $ | $Author: e107steved $ To do: @@ -77,7 +77,7 @@ class e_admin_log { define('USER_AUDIT_NEW_PW',16); // User changed password define('USER_AUDIT_NEW_EML',17); // User changed email define('USER_AUDIT_PW_RES',18); // Password reset - define('USER_AUDIT_NEW_SET',19); // User changed other settings (intentional gap in numbering) + define('USER_AUDIT_NEW_SET',19); // User changed other settings } /** @@ -87,23 +87,22 @@ class e_admin_log { * @param string $event_detail * @param int $event_type Log level */ - // Legacy entry point (not used by much) - retained for completeness. - // (Should really only be used for admin events anyway - not debugging) - function log_event($event_title, $event_detail, $event_type = E_LOG_INFORMATIVE) + // 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, $eventcode='ADMIN') { global $e107, $tp; - if($event_type >= $this->_options['log_level']) - { if($this->_options['backtrace'] == true) { $event_detail .= "\n\n".debug_backtrace(); } - $this->e_log_event($event_type,-1,"ADMIN",$event_title,$event_detail,FALSE,LOG_TO_ADMIN); - } + $this->e_log_event($event_type,-1,$eventcode,$event_title,$event_detail,FALSE,LOG_TO_ADMIN); } -// ***************************** START OF ADDITIONS ************************** /* +Generic log entry point +----------------------- Example call: (Deliberately pick separators that shouldn't be in file names) e_log_event(E_LOG_NOTICE,__FILE__."|".__FUNCTION__."@".__LINE__,"ECODE","Event Title","explanatory message",FALSE,LOG_TO_ADMIN); or: diff --git a/e107_languages/English/admin/lan_admin_log.php b/e107_languages/English/admin/lan_admin_log.php index 11717c221..474729c39 100644 --- a/e107_languages/English/admin/lan_admin_log.php +++ b/e107_languages/English/admin/lan_admin_log.php @@ -1,10 +1,10 @@