Fix unbound reload issue (twas a file permission issue) and add basic ad blocking

This commit is contained in:
Tony Blyler 2021-05-10 19:40:02 -04:00
parent 084e07cb44
commit 407bc6f0d6
4 changed files with 31 additions and 7 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
set -eu
#!/usr/local/bin/bash
set -euo pipefail
readonly DHCPD_CONF_FILE='/etc/dhcpd.conf'
readonly DHCPD_LEASES_FILE='/var/db/dhcpd.leases'
@ -24,5 +24,6 @@ fi
../dhcpd/list_active_assignments | ../unbound/local-data-file-generator > "$UNBOUND_LOCAL_DATA_FILE_TMP"
mv "$UNBOUND_LOCAL_DATA_FILE_TMP" "$UNBOUND_LOCAL_DATA_FILE"
chmod 644 "$UNBOUND_LOCAL_DATA_FILE"
rcctl restart unbound
rcctl reload unbound

4
dhcpd/list_active_assignments Normal file → Executable file
View File

@ -1,5 +1,5 @@
#!/bin/sh
set -eu
#!/usr/local/bin/bash
set -euo pipefail
readonly DHCPD_CONF_FILE="${DHCPD_CONF_FILE:-/etc/dhcpd.conf}"
readonly DHCPD_LEASES_FILE="${DHCPD_LEASES_FILE:-/var/db/dhcpd.leases}"

23
unbound/blocklist-updater Executable file
View File

@ -0,0 +1,23 @@
#!/usr/local/bin/bash
set -euo pipefail
if ! command -v curl &> /dev/null; then
>&2 echo 'curl is missing from PATH'
exit 1
fi
readonly OUTPUT_FILE='/var/unbound/etc/blocklist.conf'
curl -LSsf 'https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts' | awk '/^0\.0\.0\.0/{
# there is no need for a "0.0.0.0 0.0.0.0" line
if ($2 == "0.0.0.0") {
next
}
print "local-zone: \"" $2 "\" redirect"
print "local-data: \"" $2 " A 0.0.0.0\""
}' > "${OUTPUT_FILE}"
chmod 644 "${OUTPUT_FILE}"
rcctl reload unbound

View File

@ -1,6 +1,6 @@
#!/bin/sh
#!/usr/local/bin/bash
set -eu
set -euo pipefail
AWK_SCRIPT=$(cat << 'EOF'
/^[ \t]*[^ \t]+[ \t]+([0-9]{1,3}\.){3}[0-9]{1,3}[ \t]*$/ {