First test
This commit is contained in:
53
scripts/README.md
Executable file
53
scripts/README.md
Executable file
@@ -0,0 +1,53 @@
|
||||
# DNS Generation Scripts
|
||||
|
||||
## Introduction
|
||||
|
||||
The respective shell scripts contained within this directory can be utilised to generate application specific compliant
|
||||
configuration which can be utilised with:
|
||||
|
||||
* AdGuard Home
|
||||
* BIND9
|
||||
* Dnsmasq/Pi-hole
|
||||
* Squid
|
||||
* Unbound
|
||||
|
||||
## Usage
|
||||
|
||||
1. Copy `config.example.json` to `config.json`.
|
||||
2. Modify `config.json` to include your Cacheserver's IP(s) and the CDNs you plan to cache.
|
||||
|
||||
The following example assumes a single shared Cacheserver IP:
|
||||
```json
|
||||
{
|
||||
"combined_output": false,
|
||||
"ips": {
|
||||
"monolithic": ["10.10.10.200"]
|
||||
},
|
||||
"cache_domains": {
|
||||
"blizzard": "monolithic",
|
||||
"epicgames": "monolithic",
|
||||
"nintendo": "monolithic",
|
||||
"origin": "monolithic",
|
||||
"riot": "monolithic",
|
||||
"sony": "monolithic",
|
||||
"steam": "monolithic",
|
||||
"uplay": "monolithic",
|
||||
"wsus": "monolithic"
|
||||
}
|
||||
}
|
||||
```
|
||||
3. Run generation script relative to your DNS implementation: `bash create-dnsmasq.sh`.
|
||||
4. If `combined_output` is set to `true` this will result in a single output file: `lancache.conf` with all your enabled services (applies to Adguard Home, Dnsmasq or Unbound).
|
||||
5. Copy files from `output/{adguardhome,dnsmasq,rpz,squid,unbound}/*` to the respective locations for Dnsmasq/Unbound.
|
||||
6. Restart the appropriate service.
|
||||
|
||||
### Notes for Dnsmasq users
|
||||
|
||||
**This also applies to users utilising the script alongside Pi-hole.**
|
||||
|
||||
Multi-IP Lancache setups are only supported with Dnsmasq or Pi-hole versions >= 2.86 or 2021.09 respectively.
|
||||
|
||||
### Notes for AdGuard Home users
|
||||
|
||||
1. Utilising `"combined_output": true` is more convenient.
|
||||
2. Once you have run the script and uploaded the file to the appropriate location, you should navigate to Adguard Home -> Filters -> DNS blocklists -> Add blocklist -> Add a custom list.
|
||||
80
scripts/create-adguardhome.sh
Executable file
80
scripts/create-adguardhome.sh
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/bin/bash
|
||||
basedir=".."
|
||||
outputdir="output/adguardhome"
|
||||
path="${basedir}/cache_domains.json"
|
||||
|
||||
export IFS=' '
|
||||
|
||||
test=$(which jq);
|
||||
if [ $? -gt 0 ] ; then
|
||||
echo "This script requires jq to be installed."
|
||||
echo "Your package manager should be able to find it"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cachenamedefault="disabled"
|
||||
combinedoutput=$(jq -r ".combined_output" config.json)
|
||||
|
||||
while read line; do
|
||||
ip=$(jq ".ips[\"${line}\"]" config.json)
|
||||
declare "cacheip${line}"="${ip}"
|
||||
done <<< $(jq -r '.ips | to_entries[] | .key' config.json)
|
||||
|
||||
while read line; do
|
||||
name=$(jq -r ".cache_domains[\"${line}\"]" config.json)
|
||||
declare "cachename$line"="$name"
|
||||
done <<< $(jq -r '.cache_domains | to_entries[] | .key' config.json)
|
||||
|
||||
rm -rf ${outputdir}
|
||||
mkdir -p ${outputdir}
|
||||
while read entry; do
|
||||
unset cacheip
|
||||
unset cachename
|
||||
key=$(jq -r ".cache_domains[$entry].name" ${path})
|
||||
cachename="cachename${key}"
|
||||
if [ -z "${!cachename}" ]; then
|
||||
cachename="cachenamedefault"
|
||||
fi
|
||||
if [[ ${!cachename} == "disabled" ]]; then
|
||||
continue;
|
||||
fi
|
||||
cacheipname="cacheip${!cachename}"
|
||||
cacheip=$(jq -r 'if type == "array" then .[] else . end' <<< ${!cacheipname} | xargs)
|
||||
while read fileid; do
|
||||
while read filename; do
|
||||
destfilename=$(echo ${filename} | sed -e 's/txt/conf/')
|
||||
outputfile=${outputdir}/${destfilename}
|
||||
touch ${outputfile}
|
||||
while read fileentry; do
|
||||
# Ignore comments and newlines
|
||||
if [[ ${fileentry} == \#* ]] || [[ -z ${fileentry} ]]; then
|
||||
continue
|
||||
fi
|
||||
domainprefix="|"
|
||||
if [[ $fileentry =~ ^\*\. ]]; then
|
||||
domainprefix="||"
|
||||
fi
|
||||
parsed=$(echo ${fileentry} | sed -e "s/^\*\.//")
|
||||
if grep -q "${domainprefix}${parsed}^\$dnsrewrite" ${outputfile}; then
|
||||
continue
|
||||
fi
|
||||
for i in ${cacheip}; do
|
||||
echo "${domainprefix}${parsed}^\$dnsrewrite=${i}" >> ${outputfile}
|
||||
done
|
||||
done <<< $(cat ${basedir}/$filename | sort);
|
||||
done <<< $(jq -r ".cache_domains[${entry}].domain_files[${fileid}]" ${path})
|
||||
done <<< $(jq -r ".cache_domains[${entry}].domain_files | to_entries[] | .key" ${path})
|
||||
done <<< $(jq -r '.cache_domains | to_entries[] | .key' ${path})
|
||||
|
||||
if [[ ${combinedoutput} == "true" ]]; then
|
||||
for file in ${outputdir}/*; do f=${file//${outputdir}\/} && f=${f//.conf} && echo "# ${f^}" >> ${outputdir}/lancache.conf && cat ${file} >> ${outputdir}/lancache.conf && rm ${file}; done
|
||||
fi
|
||||
|
||||
cat << EOF
|
||||
Configuration generation completed.
|
||||
|
||||
Please copy the following files:
|
||||
- ./${outputdir}/*.conf to /opt/adguardhome/work/userfilters/
|
||||
- Navigate to Adguard Home -> Filters -> DNS blocklists -> Add blocklist -> Add a custom list
|
||||
- Add list for each service or utilise the combined output for a single list
|
||||
EOF
|
||||
76
scripts/create-dnsmasq.sh
Executable file
76
scripts/create-dnsmasq.sh
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
basedir=".."
|
||||
outputdir="output/dnsmasq"
|
||||
path="${basedir}/cache_domains.json"
|
||||
|
||||
export IFS=' '
|
||||
|
||||
test=$(which jq);
|
||||
if [ $? -gt 0 ] ; then
|
||||
echo "This script requires jq to be installed."
|
||||
echo "Your package manager should be able to find it"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cachenamedefault="disabled"
|
||||
combinedoutput=$(jq -r ".combined_output" config.json)
|
||||
|
||||
while read -r line; do
|
||||
ip=$(jq ".ips[\"${line}\"]" config.json)
|
||||
declare "cacheip${line}"="${ip}"
|
||||
done <<< $(jq -r '.ips | to_entries[] | .key' config.json)
|
||||
|
||||
while read -r line; do
|
||||
name=$(jq -r ".cache_domains[\"${line}\"]" config.json)
|
||||
declare "cachename${line}"="${name}"
|
||||
done <<< $(jq -r '.cache_domains | to_entries[] | .key' config.json)
|
||||
|
||||
rm -rf ${outputdir}
|
||||
mkdir -p ${outputdir}
|
||||
while read -r entry; do
|
||||
unset cacheip
|
||||
unset cachename
|
||||
key=$(jq -r ".cache_domains[${entry}].name" ${path})
|
||||
cachename="cachename${key}"
|
||||
if [ -z "${!cachename}" ]; then
|
||||
cachename="cachenamedefault"
|
||||
fi
|
||||
if [[ ${!cachename} == "disabled" ]]; then
|
||||
continue;
|
||||
fi
|
||||
cacheipname="cacheip${!cachename}"
|
||||
cacheip=$(jq -r 'if type == "array" then .[] else . end' <<< ${!cacheipname} | xargs)
|
||||
while read -r fileid; do
|
||||
while read -r filename; do
|
||||
destfilename=$(echo ${filename} | sed -e 's/txt/conf/')
|
||||
outputfile=${outputdir}/${destfilename}
|
||||
touch ${outputfile}
|
||||
while read -r fileentry; do
|
||||
# Ignore comments, newlines and wildcards
|
||||
if [[ ${fileentry} == \#* ]] || [[ -z ${fileentry} ]]; then
|
||||
continue
|
||||
fi
|
||||
parsed=$(echo ${fileentry} | sed -e "s/^\*\.//")
|
||||
for i in ${cacheip}; do
|
||||
if ! grep -qx "address=/${parsed}/${i}" "${outputfile}"; then
|
||||
echo "address=/${parsed}/${i}" >> "${outputfile}"
|
||||
fi
|
||||
if ! grep -qx "local=/${parsed}/" "${outputfile}"; then
|
||||
echo "local=/${parsed}/" >> "${outputfile}"
|
||||
fi
|
||||
done
|
||||
done <<< $(cat ${basedir}/${filename} | sort);
|
||||
done <<< $(jq -r ".cache_domains[${entry}].domain_files[$fileid]" ${path})
|
||||
done <<< $(jq -r ".cache_domains[${entry}].domain_files | to_entries[] | .key" ${path})
|
||||
done <<< $(jq -r '.cache_domains | to_entries[] | .key' ${path})
|
||||
|
||||
if [[ ${combinedoutput} == "true" ]]; then
|
||||
for file in ${outputdir}/*; do f=${file//${outputdir}\/} && f=${f//.conf} && echo "# ${f^}" >> ${outputdir}/lancache.conf && cat ${file} >> ${outputdir}/lancache.conf && rm ${file}; done
|
||||
fi
|
||||
|
||||
cat << EOF
|
||||
Configuration generation completed.
|
||||
|
||||
Please copy the following files:
|
||||
- ./${outputdir}/*.conf to /etc/dnsmasq/dnsmasq.d/
|
||||
EOF
|
||||
113
scripts/create-rpz.sh
Executable file
113
scripts/create-rpz.sh
Executable file
@@ -0,0 +1,113 @@
|
||||
#!/bin/bash
|
||||
basedir=".."
|
||||
outputdir="output/rpz"
|
||||
path="${basedir}/cache_domains.json"
|
||||
basedomain=${1:-lancache.net}
|
||||
|
||||
export IFS=' '
|
||||
|
||||
test=$(which jq);
|
||||
if [ $? -gt 0 ] ; then
|
||||
echo "This script requires jq to be installed."
|
||||
echo "Your package manager should be able to find it"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cachenamedefault="disabled"
|
||||
|
||||
while read line; do
|
||||
ip=$(jq ".ips[\"${line}\"]" config.json)
|
||||
declare "cacheip${line}"="${ip}"
|
||||
done <<< $(jq -r '.ips | to_entries[] | .key' config.json)
|
||||
|
||||
while read line; do
|
||||
name=$(jq -r ".cache_domains[\"${line}\"]" config.json)
|
||||
declare "cachename${line}"="${name}"
|
||||
done <<< $(jq -r '.cache_domains | to_entries[] | .key' config.json)
|
||||
|
||||
rm -rf ${outputdir}
|
||||
mkdir -p ${outputdir}
|
||||
outputfile=${outputdir}/db.rpz.${basedomain}
|
||||
cat > ${outputfile} << EOF
|
||||
\$TTL 60 ; default TTL
|
||||
\$ORIGIN rpz.${basedomain}.
|
||||
@ SOA ns1.${basedomain}. admin.${basedomain}. (
|
||||
$(date +%Y%m%d01) ; serial
|
||||
604800 ; refresh (1 week)
|
||||
600 ; retry (10 mins)
|
||||
600 ; expire (10 mins)
|
||||
600 ; minimum (10 mins)
|
||||
)
|
||||
NS ns1.${basedomain}.
|
||||
NS ns2.${basedomain}.
|
||||
|
||||
EOF
|
||||
|
||||
while read entry; do
|
||||
unset cacheip
|
||||
unset cachename
|
||||
key=$(jq -r ".cache_domains[${entry}].name" ${path})
|
||||
cachename="cachename${key}"
|
||||
if [ -z "${!cachename}" ]; then
|
||||
cachename="cachenamedefault"
|
||||
fi
|
||||
if [[ ${!cachename} == "disabled" ]]; then
|
||||
continue;
|
||||
fi
|
||||
cacheipname="cacheip${!cachename}"
|
||||
cacheip=$(jq -r 'if type == "array" then .[] else . end' <<< ${!cacheipname} | xargs)
|
||||
while read fileid; do
|
||||
while read filename; do
|
||||
echo "" >> ${outputfile}
|
||||
echo "; $(echo ${filename} | sed -e 's/.txt$//')" >> ${outputfile}
|
||||
destfilename=$(echo ${filename} | sed -e 's/txt/conf/')
|
||||
while read fileentry; do
|
||||
# Ignore comments and newlines
|
||||
if [[ ${fileentry} == \#* ]] || [[ -z ${fileentry} ]]; then
|
||||
continue
|
||||
fi
|
||||
parsed=$(echo ${fileentry})
|
||||
if grep -qx "^\"${parsed}\". " ${outputfile}; then
|
||||
continue
|
||||
fi
|
||||
t=""
|
||||
for i in ${cacheip}; do
|
||||
# only one cname per domain is allowed
|
||||
if [[ ${t} = "CNAME" ]]; then
|
||||
continue
|
||||
fi
|
||||
# for cnames you must use a fqdn with trailing dot
|
||||
t="CNAME"
|
||||
if [[ ${i} =~ ^[0-9\.]+$ ]] ; then
|
||||
t="A"
|
||||
elif [[ ! ${i} =~ \.$ ]] ; then
|
||||
i="${i}."
|
||||
fi
|
||||
printf "%-50s IN %s %s\n" \
|
||||
"${parsed}" \
|
||||
"${t}" \
|
||||
"${i}" \
|
||||
>> ${outputfile}
|
||||
done
|
||||
done <<< $(cat ${basedir}/${filename} | sort);
|
||||
done <<< $(jq -r ".cache_domains[${entry}].domain_files[${fileid}]" ${path})
|
||||
done <<< $(jq -r ".cache_domains[${entry}].domain_files | to_entries[] | .key" ${path})
|
||||
done <<< $(jq -r '.cache_domains | to_entries[] | .key' ${path})
|
||||
|
||||
cat << EOF
|
||||
Configuration generation completed.
|
||||
|
||||
Please include the rpz zone in your bind configuration"
|
||||
- cp ${outputfile} /etc/bind
|
||||
- configure the zone and use it
|
||||
|
||||
options {
|
||||
[...]
|
||||
response-policy {zone "rpz.${basedomain}";};
|
||||
[...]
|
||||
}
|
||||
zone "rpz.$basedomain" {
|
||||
type master;
|
||||
file "/etc/bind/db.rpz.${basedomain}";
|
||||
};
|
||||
EOF
|
||||
70
scripts/create-squid.sh
Executable file
70
scripts/create-squid.sh
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
basedir=".."
|
||||
outputdir="output/squid"
|
||||
path="${basedir}/cache_domains.json"
|
||||
REGEX="^\\*\\.(.*)$"
|
||||
|
||||
export IFS=' '
|
||||
|
||||
test=$(which jq);
|
||||
if [ $? -gt 0 ] ; then
|
||||
echo "This script requires jq to be installed."
|
||||
echo "Your package manager should be able to find it"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cachenamedefault="disabled"
|
||||
|
||||
while read -r line; do
|
||||
name=$(jq -r ".cache_domains[\"${line}\"]" config.json)
|
||||
declare "cachename${line}"="${name}"
|
||||
done <<< $(jq -r '.cache_domains | to_entries[] | .key' config.json)
|
||||
|
||||
rm -rf ${outputdir}
|
||||
mkdir -p ${outputdir}
|
||||
while read -r entry; do
|
||||
unset cachename
|
||||
key=$(jq -r ".cache_domains[$entry].name" ${path})
|
||||
cachename="cachename${key}"
|
||||
if [ -z "${!cachename}" ]; then
|
||||
cachename="cachenamedefault"
|
||||
fi
|
||||
if [[ ${!cachename} == "disabled" ]]; then
|
||||
continue;
|
||||
fi
|
||||
while read -r fileid; do
|
||||
while read -r filename; do
|
||||
destfilename=$(echo ${!cachename}.txt)
|
||||
outputfile=${outputdir}/${destfilename}
|
||||
touch ${outputfile}
|
||||
while read -r fileentry; do
|
||||
# Ignore comments
|
||||
if [[ ${fileentry} == \#* ]] || [[ -z ${fileentry} ]]; then
|
||||
continue
|
||||
fi
|
||||
# Ha wildcards to squid wildcards
|
||||
parsed=$(echo ${fileentry} | sed -e "s/^\*\./\./")
|
||||
# If we have cdn.thing and *.cdn.thing in cache_domains
|
||||
# Squid requires ONLY cdn.thing
|
||||
#
|
||||
# If the fileentry starts with *.cdn.thing
|
||||
if [[ ${fileentry} =~ $REGEX ]]; then
|
||||
# Does the cache_domains file also contain cdn.thing
|
||||
grep "${BASH_REMATCH[1]}" ${basedir}/${filename} | grep -v "${fileentry}" > /dev/null
|
||||
if [[ $? -eq 0 ]]; then
|
||||
# Skip *.cdn.thing as cdn.thing will be collected earlier/later
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
echo "${parsed}" >> "${outputfile}"
|
||||
done <<< $(cat ${basedir}/${filename} | sort);
|
||||
done <<< $(jq -r ".cache_domains[${entry}].domain_files[${fileid}]" ${path})
|
||||
done <<< $(jq -r ".cache_domains[${entry}].domain_files | to_entries[] | .key" ${path})
|
||||
done <<< $(jq -r '.cache_domains | to_entries[] | .key' ${path})
|
||||
|
||||
cat << EOF
|
||||
Configuration generation completed.
|
||||
|
||||
Please copy the following files:
|
||||
- ./${outputdir}/*.txt to /etc/squid/domains/
|
||||
EOF
|
||||
78
scripts/create-unbound.sh
Executable file
78
scripts/create-unbound.sh
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
basedir=".."
|
||||
outputdir="output/unbound"
|
||||
path="${basedir}/cache_domains.json"
|
||||
|
||||
export IFS=' '
|
||||
|
||||
test=$(which jq);
|
||||
if [ $? -gt 0 ] ; then
|
||||
echo "This script requires jq to be installed."
|
||||
echo "Your package manager should be able to find it"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cachenamedefault="disabled"
|
||||
combinedoutput=$(jq -r ".combined_output" config.json)
|
||||
|
||||
while read line; do
|
||||
ip=$(jq ".ips[\"${line}\"]" config.json)
|
||||
declare "cacheip${line}"="${ip}"
|
||||
done <<< $(jq -r '.ips | to_entries[] | .key' config.json)
|
||||
|
||||
while read line; do
|
||||
name=$(jq -r ".cache_domains[\"${line}\"]" config.json)
|
||||
declare "cachename${line}"="${name}"
|
||||
done <<< $(jq -r '.cache_domains | to_entries[] | .key' config.json)
|
||||
|
||||
rm -rf ${outputdir}
|
||||
mkdir -p ${outputdir}
|
||||
while read entry; do
|
||||
unset cacheip
|
||||
unset cachename
|
||||
key=$(jq -r ".cache_domains[${entry}].name" ${path})
|
||||
cachename="cachename${key}"
|
||||
if [ -z "${!cachename}" ]; then
|
||||
cachename="cachenamedefault"
|
||||
fi
|
||||
if [[ ${!cachename} == "disabled" ]]; then
|
||||
continue;
|
||||
fi
|
||||
cacheipname="cacheip${!cachename}"
|
||||
cacheip=$(jq -r 'if type == "array" then .[] else . end' <<< ${!cacheipname} | xargs)
|
||||
while read fileid; do
|
||||
while read filename; do
|
||||
destfilename=$(echo ${filename} | sed -e 's/txt/conf/')
|
||||
outputfile=${outputdir}/${destfilename}
|
||||
touch ${outputfile}
|
||||
while read fileentry; do
|
||||
# Ignore comments and newlines
|
||||
if [[ ${fileentry} == \#* ]] || [[ -z ${fileentry} ]]; then
|
||||
continue
|
||||
fi
|
||||
parsed=$(echo ${fileentry} | sed -e "s/^\*\.//")
|
||||
if grep -qx " local-zone: \"${parsed}\" redirect" ${outputfile}; then
|
||||
continue
|
||||
fi
|
||||
if [[ $(head -n 1 ${outputfile}) != "server:" ]]; then
|
||||
echo "server:" >> ${outputfile}
|
||||
fi
|
||||
echo " local-zone: \"${parsed}\" redirect" >> ${outputfile}
|
||||
for i in ${cacheip}; do
|
||||
echo " local-data: \"${parsed} 30 IN A ${i}\"" >> ${outputfile}
|
||||
done
|
||||
done <<< $(cat ${basedir}/${filename} | sort);
|
||||
done <<< $(jq -r ".cache_domains[${entry}].domain_files[${fileid}]" ${path})
|
||||
done <<< $(jq -r ".cache_domains[${entry}].domain_files | to_entries[] | .key" ${path})
|
||||
done <<< $(jq -r '.cache_domains | to_entries[] | .key' ${path})
|
||||
|
||||
if [[ ${combinedoutput} == "true" ]]; then
|
||||
for file in ${outputdir}/*; do f=${file//${outputdir}\/} && f=${f//.conf} && echo "# ${f^}" >> ${outputdir}/lancache.conf && cat ${file} >> ${outputdir}/lancache.conf && rm ${file}; done
|
||||
fi
|
||||
|
||||
cat << EOF
|
||||
Configuration generation completed.
|
||||
|
||||
Please copy the following files:
|
||||
- ./${outputdir}/*.conf to /etc/unbound/unbound.conf.d/
|
||||
EOF
|
||||
Reference in New Issue
Block a user