Compare commits

..

No commits in common. "main" and "v0.1.0" have entirely different histories.
main ... v0.1.0

13 changed files with 99 additions and 175 deletions

11
.gitmodules vendored
View file

@ -1,10 +1,15 @@
[submodule "StevenBlack-hosts"]
[submodule "repos/StevenBlack-hosts"]
path = repos/StevenBlack-hosts
url = https://github.com/StevenBlack/hosts.git
branch = master
shallow = true
[submodule "AdroitAdorKhan-EnergizedProtection"]
path = repos-noupdates/AdroitAdorKhan-EnergizedProtection
[submodule "repos/EnergizedProtection-block"]
path = repos/EnergizedProtection-block
url = https://github.com/EnergizedProtection/block.git
branch = master
shallow = true
[submodule "repos/AdroitAdorKhan-EnergizedProtection"]
path = repos/AdroitAdorKhan-EnergizedProtection
url = https://github.com/AdroitAdorKhan/EnergizedProtection.git
branch = master
shallow = true

View file

@ -1,30 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.2.0] - 2023-06-19
### Added
- dnsmasq: Add 'bogus-priv', 'domain-needed' options
- dnsmasq: Add IPv6 upstream DNS servers
- Add support for allowlists
### Changed
- Use `::` instead of `::1` as the blocked IPv6 address
- Strip `#` comments, whitespace from \*.domains
### Fixed
- Prevent AdroitAdorKhan-EnergizedProtection updates (current repo has a broken
list)
- Fix `block.list` permissions on first generation.
### Removed
- Removed in-repo custom ad domains list
## [0.1.0] - 2022-11-12
Initial published version

View file

@ -1,6 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
# ... And some others
!/allowlist.domains.example

View file

@ -1,8 +0,0 @@
# 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

View file

@ -11,27 +11,21 @@
# You may NOT use this software for commercial purposes.
###############################################################################
# Do not load /etc/hosts as a dataset for replies. (By default dnsmasq performs
# an implicit "addn-hosts=/etc/hosts"; this prevents it.)
no-hosts
# Add our block lists
addn-hosts=/etc/you-dont-need-pihole/local.list
addn-hosts=/etc/you-dont-need-pihole/custom.list
addn-hosts=/etc/you-dont-need-pihole/block.list
# Never forward addresses in the non-routed address spaces.
bogus-priv
# Return answers to DNS queries from /etc/hosts.
#localise-queries
# In-memory cache size.
cache-size=10000
# Never forward plain names (without a dot or domain part)
domain-needed
# Do not load /etc/hosts as a dataset for replies. (By default dnsmasq performs
# an implicit "addn-hosts=/etc/hosts"; this prevents it.)
no-hosts
# Return answers to DNS queries from /etc/hosts.
#localise-queries
# Don't log queries - only startup/shutdown messages. (Un-comment this option
# for debugging.)
#log-queries
@ -50,7 +44,5 @@ no-resolv
# For non-blocked DNS queries, telephone the request thru Google's global DNS
# server.
server=2001:4860:4860::8888
server=2001:4860:4860::8844
server=8.8.8.8
server=8.8.4.4

2
lists/.gitignore vendored
View file

