mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-04-19 05:40:13 +00:00
Merge branch 'master' into auto-chronometer-lcd-setup
This commit is contained in:
commit
f0e5b2b6f9
20 changed files with 1496 additions and 429 deletions
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
# (c) 2015 by Jacob Salmela
|
||||
# This file is part of Pi-hole.
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2015, 2016 by Jacob Salmela
|
||||
# Network-wide ad blocking via your Raspberry Pi
|
||||
# http://pi-hole.net
|
||||
# Blacklists domains
|
||||
#
|
||||
# Pi-hole is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -81,13 +84,14 @@ function AddDomain(){
|
|||
if $bool; then
|
||||
#domain not found in the blacklist file, add it!
|
||||
if $versbose; then
|
||||
echo "** Adding $1 to blacklist file"
|
||||
echo -n "::: Adding $1 to blacklist file..."
|
||||
fi
|
||||
echo $1 >> $blacklist
|
||||
modifyHost=true
|
||||
echo " done!"
|
||||
else
|
||||
if $versbose; then
|
||||
echo "** $1 already blacklisted! No need to add"
|
||||
echo "::: $1 already exists in blacklist.txt! No need to add"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -99,12 +103,12 @@ function RemoveDomain(){
|
|||
if $bool; then
|
||||
#Domain is not in the blacklist file, no need to Remove
|
||||
if $versbose; then
|
||||
echo "** $1 is NOT blacklisted! No need to remove"
|
||||
echo "::: $1 is NOT blacklisted! No need to remove"
|
||||
fi
|
||||
else
|
||||
#Domain is in the blacklist file, add to a temporary array
|
||||
if $versbose; then
|
||||
echo "** Un-blacklisting $dom..."
|
||||
echo "::: Un-blacklisting $dom..."
|
||||
fi
|
||||
domToRemoveList=("${domToRemoveList[@]}" $1)
|
||||
modifyHost=true
|
||||
|
@ -117,7 +121,8 @@ function ModifyHostFile(){
|
|||
if [[ -r $blacklist ]];then
|
||||
numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l)
|
||||
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||
echo "** blacklisting a total of $numberOf domain${plural}..."
|
||||
echo ":::"
|
||||
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
|
||||
if [[ -n $piholeIPv6 ]];then
|
||||
cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList
|
||||
else
|
||||
|
@ -126,12 +131,18 @@ function ModifyHostFile(){
|
|||
|
||||
fi
|
||||
else
|
||||
|
||||
|
||||
echo ":::"
|
||||
for dom in "${domToRemoveList[@]}"
|
||||
do
|
||||
#we need to remove the domains from the blacklist file and the host file
|
||||
echo "::: $dom"
|
||||
echo -n "::: removing from HOSTS file..."
|
||||
echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList
|
||||
echo " done!"
|
||||
echo -n "::: removing from blackist.txt..."
|
||||
echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist
|
||||
echo " done!"
|
||||
done
|
||||
fi
|
||||
|
||||
|
@ -139,7 +150,8 @@ function ModifyHostFile(){
|
|||
|
||||
function Reload() {
|
||||
# Reload hosts file
|
||||
echo "** Refresh lists in dnsmasq..."
|
||||
echo ":::"
|
||||
echo -n "::: Refresh lists in dnsmasq..."
|
||||
|
||||
dnsmasqPid=$(pidof dnsmasq)
|
||||
|
||||
|
@ -150,6 +162,7 @@ function Reload() {
|
|||
# service not running, start it up
|
||||
sudo service dnsmasq start
|
||||
fi
|
||||
echo " done!"
|
||||
}
|
||||
|
||||
###################################################
|
||||
|
@ -167,12 +180,11 @@ done
|
|||
|
||||
PopBlacklistFile
|
||||
|
||||
if $modifyHost || $force; then
|
||||
echo "** Modifying Hosts File"
|
||||
if $modifyHost || $force; then
|
||||
ModifyHostFile
|
||||
else
|
||||
if $versbose; then
|
||||
echo "** No changes need to be made"
|
||||
echo "::: No changes need to be made"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
# (c) 2015 by Jacob Salmela
|
||||
# This file is part of Pi-hole.
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2015, 2016 by Jacob Salmela
|
||||
# Network-wide ad blocking via your Raspberry Pi
|
||||
# http://pi-hole.net
|
||||
# Calculates stats and displays to an LCD
|
||||
#
|
||||
# Pi-hole is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -48,9 +51,13 @@ function CalcblockedToday(){
|
|||
|
||||
function CalcPercentBlockedToday(){
|
||||
if [ "$queriesToday" != "Err." ] && [ "$blockedToday" != "Err." ]; then
|
||||
#scale 2 rounds the number down, so we'll do scale 4 and then trim the last 2 zeros
|
||||
percentBlockedToday=$(echo "scale=4; $blockedToday/$queriesToday*100" | bc)
|
||||
percentBlockedToday=$(sed 's/.\{2\}$//' <<< "$percentBlockedToday")
|
||||
if [ "$queriesToday" != 0 ]; then #Fixes divide by zero error :)
|
||||
#scale 2 rounds the number down, so we'll do scale 4 and then trim the last 2 zeros
|
||||
percentBlockedToday=$(echo "scale=4; $blockedToday/$queriesToday*100" | bc)
|
||||
percentBlockedToday=$(sed 's/.\{2\}$//' <<< "$percentBlockedToday")
|
||||
else
|
||||
percentBlockedToday=0
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2015, 2016 by Jacob Salmela
|
||||
# Network-wide ad blocking via your Raspberry Pi
|
||||
# http://pi-hole.net
|
||||
# Flushes /var/log/pihole.log
|
||||
# (c) 2015 by Jacob Salmela
|
||||
# This file is part of Pi-hole.
|
||||
#
|
||||
#Pi-hole is free software: you can redistribute it and/or modify
|
||||
#it under the terms of the GNU General Public License as published by
|
||||
#the Free Software Foundation, either version 2 of the License, or
|
||||
#(at your option) any later version.
|
||||
# Pi-hole is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
truncate -s 0 /var/log/pihole.log
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2015, 2016 by Jacob Salmela
|
||||
# Network-wide ad blocking via your Raspberry Pi
|
||||
# http://pi-hole.net
|
||||
# Updates the Pi-hole web interface
|
||||
#
|
||||
# this script will update the pihole web interface files.
|
||||
#
|
||||
# if this is the first time running this script after an
|
||||
# existing installation, the existing web interface files
|
||||
# will be removed and replaced with the latest master
|
||||
# branch from github. subsequent executions of this script
|
||||
# will pull the latest version of the web interface.
|
||||
#
|
||||
# @TODO: add git as requirement to basic-install.sh
|
||||
#
|
||||
# Pi-hole is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
WEB_INTERFACE_GIT_URL="https://github.com/jacobsalmela/AdminLTE.git"
|
||||
WEB_INTERFACE_GIT_URL="https://github.com/pi-hole/AdminLTE.git"
|
||||
WEB_INTERFACE_DIR="/var/www/html/admin"
|
||||
|
||||
main() {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
# (c) 2015 by Jacob Salmela
|
||||
# This file is part of Pi-hole.
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2015, 2016 by Jacob Salmela
|
||||
# Network-wide ad blocking via your Raspberry Pi
|
||||
# http://pi-hole.net
|
||||
# Whitelists domains
|
||||
#
|
||||
# Pi-hole is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -52,7 +55,7 @@ function HandleOther(){
|
|||
validDomain=$(echo $1 | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/')
|
||||
|
||||
if [ -z "$validDomain" ]; then
|
||||
echo $1 is not a valid argument or domain name
|
||||
echo "::: $1 is not a valid argument or domain name"
|
||||
else
|
||||
domList=("${domList[@]}" $validDomain)
|
||||
fi
|
||||
|
@ -76,17 +79,21 @@ function PopWhitelistFile(){
|
|||
function AddDomain(){
|
||||
#| sed 's/\./\\./g'
|
||||
bool=false
|
||||
|
||||
grep -Ex -q "$1" $whitelist || bool=true
|
||||
if $bool; then
|
||||
#domain not found in the whitelist file, add it!
|
||||
if $versbose; then
|
||||
echo "** Adding $1 to whitelist file"
|
||||
echo -n "::: Adding $1 to whitelist.txt..."
|
||||
fi
|
||||
echo $1 >> $whitelist
|
||||
echo $1 >> $whitelist
|
||||
modifyHost=true
|
||||
if $versbose; then
|
||||
echo " done!"
|
||||
fi
|
||||
else
|
||||
if $versbose; then
|
||||
echo "** $1 already whitelisted! No need to add"
|
||||
echo "::: $1 already exists in whitelist.txt, no need to add!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -98,13 +105,13 @@ function RemoveDomain(){
|
|||
if $bool; then
|
||||
#Domain is not in the whitelist file, no need to Remove
|
||||
if $versbose; then
|
||||
echo "** $1 is NOT whitelisted! No need to remove"
|
||||
echo "::: $1 is NOT whitelisted! No need to remove"
|
||||
fi
|
||||
else
|
||||
#Domain is in the whitelist file, add to a temporary array and remove from whitelist file
|
||||
if $versbose; then
|
||||
echo "** Un-whitelisting $dom..."
|
||||
fi
|
||||
#if $versbose; then
|
||||
#echo "::: Un-whitelisting $dom..."
|
||||
#fi
|
||||
domToRemoveList=("${domToRemoveList[@]}" $1)
|
||||
modifyHost=true
|
||||
fi
|
||||
|
@ -115,30 +122,46 @@ function ModifyHostFile(){
|
|||
#remove domains in from hosts file
|
||||
if [[ -r $whitelist ]];then
|
||||
# Remove whitelist entries
|
||||
numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l)
|
||||
numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l)
|
||||
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||
echo "** Whitelisting a total of $numberOf domain${plural}..."
|
||||
awk -F':' '{ print $1 }' $whitelist | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList
|
||||
echo ":::"
|
||||
echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."
|
||||
awk -F':' '{print $1}' $whitelist | while read line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp
|
||||
awk -F':' '{print $1}' $whitelist | while read line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp
|
||||
echo "l" >> /etc/pihole/whitelist.tmp
|
||||
grep -F -x -v -f /etc/pihole/whitelist.tmp /etc/pihole/gravity.list > /etc/pihole/gravity.tmp
|
||||
rm /etc/pihole/gravity.list
|
||||
mv /etc/pihole/gravity.tmp /etc/pihole/gravity.list
|
||||
rm /etc/pihole/whitelist.tmp
|
||||
echo " done!"
|
||||
|
||||
fi
|
||||
else
|
||||
#we need to add the removed domains to the hosts file
|
||||
echo ":::"
|
||||
echo "::: Modifying HOSTS file to un-whitelist domains..."
|
||||
for rdom in "${domToRemoveList[@]}"
|
||||
do
|
||||
do
|
||||
if [[ -n $piholeIPv6 ]];then
|
||||
echo "**Blacklisting $rdom on IPv4 and IPv6"
|
||||
echo -n "::: Un-whitelisting $rdom on IPv4 and IPv6..."
|
||||
echo $rdom | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList
|
||||
echo " done!"
|
||||
else
|
||||
echo "**Blacklisting $rdom on IPv4"
|
||||
echo -n "::: Un-whitelisting $rdom on IPv4"
|
||||
echo $rdom | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList
|
||||
fi
|
||||
echo " done!"
|
||||
fi
|
||||
echo -n "::: Removing $rdom from whitelist.txt..."
|
||||
echo $rdom| sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist
|
||||
echo " done!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function Reload() {
|
||||
# Reload hosts file
|
||||
echo "** Refresh lists in dnsmasq..."
|
||||
echo ":::"
|
||||
echo -n "::: Refresh lists in dnsmasq..."
|
||||
dnsmasqPid=$(pidof dnsmasq)
|
||||
|
||||
if [[ $dnsmasqPid ]]; then
|
||||
|
@ -148,6 +171,7 @@ function Reload() {
|
|||
# service not running, start it up
|
||||
sudo service dnsmasq start
|
||||
fi
|
||||
echo " done!"
|
||||
}
|
||||
|
||||
###################################################
|
||||
|
@ -166,11 +190,11 @@ done
|
|||
PopWhitelistFile
|
||||
|
||||
if $modifyHost || $force; then
|
||||
echo "** Modifying Hosts File"
|
||||
ModifyHostFile
|
||||
ModifyHostFile
|
||||
else
|
||||
if $versbose; then
|
||||
echo "** No changes need to be made"
|
||||
echo ":::"
|
||||
echo "::: No changes need to be made"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue