diff --git a/allowlists/.gitignore b/allowlists/.gitignore new file mode 100644 index 0000000..57d81ac --- /dev/null +++ b/allowlists/.gitignore @@ -0,0 +1,6 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore +# ... And some others +!/allowlist.domains.example diff --git a/allowlists/allowlist.domains.example b/allowlists/allowlist.domains.example new file mode 100644 index 0000000..923103e --- /dev/null +++ b/allowlists/allowlist.domains.example @@ -0,0 +1,8 @@ +# Omit these domains from the blocklist. +# +# Must be in a file called *.domains in this directory. +# Comments are allowed. One domain per line. +# +# Examples: +# domain1.example.com +# domain2.example.com diff --git a/make-block.pl b/make-block.pl index ac9be32..1ac0d8a 100755 --- a/make-block.pl +++ b/make-block.pl @@ -23,6 +23,7 @@ use FindBin qw//; my %domains; my $dupes = 0; my $skip = 0; +my $removed_allowed = 0; sub add_domain_list { my $file = shift; foreach my $line (&read_stripped($file)) { @@ -82,6 +83,7 @@ MAIN: { my @domain_lists = glob "$workdir/lists/*.domains"; my @hosts_lists = glob "$workdir/lists/*.hosts"; + my @allow_lists = glob "$workdir/allowlists/*.domains"; foreach my $listfile (@domain_lists) { &add_domain_list($listfile); @@ -90,6 +92,16 @@ MAIN: { &add_host_file($hostfile); } + # Apply allowlists + my @allow_domains; + foreach my $allowlist (@allow_lists) { + push @allow_domains, &read_stripped($allowlist); + } + my $before = %domains; + delete %domains{@allow_domains}; + # Count number removed + $removed_allowed = $before - %domains; + my $written = 0; my $fho = \*STDOUT; if (defined $out && length $out) { @@ -109,5 +121,6 @@ MAIN: { printf STDERR " - %d .domains files\n", (scalar @domain_lists); printf STDERR " - %d .hosts files\n", (scalar @hosts_lists); printf STDERR "(%d duplicates)\n", $dupes if $dupes; + printf STDERR "(%d domains removed via allowlist)\n", $removed_allowed if $removed_allowed; printf STDERR "(%d skipped)\n", $skip if $skip; }