mirror of
https://codeberg.org/h3xx/you-dont-need-pihole.git
synced 2024-08-14 20:27:01 +00:00
Initial commit
This commit is contained in:
commit
c6f800c04a
7 changed files with 199 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/lists/StevenBlack-all.hosts
|
||||
block.list
|
8
custom.list
Normal file
8
custom.list
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Custom IP addresses to serve via dnsmasq, one per line
|
||||
#
|
||||
# Format:
|
||||
# IP DNS-NAME...
|
||||
#
|
||||
# Examples:
|
||||
# ffff::211:ffff:ffff:dddd joe joe-vm
|
||||
# 192.168.0.2 cindy
|
0
lists/.gitkeep
Normal file
0
lists/.gitkeep
Normal file
8
local.list
Normal file
8
local.list
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Local IP addresses to serve via dnsmasq, one per line
|
||||
#
|
||||
# Format:
|
||||
# IP DNS-NAME...
|
||||
#
|
||||
# Examples:
|
||||
# ffff::211:ffff:ffff:dddd joe joe-vm
|
||||
# 192.168.0.2 cindy
|
89
make-block.pl
Executable file
89
make-block.pl
Executable file
|
@ -0,0 +1,89 @@
|
|||
#!/usr/bin/perl
|
||||
# vi: et sts=4 sw=4 ts=4
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Getopt::Long qw/ GetOptions :config no_ignore_case /;
|
||||
|
||||
my %domains;
|
||||
my $dupes = 0;
|
||||
my $skip = 0;
|
||||
sub add_domain_list {
|
||||
my $file = shift;
|
||||
|
||||
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;
|
||||
++$dupes if defined $domains{$domain};
|
||||
$domains{$domain} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub add_host_file {
|
||||
my $file = shift;
|
||||
|
||||
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;
|
||||
if (lc $parts[0] eq lc $parts[1]) {
|
||||
++$skip;
|
||||
next;
|
||||
}
|
||||
unless (lc $parts[0] eq '0.0.0.0') {
|
||||
++$skip;
|
||||
next;
|
||||
}
|
||||
my $domain = lc $parts[1];
|
||||
++$dupes if defined $domains{$domain};
|
||||
$domains{$domain} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
MAIN: {
|
||||
my $out = 'block.list';
|
||||
my $block_ip = '0.0.0.0';
|
||||
|
||||
unless (&GetOptions(
|
||||
'out=s' => \$out,
|
||||
'O=s' => \$out,
|
||||
'i=s' => \$block_ip,
|
||||
'block-ip=s' => \$block_ip,
|
||||
)) {
|
||||
exit 2;
|
||||
}
|
||||
my @domain_lists = glob 'lists/*.domains';
|
||||
my @hosts_lists = glob 'lists/*.hosts';
|
||||
|
||||
foreach my $listfile (@domain_lists) {
|
||||
&add_domain_list($listfile);
|
||||
}
|
||||
foreach my $hostfile (@hosts_lists) {
|
||||
&add_host_file($hostfile);
|
||||
}
|
||||
|
||||
my $written = 0;
|
||||
open my $fho, '>', $out
|
||||
or die "Failed to open file $out for writing: $!";
|
||||
print $fho map {
|
||||
++$written;
|
||||
"$block_ip $_\n"
|
||||
} sort keys %domains;
|
||||
|
||||
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);
|
||||
printf STDERR "(%d duplicates)\n", $dupes if $dupes;
|
||||
printf STDERR "(%d skipped)\n", $skip if $skip;
|
||||
}
|
19
update.cfg
Normal file
19
update.cfg
Normal file
|
@ -0,0 +1,19 @@
|
|||
# vi: ft=sh
|
||||
WORKDIR=${WORKDIR:-${BASH_SOURCE%/*}}
|
||||
BACKUPSUFFIX=.old
|
||||
BLOCKLIST=$WORKDIR/block.list
|
||||
LIST_DIR=$WORKDIR/lists
|
||||
OUT=()
|
||||
URL=()
|
||||
|
||||
# StevenBlack comprehensive host list (all)
|
||||
OUT+=("$LIST_DIR/StevenBlack-all.hosts")
|
||||
URL+=('https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts')
|
||||
|
||||
# Individual hosts lists in that collection
|
||||
#OUT+=("$LIST_DIR/sb-Badd-Boyz-Hosts.hosts")
|
||||
#URL+=('https://raw.githubusercontent.com/StevenBlack/hosts/master/data/Badd-Boyz-Hosts/hosts')
|
||||
|
||||
# Not sure how I'm supposed to update this file...
|
||||
#OUT+=("$LIST_DIR/list.1.raw.githubusercontent.com.domains")
|
||||
#URL+=('???')
|
73
update.sh
Executable file
73
update.sh
Executable file
|
@ -0,0 +1,73 @@
|
|||
#!/bin/bash
|
||||
# vi: et sts=4 sw=4 ts=4
|
||||
|
||||
set -e
|
||||
|
||||
WORKDIR=${0%/*}
|
||||
CFG=$WORKDIR/update.cfg
|
||||
|
||||
. "$CFG"
|
||||
|
||||
TEMP_FILES=()
|
||||
cleanup() {
|
||||
rm -f -- "${TEMP_FILES[@]}"
|
||||
}
|
||||
trap 'cleanup' EXIT
|
||||
|
||||
for (( I = 0 ; I < ${#OUT[@]} ; ++I )); do
|
||||
MY_URL=${URL[$I]}
|
||||
MY_OUT=${OUT[$I]}
|
||||
if [[ -z $MY_URL ]]; then
|
||||
echo "$CFG: URL[$I] empty" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [[ -z $MY_OUT ]]; then
|
||||
echo "$CFG: OUT[$I] empty" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
TEMP_OUT=$(mktemp -t "${0##*/}.XXXXXX")
|
||||
TEMP_FILES+=("$TEMP_OUT")
|
||||
|
||||
if [[ -f $MY_OUT ]]; then
|
||||
cp -a -- "$MY_OUT" "$TEMP_OUT"
|
||||
fi
|
||||
|
||||
wget \
|
||||
-O "$TEMP_OUT" \
|
||||
"$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
|
||||
|
||||
done
|
||||
|
||||
if [[ -n $BACKUPSUFFIX && -f $BLOCKLIST ]]; then
|
||||
mv -- "$BLOCKLIST" "$BLOCKLIST$BACKUPSUFFIX"
|
||||
fi
|
||||
"$WORKDIR/make-block.pl" --out="$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 [[ -x /etc/rc.d/rc.dnsmasq ]]; then
|
||||
/etc/rc.d/rc.dnsmasq restart
|
||||
fi
|
Loading…
Reference in a new issue