File: listlogfiles

package info (click to toggle)
apache 1.3.34-4.1
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 4,800 kB
  • ctags: 90
  • sloc: sh: 1,273; makefile: 685; perl: 215
file content (57 lines) | stat: -rw-r--r-- 1,276 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl
#
# Scans all config files (as given by listconffiles) and finds all log files
# definitions.
#
# Pierfrancesco Caci, ik5pvx - Same licence as apache itself.
#
# Updates:
#

use warnings;
use strict;
use diagnostics;

# list here all the possible log files you want to check for.
# this is used in a regexp
my $loglist="Error|Access|Rewrite|Script|Custom";

# change this to 1 if you want to output the list of filenames with errors
my $printerrorfile = 0;

# path to listconffiles
my $listconffiles = "/usr/share/apache/listconffiles";
#my $listconffiles = "./listconffiles";

my $errorcondition = 0;

chomp (my $conffiles= `$listconffiles $ARGV[0]` );
my @conffiles=split(/\x07/,$conffiles);

foreach my $conf (@conffiles) {
  open (CONF,$conf) or warn "Can't read conf file $conf.\n$!\n";

  while (<CONF>) {
    next if /^\s*$/;
    next if /^\s*\#/;

    next unless /($loglist)Log/i;

    my (undef,$file) = split (/\s/,$_,2);

# take away surrounding ' and "
    $file =~ s/[\"\']//g;
 
    if ($file !~ m|^/var/log/| ) {
#      $errorcondition++;     # uncomment this if you prefer count of errors
      $errorcondition = 1;
      print "Wrong log file definition in $conf: $_" if $printerrorfile;
    }

  }

  close (CONF);

}

exit $errorcondition;