SomeWhereOverTheRainBow
Part of the Furniture
For those who want to enforce safe search with unbound.....
Code:
#!/bin/sh
URL="https://www.google.com/supported_domains"
FILE="/etc/unbound/unbound.conf.d/safesearch.conf" #this can be where-ever your unbound config storage is. You will have to use include: option inside the main unbound.conf though.
f_nslookup() {
local DOMAIN="$1"
nslookup ${DOMAIN} 1.1.1.1 2>/dev/null | awk '/^Address[[:space:]][0-9]*\:[[:space:]]/{if($3 ~ /((((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])\.){3}(25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\/(1?[0-9]|2?[0-9]|3?[0-2]))?)|(([0-9A-f]{0,4}:){1,7}[0-9A-f]{0,4}:{2}(\/(1?[0-2][0-8]|[0-9][0-9]))?))/ && !/1\.1\.1\.1/)print $3}' | while read -r line; do { if [ "${line%%.*}" = "0" ] || [ -z "${line%%::*}" ]; then continue; elif [ "${line##*:}" = "${line}" ]; then printf "%s " "$line"; else printf "%s " "$line"; fi; }; done
}
printf "server:\n" > "${FILE}"
{
DOMAINS="$(curl $URL 2>/dev/null)"
for DOMAIN in $DOMAINS; do
DOMAIN=$(printf "%s\n" "$DOMAIN" | cut -c 2-)
printf 'local-zone: "www.%s." transparent\n' "$DOMAIN"
printf 'local-data: "www.%s. CNAME forcesafesearch.google.com."\n' "$DOMAIN"
done
for DOMAIN in duckduckgo.com; do
printf 'local-zone: "%s." transparent\n' "$DOMAIN"
printf 'local-data: "%s. CNAME safe.%s."\n' "$DOMAIN" "$DOMAIN"
printf 'local-zone: "www.%s." transparent\n' "$DOMAIN"
printf 'local-data: "www.%s. CNAME safe.%s."\n' "$DOMAIN" "$DOMAIN"
printf 'local-zone: "start.%s." transparent\n' "$DOMAIN"
printf 'local-data: "start.%s. CNAME safe.%s."\n' "$DOMAIN" "$DOMAIN"
printf 'local-zone: "duck.com." transparent\n'
printf 'local-data: "duck.com. CNAME safe.%s."\n' "$DOMAIN"
printf 'local-zone: "www.duck.com." transparent\n'
printf 'local-data: "www.duck.com. CNAME safe.%s."\n' "$DOMAIN"
done
for DOMAIN in bing.com; do
printf 'local-zone: "%s." transparent\n' "$DOMAIN"
printf 'local-data: "%s. CNAME strict.%s."\n' "$DOMAIN" "$DOMAIN"
printf 'local-zone: "www.%s." transparent\n' "$DOMAIN"
printf 'local-data: "www.%s. CNAME strict.%s."\n' "$DOMAIN" "$DOMAIN"
done
for DOMAIN in qwant.com; do
printf 'local-zone: "api.%s." transparent\n' "$DOMAIN"
printf 'local-data: "api.%s. CNAME safeapi.%s."\n' "$DOMAIN" "$DOMAIN"
printf 'local-zone: "www.%s." transparent\n' "$DOMAIN"
printf 'local-data: "www.%s. CNAME safeapi.%s."\n' "$DOMAIN" "$DOMAIN"
printf 'local-zone: "%s." transparent\n' "$DOMAIN"
printf 'local-data: "%s. CNAME safeapi.%s."\n' "$DOMAIN" "$DOMAIN"
printf 'local-zone: "s1.%s." transparent\n' "$DOMAIN"
printf 'local-data: "s1.%s. CNAME safeapi.%s."\n' "$DOMAIN" "$DOMAIN"
printf 'local-zone: "s2.%s." transparent\n' "$DOMAIN"
printf 'local-data: "s2.%s. CNAME safeapi.%s."\n' "$DOMAIN" "$DOMAIN"
done
for DOMAIN in pixabay.com; do
printf 'local-zone: "%s." transparent\n' "$DOMAIN"
printf 'local-data: "%s. CNAME safesearch.%s."\n' "$DOMAIN" "$DOMAIN"
done
for DOMAIN in youtube; do
printf 'local-zone: "www.%s.com." transparent\n' "$DOMAIN"
printf 'local-data: "www.%s.com. CNAME restrictmoderate.%s.com."\n' "$DOMAIN" "$DOMAIN"
printf 'local-zone: "m.%s.com." transparent\n' "$DOMAIN"
printf 'local-data: "m.%s.com. CNAME restrictmoderate.%s.com."\n' "$DOMAIN" "$DOMAIN"
printf 'local-zone: "%si.googleapis.com." transparent\n' "$DOMAIN"
printf 'local-data: "%si.googleapis.com. CNAME restrictmoderate.%s.com."\n' "$DOMAIN" "$DOMAIN"
printf 'local-zone: "%s.googleapis.com." transparent\n' "$DOMAIN"
printf 'local-data: "%s.googleapis.com. CNAME restrictmoderate.%s.com."\n' "$DOMAIN" "$DOMAIN"
printf 'local-zone: "www.%s-nocookie.com." transparent\n' "$DOMAIN"
printf 'local-data: "www.%s-nocookie.com. CNAME restrictmoderate.%s.com."\n' "$DOMAIN" "$DOMAIN"
done
for YANDEX in com ru ua by kz; do
printf 'local-zone: "yandex.%s." transparent\n' "$YANDEX"
printf 'local-data: "yandex.%s. CNAME familysearch.yandex.ru."\n' "$YANDEX"
printf 'local-zone: "www.yandex.%s." transparent\n' "$YANDEX"
printf 'local-data: "www.yandex.%s. CNAME familysearch.yandex.ru."\n' "$YANDEX"
done
for DOMAIN in forcesafesearch.google.com safe.duckduckgo.com restrictmoderate.youtube.com strict.bing.com safesearch.pixabay.com safeapi.qwant.com familysearch.yandex.ru; do
for IPS in $(f_nslookup $DOMAIN); do
if [ "$DOMAIN" = "forcesafesearch.google.com" ]; then
if [ "${IPS##*:}" = "${IPS}" ]; then
printf "%s\n" 'local-data: "'${DOMAIN}'. A '${IPS}'"'
printf "%s\n" 'local-data: "'${DOMAIN}'. AAAA ::ffff:'${IPS}'"'
printf "%s\n" 'local-data: "restrict.youtube.com. A '${IPS}'"'
printf "%s\n" 'local-data: "restrict.youtube.com. AAAA ::ffff:'${IPS}'"'
else
printf "%s\n" 'local-data: "'${DOMAIN}'. AAAA '${IPS}'"'
printf "%s\n" 'local-data: "restrict.youtube.com. AAAA '${IPS}'"'
fi
else
if [ "${IPS##*:}" = "${IPS}" ]; then
printf "%s\n" 'local-data: "'${DOMAIN}'. A '${IPS}'"'
printf "%s\n" 'local-data: "'${DOMAIN}'. AAAA ::ffff:'${IPS}'"'
else
printf "%s\n" 'local-data: "'${DOMAIN}'. AAAA '${IPS}'"'
fi
fi
done
done
} >> "${FILE}"
Last edited: