]> git.wincent.com - bansshee.git/blob - contrib/RHEL-5.3/etc/logwatch/scripts/services/bansshee
Add contrib files for RHEL 5.3
[bansshee.git] / contrib / RHEL-5.3 / etc / logwatch / scripts / services / bansshee
1 #!/usr/bin/perl
2
3 use Socket;
4
5 #
6 # Storage
7 #
8
9 my %addresses;
10
11 #
12 # Functions
13 #
14
15 sub LookupIP($)
16 {
17   my $ip = shift;
18   $name = $addresses{$ip};
19   return "$name [$ip]" if defined $name;
20   ($a1, $a2, $a3, $a4) = split /\./, $ip;
21   $name = gethostbyaddr(inet_aton($ip), AF_INET);
22   if ($name)
23   {
24     $addresses{$ip} = $name;
25     return "$name [$ip]";
26   }
27   else
28   {
29     return $ip;
30   }
31 }
32
33 sub SortIPAddresses
34 {
35   ($a1, $a2, $a3, $a4) = split /\./, $a;
36   ($b1, $b2, $b3, $b4) = split /\./, $b;
37   ($a1 <=> $b1) || ($a2 <=> $b2) || ($a3 <=> $b3) || ($a4 <=> $b4);
38 }
39
40 #
41 # Main
42 #
43
44 $detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};
45
46 while (defined($line = <STDIN>))
47 {
48   chomp($line);
49
50   if ($line =~ /Performing periodic check of blocked IPs list\./)
51   {
52     $periodicChecks++;
53   }
54   elsif ($line =~ /Bansshee startup\./)
55   {
56     $startups++;
57   }
58   elsif ($line =~ /Failed password attempt for user/)
59   {
60     $failedPasswords++;
61   }
62   elsif ($line =~ /Attempted connection with illegal user/)
63   {
64     $illegalUsers++;
65   }
66   elsif ($line =~ /Adding IP (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) to blocklist\./)
67   {
68     $additions{$1} += 1;
69   }
70   elsif ($line =~ /Removing IP (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) from blocklist\./)
71   {
72     $removals{$1} += 1;
73   }
74   elsif (($line =~ /Reading config file/) ||
75          ($line =~ /Daemonizing\./) ||
76          ($line =~ /Creating new BANSSHEE iptables chain\./) ||
77          ($line =~ /Appending JUMP rule \(redirects all SSH traffic to BANSSHEE chain\)\./) ||
78          ($line =~ /Tailing log:/) ||
79          ($line =~ /Removing JUMP rule from INPUT chain\./) ||
80          ($line =~ /Flushing BANSSHEE iptables chain\./) ||
81          ($line =~ /Deleting BANSSHEE iptables chain\./))
82   {
83     # ignore
84   }
85   else
86   {
87     push @unmatchedEntries, "$line\n";
88   }
89 }
90
91 if (($startups > 0) && ($detail >= 5))
92 {
93   print "\nStart-ups: $startups time(s).\n";
94 }
95
96 if (($periodicChecks > 0) && ($detail >= 10))
97 {
98   print "\nPeriodic checks: $periodicChecks time(s).\n";
99 }
100
101 if ($failedPasswords > 0)
102 {
103   print "\nFailed password attempts: $failedPasswords time(s).\n";
104 }
105
106 if ($illegalUsers > 0)
107 {
108   print "\nIllegal user attempts: $illegalUsers time(s).\n";
109 }
110
111 if (keys %additions)
112 {
113   print "\nIPs added to blocklist:\n";
114   foreach $ip (sort { SortIPAddresses } keys %additions)
115   {
116     $host = LookupIP($ip);
117     print "    $host : $additions{$ip} time(s).\n";
118   }
119 }
120
121 if (keys %removalss)
122 {
123   print "\nIPs removed from blocklist:\n";
124   foreach $ip (sort { SortIPAddresses } keys %additions)
125   {
126     $host = LookupIP($ip);
127     print "    $host : $additions{$ip} time(s).\n";
128   }
129 }
130
131 if ($#unmatchedEntries > 0)
132 {
133   print "\n**Unmatched Entries**\n";
134   print @unmatchedEntries;
135 }
136
137 exit(0);