mirror of
https://codeberg.org/h3xx/you-dont-need-pihole.git
synced 2024-08-14 20:27:01 +00:00
Add support for allowlists
This commit is contained in:
parent
fd8061714f
commit
1a97ec8365
3 changed files with 27 additions and 0 deletions
6
allowlists/.gitignore
vendored
Normal file
6
allowlists/.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
# ... And some others
|
||||
!/allowlist.domains.example
|
8
allowlists/allowlist.domains.example
Normal file
8
allowlists/allowlist.domains.example
Normal file
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue