App-DNS-Adblock
view release on metacpan or search on metacpan
scripts/adblock.pl view on Meta::CPAN
#!/usr/bin/env perl
use lib "../lib";
use strict;
use warnings;
use App::DNS::Adblock;
use Try::Tiny;
my $timeout = 1; # 1 day timeout
$timeout *= 86400;
my $adfilter = App::DNS::Adblock->new(
adblock_stack => [
{ url => 'http://pgl.yoyo.org/adservers/serverlist.php?hostformat=adblockplus&showintro=0&startdate[day]=&startdate[month]=&startdate[year]=&mimetype=plaintext',
path => '/var/named/pgl-adblock.txt',
refresh => 7,
},
{ url => "abp:subscribe?location=https%3A%2F%2Feasylist-downloads.adblockplus.org%2Feasyprivacy.txt&title=EasyPrivacy&requiresLocation=https%3A%2F%2Feasylist-downloads.adblockplus.org%2Feasylist.txt&requiresTitle=EasyList",
path => '/var/named/easyprivacy.txt',
refresh => 5,
},
],
forwarders => [ "8.8.8.8", "8.8.4.4" ],
# blacklist => '/var/named/blacklist',
# whitelist => '/var/named/whitelist',
# debug => 1,
setdns => 1,
);
while (1) {
try {
local $SIG{ALRM} = sub { $adfilter->restore_local_dns if $adfilter->{setdns};
die "alarm\n"
};
alarm $timeout;
main();
alarm 0;
}
catch {
die $_ unless $_ eq "alarm\n";
kill HUP => $$;
print "restarted\n";
};
}
sub main {
$adfilter->run();
}
=head1 NAME
adblock.pl - command line stub
=head1 SYNOPSIS
sudo perl adblock.pl
=head1 DESCRIPTION
This script implements a DNS-based ad blocker. Execution is wrapped in a timeout function for the purpose of refreshing the adbblock stack.
=head1 CAVEATS
Tested on darwin only.
=head1 AUTHOR
( run in 1.307 second using v1.01-cache-2.11-cpan-39bf76dae61 )