diff --git a/.pullapprove.yml b/.pullapprove.yml new file mode 100644 index 00000000..ae786ecf --- /dev/null +++ b/.pullapprove.yml @@ -0,0 +1,14 @@ +approve_by_comment: true +approve_regex: '^(Approved|:shipit:|:\+1:)' +reject_regex: '^(Rejected|:-1:)' +reset_on_push: true +author_approval: required +reviewers: + members: + - brantje + - dschaper + - jacobsalmela + - Mcat12 + - PromoFaux + name: pullapprove + required: 3 diff --git a/README.md b/README.md index deea666e..09de0d03 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,65 @@ -# Automated Install -##### Designed For Raspberry Pi A+, B, B+, 2, Zero, and 3B (with an Ethernet/Wi-Fi adapter) (Works on most Debian distributions!) +[![Bountysource](https://www.bountysource.com/badge/tracker?tracker_id=3011939)](https://www.bountysource.com/trackers/3011939-pi-hole-pi-hole?utm_source=3011939&utm_medium=shield&utm_campaign=TRACKER_BADGE) -1. Install Raspbian +# Automated Install -2. Run the command below (downloads [this script](https://github.com/pi-hole/pi-hole/blob/master/automated%20install/basic-install.sh) in case you want to read over it first!) +Designed For Raspberry Pi A+, B, B+, 2, 3B, and Zero (with an Ethernet/Wi-Fi adapter) +Works on most Debian and CentOS/RHEL based distributions! -### ```curl -L https://install.pi-hole.net | bash``` +1. Install Raspbian +2. Run the command below (downloads [this script](https://github.com/pi-hole/pi-hole/blob/master/automated%20install/basic-install.sh) in case you want to read over it first!) -#### Alternative Semi-Automated install #### -``` +## `curl -L https://install.pi-hole.net | bash` + +### Alternative Semi-Automated install + +```bash wget -O basic-install.sh https://install.pi-hole.net chmod +x basic-install.sh ./basic-install.sh ``` + If you wish to read over the script before running it, then after the `wget` command, do `nano basic-install.sh` to open a text viewer - -Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](http://pi-hole.net/faq/can-i-set-the-pi-hole-to-be-the-dns-server-at-my-router-so-i-dont-have-to-change-settings-for-my-devices/) and then any device that connects to your network will have ads blocked without any further configuration. Alternatively, you can manually set each device to [use the Raspberry Pi as its DNS server](http://pi-hole.net/faq/how-do-i-use-the-pi-hole-as-my-dns-server/). +Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](http://pi-hole.net/faq/can-i-set-the-pi-hole-to-be-the-dns-server-at-my-router-so-i-dont-have-to-change-settings-for-my-devices/) and then any device that connects to your network will have ads blocked without any further configuration. Alternatively, you can manually set each device to [use the Raspberry Pi as its DNS server](http://pi-hole.net/faq/how-do-i-use-the-pi-hole-as-my-dns-server/). ## How To Install Pi-hole [![60-second install tutorial](http://i.imgur.com/5TEc3a6.png)](https://www.youtube.com/watch?v=TzFLJqUeirA) -## How Does It Work? +## How It Works + **Watch the 60-second video below to get a quick overview** [![Pi-hole exlplained](http://i.imgur.com/pG1m937.png)](https://youtu.be/9Eti3xibiho) ## Pi-hole Is Free, But Powered By Your Donations -Send a one-time donation or sign up for Optimal.com's service using our link below to provide us with a small portion of the montly fee. -* ![Paypal](http://i.imgur.com/3muNfxu.png) : [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY) -* ![Flattr](http://i.imgur.com/ZFceFRu.png) : [Donate](https://flattr.com/submit/auto?user_id=jacobsalmela&url=https://github.com/pi-hole/pi-hole) -* ![Bitcoin](http://i.imgur.com/FIlmOMG.png) : 1GKnevUnVaQM2pQieMyeHkpr8DXfkpfAtL -* ![Optimal.com](http://i.imgur.com/d4EAYrw.png) : [Optimal.com](http://api.optimal.com/partner/v1.0/bmV0d29ya3xkbnN8OlJhc3BiZXJyeSBQaS1Ib2xl/subscribe?redirect=https%3A%2F%2Fpi-hole.net%2Fthank-you%2F) (we get a small comission) +Send a one-time donation or sign up for Optimal.com's service using our link below to provide us with a small portion of the monthly fee. + +- ![Paypal](http://i.imgur.com/3muNfxu.png) : [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY) +- ![Flattr](http://i.imgur.com/ZFceFRu.png) : [Donate](https://flattr.com/submit/auto?user_id=jacobsalmela&url=https://github.com/pi-hole/pi-hole) +- ![Bitcoin](http://i.imgur.com/FIlmOMG.png) : 1GKnevUnVaQM2pQieMyeHkpr8DXfkpfAtL ## Get Help Or Connect With Us On The Web -- [@The_Pi_Hole](https://twitter.com/The_Pi_Hole) -- [/r/pihole](https://www.reddit.com/r/pihole/) -- [Pi-hole YouTube channel](https://www.youtube.com/channel/UCT5kq9w0wSjogzJb81C9U0w) -- [Wiki](https://github.com/pi-hole/pi-hole/wiki/Customization) -- [FAQs](https://pi-hole.net/help/) -- [![Join the chat at https://gitter.im/pi-hole/pi-hole](https://badges.gitter.im/pi-hole/pi-hole.svg)](https://gitter.im/pi-hole/pi-hole?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +- [@The_Pi_Hole](https://twitter.com/The_Pi_Hole) +- [/r/pihole](https://www.reddit.com/r/pihole/) +- [Pi-hole YouTube channel](https://www.youtube.com/channel/UCT5kq9w0wSjogzJb81C9U0w) +- [Wiki](https://github.com/pi-hole/pi-hole/wiki/Customization) +- [FAQs](https://pi-hole.net/help/) +- [![Join the chat at https://gitter.im/pi-hole/pi-hole](https://badges.gitter.im/pi-hole/pi-hole.svg)](https://gitter.im/pi-hole/pi-hole?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ## Technical Details -The Pi-hole is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. You can also [replace ads with any image you want](http://pi-hole.net/faq/is-it-possible-to-change-the-blank-page-that-takes-place-of-the-ads-to-something-else/) since it is just a simple Webpage taking place of the ads. +The Pi-hole is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. You can also [replace ads with any image you want](http://pi-hole.net/faq/is-it-possible-to-change-the-blank-page-that-takes-place-of-the-ads-to-something-else/) since it is just a simple Webpage taking place of the ads. ### Gravity -The [gravity.sh](https://github.com/pi-hole/pi-hole/blob/master/gravity.sh) does most of the magic. The script pulls in ad domains from many sources and compiles them into a single list of [over 1.6 million entries](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0) (if you decide to use the [mahakala list](https://github.com/pi-hole/pi-hole/commit/963eacfe0537a7abddf30441c754c67ca1e40965)). + +The [gravity.sh](https://github.com/pi-hole/pi-hole/blob/master/gravity.sh) does most of the magic. The script pulls in ad domains from many sources and compiles them into a single list of [over 1.6 million entries](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0) (if you decide to use the [mahakala list](https://github.com/pi-hole/pi-hole/commit/963eacfe0537a7abddf30441c754c67ca1e40965)). ## Web Interface -The [Web interface](https://github.com/jacobsalmela/AdminLTE#pi-hole-admin-dashboard) will be installed automatically so you can view stats and change settings. You can find it at: + +The [Web interface](https://github.com/jacobsalmela/AdminLTE#pi-hole-admin-dashboard) will be installed automatically so you can view stats and change settings. You can find it at: `http://192.168.1.x/admin/index.php` or `http://pi.hole/admin` @@ -60,55 +67,59 @@ The [Web interface](https://github.com/jacobsalmela/AdminLTE#pi-hole-admin-dashb ### Whitelist and blacklist -Domains can be whitelisted and blacklisted using two pre-installed scripts. See [the wiki page](https://github.com/pi-hole/pi-hole/wiki/Whitelisting-and-Blacklisting) for more details -![Whitelist editor in the Web interface](http://i.imgur.com/ogu2ewg.png) +Domains can be whitelisted and blacklisted using two pre-installed scripts. See [the wiki page](https://github.com/pi-hole/pi-hole/wiki/Whitelisting-and-Blacklisting) for more details ![Whitelist editor in the Web interface](http://i.imgur.com/ogu2ewg.png) ## API A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON: -```JSON + +```json { - "domains_being_blocked": "136708", - "dns_queries_today": "18108", - "ads_blocked_today": "14648", - "ads_percentage_today": "80.89" + "domains_being_blocked": "136708", + "dns_queries_today": "18108", + "ads_blocked_today": "14648", + "ads_percentage_today": "80.89" } ``` -The same output can be acheived on the CLI by running `chronometer.sh -j` + +The same output can be achieved on the CLI by running `chronometer.sh -j` ## Real-time Statistics -You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd-monitor-chronometer/) via `ssh` or on an [2.8" LCD screen](http://amzn.to/1P0q1Fj). This is accomplished via [`chronometer.sh`](https://github.com/pi-hole/pi-hole/blob/master/advanced/Scripts/chronometer.sh). -![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg) +You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd-monitor-chronometer/) via `ssh` or on an [2.8" LCD screen](http://amzn.to/1P0q1Fj). This is accomplished via [`chronometer.sh`](https://github.com/pi-hole/pi-hole/blob/master/advanced/Scripts/chronometer.sh). ![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg) ## Pi-hole Projects -- [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py) -- [Get LED alerts for each blocked ad](http://www.stinebaugh.info/get-led-alerts-for-each-blocked-ad-using-pi-hole/) -- [Pi-hole on Ubuntu 14.04 on VirtualBox](http://hbalagtas.blogspot.com/2016/02/adblocking-with-pi-hole-and-ubuntu-1404.html) -- [x86 Docker container that runs Pi-hole](https://hub.docker.com/r/diginc/pi-hole/) -- [Splunk: Pi-hole Visualizser](https://splunkbase.splunk.com/app/3023/) -- [Pi-hole Chrome extension](https://chrome.google.com/webstore/detail/pi-hole-list-editor/hlnoeoejkllgkjbnnnhfolapllcnaglh) ([open source](https://github.com/packtloss/pihole-extension)) -- [Go Bananas for CHiP-hole ad blocking](https://www.hackster.io/jacobsalmela/chip-hole-network-wide-ad-blocker-98e037) -- [Sky-Hole](http://dlaa.me/blog/post/skyhole) -- [Pi-hole in the Cloud!](http://blog.codybunch.com/2015/07/28/Pi-Hole-in-the-cloud/) -- [unRaid-hole](https://github.com/spants/unraidtemplates/blob/master/Spants/unRaid-hole.xml#L13)--[Repo and more info](http://lime-technology.com/forum/index.php?PHPSESSID=c0eae3e5ef7e521f7866034a3336489d&topic=38486.0) -- [Pi-hole on/off button](http://thetimmy.silvernight.org/pages/endisbutton/) -- [Minibian Pi-hole](http://munkjensen.net/wiki/index.php/See_my_Pi-Hole#Minibian_Pi-hole) + +- [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py) +- [Get LED alerts for each blocked ad](http://www.stinebaugh.info/get-led-alerts-for-each-blocked-ad-using-pi-hole/) +- [Pi-hole on Ubuntu 14.04 on VirtualBox](http://hbalagtas.blogspot.com/2016/02/adblocking-with-pi-hole-and-ubuntu-1404.html) +- [x86 Docker container that runs Pi-hole](https://hub.docker.com/r/diginc/pi-hole/) +- [Splunk: Pi-hole Visualizser](https://splunkbase.splunk.com/app/3023/) +- [Pi-hole Chrome extension](https://chrome.google.com/webstore/detail/pi-hole-list-editor/hlnoeoejkllgkjbnnnhfolapllcnaglh) ([open source](https://github.com/packtloss/pihole-extension)) +- [Go Bananas for CHiP-hole ad blocking](https://www.hackster.io/jacobsalmela/chip-hole-network-wide-ad-blocker-98e037) +- [Sky-Hole](http://dlaa.me/blog/post/skyhole) +- [Pi-hole in the Cloud!](http://blog.codybunch.com/2015/07/28/Pi-Hole-in-the-cloud/) +- [unRaid-hole](https://github.com/spants/unraidtemplates/blob/master/Spants/unRaid-hole.xml#L13)--[Repo and more info](http://lime-technology.com/forum/index.php?PHPSESSID=c0eae3e5ef7e521f7866034a3336489d&topic=38486.0) +- [Pi-hole on/off button](http://thetimmy.silvernight.org/pages/endisbutton/) +- [Minibian Pi-hole](http://munkjensen.net/wiki/index.php/See_my_Pi-Hole#Minibian_Pi-hole) +- [Windows Tray Stat Application](https://github.com/goldbattle/copernicus) ## Coverage -- [Adafruit livestream install](https://www.youtube.com/watch?v=eg4u2j1HYlI) -- [TekThing: 5 fun, easy projects for a Raspberry Pi](https://youtu.be/QwrKlyC2kdM?t=1m42s) -- [Pi-hole on Adafruit's blog](https://blog.adafruit.com/2016/03/04/pi-hole-is-a-black-hole-for-internet-ads-piday-raspberrypi-raspberry_pi/) -- [The Defrag Show - MSDN/Channel 9](https://channel9.msdn.com/Shows/The-Defrag-Show/Defrag-Endoscope-USB-Camera-The-Final-HoloLens-Vote-Adblock-Pi-and-more?WT.mc_id=dlvr_twitter_ch9#time=20m39s) -- [MacObserver Podcast 585](http://www.macobserver.com/tmo/podcast/macgeekgab-585) -- [Medium: Block All Ads For $53](https://medium.com/@robleathern/block-ads-on-all-home-devices-for-53-18-a5f1ec139693#.gj1xpgr5d) -- [MakeUseOf: Adblock Everywhere, The Pi-hole Way](http://www.makeuseof.com/tag/adblock-everywhere-raspberry-pi-hole-way/) -- [Lifehacker: Turn Your Pi Into An Ad Blocker With A Single Command](http://lifehacker.com/turn-a-raspberry-pi-into-an-ad-blocker-with-a-single-co-1686093533)! -- [Pi-hole on TekThing](https://youtu.be/8Co59HU2gY0?t=2m) -- [Pi-hole on Security Now! Podcast](http://www.youtube.com/watch?v=p7-osq_y8i8&t=100m26s) -- [Foolish Tech Show](https://youtu.be/bYyena0I9yc?t=2m4s) -- [Pi-hole on Ubuntu](http://www.boyter.org/2015/12/pi-hole-ubuntu-14-04/) -- [Catchpoint: iOS 9 Ad Blocking](http://blog.catchpoint.com/2015/09/14/ad-blocking-apple/) + +- [Adafruit livestream install](https://www.youtube.com/watch?v=eg4u2j1HYlI) +- [TekThing: 5 fun, easy projects for a Raspberry Pi](https://youtu.be/QwrKlyC2kdM?t=1m42s) +- [Pi-hole on Adafruit's blog](https://blog.adafruit.com/2016/03/04/pi-hole-is-a-black-hole-for-internet-ads-piday-raspberrypi-raspberry_pi/) +- [The Defrag Show - MSDN/Channel 9](https://channel9.msdn.com/Shows/The-Defrag-Show/Defrag-Endoscope-USB-Camera-The-Final-HoloLens-Vote-Adblock-Pi-and-more?WT.mc_id=dlvr_twitter_ch9#time=20m39s) +- [MacObserver Podcast 585](http://www.macobserver.com/tmo/podcast/macgeekgab-585) +- [Medium: Block All Ads For $53](https://medium.com/@robleathern/block-ads-on-all-home-devices-for-53-18-a5f1ec139693#.gj1xpgr5d) +- [MakeUseOf: Adblock Everywhere, The Pi-hole Way](http://www.makeuseof.com/tag/adblock-everywhere-raspberry-pi-hole-way/) +- [Lifehacker: Turn Your Pi Into An Ad Blocker With A Single Command](http://lifehacker.com/turn-a-raspberry-pi-into-an-ad-blocker-with-a-single-co-1686093533)! +- [Pi-hole on TekThing](https://youtu.be/8Co59HU2gY0?t=2m) +- [Pi-hole on Security Now! Podcast](http://www.youtube.com/watch?v=p7-osq_y8i8&t=100m26s) +- [Foolish Tech Show](https://youtu.be/bYyena0I9yc?t=2m4s) +- [Pi-hole on Ubuntu](http://www.boyter.org/2015/12/pi-hole-ubuntu-14-04/) +- [Catchpoint: iOS 9 Ad Blocking](http://blog.catchpoint.com/2015/09/14/ad-blocking-apple/) ## Other Operating Systems -This script will work for other UNIX-like systems with some slight **modifications**. As long as you can install `dnsmasq` and a Webserver, it should work OK. The automated install is only for a clean install of a Debian based system, such as the Raspberry Pi. + +This script will work for other UNIX-like systems with some slight **modifications**. As long as you can install `dnsmasq` and a Webserver, it should work OK. The automated install is only for a clean install of a Debian based system, such as the Raspberry Pi. diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index d83ca867..a289a9a5 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -47,9 +47,9 @@ fi #globals basename=pihole -piholeDir=/etc/$basename -adList=$piholeDir/gravity.list -blacklist=$piholeDir/blacklist.txt +piholeDir=/etc/${basename} +adList=${piholeDir}/gravity.list +blacklist=${piholeDir}/blacklist.txt reload=true addmode=true force=false @@ -61,9 +61,9 @@ domToRemoveList=() piholeIPfile=/etc/pihole/piholeIP piholeIPv6file=/etc/pihole/.useIPv6 -if [[ -f $piholeIPfile ]];then +if [[ -f ${piholeIPfile} ]];then # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script - piholeIP=$(cat $piholeIPfile) + piholeIP=$(cat ${piholeIPfile}) #rm $piholeIPfile else # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script @@ -75,13 +75,13 @@ fi modifyHost=false # After setting defaults, check if there's local overrides -if [[ -r $piholeDir/pihole.conf ]];then +if [[ -r ${piholeDir}/pihole.conf ]];then echo "::: Local calibration requested..." - . $piholeDir/pihole.conf + . ${piholeDir}/pihole.conf fi -if [[ -f $piholeIPv6file ]];then +if [[ -f ${piholeIPv6file} ]];then # If the file exists, then the user previously chose to use IPv6 in the automated installer piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi @@ -92,14 +92,14 @@ function HandleOther(){ if [ -z "$validDomain" ]; then echo "::: $1 is not a valid argument or domain name" else - domList=("${domList[@]}" $validDomain) + domList=("${domList[@]}" ${validDomain}) fi } function PopBlacklistFile(){ #check blacklist file exists, and if not, create it - if [[ ! -f $blacklist ]];then - touch $blacklist + if [[ ! -f ${blacklist} ]];then + touch ${blacklist} fi for dom in "${domList[@]}"; do if "$addmode"; then @@ -113,17 +113,17 @@ function PopBlacklistFile(){ function AddDomain(){ #| sed 's/\./\\./g' bool=false - grep -Ex -q "$1" $blacklist || bool=true - if $bool; then + grep -Ex -q "$1" ${blacklist} || bool=true + if ${bool}; then #domain not found in the blacklist file, add it! - if $verbose; then + if ${verbose}; then echo -n "::: Adding $1 to blacklist file..." fi - echo "$1" >> $blacklist + echo "$1" >> ${blacklist} modifyHost=true echo " done!" else - if $verbose; then + if ${verbose}; then echo "::: $1 already exists in $blacklist! No need to add" fi fi @@ -132,15 +132,15 @@ function AddDomain(){ function RemoveDomain(){ bool=false - grep -Ex -q "$1" $blacklist || bool=true - if $bool; then + grep -Ex -q "$1" ${blacklist} || bool=true + if ${bool}; then #Domain is not in the blacklist file, no need to Remove - if $verbose; then + if ${verbose}; then echo "::: $1 is NOT blacklisted! No need to remove" fi else #Domain is in the blacklist file, add to a temporary array - if $verbose; then + if ${verbose}; then echo "::: Un-blacklisting $dom..." fi domToRemoveList=("${domToRemoveList[@]}" $1) @@ -149,17 +149,17 @@ function RemoveDomain(){ } function ModifyHostFile(){ - if $addmode; then + if ${addmode}; then #add domains to the hosts file - if [[ -r $blacklist ]];then - numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l) + if [[ -r ${blacklist} ]];then + numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l) plural=; [[ "$numberOf" != "1" ]] && plural=s 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 + if [[ -n ${piholeIPv6} ]];then + cat ${blacklist} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList} else - cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList + cat ${blacklist} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList} fi fi else @@ -169,10 +169,10 @@ function ModifyHostFile(){ #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 "$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 "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist} echo " done!" done fi @@ -185,12 +185,12 @@ function Reload() { dnsmasqPid=$(pidof dnsmasq) - if [[ $dnsmasqPid ]]; then + if [[ ${dnsmasqPid} ]]; then # service already running - reload config - $SUDO killall -s HUP dnsmasq + ${SUDO} killall -s HUP dnsmasq else # service not running, start it up - $SUDO service dnsmasq start + ${SUDO} service dnsmasq start fi echo " done!" } @@ -223,15 +223,15 @@ done PopBlacklistFile -if $modifyHost || $force; then +if ${modifyHost} || ${force}; then ModifyHostFile else - if $verbose; then + if ${verbose}; then echo "::: No changes need to be made" fi exit 1 fi -if $reload; then +if ${reload}; then Reload fi diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index 806093e1..eae7cf1c 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -21,7 +21,7 @@ function CalcBlockedDomains(){ CheckIPv6 if [ -e "$gravity" ]; then #Are we IPV6 or IPV4? - if [[ -n $piholeIPv6 ]];then + if [[ -n ${piholeIPv6} ]];then #We are IPV6 blockedDomainsTotal=$(wc -l /etc/pihole/gravity.list | awk '{print $1/2}') else @@ -43,7 +43,7 @@ function CalcQueriesToday(){ function CalcblockedToday(){ if [ -e "$piLog" ] && [ -e "$gravity" ];then - blockedToday=$(cat $piLog | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l) + blockedToday=$(cat ${piLog} | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l) else blockedToday="Err." fi @@ -63,7 +63,7 @@ function CalcPercentBlockedToday(){ function CheckIPv6(){ piholeIPv6file="/etc/pihole/.useIPv6" - if [[ -f $piholeIPv6file ]];then + if [[ -f ${piholeIPv6file} ]];then # If the file exists, then the user previously chose to use IPv6 in the automated installer piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index e22a36aa..e2e59244 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -10,9 +10,6 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# Nate Brandeburg -# nate@ubiquisoft.com -# 3/24/2016 ######## GLOBAL VARS ######## DEBUG_LOG="/var/log/pihole_debug.log" @@ -46,75 +43,75 @@ fi # Ensure the file exists, create if not, clear if exists. if [ ! -f "$DEBUG_LOG" ]; then - $SUDO touch $DEBUG_LOG - $SUDO chmod 644 $DEBUG_LOG - $SUDO chown "$USER":root $DEBUG_LOG + ${SUDO} touch ${DEBUG_LOG} + ${SUDO} chmod 644 ${DEBUG_LOG} + ${SUDO} chown "$USER":root ${DEBUG_LOG} else - truncate -s 0 $DEBUG_LOG + truncate -s 0 ${DEBUG_LOG} fi ### Private functions exist here ### function versionCheck { - echo "#######################################" >> $DEBUG_LOG - echo "########## Versions Section ###########" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "########## Versions Section ###########" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} TMP=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) - echo "Pi-hole Version: $TMP" >> $DEBUG_LOG + echo "Pi-hole Version: $TMP" >> ${DEBUG_LOG} TMP=$(cd /var/www/html/admin && git describe --tags --abbrev=0) - echo "WebUI Version: $TMP" >> $DEBUG_LOG - echo >> $DEBUG_LOG + echo "WebUI Version: $TMP" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} } function distroCheck { - echo "#######################################" >> $DEBUG_LOG - echo "######## Distribution Section #########" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "######## Distribution Section #########" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} - TMP=$(cat /etc/*release/ || echo "Failed to find release") - echo "Distribution Version: $TMP" >> $DEBUG_LOG + TMP=$(cat /etc/*release || echo "Failed to find release") + echo "Distribution Version: $TMP" >> ${DEBUG_LOG} } function compareWhitelist { if [ ! -f "$WHITELISTMATCHES" ]; then - $SUDO touch $WHITELISTMATCHES - $SUDO chmod 644 $WHITELISTMATCHES - $SUDO chown "$USER":root $WHITELISTMATCHES + ${SUDO} touch ${WHITELISTMATCHES} + ${SUDO} chmod 644 ${WHITELISTMATCHES} + ${SUDO} chown "$USER":root ${WHITELISTMATCHES} else - truncate -s 0 $WHITELISTMATCHES + truncate -s 0 ${WHITELISTMATCHES} fi - echo "#######################################" >> $DEBUG_LOG - echo "######## Whitelist Comparison #########" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "######## Whitelist Comparison #########" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} while read -r line; do TMP=$(grep -w ".* $line$" "$GRAVITYFILE") if [ ! -z "$TMP" ]; then - echo "$TMP" >> $DEBUG_LOG - echo "$TMP" >> $WHITELISTMATCHES + echo "$TMP" >> ${DEBUG_LOG} + echo "$TMP" >> ${WHITELISTMATCHES} fi done < "$WHITELISTFILE" - echo >> $DEBUG_LOG + echo >> ${DEBUG_LOG} } function compareBlacklist { - echo "#######################################" >> $DEBUG_LOG - echo "######## Blacklist Comparison #########" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "######## Blacklist Comparison #########" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} while read -r line; do if [ ! -z "$line" ]; then - grep -w ".* $line$" "$GRAVITYFILE" >> $DEBUG_LOG + grep -w ".* $line$" "$GRAVITYFILE" >> ${DEBUG_LOG} fi done < "$BLACKLISTFILE" - echo >> $DEBUG_LOG + echo >> ${DEBUG_LOG} } function testNslookup { TESTURL="doubleclick.com" - echo "#######################################" >> $DEBUG_LOG - echo "############ NSLookup Test ############" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "############ NSLookup Test ############" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} # Find a blocked url that has not been whitelisted. if [ -s "$WHITELISTMATCHES" ]; then while read -r line; do @@ -131,77 +128,77 @@ function testNslookup { done < "$GRAVITYFILE" fi - echo "NSLOOKUP of $TESTURL from PiHole:" >> $DEBUG_LOG - nslookup "$TESTURL" >> $DEBUG_LOG - echo >> $DEBUG_LOG - echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> $DEBUG_LOG - nslookup "$TESTURL" 8.8.8.8 >> $DEBUG_LOG - echo >> $DEBUG_LOG + echo "NSLOOKUP of $TESTURL from PiHole:" >> ${DEBUG_LOG} + nslookup "$TESTURL" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} + echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> ${DEBUG_LOG} + nslookup "$TESTURL" 8.8.8.8 >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} } function checkProcesses { - echo "#######################################" >> $DEBUG_LOG - echo "########### Processes Check ###########" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "########### Processes Check ###########" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} echo ":::" echo "::: Logging status of lighttpd and dnsmasq..." PROCESSES=( lighttpd dnsmasq ) for i in "${PROCESSES[@]}" do - echo "" >> $DEBUG_LOG + echo "" >> ${DEBUG_LOG} echo -n "$i" >> "$DEBUG_LOG" - echo " processes status:" >> $DEBUG_LOG - $SUDO systemctl -l status "$i" >> "$DEBUG_LOG" + echo " processes status:" >> ${DEBUG_LOG} + ${SUDO} systemctl -l status "$i" >> "$DEBUG_LOG" done } function debugLighttpd { echo "::: Writing lighttpd to debug log..." - echo "#######################################" >> $DEBUG_LOG - echo "############ lighttpd.conf ############" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "############ lighttpd.conf ############" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} if [ -e "$LIGHTTPDFILE" ] then while read -r line; do if [ ! -z "$line" ]; then [[ "$line" =~ ^#.*$ ]] && continue - echo "$line" >> $DEBUG_LOG + echo "$line" >> ${DEBUG_LOG} fi done < "$LIGHTTPDFILE" - echo >> $DEBUG_LOG + echo >> ${DEBUG_LOG} else - echo "No lighttpd.conf file found!" >> $DEBUG_LOG + echo "No lighttpd.conf file found!" >> ${DEBUG_LOG} printf ":::\tNo lighttpd.conf file found\n" fi if [ -e "$LIGHTTPDERRFILE" ] then - echo "#######################################" >> $DEBUG_LOG - echo "######### lighttpd error.log ##########" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG - cat "$LIGHTTPDERRFILE" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "######### lighttpd error.log ##########" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} + cat "$LIGHTTPDERRFILE" >> ${DEBUG_LOG} else - echo "No lighttpd error.log file found!" >> $DEBUG_LOG + echo "No lighttpd error.log file found!" >> ${DEBUG_LOG} printf ":::\tNo lighttpd error.log file found\n" fi - echo >> $DEBUG_LOG + echo >> ${DEBUG_LOG} } ### END FUNCTIONS ### ### Check Pi internet connections ### # Log the IP addresses of this Pi -IPADDR=$($SUDO ifconfig | perl -nle 's/dr:(\S+)/print $1/e') +IPADDR=$(${SUDO} ifconfig | perl -nle 's/dr:(\S+)/print $1/e') echo "::: Writing local IPs to debug log" -echo "IP Addresses of this Pi:" >> $DEBUG_LOG -echo "$IPADDR" >> $DEBUG_LOG -echo >> $DEBUG_LOG +echo "IP Addresses of this Pi:" >> ${DEBUG_LOG} +echo "$IPADDR" >> ${DEBUG_LOG} +echo >> ${DEBUG_LOG} # Check if we can connect to the local gateway GATEWAY_CHECK=$(ping -q -w 1 -c 1 "$(ip r | grep default | cut -d ' ' -f 3)" > /dev/null && echo ok || echo error) -echo "Gateway check:" >> $DEBUG_LOG -echo "$GATEWAY_CHECK" >> $DEBUG_LOG -echo >> $DEBUG_LOG +echo "Gateway check:" >> ${DEBUG_LOG} +echo "$GATEWAY_CHECK" >> ${DEBUG_LOG} +echo >> ${DEBUG_LOG} versionCheck distroCheck @@ -212,109 +209,109 @@ checkProcesses debugLighttpd echo "::: Writing dnsmasq.conf to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "############### Dnsmasq ###############" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "############### Dnsmasq ###############" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$DNSMASQFILE" ] then #cat $DNSMASQFILE >> $DEBUG_LOG while read -r line; do if [ ! -z "$line" ]; then [[ "$line" =~ ^#.*$ ]] && continue - echo "$line" >> $DEBUG_LOG + echo "$line" >> ${DEBUG_LOG} fi done < "$DNSMASQFILE" - echo >> $DEBUG_LOG + echo >> ${DEBUG_LOG} else - echo "No dnsmasq.conf file found!" >> $DEBUG_LOG + echo "No dnsmasq.conf file found!" >> ${DEBUG_LOG} printf ":::\tNo dnsmasq.conf file found!\n" fi echo "::: Writing 01-pihole.conf to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "########### 01-pihole.conf ############" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "########### 01-pihole.conf ############" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$PIHOLECONFFILE" ] then while read -r line; do if [ ! -z "$line" ]; then [[ "$line" =~ ^#.*$ ]] && continue - echo "$line" >> $DEBUG_LOG + echo "$line" >> ${DEBUG_LOG} fi done < "$PIHOLECONFFILE" - echo >> $DEBUG_LOG + echo >> ${DEBUG_LOG} else - echo "No 01-pihole.conf file found!" >> $DEBUG_LOG + echo "No 01-pihole.conf file found!" >> ${DEBUG_LOG} printf ":::\tNo 01-pihole.conf file found\n" fi echo "::: Writing size of gravity.list to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "############ gravity.list #############" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "############ gravity.list #############" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$GRAVITYFILE" ] then - wc -l "$GRAVITYFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG + wc -l "$GRAVITYFILE" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} else - echo "No gravity.list file found!" >> $DEBUG_LOG + echo "No gravity.list file found!" >> ${DEBUG_LOG} printf ":::\tNo gravity.list file found\n" fi # Write the hostname output to compare against entries in /etc/hosts, which is logged next -echo "Hostname of this pihole is: " >> $DEBUG_LOG -hostname >> $DEBUG_LOG +echo "Hostname of this pihole is: " >> ${DEBUG_LOG} +hostname >> ${DEBUG_LOG} echo "::: Writing hosts file to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "################ Hosts ################" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "################ Hosts ################" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$HOSTSFILE" ] then - cat "$HOSTSFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG + cat "$HOSTSFILE" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} else - echo "No hosts file found!" >> $DEBUG_LOG + echo "No hosts file found!" >> ${DEBUG_LOG} printf ":::\tNo hosts file found!\n" fi ### PiHole application specific logging ### echo "::: Writing whitelist to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "############## Whitelist ##############" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "############## Whitelist ##############" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$WHITELISTFILE" ] then - cat "$WHITELISTFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG + cat "$WHITELISTFILE" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} else - echo "No whitelist.txt file found!" >> $DEBUG_LOG + echo "No whitelist.txt file found!" >> ${DEBUG_LOG} printf ":::\tNo whitelist.txt file found!\n" fi echo "::: Writing blacklist to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "############## Blacklist ##############" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "############## Blacklist ##############" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$BLACKLISTFILE" ] then - cat "$BLACKLISTFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG + cat "$BLACKLISTFILE" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} else - echo "No blacklist.txt file found!" >> $DEBUG_LOG + echo "No blacklist.txt file found!" >> ${DEBUG_LOG} printf ":::\tNo blacklist.txt file found!\n" fi echo "::: Writing adlists.list to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "############ adlists.list #############" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "############ adlists.list #############" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$ADLISTSFILE" ] then - cat "$ADLISTSFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG + cat "$ADLISTSFILE" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} else - echo "No adlists.list file found... using adlists.default!" >> $DEBUG_LOG + echo "No adlists.list file found... using adlists.default!" >> ${DEBUG_LOG} printf ":::\tNo adlists.list file found... using adlists.default!\n" fi @@ -323,34 +320,44 @@ fi function dumpPiHoleLog { trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT echo -e "::: Writing current pihole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)" - echo "#######################################" >> $DEBUG_LOG - echo "############# pihole.log ##############" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "############# pihole.log ##############" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} if [ -e "$PIHOLELOG" ] then while true; do - tail -f "$PIHOLELOG" >> $DEBUG_LOG - echo >> $DEBUG_LOG + tail -f "$PIHOLELOG" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} done else - echo "No pihole.log file found!" >> $DEBUG_LOG + echo "No pihole.log file found!" >> ${DEBUG_LOG} printf ":::\tNo pihole.log file found!\n" fi } # Anything to be done after capturing of pihole.log terminates function finalWork { - echo "::: Finshed debugging!" - TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999) + echo "::: Finshed debugging!" + echo "::: The degug log can be uploaded to Termbin.com for easier sharing." + read -r -p "::: Would you like to upload the log? [y/N] " response + case ${response} in + [yY][eE][sS]|[yY]) + TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999) + ;; + *) + echo "::: Log will NOT be uploaded to Termbin." + ;; + esac - # Check if termbin.com is reachable. When it's not, point to local log instead - if [ -n "$TERMBIN" ] - then - echo "::: Debug log can be found at : $TERMBIN" - else - echo "::: Debug log can be found at : /var/log/pihole_debug.log" - fi + # Check if termbin.com is reachable. When it's not, point to local log instead + if [ -n "$TERMBIN" ] + then + echo "::: Debug log can be found at : $TERMBIN" + else + echo "::: Debug log can be found at : /var/log/pihole_debug.log" + fi } + trap finalWork EXIT ### Method calls for additional logging ### diff --git a/advanced/Scripts/setupLCD.sh b/advanced/Scripts/setupLCD.sh index 03be4e0a..c77f1f4a 100755 --- a/advanced/Scripts/setupLCD.sh +++ b/advanced/Scripts/setupLCD.sh @@ -44,12 +44,12 @@ getInitSys() { # https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L274-L285 autoLoginPiToConsole() { if [ -e /etc/init.d/lightdm ]; then - if [ $SYSTEMD -eq 1 ]; then - $SUDO systemctl set-default multi-user.target - $SUDO ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service + if [ ${SYSTEMD} -eq 1 ]; then + ${SUDO} systemctl set-default multi-user.target + ${SUDO} ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service else - $SUDO update-rc.d lightdm disable 2 - $SUDO sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/" + ${SUDO} update-rc.d lightdm disable 2 + ${SUDO} sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/" fi fi } @@ -66,23 +66,23 @@ echo /usr/local/bin/chronometer.sh >> /home/pi/.bashrc # Set up the LCD screen based on Adafruits instuctions: # https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/easy-install -curl -SLs https://apt.adafruit.com/add-pin | $SUDO bash -$SUDO apt-get -y install raspberrypi-bootloader -$SUDO apt-get -y install adafruit-pitft-helper -$SUDO adafruit-pitft-helper -t 28r +curl -SLs https://apt.adafruit.com/add-pin | ${SUDO} bash +${SUDO} apt-get -y install raspberrypi-bootloader +${SUDO} apt-get -y install adafruit-pitft-helper +${SUDO} adafruit-pitft-helper -t 28r # Download the cmdline.txt file that prevents the screen from going blank after a period of time -$SUDO mv /boot/cmdline.txt /boot/cmdline.orig -$SUDO curl -o /boot/cmdline.txt https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/cmdline.txt +${SUDO} mv /boot/cmdline.txt /boot/cmdline.orig +${SUDO} curl -o /boot/cmdline.txt https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/cmdline.txt # Back up the original file and download the new one -$SUDO mv /etc/default/console-setup /etc/default/console-setup.orig -$SUDO curl -o /etc/default/console-setup https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/console-setup +${SUDO} mv /etc/default/console-setup /etc/default/console-setup.orig +${SUDO} curl -o /etc/default/console-setup https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/console-setup # Instantly apply the font change to the LCD screen -$SUDO setupcon +${SUDO} setupcon -$SUDO reboot +${SUDO} reboot # Start showing the stats on the screen by running the command on another tty: # http://unix.stackexchange.com/questions/170063/start-a-process-on-a-different-tty diff --git a/advanced/Scripts/updateDashboard.sh b/advanced/Scripts/updateDashboard.sh index 6955683d..991089c2 100755 --- a/advanced/Scripts/updateDashboard.sh +++ b/advanced/Scripts/updateDashboard.sh @@ -55,7 +55,7 @@ is_repo() { # replaces it with the current master branch from github make_repo() { # remove the non-repod interface and clone the interface - rm -rf $WEB_INTERFACE_DIR + rm -rf ${WEB_INTERFACE_DIR} git clone "$WEB_INTERFACE_GIT_URL" "$WEB_INTERFACE_DIR" } diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh new file mode 100644 index 00000000..e7e7c782 --- /dev/null +++ b/advanced/Scripts/version.sh @@ -0,0 +1,20 @@ +#!/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 +# 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 +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. + +piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) +webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) + +piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') +webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') + +echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)" +echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)" \ No newline at end of file diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 266ac49e..75d62173 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -47,9 +47,9 @@ fi #globals basename=pihole -piholeDir=/etc/$basename -adList=$piholeDir/gravity.list -whitelist=$piholeDir/whitelist.txt +piholeDir=/etc/${basename} +adList=${piholeDir}/gravity.list +whitelist=${piholeDir}/whitelist.txt reload=true addmode=true force=false @@ -61,9 +61,9 @@ domToRemoveList=() piholeIPfile=/etc/pihole/piholeIP piholeIPv6file=/etc/pihole/.useIPv6 -if [[ -f $piholeIPfile ]];then +if [[ -f ${piholeIPfile} ]];then # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script - piholeIP=$(cat $piholeIPfile) + piholeIP=$(cat ${piholeIPfile}) #rm $piholeIPfile else # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script @@ -75,12 +75,12 @@ fi modifyHost=false # After setting defaults, check if there's local overrides -if [[ -r $piholeDir/pihole.conf ]];then +if [[ -r ${piholeDir}/pihole.conf ]];then echo "::: Local calibration requested..." - . $piholeDir/pihole.conf + . ${piholeDir}/pihole.conf fi -if [[ -f $piholeIPv6file ]];then +if [[ -f ${piholeIPv6file} ]];then # If the file exists, then the user previously chose to use IPv6 in the automated installer piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi @@ -91,18 +91,18 @@ function HandleOther(){ if [ -z "$validDomain" ]; then echo "::: $1 is not a valid argument or domain name" else - domList=("${domList[@]}" $validDomain) + domList=("${domList[@]}" ${validDomain}) fi } function PopWhitelistFile(){ #check whitelist file exists, and if not, create it - if [[ ! -f $whitelist ]];then - touch $whitelist + if [[ ! -f ${whitelist} ]];then + touch ${whitelist} fi for dom in "${domList[@]}" do - if $addmode; then + if ${addmode}; then AddDomain "$dom" else RemoveDomain "$dom" @@ -114,19 +114,19 @@ function AddDomain(){ #| sed 's/\./\\./g' bool=false - grep -Ex -q "$1" $whitelist || bool=true - if $bool; then + grep -Ex -q "$1" ${whitelist} || bool=true + if ${bool}; then #domain not found in the whitelist file, add it! - if $verbose; then + if ${verbose}; then echo -n "::: Adding $1 to $whitelist..." fi - echo "$1" >> $whitelist + echo "$1" >> ${whitelist} modifyHost=true - if $verbose; then + if ${verbose}; then echo " done!" fi else - if $verbose; then + if ${verbose}; then echo "::: $1 already exists in $whitelist, no need to add!" fi fi @@ -135,10 +135,10 @@ function AddDomain(){ function RemoveDomain(){ bool=false - grep -Ex -q "$1" $whitelist || bool=true - if $bool; then + grep -Ex -q "$1" ${whitelist} || bool=true + if ${bool}; then #Domain is not in the whitelist file, no need to Remove - if $verbose; then + if ${verbose}; then echo "::: $1 is NOT whitelisted! No need to remove" fi else @@ -152,21 +152,21 @@ function RemoveDomain(){ } function ModifyHostFile(){ - if $addmode; then + if ${addmode}; then #remove domains in from hosts file - if [[ -r $whitelist ]];then + 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 ":::" echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..." - awk -F':' '{print $1}' $whitelist | while read -r line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp - awk -F':' '{print $1}' $whitelist | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp + awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp + awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp echo "l" >> /etc/pihole/whitelist.tmp - grep -F -x -v -f $piholeDir/whitelist.tmp $adList > $piholeDir/gravity.tmp - rm $adList - mv $piholeDir/gravity.tmp $adList - rm $piholeDir/whitelist.tmp + grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp + rm ${adList} + mv ${piholeDir}/gravity.tmp ${adList} + rm ${piholeDir}/whitelist.tmp echo " done!" fi @@ -175,20 +175,23 @@ function ModifyHostFile(){ echo ":::" echo "::: Modifying HOSTS file to un-whitelist domains..." for rdom in "${domToRemoveList[@]}" - do - if [[ -n $piholeIPv6 ]];then - 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 -n "::: Un-whitelisting $rdom on IPv4" - echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList - echo " done!" - fi - echo -n "::: Removing $rdom from $whitelist..." - echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist - echo " done!" - done + do + if grep -q "$rdom" /etc/pihole/*.domains; then + echo "::: AdLists contain $rdom, re-adding block" + if [[ -n ${piholeIPv6} ]];then + echo -n "::: Restoring block for $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 -n "::: Restoring block for $rdom on IPv4..." + echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList} + echo " done!" + fi + fi + echo -n "::: Removing $rdom from $whitelist..." + echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} + echo " done!" + done fi } @@ -198,12 +201,12 @@ function Reload() { echo -n "::: Refresh lists in dnsmasq..." dnsmasqPid=$(pidof dnsmasq) - if [[ $dnsmasqPid ]]; then + if [[ ${dnsmasqPid} ]]; then # service already running - reload config - $SUDO killall -s HUP dnsmasq + ${SUDO} killall -s HUP dnsmasq else # service not running, start it up - $SUDO service dnsmasq start + ${SUDO} service dnsmasq start fi echo " done!" } @@ -236,16 +239,16 @@ done PopWhitelistFile -if $modifyHost || $force; then +if ${modifyHost} || ${force}; then ModifyHostFile else - if $verbose; then + if ${verbose}; then echo ":::" echo "::: No changes need to be made" fi exit 1 fi -if $reload; then +if ${reload}; then Reload fi diff --git a/advanced/index.html b/advanced/index.html index 6bfc7988..3a4abe1f 100644 --- a/advanced/index.html +++ b/advanced/index.html @@ -1,4 +1,7 @@ +
+ + - \ No newline at end of file +