Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Item13063: Log all configuration changes
This causes configure to log all changes to the 'notice' level - log
level 2.

Format of log message is:

| timestamp level | username | remote IP | Config key | Old value | New Value |
  • Loading branch information
gac410 committed Nov 6, 2014
1 parent 5b07d2a commit 879ea8f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
11 changes: 10 additions & 1 deletion core/lib/Foswiki.spec
Expand Up @@ -1204,7 +1204,7 @@ $Foswiki::cfg{DebugFileName} = '';
# or Foswiki 1.1 logging directory =$Foswiki::cfg{Log}{Dir}/warn%DATE%.txt=
$Foswiki::cfg{WarningFileName} = '';
# **PATH**
# **PATH DISPLAY_IF="/Compatibility/i.test({Log}{Implementation}) || {LogFileName}"**
# Log file recording web activity when using the Compatibility logger
# (High volume). If =%DATE%= is included in the file name, it gets expanded
# to YYYYMM (year, month), causing a new log to be written each month.
Expand All @@ -1215,6 +1215,15 @@ $Foswiki::cfg{WarningFileName} = '';
# or Foswiki 1.1 logging directory =$Foswiki::cfg{Log}{Dir}/log%DATE%.txt=
$Foswiki::cfg{LogFileName} = '';
# **PATH DISPLAY_IF="/Compatibility/i.test({Log}{Implementation}) || {ConfigureLogFileName}"**
# Log file recording configuration changes when using the Compatibility logger
# If =%DATE%= is included in the file name, it gets expanded
# to YYYYMM (year, month), causing a new log to be written each month.
#
# To use the Compatibility logger, set this to a valid file path and name.
#
$Foswiki::cfg{ConfigureLogFileName} = '';
#---++ Statistics
# Statistics are usually assembled by a cron script
Expand Down
48 changes: 30 additions & 18 deletions core/lib/Foswiki/Configure/Wizards/Save.pm
Expand Up @@ -278,6 +278,8 @@ sub save {
sub _compareConfigs {
my ( $spec, $o, $n, $reporter, $keypath ) = @_;

my $session = $Foswiki::Plugins::SESSION;

return 1 unless ( defined $o || defined $n );

my $old =
Expand All @@ -287,14 +289,18 @@ sub _compareConfigs {
Foswiki::Configure::Reporter::ellipsis(
Foswiki::Configure::Reporter::uneval($n), CHANGE_LIMIT );

# Intermediates on the road to a value will return undef here.
my $vs = $spec->getValueObject($keypath);
if ( $vs && $vs->{typename} eq 'PASSWORD' ) {
$old = '_[redacted]_';
$new = '_[redacted]_';
}

if ( ref($o) ne ref($n) ) {
$reporter->NOTE("| $keypath | $old | $new |") if $reporter;
_logAndReport( $reporter, $session, $keypath, $old, $new );
return 0;
}

# Intermediates on the road to a value will return undef here.
my $vs = $spec->getValueObject($keypath);

# We know they are the same type
if ( ref($o) eq 'HASH' ) {
my %keys = map { $_ => 1 } ( keys %$o, keys %$n );
Expand All @@ -319,9 +325,7 @@ sub _compareConfigs {

if ( ref($o) eq 'ARRAY' ) {
if ( scalar(@$o) != scalar(@$n) ) {
if ($reporter) {
$reporter->NOTE("| $keypath | $old | $new |");
}
_logAndReport( $reporter, $session, $keypath, $old, $new );
return 0;
}
else {
Expand All @@ -332,9 +336,7 @@ sub _compareConfigs {
)
)
{
if ($reporter) {
$reporter->NOTE("| $keypath | $old | $new |");
}
_logAndReport( $reporter, $session, $keypath, $old, $new );
return 0;
}
}
Expand All @@ -344,20 +346,30 @@ sub _compareConfigs {
|| ( defined $o && !defined $n )
|| $o ne $n )
{
if ($reporter) {
if ( $vs && $vs->{typename} eq 'PASSWORD' ) {
$reporter->NOTE("| $keypath | _[redacted]_ | _[redacted]_ |");
}
else {
$reporter->NOTE("| $keypath | $old | $new |");
}
}
_logAndReport( $reporter, $session, $keypath, $old, $new );
return 0;
}

return 1;
}

sub _logAndReport {
my ( $reporter, $session, $keypath, $old, $new ) = @_;

$session->logger->log(
{
level => 'notice',
action => 'save',
setting => $keypath,
newvalue => $new,
oldvalue => $old,
}
);
if ($reporter) {
$reporter->NOTE("| $keypath | $old | $new |");
}
}

# $datum starts as \%Foswiki::cfg and recurses down the hash tree
sub _generateLSC {
my ( $spec, $datum, $keys, $reporter ) = @_;
Expand Down
6 changes: 6 additions & 0 deletions core/lib/Foswiki/Logger.pm
Expand Up @@ -242,6 +242,12 @@ sub getOldCall {
push( @fields, $extra );
push( @fields, $fhash->{remoteAddr} || '' );
}
elsif ( $level eq 'notice' ) { # Configuration changes logged as notice
foreach my $key (qw( user remoteAddr setting oldvalue newvalue)) {
push( @fields, $fhash->{$key} || '' );
delete $fhash->{$key};
}
}
else {
push( @fields, $fhash->{caller} ) if defined $fhash->{caller};
push( @fields, @{ $fhash->{extra} } ) if defined $fhash->{extra};
Expand Down

0 comments on commit 879ea8f

Please sign in to comment.