mirror of
https://github.com/pi-hole/docker-pi-hole.git
synced 2024-07-04 07:01:08 +02:00
commit
ea0a3221de
|
@ -27,7 +27,7 @@ THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
base_vars = {
|
base_vars = {
|
||||||
'name': 'diginc/pi-hole',
|
'name': 'diginc/pi-hole',
|
||||||
'maintainer' : 'adam@diginc.us',
|
'maintainer' : 'adam@diginc.us',
|
||||||
's6_version' : 'v1.20.0.0',
|
's6_version' : 'v1.21.2.1',
|
||||||
}
|
}
|
||||||
|
|
||||||
os_base_vars = {
|
os_base_vars = {
|
||||||
|
|
|
@ -11,7 +11,7 @@ ENV PATH /opt/pihole:${PATH}
|
||||||
COPY install.sh /usr/local/bin/docker-install.sh
|
COPY install.sh /usr/local/bin/docker-install.sh
|
||||||
ENV setupVars /etc/pihole/setupVars.conf
|
ENV setupVars /etc/pihole/setupVars.conf
|
||||||
ENV PIHOLE_INSTALL /tmp/ph_install.sh
|
ENV PIHOLE_INSTALL /tmp/ph_install.sh
|
||||||
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.20.0.0/s6-overlay-amd64.tar.gz
|
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.21.2.1/s6-overlay-amd64.tar.gz
|
||||||
|
|
||||||
# TODO Re-enable upgrade after php5 packages use the latest greatest libressl packages, conflicts are breaking build 2017-11-14
|
# TODO Re-enable upgrade after php5 packages use the latest greatest libressl packages, conflicts are breaking build 2017-11-14
|
||||||
# RUN apk upgrade --update && \
|
# RUN apk upgrade --update && \
|
||||||
|
|
|
@ -11,7 +11,7 @@ ENV PATH /opt/pihole:${PATH}
|
||||||
COPY install.sh /usr/local/bin/docker-install.sh
|
COPY install.sh /usr/local/bin/docker-install.sh
|
||||||
ENV setupVars /etc/pihole/setupVars.conf
|
ENV setupVars /etc/pihole/setupVars.conf
|
||||||
ENV PIHOLE_INSTALL /tmp/ph_install.sh
|
ENV PIHOLE_INSTALL /tmp/ph_install.sh
|
||||||
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.20.0.0/s6-overlay-armhf.tar.gz
|
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.21.2.1/s6-overlay-armhf.tar.gz
|
||||||
|
|
||||||
# TODO Re-enable upgrade after php5 packages use the latest greatest libressl packages, conflicts are breaking build 2017-11-14
|
# TODO Re-enable upgrade after php5 packages use the latest greatest libressl packages, conflicts are breaking build 2017-11-14
|
||||||
# RUN apk upgrade --update && \
|
# RUN apk upgrade --update && \
|
||||||
|
|
|
@ -11,7 +11,7 @@ ENV PATH /opt/pihole:${PATH}
|
||||||
COPY install.sh /usr/local/bin/docker-install.sh
|
COPY install.sh /usr/local/bin/docker-install.sh
|
||||||
ENV setupVars /etc/pihole/setupVars.conf
|
ENV setupVars /etc/pihole/setupVars.conf
|
||||||
ENV PIHOLE_INSTALL /tmp/ph_install.sh
|
ENV PIHOLE_INSTALL /tmp/ph_install.sh
|
||||||
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.20.0.0/s6-overlay-aarch64.tar.gz
|
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.21.2.1/s6-overlay-aarch64.tar.gz
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y wget curl net-tools cron && \
|
apt-get install -y wget curl net-tools cron && \
|
||||||
|
|
|
@ -11,7 +11,7 @@ ENV PATH /opt/pihole:${PATH}
|
||||||
COPY install.sh /usr/local/bin/docker-install.sh
|
COPY install.sh /usr/local/bin/docker-install.sh
|
||||||
ENV setupVars /etc/pihole/setupVars.conf
|
ENV setupVars /etc/pihole/setupVars.conf
|
||||||
ENV PIHOLE_INSTALL /tmp/ph_install.sh
|
ENV PIHOLE_INSTALL /tmp/ph_install.sh
|
||||||
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.20.0.0/s6-overlay-amd64.tar.gz
|
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.21.2.1/s6-overlay-amd64.tar.gz
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y wget curl net-tools cron && \
|
apt-get install -y wget curl net-tools cron && \
|
||||||
|
|
|
@ -11,7 +11,7 @@ ENV PATH /opt/pihole:${PATH}
|
||||||
COPY install.sh /usr/local/bin/docker-install.sh
|
COPY install.sh /usr/local/bin/docker-install.sh
|
||||||
ENV setupVars /etc/pihole/setupVars.conf
|
ENV setupVars /etc/pihole/setupVars.conf
|
||||||
ENV PIHOLE_INSTALL /tmp/ph_install.sh
|
ENV PIHOLE_INSTALL /tmp/ph_install.sh
|
||||||
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.20.0.0/s6-overlay-armhf.tar.gz
|
ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.21.2.1/s6-overlay-armhf.tar.gz
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y wget curl net-tools cron && \
|
apt-get install -y wget curl net-tools cron && \
|
||||||
|
|
|
@ -276,7 +276,9 @@ test_framework_stubbing() {
|
||||||
if [ -n "$PYTEST" ] ; then
|
if [ -n "$PYTEST" ] ; then
|
||||||
echo ":::::: Tests are being ran - stub out ad list fetching and add a fake ad block"
|
echo ":::::: Tests are being ran - stub out ad list fetching and add a fake ad block"
|
||||||
sed -i 's/^gravity_spinup$/#gravity_spinup # DISABLED FOR PYTEST/g' "$(which gravity.sh)"
|
sed -i 's/^gravity_spinup$/#gravity_spinup # DISABLED FOR PYTEST/g' "$(which gravity.sh)"
|
||||||
echo 'testblock.pi-hole.local' >> /etc/pihole/blacklist.txt
|
echo '123.123.123.123 testblock.pi-hole.local' > /var/www/html/fake.list
|
||||||
|
echo 'file:///var/www/html/fake.list' > /etc/pihole/adlists.list
|
||||||
|
echo 'http://localhost/fake.list' >> /etc/pihole/adlists.list
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
26
install.sh
26
install.sh
|
@ -1,8 +1,9 @@
|
||||||
#!/bin/bash -ex
|
#!/bin/bash -ex
|
||||||
mkdir -p /etc/pihole/
|
mkdir -p /etc/pihole/
|
||||||
export CORE_TAG='v3.1.4'
|
export CORE_TAG='v3.2'
|
||||||
export WEB_TAG='v3.1'
|
export WEB_TAG='v3.2'
|
||||||
export FTL_TAG='v2.11.1'
|
export FTL_TAG='v2.12'
|
||||||
|
export USE_DEVELOPMENT_BRANCHES=false
|
||||||
|
|
||||||
# Make pihole scripts fail searching for `systemctl`,
|
# Make pihole scripts fail searching for `systemctl`,
|
||||||
# which fails pretty miserably in docker compared to `service`
|
# which fails pretty miserably in docker compared to `service`
|
||||||
|
@ -45,7 +46,7 @@ if [[ "$TAG" == 'debian' ]] ; then
|
||||||
# IPv6 support for nc openbsd better than traditional
|
# IPv6 support for nc openbsd better than traditional
|
||||||
apt-get install -y --force-yes netcat-openbsd
|
apt-get install -y --force-yes netcat-openbsd
|
||||||
elif [[ "$TAG" == 'alpine' ]] ; then
|
elif [[ "$TAG" == 'alpine' ]] ; then
|
||||||
apk add \
|
apk add -U \
|
||||||
dnsmasq \
|
dnsmasq \
|
||||||
nginx \
|
nginx \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
|
@ -59,9 +60,18 @@ piholeGitUrl="${piholeGitUrl}"
|
||||||
webInterfaceGitUrl="${webInterfaceGitUrl}"
|
webInterfaceGitUrl="${webInterfaceGitUrl}"
|
||||||
webInterfaceDir="${webInterfaceDir}"
|
webInterfaceDir="${webInterfaceDir}"
|
||||||
git clone "${piholeGitUrl}" "${PI_HOLE_LOCAL_REPO}"
|
git clone "${piholeGitUrl}" "${PI_HOLE_LOCAL_REPO}"
|
||||||
pushd "${PI_HOLE_LOCAL_REPO}"; git reset --hard "${CORE_TAG}"; popd;
|
|
||||||
git clone "${webInterfaceGitUrl}" "${webInterfaceDir}"
|
git clone "${webInterfaceGitUrl}" "${webInterfaceDir}"
|
||||||
pushd "${webInterfaceDir}"; git reset --hard "${WEB_TAG}"; popd;
|
if [[ $USE_DEVELOPMENT_BRANCHES == true ]] ; then
|
||||||
|
pushd "${PI_HOLE_LOCAL_REPO}"; git checkout development; popd;
|
||||||
|
pushd "${webInterfaceDir}"; git checkout devel; popd;
|
||||||
|
else
|
||||||
|
pushd "${PI_HOLE_LOCAL_REPO}";
|
||||||
|
git reset --hard "${CORE_TAG}";
|
||||||
|
# Can be removed once https://github.com/pi-hole/pi-hole/pull/1779 is in a release
|
||||||
|
git checkout 8d721d086cbe4b49665c9e0b1d81499b284776a9 gravity.sh
|
||||||
|
popd;
|
||||||
|
pushd "${webInterfaceDir}"; git reset --hard "${WEB_TAG}"; popd;
|
||||||
|
fi
|
||||||
|
|
||||||
export PIHOLE_INTERFACE=eth0
|
export PIHOLE_INTERFACE=eth0
|
||||||
export IPV4_ADDRESS=0.0.0.0
|
export IPV4_ADDRESS=0.0.0.0
|
||||||
|
@ -70,8 +80,8 @@ export PIHOLE_DNS_1=8.8.8.8
|
||||||
export PIHOLE_DNS_2=8.8.4.4
|
export PIHOLE_DNS_2=8.8.4.4
|
||||||
export QUERY_LOGGING=true
|
export QUERY_LOGGING=true
|
||||||
|
|
||||||
tmpLog="${tmpLog}"
|
tmpLog="/tmp/pihole-install.log"
|
||||||
instalLogLoc="${instalLogLoc}"
|
installLogLoc="${installLogLoc}"
|
||||||
installPihole | tee "${tmpLog}"
|
installPihole | tee "${tmpLog}"
|
||||||
sed -i 's/readonly //g' /opt/pihole/webpage.sh
|
sed -i 's/readonly //g' /opt/pihole/webpage.sh
|
||||||
if [[ "$TAG" == 'alpine' ]] ; then
|
if [[ "$TAG" == 'alpine' ]] ; then
|
||||||
|
|
|
@ -1,235 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
# Pi-hole: A black hole for Internet advertisements
|
|
||||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
|
||||||
# Network-wide ad blocking via your own hardware.
|
|
||||||
#
|
|
||||||
# Whitelists and blacklists domains
|
|
||||||
#
|
|
||||||
# This file is copyright under the latest version of the EUPL.
|
|
||||||
# Please see LICENSE file for your rights under this license.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#globals
|
|
||||||
basename=pihole
|
|
||||||
piholeDir=/etc/${basename}
|
|
||||||
whitelist=${piholeDir}/whitelist.txt
|
|
||||||
blacklist=${piholeDir}/blacklist.txt
|
|
||||||
readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
|
||||||
reload=false
|
|
||||||
addmode=true
|
|
||||||
verbose=true
|
|
||||||
|
|
||||||
domList=()
|
|
||||||
domToRemoveList=()
|
|
||||||
|
|
||||||
listMain=""
|
|
||||||
listAlt=""
|
|
||||||
|
|
||||||
helpFunc() {
|
|
||||||
|
|
||||||
if [[ ${listMain} == ${whitelist} ]]; then
|
|
||||||
letter="w"
|
|
||||||
word="white"
|
|
||||||
else
|
|
||||||
letter="b"
|
|
||||||
word="black"
|
|
||||||
fi
|
|
||||||
|
|
||||||
cat << EOM
|
|
||||||
::: Immediately ${word}lists one or more domains in the hosts file
|
|
||||||
:::
|
|
||||||
::: Usage: pihole -${letter} domain1 [domain2 ...]
|
|
||||||
:::
|
|
||||||
::: Options:
|
|
||||||
::: -d, --delmode Remove domains from the ${word}list
|
|
||||||
::: -nr, --noreload Update ${word}list without refreshing dnsmasq
|
|
||||||
::: -q, --quiet Output is less verbose
|
|
||||||
::: -h, --help Show this help dialog
|
|
||||||
::: -l, --list Display your ${word}listed domains
|
|
||||||
EOM
|
|
||||||
if [[ "${letter}" == "b" ]]; then
|
|
||||||
echo "::: -wild, --wildcard Add wildcard entry (only blacklist)"
|
|
||||||
fi
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
EscapeRegexp() {
|
|
||||||
# This way we may safely insert an arbitrary
|
|
||||||
# string in our regular expressions
|
|
||||||
# Also remove leading "." if present
|
|
||||||
echo $* | sed 's/^\.*//' | sed "s/[]\.|$(){}?+*^]/\\\\&/g" | sed "s/\\//\\\\\//g"
|
|
||||||
}
|
|
||||||
|
|
||||||
HandleOther(){
|
|
||||||
# First, convert everything to lowercase
|
|
||||||
domain=$(sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" <<< "$1")
|
|
||||||
|
|
||||||
#check validity of domain
|
|
||||||
validDomain=$(echo "${domain}" | perl -lne 'print if /(?!.*[^a-z0-9-\.].*)^((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9-]+\.)*[a-z]{2,63}/')
|
|
||||||
if [ -z "${validDomain}" ]; then
|
|
||||||
echo "::: $1 is not a valid argument or domain name"
|
|
||||||
else
|
|
||||||
domList=("${domList[@]}" ${validDomain})
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
PoplistFile() {
|
|
||||||
#check whitelist file exists, and if not, create it
|
|
||||||
if [[ ! -f ${whitelist} ]]; then
|
|
||||||
touch ${whitelist}
|
|
||||||
fi
|
|
||||||
for dom in "${domList[@]}"; do
|
|
||||||
# Logic : If addmode then add to desired list and remove from the other; if delmode then remove from desired list but do not add to the other
|
|
||||||
if ${addmode}; then
|
|
||||||
AddDomain "${dom}" "${listMain}"
|
|
||||||
RemoveDomain "${dom}" "${listAlt}"
|
|
||||||
if [[ "${listMain}" == "${whitelist}" || "${listMain}" == "${blacklist}" ]]; then
|
|
||||||
RemoveDomain "${dom}" "${wildcardlist}"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
RemoveDomain "${dom}" "${listMain}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
AddDomain() {
|
|
||||||
list="$2"
|
|
||||||
domain=$(EscapeRegexp "$1")
|
|
||||||
|
|
||||||
if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then
|
|
||||||
|
|
||||||
bool=true
|
|
||||||
#Is the domain in the list we want to add it to?
|
|
||||||
grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false
|
|
||||||
|
|
||||||
if [[ "${bool}" == false ]]; then
|
|
||||||
#domain not found in the whitelist file, add it!
|
|
||||||
if [[ "${verbose}" == true ]]; then
|
|
||||||
echo "::: Adding $1 to $list..."
|
|
||||||
fi
|
|
||||||
reload=true
|
|
||||||
# Add it to the list we want to add it to
|
|
||||||
echo "$1" >> "${list}"
|
|
||||||
else
|
|
||||||
if [[ "${verbose}" == true ]]; then
|
|
||||||
echo "::: ${1} already exists in ${list}, no need to add!"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif [[ "${list}" == "${wildcardlist}" ]]; then
|
|
||||||
|
|
||||||
source "${piholeDir}/setupVars.conf"
|
|
||||||
#Remove the /* from the end of the IPv4addr.
|
|
||||||
IPV4_ADDRESS=${IPV4_ADDRESS%/*}
|
|
||||||
IPV6_ADDRESS=${IPV6_ADDRESS}
|
|
||||||
|
|
||||||
bool=true
|
|
||||||
#Is the domain in the list?
|
|
||||||
grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false
|
|
||||||
|
|
||||||
if [[ "${bool}" == false ]]; then
|
|
||||||
if [[ "${verbose}" == true ]]; then
|
|
||||||
echo "::: Adding $1 to wildcard blacklist..."
|
|
||||||
fi
|
|
||||||
reload=true
|
|
||||||
echo "address=/$1/${IPV4_ADDRESS}" >> "${wildcardlist}"
|
|
||||||
if [[ ${#IPV6_ADDRESS} > 0 ]] ; then
|
|
||||||
echo "address=/$1/${IPV6_ADDRESS}" >> "${wildcardlist}"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [[ "${verbose}" == true ]]; then
|
|
||||||
echo "::: ${1} already exists in wildcard blacklist, no need to add!"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
RemoveDomain() {
|
|
||||||
list="$2"
|
|
||||||
domain=$(EscapeRegexp "$1")
|
|
||||||
|
|
||||||
if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then
|
|
||||||
|
|
||||||
bool=true
|
|
||||||
#Is it in the list? Logic follows that if its whitelisted it should not be blacklisted and vice versa
|
|
||||||
grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false
|
|
||||||
if [[ "${bool}" == true ]]; then
|
|
||||||
# Remove it from the other one
|
|
||||||
echo "::: Removing $1 from $list..."
|
|
||||||
# Busybox sed compatible case-insensitive domain removal
|
|
||||||
sed -i "$(grep -in "^${domain}$" ${list} | awk -F':' '{print $1}' | tr '\n' ',' | sed 's/,$/\n/')d" ${list}
|
|
||||||
reload=true
|
|
||||||
else
|
|
||||||
if [[ "${verbose}" == true ]]; then
|
|
||||||
echo "::: ${1} does not exist in ${list}, no need to remove!"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif [[ "${list}" == "${wildcardlist}" ]]; then
|
|
||||||
|
|
||||||
bool=true
|
|
||||||
#Is it in the list?
|
|
||||||
grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false
|
|
||||||
if [[ "${bool}" == true ]]; then
|
|
||||||
# Remove it from the other one
|
|
||||||
echo "::: Removing $1 from $list..."
|
|
||||||
# Busybox sed compatible case-insensitive domain removal
|
|
||||||
sed -i "$(grep -in "/${domain}/" ${list} | awk -F':' '{print $1}' | tr '\n' ',' | sed 's/,$/\n/')d" ${list}
|
|
||||||
reload=true
|
|
||||||
else
|
|
||||||
if [[ "${verbose}" == true ]]; then
|
|
||||||
echo "::: ${1} does not exist in ${list}, no need to remove!"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
Reload() {
|
|
||||||
# Reload hosts file
|
|
||||||
pihole -g -sd
|
|
||||||
}
|
|
||||||
|
|
||||||
Displaylist() {
|
|
||||||
if [[ ${listMain} == ${whitelist} ]]; then
|
|
||||||
string="gravity resistant domains"
|
|
||||||
else
|
|
||||||
string="domains caught in the sinkhole"
|
|
||||||
fi
|
|
||||||
verbose=false
|
|
||||||
echo -e " Displaying $string \n"
|
|
||||||
count=1
|
|
||||||
while IFS= read -r RD; do
|
|
||||||
echo "${count}: ${RD}"
|
|
||||||
count=$((count+1))
|
|
||||||
done < "${listMain}"
|
|
||||||
exit 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for var in "$@"; do
|
|
||||||
case "${var}" in
|
|
||||||
"-w" | "whitelist" ) listMain="${whitelist}"; listAlt="${blacklist}";;
|
|
||||||
"-b" | "blacklist" ) listMain="${blacklist}"; listAlt="${whitelist}";;
|
|
||||||
"-wild" | "wildcard" ) listMain="${wildcardlist}";;
|
|
||||||
"-nr"| "--noreload" ) reload=false;;
|
|
||||||
"-d" | "--delmode" ) addmode=false;;
|
|
||||||
"-f" | "--force" ) force=true;;
|
|
||||||
"-q" | "--quiet" ) verbose=false;;
|
|
||||||
"-h" | "--help" ) helpFunc;;
|
|
||||||
"-l" | "--list" ) Displaylist;;
|
|
||||||
* ) HandleOther "${var}";;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
shift
|
|
||||||
|
|
||||||
if [[ $# = 0 ]]; then
|
|
||||||
helpFunc
|
|
||||||
fi
|
|
||||||
|
|
||||||
PoplistFile
|
|
||||||
|
|
||||||
if ${reload}; then
|
|
||||||
Reload
|
|
||||||
fi
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ check_output = testinfra.get_backend(
|
||||||
def DockerGeneric(request, args, image, cmd):
|
def DockerGeneric(request, args, image, cmd):
|
||||||
assert 'docker' in check_output('id'), "Are you in the docker group?"
|
assert 'docker' in check_output('id'), "Are you in the docker group?"
|
||||||
if 'pi-hole' in image:
|
if 'pi-hole' in image:
|
||||||
args += " --dns 127.0.0.1 -v /dev/null:/etc/.pihole/adlists.default -e PYTEST=\"True\""
|
args += " --dns 127.0.0.1 -v /dev/null:/etc/pihole/adlists.default -e PYTEST=\"True\""
|
||||||
docker_run = "docker run -d {} {} {}".format(args, image, cmd)
|
docker_run = "docker run -d {} {} {}".format(args, image, cmd)
|
||||||
print docker_run
|
print docker_run
|
||||||
docker_id = check_output(docker_run)
|
docker_id = check_output(docker_run)
|
||||||
|
|
|
@ -10,6 +10,7 @@ def RunningPiHole(DockerPersist, Slow, persist_webserver, persist_tag, start_cmd
|
||||||
''' Override the RunningPiHole to run and check for success of a
|
''' Override the RunningPiHole to run and check for success of a
|
||||||
dnsmasq start based `pihole` script command '''
|
dnsmasq start based `pihole` script command '''
|
||||||
#print DockerPersist.run('ps -ef').stdout
|
#print DockerPersist.run('ps -ef').stdout
|
||||||
|
assert DockerPersist.dig.run('ping -c 1 test_pihole').rc == 0
|
||||||
Slow(lambda: DockerPersist.run('pgrep dnsmasq').rc == 0)
|
Slow(lambda: DockerPersist.run('pgrep dnsmasq').rc == 0)
|
||||||
Slow(lambda: DockerPersist.run('pgrep {}'.format(persist_webserver)).rc == 0)
|
Slow(lambda: DockerPersist.run('pgrep {}'.format(persist_webserver)).rc == 0)
|
||||||
oldpid = DockerPersist.run('pidof dnsmasq')
|
oldpid = DockerPersist.run('pidof dnsmasq')
|
||||||
|
@ -30,15 +31,17 @@ def test_pihole_start_cmd(RunningPiHole, start_cmd, persist_tag):
|
||||||
''' the start_cmd tests are all built into the RunningPiHole fixture in this file '''
|
''' the start_cmd tests are all built into the RunningPiHole fixture in this file '''
|
||||||
assert RunningPiHole.cmd.stdout == START_DNS_STDOUT[persist_tag]
|
assert RunningPiHole.cmd.stdout == START_DNS_STDOUT[persist_tag]
|
||||||
|
|
||||||
@pytest.mark.parametrize('start_cmd,hostname,expected_ip, expected_message', [
|
@pytest.mark.parametrize('start_cmd,hostname,expected_ip, expected_messages', [
|
||||||
('enable', 'pi.hole', '127.0.0.1', 'enabled'),
|
('enable', 'pi.hole', '127.0.0.1', ['Enabling blocking','Pi-hole Enabled']),
|
||||||
('disable 0', 'pi.hole', '127.0.0.1', 'disabled'),
|
('disable', 'pi.hole', '127.0.0.1', ['Disabling blocking','Pi-hole Disabled']),
|
||||||
])
|
])
|
||||||
def test_pihole_start_cmd(RunningPiHole, Dig, persist_tag, start_cmd, hostname, expected_ip, expected_message):
|
def test_pihole_start_cmd(RunningPiHole, Dig, persist_tag, start_cmd, hostname, expected_ip, expected_messages):
|
||||||
''' the start_cmd tests are all built into the RunningPiHole fixture in this file '''
|
''' the start_cmd tests are all built into the RunningPiHole fixture in this file '''
|
||||||
dig_cmd = "dig +time=1 +noall +answer {} @test_pihole | awk '{{ print $5 }}'".format(hostname)
|
dig_cmd = "dig +time=1 +noall +answer {} @test_pihole".format(hostname)
|
||||||
lookup = RunningPiHole.dig.run(dig_cmd).stdout.rstrip('\n')
|
lookup = RunningPiHole.dig.run(dig_cmd)
|
||||||
assert lookup == expected_ip
|
assert lookup.rc == 0
|
||||||
|
lookup_ip = lookup.stdout.split()[4]
|
||||||
|
assert lookup_ip == expected_ip
|
||||||
|
|
||||||
stdout = "::: Blocking has been {}!\n".format(expected_message)
|
for part_of_output in expected_messages:
|
||||||
assert stdout in RunningPiHole.cmd.stdout
|
assert part_of_output in RunningPiHole.cmd.stdout
|
||||||
|
|
|
@ -56,7 +56,7 @@ def test_html_index_requests_load_as_expected(RunningPiHole, Slow, addr, url):
|
||||||
assert http_rc.rc == 0
|
assert http_rc.rc == 0
|
||||||
assert int(http_rc.stdout) == 200
|
assert int(http_rc.stdout) == 200
|
||||||
page_contents = RunningPiHole.run('cat /tmp/curled_file ').stdout
|
page_contents = RunningPiHole.run('cat /tmp/curled_file ').stdout
|
||||||
assert 'blocked' in page_contents
|
assert 'testblock.pi-hole.local' in page_contents
|
||||||
|
|
||||||
@pytest.mark.parametrize('addr', [ 'testblock.pi-hole.local' ])
|
@pytest.mark.parametrize('addr', [ 'testblock.pi-hole.local' ])
|
||||||
@pytest.mark.parametrize('url', [ '/index.js', '/any.js'] )
|
@pytest.mark.parametrize('url', [ '/index.js', '/any.js'] )
|
||||||
|
@ -65,7 +65,7 @@ def test_javascript_requests_load_as_expected(RunningPiHole, addr, url):
|
||||||
http_rc = RunningPiHole.run(command)
|
http_rc = RunningPiHole.run(command)
|
||||||
assert http_rc.rc == 0
|
assert http_rc.rc == 0
|
||||||
assert int(http_rc.stdout) == 200
|
assert int(http_rc.stdout) == 200
|
||||||
assert RunningPiHole.run('md5sum /tmp/curled_file /var/www/html/pihole/index.js').rc == 0
|
assert 'var x = "Pi-hole: A black hole for Internet advertisements."' in RunningPiHole.run('cat /tmp/curled_file').stdout
|
||||||
|
|
||||||
# IPv6 checks aren't passing CORS, removed :(
|
# IPv6 checks aren't passing CORS, removed :(
|
||||||
@pytest.mark.parametrize('addr', [ 'localhost' ] )
|
@pytest.mark.parametrize('addr', [ 'localhost' ] )
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -5,5 +5,5 @@ envlist = py27
|
||||||
whitelist_externals = docker
|
whitelist_externals = docker
|
||||||
deps = -rrequirements.txt
|
deps = -rrequirements.txt
|
||||||
commands = docker run --rm --privileged multiarch/qemu-user-static:register --reset
|
commands = docker run --rm --privileged multiarch/qemu-user-static:register --reset
|
||||||
./Dockerfile.py
|
./Dockerfile.py -v
|
||||||
pytest {posargs:-vv -n auto} ./test/
|
pytest {posargs:-vv -n auto} ./test/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user