home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20110725.etc.tar.gz / bradford.20110725.etc.tar / etc / sysconfig / scripts / SuSEfirewall2-showlog < prev   
Text File  |  2006-04-22  |  2KB  |  109 lines

  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use Sys::Hostname;
  5. use Net::DNS;
  6.  
  7. my $res;
  8. if($#ARGV >= 0 && $ARGV[0] eq '-N')
  9. {
  10.     $res = Net::DNS::Resolver->new;
  11.     $res->tcp_timeout(10);
  12.     $res->udp_timeout(10);
  13.     $res->persistent_tcp(1);
  14.     $res->persistent_udp(1);
  15.     shift @ARGV;
  16. }
  17.  
  18. if($#ARGV < 0)
  19. {
  20.     $ARGV[0] = '/var/log/firewall';
  21. }
  22. elsif($ARGV[0] eq '--help' || $ARGV[0] eq '-h')
  23. {
  24.     print "Usage: $0 FILES\n";
  25.     print "    /var/log/firewall will be used if no file is specified\n";
  26.     print "    specify - as file to read from STDIN\n";
  27.     exit 0;
  28. }
  29. elsif($ARGV[0] eq '-')
  30. {
  31.     shift @ARGV;
  32. }
  33.  
  34. my %dnscache;
  35. sub dnsresolve($)
  36. {
  37.     my $ip = shift;
  38.     return $dnscache{$ip} if(exists $dnscache{$ip});
  39.  
  40.     my $query = $res->search($ip);
  41.  
  42.     if ($query)
  43.     {
  44.     my $a;
  45.     foreach my $rr (grep { $_->type eq 'PTR' } $query->answer)
  46.     {
  47.         $a = $rr->ptrdname;
  48.     }
  49.     if($a)
  50.     {
  51.         $dnscache{$ip} = $a;
  52.         return $a;
  53.     }
  54.     }
  55.     return $ip;
  56. }
  57.  
  58. my $hostname = hostname;
  59.  
  60. my ($sflog,$src,$dst,$spt,$dpt,$interface,$proto);
  61.  
  62. format STDOUT =
  63. @<<<<<<<<<<<<<<< @<<<<<< @>>>>>>>>>>>>>>>>>>>>>>>>>>>@<<<<< @|||||| @>>>>>>>>>>>>>>>>>>>>>>>>>>>@<<<<<
  64. $sflog,         $proto, $src,                        $spt,  $interface, $dst,$dpt
  65. .
  66.  
  67. while(<>)
  68. {
  69.     next unless /^.*$hostname kernel: SFW2/;
  70.     chomp;
  71.     s/^.*$hostname kernel: //;
  72.     s/OPT \((.*)\)/OPT=$1/;
  73.     my @arr = split(/ /);
  74.     $sflog = shift @arr;
  75.     $sflog =~ s/^SFW2-//;
  76.  
  77.     my %tags = map { my @a = split(/=/,$_,2); $a[0] => $a[1]; } @arr;
  78.  
  79.     $src = $tags{SRC};
  80.     $dst = $tags{DST};
  81.  
  82.     $src = dnsresolve($src) if($res && $src);
  83.     $dst = dnsresolve($dst) if($res && $dst);
  84.     
  85.     $src = '['.$src.']' if($src =~ /:/);
  86.     $dst = '['.$dst.']' if($dst =~ /:/);
  87.     $spt = ':'.$tags{SPT} if($tags{SPT});
  88.     $dpt = ':'.$tags{DPT} if($tags{DPT});
  89.     $proto = lc $tags{PROTO};
  90.  
  91.     if($tags{IN})
  92.     {
  93.     $interface = '> '.$tags{IN};
  94.     }
  95.     else
  96.     {
  97.     $interface = $tags{OUT}.' >';
  98.     }
  99.  
  100.     $spt = ' '.$tags{TYPE} if ($proto =~ /ICMP.*/);
  101.  
  102.     $src =~ s/(.*):.*:.*:.*:(.*:.*:.*:.*)/$1...$2/;
  103.     $dst =~ s/(.*):.*:.*:.*:(.*:.*:.*:.*)/$1...$2/;
  104.  
  105.     write;
  106. }
  107.  
  108. # vim: sw=4
  109.