"Fossies" - the Fresh Open Source Software Archive

Member "spammilt-0.5.0-rc7/mrtg/spammilt.pl" (4 Dec 2003, 4539 Bytes) of package /linux/privat/old/spammilt-0.5.0-rc7.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "spammilt.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/perl
    2 #
    3 #-------------------------------------------------------------------------------
    4 #
    5 # $Id: spammilt.pl,v 1.1 2003/12/04 22:59:25 sanne Exp $ 
    6 #
    7 # $Log: spammilt.pl,v $
    8 # Revision 1.1  2003/12/04 22:59:25  sanne
    9 # Added: MRTG config files and perl script. Perl script must be copied to /etc/mrtg. Both mrtg config files to mrtg config dir
   10 #
   11 # 
   12 #
   13 
   14 use strict;
   15 use Socket;
   16 use FileHandle;
   17 
   18 
   19 sub write_file {
   20     my $ALL = shift;
   21     my $time = time;
   22     
   23     open SPAMTEMPFILE, ">/tmp/spammilt.tmp";
   24     print SPAMTEMPFILE "$time ";
   25     print SPAMTEMPFILE $ALL;
   26 
   27 }
   28 
   29 sub read_file {
   30     my $line;    
   31 
   32     open SPAMTEMPFILE, "</tmp/spammilt.tmp";
   33     read SPAMTEMPFILE, $line, 80;
   34     chomp($line);
   35 
   36     my ($time, $connects, $processed, $rejects, $discards, $redirects, $whitelisted, $blacklisted, $unknown, $dnsbl, $dnsbl_ignore, $bayesian, $accept) = split / /,$line;
   37     return ($time, $connects, $processed, $rejects, $discards, $redirects, $whitelisted, $blacklisted, $unknown, $dnsbl, $dnsbl_ignore, $bayesian, $accept);
   38 }
   39 
   40 my $host = "localhost";
   41 my $port = 5555;
   42 
   43 my $proto = getprotobyname('tcp');
   44 
   45 my $iaddr = inet_aton($host);
   46 my $paddr = sockaddr_in($port, $iaddr);
   47 
   48 socket(SOCKET, PF_INET, SOCK_STREAM, $proto) or die "Socket: $!\n";
   49 connect(SOCKET, $paddr) or die "Connect: $!\n";
   50 
   51 my $line = <SOCKET>;
   52 
   53 close(SOCKET) or die "close: $!\n";
   54 
   55 
   56 chomp($line);
   57 
   58 my ($c_connects, $c_processed, $c_rejects, $c_discards, $c_redirects, $c_whitelisted, $c_blacklisted, $c_unknown, $c_dnsbl, $c_dnsbl_ignore, $c_bayesian, $c_accept) = split / /,$line;
   59 my ($connects, $processed, $rejects, $discards, $redirects, $whitelisted, $blacklisted, $unknown, $dnsbl, $dnsbl_ignore, $bayesian, $accept) = split / /,$line;
   60 my $time = localtime;
   61 my $uptime = `uptime`;
   62   if ($uptime =~ /days/)   { ($uptime) = ($uptime =~ m/^.*up\ (.*\:[0-9]{2}),/);   }
   63   elsif ($uptime =~ /min/) { ($uptime) = ($uptime =~ m/^.*up\ (.*[0-9]+\ min),/);  }
   64   else { ($uptime) = ($uptime =~ m/^.*up\ \ (.*\:[0-9]{2}),/); }
   65 
   66 #print "------------------------------\n";
   67 #print "$time\n";
   68 #print "------------------------------\n";
   69 #print "Connects         $connects\n";
   70 #print "Processed        $processed\n";
   71 #print "Rejects          $rejects\n";
   72 #print "Discards         $discards\n";
   73 #print "Redirects        $redirects\n";
   74 #print "Whitelisted      $whitelisted\n";
   75 #print "Blacklisted      $blacklisted\n";
   76 #print "Unknown hosts    $unknown\n";
   77 #print "DNSBL            $dnsbl\n";
   78 #print "DNSBL ignored    $dnsbl_ignore\n";
   79 #print "Bayesian         $bayesian\n";
   80 #print "Accept           $accept\n";
   81 #print "------------------------------\n";
   82 
   83 
   84 if ($ARGV[1] eq "diff" ) {
   85     my ($r_time, $r_connects, $r_processed, $r_rejects, $r_discards, $r_redirects, $r_whitelisted, $r_blacklisted, $r_unknown, $r_dnsbl, $r_dnsbl_ignore, $r_bayesian, $r_accept) = read_file;
   86 
   87     $time = time - $r_time;
   88     $connects = $c_connects - $r_connects;
   89     $processed = $c_processed - $r_processed;
   90     $rejects = $c_rejects - $r_rejects;
   91     $discards = $c_discards - $r_discards;
   92     $redirects = $c_redirects - $r_redirects;
   93     $whitelisted = $c_whitelisted - $r_whitelisted;
   94     $blacklisted = $c_blacklisted - $r_blacklisted;
   95     $unknown = $c_unknown - $r_unknown;
   96     $dnsbl = $c_dnsbl - $r_dnsbl;
   97     $dnsbl_ignore = $c_dnsbl_ignore - $r_dnsbl_ignore;
   98     $bayesian = $c_bayesian - $r_bayesian;
   99     $accept = $c_accept - $r_accept;
  100 }
  101 if ($ARGV[0] eq "version" ) {
  102     print "Version: 0.0\n"; 
  103     exit;
  104 } elsif ($ARGV[0] eq "update" ) {
  105     write_file($line);
  106     exit;
  107 } elsif ($ARGV[0] eq "connects" ) {
  108   print "$connects\n";
  109   print "$processed\n";
  110 } elsif ($ARGV[0] eq "rejected" ) {
  111   print "$processed\n";
  112   print "$rejects\n";
  113 }elsif ($ARGV[0] eq "discarded" ) {
  114   print "$processed\n";
  115   print "$discards\n";
  116 }elsif ($ARGV[0] eq "redirected" ) {
  117   print "$processed\n";
  118   print "$redirects\n";
  119 }elsif ($ARGV[0] eq "whitelisted" ) {
  120   print "$processed\n";
  121   print "$whitelisted\n";
  122 }elsif ($ARGV[0] eq "blacklisted" ) {
  123   print "$processed\n";
  124   print "$blacklisted\n";
  125 }elsif ($ARGV[0] eq "unknownhosts" ) {
  126   print "$processed\n";
  127   print "$unknown\n";
  128 }elsif ($ARGV[0] eq "dnsbl" ) {
  129   print "$processed\n";
  130   print "$dnsbl\n";
  131 }elsif ($ARGV[0] eq "dnsblignored" ) {
  132   print "$processed\n";
  133   print "$dnsbl_ignore\n";
  134 }elsif ($ARGV[0] eq "bayesian" ) {
  135   print "$processed\n";
  136   print "$bayesian\n";
  137 }elsif ($ARGV[0] eq "accepted" ) {
  138   print "$processed\n";
  139   print "$accept\n";
  140 }
  141 
  142   print "$uptime\n";
  143   print "XXX\n";
  144 
  145   # Exit quietly.
  146   exit 0