Mail-SpamCannibal
view release on metacpan or search on metacpan
lib/Mail/SpamCannibal/ScriptSupport.pm view on Meta::CPAN
unless ($gracep > 2) {
$signal = 9; # on last try, kill forceably
}
sleep 1;
}
}
=item * dbjob_recover(\%default_config);
This function destroys and reinstantiates the database environment. The file
B<blockedBYwatcher> is removed from the environment directory if it is
present.
All DB tasks should be terminated prior to calling this function.
DO NOT call this job for a DB environment that has not been initialized.
usage: if(dbjob_chk(\%default_config) {
dbjob_kill(\%default_config,$graceperiod);
dbjob_recover(\%default_config);
... restart db jobs
}
input: pointer to db configuration,
returns: nothing
=cut
sub dbjob_recover {
my($default) = @_;
# all jobs should be dead
# get the UID and GID for environment files
die "directory $default->{dbhome} does not exist\n"
unless -e $default->{dbhome} && -d $default->{dbhome};
my $test = $default->{dbhome};
if (exists $default->{dbfile} &&
$default->{dbfile}->[0] &&
-e $test .'/'. $default->{dbfile}->[0]) {
$test .= '/'. $default->{dbfile}->[0];
}
elsif (exists $default->{txtfile} &&
$default->{txtfile}->[0] &&
-e $test .'/'. $default->{txtfile}->[0]) {
$test .= '/'. $default->{txtfile}->[0];
}
my($mode,$uid,$gid) = (stat($test))[2,4,5];
$mode &= 0777;
my %local_default = %$default;
$local_default{recover} = 1;
# recover the environment
my $tool = new IPTables::IPv4::DBTarpit::Tools(%local_default);
$tool->closedb;
# restore permissions
opendir(ENVF,$default->{dbhome}) || die "could not open DB $default->{dbhome} directory\n";
my @env = grep(/^__/,readdir(ENVF));
closedir ENVF;
foreach(@env) {
chmod $mode, $default->{dbhome} .'/'. $_;
chown $uid, $gid, $default->{dbhome} .'/'. $_;
}
# it's now ok to restart jobs
unlink $default->{dbhome} .'/blockedBYwatcher'; # remove the job block
}
=item * ($respip,$err,$blrsp,$exp,$zon)=unpack_contrib($record);
Unpack a 'blcontrib' record.
input: record from 'blcontrib' database
output: netaddr - our response code,
our error message,
netaddr - remote response code,
expire
dnsbl zone
This undoes pack("a4 x A* x a4 x N x A*",@_);
=cut
# pack("a4 x A* x a4 x N x A*",$dnresp,$error,$netA,$expire,$zon);
sub unpack_contrib {
my ($ip,$rest) = unpack("a4 x a*",shift);
my ($err,$rst2) = split(/\0/,$rest,2);
# using A* here instead of a*, strips everything after 'zon'
my ($rsp,$exp,$zon) = unpack("a4 x N x A*",$rst2);
return ($ip,$err,$rsp,$exp,$zon);
}
=item * ($which,$text)=lookupIP(\%config,$dotquadIP,$sockpath,$is_network);
This function checks the SpamCannibal databases for the
presence of an IP address and returns a text string describing why the IP address is in the
SpamCannibal data base or a descriptive not found message.
input: (localhost)
\%database config,
dotquad IP address,
/path/to/fifo,
0,
(or remote host)
\%database config,
dotquad IP address,
hostname:port,
timeout seconds
returns: which database,
text string
which = 0 for evidence
1 for blcontrib
NOTE: the database config hash is the same as returned by Mail::SpamCannibal::SiteConfig
Text error return messages: message, meaning
invalid IP address, says it all
not found in system database, not in tarpit db
( run in 2.120 seconds using v1.01-cache-2.11-cpan-71847e10f99 )