On 6/7/2017 9:31 AM, Hardy wrote:
>
>
> On 07.06.2017 03:55, Jerry Stuckle wrote:
>
>> What I want is to call the script during ACL processing, and if the
>> domain has been registered less than 7 days (0 <= return value < 7), the
>> email is rejected.
>
> How do you do that? Do you query 'whois'?
> Would you share your script?
>
> Hardy
>
I'll reply to Hardy to keep from filling the list, but thanks to all who
responded.
When I said it returns the number of days, I mean the subroutine (sorry
- I said script above) returns the number of days. It doesn't write to
stdout and does not exit with a value.
This isn't my script, but one I got from another user on the spamcop
forum. Modified slightly for my system (please forgive any poor coding
- I'm a C/C++ programmer, not Perl, and will accept any and all
suggestions!) it is attached (yes, it does call whois).
In my acl_check_rcpt section I have:
# Testing check domain for number of days it has been active
deny
set acl_m1 = ${perl{domain_age}{$sender_address_domain}}
message = Rejected because $sender_address_domain is a new domain
condition = ${if and{{>={$acl_m1}{0}}{<={$acl_m1}{7}}}}
It seems to work on our test system; I just put it on the live system
and will monitor. It shouldn't take long for it to reject some spam -
just my id is getting over 100 per day.
Again - thanks for the help; your input was invaluable in getting this
to work. The exim documentation seems to be excellent for reference,
but when you don't know where to start it is a bit overwhelming.
Jerry
# Parameter: the domain to check
# Return value: domain age in days (or -1 on error)
sub domain_age
{
my $whoiscmd = '/usr/bin/whois';
my $domain = shift;
my @months = ("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" );
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
my $c = `$whoiscmd '$domain' |grep -i 'creat' | head -n1 | cut -d':' -f 2-`;
$c =~ s/^\s+//; # trim initial spaces
if ($c ne "")
{
my $mm = -1;
my ($dd, $mmm, $yyyy) = split('-', $c);
if ($mmm ne "" && $dd ne "" && $yyyy ne "")
{
my $i;
for ($i = 0; $i <= $#months; ++$i)
{
if ($months[$i] eq $mmm)
{
$mm = $i;
last;
}
}
}
if ($mm != -1)
{
my $curdays = $year*365+$mon*30+$mday;
my $domain_days = ($yyyy-1900)*365+$mm*30+($dd-0);
my $age = $curdays-$domain_days;
if ($age < 0)
{
$age = 0;
}
return $age;
}
}
return -1;
}