Merge branch 'development' of https://github.com/pi-hole/pi-hole into alpine_support

This commit is contained in:
Eric Warnke 2016-10-28 13:18:18 -04:00
commit 1e9cb37d63
6 changed files with 55 additions and 16 deletions

3
.codeclimate.yml Normal file
View file

@ -0,0 +1,3 @@
engines:
shellcheck:
enabled: true

View file

@ -20,6 +20,12 @@
# OR IN /etc/dnsmasq.conf # # OR IN /etc/dnsmasq.conf #
############################################################################### ###############################################################################
address=/pi.hole/@IPv4@
address=/pi.hole/@IPv6@
address=/@HOSTNAME@/@IPv4@
address=/@HOSTNAME@/@IPv6@
addn-hosts=/etc/pihole/gravity.list addn-hosts=/etc/pihole/gravity.list
domain-needed domain-needed
@ -33,8 +39,6 @@ server=@DNS2@
interface=@INT@ interface=@INT@
listen-address=127.0.0.1
cache-size=10000 cache-size=10000
log-queries log-queries

View file

@ -12,6 +12,7 @@
server.modules = ( server.modules = (
"mod_access", "mod_access",
"mod_accesslog", "mod_accesslog",
"mod_auth",
"mod_expire", "mod_expire",
"mod_compress", "mod_compress",
"mod_redirect", "mod_redirect",
@ -60,3 +61,6 @@ $HTTP["url"] =~ "^(?!/admin)/.*" {
# Create a response header for debugging using curl -I # Create a response header for debugging using curl -I
setenv.add-response-header = ( "X-Pi-hole" => "A black hole for Internet advertisements." ) setenv.add-response-header = ( "X-Pi-hole" => "A black hole for Internet advertisements." )
} }
# Add user chosen options held in external file
include_shell "cat external.conf 2>/dev/null"

View file

@ -11,6 +11,7 @@
server.modules = ( server.modules = (
"mod_access", "mod_access",
"mod_auth",
"mod_fastcgi", "mod_fastcgi",
"mod_accesslog", "mod_accesslog",
"mod_expire", "mod_expire",
@ -77,3 +78,6 @@ $HTTP["url"] =~ "^(?!/admin)/.*" {
# Create a response header for debugging using curl -I # Create a response header for debugging using curl -I
setenv.add-response-header = ( "X-Pi-hole" => "A black hole for Internet advertisements." ) setenv.add-response-header = ( "X-Pi-hole" => "A black hole for Internet advertisements." )
} }
# Add user chosen options held in external file
include_shell "cat external.conf 2>/dev/null"

View file

@ -555,6 +555,37 @@ version_check_dnsmasq() {
else else
sed -i '/^server=@DNS2@/d' ${dnsmasq_pihole_01_location} sed -i '/^server=@DNS2@/d' ${dnsmasq_pihole_01_location}
fi fi
#sed -i "s/@HOSTNAME@/$hostname/" ${dnsmasq_pihole_01_location}
if [[ -f /etc/hostname ]]; then
hostname=$(</etc/hostname)
elif [ -x "$(command -v hostname)" ]; then
hostname=$(hostname -f)
fi
#Replace IPv4 and IPv6 tokens in 01-pihole.conf for pi.hole resolution.
if [[ "${IPv4_address}" != "" ]]; then
tmp=${IPv4_address%/*}
sed -i "s/@IPv4@/$tmp/" ${dnsmasq_pihole_01_location}
else
sed -i '/^address=\/pi.hole\/@IPv4@/d' ${dnsmasq_pihole_01_location}
sed -i '/^address=\/@HOSTNAME@\/@IPv4@/d' ${dnsmasq_pihole_01_location}
fi
if [[ "${IPv6_address}" != "" ]]; then
sed -i "s/@IPv6@/$IPv6_address/" ${dnsmasq_pihole_01_location}
else
sed -i '/^address=\/pi.hole\/@IPv6@/d' ${dnsmasq_pihole_01_location}
sed -i '/^address=\/@HOSTNAME@\/@IPv6@/d' ${dnsmasq_pihole_01_location}
fi
if [[ "${hostname}" != "" ]]; then
sed -i "s/@HOSTNAME@/$hostname/" ${dnsmasq_pihole_01_location}
else
sed -i '/^address=\/@HOSTNAME@*/d' ${dnsmasq_pihole_01_location}
fi
sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${dnsmasq_conf} sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${dnsmasq_conf}
} }
@ -580,6 +611,7 @@ installScripts() {
install -o "${USER}" -Dm755 -t /opt/pihole/ gravity.sh install -o "${USER}" -Dm755 -t /opt/pihole/ gravity.sh
install -o "${USER}" -Dm755 -t /opt/pihole/ ./advanced/Scripts/*.sh install -o "${USER}" -Dm755 -t /opt/pihole/ ./advanced/Scripts/*.sh
install -o "${USER}" -Dm755 -t /opt/pihole/ ./automated\ install/uninstall.sh
install -o "${USER}" -Dm755 -t /usr/local/bin/ pihole install -o "${USER}" -Dm755 -t /usr/local/bin/ pihole
install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole
@ -601,6 +633,8 @@ installConfigs() {
chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd
mkdir -p /var/cache/lighttpd/compress mkdir -p /var/cache/lighttpd/compress
chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress
mkdir -p /var/cache/lighttpd/uploads
chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/uploads
} }
stop_service() { stop_service() {

View file

@ -29,8 +29,7 @@ EOM
adListFile=/etc/pihole/adlists.list adListFile=/etc/pihole/adlists.list
adListDefault=/etc/pihole/adlists.default adListDefault=/etc/pihole/adlists.default
whitelistScript=/opt/pihole/whitelist.sh whitelistScript="pihole -w"
blacklistScript=/opt/pihole/blacklist.sh
whitelistFile=/etc/pihole/whitelist.txt whitelistFile=/etc/pihole/whitelist.txt
blacklistFile=/etc/pihole/blacklist.txt blacklistFile=/etc/pihole/blacklist.txt
@ -186,7 +185,7 @@ gravity_Schwarzchild() {
} }
gravity_Blacklist() { gravity_Blacklist() {
# Append blacklist entries if they exist # Append blacklist entries to eventHorizon if they exist
if [[ -f "${blacklistFile}" ]]; then if [[ -f "${blacklistFile}" ]]; then
numBlacklisted=$(wc -l < "${blacklistFile}") numBlacklisted=$(wc -l < "${blacklistFile}")
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
@ -216,11 +215,13 @@ gravity_Whitelist() {
# Ensure adlist domains are in whitelist.txt # Ensure adlist domains are in whitelist.txt
${whitelistScript} -nr -q "${urls[@]}" > /dev/null ${whitelistScript} -nr -q "${urls[@]}" > /dev/null
# Check whitelist.txt exists.
if [[ -f "${whitelistFile}" ]]; then if [[ -f "${whitelistFile}" ]]; then
# Remove anything in whitelist.txt from the Event Horizon # Remove anything in whitelist.txt from the Event Horizon
numWhitelisted=$(wc -l < "${whitelistFile}") numWhitelisted=$(wc -l < "${whitelistFile}")
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
echo -n "::: Whitelisting $numWhitelisted domain${plural}..." echo -n "::: Whitelisting $numWhitelisted domain${plural}..."
#print everything from preEventHorizon into eventHorizon EXCEPT domains in whitelist.txt
grep -F -x -v -f ${whitelistFile} ${piholeDir}/${preEventHorizon} > ${piholeDir}/${eventHorizon} grep -F -x -v -f ${whitelistFile} ${piholeDir}/${preEventHorizon} > ${piholeDir}/${eventHorizon}
echo " done!" echo " done!"
else else
@ -240,31 +241,20 @@ gravity_unique() {
gravity_hostFormat() { gravity_hostFormat() {
# Format domain list as "192.168.x.x domain.com" # Format domain list as "192.168.x.x domain.com"
echo "::: Formatting domains into a HOSTS file..." echo "::: Formatting domains into a HOSTS file..."
if [[ -f /etc/hostname ]]; then
hostname=$(</etc/hostname)
elif [ -x "$(command -v hostname)" ]; then
hostname=$(hostname -f)
else
echo "::: Error: Unable to determine fully qualified domain name of host"
fi
# Check vars from setupVars.conf to see if we're using IPv4, IPv6, Or both. # Check vars from setupVars.conf to see if we're using IPv4, IPv6, Or both.
if [[ -n "${IPv4_address}" && -n "${IPv6_address}" ]];then if [[ -n "${IPv4_address}" && -n "${IPv6_address}" ]];then
# Both IPv4 and IPv6 # Both IPv4 and IPv6
echo -e "$IPv4_address $hostname\n$IPv6_address $hostname\n$IPv4_address pi.hole\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc}
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc}
elif [[ -n "${IPv4_address}" && -z "${IPv6_address}" ]];then elif [[ -n "${IPv4_address}" && -z "${IPv6_address}" ]];then
# Only IPv4 # Only IPv4
echo -e "$IPv4_address $hostname\n$IPv4_address pi.hole" > ${piholeDir}/${accretionDisc}
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc}
elif [[ -z "${IPv4_address}" && -n "${IPv6_address}" ]];then elif [[ -z "${IPv4_address}" && -n "${IPv6_address}" ]];then
# Only IPv6 # Only IPv6
echo -e "$IPv6_address $hostname\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc}
cat ${piholeDir}/${eventHorizon} | awk -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} cat ${piholeDir}/${eventHorizon} | awk -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc}
elif [[ -z "${IPv4_address}" && -z "${IPv6_address}" ]];then elif [[ -z "${IPv4_address}" && -z "${IPv6_address}" ]];then