Page 1 of 1

Crude reputation idea

Posted: Thu Aug 28, 2008 4:23 pm
by exi1ed0ne
I had a thought that a very basic reputation system could be set up using qmail-scanner and qgreylist. Here is the thought:

1) Have qmail-scanner increment the number in a file for the number of times a class C hits the delete threshold.

2) Add an additional check to qgreylist for that file, and if it reached a configurable threshold, 5.7.1 the email

3) Add a cleanup function that runs every hour and removes files that haven't been written to in 24 hours.

I'm making a stab at #1, but running into issues. I've added the following at around line 3770 (the delete section), but it isn't kicking out the files at all. Sigh. Anyone see any reason why this wouldn't generate a file and then increment a number inside of it?

Code: Select all

          #Add in spamhits to greylisting files
          my ( $a, $b, $c, $d ) = $ENV{'TCPREMOTEIP'};

          my $bl_file = "/var/qmail/blacklist/$a.$b.$c";
          open (FILE, "+>>" . $bl_file);
          flock(FILE, 2);

          seek FILE, 0, 0;
          my @file_contents = <FILE>;
          truncate FILE, 0;

          my $counterVar;

          if ($file_contents[0] =~ /^(\d+)$/)
          {
             $counterVar = $1;
          }
          else
          {
             $counterVar = 'COUNTER ERROR';  # the regular expression didn't match
          }

          $counterVar++; 

          print FILE $counterVar;
          close (FILE);

Posted: Thu Aug 28, 2008 4:28 pm
by scott
so it never writes to the filehandle you're opening in FILE at all? Or is it just not writing your variable to it?

Posted: Thu Aug 28, 2008 4:54 pm
by exi1ed0ne
Not creating the file. Dir perms are 777 at the moment. The only thing I can think of is that $ENV{'TCPREMOTEIP'} isn't doing what I think it is doing, and I should be looking elsewhere for the IP of the sender.

Posted: Thu Aug 28, 2008 11:57 pm
by scott
is it even changing the timestamp on the file? Just to double check I'd throw a little debug output into FILE. Im not sure your array is actually getting populated like that. Normally I throw the output out of a file read into a while loop, and assign it to a variable with $foo = $_; and then do my string compare off that.

Posted: Fri Aug 29, 2008 9:56 am
by exi1ed0ne
The dir is empty, and it should be creating a file named the first three octets of the sending IP. Inside the file should only be the number of times that IP has hit the delete threshold. Kinda like how qgreylist has the files, just with a counter inside. :)

I'll change it to a static filename and see if I get anything in there if I get some time today. That will isolate that part of the code, since I really think that is what is causing the issues.

Posted: Fri Aug 29, 2008 2:17 pm
by scott
Yeah I'd throw some debug bits in there before and after it to trap it. If its not creating the file in the first place either its not getting the right path, or a permissions problem