@ -3,5 +3,5 @@
# Except this file
!.gitignore
# ... And some others
!/*.example
!/AdroitAdorKhan-core.hosts
!/custom-ad-domains.domains

View file

@ -1 +1 @@
../repos-noupdates/AdroitAdorKhan-EnergizedProtection/core/hosts
../repos/AdroitAdorKhan-EnergizedProtection/core/hosts

View file

@ -0,0 +1,12 @@
1.nbryb.com
100.nbryb.com
50.nbryb.com
anawkward.com
cpa-optimizer.best
mob-track.com
notorietycheerypositively.com
play.nbryb.com
roastclap.com
syndication.realsrv.com
tripsbooth.com
www.myemailtracking.com

View file

@ -1,8 +0,0 @@
# Add these custom domains for 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

View file

@ -1,4 +1,5 @@
#!/usr/bin/perl
# vi: et sts=4 sw=4 ts=4
###############################################################################
# You Don't Need Pi-hole
@ -13,30 +14,41 @@
# You may NOT use this software for commercial purposes.
###############################################################################
use 5.012;
use strict;
use warnings;
use Getopt::Long qw/ GetOptions :config bundling no_getopt_compat no_ignore_case /;
use Getopt::Long qw/ GetOptions :config no_ignore_case /;
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)) {
open my $fni, '<', $file
or die "Failed to open file $file for reading: $!";
foreach my $line (<$fni>) {
chomp $line;
$line =~ s/^\s+|\s+$//;
my $domain = lc $line;
if (defined $domains{$domain}) {
++$dupes;
}
++$dupes if defined $domains{$domain};
$domains{$domain} = 1;
}
}
sub add_host_file {
my $file = shift;
foreach my $line (read_stripped($file)) {
open my $fni, '<', $file
or die "Failed to open file $file for reading: $!";
foreach my $line (<$fni>) {
chomp $line;
# strip whitespace and comments
$line =~ s/^\s+|\s+$|\s*#.*$//;
next unless $line;
my @parts = split /\s+/, $line;
die "Malformed line in $file: $line; @parts"
unless @parts > 1;
@ -49,60 +61,35 @@ sub add_host_file {
next;
}
my $domain = lc $parts[1];
if (defined $domains{$domain}) {
++$dupes;
}
++$dupes if defined $domains{$domain};
$domains{$domain} = 1;
}
}
sub read_stripped {
my $file = shift;
open my $fni, '<', $file
or die "Failed to open file $file for reading: $!";
map {
chomp;
# Strip whitespace and comments
s/^\s+|\s+$|\s*#.*$//;
$_ || ()
} <$fni>;
}
MAIN: {
my $out;
my $block_ip = '0.0.0.0 ::';
my $block_ip = '0.0.0.0 ::1';
my $workdir = $FindBin::RealBin;
unless (GetOptions(
'out|O=s' => \$out,
'block-ip|i=s' => \$block_ip,
unless (&GetOptions(
'out=s' => \$out,
'O=s' => \$out,
'i=s' => \$block_ip,
'block-ip=s' => \$block_ip,
)) {
exit 2;
}
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);
&add_domain_list($listfile);
}
foreach my $hostfile (@hosts_lists) {
add_host_file($hostfile);
&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) {
@ -118,16 +105,9 @@ MAIN: {
} @block_ip;
} sort keys %domains;
printf STDERR "%d domains written to %s from\n", $written, $out // 'STDOUT';
printf STDERR "%d domains written to %s from\n", $written, $out;
printf STDERR " - %d .domains files\n", (scalar @domain_lists);
printf STDERR " - %d .hosts files\n", (scalar @hosts_lists);
if ($dupes) {
say STDERR "($dupes duplicates)";
}
if ($removed_allowed) {
say STDERR "($removed_allowed domains removed via allowlist)";
}
if ($skip) {
say STDERR "($skip skipped)";
}
printf STDERR "(%d duplicates)\n", $dupes if $dupes;
printf STDERR "(%d skipped)\n", $skip if $skip;
}

@ -1 +0,0 @@
Subproject commit d34e794936f3bcd23b5df198c13b57f088041f9c

@ -0,0 +1 @@
Subproject commit 112ded65a22583512bb814abaf9292122d713965

View file

@ -1,4 +1,5 @@
#!/bin/bash
# vi: et sts=4 sw=4 ts=4
###############################################################################
# You Don't Need Pi-hole
@ -13,17 +14,20 @@
# You may NOT use this software for commercial purposes.
###############################################################################
set -e
WORKDIR=${0%/*}
CFG=$WORKDIR/update.cfg
# Config defaults
BACKUPSUFFIX=
BLOCKLIST=$WORKDIR/block.list
LIST_DIR=$WORKDIR/lists
OUT=()
URL=()
DNSMASQ_RESTART_COMMAND=()
if [[ -f $CFG ]]; then
. "$CFG" || exit
. "$CFG"
fi
TEMP_DIR=$(mktemp -d -t "${0##*/}.XXXXXX")
@ -32,38 +36,7 @@ cleanup() {
}
trap 'cleanup' EXIT
copy_perms() {
local -r FROM=$1 TO=$2
chmod --reference="$FROM" -- "$TO" || exit
if [[ $UID -eq 0 ]]; then
chown --reference="$FROM" -- "$TO" || exit
fi
}
replace_with() {
local -r ORIG=$1 NEW=$2
if ! diff -q -- "$ORIG" "$NEW" &>/dev/null; then
# There's a change
if [[ -f $ORIG ]]; then
copy_perms "$ORIG" "$NEW"
if [[ -n $BACKUPSUFFIX ]]; then
mv -- "$ORIG" "$ORIG$BACKUPSUFFIX" || exit
fi
else
mkdir -p -- "${ORIG%/*}" || exit
fi
mv -- "$NEW" "$ORIG" || exit
else
printf 'File "%s" not modified\n' \
"$ORIG" \
>&2
fi
}
(cd "$WORKDIR" &&
git submodule update --init 'repos-noupdates/*' &&
git submodule update --init --remote 'repos/*'
) || exit
(cd "$WORKDIR" && git submodule update --init --remote)
for (( I = 0 ; I < ${#OUT[@]} ; ++I )); do
MY_URL=${URL[$I]}
@ -79,31 +52,45 @@ for (( I = 0 ; I < ${#OUT[@]} ; ++I )); do
TEMP_OUT=$(mktemp -p "$TEMP_DIR")
if [[ -f $MY_OUT ]]; then
cp -a -- "$MY_OUT" "$TEMP_OUT"
fi
wget \
-O "$TEMP_OUT" \
"$MY_URL" || exit
"$MY_URL"
if [[ -f $MY_OUT ]]; then
chmod --reference="$MY_OUT" "$TEMP_OUT"
if [[ -n $BACKUPSUFFIX ]]; then
mv -- "$MY_OUT" "$MY_OUT$BACKUPSUFFIX"
fi
fi
mkdir -p -- "${MY_OUT%/*}"
mv -- "$TEMP_OUT" "$MY_OUT"
# If the old one is the same, don't keep it around
if [[ -n $BACKUPSUFFIX && -f $MY_OUT$BACKUPSUFFIX ]]; then
if diff -q "$MY_OUT" "$MY_OUT$BACKUPSUFFIX"; then
rm -f -- "$MY_OUT$BACKUPSUFFIX"
fi
fi
replace_with "$MY_OUT" "$TEMP_OUT"
done
TEMP_BLOCKLIST=$(mktemp -p "$TEMP_DIR")
"$WORKDIR/make-block.pl" --out="$TEMP_BLOCKLIST" || exit
# Blocklist generation succeeded, install it!
if [[ ! -e $BLOCKLIST ]]; then
(
# First time:
# Create an empty blocklist with -rw-r--r-- permissions.
# Prevents file not being readable; disregard permissions coming from
# whatever file permissions 'mktemp' sets.
umask 0022
touch -- "$BLOCKLIST"
) || exit
if [[ -n $BACKUPSUFFIX && -f $BLOCKLIST ]]; then
mv -- "$BLOCKLIST" "$BLOCKLIST$BACKUPSUFFIX"
fi
"$WORKDIR/make-block.pl" --out="$BLOCKLIST"
replace_with "$BLOCKLIST" "$TEMP_BLOCKLIST"
# If the old one is the same the same, don't keep it around
if [[ -n $BACKUPSUFFIX && -f $BLOCKLIST$BACKUPSUFFIX ]]; then
if diff -q "$BLOCKLIST" "$BLOCKLIST$BACKUPSUFFIX"; then
rm -f -- "$BLOCKLIST$BACKUPSUFFIX"
fi
fi
if [[ ${#DNSMASQ_RESTART_COMMAND[@]} -gt 0 ]]; then
"${DNSMASQ_RESTART_COMMAND[@]}" || exit
"${DNSMASQ_RESTART_COMMAND[@]}"
fi