Custom Config

Webmaster webmaster at NWDHOSTING.COM
Tue Apr 27 22:06:10 IST 2004


That enables scanning for everyone.  We host multiple domains, and I
wanted the admins of those domains to be able to disable scannng for their
domain only, the information being pulled from a database.  I was able to
resolve the problem though, the logging routine was killing it.  All is
working as expected now...  If anyone wants to know:

Virus Scanning = &SACustomCheck
Spam Checks = &SACustomCheck



Here are the functions for CustomConfig.pm

sub InitSACustomCheck {
 return if defined $dbh;

 MailScanner::Log::InfoLog("Initializing database connection");

 $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$db_host",
                     $db_user, $db_pass,
                     {PrintError => 0});

 if (!$dbh) {
  MailScanner::Log::WarnLog("Unable to initialize database connection:
%s", $DBI::errstr);
  return;
 }

 MailScanner::Log::InfoLog("Finished initializing database connection");
}

sub EndSACustomCheck {
 $dbh->disconnect if defined $dbh;
 MailScanner::Log::InfoLog("Disconnected from the database");
}

sub SACustomCheck {
  my($message) = @_;

  return unless $message;

  if(!$dbh->ping) {
   undef $dbh;
   MailScanner::Log::InfoLog("Database ping failure attempting to
re-connect");
   InitSACustomCheck();
  }

  return unless defined $dbh;

  foreach (@{$message->{to}}) {
          ($to, $domain)=split("\@", $_);
          push(@domains, "domain='$domain'");
  }

  $where=join(" OR ", @domains);

  my $sth = $dbh->prepare("SELECT value FROM custom_score WHERE
opt='checks' AND ($where)");
  $sth->execute();

  # was there any options returned, if not, defauly yes
  if ($sth->rows == 0){
          $checks=1;
  }else{
        # if any domain is set to yes, it gets scanned
        while (my $ref = $sth->fetchrow_hashref()) {
                if ($ref->{'value'} eq "yes") {
                        $checks=1;
                }
        }
  }
  # otherwise, no
  if ($checks != 1) {
        $checks=0;
  }

  return $checks;

}



Brian  :)



> Webmaster wrote:
>> I am trying to do a custom function so each domain we host can have
>> their
>> own options.  I was able to get the "Required SpamAssassin Score" option
>> to work properly, I get the domain from the to address, get that domains
>> score from a database, and return it.  I tried to do the same thing with
>> "Spam Checks", but it does not work, Ms seems to go into a loop.  I
>> tried
>> the return value as 1 or 0 as the CostomCinfig.pm file said, even tried
>> returning "yes" or "no", but no luck.  Any ideas?  Some of our customers
>> have asked that we do not scan their mail at all (go figure, paranoid
>> people)
>
> Wouldn't this do that?
>
> # If you want to be able to switch scanning on/off for different users or
> # different domains, set this to the filename of a ruleset.
> # This can also be the filename of a ruleset.
> Virus Scanning = yes
>
> --
> /Peter Bonivart
>
> --Unix lovers do it in the Sun
>
> Sun Fire V210, Solaris 9, Sendmail 8.12.10, MailScanner 4.29.7,
> SpamAssassin 2.63 + DCC 1.2.39, ClamAV 0.70 + GMP 4.1.2, Vispan 1.3
>
> -------------------------- MailScanner list ----------------------
> To leave, send    leave mailscanner    to jiscmail at jiscmail.ac.uk
> For further info about MailScanner, please see the Most Asked
> Questions at    http://www.mailscanner.biz/maq/     and the archives
> at    http://www.jiscmail.ac.uk/lists/mailscanner.html
>

-------------------------- MailScanner list ----------------------
To leave, send    leave mailscanner    to jiscmail at jiscmail.ac.uk
For further info about MailScanner, please see the Most Asked
Questions at    http://www.mailscanner.biz/maq/     and the archives
at    http://www.jiscmail.ac.uk/lists/mailscanner.html



More information about the MailScanner mailing list