Merge branch 'development' into new/https

pull/1420/head
Adam Warner 7 years ago committed by GitHub
commit 7b1524ad01

@ -9,7 +9,7 @@
_{replace this text with a number from 1 to 10, with 1 being not familiar, and 10 being very familiar}_ _{replace this text with a number from 1 to 10, with 1 being not familiar, and 10 being very familiar}_
--- ---
**[FEATURE REQUEST | QUESTION | OTHER]:** **[BUG REPORT | OTHER]:**
Please [submit your feature request here](https://discourse.pi-hole.net/c/feature-requests), so it is votable by the community. It's also easier for us to track. Please [submit your feature request here](https://discourse.pi-hole.net/c/feature-requests), so it is votable by the community. It's also easier for us to track.

@ -3,17 +3,17 @@
***Please submit all pull requests against the `development` branch. Failure to do so will delay or deny your request*** ***Please submit all pull requests against the `development` branch. Failure to do so will delay or deny your request***
- [] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md). - [] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md).
- [] I have checked that [another pull request](https://github.com/pi-hole/pi-hole/pulls) for this purpose does not exist. - [] I have written tests and verified that they fail without my change.
- [] I have considered, and confirmed that this submission will be valuable to others. - [] I have squashed any insignificant commits.
- [] I accept that this submission may not be used, and the pull request closed at the will of the maintainer. - [] This change has comments for package types, values, functions, and non-obvious lines of code.
- [] I give this submission freely, and claim no ownership to its content. - [] I am willing to help maintain this change if there are issues with it later.
- [] I give this submission freely and claim no ownership. It is compatible with the EUPL 1.2 license.
- [] I have Signed Off all commits. (`git commit --signoff`)
**How familiar are you with the codebase?:** ***Please explain what you have done and wish to accomplish with this Pull Request***
_{replace this text with a number from 1 to 10, with 1 being not familiar, and 10 being very familiar}_ 1. What does this change do, exactly?
--- 2. Please link to the relevant issues.
_{replace this line with your pull request content}_
3. Which documentation changes (if any) need to be made because of this PR?
_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._

@ -10,7 +10,7 @@ group_defaults:
reset_on_push: reset_on_push:
enabled: true enabled: true
reject_value: -2 reject_value: -2
approve_regex: '^(Approved|:shipit:|:\+1:|Engage)' approve_regex: '^(Approved|:shipit:|:\+1:|Engage|:taco:)'
reject_regex: '^(Rejected|:-1:|Borg)' reject_regex: '^(Rejected|:-1:|Borg)'
author_approval: author_approval:
auto: true auto: true
@ -35,4 +35,4 @@ groups:
- master - master
required: 4 required: 4
teams: teams:
- admin - approvers

@ -12,81 +12,63 @@ This license applies to the whole project EXCEPT:
The licenses that existed prior to this change have remained intact. The licenses that existed prior to this change have remained intact.
------------------------------------------------------------- -------------------------------------------------------------
EUROPEAN UNION PUBLIC LICENCE v. 1.2
European Union Public Licence EUPL © the European Union 2007, 2016
V. 1.1
EUPL (C) the European Community 2007 This European Union Public Licence (the EUPL) applies to the Work (as defined below) which is provided under the terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such use is covered by a right of the copyright holder of the Work).
The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following notice immediately following the copyright notice for the Work:
This European Union Public Licence (the "EUPL") applies to the Work or Software (as defined below) which is provided under the terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such use is covered by a right of the copyright holder of the Work). Licensed under the EUPL
or has expressed by any other means his willingness to license under the EUPL.
The Original Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following notice immediately following the copyright notice for the Original Work:
Licensed under the EUPL V.1.1
or has expressed by any other mean his willingness to license under the EUPL.
1. Definitions 1. Definitions
In this Licence, the following terms have the following meaning: In this Licence, the following terms have the following meaning:
- The Licence: this Licence. - The Licence: this Licence.
- The Original Work: the work or software distributed or communicated by the Licensor under this Licence, available as Source Code and also as Executable Code as the case may be.
- The Original Work or the Software: the software distributed and/or communicated by the Licensor under this Licence, available as Source Code and also as Executable Code as the case may be.
- Derivative Works: the works or software that could be created by the Licensee, based upon the Original Work or modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in the country mentioned in Article 15. - Derivative Works: the works or software that could be created by the Licensee, based upon the Original Work or modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in the country mentioned in Article 15.
- The Work: the Original Work or its Derivative Works.
- The Work: the Original Work and/or its Derivative Works.
- The Source Code: the human-readable form of the Work which is the most convenient for people to study and modify. - The Source Code: the human-readable form of the Work which is the most convenient for people to study and modify.
- The Executable Code: any code which has generally been compiled and which is meant to be interpreted by a computer as a program. - The Executable Code: any code which has generally been compiled and which is meant to be interpreted by a computer as a program.
- The Licensor: the natural or legal person that distributes or communicates the Work under the Licence.
- The Licensor: the natural or legal person that distributes and/or communicates the Work under the Licence.
- Contributor(s): any natural or legal person who modifies the Work under the Licence, or otherwise contributes to the creation of a Derivative Work. - Contributor(s): any natural or legal person who modifies the Work under the Licence, or otherwise contributes to the creation of a Derivative Work.
- The Licensee or You: any natural or legal person who makes any usage of the Work under the terms of the Licence.
- The Licensee or "You": any natural or legal person who makes any usage of the Software under the terms of the Licence. - Distribution or Communication: any act of selling, giving, lending, renting, distributing, communicating, transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential functionalities at the disposal of any other natural or legal person.
- Distribution and/or Communication: any act of selling, giving, lending, renting, distributing, communicating, transmitting, or otherwise making available, on-line or off-line, copies of the Work or providing access to its essential functionalities at the disposal of any other natural or legal person.
2. Scope of the rights granted by the Licence 2. Scope of the rights granted by the Licence
The Licensor hereby grants You a world-wide, royalty-free, non-exclusive, sub-licensable licence to do the following, for the duration of copyright vested in the Original Work: The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for the duration of copyright vested in the Original Work:
- use the Work in any circumstance and for all usage, - use the Work in any circumstance and for all usage,
- reproduce the Work, - reproduce the Work,
- modify the Original Work, and make Derivative Works based upon the Work, - modify the Work, and make Derivative Works based upon the Work,
- communicate to the public, including the right to make available or display the Work or copies thereof to the public and perform publicly, as the case may be, the Work, - communicate to the public, including the right to make available or display the Work or copies thereof to the public and perform publicly, as the case may be, the Work,
- distribute the Work or copies thereof, - distribute the Work or copies thereof,
- lend and rent the Work or copies thereof, - lend and rent the Work or copies thereof,
- sub-license rights in the Work or copies thereof. - sublicense rights in the Work or copies thereof.
Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the applicable law permits so. Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the applicable law permits so.
In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed by law in order to make effective the licence of the economic rights here above listed. In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed by law in order to make effective the licence of the economic rights here above listed.
The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the extent necessary to make use of the rights granted on the Work under this Licence.
The Licensor grants to the Licensee royalty-free, non exclusive usage rights to any patents held by the Licensor, to the extent necessary to make use of the rights granted on the Work under this Licence.
3. Communication of the Source Code 3. Communication of the Source Code
The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to distribute and/or communicate the Work. The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to distribute or communicate the Work.
4. Limitations on copyright 4. Limitations on copyright
Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the exclusive rights of the rights owners in the Original Work or Software, of the exhaustion of those rights or of other applicable limitations thereto. Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations thereto.
5. Obligations of the Licensee 5. Obligations of the Licensee
The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those obligations are the following: The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those obligations are the following:
Attribution right: the Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the Licence with every copy of the Work he/she distributes and/or communicates. The Licensee must cause any Derivative Work to carry prominent notices stating that the Work has been modified and the date of modification. Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work to carry prominent notices stating that the Work has been modified and the date of modification.
Copyleft clause: If the Licensee distributes and/or communicates copies of the Original Works or Derivative Works based upon the Original Work, this Distribution and/or Communication will be done under the terms of this Licence or of a later version of this Licence unless the Original Work is expressly distributed only under this version of the Licence. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the Work or Derivative Work that alter or restrict the terms of the Licence. Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless the Original Work is expressly distributed only under this version of the Licence - for example by communicating EUPL v. 1.2 only. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the Work or Derivative Work that alter or restrict the terms of the Licence.
Compatibility clause: If the Licensee Distributes and/or Communicates Derivative Works or copies thereof based upon both the Original Work and another work licensed under a Compatible Licence, this Distribution and/or Communication can be done under the terms of this Compatible Licence. For the sake of this clause, "Compatible Licence" refers to the licences listed in the appendix attached to this Licence. Should the Licensees obligations under the Compatible Licence conflict with his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail. Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done under the terms of this Compatible Licence. For the sake of this clause, Compatible Licence refers to the licences listed in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail.
Provision of Source Code: When distributing and/or communicating copies of the Work, the Licensee will provide a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available for as long as the Licensee continues to distribute and/or communicate the Work. Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available for as long as the Licensee continues to distribute or communicate the Work.
Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the copyright notice. Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the copyright notice.
@ -100,10 +82,8 @@ Each time You accept the Licence, the original Licensor and subsequent Contribut
7. Disclaimer of Warranty 7. Disclaimer of Warranty
The Work is a work in progress, which is continuously improved by numerous contributors. It is not a finished work and may therefore contain defects or "bugs" inherent to this type of software development. The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work and may therefore contain defects or bugs inherent to this type of development.
For the above reason, the Work is provided under the Licence on an as is basis and without warranties of any kind concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this Licence.
For the above reason, the Work is provided under the Licence on an "as is" basis and without warranties of any kind concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this Licence.
This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work. This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work.
8. Disclaimer of Liability 8. Disclaimer of Liability
@ -112,56 +92,55 @@ Except in the cases of wilful misconduct or damages directly caused to natural p
9. Additional agreements 9. Additional agreements
While distributing the Original Work or Derivative Works, You may choose to conclude an additional agreement to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or services consistent with this Licence. However, in accepting such obligations, You may act only on your own behalf and on your sole responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by the fact You have accepted any such warranty or additional liability. While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by the fact You have accepted any warranty or additional liability.
10. Acceptance of the Licence 10. Acceptance of the Licence
The provisions of this Licence can be accepted by clicking on an icon "I agree" placed under the bottom of a window displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms and conditions. The provisions of this Licence can be accepted by clicking on an icon I agree placed under the bottom of a window displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms and conditions.
Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution or Communication by You of the Work or copies thereof.
Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution and/or Communication by You of the Work or copies thereof.
11. Information to the public 11. Information to the public
In case of any Distribution and/or Communication of the Work by means of electronic communication by You (for example, by offering to download the Work from a remote location) the distribution channel or media (for example, a website) must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence and the way it may be accessible, concluded, stored and reproduced by the Licensee. In case of any Distribution or Communication of the Work by means of electronic communication by You (for example, by offering to download the Work from a remote location) the distribution channel or media (for example, a website) must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence and the way it may be accessible, concluded, stored and reproduced by the Licensee.
12. Termination of the Licence 12. Termination of the Licence
The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms of the Licence. The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms of the Licence.
Such a termination will not terminate the licences of any person who has received the Work from the Licensee under the Licence, provided such persons remain in full compliance with the Licence. Such a termination will not terminate the licences of any person who has received the Work from the Licensee under the Licence, provided such persons remain in full compliance with the Licence.
13. Miscellaneous 13. Miscellaneous
Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the Work licensed hereunder. Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the Work.
If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid and enforceable.
If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or enforceability of the Licence as a whole. Such provision will be construed and/or reformed so as necessary to make it valid and enforceable. The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence. New versions of the Licence will be published with a unique version number.
The European Commission may publish other linguistic versions and/or new versions of this Licence, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence. New versions of the Licence will be published with a unique version number.
All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take advantage of the linguistic version of their choice. All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take advantage of the linguistic version of their choice.
14. Jurisdiction 14. Jurisdiction
Any litigation resulting from the interpretation of this License, arising between the European Commission, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice of the European Communities, as laid down in article 238 of the Treaty establishing the European Community. Without prejudice to specific agreement between parties,
- any litigation resulting from the interpretation of this License, arising between the European Union institutions, bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union,
Any litigation arising between Parties, other than the European Commission, and resulting from the interpretation of this License, will be subject to the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business. - any litigation arising between other parties and resulting from the interpretation of this License, will be subject to the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business.
15. Applicable Law 15. Applicable Law
This Licence shall be governed by the law of the European Union country where the Licensor resides or has his registered office. Without prejudice to specific agreement between parties,
- this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat, resides or has his registered office,
This licence shall be governed by the Belgian law if: - this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside a European Union Member State.
- a litigation arises between the European Commission, as a Licensor, and any Licensee;
- the Licensor, other than the European Commission, has no residence or registered office inside a European Union country.
=== ===
Appendix Appendix
"Compatible Licences" according to article 5 EUPL are: Compatible Licences according to Article 5 EUPL are:
- GNU General Public License (GNU GPL) v. 2 - GNU General Public License (GPL) v. 2, v. 3
- GNU Affero General Public License (AGPL) v. 3
- Open Software License (OSL) v. 2.1, v. 3.0 - Open Software License (OSL) v. 2.1, v. 3.0
- Common Public License v. 1.0 - Eclipse Public License (EPL) v. 1.0
- Eclipse Public License v. 1.0 - CeCILL v. 2.0, v. 2.1
- Cecill v. 2.0 - Mozilla Public Licence (MPL) v. 2
- GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
- Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software
- European Union Public Licence (EUPL) v. 1.1, v. 1.2
- Québec Free and Open-Source Licence - Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+)
- The European Commission may update this Appendix to later versions of the above licences without producing a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the covered Source Code from exclusive appropriation.
- All other changes or additions to this Appendix require the production of a new EUPL version.

@ -8,37 +8,37 @@
<a href=https://discourse.pi-hole.net><img src="https://assets.pi-hole.net/static/Vortex_with_text_and_TM.png" width=210></a> <a href=https://discourse.pi-hole.net><img src="https://assets.pi-hole.net/static/Vortex_with_text_and_TM.png" width=210></a>
</p> </p>
## The multi-platform, network-wide ad blocker ## Pi-hole®: The multi-platform, network-wide ad blocker
Block ads for **all** your devices _without_ the need to install client-side software. The Pi-hole™ blocks ads at the DNS-level, so all your devices are protected. Block ads for **all** your devices _without_ the need to install client-side software.
- Web Browsers
- Cell Phones
- Smart TV's
- Internet-connected home automation
- Anything that communicates with the Internet
<p align="center"> <p align="center">
<a href=http://www.digitalocean.com/?refcode=344d234950e1><img src="https://assets.pi-hole.net/static/DOHostingSlug.png"></a> <a href=http://www.digitalocean.com/?refcode=344d234950e1><img src="https://assets.pi-hole.net/static/DOHostingSlug.png"></a>
</p> </p>
## Your Support Still Matters ## Executive Summary
The Pi-hole blocks ads at the DNS-level, so all your devices are protected.
Digital Ocean helps with our infrastructure, but our developers are all volunteers so *your donations help keep us innovating*. Sending a donation using our links below helps us offset a portion of our monthly costs.
- ![Paypal](https://assets.pi-hole.net/static/paypal.png) [Donate via PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY) - **Easy-to-install** - our intelligent installer walks you through the process with no additional software needed on client devices
- ![Bitcoin](https://assets.pi-hole.net/static/Bitcoin.png) Bitcoin Address: 1GKnevUnVaQM2pQieMyeHkpr8DXfkpfAtL - **Universal** - ads are blocked in _non-browser locations_ such as ad-supported mobile apps and smart TVs
- **Quick** - installation takes less than ten minutes and it [_really_ is _that easy_](https://discourse.pi-hole.net/t/new-pi-hole-questions/3971/5?u=jacob.salmela)
- **Informative** - an administrative Web interface shows ad-blocking statistics
- **Lightweight** - designed to run on [minimal resources](https://discourse.pi-hole.net/t/hardware-software-requirements/273)
- **Scalable** - even in large environments, [Pi-hole can handle hundreds of millions of queries](https://pi-hole.net/2017/05/24/how-much-traffic-can-pi-hole-handle/) (with the right hardware specs)
- **Powerful** - advertisements are blocked over IPv4 _and_ IPv6
- **Fast** - it speeds up high-cost, high-latency networks by caching DNS queries and saves bandwidth by not downloading advertisement elements
- **Versatile** - Pi-hole can function also function as a DHCP server
### One-Step Automated Install # One-Step Automated Install
1. Install a [supported operating system](https://discourse.pi-hole.net/t/hardware-software-requirements/273/1) 1. Install a [supported operating system](https://discourse.pi-hole.net/t/hardware-software-requirements/273/1)
2. Run the command below (it 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!) 2. Run the command below (it 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!)
### `curl -sSL https://install.pi-hole.net | bash` #### `curl -sSL https://install.pi-hole.net | bash`
#### Alternative Semi-Automated Install Methods ## Alternative Semi-Automated Install Methods
_If you wish to read over the script before running it, run `nano basic-install.sh` to open the file in a text viewer._ _If you wish to read over the script before running it, run `nano basic-install.sh` to open the file in a text viewer._
##### Clone our repository and run the automated installer from your device. ### Clone our repository and run the automated installer from your device.
``` ```
git clone --depth 1 https://github.com/pi-hole/pi-hole.git Pi-hole git clone --depth 1 https://github.com/pi-hole/pi-hole.git Pi-hole
@ -53,91 +53,233 @@ wget -O basic-install.sh https://install.pi-hole.net
bash basic-install.sh bash basic-install.sh
``` ```
Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245) 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 Pi-hole™ as their DNS server. Once installed, [configure your router to have **DHCP clients use the Pi-hole as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245) and then any device that connects to your network will have ads blocked without any further configuration.
If your router does not support setting the DNS server, you can [use Pi-hole's built in DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026); just be sure to disable DHCP on your router first.
Alternatively, you can manually set each device to use Pi-hole as their DNS server.
## What is Pi-hole™ and how do I install it? # What is Pi-hole and how do I install it?
<p align="center"> <p align="center">
<a href=https://www.youtube.com/watch?v=vKWjx1AQYgs><img src="https://assets.pi-hole.net/static/video-explainer.png"></a> <a href=https://www.youtube.com/watch?v=vKWjx1AQYgs><img src="https://assets.pi-hole.net/static/video-explainer.png"></a>
</p> </p>
# Pi-hole Is Free, But Powered By Your Donations
## Get Help Or Connect With Us On The Web [Digital Ocean](http://www.digitalocean.com/?refcode=344d234950e1) helps with our infrastructure, but [our developers](https://github.com/orgs/pi-hole/people) are all volunteers so *your donations help keep us innovating*.
- [Users Forum](https://discourse.pi-hole.net/) - ![Paypal](https://assets.pi-hole.net/static/paypal.png) [Donate via PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY)
- [FAQs](https://discourse.pi-hole.net/c/faqs) - ![Bitcoin](https://assets.pi-hole.net/static/Bitcoin.png) Bitcoin Address: 1GKnevUnVaQM2pQieMyeHkpr8DXfkpfAtL
- [Wiki](https://github.com/pi-hole/pi-hole/wiki)
- ![Twitter](https://assets.pi-hole.net/static/twitter.png) [Tweet @The_Pi_Hole](https://twitter.com/The_Pi_Hole) ## Other Ways To Support Us
- ![Reddit](https://assets.pi-hole.net/static/reddit.png) [Reddit /r/pihole](https://www.reddit.com/r/pihole/) ### Affiliate Links
- ![YouTube](https://assets.pi-hole.net/static/youtube.png) [Pi-hole channel](https://www.youtube.com/channel/UCT5kq9w0wSjogzJb81C9U0w) If you'd rather not send money, there are [other ways to support us](https://pi-hole.net/donate): you can sign up for services through our affiliate links, which will also help us offset some of the costs associated with keeping Pi-hole operational; or you can support us in some non-tangible ways as listed below.
- [![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)
### Contributing Code Via Pull Requests
We don't work on Pi-hole for monetary reasons; we work on it because we think it's fun and we think our software is important in today's world. To that end, we welcome all contributors--from novices to masters.
If you feel you have some code to contribute, we're happy to take a look. Just make sure to fill out our template when submitting a pull request. We're all volunteers on the project and without all the information in the template, it's very difficult for us to quickly get the code merged in.
You'll find that the [install script](https://github.com/pi-hole/pi-hole/blob/master/automated%20install/basic-install.sh) and the [debug script](https://github.com/pi-hole/pi-hole/blob/master/advanced/Scripts/piholeDebug.sh) have an abundance of comments. These are two important scripts but we think they can also be a valuable resource to those who want to learn how to write scripts or code a program, which is why they are fully commented. So we encourage anyone who likes to tinker to read through it and submit a PR for us to review.
### Presenting About Pi-hole
## Technical Details Word-of-mouth has immensely helped our project grow. If you are going to be presenting about Pi-hole at a conference, meetup, or even for a school project, [get a hold of us for some free swag](https://pi-hole.net/2017/05/17/giving-a-presentation-on-pi-hole-contact-us-first-for-some-goodies-and-support/) to hand out to your audience.
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. # Overview Of Features
### Gravity ## The Dashboard (Web Interface)
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)). This script is controlled by the `pihole` command. Please run `pihole -h` to see what commands can be run via `pihole`. The [dashboard](https://github.com/pi-hole/AdminLTE#pi-hole-admin-dashboard) will (by default) be enabled during installation so you can view stats, change settings, and configure your Pi-hole.
![Pi-hole Dashboard](https://assets.pi-hole.net/static/dashboard.png)
There are several ways to [access the dashboard](https://discourse.pi-hole.net/t/how-do-i-access-pi-holes-dashboard-admin-interface/3168):
#### Other Operating Systems 1. `http://<IP_ADDPRESS_OF_YOUR_PI_HOLE>/admin/`
2. `http:/pi.hole/admin/` (when using Pi-hole as your DNS server)
3. `http://pi.hole/` (when using Pi-hole as your DNS server)
The automated install is only for a clean install of a Debian family or Fedora based system, such as the Raspberry Pi. However, this script will work for most UNIX-like systems, some with some slight **modifications** that we can help you work through. If you can install `dnsmasq` and a web server, it should work OK. If there are other platforms you'd like supported, let us know. ### The Query Log
### Web Interface If enabled, the query log will show all of the DNS queries requested by clients using Pi-hole as their DNS server. Forwarded domains will show in green, and blocked (_Pi-holed_) domains will show in red. You can also white or black list domains from within this section.
The [Web interface](https://github.com/pi-hole/AdminLTE#pi-hole-admin-dashboard) will be installed automatically so you can view stats and change settings. You can find it at: <p align="center">
<img src="https://assets.pi-hole.net/static/query_log.png">
</p>
The query log and graphs are what have helped people [discover what sort of traffic is traversing their networks](https://pi-hole.net/2017/07/06/round-3-what-really-happens-on-your-network/).
`http://192.168.1.x/admin/index.php` or `http://pi.hole/admin` #### Long-term Statistics
Using our Faster-Than-Light Engine ([FTL](https://github.com/pi-hole/FTL)), Pi-hole can store all of the domains queried in a database for retrieval or analysis later on. You can view this data as a graph, individual queries, or top clients/advertisers.
<p align="center">
<img src="https://assets.pi-hole.net/static/long-term-stats.png">
</p>
![Pi-hole Advanced Stats Dashboard](https://assets.pi-hole.net/static/dashboard212.png) ### Whitelist And Blacklist
### Whitelist and blacklist Domains can be [whitelisted](https://discourse.pi-hole.net/t/commonly-whitelisted-domains/212) and/or [blacklisted](https://discourse.pi-hole.net/t/commonly-blacklisted-domains/305) using either the dashboard or [the `pihole` command](https://discourse.pi-hole.net/t/the-pihole-command-with-examples/738).
Domains can be whitelisted and blacklisted using either the web interface or the command line. See [the wiki page](https://github.com/pi-hole/pi-hole/wiki/Whitelisting-and-Blacklisting) for more details
<p align="center"> <p align="center">
<a href=https://github.com/pi-hole/pi-hole/wiki/Whitelisting-and-Blacklisting><img src="https://assets.pi-hole.net/static/whitelist212.png"></a> <a href=https://github.com/pi-hole/pi-hole/wiki/Whitelisting-and-Blacklisting><img src="https://assets.pi-hole.net/static/whitelist.png"></a>
</p> </p>
#### Additional Blocklists
By default, Pi-hole blocks over 100,000 known ad-serving domains. You can expand the blocking power of your Pi-hole by [adding additional lists](https://discourse.pi-hole.net/t/how-do-i-add-additional-block-lists-to-pi-hole/259) such as the ones found on [The Big Blocklist Collection](https://wally3k.github.io/).
<p align="center">
<a href=https://discourse.pi-hole.net/t/how-do-i-add-additional-block-lists-to-pi-hole/259><img src="https://assets.pi-hole.net/static/manage-ad-lists.png"></a>
</p>
### Enable And Disable Pi-hole
Sometimes you may want to stop using Pi-hole or turn it back on. You can trigger this via the dashboard or command line.
<p align="center">
<img src="https://assets.pi-hole.net/static/enable-disable.png">
</p>
### Tools
<p align="center">
<img src="https://assets.pi-hole.net/static/tools.png">
</p>
#### Update Ad Lists
This runs `gravity` to download any newly-added domains from your source lists.
#### Query Ad Lists
You can find out what list a certain domain was on. This is useful for troubleshooting sites that may not work properly due to a blocked domain.
#### `tail`ing Log Files
You can [watch the log files](https://discourse.pi-hole.net/t/how-do-i-watch-and-interpret-the-pihole-log-file/276) in real time to help debug any issues, or just see what's happening with your Pi-hole.
#### Pi-hole Debugger
If you are having trouble with your Pi-hole, this is the place to go. You can run the debugger and it will attempt to diagnose any issues and then link to an FAQ with instructions on rectifying the problem.
<p align="center">
<img src="https://assets.pi-hole.net/static/debug-gui.png">
</p>
If run [via the command line](https://discourse.pi-hole.net/t/the-pihole-command-with-examples/738#debug), you will see red/yellow/green text, which makes it easy to identify any problems.
<p align="center">
<a href=https://discourse.pi-hole.net/t/the-pihole-command-with-examples/738#debugs><img src="https://assets.pi-hole.net/static/debug-cli.png"></a>
</p>
After the debugger has finished, you have the option to upload it to our secure server for 48 hours. All you need to do then is provide one of our developers the unique token generated by the debugger (this is usually done via [our forums](https://discourse.pi-hole.net/c/bugs-problems-issues)).
<p align="center">
<a href=https://discourse.pi-hole.net/t/the-pihole-command-with-examples/738#debugs><img src="https://assets.pi-hole.net/static/debug-token.png"></a>
</p>
However, most of the time, you will be able to solve any issues without any intervention from us. But if you can't, we're always around to help out.
### Settings ### Settings
The settings page lets you control and configure your Pi-hole™. You can do things like: The settings page lets you control and configure your Pi-hole. You can do things like:
- enable Pi-hole's built-in DHCP server - view networking information
- exclude domains from the graphs - flush logs or disable the logging of queries
- [enable Pi-hole's built-in DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026)
- [manage block lists](https://discourse.pi-hole.net/t/how-do-i-add-additional-block-lists-to-pi-hole/259)
- exclude domains from the graphs and enable privacy options
- configure upstream DNS servers - configure upstream DNS servers
- restart Pi-hole's services
- back up some of Pi-hole's important files
- and more! - and more!
![Settings page](https://assets.pi-hole.net/static/settings212.png) <p align="center">
<img src="https://assets.pi-hole.net/static/settings-page.png">
</p>
## Built-in DHCP Server
#### Built-in DHCP Server Pi-hole ships with a [built-in DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026). This allows you to let your network devices use Pi-hole as their DNS server if your router does not let you adjust the DHCP options.
One nice feature of using Pi-hole's DHCP server if you can set hostnames and DHCP reservations so you'll [see hostnames in the query log instead of IP addresses](https://discourse.pi-hole.net/t/how-do-i-show-hostnames-instead-of-ip-addresses-in-the-dashboard/3530). You can still do this without using Pi-hole's DHCP server; it just takes a little more work. If you do plan to use Pi-hole's DHCP server, be sure to disable DHCP on your router first.
Pi-hole™ ships with a built-in DHCP server. This allows you to let your network devices use Pi-hole™ as their DNS server if your router does not let you adjust the DHCP options.
<p align="center"> <p align="center">
<a href=hhttps://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245><img src="https://assets.pi-hole.net/static/piholedhcpserver.png"></a> <a href=https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026><img src="https://assets.pi-hole.net/static/piholedhcpserver.png"></a>
</p> </p>
## API ## The FTL Engine: Our API
A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON: A read-only API can be accessed at `admin/api.php` (the same output can be achieved on the CLI by running `pihole -c -j`).
It returns the following JSON:
``` json ``` json
{ {
"domains_being_blocked": "136708", "domains_being_blocked":111175,
"dns_queries_today": "18108", "dns_queries_today":15669,
"ads_blocked_today": "14648", "ads_blocked_today":1752,
"ads_percentage_today": "80.89" "ads_percentage_today":11.181314,
} "unique_domains":1178,
"queries_forwarded":9177,
"queries_cached":4740,
"unique_clients":18
}
``` ```
The same output can be achieved on the CLI by running `chronometer.sh -j` More details on the API can be found [here](https://discourse.pi-hole.net/t/pi-hole-api/1863) and on [the repo itself](https://github.com/pi-hole/FTL).
### Real-time Statistics, Courtesy Of The Time Cops
Using [chronometer2](https://github.com/pi-hole/pi-hole/blob/master/advanced/Scripts/chronometer.sh), you can view [real-time stats](https://discourse.pi-hole.net/t/how-do-i-view-my-pi-holes-stats-over-ssh-or-on-an-lcd-using-chronometer/240) via `ssh` or on an LCD screen such as the [2.8" LCD screen from Adafruit](http://amzn.to/1P0q1Fj).
Simply run `pihole -c` for some detailed information.
```
|¯¯¯(¯)__|¯|_ ___|¯|___ Pi-hole: v3.2
| ¯_/¯|__| ' \/ _ \ / -_) AdminLTE: v3.2
|_| |_| |_||_\___/_\___| FTL: v2.10
——————————————————————————————————————————————————————————
Hostname: pihole (Raspberry Pi 1, Model B)
Uptime: 11 days, 12:55:01
Task Load: 0.35 0.16 0.15 (Active: 5 of 33 tasks)
CPU usage: 48% (1 core @ 700 MHz, 47c)
RAM usage: 12% (Used: 54 MB of 434 MB)
HDD usage: 20% (Used: 1 GB of 7 GB)
LAN addr: 192.168.1.100 (Gateway: 192.168.1.1)
Pi-hole: Active (Blocking: 111175 sites)
Ads Today: 11% (1759 of 15812 queries)
Fwd DNS: 208.67.222.222 (Alt DNS: 3 others)
——————————————————————————————————————————————————————————
Recently blocked: www.google-analytics.com
Top Advertiser: www.example.org
Top Domain: www.example.org
Top Client: somehost
```
<p align="center">
<img src="https://assets.pi-hole.net/static/chrono1.jpg">
</p>
<p align="center">
<img src="https://assets.pi-hole.net/static/chrono2.jpg">
</p>
# Get Help Or Connect With Us On The Web
- [Users Forum](https://discourse.pi-hole.net/)
- [FAQs](https://discourse.pi-hole.net/c/faqs)
- [Feature requests](https://discourse.pi-hole.net/c/feature-requests?order=votes)
- [Wiki](https://github.com/pi-hole/pi-hole/wiki)
- [Facebook](https://www.facebook.com/ThePiHole/)
- ![Twitter](https://assets.pi-hole.net/static/twitter.png) [Tweet @The_Pi_Hole](https://twitter.com/The_Pi_Hole)
- ![Reddit](https://assets.pi-hole.net/static/reddit.png) [Reddit /r/pihole](https://www.reddit.com/r/pihole/)
- ![YouTube](https://assets.pi-hole.net/static/youtube.png) [Pi-hole channel](https://www.youtube.com/channel/UCT5kq9w0wSjogzJb81C9U0w)
- [![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
## Real-time Statistics To summarize into a short sentence, the Pi-hole is an **advertising-aware DNS/Web server**. And while quite outdated at this point, [this original blog post about Pi-hole](https://jacobsalmela.com/2015/06/16/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0/) goes into **great detail** about how it was setup and how it works. Syntactically, it's no longer accurate, but the same basic principles and logic still apply to Pi-hole's current state.
You can view [real-time stats](https://discourse.pi-hole.net/t/how-do-i-view-my-pi-holes-stats-over-ssh-or-on-an-lcd-using-chronometer/240) 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 Projects
- [An ad blocking Magic Mirror](https://zonksec.com/blog/magic-mirror-dns-filtering/#dnssoftware) - [An ad blocking Magic Mirror](https://zonksec.com/blog/magic-mirror-dns-filtering/#dnssoftware)
- [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py) - [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py)
@ -156,8 +298,9 @@ You can view [real-time stats](https://discourse.pi-hole.net/t/how-do-i-view-my-
- [Let your blink1 device blink when Pi-hole filters ads](https://gist.github.com/elpatron68/ec0b4c582e5abf604885ac1e068d233f) - [Let your blink1 device blink when Pi-hole filters ads](https://gist.github.com/elpatron68/ec0b4c582e5abf604885ac1e068d233f)
- [Pi-hole Prometheus exporter](https://github.com/nlamirault/pihole_exporter): a [Prometheus](https://prometheus.io/) exporter for Pi-hole - [Pi-hole Prometheus exporter](https://github.com/nlamirault/pihole_exporter): a [Prometheus](https://prometheus.io/) exporter for Pi-hole
- [Pi-hole Droid - open source Android client](https://github.com/friimaind/pi-hole-droid) - [Pi-hole Droid - open source Android client](https://github.com/friimaind/pi-hole-droid)
- [Windows DNS Swapper](https://github.com/roots84/DNS-Swapper), see [#1400](https://github.com/pi-hole/pi-hole/issues/1400)
## Coverage # Coverage
- [Adafruit livestream install](https://www.youtube.com/watch?v=eg4u2j1HYlI) - [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) - [TekThing: 5 fun, easy projects for a Raspberry Pi](https://youtu.be/QwrKlyC2kdM?t=1m42s)

@ -21,10 +21,13 @@
############################################################################### ###############################################################################
addn-hosts=/etc/pihole/gravity.list addn-hosts=/etc/pihole/gravity.list
addn-hosts=/etc/pihole/black.list
addn-hosts=/etc/pihole/local.list addn-hosts=/etc/pihole/local.list
domain-needed domain-needed
localise-queries
bogus-priv bogus-priv
no-resolv no-resolv

@ -0,0 +1,28 @@
if [[ -t 1 ]] && [[ $(tput colors) -ge 8 ]]; then
COL_NC=''
COL_WHITE=''
COL_BLACK=''
COL_BLUE=''
COL_LIGHT_BLUE=''
COL_GREEN=''
COL_LIGHT_GREEN=''
COL_CYAN=''
COL_LIGHT_CYAN=''
COL_RED=''
COL_LIGHT_RED=''
COL_URG_RED=''
COL_PURPLE=''
COL_LIGHT_PURPLE=''
COL_BROWN=''
COL_YELLOW=''
COL_GRAY=''
COL_LIGHT_GRAY=''
COL_DARK_GRAY=''
fi
TICK="[${COL_LIGHT_GREEN}✓${COL_NC}]"
CROSS="[${COL_LIGHT_RED}✗${COL_NC}]"
INFO="[i]"
QST="[?]"
DONE="${COL_LIGHT_GREEN} done!${COL_NC}"
OVER="\r\033[K"

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC1090,SC1091
# Pi-hole: A black hole for Internet advertisements # Pi-hole: A black hole for Internet advertisements
# (c) 2017 Pi-hole, LLC (https://pi-hole.net) # (c) 2017 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware. # Network-wide ad blocking via your own hardware.
@ -7,102 +8,565 @@
# #
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
LC_NUMERIC=C
#Functions############################################################################################################## # Retrieve stats from FTL engine
piLog="/var/log/pihole.log" pihole-FTL() {
gravity="/etc/pihole/gravity.list" ftl_port=$(cat /var/run/pihole-FTL.port 2> /dev/null)
if [[ -n "$ftl_port" ]]; then
. /etc/pihole/setupVars.conf
function GetFTLData {
# Open connection to FTL # Open connection to FTL
exec 3<>/dev/tcp/localhost/"$(cat /var/run/pihole-FTL.port)" exec 3<>"/dev/tcp/localhost/$ftl_port"
# Test if connection is open # Test if connection is open
if { >&3; } 2> /dev/null; then if { "true" >&3; } 2> /dev/null; then
# Send command to FTL # Send command to FTL
echo -e ">$1" >&3 echo -e ">$1" >&3
# Read input # Read input
read -r -t 1 LINE <&3 read -r -t 1 LINE <&3
until [ ! $? ] || [[ "$LINE" == *"EOM"* ]]; do until [[ ! $? ]] || [[ "$LINE" == *"EOM"* ]]; do
echo "$LINE" >&1 echo "$LINE" >&1
read -r -t 1 LINE <&3 read -r -t 1 LINE <&3
done done
# Close connection # Close connection
exec 3>&- exec 3>&-
exec 3<&- exec 3<&-
fi fi
else
echo "0"
fi
} }
outputJSON() { # Print spaces to align right-side additional text
get_summary_data printFunc() {
echo "{\"domains_being_blocked\":${domains_being_blocked_raw},\"dns_queries_today\":${dns_queries_today_raw},\"ads_blocked_today\":${ads_blocked_today_raw},\"ads_percentage_today\":${ads_percentage_today_raw}}" local text_last
title="$1"
title_len="${#title}"
text_main="$2"
text_main_nocol="$text_main"
if [[ "${text_main:0:1}" == "" ]]; then
text_main_nocol=$(sed 's/\[[0-9;]\{1,5\}m//g' <<< "$text_main")
fi
text_main_len="${#text_main_nocol}"
text_addn="$3"
if [[ "$text_addn" == "last" ]]; then
text_addn=""
text_last="true"
fi
# If there is additional text, define max length of text_main
if [[ -n "$text_addn" ]]; then
case "$scr_cols" in
[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-4]) text_main_max_len="9";;
4[5-9]) text_main_max_len="14";;
*) text_main_max_len="19";;
esac
fi
[[ -z "$text_addn" ]] && text_main_max_len="$(( scr_cols - title_len ))"
# Remove excess characters from main text
if [[ "$text_main_len" -gt "$text_main_max_len" ]]; then
# Trim text without colours
text_main_trim="${text_main_nocol:0:$text_main_max_len}"
# Replace with trimmed text
text_main="${text_main/$text_main_nocol/$text_main_trim}"
fi
# Determine amount of spaces for each line
if [[ -n "$text_last" ]]; then
# Move cursor to end of screen
spc_num=$(( scr_cols - ( title_len + text_main_len ) ))
else
spc_num=$(( text_main_max_len - text_main_len ))
fi
[[ "$spc_num" -le 0 ]] && spc_num="0"
spc=$(printf "%${spc_num}s")
#spc="${spc// /.}" # Debug: Visualise spaces
printf "%s%s$spc" "$title" "$text_main"
if [[ -n "$text_addn" ]]; then
printf "%s(%s)%s\\n" "$COL_NC$COL_DARK_GRAY" "$text_addn" "$COL_NC"
else
# Do not print trailing newline on final line
[[ -z "$text_last" ]] && printf "%s\\n" "$COL_NC"
fi
} }
get_summary_data() { # Perform on first Chrono run (not for JSON formatted string)
local summary=$(GetFTLData "stats") get_init_stats() {
domains_being_blocked_raw=$(grep "domains_being_blocked" <<< "${summary}" | grep -Eo "[0-9]+$") calcFunc(){ awk "BEGIN {print $*}" 2> /dev/null; }
domains_being_blocked=$(printf "%'.f" ${domains_being_blocked_raw})
dns_queries_today_raw=$(grep "dns_queries_today" <<< "$summary" | grep -Eo "[0-9]+$") # Convert bytes to human-readable format
dns_queries_today=$(printf "%'.f" ${dns_queries_today_raw}) hrBytes() {
ads_blocked_today_raw=$(grep "ads_blocked_today" <<< "$summary" | grep -Eo "[0-9]+$") awk '{
ads_blocked_today=$(printf "%'.f" ${ads_blocked_today_raw}) num=$1;
ads_percentage_today_raw=$(grep "ads_percentage_today" <<< "$summary" | grep -Eo "[0-9.]+$") if(num==0) {
LC_NUMERIC=C ads_percentage_today=$(printf "%'.f" ${ads_percentage_today_raw}) print "0 B"
} else {
xxx=(num<0?-num:num)
sss=(num<0?-1:1)
split("B KB MB GB TB PB",type)
for(i=5;yyy < 1;i--) {
yyy=xxx / (2^(10*i))
}
printf "%.0f " type[i+2], yyy*sss
}
}' <<< "$1";
}
# Convert seconds to human-readable format
hrSecs() {
day=$(( $1/60/60/24 )); hrs=$(( $1/3600%24 ))
mins=$(( ($1%3600)/60 )); secs=$(( $1%60 ))
[[ "$day" -ge "2" ]] && plu="s"
[[ "$day" -ge "1" ]] && days="$day day${plu}, " || days=""
printf "%s%02d:%02d:%02d\\n" "$days" "$hrs" "$mins" "$secs"
}
# Set Colour Codes
coltable="/opt/pihole/COL_TABLE"
if [[ -f "${coltable}" ]]; then
source ${coltable}
else
COL_NC=""
COL_DARK_GRAY=""
COL_LIGHT_GREEN=""
COL_LIGHT_BLUE=""
COL_LIGHT_RED=""
COL_YELLOW=""
COL_LIGHT_RED=""
COL_URG_RED=""
fi
# Get RPi throttle state (RPi 3B only) & model number, or OS distro info
if command -v vcgencmd &> /dev/null; then
local sys_throttle_raw
local sys_rev_raw
sys_throttle_raw=$(vgt=$(sudo vcgencmd get_throttled); echo "${vgt##*x}")
# Active Throttle Notice: http://bit.ly/2gnunOo
if [[ "$sys_throttle_raw" != "0" ]]; then
case "$sys_throttle_raw" in
*0001) thr_type="${COL_YELLOW}Under Voltage";;
*0002) thr_type="${COL_LIGHT_BLUE}Arm Freq Cap";;
*0003) thr_type="${COL_YELLOW}UV${COL_DARK_GRAY},${COL_NC} ${COL_LIGHT_BLUE}AFC";;
*0004) thr_type="${COL_LIGHT_RED}Throttled";;
*0005) thr_type="${COL_YELLOW}UV${COL_DARK_GRAY},${COL_NC} ${COL_LIGHT_RED}TT";;
*0006) thr_type="${COL_LIGHT_BLUE}AFC${COL_DARK_GRAY},${COL_NC} ${COL_LIGHT_RED}TT";;
*0007) thr_type="${COL_YELLOW}UV${COL_DARK_GRAY},${COL_NC} ${COL_LIGHT_BLUE}AFC${COL_DARK_GRAY},${COL_NC} ${COL_LIGHT_RED}TT";;
esac
[[ -n "$thr_type" ]] && sys_throttle="$thr_type${COL_DARK_GRAY}"
fi
sys_rev_raw=$(awk '/Revision/ {print $3}' < /proc/cpuinfo)
case "$sys_rev_raw" in
000[2-6]) sys_model=" 1, Model B";; # 256MB
000[7-9]) sys_model=" 1, Model A";; # 256MB
000d|000e|000f) sys_model=" 1, Model B";; # 512MB
0010|0013) sys_model=" 1, Model B+";; # 512MB
0012|0015) sys_model=" 1, Model A+";; # 256MB
a0104[0-1]|a21041|a22042) sys_model=" 2, Model B";; # 1GB
900021) sys_model=" 1, Model A+";; # 512MB
900032) sys_model=" 1, Model B+";; # 512MB
90009[2-3]|920093) sys_model=" Zero";; # 512MB
9000c1) sys_model=" Zero W";; # 512MB
a02082|a[2-3]2082) sys_model=" 3, Model B";; # 1GB
*) sys_model="";;
esac
sys_type="Raspberry Pi$sys_model"
else
source "/etc/os-release"
CODENAME=$(sed 's/[()]//g' <<< "${VERSION/* /}")
sys_type="${NAME/ */} ${CODENAME^} $VERSION_ID"
fi
# Get core count
sys_cores=$(grep -c "^processor" /proc/cpuinfo)
# Test existence of clock speed file for ARM CPU
if [[ -f "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]]; then
scaling_freq_file="/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
fi
# Test existence of temperature file
if [[ -f "/sys/class/thermal/thermal_zone0/temp" ]]; then
temp_file="/sys/class/thermal/thermal_zone0/temp"
elif [[ -f "/sys/class/hwmon/hwmon0/temp1_input" ]]; then
temp_file="/sys/class/hwmon/hwmon0/temp1_input"
else
temp_file=""
fi
# Test existence of setupVars config
if [[ -f "/etc/pihole/setupVars.conf" ]]; then
setupVars="/etc/pihole/setupVars.conf"
fi
} }
normalChrono() { get_sys_stats() {
for (( ; ; )); do local ph_ver_raw
get_summary_data local cpu_raw
domain=$(GetFTLData recentBlocked) local ram_raw
clear local disk_raw
# Displays a colorful Pi-hole logo
echo " ___ _ _ _" # Update every 12 refreshes (Def: every 60s)
echo "| _ (_)___| |_ ___| |___" count=$((count+1))
echo "| _/ |___| ' \/ _ \ / -_)" if [[ "$count" == "1" ]] || (( "$count" % 12 == 0 )); then
echo "|_| |_| |_||_\___/_\___|" # Do not source setupVars if file does not exist
echo "" [[ -n "$setupVars" ]] && source "$setupVars"
echo " ${IPV4_ADDRESS}"
echo "" mapfile -t ph_ver_raw < <(pihole -v -c 2> /dev/null | sed -n 's/^.* v/v/p')
uptime | cut -d' ' -f11- if [[ -n "${ph_ver_raw[0]}" ]]; then
#uptime -p #Doesn't work on all versions of uptime ph_core_ver="${ph_ver_raw[0]}"
uptime | awk -F'( |,|:)+' '{if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes."}' ph_lte_ver="${ph_ver_raw[1]}"
echo "-------------------------------" ph_ftl_ver="${ph_ver_raw[2]}"
echo "Recently blocked:" else
echo " $domain" ph_core_ver="-1"
fi
echo "Blocking: ${domains_being_blocked}"
echo "Queries: ${dns_queries_today}" sys_name=$(hostname)
echo "Pi-holed: ${ads_blocked_today} (${ads_percentage_today}%)"
[[ -n "$TEMPERATUREUNIT" ]] && temp_unit="$TEMPERATUREUNIT" || temp_unit="c"
sleep 5
done # Get storage stats for partition mounted on /
read -r -a disk_raw <<< "$(df -B1 / 2> /dev/null | awk 'END{ print $3,$2,$5 }')"
disk_used="${disk_raw[0]}"
disk_total="${disk_raw[1]}"
disk_perc="${disk_raw[2]}"
net_gateway=$(route -n | awk '$4 == "UG" {print $2;exit}')
# Get DHCP stats, if feature is enabled
if [[ "$DHCP_ACTIVE" == "true" ]]; then
ph_dhcp_max=$(( ${DHCP_END##*.} - ${DHCP_START##*.} + 1 ))
fi
# Get DNS server count
dns_count="0"
[[ -n "${PIHOLE_DNS_1}" ]] && dns_count=$((dns_count+1))
[[ -n "${PIHOLE_DNS_2}" ]] && dns_count=$((dns_count+1))
[[ -n "${PIHOLE_DNS_3}" ]] && dns_count=$((dns_count+1))
[[ -n "${PIHOLE_DNS_4}" ]] && dns_count=$((dns_count+1))
[[ -n "${PIHOLE_DNS_5}" ]] && dns_count=$((dns_count+1))
[[ -n "${PIHOLE_DNS_6}" ]] && dns_count=$((dns_count+1))
[[ -n "${PIHOLE_DNS_7}" ]] && dns_count=$((dns_count+1))
[[ -n "${PIHOLE_DNS_8}" ]] && dns_count=$((dns_count+1))
[[ -n "${PIHOLE_DNS_9}" ]] && dns_count="$dns_count+"
fi
# Get screen size
read -r -a scr_size <<< "$(stty size 2>/dev/null || echo 24 80)"
scr_lines="${scr_size[0]}"
scr_cols="${scr_size[1]}"
# Determine Chronometer size behaviour
if [[ "$scr_cols" -ge 58 ]]; then
chrono_width="large"
elif [[ "$scr_cols" -gt 40 ]]; then
chrono_width="medium"
else
chrono_width="small"
fi
# Determine max length of divider string
scr_line_len=$(( scr_cols - 2 ))
[[ "$scr_line_len" -ge 58 ]] && scr_line_len="58"
scr_line_str=$(printf "%${scr_line_len}s")
scr_line_str="${scr_line_str// /—}"
sys_uptime=$(hrSecs "$(cut -d. -f1 /proc/uptime)")
sys_loadavg=$(cut -d " " -f1,2,3 /proc/loadavg)
# Get CPU usage, only counting processes over 1% as active
# shellcheck disable=SC2009
cpu_raw=$(ps -eo pcpu,rss --no-headers | grep -E -v " 0")
cpu_tasks=$(wc -l <<< "$cpu_raw")
cpu_taskact=$(sed -r "/(^ 0.)/d" <<< "$cpu_raw" | wc -l)
cpu_perc=$(awk '{sum+=$1} END {printf "%.0f\n", sum/'"$sys_cores"'}' <<< "$cpu_raw")
# Get CPU clock speed
if [[ -n "$scaling_freq_file" ]]; then
cpu_mhz=$(( $(< /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) / 1000 ))
else
cpu_mhz=$(lscpu | awk -F ":" '/MHz/ {print $2;exit}')
cpu_mhz=$(printf "%.0f" "${cpu_mhz//[[:space:]]/}")
fi
# Determine whether to display CPU clock speed as MHz or GHz
if [[ -n "$cpu_mhz" ]]; then
[[ "$cpu_mhz" -le "999" ]] && cpu_freq="$cpu_mhz MHz" || cpu_freq="$(calcFunc "$cpu_mhz"/1000) GHz"
fi
# Determine colour for temperature
if [[ -n "$temp_file" ]]; then
if [[ "$temp_unit" == "C" ]]; then
cpu_temp=$(printf "%.0fc\\n" "$(calcFunc "$(< $temp_file) / 1000")")
case "${cpu_temp::-1}" in
-*|[0-9]|[1-3][0-9]) cpu_col="$COL_LIGHT_BLUE";;
4[0-9]) cpu_col="";;
5[0-9]) cpu_col="$COL_YELLOW";;
6[0-9]) cpu_col="$COL_LIGHT_RED";;
*) cpu_col="$COL_URG_RED";;
esac
# $COL_NC$COL_DARK_GRAY is needed for $COL_URG_RED
cpu_temp_str=" @ $cpu_col$cpu_temp$COL_NC$COL_DARK_GRAY"
elif [[ "$temp_unit" == "F" ]]; then
cpu_temp=$(printf "%.0ff\\n" "$(calcFunc "($(< $temp_file) / 1000) * 9 / 5 + 32")")
case "${cpu_temp::-1}" in
-*|[0-9]|[0-9][0-9]) cpu_col="$COL_LIGHT_BLUE";;
1[0-1][0-9]) cpu_col="";;
1[2-3][0-9]) cpu_col="$COL_YELLOW";;
1[4-5][0-9]) cpu_col="$COL_LIGHT_RED";;
*) cpu_col="$COL_URG_RED";;
esac
cpu_temp_str=" @ $cpu_col$cpu_temp$COL_NC$COL_DARK_GRAY"
else
cpu_temp_str=$(printf " @ %.0fk\\n" "$(calcFunc "($(< $temp_file) / 1000) + 273.15")")
fi
else
cpu_temp_str=""
fi
read -r -a ram_raw <<< "$(awk '/MemTotal:/{total=$2} /MemFree:/{free=$2} /Buffers:/{buffers=$2} /^Cached:/{cached=$2} END {printf "%.0f %.0f %.0f", (total-free-buffers-cached)*100/total, (total-free-buffers-cached)*1024, total*1024}' /proc/meminfo)"
ram_perc="${ram_raw[0]}"
ram_used="${ram_raw[1]}"
ram_total="${ram_raw[2]}"
if [[ "$(pihole status web 2> /dev/null)" == "1" ]]; then
ph_status="${COL_LIGHT_GREEN}Active"
else
ph_status="${COL_LIGHT_RED}Offline"
fi
if [[ "$DHCP_ACTIVE" == "true" ]]; then
local ph_dhcp_range
ph_dhcp_range=$(seq -s "|" -f "${DHCP_START%.*}.%g" "${DHCP_START##*.}" "${DHCP_END##*.}")
# Count dynamic leases from available range, and not static leases
ph_dhcp_num=$(grep -cE "$ph_dhcp_range" "/etc/pihole/dhcp.leases")
ph_dhcp_percent=$(( ph_dhcp_num * 100 / ph_dhcp_max ))
fi
}
get_ftl_stats() {
local stats_raw
mapfile -t stats_raw < <(pihole-FTL "stats")
domains_being_blocked_raw="${stats_raw[0]#* }"
dns_queries_today_raw="${stats_raw[1]#* }"
ads_blocked_today_raw="${stats_raw[2]#* }"
ads_percentage_today_raw="${stats_raw[3]#* }"
queries_forwarded_raw="${stats_raw[5]#* }"
queries_cached_raw="${stats_raw[6]#* }"
# Only retrieve these stats when not called from jsonFunc
if [[ -z "$1" ]]; then
local top_ad_raw
local top_domain_raw
local top_client_raw
domains_being_blocked=$(printf "%.0f\\n" "${domains_being_blocked_raw}")
dns_queries_today=$(printf "%.0f\\n" "${dns_queries_today_raw}")
ads_blocked_today=$(printf "%.0f\\n" "${ads_blocked_today_raw}")
ads_percentage_today=$(printf "%'.0f\\n" "${ads_percentage_today_raw}")
queries_cached_percentage=$(printf "%.0f\\n" "$(calcFunc "$queries_cached_raw * 100 / ( $queries_forwarded_raw + $queries_cached_raw )")")
recent_blocked=$(pihole-FTL recentBlocked)
read -r -a top_ad_raw <<< "$(pihole-FTL "top-ads (1)")"
read -r -a top_domain_raw <<< "$(pihole-FTL "top-domains (1)")"
read -r -a top_client_raw <<< "$(pihole-FTL "top-clients (1)")"
top_ad="${top_ad_raw[2]}"
top_domain="${top_domain_raw[2]}"
if [[ "${top_client_raw[3]}" ]]; then
top_client="${top_client_raw[3]}"
else
top_client="${top_client_raw[2]}"
fi
fi
}
get_strings() {
# Expand or contract strings depending on screen size
if [[ "$chrono_width" == "large" ]]; then
phc_str=" ${COL_DARK_GRAY}Pi-hole"
lte_str=" ${COL_DARK_GRAY}Admin"
ftl_str=" ${COL_DARK_GRAY}FTL"
api_str="${COL_LIGHT_RED}API Offline"
host_info="$sys_type"
sys_info="$sys_throttle"
sys_info2="Active: $cpu_taskact of $cpu_tasks tasks"
used_str="Used: "
leased_str="Leased: "
domains_being_blocked=$(printf "%'.0f" "$domains_being_blocked")
ads_blocked_today=$(printf "%'.0f" "$ads_blocked_today")
dns_queries_today=$(printf "%'.0f" "$dns_queries_today")
ph_info="Blocking: $domains_being_blocked sites"
total_str="Total: "
else
phc_str=" ${COL_DARK_GRAY}PH"
lte_str=" ${COL_DARK_GRAY}Web"
ftl_str=" ${COL_DARK_GRAY}FTL"
api_str="${COL_LIGHT_RED}API Down"
ph_info="$domains_being_blocked blocked"
fi
[[ "$sys_cores" -ne 1 ]] && sys_cores_txt="${sys_cores}x "
cpu_info="$sys_cores_txt$cpu_freq$cpu_temp_str"
ram_info="$used_str$(hrBytes "$ram_used") of $(hrBytes "$ram_total")"
disk_info="$used_str$(hrBytes "$disk_used") of $(hrBytes "$disk_total")"
lan_info="Gateway: $net_gateway"
dhcp_info="$leased_str$ph_dhcp_num of $ph_dhcp_max"
ads_info="$total_str$ads_blocked_today of $dns_queries_today"
dns_info="$dns_count DNS servers"
[[ "$recent_blocked" == "0" ]] && recent_blocked="${COL_LIGHT_RED}FTL offline${COL_NC}"
} }
displayHelp() { chronoFunc() {
cat << EOM get_init_stats
::: Displays stats about your piHole!
::: for (( ; ; )); do
::: Usage: sudo pihole -c [optional:-j] get_sys_stats
::: Note: If no option is passed, then stats are displayed on screen, updated every 5 seconds get_ftl_stats
::: get_strings
::: Options:
::: -j, --json output stats as JSON formatted string # Strip excess development version numbers
::: -h, --help display this help text if [[ "$ph_core_ver" != "-1" ]]; then
EOM phc_ver_str="$phc_str: ${ph_core_ver%-*}${COL_NC}"
exit 0 lte_ver_str="$lte_str: ${ph_lte_ver%-*}${COL_NC}"
ftl_ver_str="$ftl_str: ${ph_ftl_ver%-*}${COL_NC}"
else
phc_ver_str="$phc_str: $api_str${COL_NC}"
fi
# Get refresh number
if [[ "$*" == *"-r"* ]]; then
num="$*"
num="${num/*-r /}"
num="${num/ */}"
num_str="Refresh set for every $num seconds"
else
num_str=""
fi
clear
# Remove exit message heading on third refresh
if [[ "$count" -le 2 ]] && [[ "$*" != *"-e"* ]]; then
echo -e " ${COL_LIGHT_GREEN}Pi-hole Chronometer${COL_NC}
$num_str
${COL_LIGHT_RED}Press Ctrl-C to exit${COL_NC}
${COL_DARK_GRAY}$scr_line_str${COL_NC}"
else
echo -e "|¯¯¯(¯)_|¯|_ ___|¯|___$phc_ver_str
| ¯_/¯|_| ' \\/ _ \\ / -_)$lte_ver_str
|_| |_| |_||_\\___/_\\___|$ftl_ver_str
${COL_DARK_GRAY}$scr_line_str${COL_NC}"
fi
printFunc " Hostname: " "$sys_name" "$host_info"
printFunc " Uptime: " "$sys_uptime" "$sys_info"
printFunc " Task Load: " "$sys_loadavg" "$sys_info2"
printFunc " CPU usage: " "$cpu_perc%" "$cpu_info"
printFunc " RAM usage: " "$ram_perc%" "$ram_info"
printFunc " HDD usage: " "$disk_perc" "$disk_info"
if [[ "$scr_lines" -gt 17 ]] && [[ "$chrono_width" != "small" ]]; then
printFunc " LAN addr: " "${IPV4_ADDRESS/\/*/}" "$lan_info"
fi
if [[ "$DHCP_ACTIVE" == "true" ]]; then
printFunc "DHCP usage: " "$ph_dhcp_percent%" "$dhcp_info"
fi
printFunc " Pi-hole: " "$ph_status" "$ph_info"
printFunc " Ads Today: " "$ads_percentage_today%" "$ads_info"
printFunc "Local Qrys: " "$queries_cached_percentage%" "$dns_info"
printFunc " Blocked: " "$recent_blocked"
printFunc "Top Advert: " "$top_ad"
# Provide more stats on screens with more lines
if [[ "$scr_lines" -eq 17 ]]; then
if [[ "$DHCP_ACTIVE" == "true" ]]; then
printFunc "Top Domain: " "$top_domain" "last"
else
print_client="true"
fi
else
print_client="true"
fi
if [[ -n "$print_client" ]]; then
printFunc "Top Domain: " "$top_domain"
printFunc "Top Client: " "$top_client" "last"
fi
# Handle exit/refresh options
if [[ "$*" == *"-e"* ]]; then
exit 0
else
if [[ "$*" == *"-r"* ]]; then
sleep "$num"
else
sleep 5
fi
fi
done
}
jsonFunc() {
get_ftl_stats "json"
echo "{\"domains_being_blocked\":${domains_being_blocked_raw},\"dns_queries_today\":${dns_queries_today_raw},\"ads_blocked_today\":${ads_blocked_today_raw},\"ads_percentage_today\":${ads_percentage_today_raw}}"
}
helpFunc() {
if [[ "$1" == "?" ]]; then
echo "Unknown option. Please view 'pihole -c --help' for more information"
else
echo "Usage: pihole -c [options]
Example: 'pihole -c -j'
Calculates stats and displays to an LCD
Options:
-j, --json Output stats as JSON formatted string
-r, --refresh Set update frequency (in seconds)
-e, --exit Output stats and exit witout refreshing
-h, --help Display this help text"
fi
exit 0
} }
if [[ $# = 0 ]]; then if [[ $# = 0 ]]; then
normalChrono chronoFunc
fi fi
for var in "$@"; do for var in "$@"; do
case "$var" in case "$var" in
"-j" | "--json" ) outputJSON;; "-j" | "--json" ) jsonFunc;;
"-h" | "--help" ) displayHelp;; "-h" | "--help" ) helpFunc;;
* ) exit 1;; "-r" | "--refresh" ) chronoFunc "$@";;
esac "-e" | "--exit" ) chronoFunc "$@";;
* ) helpFunc "?";;
esac
done done

@ -3,14 +3,12 @@
# (c) 2017 Pi-hole, LLC (https://pi-hole.net) # (c) 2017 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware. # Network-wide ad blocking via your own hardware.
# #
# Whitelists and blacklists domains # Whitelist and blacklist domains
# #
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
# Globals
#globals
basename=pihole basename=pihole
piholeDir=/etc/${basename} piholeDir=/etc/${basename}
whitelist=${piholeDir}/whitelist.txt whitelist=${piholeDir}/whitelist.txt
@ -26,209 +24,225 @@ domToRemoveList=()
listMain="" listMain=""
listAlt="" listAlt=""
helpFunc() { colfile="/opt/pihole/COL_TABLE"
source ${colfile}
if [[ ${listMain} == ${whitelist} ]]; then
letter="w"
word="white"
else
letter="b"
word="black"
fi
cat << EOM helpFunc() {
::: Immediately ${word}lists one or more domains in the hosts file if [[ "${listMain}" == "${whitelist}" ]]; then
::: param="w"
::: Usage: pihole -${letter} domain1 [domain2 ...] type="white"
::: elif [[ "${listMain}" == "${wildcardlist}" ]]; then
::: Options: param="wild"
::: -d, --delmode Remove domains from the ${word}list type="wildcard black"
::: -nr, --noreload Update ${word}list without refreshing dnsmasq else
::: -q, --quiet Output is less verbose param="b"
::: -h, --help Show this help dialog type="black"
::: -l, --list Display your ${word}listed domains fi
EOM
if [[ "${letter}" == "b" ]]; then echo "Usage: pihole -${param} [options] <domain> <domain2 ...>
echo "::: -wild, --wildcard Add wildcard entry (only blacklist)" Example: 'pihole -${param} site.com', or 'pihole -${param} site1.com site2.com'
fi ${type^}list one or more domains
exit 0
Options:
-d, --delmode Remove domain(s) from the ${type}list
-nr, --noreload Update ${type}list without refreshing dnsmasq
-q, --quiet Make output less verbose
-h, --help Show this help dialog
-l, --list Display all your ${type}listed domains"
exit 0
} }
EscapeRegexp() { EscapeRegexp() {
# This way we may safely insert an arbitrary # This way we may safely insert an arbitrary
# string in our regular expressions # string in our regular expressions
# Also remove leading "." if present # Also remove leading "." if present
echo $* | sed 's/^\.*//' | sed "s/[]\.|$(){}?+*^]/\\\\&/g" | sed "s/\\//\\\\\//g" echo $* | sed 's/^\.*//' | sed "s/[]\.|$(){}?+*^]/\\\\&/g" | sed "s/\\//\\\\\//g"
} }
HandleOther(){ HandleOther() {
# First, convert everything to lowercase # Convert to lowercase
domain=$(sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" <<< "$1") domain="${1,,}"
#check validity of domain # 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}/') validDomain=$(perl -lne 'print if /^((-|_)*[a-z\d]((-|_)*[a-z\d])*(-|_)*)(\.(-|_)*([a-z\d]((-|_)*[a-z\d])*))*$/' <<< "${domain}") # Valid chars check
if [ -z "${validDomain}" ]; then validDomain=$(perl -lne 'print if /^.{1,253}$/' <<< "${validDomain}") # Overall length check
echo "::: $1 is not a valid argument or domain name" validDomain=$(perl -lne 'print if /^[^\.]{1,63}(\.[^\.]{1,63})*$/' <<< "${validDomain}") # Length of each label
else
domList=("${domList[@]}" ${validDomain}) if [[ -z "${validDomain}" ]]; then
fi echo -e " ${CROSS} $1 is not a valid argument or domain name!"
else
echo -e " ${TICK} $1 is a valid domain name!"
domList=("${domList[@]}" ${validDomain})
fi
} }
PoplistFile() { PoplistFile() {
#check whitelist file exists, and if not, create it # Check whitelist file exists, and if not, create it
if [[ ! -f ${whitelist} ]]; then if [[ ! -f ${whitelist} ]]; then
touch ${whitelist} touch ${whitelist}
fi 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 for dom in "${domList[@]}"; do
if ${addmode}; then # 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
AddDomain "${dom}" "${listMain}" if ${addmode}; then
RemoveDomain "${dom}" "${listAlt}" AddDomain "${dom}" "${listMain}"
if [[ "${listMain}" == "${whitelist}" || "${listMain}" == "${blacklist}" ]]; then RemoveDomain "${dom}" "${listAlt}"
RemoveDomain "${dom}" "${wildcardlist}" if [[ "${listMain}" == "${whitelist}" || "${listMain}" == "${blacklist}" ]]; then
fi RemoveDomain "${dom}" "${wildcardlist}"
else fi
RemoveDomain "${dom}" "${listMain}" else
fi RemoveDomain "${dom}" "${listMain}"
done fi
done
} }
AddDomain() { AddDomain() {
list="$2" list="$2"
domain=$(EscapeRegexp "$1") domain=$(EscapeRegexp "$1")
if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then [[ "${list}" == "${whitelist}" ]] && listname="whitelist"
[[ "${list}" == "${blacklist}" ]] && listname="blacklist"
bool=true [[ "${list}" == "${wildcardlist}" ]] && listname="wildcard blacklist"
#Is the domain in the list we want to add it to?
grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then
bool=true
if [[ "${bool}" == false ]]; then # Is the domain in the list we want to add it to?
#domain not found in the whitelist file, add it! grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false
if [[ "${verbose}" == true ]]; then
echo "::: Adding $1 to $list..." if [[ "${bool}" == false ]]; then
fi # Domain not found in the whitelist file, add it!
reload=true if [[ "${verbose}" == true ]]; then
# Add it to the list we want to add it to echo -e " ${INFO} Adding $1 to $listname..."
echo "$1" >> "${list}" fi
else reload=true
if [[ "${verbose}" == true ]]; then # Add it to the list we want to add it to
echo "::: ${1} already exists in ${list}, no need to add!" echo "$1" >> "${list}"
fi else
fi if [[ "${verbose}" == true ]]; then
echo -e " ${INFO} ${1} already exists in ${listname}, no need to add!"
elif [[ "${list}" == "${wildcardlist}" ]]; then fi
fi
source "${piholeDir}/setupVars.conf" elif [[ "${list}" == "${wildcardlist}" ]]; then
#Remove the /* from the end of the IPv4addr. source "${piholeDir}/setupVars.conf"
IPV4_ADDRESS=${IPV4_ADDRESS%/*} # Remove the /* from the end of the IP addresses
IPV6_ADDRESS=${IPV6_ADDRESS} IPV4_ADDRESS=${IPV4_ADDRESS%/*}
IPV6_ADDRESS=${IPV6_ADDRESS%/*}
bool=true
#Is the domain in the list? bool=true
grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false # 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 if [[ "${bool}" == false ]]; then
echo "::: Adding $1 to wildcard blacklist..." if [[ "${verbose}" == true ]]; then
fi echo -e " ${INFO} Adding $1 to wildcard blacklist..."
reload=true fi
echo "address=/$1/${IPV4_ADDRESS}" >> "${wildcardlist}" reload=true
if [[ ${#IPV6_ADDRESS} > 0 ]] ; then echo "address=/$1/${IPV4_ADDRESS}" >> "${wildcardlist}"
echo "address=/$1/${IPV6_ADDRESS}" >> "${wildcardlist}" if [[ "${#IPV6_ADDRESS}" > 0 ]]; then
fi echo "address=/$1/${IPV6_ADDRESS}" >> "${wildcardlist}"
else fi
if [[ "${verbose}" == true ]]; then else
echo "::: ${1} already exists in wildcard blacklist, no need to add!" if [[ "${verbose}" == true ]]; then
fi echo -e " ${INFO} ${1} already exists in wildcard blacklist, no need to add!"
fi fi
fi fi
fi
} }
RemoveDomain() { RemoveDomain() {
list="$2" list="$2"
domain=$(EscapeRegexp "$1") domain=$(EscapeRegexp "$1")
if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then [[ "${list}" == "${whitelist}" ]] && listname="whitelist"
[[ "${list}" == "${blacklist}" ]] && listname="blacklist"
bool=true [[ "${list}" == "${wildcardlist}" ]] && listname="wildcard blacklist"
#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 [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then
if [[ "${bool}" == true ]]; then bool=true
# Remove it from the other one # Is it in the list? Logic follows that if its whitelisted it should not be blacklisted and vice versa
echo "::: Removing $1 from $list..." grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false
# /I flag: search case-insensitive if [[ "${bool}" == true ]]; then
sed -i "/${domain}/Id" "${list}" # Remove it from the other one
reload=true echo -e " ${INFO} Removing $1 from $listname..."
else # /I flag: search case-insensitive
if [[ "${verbose}" == true ]]; then sed -i "/${domain}/Id" "${list}"
echo "::: ${1} does not exist in ${list}, no need to remove!" reload=true
fi else
fi if [[ "${verbose}" == true ]]; then
echo -e " ${INFO} ${1} does not exist in ${listname}, no need to remove!"
elif [[ "${list}" == "${wildcardlist}" ]]; then fi
fi
bool=true elif [[ "${list}" == "${wildcardlist}" ]]; then
#Is it in the list? bool=true
grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false # Is it in the list?
if [[ "${bool}" == true ]]; then grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false
# Remove it from the other one if [[ "${bool}" == true ]]; then
echo "::: Removing $1 from $list..." # Remove it from the other one
# /I flag: search case-insensitive echo -e " ${INFO} Removing $1 from $listname..."
sed -i "/address=\/${domain}/Id" "${list}" # /I flag: search case-insensitive
reload=true sed -i "/address=\/${domain}/Id" "${list}"
else reload=true
if [[ "${verbose}" == true ]]; then else
echo "::: ${1} does not exist in ${list}, no need to remove!" if [[ "${verbose}" == true ]]; then
fi echo -e " ${INFO} ${1} does not exist in ${listname}, no need to remove!"
fi fi
fi fi
fi
} }
Reload() { Reload() {
# Reload hosts file # Reload hosts file
pihole -g -sd echo ""
echo -e " ${INFO} Updating gravity..."
echo ""
pihole -g -sd
} }
Displaylist() { Displaylist() {
if [[ ${listMain} == ${whitelist} ]]; then if [[ -f ${listMain} ]]; then
string="gravity resistant domains" if [[ "${listMain}" == "${whitelist}" ]]; then
string="gravity resistant domains"
else else
string="domains caught in the sinkhole" string="domains caught in the sinkhole"
fi fi
verbose=false verbose=false
echo -e " Displaying $string \n" echo -e "Displaying $string:\n"
count=1 count=1
while IFS= read -r RD; do while IFS= read -r RD; do
echo "${count}: ${RD}" echo " ${count}: ${RD}"
count=$((count+1)) count=$((count+1))
done < "${listMain}" done < "${listMain}"
exit 0; else
echo -e " ${COL_LIGHT_RED}${listMain} does not exist!${COL_NC}"
fi
exit 0;
} }
for var in "$@"; do for var in "$@"; do
case "${var}" in case "${var}" in
"-w" | "whitelist" ) listMain="${whitelist}"; listAlt="${blacklist}";; "-w" | "whitelist" ) listMain="${whitelist}"; listAlt="${blacklist}";;
"-b" | "blacklist" ) listMain="${blacklist}"; listAlt="${whitelist}";; "-b" | "blacklist" ) listMain="${blacklist}"; listAlt="${whitelist}";;
"-wild" | "wildcard" ) listMain="${wildcardlist}";; "-wild" | "wildcard" ) listMain="${wildcardlist}";;
"-nr"| "--noreload" ) reload=false;; "-nr"| "--noreload" ) reload=false;;
"-d" | "--delmode" ) addmode=false;; "-d" | "--delmode" ) addmode=false;;
"-f" | "--force" ) force=true;; "-f" | "--force" ) force=true;;
"-q" | "--quiet" ) verbose=false;; "-q" | "--quiet" ) verbose=false;;
"-h" | "--help" ) helpFunc;; "-h" | "--help" ) helpFunc;;
"-l" | "--list" ) Displaylist;; "-l" | "--list" ) Displaylist;;
* ) HandleOther "${var}";; * ) HandleOther "${var}";;
esac esac
done done
shift shift
if [[ $# = 0 ]]; then if [[ $# = 0 ]]; then
helpFunc helpFunc
fi fi
PoplistFile PoplistFile
if ${reload}; then if ${reload}; then
Reload Reload
fi fi

@ -3,13 +3,14 @@
# (c) 2017 Pi-hole, LLC (https://pi-hole.net) # (c) 2017 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware. # Network-wide ad blocking via your own hardware.
# #
# Checkout other branches than master # Switch Pi-hole subsystems to a different Github branch.
# #
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
readonly PI_HOLE_FILES_DIR="/etc/.pihole" readonly PI_HOLE_FILES_DIR="/etc/.pihole"
PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" PH_TEST="true"
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
# webInterfaceGitUrl set in basic-install.sh # webInterfaceGitUrl set in basic-install.sh
# webInterfaceDir set in basic-install.sh # webInterfaceDir set in basic-install.sh
@ -18,9 +19,103 @@ PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
# setupVars set in basic-install.sh # setupVars set in basic-install.sh
source "${setupVars}" source "${setupVars}"
update="false" update="false"
coltable="/opt/pihole/COL_TABLE"
source ${coltable}
check_download_exists() {
status=$(curl --head --silent "https://ftl.pi-hole.net/${1}" | head -n 1)
if grep -q "404" <<< "$status"; then
return 1
else
return 0
fi
}
FTLinstall() {
# Download and install FTL binary
local binary
binary="${1}"
local path
path="${2}"
local str
str="Installing FTL"
echo -ne " ${INFO} ${str}..."
if curl -sSL --fail "https://ftl.pi-hole.net/${path}" -o "/tmp/${binary}"; then
# Get sha1 of the binary we just downloaded for verification.
curl -sSL --fail "https://ftl.pi-hole.net/${path}.sha1" -o "/tmp/${binary}.sha1"
# Check if we just downloaded text, or a binary file.
cd /tmp || return 1
if sha1sum --status --quiet -c "${binary}".sha1; then
echo -n "transferred... "
stop_service pihole-FTL &> /dev/null
install -T -m 0755 "/tmp/${binary}" "/usr/bin/pihole-FTL"
rm "/tmp/${binary}" "/tmp/${binary}.sha1"
start_service pihole-FTL &> /dev/null
echo -e "${OVER} ${TICK} ${str}"
return 0
else
echo -e "${OVER} ${CROSS} ${str}"
echo -e " ${COL_LIGHT_RED}Error: Download of binary from ftl.pi-hole.net failed${COL_NC}"
return 1
fi
else
echo -e "${OVER} ${CROSS} ${str}"
echo -e " ${COL_LIGHT_RED}Error: URL not found${COL_NC}"
fi
}
get_binary_name() {
local machine
machine=$(uname -m)
local str
str="Detecting architecture"
echo -ne " ${INFO} ${str}..."
if [[ "${machine}" == "arm"* || "${machine}" == *"aarch"* ]]; then
# ARM
local rev
rev=$(uname -m | sed "s/[^0-9]//g;")
local lib
lib=$(ldd /bin/ls | grep -E '^\s*/lib' | awk '{ print $1 }')
if [[ "${lib}" == "/lib/ld-linux-aarch64.so.1" ]]; then
echo -e "${OVER} ${TICK} Detected ARM-aarch64 architecture"
binary="pihole-FTL-aarch64-linux-gnu"
elif [[ "${lib}" == "/lib/ld-linux-armhf.so.3" ]]; then
if [[ "$rev" -gt "6" ]]; then
echo -e "${OVER} ${TICK} Detected ARM-hf architecture (armv7+)"
binary="pihole-FTL-arm-linux-gnueabihf"
else
echo -e "${OVER} ${TICK} Detected ARM-hf architecture (armv6 or lower) Using ARM binary"
binary="pihole-FTL-arm-linux-gnueabi"
fi
else
echo -e "${OVER} ${TICK} Detected ARM architecture"
binary="pihole-FTL-arm-linux-gnueabi"
fi
elif [[ "${machine}" == "ppc" ]]; then
# PowerPC
echo -e "${OVER} ${TICK} Detected PowerPC architecture"
binary="pihole-FTL-powerpc-linux-gnu"
elif [[ "${machine}" == "x86_64" ]]; then
# 64bit
echo -e "${OVER} ${TICK} Detected x86_64 architecture"
binary="pihole-FTL-linux-x86_64"
else
# Something else - we try to use 32bit executable and warn the user
if [[ ! "${machine}" == "i686" ]]; then
echo -e "${OVER} ${CROSS} ${str}...
${COL_LIGHT_RED}Not able to detect architecture (unknown: ${machine}), trying 32bit executable
Contact support if you experience issues (e.g: FTL not running)${COL_NC}"
else
echo -e "${OVER} ${TICK} Detected 32bit (i686) architecture"
fi
binary="pihole-FTL-linux-x86_32"
fi
}
fully_fetch_repo() { fully_fetch_repo() {
# Add upstream branches to shallow clone # Add upstream branches to shallow clone
local directory="${1}" local directory="${1}"
@ -35,91 +130,105 @@ fully_fetch_repo() {
return 0 return 0
} }
get_available_branches(){ get_available_branches() {
# Return available branches # Return available branches
local directory="${1}" local directory
directory="${1}"
local output
cd "${directory}" || return 1 cd "${directory}" || return 1
# Get reachable remote branches # Get reachable remote branches, but store STDERR as STDOUT variable
git remote show origin | grep 'tracked' | sed 's/tracked//;s/ //g' output=$( { git remote show origin | grep 'tracked' | sed 's/tracked//;s/ //g'; } 2>&1 )
echo "$output"
return return
} }
fetch_checkout_pull_branch() { fetch_checkout_pull_branch() {
# Check out specified branch # Check out specified branch
local directory="${1}" local directory
local branch="${2}" directory="${1}"
local branch
branch="${2}"
# Set the reference for the requested branch, fetch, check it put and pull it # Set the reference for the requested branch, fetch, check it put and pull it
cd "${directory}" cd "${directory}" || return 1
git remote set-branches origin "${branch}" || return 1 git remote set-branches origin "${branch}" || return 1
git stash --all --quiet &> /dev/null || true
git clean --quiet --force -d || true
git fetch --quiet || return 1 git fetch --quiet || return 1
checkout_pull_branch "${directory}" "${branch}" || return 1 checkout_pull_branch "${directory}" "${branch}" || return 1
} }
checkout_pull_branch() { checkout_pull_branch() {
# Check out specified branch # Check out specified branch
local directory="${1}" local directory
local branch="${2}" directory="${1}"
local branch
branch="${2}"
local oldbranch local oldbranch
cd "${directory}" || return 1 cd "${directory}" || return 1
oldbranch="$(git symbolic-ref HEAD)" oldbranch="$(git symbolic-ref HEAD)"
git checkout "${branch}" || return 1 git checkout "${branch}" --quiet || return 1
if [ "$(git diff "${oldbranch}" | grep -c "^")" -gt "0" ]; then if [[ "$(git diff "${oldbranch}" | grep -c "^")" -gt "0" ]]; then
update="true" update="true"
fi fi
git pull || return 1 git_pull=$(git pull || return 1)
if [[ "$git_pull" == *"up-to-date"* ]]; then
echo -e " ${INFO} $(git pull)"
else
echo -e "$git_pull\\n"
fi
return 0 return 0
} }
warning1() { warning1() {
echo "::: Note that changing the branch is a severe change of your Pi-hole system." echo " Please note that changing branches severely alters your Pi-hole subsystems"
echo "::: This is not supported unless one of the developers explicitly asks you to do this!" echo " Features that work on the master branch, may not on a development branch"
read -r -p "::: Have you read and understood this? [y/N] " response echo -e " ${COL_LIGHT_RED}This feature is NOT supported unless a Pi-hole developer explicitly asks!${COL_NC}"
case ${response} in read -r -p " Have you read and understood this? [y/N] " response
case "${response}" in
[yY][eE][sS]|[yY]) [yY][eE][sS]|[yY])
echo "::: Continuing." echo ""
return 0 return 0
;; ;;
*) *)
echo "::: Aborting." echo -e "\\n ${INFO} Branch change has been cancelled"
return 1 return 1
;; ;;
esac esac
} }
checkout() checkout() {
{
local corebranches local corebranches
local webbranches local webbranches
# Avoid globbing # Avoid globbing
set -f set -f
#This is unlikely # This is unlikely
if ! is_repo "${PI_HOLE_FILES_DIR}" ; then if ! is_repo "${PI_HOLE_FILES_DIR}" ; then
echo "::: Critical Error: Core Pi-hole repo is missing from system!" echo -e " ${COL_LIGHT_RED}Error: Core Pi-hole repo is missing from system!
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}"
exit 1; exit 1;
fi fi
if [[ ${INSTALL_WEB} == "true" ]]; then if [[ "${INSTALL_WEB}" == "true" ]]; then
if ! is_repo "${webInterfaceDir}" ; then if ! is_repo "${webInterfaceDir}" ; then
echo "::: Critical Error: Web Admin repo is missing from system!" echo -e " ${COL_LIGHT_RED}Error: Web Admin repo is missing from system!
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}"
exit 1; exit 1;
fi fi
fi fi
if [[ -z "${1}" ]]; then if [[ -z "${1}" ]]; then
echo "::: No option detected. Please use 'pihole checkout <master|dev>'." echo -e " ${COL_LIGHT_RED}Invalid option${COL_NC}
echo "::: Or enter the repository and branch you would like to check out:" Try 'pihole checkout --help' for more information."
echo "::: 'pihole checkout <web|core> <branchname>'"
exit 1 exit 1
fi fi
@ -129,74 +238,118 @@ checkout()
if [[ "${1}" == "dev" ]] ; then if [[ "${1}" == "dev" ]] ; then
# Shortcut to check out development branches # Shortcut to check out development branches
echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo -e " ${INFO} Shortcut \"dev\" detected - checking out development / devel branches..."
echo "::: Pi-hole core" echo ""
fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } echo -e " ${INFO} Pi-hole Core"
if [[ ${INSTALL_WEB} == "true" ]]; then fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo " ${CROSS} Unable to pull Core developement branch"; exit 1; }
echo "::: Web interface" if [[ "${INSTALL_WEB}" == "true" ]]; then
fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } echo ""
echo -e " ${INFO} Web interface"
fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo " ${CROSS} Unable to pull Web development branch"; exit 1; }
fi fi
echo "::: done!" #echo -e " ${TICK} Pi-hole Core"
get_binary_name
local path
path="development/${binary}"
FTLinstall "${binary}" "${path}"
elif [[ "${1}" == "master" ]] ; then elif [[ "${1}" == "master" ]] ; then
# Shortcut to check out master branches # Shortcut to check out master branches
echo "::: Shortcut \"master\" detected - checking out master branches ..." echo -e " ${INFO} Shortcut \"master\" detected - checking out master branches..."
echo "::: Pi-hole core" echo -e " ${INFO} Pi-hole core"
fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo " ${CROSS} Unable to pull Core master branch"; exit 1; }
if [[ ${INSTALL_WEB} == "true" ]]; then if [[ ${INSTALL_WEB} == "true" ]]; then
echo "::: Web interface" echo -e " ${INFO} Web interface"
fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo " ${CROSS} Unable to pull Web master branch"; exit 1; }
fi fi
echo "::: done!" #echo -e " ${TICK} Web Interface"
get_binary_name
local path
path="master/${binary}"
FTLinstall "${binary}" "${path}"
elif [[ "${1}" == "core" ]] ; then elif [[ "${1}" == "core" ]] ; then
echo -n "::: Fetching remote branches for Pi-hole core from ${piholeGitUrl} ... " str="Fetching branches from ${piholeGitUrl}"
echo -ne " ${INFO} $str"
if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then
echo "::: Fetching all branches for Pi-hole core repo failed!" echo -e " ${CROSS} $str"
exit 1 exit 1
fi fi
corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}")) corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}"))
echo " done!"
echo "::: ${#corebranches[@]} branches available" if [[ "${corebranches[*]}" == *"master"* ]]; then
echo ":::" echo -e "${OVER} ${TICK} $str
# Have to user chosing the branch he wants ${INFO} ${#corebranches[@]} branches available for Pi-hole Core"
else
# Print STDERR output from get_available_branches
echo -e "${OVER} ${CROSS} $str\\n\\n${corebranches[*]}"
exit 1
fi
echo ""
# Have the user choose the branch they want
if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then
echo "::: Requested branch \"${2}\" is not available!" echo -e " ${INFO} Requested branch \"${2}\" is not available"
echo "::: Available branches for core are:" echo -e " ${INFO} Available branches for Core are:"
for e in "${corebranches[@]}"; do echo "::: $e"; done for e in "${corebranches[@]}"; do echo " - $e"; done
exit 1 exit 1
fi fi
checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}"
elif [[ "${1}" == "web" && "${INSTALL_WEB}" == "true" ]] ; then elif [[ "${1}" == "web" ]] && [[ "${INSTALL_WEB}" == "true" ]] ; then
echo -n "::: Fetching remote branches for the web interface from ${webInterfaceGitUrl} ... " str="Fetching branches from ${webInterfaceGitUrl}"
echo -ne " ${INFO} $str"
if ! fully_fetch_repo "${webInterfaceDir}" ; then if ! fully_fetch_repo "${webInterfaceDir}" ; then
echo "::: Fetching all branches for Pi-hole web interface repo failed!" echo -e " ${CROSS} $str"
exit 1 exit 1
fi fi
webbranches=($(get_available_branches "${webInterfaceDir}")) webbranches=($(get_available_branches "${webInterfaceDir}"))
echo " done!"
echo "::: ${#webbranches[@]} branches available" if [[ "${webbranches[*]}" == *"master"* ]]; then
echo ":::" echo -e "${OVER} ${TICK} $str
# Have to user chosing the branch he wants ${INFO} ${#webbranches[@]} branches available for Web Admin"
else
# Print STDERR output from get_available_branches
echo -e "${OVER} ${CROSS} $str\\n\\n${webbranches[*]}"
exit 1
fi
echo ""
# Have the user choose the branch they want
if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then
echo "::: Requested branch \"${2}\" is not available!" echo -e " ${INFO} Requested branch \"${2}\" is not available"
echo "::: Available branches for web are:" echo -e " ${INFO} Available branches for Web Admin are:"
for e in "${webbranches[@]}"; do echo "::: $e"; done for e in "${webbranches[@]}"; do echo " - $e"; done
exit 1 exit 1
fi fi
checkout_pull_branch "${webInterfaceDir}" "${2}" checkout_pull_branch "${webInterfaceDir}" "${2}"
elif [[ "${1}" == "ftl" ]] ; then
get_binary_name
local path
path="${2}/${binary}"
if check_download_exists "$path"; then
echo " ${TICK} Branch ${2} exists"
FTLinstall "${binary}" "${path}"
else
echo " ${CROSS} Requested branch \"${2}\" is not available"
ftlbranches=( $(git ls-remote https://github.com/pi-hole/ftl | grep 'heads' | sed 's/refs\/heads\///;s/ //g' | awk '{print $2}') )
echo -e " ${INFO} Available branches for FTL are:"
for e in "${ftlbranches[@]}"; do echo " - $e"; done
exit 1
fi
else else
echo "::: Requested option \"${1}\" is not available!" echo -e " ${INFO} Requested option \"${1}\" is not available"
exit 1 exit 1
fi fi
# Force updating everything # Force updating everything
if [[ ! "${1}" == "web" && "${update}" == "true" ]]; then if [[ ( ! "${1}" == "web" && ! "${1}" == "ftl" ) && "${update}" == "true" ]]; then
echo "::: Running installer to upgrade your installation" echo -e " ${INFO} Running installer to upgrade your installation"
if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then
exit 0 exit 0
else else
echo "Unable to complete update, contact Pi-hole" echo -e " ${COL_LIGHT_RED} Error: Unable to complete update, please contact support${COL_NC}"
exit 1 exit 1
fi fi
fi fi
} }

File diff suppressed because it is too large Load Diff

@ -8,17 +8,41 @@
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
echo -n "::: Flushing /var/log/pihole.log ..." colfile="/opt/pihole/COL_TABLE"
# Test if logrotate is available on this system source ${colfile}
if command -v /usr/sbin/logrotate &> /dev/null; then
# Flush twice to move all data out of sight of FTL if [[ "$@" != *"quiet"* ]]; then
/usr/sbin/logrotate --force /etc/pihole/logrotate echo -ne " ${INFO} Flushing /var/log/pihole.log ..."
/usr/sbin/logrotate --force /etc/pihole/logrotate fi
if [[ "$@" == *"once"* ]]; then
# Nightly logrotation
if command -v /usr/sbin/logrotate >/dev/null; then
# Logrotate once
/usr/sbin/logrotate --force /etc/pihole/logrotate
else
# Copy pihole.log over to pihole.log.1
# and empty out pihole.log
# Note that moving the file is not an option, as
# dnsmasq would happily continue writing into the
# moved file (it will have the same file handler)
cp /var/log/pihole.log /var/log/pihole.log.1
echo " " > /var/log/pihole.log
fi
else else
# Flush both pihole.log and pihole.log.1 (if existing) # Manual flushing
echo " " > /var/log/pihole.log if command -v /usr/sbin/logrotate >/dev/null; then
if [ -f /var/log/pihole.log.1 ]; then # Logrotate twice to move all data out of sight of FTL
echo " " > /var/log/pihole.log.1 /usr/sbin/logrotate --force /etc/pihole/logrotate; sleep 3
/usr/sbin/logrotate --force /etc/pihole/logrotate
else
# Flush both pihole.log and pihole.log.1 (if existing)
echo " " > /var/log/pihole.log
if [ -f /var/log/pihole.log.1 ]; then
echo " " > /var/log/pihole.log.1
fi
fi fi
fi fi
echo "... done!"
if [[ "$@" != *"quiet"* ]]; then
echo -e "${OVER} ${TICK} Flushed /var/log/pihole.log"
fi

@ -10,17 +10,19 @@
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
# Variables # Variables
readonly ADMIN_INTERFACE_GIT_URL="https://github.com/pi-hole/AdminLTE.git" readonly ADMIN_INTERFACE_GIT_URL="https://github.com/pi-hole/AdminLTE.git"
readonly ADMIN_INTERFACE_DIR="/var/www/html/admin" readonly ADMIN_INTERFACE_DIR="/var/www/html/admin"
readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git" readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git"
readonly PI_HOLE_FILES_DIR="/etc/.pihole" readonly PI_HOLE_FILES_DIR="/etc/.pihole"
# shellcheck disable=SC2034
PH_TEST=true PH_TEST=true
source ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh
# shellcheck disable=SC1090
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
# shellcheck disable=SC1091
source "/opt/pihole/COL_TABLE"
# is_repo() sourced from basic-install.sh # is_repo() sourced from basic-install.sh
# make_repo() sourced from basic-install.sh # make_repo() sourced from basic-install.sh
@ -30,14 +32,14 @@ source ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh
GitCheckUpdateAvail() { GitCheckUpdateAvail() {
local directory="${1}" local directory="${1}"
curdir=$PWD curdir=$PWD
cd "${directory}" cd "${directory}" || return
# Fetch latest changes in this repo # Fetch latest changes in this repo
git fetch --quiet origin git fetch --quiet origin
# @ alone is a shortcut for HEAD. Older versions of git # @ alone is a shortcut for HEAD. Older versions of git
# need @{0} # need @{0}
LOCAL="$(git rev-parse @{0})" LOCAL="$(git rev-parse "@{0}")"
# The suffix @{upstream} to a branchname # The suffix @{upstream} to a branchname
# (short form <branchname>@{u}) refers # (short form <branchname>@{u}) refers
@ -46,23 +48,23 @@ GitCheckUpdateAvail() {
# (configured with branch.<name>.remote and # (configured with branch.<name>.remote and
# branch.<name>.merge). A missing branchname # branch.<name>.merge). A missing branchname
# defaults to the current one. # defaults to the current one.
REMOTE="$(git rev-parse @{upstream})" REMOTE="$(git rev-parse "@{upstream}")"
if [[ ${#LOCAL} == 0 ]]; then if [[ "${#LOCAL}" == 0 ]]; then
echo "::: Error: Local revision could not be obtained, ask Pi-hole support." echo -e "\\n ${COL_LIGHT_RED}Error: Local revision could not be obtained, please contact Pi-hole Support
echo "::: Additional debugging output:" Additional debugging output:${COL_NC}"
git status git status
exit exit
fi fi
if [[ ${#REMOTE} == 0 ]]; then if [[ "${#REMOTE}" == 0 ]]; then
echo "::: Error: Remote revision could not be obtained, ask Pi-hole support." echo -e "\\n ${COL_LIGHT_RED}Error: Remote revision could not be obtained, please contact Pi-hole Support
echo "::: Additional debugging output:" Additional debugging output:${COL_NC}"
git status git status
exit exit
fi fi
# Change back to original directory # Change back to original directory
cd "${curdir}" cd "${curdir}" || exit
if [[ "${LOCAL}" != "${REMOTE}" ]]; then if [[ "${LOCAL}" != "${REMOTE}" ]]; then
# Local branch is behind remote branch -> Update # Local branch is behind remote branch -> Update
@ -76,9 +78,10 @@ GitCheckUpdateAvail() {
} }
FTLcheckUpdate() { FTLcheckUpdate() {
local FTLversion
local FTLversion=$(/usr/bin/pihole-FTL tag) FTLversion=$(/usr/bin/pihole-FTL tag)
local FTLlatesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep 'Location' | awk -F '/' '{print $NF}' | tr -d '\r\n') local FTLlatesttag
FTLlatesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep 'Location' | awk -F '/' '{print $NF}' | tr -d '\r\n')
if [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then if [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then
return 0 return 0
@ -90,53 +93,59 @@ FTLcheckUpdate() {
main() { main() {
local pihole_version_current local pihole_version_current
local web_version_current local web_version_current
local basicError="\\n ${COL_LIGHT_RED}Unable to complete update, please contact Pi-hole Support${COL_NC}"
# shellcheck disable=1090,2154
source "${setupVars}" source "${setupVars}"
#This is unlikely # This is unlikely
if ! is_repo "${PI_HOLE_FILES_DIR}" ; then if ! is_repo "${PI_HOLE_FILES_DIR}" ; then
echo "::: Critical Error: Core Pi-hole repo is missing from system!" echo -e "\\n ${COL_LIGHT_RED}Error: Core Pi-hole repo is missing from system!
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" Please re-run install script from https://pi-hole.net${COL_NC}"
exit 1; exit 1;
fi fi
echo "::: Checking for updates..." echo -e " ${INFO} Checking for updates..."
if GitCheckUpdateAvail "${PI_HOLE_FILES_DIR}" ; then if GitCheckUpdateAvail "${PI_HOLE_FILES_DIR}" ; then
core_update=true core_update=true
echo "::: Pi-hole Core: update available" echo -e " ${INFO} Pi-hole Core:\\t${COL_YELLOW}update available${COL_NC}"
else else
core_update=false core_update=false
echo "::: Pi-hole Core: up to date" echo -e " ${INFO} Pi-hole Core:\\t${COL_LIGHT_GREEN}up to date${COL_NC}"
fi fi
if FTLcheckUpdate ; then if FTLcheckUpdate ; then
FTL_update=true FTL_update=true
echo "::: FTL: update available" echo -e " ${INFO} FTL:\\t\\t${COL_YELLOW}update available${COL_NC}"
else else
FTL_update=false FTL_update=false
echo "::: FTL: up to date" echo -e " ${INFO} FTL:\\t\\t${COL_LIGHT_GREEN}up to date${COL_NC}"
fi fi
if ${FTL_update}; then # Logic: Don't update FTL when there is a core update available
echo ":::" # since the core update will run the installer which will itself
echo "::: FTL out of date" # re-install (i.e. update) FTL
if ${FTL_update} && ! ${core_update}; then
echo ""
echo -e " ${INFO} FTL out of date"
FTLdetect FTLdetect
echo ":::" echo ""
fi fi
if [[ ${INSTALL_WEB} == true ]]; then if [[ "${INSTALL_WEB}" == true ]]; then
if ! is_repo "${ADMIN_INTERFACE_DIR}" ; then if ! is_repo "${ADMIN_INTERFACE_DIR}" ; then
echo "::: Critical Error: Web Admin repo is missing from system!" echo -e "\\n ${COL_LIGHT_RED}Error: Web Admin repo is missing from system!
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" Please re-run install script from https://pi-hole.net${COL_NC}"
exit 1; exit 1;
fi fi
if GitCheckUpdateAvail "${ADMIN_INTERFACE_DIR}" ; then if GitCheckUpdateAvail "${ADMIN_INTERFACE_DIR}" ; then
web_update=true web_update=true
echo "::: Web Interface: update available" echo -e " ${INFO} Web Interface:\\t${COL_YELLOW}update available${COL_NC}"
else else
web_update=false web_update=false
echo "::: Web Interface: up to date" echo -e " ${INFO} Web Interface:\\t${COL_LIGHT_GREEN}up to date${COL_NC}"
fi fi
# Logic # Logic
@ -151,72 +160,69 @@ main() {
if ! ${core_update} && ! ${web_update} ; then if ! ${core_update} && ! ${web_update} ; then
if ! ${FTL_update} ; then if ! ${FTL_update} ; then
echo ":::" echo ""
echo "::: Everything is up to date!" echo -e " ${TICK} Everything is up to date!"
exit 0 exit 0
fi fi
elif ! ${core_update} && ${web_update} ; then elif ! ${core_update} && ${web_update} ; then
echo ":::" echo ""
echo "::: Pi-hole Web Admin files out of date" echo -e " ${INFO} Pi-hole Web Admin files out of date"
getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}" getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}"
elif ${core_update} && ! ${web_update} ; then elif ${core_update} && ! ${web_update} ; then
echo ":::" echo ""
echo "::: Pi-hole core files out of date" echo -e " ${INFO} Pi-hole core files out of date"
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}" getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || \
echo -e "${basicError}" && exit 1
elif ${core_update} && ${web_update} ; then elif ${core_update} && ${web_update} ; then
echo ":::" echo ""
echo "::: Updating Pi-hole core and web admin files" echo -e " ${INFO} Updating Pi-hole core and web admin files"
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}" getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended || \
echo -e "${basicError}" && exit 1
else else
echo "*** Update script has malfunctioned, fallthrough reached. Please contact support" echo -e " ${COL_LIGHT_RED}Update script has malfunctioned, please contact Pi-hole Support${COL_NC}"
exit 1 exit 1
fi fi
else # Web Admin not installed, so only verify if core is up to date else # Web Admin not installed, so only verify if core is up to date
if ! ${core_update}; then if ! ${core_update}; then
if ! ${FTL_update} ; then if ! ${FTL_update} ; then
echo ":::" echo ""
echo "::: Everything is up to date!" echo -e " ${INFO} Everything is up to date!"
exit 0 exit 0
fi fi
else else
echo ":::" echo ""
echo "::: Pi-hole core files out of date" echo -e " ${INFO} Pi-hole Core files out of date"
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}" getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || \
echo -e "${basicError}" && exit 1
fi fi
fi fi
if [[ "${web_update}" == true ]]; then if [[ "${web_update}" == true ]]; then
web_version_current="$(/usr/local/bin/pihole version --admin --current)" web_version_current="$(/usr/local/bin/pihole version --admin --current)"
echo ":::" echo ""
echo "::: Web Admin version is now at ${web_version_current}" echo -e " ${INFO} Web Admin version is now at ${web_version_current/* v/v}
echo "::: If you had made any changes in '/var/www/html/admin/', they have been stashed using 'git stash'" ${INFO} If you had made any changes in '/var/www/html/admin/', they have been stashed using 'git stash'"
fi fi
if [[ "${core_update}" == true ]]; then if [[ "${core_update}" == true ]]; then
pihole_version_current="$(/usr/local/bin/pihole version --pihole --current)" pihole_version_current="$(/usr/local/bin/pihole version --pihole --current)"
echo ":::" echo ""
echo "::: Pi-hole version is now at ${pihole_version_current}" echo -e " ${INFO} Pi-hole version is now at ${pihole_version_current/* v/v}
echo "::: If you had made any changes in '/etc/.pihole/', they have been stashed using 'git stash'" ${INFO} If you had made any changes in '/etc/.pihole/', they have been stashed using 'git stash'"
fi fi
if [[ ${FTL_update} == true ]]; then if [[ "${FTL_update}" == true ]]; then
FTL_version_current="$(/usr/bin/pihole-FTL tag)" FTL_version_current="$(/usr/bin/pihole-FTL tag)"
echo ":::" echo -e "\\n ${INFO} FTL version is now at ${FTL_version_current/* v/v}"
echo "::: FTL version is now at ${FTL_version_current}"
start_service pihole-FTL start_service pihole-FTL
enable_service pihole-FTL enable_service pihole-FTL
fi fi
echo "" echo ""
exit 0 exit 0
} }
main main

@ -3,24 +3,29 @@
# (c) 2017 Pi-hole, LLC (https://pi-hole.net) # (c) 2017 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware. # Network-wide ad blocking via your own hardware.
# #
# shows version numbers # Show version numbers
# #
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
# Variables # Variables
DEFAULT="-1" DEFAULT="-1"
PHGITDIR="/etc/.pihole/" COREGITDIR="/etc/.pihole/"
WEBGITDIR="/var/www/html/admin/" WEBGITDIR="/var/www/html/admin/"
getLocalVersion() { getLocalVersion() {
# FTL requires a different method
if [[ "$1" == "FTL" ]]; then
pihole-FTL version
return 0
fi
# Get the tagged version of the local repository # Get the tagged version of the local repository
local directory="${1}" local directory="${1}"
local version local version
cd "${directory}" || { echo "${DEFAULT}"; return 1; } cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; }
version=$(git describe --tags --always || \ version=$(git describe --tags --always || echo "$DEFAULT")
echo "${DEFAULT}")
if [[ "${version}" =~ ^v ]]; then if [[ "${version}" =~ ^v ]]; then
echo "${version}" echo "${version}"
elif [[ "${version}" == "${DEFAULT}" ]]; then elif [[ "${version}" == "${DEFAULT}" ]]; then
@ -33,13 +38,18 @@ getLocalVersion() {
} }
getLocalHash() { getLocalHash() {
# Local FTL hash does not exist on filesystem
if [[ "$1" == "FTL" ]]; then
echo "N/A"
return 0
fi
# Get the short hash of the local repository # Get the short hash of the local repository
local directory="${1}" local directory="${1}"
local hash local hash
cd "${directory}" || { echo "${DEFAULT}"; return 1; } cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; }
hash=$(git rev-parse --short HEAD || \ hash=$(git rev-parse --short HEAD || echo "$DEFAULT")
echo "${DEFAULT}")
if [[ "${hash}" == "${DEFAULT}" ]]; then if [[ "${hash}" == "${DEFAULT}" ]]; then
echo "ERROR" echo "ERROR"
return 1 return 1
@ -49,12 +59,33 @@ getLocalHash() {
return 0 return 0
} }
getRemoteHash(){
# Remote FTL hash is not applicable
if [[ "$1" == "FTL" ]]; then
echo "N/A"
return 0
fi
local daemon="${1}"
local branch="${2}"
hash=$(git ls-remote --heads "https://github.com/pi-hole/${daemon}" | \
awk -v bra="$branch" '$0~bra {print substr($0,0,8);exit}')
if [[ -n "$hash" ]]; then
echo "$hash"
else
echo "ERROR"
return 1
fi
return 0
}
getRemoteVersion(){ getRemoteVersion(){
# Get the version from the remote origin # Get the version from the remote origin
local daemon="${1}" local daemon="${1}"
local version local version
version=$(curl --silent --fail https://api.github.com/repos/pi-hole/${daemon}/releases/latest | \ version=$(curl --silent --fail "https://api.github.com/repos/pi-hole/${daemon}/releases/latest" | \
awk -F: '$1 ~/tag_name/ { print $2 }' | \ awk -F: '$1 ~/tag_name/ { print $2 }' | \
tr -cd '[[:alnum:]]._-') tr -cd '[[:alnum:]]._-')
if [[ "${version}" =~ ^v ]]; then if [[ "${version}" =~ ^v ]]; then
@ -66,72 +97,72 @@ getRemoteVersion(){
return 0 return 0
} }
#PHHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \ versionOutput() {
# grep sha | \ [[ "$1" == "pi-hole" ]] && GITDIR=$COREGITDIR
# head -n1 | \ [[ "$1" == "AdminLTE" ]] && GITDIR=$WEBGITDIR
# awk -F ' ' '{ print $2 }' | \ [[ "$1" == "FTL" ]] && GITDIR="FTL"
# tr -cd '[[:alnum:]]._-')
#WEBHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/master | \ [[ "$2" == "-c" ]] || [[ "$2" == "--current" ]] || [[ -z "$2" ]] && current=$(getLocalVersion $GITDIR)
# grep sha | \ [[ "$2" == "-l" ]] || [[ "$2" == "--latest" ]] || [[ -z "$2" ]] && latest=$(getRemoteVersion "$1")
# head -n1 | \ if [[ "$2" == "-h" ]] || [[ "$2" == "--hash" ]]; then
# awk -F ' ' '{ print $2 }' | \ [[ "$3" == "-c" ]] || [[ "$3" == "--current" ]] || [[ -z "$3" ]] && curHash=$(getLocalHash "$GITDIR")
# tr -cd '[[:alnum:]]._-') [[ "$3" == "-l" ]] || [[ "$3" == "--latest" ]] || [[ -z "$3" ]] && latHash=$(getRemoteHash "$1" "$(cd "$GITDIR" 2> /dev/null && git rev-parse --abbrev-ref HEAD)")
fi
if [[ -n "$current" ]] && [[ -n "$latest" ]]; then
output="${1^} version is $current (Latest: $latest)"
elif [[ -n "$current" ]] && [[ -z "$latest" ]]; then
output="Current ${1^} version is $current"
elif [[ -z "$current" ]] && [[ -n "$latest" ]]; then
output="Latest ${1^} version is $latest"
elif [[ "$curHash" == "N/A" ]] || [[ "$latHash" == "N/A" ]]; then
output="${1^} hash is not applicable"
elif [[ -n "$curHash" ]] && [[ -n "$latHash" ]]; then
output="${1^} hash is $curHash (Latest: $latHash)"
elif [[ -n "$curHash" ]] && [[ -z "$latHash" ]]; then
output="Current ${1^} hash is $curHash"
elif [[ -z "$curHash" ]] && [[ -n "$latHash" ]]; then
output="Latest ${1^} hash is $latHash"
else
errorOutput
fi
normalOutput() { [[ -n "$output" ]] && echo " $output"
echo "::: Pi-hole version is $(getLocalVersion "${PHGITDIR}") (Latest version is $(getRemoteVersion pi-hole))"
if [ -d "${WEBGITDIR}" ]; then
echo "::: Web-Admin version is $(getLocalVersion "${WEBGITDIR}") (Latest version is $(getRemoteVersion AdminLTE))"
fi
} }
webOutput() { errorOutput() {
if [ -d "${WEBGITDIR}" ]; then echo " Invalid Option! Try 'pihole -v --help' for more information."
case "${1}" in exit 1
"-l" | "--latest" ) echo $(getRemoteVersion AdminLTE);;
"-c" | "--current" ) echo $(getLocalVersion "${WEBGITDIR}");;
"-h" | "--hash" ) echo $(getLocalHash "${WEBGITDIR}");;
* ) echo "::: Invalid Option!"; exit 1;
esac
else
echo "::: Web interface not installed!"; exit 1;
fi
} }
coreOutput() { defaultOutput() {
case "${1}" in versionOutput "pi-hole" "$@"
"-l" | "--latest" ) echo $(getRemoteVersion pi-hole);; versionOutput "AdminLTE" "$@"
"-c" | "--current" ) echo $(getLocalVersion "${PHGITDIR}");; versionOutput "FTL" "$@"
"-h" | "--hash" ) echo $(getLocalHash "${PHGITDIR}");;
* ) echo "::: Invalid Option!"; exit 1;
esac
} }
helpFunc() { helpFunc() {
cat << EOM echo "Usage: pihole -v [repo | option] [option]
::: Example: 'pihole -v -p -l'
::: Show Pi-hole/Web Admin versions Show Pi-hole, Admin Console & FTL versions
:::
::: Usage: pihole -v [ -a | -p ] [ -l | -c ] Repositories:
::: -p, --pihole Only retrieve info regarding Pi-hole repository
::: Options: -a, --admin Only retrieve info regarding AdminLTE repository
::: -a, --admin Show both current and latest versions of web admin -f, --ftl Only retrieve info regarding FTL repository
::: -p, --pihole Show both current and latest versions of Pi-hole core files
::: -l, --latest (Only after -a | -p) Return only latest version Options:
::: -c, --current (Only after -a | -p) Return only current version -c, --current Return the current version
::: -h, --help Show this help dialog -l, --latest Return the latest version
::: --hash Return the Github hash from your local repositories
EOM -h, --help Show this help dialog"
exit 0 exit 0
} }
if [[ $# = 0 ]]; then
normalOutput
fi
case "${1}" in case "${1}" in
"-a" | "--admin" ) shift; webOutput "$@";; "-p" | "--pihole" ) shift; versionOutput "pi-hole" "$@";;
"-p" | "--pihole" ) shift; coreOutput "$@" ;; "-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";;
"-f" | "--ftl" ) shift; versionOutput "FTL" "$@";;
"-h" | "--help" ) helpFunc;; "-h" | "--help" ) helpFunc;;
* ) defaultOutput "$@";;
esac esac

@ -8,31 +8,31 @@
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
readonly setupVars="/etc/pihole/setupVars.conf" readonly setupVars="/etc/pihole/setupVars.conf"
readonly dnsmasqconfig="/etc/dnsmasq.d/01-pihole.conf" readonly dnsmasqconfig="/etc/dnsmasq.d/01-pihole.conf"
readonly dhcpconfig="/etc/dnsmasq.d/02-pihole-dhcp.conf" readonly dhcpconfig="/etc/dnsmasq.d/02-pihole-dhcp.conf"
# 03 -> wildcards # 03 -> wildcards
readonly dhcpstaticconfig="/etc/dnsmasq.d/04-pihole-static-dhcp.conf" readonly dhcpstaticconfig="/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
coltable="/opt/pihole/COL_TABLE"
if [[ -f ${coltable} ]]; then
source ${coltable}
fi
helpFunc() { helpFunc() {
cat << EOM echo "Usage: pihole -a [options]
::: Set admin options for the web interface of pihole Example: pihole -a -p password
::: Set options for the Admin Console
::: Usage: pihole -a [options]
::: Options:
::: Options: -p, password Set Admin Console password
::: -p, password Set web interface password, an empty input will remove any previously set password -c, celsius Set Celsius as preferred temperature unit
::: -c, celsius Set Celsius temperature unit -f, fahrenheit Set Fahrenheit as preferred temperature unit
::: -f, fahrenheit Set Fahrenheit temperature unit -k, kelvin Set Kelvin as preferred temperature unit
::: -k, kelvin Set Kelvin temperature unit -r, hostrecord Add a name to the DNS associated to an IPv4/IPv6 address
::: -h, --help Show this help dialog -h, --help Show this help dialog
::: -i, interface Setup interface listening behavior of dnsmasq -i, interface Specify dnsmasq's interface listening behavior
::: pihole -a -i local : Listen on all interfaces, but allow only queries from Add '-h' for more info on interface usage"
::: devices that are at most one hop away (local devices)
::: pihole -a -i single : Listen only on one interface (see PIHOLE_INTERFACE)
::: pihole -a -i all : Listen on all interfaces, permit all origins
EOM
exit 0 exit 0
} }
@ -61,14 +61,19 @@ delete_dnsmasq_setting() {
sed -i "/${1}/d" "${dnsmasqconfig}" sed -i "/${1}/d" "${dnsmasqconfig}"
} }
SetTemperatureUnit(){ SetTemperatureUnit() {
change_setting "TEMPERATUREUNIT" "${unit}" change_setting "TEMPERATUREUNIT" "${unit}"
echo -e " ${TICK} Set temperature unit to ${unit}"
} }
SetWebPassword(){ HashPassword() {
# Compute password hash twice to avoid rainbow table vulnerability
return=$(echo -n ${1} | sha256sum | sed 's/\s.*$//')
return=$(echo -n ${return} | sha256sum | sed 's/\s.*$//')
echo ${return}
}
SetWebPassword() {
if [ "${SUDO_USER}" == "www-data" ]; then if [ "${SUDO_USER}" == "www-data" ]; then
echo "Security measure: user www-data is not allowed to change webUI password!" echo "Security measure: user www-data is not allowed to change webUI password!"
echo "Exiting" echo "Exiting"
@ -81,26 +86,33 @@ SetWebPassword(){
exit 1 exit 1
fi fi
read -s -p "Enter New Password (Blank for no password): " PASSWORD if (( ${#args[2]} > 0 )) ; then
echo "" readonly PASSWORD="${args[2]}"
readonly CONFIRM="${PASSWORD}"
if [ "${PASSWORD}" == "" ]; then else
change_setting "WEBPASSWORD" "" # Prevents a bug if the user presses Ctrl+C and it continues to hide the text typed.
echo "Password Removed" # So we reset the terminal via stty if the user does press Ctrl+C
exit 0 trap '{ echo -e "\nNo password will be set" ; stty sane ; exit 1; }' INT
fi read -s -p "Enter New Password (Blank for no password): " PASSWORD
echo ""
if [ "${PASSWORD}" == "" ]; then
change_setting "WEBPASSWORD" ""
echo -e " ${TICK} Password Removed"
exit 0
fi
read -s -p "Confirm Password: " CONFIRM
echo ""
fi
read -s -p "Confirm Password: " CONFIRM
echo ""
if [ "${PASSWORD}" == "${CONFIRM}" ] ; then if [ "${PASSWORD}" == "${CONFIRM}" ] ; then
# Compute password hash twice to avoid rainbow table vulnerability hash=$(HashPassword ${PASSWORD})
hash=$(echo -n ${PASSWORD} | sha256sum | sed 's/\s.*$//')
hash=$(echo -n ${hash} | sha256sum | sed 's/\s.*$//')
# Save hash to file # Save hash to file
change_setting "WEBPASSWORD" "${hash}" change_setting "WEBPASSWORD" "${hash}"
echo "New password set" echo -e " ${TICK} New password set"
else else
echo "Passwords don't match. Your password has not been changed" echo -e " ${CROSS} Passwords don't match. Your password has not been changed"
exit 1 exit 1
fi fi
} }
@ -164,8 +176,7 @@ trust-anchor=.,19036,8,2,49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE3
} }
SetDNSServers(){ SetDNSServers() {
# Save setting to file # Save setting to file
delete_setting "PIHOLE_DNS" delete_setting "PIHOLE_DNS"
IFS=',' read -r -a array <<< "${args[2]}" IFS=',' read -r -a array <<< "${args[2]}"
@ -196,72 +207,68 @@ SetDNSServers(){
# Restart dnsmasq to load new configuration # Restart dnsmasq to load new configuration
RestartDNS RestartDNS
} }
SetExcludeDomains(){ SetExcludeDomains() {
change_setting "API_EXCLUDE_DOMAINS" "${args[2]}" change_setting "API_EXCLUDE_DOMAINS" "${args[2]}"
} }
SetExcludeClients(){ SetExcludeClients() {
change_setting "API_EXCLUDE_CLIENTS" "${args[2]}" change_setting "API_EXCLUDE_CLIENTS" "${args[2]}"
} }
Reboot(){ Reboot() {
nohup bash -c "sleep 5; reboot" &> /dev/null </dev/null & nohup bash -c "sleep 5; reboot" &> /dev/null </dev/null &
} }
RestartDNS(){ RestartDNS() {
local str="Restarting DNS service"
if [ -x "$(command -v systemctl)" ]; then [[ -t 1 ]] && echo -ne " ${INFO} ${str}"
systemctl restart dnsmasq &> /dev/null if command -v systemctl &> /dev/null; then
else output=$( { systemctl restart dnsmasq; } 2>&1 )
service dnsmasq restart &> /dev/null else
fi output=$( { service dnsmasq restart; } 2>&1 )
fi
if [[ -z "${output}" ]]; then
[[ -t 1 ]] && echo -e "${OVER} ${TICK} ${str}"
else
[[ ! -t 1 ]] && OVER=""
echo -e "${OVER} ${CROSS} ${output}"
fi
} }
SetQueryLogOptions(){ SetQueryLogOptions() {
change_setting "API_QUERY_LOG_SHOW" "${args[2]}" change_setting "API_QUERY_LOG_SHOW" "${args[2]}"
} }
ProcessDHCPSettings() { ProcessDHCPSettings() {
source "${setupVars}" source "${setupVars}"
if [[ "${DHCP_ACTIVE}" == "true" ]]; then if [[ "${DHCP_ACTIVE}" == "true" ]]; then
interface=$(grep 'PIHOLE_INTERFACE=' /etc/pihole/setupVars.conf | sed "s/.*=//")
interface=$(grep 'PIHOLE_INTERFACE=' /etc/pihole/setupVars.conf | sed "s/.*=//")
# Use eth0 as fallback interface
# Use eth0 as fallback interface if [ -z ${interface} ]; then
if [ -z ${interface} ]; then interface="eth0"
interface="eth0" fi
fi
if [[ "${PIHOLE_DOMAIN}" == "" ]]; then
if [[ "${PIHOLE_DOMAIN}" == "" ]]; then PIHOLE_DOMAIN="local"
PIHOLE_DOMAIN="local" change_setting "PIHOLE_DOMAIN" "${PIHOLE_DOMAIN}"
change_setting "PIHOLE_DOMAIN" "${PIHOLE_DOMAIN}" fi
fi
if [[ "${DHCP_LEASETIME}" == "0" ]]; then
if [[ "${DHCP_LEASETIME}" == "0" ]]; then leasetime="infinite"
leasetime="infinite" elif [[ "${DHCP_LEASETIME}" == "" ]]; then
elif [[ "${DHCP_LEASETIME}" == "" ]]; then leasetime="24h"
leasetime="24h" change_setting "DHCP_LEASETIME" "${leasetime}"
change_setting "DHCP_LEASETIME" "${leasetime}" else
else leasetime="${DHCP_LEASETIME}h"
leasetime="${DHCP_LEASETIME}h" fi
fi
# Write settings to file
# Write settings to file echo "###############################################################################
echo "###############################################################################
# DHCP SERVER CONFIG FILE AUTOMATICALLY POPULATED BY PI-HOLE WEB INTERFACE. # # DHCP SERVER CONFIG FILE AUTOMATICALLY POPULATED BY PI-HOLE WEB INTERFACE. #
# ANY CHANGES MADE TO THIS FILE WILL BE LOST ON CHANGE # # ANY CHANGES MADE TO THIS FILE WILL BE LOST ON CHANGE #
############################################################################### ###############################################################################
@ -272,26 +279,27 @@ dhcp-leasefile=/etc/pihole/dhcp.leases
#quiet-dhcp #quiet-dhcp
" > "${dhcpconfig}" " > "${dhcpconfig}"
if [[ "${PIHOLE_DOMAIN}" != "none" ]]; then if [[ "${PIHOLE_DOMAIN}" != "none" ]]; then
echo "domain=${PIHOLE_DOMAIN}" >> "${dhcpconfig}" echo "domain=${PIHOLE_DOMAIN}" >> "${dhcpconfig}"
fi fi
if [[ "${DHCP_IPv6}" == "true" ]]; then if [[ "${DHCP_IPv6}" == "true" ]]; then
echo "#quiet-dhcp6 echo "#quiet-dhcp6
#enable-ra #enable-ra
dhcp-option=option6:dns-server,[::] dhcp-option=option6:dns-server,[::]
dhcp-range=::100,::1ff,constructor:${interface},ra-names,slaac,${leasetime} dhcp-range=::100,::1ff,constructor:${interface},ra-names,slaac,${leasetime}
ra-param=*,0,0 ra-param=*,0,0
" >> "${dhcpconfig}" " >> "${dhcpconfig}"
fi fi
else else
rm "${dhcpconfig}" &> /dev/null if [[ -f "${dhcpconfig}" ]]; then
rm "${dhcpconfig}" &> /dev/null
fi
fi fi
} }
EnableDHCP(){ EnableDHCP() {
change_setting "DHCP_ACTIVE" "true" change_setting "DHCP_ACTIVE" "true"
change_setting "DHCP_START" "${args[2]}" change_setting "DHCP_START" "${args[2]}"
change_setting "DHCP_END" "${args[3]}" change_setting "DHCP_END" "${args[3]}"
@ -309,8 +317,7 @@ EnableDHCP(){
RestartDNS RestartDNS
} }
DisableDHCP(){ DisableDHCP() {
change_setting "DHCP_ACTIVE" "false" change_setting "DHCP_ACTIVE" "false"
# Remove possible old setting from file # Remove possible old setting from file
@ -322,23 +329,20 @@ DisableDHCP(){
RestartDNS RestartDNS
} }
SetWebUILayout(){ SetWebUILayout() {
change_setting "WEBUIBOXEDLAYOUT" "${args[2]}" change_setting "WEBUIBOXEDLAYOUT" "${args[2]}"
} }
CustomizeAdLists() { CustomizeAdLists() {
list="/etc/pihole/adlists.list" list="/etc/pihole/adlists.list"
if [[ "${args[2]}" == "enable" ]] ; then if [[ "${args[2]}" == "enable" ]]; then
sed -i "\\@${args[3]}@s/^#http/http/g" "${list}" sed -i "\\@${args[3]}@s/^#http/http/g" "${list}"
elif [[ "${args[2]}" == "disable" ]] ; then elif [[ "${args[2]}" == "disable" ]]; then
sed -i "\\@${args[3]}@s/^http/#http/g" "${list}" sed -i "\\@${args[3]}@s/^http/#http/g" "${list}"
elif [[ "${args[2]}" == "add" ]] ; then elif [[ "${args[2]}" == "add" ]]; then
echo "${args[3]}" >> ${list} echo "${args[3]}" >> ${list}
elif [[ "${args[2]}" == "del" ]] ; then elif [[ "${args[2]}" == "del" ]]; then
var=$(echo "${args[3]}" | sed 's/\//\\\//g') var=$(echo "${args[3]}" | sed 's/\//\\\//g')
sed -i "/${var}/Id" "${list}" sed -i "/${var}/Id" "${list}"
else else
@ -347,18 +351,15 @@ CustomizeAdLists() {
fi fi
} }
SetPrivacyMode(){ SetPrivacyMode() {
if [[ "${args[2]}" == "true" ]]; then
if [[ "${args[2]}" == "true" ]] ; then
change_setting "API_PRIVACY_MODE" "true" change_setting "API_PRIVACY_MODE" "true"
else else
change_setting "API_PRIVACY_MODE" "false" change_setting "API_PRIVACY_MODE" "false"
fi fi
} }
ResolutionSettings() { ResolutionSettings() {
typ="${args[2]}" typ="${args[2]}"
state="${args[3]}" state="${args[3]}"
@ -367,11 +368,9 @@ ResolutionSettings() {
elif [[ "${typ}" == "clients" ]]; then elif [[ "${typ}" == "clients" ]]; then
change_setting "API_GET_CLIENT_HOSTNAME" "${state}" change_setting "API_GET_CLIENT_HOSTNAME" "${state}"
fi fi
} }
AddDHCPStaticAddress() { AddDHCPStaticAddress() {
mac="${args[2]}" mac="${args[2]}"
ip="${args[3]}" ip="${args[3]}"
host="${args[4]}" host="${args[4]}"
@ -386,45 +385,63 @@ AddDHCPStaticAddress() {
# Full info given # Full info given
echo "dhcp-host=${mac},${ip},${host}" >> "${dhcpstaticconfig}" echo "dhcp-host=${mac},${ip},${host}" >> "${dhcpstaticconfig}"
fi fi
} }
RemoveDHCPStaticAddress() { RemoveDHCPStaticAddress() {
mac="${args[2]}" mac="${args[2]}"
sed -i "/dhcp-host=${mac}.*/d" "${dhcpstaticconfig}" sed -i "/dhcp-host=${mac}.*/d" "${dhcpstaticconfig}"
} }
SetHostRecord(){ SetHostRecord() {
if [[ "${1}" == "-h" ]] || [[ "${1}" == "--help" ]]; then
echo "Usage: pihole -a hostrecord <domain> [IPv4-address],[IPv6-address]
Example: 'pihole -a hostrecord home.domain.com 192.168.1.1,2001:db8:a0b:12f0::1'
Add a name to the DNS associated to an IPv4/IPv6 address
Options:
\"\" Empty: Remove host record
-h, --help Show this help dialog"
exit 0
fi
if [ -n "${args[3]}" ]; then if [[ -n "${args[3]}" ]]; then
change_setting "HOSTRECORD" "${args[2]},${args[3]}" change_setting "HOSTRECORD" "${args[2]},${args[3]}"
echo "Setting host record for ${args[2]} -> ${args[3]}" echo -e " ${TICK} Setting host record for ${args[2]} to ${args[3]}"
else else
change_setting "HOSTRECORD" "" change_setting "HOSTRECORD" ""
echo "Removing host record" echo -e " ${TICK} Removing host record"
fi fi
ProcessDNSSettings ProcessDNSSettings
# Restart dnsmasq to load new configuration # Restart dnsmasq to load new configuration
RestartDNS RestartDNS
} }
SetListeningMode(){ SetListeningMode() {
source "${setupVars}" source "${setupVars}"
if [[ "${args[2]}" == "all" ]] ; then if [[ "$3" == "-h" ]] || [[ "$3" == "--help" ]]; then
echo "Listening on all interfaces, permiting all origins, hope you have a firewall!" echo "Usage: pihole -a -i [interface]
Example: 'pihole -a -i local'
Specify dnsmasq's network interface listening behavior
Interfaces:
local Listen on all interfaces, but only allow queries from
devices that are at most one hop away (local devices)
single Listen only on ${PIHOLE_INTERFACE} interface
all Listen on all interfaces, permit all origins"
exit 0
fi
if [[ "${args[2]}" == "all" ]]; then
echo -e " ${INFO} Listening on all interfaces, permiting all origins. Please use a firewall!"
change_setting "DNSMASQ_LISTENING" "all" change_setting "DNSMASQ_LISTENING" "all"
elif [[ "${args[2]}" == "local" ]] ; then elif [[ "${args[2]}" == "local" ]]; then
echo "Listening on all interfaces, permitting only origins that are at most one hop away (local devices)" echo -e " ${INFO} Listening on all interfaces, permiting origins from one hop away (LAN)"
change_setting "DNSMASQ_LISTENING" "local" change_setting "DNSMASQ_LISTENING" "local"
else else
echo "Listening only on interface ${PIHOLE_INTERFACE}" echo -e " ${INFO} Listening only on interface ${PIHOLE_INTERFACE}"
change_setting "DNSMASQ_LISTENING" "single" change_setting "DNSMASQ_LISTENING" "single"
fi fi
@ -435,17 +452,19 @@ SetListeningMode(){
# Restart dnsmasq to load new configuration # Restart dnsmasq to load new configuration
RestartDNS RestartDNS
fi fi
} }
Teleporter() Teleporter() {
{
local datetimestamp=$(date "+%Y-%m-%d_%H-%M-%S") local datetimestamp=$(date "+%Y-%m-%d_%H-%M-%S")
php /var/www/html/admin/scripts/pi-hole/php/teleporter.php > "pi-hole-teleporter_${datetimestamp}.zip" php /var/www/html/admin/scripts/pi-hole/php/teleporter.php > "pi-hole-teleporter_${datetimestamp}.zip"
} }
main() { audit()
{
echo "${args[2]}" >> /etc/pihole/auditlog.list
}
main() {
args=("$@") args=("$@")
case "${args[1]}" in case "${args[1]}" in
@ -467,10 +486,11 @@ main() {
"resolve" ) ResolutionSettings;; "resolve" ) ResolutionSettings;;
"addstaticdhcp" ) AddDHCPStaticAddress;; "addstaticdhcp" ) AddDHCPStaticAddress;;
"removestaticdhcp" ) RemoveDHCPStaticAddress;; "removestaticdhcp" ) RemoveDHCPStaticAddress;;
"hostrecord" ) SetHostRecord;; "-r" | "hostrecord" ) SetHostRecord "$3";;
"-i" | "interface" ) SetListeningMode;; "-i" | "interface" ) SetListeningMode "$@";;
"-t" | "teleporter" ) Teleporter;; "-t" | "teleporter" ) Teleporter;;
"adlist" ) CustomizeAdLists;; "adlist" ) CustomizeAdLists;;
"audit" ) audit;;
* ) helpFunc;; * ) helpFunc;;
esac esac
@ -479,5 +499,4 @@ main() {
if [[ $# = 0 ]]; then if [[ $# = 0 ]]; then
helpFunc helpFunc
fi fi
} }

@ -185,7 +185,7 @@ function add() {
} }
$.ajax({ $.ajax({
url: "admin/scripts/pi-hole/php/add.php", url: "/admin/scripts/pi-hole/php/add.php",
method: "post", method: "post",
data: {"domain":domain.val(), "list":"white", "pw":pw.val()}, data: {"domain":domain.val(), "list":"white", "pw":pw.val()},
success: function(response) { success: function(response) {

@ -8,3 +8,14 @@
notifempty notifempty
nomail nomail
} }
/var/log/pihole-FTL.log {
# su #
weekly
copytruncate
rotate 3
compress
delaycompress
notifempty
nomail
}

@ -26,7 +26,7 @@ start() {
echo "pihole-FTL is already running" echo "pihole-FTL is already running"
else else
touch /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port touch /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port
chown pihole:pihole /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port chown pihole:pihole /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port /etc/pihole
chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port
su -s /bin/sh -c "/usr/bin/pihole-FTL" "$FTLUSER" su -s /bin/sh -c "/usr/bin/pihole-FTL" "$FTLUSER"
echo echo

@ -21,9 +21,10 @@
# Pi-hole: Update Pi-hole! Uncomment to enable auto update # Pi-hole: Update Pi-hole! Uncomment to enable auto update
#30 2 * * 7 root PATH="$PATH:/usr/local/bin/" pihole updatePihole #30 2 * * 7 root PATH="$PATH:/usr/local/bin/" pihole updatePihole
# Pi-hole: Flush the log daily at 00:00 so it doesn't get out of control # Pi-hole: Flush the log daily at 00:00
# Stats will be viewable in the Web interface thanks to the cron job above
# The flush script will use logrotate if available # The flush script will use logrotate if available
00 00 * * * root PATH="$PATH:/usr/local/bin/" pihole flush # parameter "once": logrotate only once (default is twice)
# parameter "quiet": don't print messages
00 00 * * * root PATH="$PATH:/usr/local/bin/" pihole flush once quiet
@reboot root /usr/sbin/logrotate /etc/pihole/logrotate @reboot root /usr/sbin/logrotate /etc/pihole/logrotate

File diff suppressed because it is too large Load Diff

@ -8,19 +8,30 @@
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
source "/opt/pihole/COL_TABLE"
while true; do
read -rp " ${QST} Are you sure you would like to remove ${COL_WHITE}Pi-hole${COL_NC}? [y/N] " yn
case ${yn} in
[Yy]* ) break;;
[Nn]* ) echo -e "\n ${COL_LIGHT_GREEN}Uninstall has been cancelled${COL_NC}"; exit 0;;
* ) echo -e "\n ${COL_LIGHT_GREEN}Uninstall has been cancelled${COL_NC}"; exit 0;;
esac
done
# Must be root to uninstall # Must be root to uninstall
str="Root user check"
if [[ ${EUID} -eq 0 ]]; then if [[ ${EUID} -eq 0 ]]; then
echo "::: You are root." echo -e " ${TICK} ${str}"
else else
echo "::: Sudo will be used for the uninstall." # Check if sudo is actually installed
# Check if it is actually installed # If it isn't, exit because the uninstall can not complete
# If it isn't, exit because the unnstall cannot complete
if [ -x "$(command -v sudo)" ]; then if [ -x "$(command -v sudo)" ]; then
export SUDO="sudo" export SUDO="sudo"
else else
echo "::: Please install sudo or run this as root." echo -e " ${CROSS} ${str}
Script called with non-root privileges
The Pi-hole requires elevated privleges to uninstall"
exit 1 exit 1
fi fi
fi fi
@ -54,59 +65,48 @@ elif [ -x "$(command -v apt-get)" ]; then
${SUDO} ${PKG_MANAGER} -y autoclean ${SUDO} ${PKG_MANAGER} -y autoclean
} }
else else
echo "OS distribution not supported" echo -e " ${CROSS} OS distribution not supported"
exit exit 1
fi fi
spinner() {
local pid=$1
local delay=0.50
local spinstr='/-\|'
while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do
local temp=${spinstr#?}
printf " [%c] " "${spinstr}"
local spinstr=${temp}${spinstr%"$temp}"}
sleep ${delay}
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
removeAndPurge() { removeAndPurge() {
# Purge dependencies # Purge dependencies
echo ":::" echo ""
for i in "${PIHOLE_DEPS[@]}"; do for i in "${PIHOLE_DEPS[@]}"; do
package_check ${i} > /dev/null package_check ${i} > /dev/null
if [ $? -eq 0 ]; then if [[ "$?" -eq 0 ]]; then
while true; do while true; do
read -rp "::: Do you wish to remove ${i} from your system? [y/n]: " yn read -rp " ${QST} Do you wish to remove ${COL_WHITE}${i}${COL_NC} from your system? [Y/N] " yn
case ${yn} in case ${yn} in
[Yy]* ) printf ":::\tRemoving %s..." "${i}"; ${SUDO} ${PKG_REMOVE} "${i}" &> /dev/null & spinner $!; printf "done!\n"; break;; [Yy]* )
[Nn]* ) printf ":::\tSkipping %s\n" "${i}"; break;; echo -ne " ${INFO} Removing ${i}...";
* ) printf "::: You must answer yes or no!\n";; ${SUDO} ${PKG_REMOVE} "${i}" &> /dev/null;
echo -e "${OVER} ${INFO} Removed ${i}";
break;;
[Nn]* ) echo -e " ${INFO} Skipped ${i}"; break;;
esac esac
done done
else else
printf ":::\tPackage %s not installed... Not removing.\n" "${i}" echo -e " ${INFO} Package ${i} not installed"
fi fi
done done
# Remove dependency config files # Remove dnsmasq config files
echo "::: Removing dnsmasq config files..."
${SUDO} rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null ${SUDO} rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null
echo -e " ${TICK} Removing dnsmasq config files"
# Take care of any additional package cleaning # Take care of any additional package cleaning
printf "::: Auto removing & cleaning remaining dependencies..." echo -ne " ${INFO} Removing & cleaning remaining dependencies..."
package_cleanup &> /dev/null & spinner $!; printf "done!\n"; package_cleanup &> /dev/null
echo -e "${OVER} ${TICK} Removed & cleaned up remaining dependencies"
# Call removeNoPurge to remove PiHole specific files # Call removeNoPurge to remove Pi-hole specific files
removeNoPurge removeNoPurge
} }
removeNoPurge() { removeNoPurge() {
echo ":::" # Only web directories/files that are created by Pi-hole should be removed
# Only web directories/files that are created by pihole should be removed. echo -ne " ${INFO} Removing Web Interface..."
echo "::: Removing the Pi-hole Web server files..."
${SUDO} rm -rf /var/www/html/admin &> /dev/null ${SUDO} rm -rf /var/www/html/admin &> /dev/null
${SUDO} rm -rf /var/www/html/pihole &> /dev/null ${SUDO} rm -rf /var/www/html/pihole &> /dev/null
${SUDO} rm /var/www/html/index.lighttpd.orig &> /dev/null ${SUDO} rm /var/www/html/index.lighttpd.orig &> /dev/null
@ -117,28 +117,29 @@ removeNoPurge() {
${SUDO} rm -rf /var/www/html &> /dev/null ${SUDO} rm -rf /var/www/html &> /dev/null
fi fi
fi fi
echo -e "${OVER} ${TICK} Removed Web Interface"
# Attempt to preserve backwards compatibility with older versions # Attempt to preserve backwards compatibility with older versions
# to guarantee no additional changes were made to /etc/crontab after # to guarantee no additional changes were made to /etc/crontab after
# the installation of pihole, /etc/crontab.pihole should be permanently # the installation of pihole, /etc/crontab.pihole should be permanently
# preserved. # preserved.
if [[ -f /etc/crontab.orig ]]; then if [[ -f /etc/crontab.orig ]]; then
echo "::: Initial Pi-hole cron detected. Restoring the default system cron..."
${SUDO} mv /etc/crontab /etc/crontab.pihole ${SUDO} mv /etc/crontab /etc/crontab.pihole
${SUDO} mv /etc/crontab.orig /etc/crontab ${SUDO} mv /etc/crontab.orig /etc/crontab
${SUDO} service cron restart ${SUDO} service cron restart
echo -e " ${TICK} Restored the default system cron"
fi fi
# Attempt to preserve backwards compatibility with older versions # Attempt to preserve backwards compatibility with older versions
if [[ -f /etc/cron.d/pihole ]];then if [[ -f /etc/cron.d/pihole ]];then
echo "::: Removing cron.d/pihole..."
${SUDO} rm /etc/cron.d/pihole &> /dev/null ${SUDO} rm /etc/cron.d/pihole &> /dev/null
echo -e " ${TICK} Removed /etc/cron.d/pihole"
fi fi
echo "::: Removing config files and scripts..."
package_check lighttpd > /dev/null package_check lighttpd > /dev/null
if [ $? -eq 1 ]; then if [[ $? -eq 1 ]]; then
${SUDO} rm -rf /etc/lighttpd/ &> /dev/null ${SUDO} rm -rf /etc/lighttpd/ &> /dev/null
echo -e " ${TICK} Removed lighttpd"
else else
if [ -f /etc/lighttpd/lighttpd.conf.orig ]; then if [ -f /etc/lighttpd/lighttpd.conf.orig ]; then
${SUDO} mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf ${SUDO} mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf
@ -154,28 +155,53 @@ removeNoPurge() {
${SUDO} rm /usr/local/bin/pihole &> /dev/null ${SUDO} rm /usr/local/bin/pihole &> /dev/null
${SUDO} rm /etc/bash_completion.d/pihole &> /dev/null ${SUDO} rm /etc/bash_completion.d/pihole &> /dev/null
${SUDO} rm /etc/sudoers.d/pihole &> /dev/null ${SUDO} rm /etc/sudoers.d/pihole &> /dev/null
echo -e " ${TICK} Removed config files"
# Remove FTL
if command -v pihole-FTL &> /dev/null; then
echo -ne " ${INFO} Removing pihole-FTL..."
if [[ -x "$(command -v systemctl)" ]]; then
systemctl stop pihole-FTL
else
service pihole-FTL stop
fi
${SUDO} rm /etc/init.d/pihole-FTL
${SUDO} rm /usr/bin/pihole-FTL
echo -e "${OVER} ${TICK} Removed pihole-FTL"
fi
# If the pihole user exists, then remove # If the pihole user exists, then remove
if id "pihole" >/dev/null 2>&1; then if id "pihole" &> /dev/null; then
echo "::: Removing pihole user..." ${SUDO} userdel -r pihole 2> /dev/null
${SUDO} userdel -r pihole if [[ "$?" -eq 0 ]]; then
echo -e " ${TICK} Removed 'pihole' user"
else
echo -e " ${CROSS} Unable to remove 'pihole' user"
fi
fi fi
echo ":::" echo -e "\n We're sorry to see you go, but thanks for checking out Pi-hole!
printf "::: Finished removing PiHole from your system. Sorry to see you go!\n" If you need help, reach out to us on Github, Discourse, Reddit or Twitter
printf "::: Reach out to us at https://github.com/pi-hole/pi-hole/issues if you need help\n" Reinstall at any time: ${COL_WHITE}curl -sSL https://install.pi-hole.net | bash${COL_NC}
printf "::: Reinstall by simpling running\n:::\n:::\tcurl -sSL https://install.pi-hole.net | bash\n:::\n::: at any time!\n:::\n"
printf "::: PLEASE RESET YOUR DNS ON YOUR ROUTER/CLIENTS TO RESTORE INTERNET CONNECTIVITY!\n" ${COL_LIGHT_RED}Please reset the DNS on your router/clients to restore internet connectivity
${COL_LIGHT_GREEN}Uninstallation Complete! ${COL_NC}"
} }
######### SCRIPT ########### ######### SCRIPT ###########
echo "::: Preparing to remove packages, be sure that each may be safely removed depending on your operating system." if command -v vcgencmd &> /dev/null; then
echo "::: (SAFE TO REMOVE ALL ON RASPBIAN)" echo -e " ${INFO} All dependencies are safe to remove on Raspbian"
else
echo -e " ${INFO} Be sure to confirm if any dependencies should not be removed"
fi
while true; do while true; do
read -rp "::: Do you wish to purge PiHole's dependencies from your OS? (You will be prompted for each package) [y/n]: " yn read -rp " ${QST} Do you wish to go through each dependency for removal? [Y/n] " yn
case ${yn} in case ${yn} in
[Yy]* ) removeAndPurge; break;; [Yy]* ) removeAndPurge; break;;
[Nn]* ) removeNoPurge; break;; [Nn]* ) removeNoPurge; break;;
* ) removeAndPurge; break;;
esac esac
done done

@ -8,52 +8,50 @@
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
# Run this script as root or under sudo # Run this script as root or under sudo
echo ":::"
coltable="/opt/pihole/COL_TABLE"
source ${coltable}
helpFunc() { helpFunc() {
cat << EOM echo "Usage: pihole -g
::: Pull in domains from adlists Update domains from blocklists specified in adlists.list
:::
::: Usage: pihole -g Options:
::: -f, --force Force the download of all specified blocklists
::: Options: -h, --help Show this help dialog"
::: -f, --force Force lists to be downloaded, even if they don't need updating. exit 0
::: -h, --help Show this help dialog
EOM
exit 0
} }
PIHOLE_COMMAND="/usr/local/bin/pihole" PIHOLE_COMMAND="/usr/local/bin/pihole"
adListFile=/etc/pihole/adlists.list adListFile=/etc/pihole/adlists.list
adListDefault=/etc/pihole/adlists.default #being deprecated adListDefault=/etc/pihole/adlists.default # Deprecated
adListRepoDefault=/etc/.pihole/adlists.default adListRepoDefault=/etc/.pihole/adlists.default
whitelistScript="${PIHOLE_COMMAND} -w" whitelistScript="${PIHOLE_COMMAND} -w"
whitelistFile=/etc/pihole/whitelist.txt whitelistFile=/etc/pihole/whitelist.txt
blacklistFile=/etc/pihole/blacklist.txt blacklistFile=/etc/pihole/blacklist.txt
readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf"
#Source the setupVars from install script for the IP # Source the setupVars from install script for the IP
setupVars=/etc/pihole/setupVars.conf setupVars=/etc/pihole/setupVars.conf
if [[ -f ${setupVars} ]];then if [[ -f "${setupVars}" ]];then
. /etc/pihole/setupVars.conf . /etc/pihole/setupVars.conf
else else
echo "::: WARNING: /etc/pihole/setupVars.conf missing. Possible installation failure." echo -e " ${COL_LIGHT_RED}Error: /etc/pihole/setupVars.conf missing. Possible installation failure.${COL_NC}
echo "::: Please run 'pihole -r', and choose the 'reconfigure' option to reconfigure." Please run 'pihole -r', and choose the 'reconfigure' option to reconfigure."
exit 1 exit 1
fi fi
#Remove the /* from the end of the IPv4addr. # Remove the /* from the end of the IP addresses
IPV4_ADDRESS=${IPV4_ADDRESS%/*} IPV4_ADDRESS=${IPV4_ADDRESS%/*}
IPV6_ADDRESS=${IPV6_ADDRESS} IPV6_ADDRESS=${IPV6_ADDRESS%/*}
# Variables for various stages of downloading and formatting the list # Variables for various stages of downloading and formatting the list
basename=pihole basename=pihole
piholeDir=/etc/${basename} piholeDir=/etc/${basename}
adList=${piholeDir}/gravity.list adList=${piholeDir}/gravity.list
blackList=${piholeDir}/black.list
localList=${piholeDir}/local.list localList=${piholeDir}/local.list
justDomainsExtension=domains justDomainsExtension=domains
matterAndLight=${basename}.0.matterandlight.txt matterAndLight=${basename}.0.matterandlight.txt
@ -64,13 +62,13 @@ accretionDisc=${basename}.3.accretionDisc.txt
skipDownload=false skipDownload=false
# Warn users still using pihole.conf that it no longer has any effect (I imagine about 2 people use it) # Warn users still using pihole.conf that it no longer has any effect
if [[ -r ${piholeDir}/pihole.conf ]]; then if [[ -r ${piholeDir}/pihole.conf ]]; then
echo "::: pihole.conf file no longer supported. Over-rides in this file are ignored." echo -e " ${COL_LIGHT_RED}pihole.conf file no longer supported. Overrides in this file are ignored.${COL_NC}"
fi fi
########################### ###########################
# collapse - begin formation of pihole # Collapse - begin formation of pihole
gravity_collapse() { gravity_collapse() {
#New Logic: #New Logic:
@ -78,355 +76,401 @@ gravity_collapse() {
# If not, cp /etc/.pihole/adlists.default /etc/pihole/adlists.list # If not, cp /etc/.pihole/adlists.default /etc/pihole/adlists.list
# Read from adlists.list # Read from adlists.list
#The following two blocks will sort out any missing adlists in the /etc/pihole directory, and remove legacy adlists.default # The following two blocks will sort out any missing adlists in the /etc/pihole directory, and remove legacy adlists.default
if [ -f ${adListDefault} ] && [ -f ${adListFile} ]; then if [[ -f "${adListDefault}" ]] && [[ -f "${adListFile}" ]]; then
rm ${adListDefault} rm "${adListDefault}"
fi fi
if [ ! -f ${adListFile} ]; then if [ ! -f "${adListFile}" ]; then
cp ${adListRepoDefault} ${adListFile} cp "${adListRepoDefault}" "${adListFile}"
fi fi
echo "::: Neutrino emissions detected..." echo -e " ${INFO} Neutrino emissions detected..."
echo ":::" echo ""
echo -n "::: Pulling source lists into range..." local str="Pulling source lists into range"
echo -ne " ${INFO} ${str}..."
sources=() sources=()
while IFS= read -r line || [[ -n "$line" ]]; do while IFS= read -r line || [[ -n "$line" ]]; do
#Do not read commented out or blank lines # Do not read commented out or blank lines
if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then
echo "" > /dev/null echo "" > /dev/null
else else
sources+=(${line}) sources+=(${line})
fi fi
done < ${adListFile} done < ${adListFile}
echo " done!"
echo -e "${OVER} ${TICK} ${str}"
} }
# patternCheck - check to see if curl downloaded any new files. # patternCheck - check to see if curl downloaded any new files.
gravity_patternCheck() { gravity_patternCheck() {
patternBuffer=$1 patternBuffer=$1
success=$2 success=$2
error=$3 error=$3
if [ $success = true ]; then if [[ "${success}" = true ]]; then
# check if download was successful but list has not been modified # Check if download was successful but list has not been modified
if [ "${error}" == "304" ]; then if [[ "${error}" == "304" ]]; then
echo "::: No changes detected, transport skipped!" echo -e " ${TICK} No changes detected, transport skipped!"
# check if the patternbuffer is a non-zero length file # Check if the patternbuffer is a non-zero length file
elif [[ -s "${patternBuffer}" ]]; then elif [[ -s "${patternBuffer}" ]]; then
# Some of the blocklists are copyright, they need to be downloaded # Some blocklists are copyright, they need to be downloaded and stored
# and stored as is. They can be processed for content after they # as is. They can be processed for content after they have been saved.
# have been saved. mv "${patternBuffer}" "${saveLocation}"
mv "${patternBuffer}" "${saveLocation}" echo -e " ${TICK} List updated, transport successful!"
echo "::: List updated, transport successful!" else
else # Empty file -> use previously downloaded list
# Empty file -> use previously downloaded list echo -e " ${INFO} Received empty file, ${COL_LIGHT_GREEN}using cached one${COL_NC} (list not updated!)"
echo "::: Received empty file, using cached one (list not updated!)" fi
fi else
else # Check if cached list exists
# check if cached list exists if [[ -r "${saveLocation}" ]]; then
if [[ -r "${saveLocation}" ]]; then echo -e " ${CROSS} List download failed, using cached list (list not updated!)"
echo "::: List download failed, using cached list (list not updated!)" else
else echo -e " ${CROSS} Download failed and no cached list available (list will not be considered)"
echo "::: Download failed and no cached list available (list will not be considered)" fi
fi fi
fi
} }
# transport - curl the specified url with any needed command extentions # transport - curl the specified url with any needed command extentions
gravity_transport() { gravity_transport() {
url=$1 url=$1
cmd_ext=$2 cmd_ext=$2
agent=$3 agent=$3
# tmp file, so we don't have to store the (long!) lists in RAM # tmp file, so we don't have to store the (long!) lists in RAM
patternBuffer=$(mktemp) patternBuffer=$(mktemp)
heisenbergCompensator="" heisenbergCompensator=""
if [[ -r ${saveLocation} ]]; then if [[ -r ${saveLocation} ]]; then
# if domain has been saved, add file for date check to only download newer # If domain has been saved, add file for date check to only download newer
heisenbergCompensator="-z ${saveLocation}" heisenbergCompensator="-z ${saveLocation}"
fi fi
# Silently curl url # Silently curl url
err=$(curl -s -L ${cmd_ext} ${heisenbergCompensator} -w %{http_code} -A "${agent}" ${url} -o ${patternBuffer}) echo -e "${OVER} ${TICK} ${str}"
local str="Status:"
echo " done" echo -ne " ${INFO} ${str} Pending"
# Analyze http response err=$(curl -s -L ${cmd_ext} ${heisenbergCompensator} -w %{http_code} -A "${agent}" ${url} -o ${patternBuffer})
echo -n "::: Status: "
case "$err" in # Analyze http response
"200" ) echo "Success (OK)"; success=true;; case "$err" in
"304" ) echo "Not modified"; success=true;; "200" ) echo -e "${OVER} ${TICK} ${str} Success (OK)"; success=true;;
"403" ) echo "Forbidden"; success=false;; "304" ) echo -e "${OVER} ${TICK} ${str} Not modified"; success=true;;
"404" ) echo "Not found"; success=false;; "403" ) echo -e "${OVER} ${CROSS} ${str} Forbidden"; success=false;;
"408" ) echo "Time-out"; success=false;; "404" ) echo -e "${OVER} ${CROSS} ${str} Not found"; success=false;;
"451" ) echo "Unavailable For Legal Reasons"; success=false;; "408" ) echo -e "${OVER} ${CROSS} ${str} Time-out"; success=false;;
"521" ) echo "Web Server Is Down (Cloudflare)"; success=false;; "451" ) echo -e "${OVER} ${CROSS} ${str} Unavailable For Legal Reasons"; success=false;;
"522" ) echo "Connection Timed Out (Cloudflare)"; success=false;; "521" ) echo -e "${OVER} ${CROSS} ${str} Web Server Is Down (Cloudflare)"; success=false;;
"500" ) echo "Internal Server Error"; success=false;; "522" ) echo -e "${OVER} ${CROSS} ${str} Connection Timed Out (Cloudflare)"; success=false;;
* ) echo "Status $err"; success=false;; "500" ) echo -e "${OVER} ${CROSS} ${str} Internal Server Error"; success=false;;
esac * ) echo -e "${OVER} ${CROSS} ${str} Status $err"; success=false;;
esac
# Process result
gravity_patternCheck "${patternBuffer}" ${success} "${err}" # Process result
gravity_patternCheck "${patternBuffer}" "${success}" "${err}"
# Delete temp file if it hasn't been moved
if [[ -f "${patternBuffer}" ]]; then # Delete temp file if it hasn't been moved
rm "${patternBuffer}" if [[ -f "${patternBuffer}" ]]; then
fi rm "${patternBuffer}"
fi
} }
# spinup - main gravity function # spinup - main gravity function
gravity_spinup() { gravity_spinup() {
echo ":::" echo ""
# Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and # blank lines # Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and # blank lines
for ((i = 0; i < "${#sources[@]}"; i++)); do for ((i = 0; i < "${#sources[@]}"; i++)); do
url=${sources[$i]} url=${sources[$i]}
# Get just the domain from the URL # Get just the domain from the URL
domain=$(echo "${url}" | cut -d'/' -f3) domain=$(cut -d'/' -f3 <<< "${url}")
# Save the file as list.#.domain # Save the file as list.#.domain
saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension} saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension}
activeDomains[$i]=${saveLocation} activeDomains[$i]=${saveLocation}
agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36"
# Use a case statement to download lists that need special cURL commands # Use a case statement to download lists that need special cURL commands
# to complete properly and reset the user agent when required # to complete properly and reset the user agent when required
case "${domain}" in case "${domain}" in
"adblock.mahakala.is") "pgl.yoyo.org")
agent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36' cmd_ext="-d mimetype=plaintext -d hostformat=hosts"
cmd_ext="-e http://forum.xda-developers.com/" ;;
;;
# Default is a simple request
"adaway.org") *) cmd_ext=""
agent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36' esac
;;
if [[ "${skipDownload}" == false ]]; then
"pgl.yoyo.org") local str="Aiming tractor beam at $domain"
cmd_ext="-d mimetype=plaintext -d hostformat=hosts" echo -ne " ${INFO} ${str}..."
;;
gravity_transport "$url" "$cmd_ext" "$agent" "$str"
# Default is a simple request echo ""
*) cmd_ext="" fi
esac done
if [[ "${skipDownload}" == false ]]; then
echo -n "::: Getting $domain list..."
gravity_transport "$url" "$cmd_ext" "$agent"
fi
done
} }
# Schwarzchild - aggregate domains to one list and add blacklisted domains # Schwarzchild - aggregate domains to one list and add blacklisted domains
gravity_Schwarzchild() { gravity_Schwarzchild() {
echo "::: " echo ""
# Find all active domains and compile them into one file and remove CRs # Find all active domains and compile them into one file and remove CRs
echo -n "::: Aggregating list of domains..." local str="Aggregating list of domains"
truncate -s 0 ${piholeDir}/${matterAndLight} echo -ne " ${INFO} ${str}..."
for i in "${activeDomains[@]}"; do
# Only assimilate list if it is available (download might have faild permanently) truncate -s 0 ${piholeDir}/${matterAndLight}
if [[ -r "${i}" ]]; then for i in "${activeDomains[@]}"; do
cat "${i}" | tr -d '\r' >> ${piholeDir}/${matterAndLight} # Only assimilate list if it is available (download might have failed permanently)
fi if [[ -r "${i}" ]]; then
done cat "${i}" | tr -d '\r' >> ${piholeDir}/${matterAndLight}
echo " done!" fi
done
echo -e "${OVER} ${TICK} ${str}"
} }
gravity_Blacklist() { gravity_Blacklist() {
# Append blacklist entries to eventHorizon 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
echo -n "::: Blacklisting $numBlacklisted domain${plural}..." local str="Exact blocked domain${plural}: $numBlacklisted"
cat ${blacklistFile} >> ${piholeDir}/${eventHorizon} echo -e " ${INFO} ${str}"
echo " done!" else
else echo -e " ${INFO} Nothing to blacklist!"
echo "::: Nothing to blacklist!" fi
fi
} }
gravity_Wildcard() { gravity_Wildcard() {
# Return number of wildcards in output - don't actually handle wildcards # Return number of wildcards in output - don't actually handle wildcards
if [[ -f "${wildcardlist}" ]]; then if [[ -f "${wildcardlist}" ]]; then
numWildcards=$(grep -c ^ "${wildcardlist}") numWildcards=$(grep -c ^ "${wildcardlist}")
if [[ -n "${IPV4_ADDRESS}" && -n "${IPV6_ADDRESS}" ]];then if [[ -n "${IPV4_ADDRESS}" ]] && [[ -n "${IPV6_ADDRESS}" ]];then
let numWildcards/=2 let numWildcards/=2
fi fi
plural=; [[ "$numWildcards" != "1" ]] && plural=s plural=; [[ "$numWildcards" != "1" ]] && plural=s
echo "::: Wildcard blocked domain${plural}: $numWildcards" echo -e " ${INFO} Wildcard blocked domain${plural}: $numWildcards"
else else
echo "::: No wildcards used!" echo -e " ${INFO} No wildcards used!"
fi fi
} }
gravity_Whitelist() { gravity_Whitelist() {
#${piholeDir}/${eventHorizon}) echo ""
echo ":::" # Prevent our sources from being pulled into the hole
# Prevent our sources from being pulled into the hole plural=; [[ "${sources[@]}" != "1" ]] && plural=s
plural=; [[ "${sources[@]}" != "1" ]] && plural=s local str="Adding adlist source${plural} to the whitelist"
echo -n "::: Adding adlist source${plural} to the whitelist..." echo -ne " ${INFO} ${str}..."
urls=() urls=()
for url in "${sources[@]}"; do for url in "${sources[@]}"; do
tmp=$(echo "${url}" | awk -F '/' '{print $3}') tmp=$(awk -F '/' '{print $3}' <<< "${url}")
urls=("${urls[@]}" ${tmp}) urls=("${urls[@]}" ${tmp})
done done
echo " done!"
echo -e "${OVER} ${TICK} ${str}"
# Ensure adlist domains are in whitelist.txt
${whitelistScript} -nr -q "${urls[@]}" > /dev/null # Ensure adlist domains are in whitelist.txt
${whitelistScript} -nr -q "${urls[@]}" > /dev/null
# Check whitelist.txt exists.
if [[ -f "${whitelistFile}" ]]; then # Check whitelist.txt exists.
# Remove anything in whitelist.txt from the Event Horizon if [[ -f "${whitelistFile}" ]]; then
numWhitelisted=$(wc -l < "${whitelistFile}") # Remove anything in whitelist.txt from the Event Horizon
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s numWhitelisted=$(wc -l < "${whitelistFile}")
echo -n "::: Whitelisting $numWhitelisted domain${plural}..." plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
#print everything from preEventHorizon into eventHorizon EXCEPT domains in whitelist.txt local str="Whitelisting $numWhitelisted domain${plural}"
grep -F -x -v -f ${whitelistFile} ${piholeDir}/${preEventHorizon} > ${piholeDir}/${eventHorizon} echo -ne " ${INFO} ${str}..."
echo " done!"
else # Print everything from preEventHorizon into eventHorizon EXCEPT domains in whitelist.txt
echo "::: Nothing to whitelist!" grep -F -x -v -f ${whitelistFile} ${piholeDir}/${preEventHorizon} > ${piholeDir}/${eventHorizon}
fi
echo -e "${OVER} ${TICK} ${str}"
else
echo -e " ${INFO} Nothing to whitelist!"
fi
} }
gravity_unique() { gravity_unique() {
# Sort and remove duplicates # Sort and remove duplicates
echo -n "::: Removing duplicate domains...." local str="Removing duplicate domains"
sort -u ${piholeDir}/${supernova} > ${piholeDir}/${preEventHorizon} echo -ne " ${INFO} ${str}..."
echo " done!"
numberOf=$(wc -l < ${piholeDir}/${preEventHorizon}) sort -u ${piholeDir}/${supernova} > ${piholeDir}/${preEventHorizon}
echo "::: $numberOf unique domains trapped in the event horizon."
echo -e "${OVER} ${TICK} ${str}"
numberOf=$(wc -l < ${piholeDir}/${preEventHorizon})
echo -e " ${INFO} ${COL_LIGHT_BLUE}${numberOf}${COL_NC} unique domains trapped in the event horizon."
} }
gravity_hostFormat() { gravity_doHostFormat() {
# Format domain list as "192.168.x.x domain.com"
echo -n "::: 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
awk -v ipv4addr="$IPV4_ADDRESS" -v ipv6addr="$IPV6_ADDRESS" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> "${2}" < "${1}"
elif [[ -n "${IPV4_ADDRESS}" ]] && [[ -z "${IPV6_ADDRESS}" ]];then
# Only IPv4
awk -v ipv4addr="$IPV4_ADDRESS" '{sub(/\r$/,""); print ipv4addr" "$0}' >> "${2}" < "${1}"
elif [[ -z "${IPV4_ADDRESS}" ]] && [[ -n "${IPV6_ADDRESS}" ]];then
# Only IPv6
awk -v ipv6addr="$IPV6_ADDRESS" '{sub(/\r$/,""); print ipv6addr" "$0}' >> "${2}" < "${1}"
elif [[ -z "${IPV4_ADDRESS}" ]] &&[[ -z "${IPV6_ADDRESS}" ]];then
echo -e "${OVER} ${CROSS} ${str}"
echo -e " ${COL_LIGHT_RED}No IP Values found! Please run 'pihole -r' and choose reconfigure to restore values${COL_NC}"
exit 1
fi
}
echo -e "${IPV4_ADDRESS} ${hostname}\n${IPV6_ADDRESS} ${hostname}\n${IPV4_ADDRESS} pi.hole\n${IPV6_ADDRESS} pi.hole" > ${localList} gravity_hostFormatLocal() {
# Both IPv4 and IPv6 # Format domain list as "192.168.x.x domain.com"
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 if [[ -f "/etc/hostname" ]]; then
hostname=$(< /etc/hostname)
elif [ -x "$(command -v hostname)" ]; then
hostname=$(hostname -f)
else
echo -e " ${CROSS} Unable to determine fully qualified domain name of host"
fi
echo -e "${IPV4_ADDRESS} ${hostname}\n${IPV4_ADDRESS} pi.hole" > ${localList} echo -e "${hostname}\npi.hole" > "${localList}.tmp"
# Only IPv4 # Copy the file over as /etc/pihole/local.list so dnsmasq can use it
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPV4_ADDRESS" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} rm "${localList}"
gravity_doHostFormat "${localList}.tmp" "${localList}"
rm "${localList}.tmp"
}
elif [[ -z "${IPV4_ADDRESS}" && -n "${IPV6_ADDRESS}" ]];then gravity_hostFormatGravity() {
# Format domain list as "192.168.x.x domain.com"
echo "" > "${piholeDir}/${accretionDisc}"
gravity_doHostFormat "${piholeDir}/${eventHorizon}" "${piholeDir}/${accretionDisc}"
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
mv "${piholeDir}/${accretionDisc}" "${adList}"
echo -e "${IPV6_ADDRESS} ${hostname}\n${IPV6_ADDRESS} pi.hole" > ${localList} }
# Only IPv6
cat ${piholeDir}/${eventHorizon} | awk -v ipv6addr="$IPV6_ADDRESS" '{sub(/\r$/,""); print ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc}
elif [[ -z "${IPV4_ADDRESS}" && -z "${IPV6_ADDRESS}" ]];then gravity_hostFormatBlack() {
echo "::: No IP Values found! Please run 'pihole -r' and choose reconfigure to restore values" if [[ -f "${blacklistFile}" ]]; then
exit 1 numBlacklisted=$(wc -l < "${blacklistFile}")
# Format domain list as "192.168.x.x domain.com"
gravity_doHostFormat "${blacklistFile}" "${blackList}.tmp"
# Copy the file over as /etc/pihole/black.list so dnsmasq can use it
mv "${blackList}.tmp" "${blackList}"
else
echo -e " ${INFO} Nothing to blacklist!"
fi fi
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
cp ${piholeDir}/${accretionDisc} ${adList}
echo " done!"
} }
# blackbody - remove any remnant files from script processes # blackbody - remove any remnant files from script processes
gravity_blackbody() { gravity_blackbody() {
# Loop through list files # Loop through list files
for file in ${piholeDir}/*.${justDomainsExtension}; do for file in ${piholeDir}/*.${justDomainsExtension}; do
# If list is in active array then leave it (noop) else rm the list # If list is in active array then leave it (noop) else rm the list
if [[ " ${activeDomains[@]} " =~ ${file} ]]; then if [[ " ${activeDomains[@]} " =~ ${file} ]]; then
: :
else else
rm -f "${file}" rm -f "${file}"
fi fi
done done
} }
gravity_advanced() { gravity_advanced() {
# Remove comments and print only the domain name # Remove comments and print only the domain name
# Most of the lists downloaded are already in hosts file format but the spacing/formating is not contigious # Most of the lists downloaded are already in hosts file format but the spacing/formating is not contigious
# This helps with that and makes it easier to read # This helps with that and makes it easier to read
# It also helps with debugging so each stage of the script can be researched more in depth # It also helps with debugging so each stage of the script can be researched more in depth
echo -n "::: Formatting list of domains to remove comments...." local str="Formatting list of domains to remove comments"
#awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' ${piholeDir}/${matterAndLight} | sed -nr -e 's/\.{2,}/./g' -e '/\./p' > ${piholeDir}/${supernova} echo -ne " ${INFO} ${str}..."
#Above line does not correctly grab domains where comment is on the same line (e.g 'addomain.com #comment')
#Awk -F splits on given IFS, we grab the right hand side (chops trailing #coments and /'s to grab the domain only. #awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' ${piholeDir}/${matterAndLight} | sed -nr -e 's/\.{2,}/./g' -e '/\./p' > ${piholeDir}/${supernova}
#Last awk command takes non-commented lines and if they have 2 fields, take the left field (the domain) and leave #Above line does not correctly grab domains where comment is on the same line (e.g 'addomain.com #comment')
#+ the right (IP address), otherwise grab the single field. #Awk -F splits on given IFS, we grab the right hand side (chops trailing #coments and /'s to grab the domain only.
cat ${piholeDir}/${matterAndLight} | \ #Last awk command takes non-commented lines and if they have 2 fields, take the left field (the domain) and leave
awk -F '#' '{print $1}' | \ #+ the right (IP address), otherwise grab the single field.
awk -F '/' '{print $1}' | \ cat ${piholeDir}/${matterAndLight} | \
awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' | \ awk -F '#' '{print $1}' | \
sed -nr -e 's/\.{2,}/./g' -e '/\./p' > ${piholeDir}/${supernova} awk -F '/' '{print $1}' | \
echo " done!" awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' | \
sed -nr -e 's/\.{2,}/./g' -e '/\./p' > ${piholeDir}/${supernova}
numberOf=$(wc -l < ${piholeDir}/${supernova})
echo "::: ${numberOf} domains being pulled in by gravity..." echo -e "${OVER} ${TICK} ${str}"
gravity_unique numberOf=$(wc -l < ${piholeDir}/${supernova})
echo -e " ${INFO} ${COL_LIGHT_BLUE}${numberOf}${COL_NC} domains being pulled in by gravity"
gravity_unique
} }
gravity_reload() { gravity_reload() {
#Clear no longer needed files... # Reload hosts file
echo ":::" echo ""
echo -n "::: Cleaning up un-needed files..." local str="Refreshing lists in dnsmasq"
rm ${piholeDir}/pihole.*.txt echo -e " ${INFO} ${str}..."
echo " done!"
# Ensure /etc/dnsmasq.d/01-pihole.conf is pointing at the correct list!
# Reload hosts file # First escape forward slashes in the path:
echo ":::" adList=${adList//\//\\\/}
echo -n "::: Refresh lists in dnsmasq..." # Now replace the line in dnsmasq file
# sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
#ensure /etc/dnsmasq.d/01-pihole.conf is pointing at the correct list!
#First escape forward slashes in the path: "${PIHOLE_COMMAND}" restartdns
adList=${adList//\//\\\/}
#Now replace the line in dnsmasq file
# sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
"${PIHOLE_COMMAND}" restartdns
echo " done!"
} }
for var in "$@"; do for var in "$@"; do
case "${var}" in case "${var}" in
"-f" | "--force" ) forceGrav=true;; "-f" | "--force" ) forceGrav=true;;
"-h" | "--help" ) helpFunc;; "-h" | "--help" ) helpFunc;;
"-sd" | "--skip-download" ) skipDownload=true;; "-sd" | "--skip-download" ) skipDownload=true;;
esac "-b" | "--blacklist-only" ) blackListOnly=true;;
esac
done done
if [[ "${forceGrav}" == true ]]; then if [[ "${forceGrav}" == true ]]; then
echo -n "::: Deleting exising list cache..." str="Deleting exising list cache"
rm /etc/pihole/list.* echo -ne "${INFO} ${str}..."
echo " done!"
if rm /etc/pihole/list.* 2> /dev/null; then
echo -e "${OVER} ${TICK} ${str}"
else
echo -e "${OVER} ${CROSS} ${str}"
fi
fi fi
gravity_collapse if [[ ! "${blackListOnly}" == true ]]; then
gravity_spinup gravity_collapse
if [[ "${skipDownload}" == false ]]; then gravity_spinup
if [[ "${skipDownload}" == false ]]; then
gravity_Schwarzchild gravity_Schwarzchild
gravity_advanced gravity_advanced
else else
echo "::: Using cached Event Horizon list..." echo -e " ${INFO} Using cached Event Horizon list..."
numberOf=$(wc -l < ${piholeDir}/${preEventHorizon}) numberOf=$(wc -l < ${piholeDir}/${preEventHorizon})
echo "::: $numberOf unique domains trapped in the event horizon." echo -e " ${INFO} ${COL_LIGHT_BLUE}$numberOf${COL_NC} unique domains trapped in the event horizon."
fi
gravity_Whitelist
fi fi
gravity_Whitelist
gravity_Blacklist gravity_Blacklist
gravity_Wildcard gravity_Wildcard
gravity_hostFormat str="Formatting domains into a HOSTS file"
echo -ne " ${INFO} ${str}..."
if [[ ! "${blackListOnly}" == true ]]; then
gravity_hostFormatLocal
gravity_hostFormatGravity
fi
gravity_hostFormatBlack
echo -e "${OVER} ${TICK} ${str}"
gravity_blackbody gravity_blackbody
if [[ ! "${blackListOnly}" == true ]]; then
# Clear no longer needed files...
str="Cleaning up un-needed files"
echo -ne " ${INFO} ${str}..."
rm ${piholeDir}/pihole.*.txt 2> /dev/null
echo -e "${OVER} ${TICK} ${str}"
fi
gravity_reload gravity_reload
"${PIHOLE_COMMAND}" status "${PIHOLE_COMMAND}" status

553
pihole

@ -8,16 +8,19 @@
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole" colfile="/opt/pihole/COL_TABLE"
source ${colfile}
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf"
# Must be root to use this tool # Must be root to use this tool
if [[ ! $EUID -eq 0 ]];then if [[ ! $EUID -eq 0 ]];then
if [ -x "$(command -v sudo)" ];then if [[ -x "$(command -v sudo)" ]]; then
exec sudo bash "$0" "$@" exec sudo bash "$0" "$@"
exit $? exit $?
else else
echo "::: sudo is needed to run pihole commands. Please run this script as root or install sudo." echo -e " ${CROSS} sudo is needed to run pihole commands. Please run this script as root or install sudo."
exit 1 exit 1
fi fi
fi fi
@ -61,7 +64,7 @@ debugFunc() {
} }
flushFunc() { flushFunc() {
"${PI_HOLE_SCRIPT_DIR}"/piholeLogFlush.sh "${PI_HOLE_SCRIPT_DIR}"/piholeLogFlush.sh "$@"
exit 0 exit 0
} }
@ -84,10 +87,14 @@ scanList(){
domain="${1}" domain="${1}"
list="${2}" list="${2}"
method="${3}" method="${3}"
if [[ ${method} == "-exact" ]] ; then
grep -i -E "(^|\s)${domain}($|\s)" "${list}" # Switch folder, preventing grep from printing file path
cd "/etc/pihole" || return 1
if [[ -n "${method}" ]]; then
grep -i -E -l "(^|\s|\/)${domain}($|\s|\/)" ${list} /dev/null 2> /dev/null
else else
grep -i "${domain}" "${list}" grep -i "${domain}" ${list} /dev/null 2> /dev/null
fi fi
} }
@ -107,39 +114,217 @@ processWildcards() {
} }
queryFunc() { queryFunc() {
domain="${2}" options="$*"
method="${3}" options="${options/-q /}"
lists=( /etc/pihole/list.* /etc/pihole/blacklist.txt)
for list in ${lists[@]}; do if [[ "${options}" == "-h" ]] || [[ "${options}" == "--help" ]]; then
if [ -e "${list}" ]; then echo "Usage: pihole -q [option] <domain>
result=$(scanList ${domain} ${list} ${method}) Example: 'pihole -q -exact domain.com'
# Remove empty lines before couting number of results Query the adlists for a specified domain
count=$(sed '/^\s*$/d' <<< "$result" | wc -l)
echo "::: ${list} (${count} results)" Options:
if [[ ${count} > 0 ]]; then -adlist Print the name of the block list URL
echo "${result}" -exact Search the block lists for exact domain matches
-all Return all query matches within a block list
-h, --help Show this help dialog"
exit 0
fi
if [[ "${options}" == *"-exact"* ]]; then
method="exact"
exact=true
fi
if [[ "${options}" == *"-adlist"* ]]; then
adlist=true
fi
if [[ "${options}" == *"-bp"* ]]; then
method="exact"
blockpage=true
fi
if [[ "${options}" == *"-all"* ]]; then
all=true
fi
# Strip valid options, leaving only the domain and invalid options
options=$(sed 's/ \?-\(exact\|adlist\(s\)\?\|bp\|all\) \?//g' <<< "$options")
# Handle errors
if [[ "${options}" == *" "* ]]; then
error=true
str="Unknown option specified"
elif [[ "${options}" == "-q" ]]; then
error=true
str="No domain specified"
fi
if [[ -n "${error}" ]]; then
echo -e " ${COL_LIGHT_RED}${str}${COL_NC}
Try 'pihole -q --help' for more information."
exit 1
fi
# If domain contains non ASCII characters, convert domain to punycode if python is available
# Cr: https://serverfault.com/a/335079
if [[ "$options" = *[![:ascii:]]* ]]; then
if command -v python &> /dev/null; then
query=$(python -c 'import sys;print sys.argv[1].decode("utf-8").encode("idna")' "${options}")
fi
else
query="${options}"
fi
# Scan Whitelist and Blacklist
lists="whitelist.txt blacklist.txt"
results=($(scanList "${query}" "${lists}" "${method}"))
if [[ -n "${results[*]}" ]]; then
blResult=true
# Loop through each scanList line to print appropriate title
for result in "${results[@]}"; do
filename="${result/:*/}"
if [[ -n "$exact" ]]; then
printf " Exact result in %s\n" "${filename}"
elif [[ -n "$blockpage" ]]; then
printf "π %s\n" "${filename}"
else
domain="${result/*:/}"
if [[ ! "${filename}" == "${filename_prev:-}" ]]; then
printf " Result from %s\n" "${filename}"
fi
printf " %s\n" "${domain}"
filename_prev="${filename}"
fi fi
echo "" done
fi
# Scan Wildcards
if [[ -e "${wildcardlist}" ]]; then
wildcards=($(processWildcards "${query}"))
for match in "${wildcards[@]}"; do
results=($(scanList "\/${match}\/" ${wildcardlist}))
if [[ -n "${results[*]}" ]]; then
# Remove empty lines before couting number of results
count=$(sed '/^\s*$/d' <<< "${results[@]}" | wc -l)
if [[ "${count}" -ge 0 ]]; then
blResult=true
if [[ -z "${blockpage}" ]]; then
printf " Wildcard result in %s\n" "${wildcardlist/*dnsmasq.d\/}"
fi
if [[ -n "${blockpage}" ]]; then
echo "π ${wildcardlist/*\/}"
else
echo " *.${match}"
fi
fi
fi
done
[[ -n "${blResult}" ]] && [[ -n "${blockpage}" ]] && exit 0
fi
# Glob *.domains file names, remove file paths and sort by list number
lists_raw=(/etc/pihole/*.domains)
IFS_OLD=$IFS
IFS=$'\n'
lists=$(sort -t . -k 2 -g <<< "${lists_raw[*]//\/etc\/pihole\//}")
# Scan Domains files
results=($(scanList "${query}" "${lists}" "${method}"))
# Handle notices
if [[ -z "${blResult}" ]] && [[ -z "${results[*]}" ]]; then
notice=true
str="No ${method/t/t }results found for ${query} found within block lists"
elif [[ -z "${all}" ]] && [[ "${#results[*]}" -ge 16000 ]]; then
# 16000 chars is 15 chars X 1000 lines worth of results
notice=true
str="Hundreds of ${method/t/t }results found for ${query}
This can be overriden using the -all option"
fi
if [[ -n "${notice}" ]]; then
echo -e " ${INFO} ${str}"
exit
fi
# Remove unwanted content from results
if [[ -z "${method}" ]]; then
results=($(sed "/:#/d" <<< "${results[*]}")) # Lines starting with comments
results=($(sed "s/[ \t]#.*//g" <<< "${results[*]}")) # Comments after domain
results=($(sed "s/:.*[ \t]/:/g" <<< "${results[*]}")) # IP address
fi
IFS=$IFS_OLD
# Get adlist content as array
if [[ -n "${adlist}" ]] || [[ -n "${blockpage}" ]]; then
if [[ -f "/etc/pihole/adlists.list" ]]; then
for url in $(< /etc/pihole/adlists.list); do
if [[ "${url:0:4}" == "http" ]] || [[ "${url:0:3}" == "www" ]]; then
adlists+=("$url")
fi
done
else else
echo "::: ${list} does not exist" echo -e " ${COL_LIGHT_RED}The file '/etc/pihole/adlists.list' was not found${COL_NC}"
echo "" exit 1
fi fi
done fi
if [[ -n "${results[*]}" ]]; then
if [[ -n "${exact}" ]]; then
echo " Exact result(s) for ${query} found in:"
fi
for result in "${results[@]}"; do
filename="${result/:*/}"
# Convert file name to URL name for -adlist or -bp options
if [[ -n "${adlist}" ]] || [[ -n "${blockpage}" ]]; then
filenum=("${filename/list./}")
filenum=("${filenum/.*/}")
filename="${adlists[$filenum]}"
# If gravity has generated associated .domains files
# but adlists.list has been modified since
if [[ -z "${filename}" ]]; then
filename="${COL_LIGHT_RED}Error: no associated adlists URL found${COL_NC}"
fi
fi
# Scan for possible wildcard matches if [[ -n "${exact}" ]]; then
if [ -e "${wildcardlist}" ]; then printf " %s\n" "${filename}"
local wildcards=($(processWildcards "${domain}")) elif [[ -n "${blockpage}" ]]; then
for domain in ${wildcards[@]}; do printf "%s %s\n" "${filenum}" "${filename}"
result=$(scanList "\/${domain}\/" ${wildcardlist}) else # Standard query output
# Remove empty lines before couting number of results
count=$(sed '/^\s*$/d' <<< "$result" | wc -l) # Print filename heading once per file, not for every match
if [[ ${count} > 0 ]]; then if [[ ! "${filename}" == "${filename_prev:-}" ]]; then
echo "::: Wildcard blocking ${domain} (${count} results)" unset count
echo "${result}" printf " Result from %s\n" "${filename}"
echo "" else
let count++
fi
# Print matching domain if $max_count has not been reached
[[ -z "${all}" ]] && max_count="20"
if [[ -z "${all}" ]] && [[ "${count}" -eq "${max_count}" ]]; then
echo " Over $count results found, skipping rest of file"
elif [[ -z "${all}" ]] && [[ "${count}" -gt "${max_count}" ]]; then
continue
else
domain="${result/*:/}"
printf " %s\n" "${domain}"
fi
filename_prev="${filename}"
fi fi
done done
fi fi
exit 0 exit 0
} }
@ -163,163 +348,284 @@ versionFunc() {
restartDNS() { restartDNS() {
dnsmasqPid=$(pidof dnsmasq) dnsmasqPid=$(pidof dnsmasq)
if [[ ${dnsmasqPid} ]]; then local str="Restarting DNS service"
# service already running - reload config echo -ne " ${INFO} ${str}"
if [ -x "$(command -v systemctl)" ]; then if [[ "${dnsmasqPid}" ]]; then
systemctl restart dnsmasq # Service already running - reload config
if [[ -x "$(command -v systemctl)" ]]; then
output=$( { systemctl restart dnsmasq; } 2>&1 )
else
output=$( { service dnsmasq restart; } 2>&1 )
fi
if [[ -z "${output}" ]]; then
echo -e "${OVER} ${TICK} ${str}"
else else
service dnsmasq restart echo -e "${OVER} ${CROSS} ${output}"
fi fi
else else
# service not running, start it up # Service not running, start it up
if [ -x "$(command -v systemctl)" ]; then if [[ -x "$(command -v systemctl)" ]]; then
systemctl start dnsmasq output=$( { systemctl start dnsmasq; } 2>&1 )
else
output=$( { service dnsmasq start; } 2>&1 )
fi
if [[ -z "${output}" ]]; then
echo -e "${OVER} ${TICK} ${str}"
else else
service dnsmasq start echo -e "${OVER} ${CROSS} ${output}"
fi fi
fi fi
} }
piholeEnable() { piholeEnable() {
if [[ "${1}" == "0" ]] ; then if [[ "${2}" == "-h" ]] || [[ "${2}" == "--help" ]]; then
#Disable Pihole echo "Usage: pihole disable [time]
Example: 'pihole disable', or 'pihole disable 5m'
Disable Pi-hole subsystems
Time:
#s Disable Pi-hole functionality for # second(s)
#m Disable Pi-hole functionality for # minute(s)"
exit 0
elif [[ "${1}" == "0" ]]; then
# Disable Pi-hole
sed -i 's/^addn-hosts=\/etc\/pihole\/gravity.list/#addn-hosts=\/etc\/pihole\/gravity.list/' /etc/dnsmasq.d/01-pihole.conf sed -i 's/^addn-hosts=\/etc\/pihole\/gravity.list/#addn-hosts=\/etc\/pihole\/gravity.list/' /etc/dnsmasq.d/01-pihole.conf
echo "::: Blocking has been disabled!" sed -i 's/^addn-hosts=\/etc\/pihole\/black.list/#addn-hosts=\/etc\/pihole\/black.list/' /etc/dnsmasq.d/01-pihole.conf
if [[ $# > 1 ]] ; then if [[ -e "$wildcardlist" ]]; then
if [[ ${2} == *"s"* ]] ; then mv "$wildcardlist" "/etc/pihole/wildcard.list"
fi
if [[ $# > 1 ]]; then
local error=false
if [[ "${2}" == *"s" ]]; then
tt=${2%"s"} tt=${2%"s"}
echo "::: Blocking will be re-enabled in ${tt} seconds" if [[ "${tt}" =~ ^-?[0-9]+$ ]];then
nohup bash -c "sleep ${tt}; pihole enable" </dev/null &>/dev/null & local str="Disabling blocking for ${tt} seconds"
elif [[ ${2} == *"m"* ]] ; then echo -e " ${INFO} ${str}..."
local str="Blocking will be re-enabled in ${tt} seconds"
nohup bash -c "sleep ${tt}; pihole enable" </dev/null &>/dev/null &
else
local error=true
fi
elif [[ "${2}" == *"m" ]]; then
tt=${2%"m"} tt=${2%"m"}
echo "::: Blocking will be re-enabled in ${tt} minutes" if [[ "${tt}" =~ ^-?[0-9]+$ ]];then
tt=$((${tt}*60)) local str="Disabling blocking for ${tt} minutes"
nohup bash -c "sleep ${tt}; pihole enable" </dev/null &>/dev/null & echo -e " ${INFO} ${str}..."
local str="Blocking will be re-enabled in ${tt} minutes"
tt=$((${tt}*60))
nohup bash -c "sleep ${tt}; pihole enable" </dev/null &>/dev/null &
else
local error=true
fi
elif [[ -n "${2}" ]]; then
local error=true
else else
echo "::: Unknown format for delayed reactivation of the blocking!" echo -e " ${INFO} Disabling blocking"
echo "::: Example:" fi
echo "::: pihole disable 5s - will disable blocking for 5 seconds"
echo "::: pihole disable 7m - will disable blocking for 7 minutes" if [[ ${error} == true ]];then
echo "::: Blocking will not automatically be re-enabled!" echo -e " ${COL_LIGHT_RED}Unknown format for delayed reactivation of the blocking!${COL_NC}"
echo -e " Try 'pihole disable --help' for more information."
exit 1
fi fi
local str="Pi-hole Disabled"
fi fi
else else
#Enable pihole # Enable Pi-hole
echo "::: Blocking has been enabled!" echo -e " ${INFO} Enabling blocking"
local str="Pi-hole Enabled"
sed -i 's/^#addn-hosts/addn-hosts/' /etc/dnsmasq.d/01-pihole.conf sed -i 's/^#addn-hosts/addn-hosts/' /etc/dnsmasq.d/01-pihole.conf
if [[ -e "/etc/pihole/wildcard.list" ]]; then
mv "/etc/pihole/wildcard.list" "$wildcardlist"
fi
fi fi
restartDNS restartDNS
echo -e "${OVER} ${TICK} ${str}"
} }
piholeLogging() { piholeLogging() {
shift shift
if [[ "${1}" == "-h" ]] || [[ "${1}" == "--help" ]]; then
if [[ "${1}" == "off" ]] ; then echo "Usage: pihole logging [options]
#Disable Logging Example: 'pihole logging on'
Specify whether the Pi-hole log should be used
Options:
on Enable the Pi-hole log at /var/log/pihole.log
off Disable the Pi-hole log at /var/log/pihole.log"
exit 0
elif [[ "${1}" == "off" ]]; then
# Disable logging
sed -i 's/^log-queries/#log-queries/' /etc/dnsmasq.d/01-pihole.conf sed -i 's/^log-queries/#log-queries/' /etc/dnsmasq.d/01-pihole.conf
sed -i 's/^QUERY_LOGGING=true/QUERY_LOGGING=false/' /etc/pihole/setupVars.conf sed -i 's/^QUERY_LOGGING=true/QUERY_LOGGING=false/' /etc/pihole/setupVars.conf
pihole -f pihole -f
echo "::: Logging has been disabled!" echo -e " ${INFO} Disabling logging..."
elif [[ "${1}" == "on" ]] ; then local str="Logging has been disabled!"
#Enable logging elif [[ "${1}" == "on" ]]; then
# Enable logging
sed -i 's/^#log-queries/log-queries/' /etc/dnsmasq.d/01-pihole.conf sed -i 's/^#log-queries/log-queries/' /etc/dnsmasq.d/01-pihole.conf
sed -i 's/^QUERY_LOGGING=false/QUERY_LOGGING=true/' /etc/pihole/setupVars.conf sed -i 's/^QUERY_LOGGING=false/QUERY_LOGGING=true/' /etc/pihole/setupVars.conf
echo "::: Logging has been enabled!" echo -e " ${INFO} Enabling logging..."
local str="Logging has been enabled!"
else else
echo "::: Invalid option passed, please pass 'on' or 'off'" echo -e " ${COL_LIGHT_RED}Invalid option${COL_NC}
Try 'pihole logging --help' for more information."
exit 1 exit 1
fi fi
restartDNS restartDNS
echo -e "${OVER} ${TICK} ${str}"
} }
piholeStatus() { piholeStatus() {
if [[ $(netstat -plnt | grep -c ':53 ') > 0 ]]; then if [[ "$(netstat -plnt | grep -c ':53 ')" -gt "0" ]]; then
if [[ "${1}" != "web" ]] ; then if [[ "${1}" != "web" ]]; then
echo "::: DNS service is running" echo -e " ${TICK} DNS service is running"
fi fi
else else
if [[ "${1}" == "web" ]] ; then if [[ "${1}" == "web" ]]; then
echo "-1"; echo "-1";
else else
echo "::: DNS service is NOT running" echo -e " ${CROSS} DNS service is NOT running"
fi fi
return return
fi fi
if [[ $(grep -i "^#addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf) ]] ; then if [[ "$(grep -i "^#addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)" ]]; then
#list is commented out # List is commented out
if [[ "${1}" == "web" ]] ; then if [[ "${1}" == "web" ]]; then
echo 0; echo 0;
else else
echo "::: Pi-hole blocking is Disabled"; echo -e " ${CROSS} Pi-hole blocking is Disabled";
fi fi
elif [[ $(grep -i "^addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf) ]] ; then elif [[ "$(grep -i "^addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)" ]]; then
#list set # List set
if [[ "${1}" == "web" ]] ; then if [[ "${1}" == "web" ]]; then
echo 1; echo 1;
else else
echo "::: Pi-hole blocking is Enabled"; echo -e " ${TICK} Pi-hole blocking is Enabled";
fi fi
else else
#addn-host not found # Addn-host not found
if [[ "${1}" == "web" ]] ; then if [[ "${1}" == "web" ]]; then
echo 99 echo 99
else else
echo "::: No hosts file linked to dnsmasq, adding it in enabled state" echo -e " ${INFO} No hosts file linked to dnsmasq, adding it in enabled state"
fi fi
#add addn-host= to dnsmasq # Add addn-host= to dnsmasq
echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf
restartDNS restartDNS
fi fi
} }
tailFunc() { tailFunc() {
echo "Press Ctrl-C to exit" date=$(date +'%b %d ')
tail -F /var/log/pihole.log echo -e " ${INFO} Press Ctrl-C to exit"
tail -f /var/log/pihole.log | sed \
-e "s,\(${date}\| dnsmasq\[.*[0-9]]\),,g" \
-e "s,\(.*\(gravity.list\|black.list\| config \).* is \(${IPV4_ADDRESS%/*}\|${IPV6_ADDRESS:-NULL}\).*\),${COL_LIGHT_RED}&${COL_NC}," \
-e "s,.*\(query\[A\|DHCP\).*,${COL_NC}&${COL_NC}," \
-e "s,.*,${COL_DARK_GRAY}&${COL_NC},"
exit 0 exit 0
} }
piholeCheckoutFunc() { piholeCheckoutFunc() {
if [[ "$2" == "-h" ]] || [[ "$2" == "--help" ]]; then
echo "Usage: pihole checkout [repo] [branch]
Example: 'pihole checkout master' or 'pihole checkout core dev'
Switch Pi-hole subsystems to a different Github branch
Repositories:
core [branch] Change the branch of Pi-hole's core subsystem
web [branch] Change the branch of Admin Console subsystem
ftl [branch] Change the branch of Pi-hole's FTL subsystem
Branches:
master Update subsystems to the latest stable release
dev Update subsystems to the latest development release"
exit 0
fi
source "${PI_HOLE_SCRIPT_DIR}"/piholeCheckout.sh source "${PI_HOLE_SCRIPT_DIR}"/piholeCheckout.sh
shift shift
checkout "$@" checkout "$@"
} }
tricorderFunc() {
if [[ ! -p "/dev/stdin" ]]; then
echo -e " ${INFO} Please do not call Tricorder directly"
exit 1
fi
if ! timeout 2 nc -z tricorder.pi-hole.net 9998 &> /dev/null; then
echo -e " ${CROSS} Unable to connect to Pi-hole's Tricorder server"
exit 1
fi
if command -v openssl &> /dev/null; then
openssl s_client -quiet -connect tricorder.pi-hole.net:9998 2> /dev/null < /dev/stdin
exit "$?"
else
echo -e " ${INFO} ${COL_YELLOW}Security Notice${COL_NC}: ${COL_WHITE}openssl${COL_NC} is not installed
Your debug log will be transmitted unencrypted via plain-text
There is a possibility that this could be intercepted by a third party
If you wish to cancel, press Ctrl-C to exit within 10 seconds"
secs="10"
while [[ "$secs" -gt "0" ]]; do
echo -ne "."
sleep 1
: $((secs--))
done
echo " "
nc tricorder.pi-hole.net 9999 < /dev/stdin
exit "$?"
fi
}
helpFunc() { helpFunc() {
cat << EOM echo "Usage: pihole [options]
::: Control all Pi-hole specific functions Example: 'pihole -w -h'
::: Add '-h' after specific commands for more information on usage
::: Usage: pihole [options]
::: Add -h after -w (whitelist), -b (blacklist), -c (chronometer), or -a (admin) for more information on usage Whitelist/Blacklist Options:
::: -w, whitelist Whitelist domain(s)
::: Options: -b, blacklist Blacklist domain(s)
::: -w, whitelist Whitelist domain(s) -wild, wildcard Blacklist domain(s), and all its subdomains
::: -b, blacklist Blacklist domain(s) (exact match) Add '-h' for more info on whitelist/blacklist usage
::: -wild, wildcard Blacklist whole domain(s) (wildcard)
::: -d, debug Start a debugging session Debugging Options:
::: Automated debugging can be enabled with '-a'. -d, debug Start a debugging session
::: 'pihole -d -a' Add '-a' to enable automated debugging
::: -f, flush Flush the 'pihole.log' file -f, flush Flush the Pi-hole log
::: -t, tail Output the last lines of the 'pihole.log' file. Lines are appended as the file grows -r, reconfigure Reconfigure or Repair Pi-hole subsystems
::: -up, updatePihole Update Pi-hole components -t, tail View the live output of the Pi-hole log
::: -r, reconfigure Reconfigure or Repair Pi-hole
::: -g, updateGravity Update the list of ad-serving domains Options:
::: -c, chronometer Calculates stats and displays to an LCD -a, admin Admin Console options
::: -h, help Show this help dialog Add '-h' for more info on admin console usage
::: -v, version Show installed versions of Pi-hole and Web-Admin -c, chronometer Calculates stats and displays to an LCD
::: -q, query Query the adlists for a specific domain Add '-h' for more info on chronometer usage
::: 'pihole -q domain -exact' shows exact matches only -g, updateGravity Update the list of ad-serving domains
::: -l, logging Enable or Disable logging (pass 'on' or 'off') -h, --help, help Show this help dialog
::: -a, admin Admin webpage options -l, logging Specify whether the Pi-hole log should be used
::: uninstall Uninstall Pi-hole from your system! :( Add '-h' for more info on logging usage
::: status Display if Pi-hole is Enabled or Disabled -q, query Query the adlists for a specified domain
::: enable Enable Pi-hole DNS Blocking Add '-h' for more info on query usage
::: disable Disable Pi-hole DNS Blocking -up, updatePihole Update Pi-hole subsystems
::: Blocking can also be disabled only temporarily, e.g., -v, version Show installed versions of Pi-hole, Admin Console & FTL
::: 'pihole disable 5m' - will disable blocking for 5 minutes Add '-h' for more info on version usage
::: restartdns Restart dnsmasq uninstall Uninstall Pi-hole from your system
::: checkout Check out different branches status Display the running status of Pi-hole subsystems
EOM enable Enable Pi-hole subsystems
disable Disable Pi-hole subsystems
Add '-h' for more info on disable usage
restartdns Restart Pi-hole subsystems
checkout Switch Pi-hole subsystems to a different Github branch
Add '-h' for more info on checkout usage";
exit 0 exit 0
} }
@ -333,7 +639,7 @@ case "${1}" in
"-b" | "blacklist" ) blacklistFunc "$@";; "-b" | "blacklist" ) blacklistFunc "$@";;
"-wild" | "wildcard" ) wildcardFunc "$@";; "-wild" | "wildcard" ) wildcardFunc "$@";;
"-d" | "debug" ) debugFunc "$@";; "-d" | "debug" ) debugFunc "$@";;
"-f" | "flush" ) flushFunc;; "-f" | "flush" ) flushFunc "$@";;
"-up" | "updatePihole" ) updatePiholeFunc;; "-up" | "updatePihole" ) updatePiholeFunc;;
"-r" | "reconfigure" ) reconfigurePiholeFunc;; "-r" | "reconfigure" ) reconfigurePiholeFunc;;
"-g" | "updateGravity" ) updateGravityFunc "$@";; "-g" | "updateGravity" ) updateGravityFunc "$@";;
@ -344,11 +650,12 @@ case "${1}" in
"-l" | "logging" ) piholeLogging "$@";; "-l" | "logging" ) piholeLogging "$@";;
"uninstall" ) uninstallFunc;; "uninstall" ) uninstallFunc;;
"enable" ) piholeEnable 1;; "enable" ) piholeEnable 1;;
"disable" ) piholeEnable 0 $2;; "disable" ) piholeEnable 0 "$2";;
"status" ) piholeStatus "$2";; "status" ) piholeStatus "$2";;
"restartdns" ) restartDNS;; "restartdns" ) restartDNS;;
"-a" | "admin" ) webpageFunc "$@";; "-a" | "admin" ) webpageFunc "$@";;
"-t" | "tail" ) tailFunc;; "-t" | "tail" ) tailFunc;;
"checkout" ) piholeCheckoutFunc "$@";; "checkout" ) piholeCheckoutFunc "$@";;
"tricorder" ) tricorderFunc;;
* ) helpFunc;; * ) helpFunc;;
esac esac

@ -9,6 +9,10 @@ SETUPVARS = {
'PIHOLE_DNS_2' : '4.2.2.2' 'PIHOLE_DNS_2' : '4.2.2.2'
} }
tick_box="[\x1b[1;32m\xe2\x9c\x93\x1b[0m]".decode("utf-8")
cross_box="[\x1b[1;31m\xe2\x9c\x97\x1b[0m]".decode("utf-8")
info_box="[i]".decode("utf-8")
def test_setupVars_are_sourced_to_global_scope(Pihole): def test_setupVars_are_sourced_to_global_scope(Pihole):
''' currently update_dialogs sources setupVars with a dot, ''' currently update_dialogs sources setupVars with a dot,
then various other functions use the variables. then various other functions use the variables.
@ -55,6 +59,8 @@ def test_setupVars_saved_to_file(Pihole):
TERM=xterm TERM=xterm
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
{} {}
mkdir -p /etc/dnsmasq.d
version_check_dnsmasq
finalExports finalExports
cat /etc/pihole/setupVars.conf cat /etc/pihole/setupVars.conf
'''.format(set_setup_vars)) '''.format(set_setup_vars))
@ -74,7 +80,7 @@ def test_configureFirewall_firewalld_running_no_errors(Pihole):
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
configureFirewall configureFirewall
''') ''')
expected_stdout = 'Configuring FirewallD for httpd and dnsmasq.' expected_stdout = 'Configuring FirewallD for httpd and dnsmasq'
assert expected_stdout in configureFirewall.stdout assert expected_stdout in configureFirewall.stdout
firewall_calls = Pihole.run('cat /var/log/firewall-cmd').stdout firewall_calls = Pihole.run('cat /var/log/firewall-cmd').stdout
assert 'firewall-cmd --state' in firewall_calls assert 'firewall-cmd --state' in firewall_calls
@ -89,7 +95,7 @@ def test_configureFirewall_firewalld_disabled_no_errors(Pihole):
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
configureFirewall configureFirewall
''') ''')
expected_stdout = 'No active firewall detected.. skipping firewall configuration.' expected_stdout = 'No active firewall detected.. skipping firewall configuration'
assert expected_stdout in configureFirewall.stdout assert expected_stdout in configureFirewall.stdout
def test_configureFirewall_firewalld_enabled_declined_no_errors(Pihole): def test_configureFirewall_firewalld_enabled_declined_no_errors(Pihole):
@ -173,8 +179,11 @@ def test_installPiholeWeb_fresh_install_no_errors(Pihole):
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
installPiholeWeb installPiholeWeb
''') ''')
assert 'Installing pihole custom index page...' in installWeb.stdout assert info_box + ' Installing blocking page...' in installWeb.stdout
assert tick_box + ' Creating directory for blocking page, and copying files' in installWeb.stdout
assert cross_box + ' Backing up index.lighttpd.html' in installWeb.stdout
assert 'No default index.lighttpd.html file found... not backing up' in installWeb.stdout assert 'No default index.lighttpd.html file found... not backing up' in installWeb.stdout
assert tick_box + ' Installing sudoer file' in installWeb.stdout
web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout
assert 'index.php' in web_directory assert 'index.php' in web_directory
assert 'index.js' in web_directory assert 'index.js' in web_directory
@ -187,11 +196,12 @@ def test_installPiholeWeb_empty_directory_no_errors(Pihole):
mkdir -p /var/www/html/pihole mkdir -p /var/www/html/pihole
installPiholeWeb installPiholeWeb
''') ''')
assert 'Installing pihole custom index page...' in installWeb.stdout assert info_box + ' Installing blocking page...' in installWeb.stdout
assert info_box + ' Installing index.php' in installWeb.stdout
assert info_box + ' Installing index.js' in installWeb.stdout
assert info_box + ' Installing blockingpage.css' in installWeb.stdout
assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout
assert 'index.php missing, replacing...' in installWeb.stdout assert tick_box + ' Installing sudoer file' in installWeb.stdout
assert 'index.js missing, replacing...' in installWeb.stdout
assert 'blockingpage.css missing, replacing...' in installWeb.stdout
web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout
assert 'index.php' in web_directory assert 'index.php' in web_directory
assert 'index.js' in web_directory assert 'index.js' in web_directory
@ -205,11 +215,13 @@ def test_installPiholeWeb_index_php_no_errors(Pihole):
touch /var/www/html/pihole/index.php touch /var/www/html/pihole/index.php
installPiholeWeb installPiholeWeb
''') ''')
assert 'Installing pihole custom index page...' in installWeb.stdout assert info_box + ' Installing blocking page...' in installWeb.stdout
assert info_box + ' Installing index.php' in installWeb.stdout
assert 'detected index.php, not overwriting' in installWeb.stdout
assert info_box + ' Installing index.js' in installWeb.stdout
assert info_box + ' Installing blockingpage.css' in installWeb.stdout
assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout
assert 'Existing index.php detected, not overwriting' in installWeb.stdout assert tick_box + ' Installing sudoer file' in installWeb.stdout
assert 'index.js missing, replacing...' in installWeb.stdout
assert 'blockingpage.css missing, replacing...' in installWeb.stdout
web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout
assert 'index.php' in web_directory assert 'index.php' in web_directory
assert 'index.js' in web_directory assert 'index.js' in web_directory
@ -223,11 +235,13 @@ def test_installPiholeWeb_index_js_no_errors(Pihole):
touch /var/www/html/pihole/index.js touch /var/www/html/pihole/index.js
installPiholeWeb installPiholeWeb
''') ''')
assert 'Installing pihole custom index page...' in installWeb.stdout assert info_box + ' Installing blocking page...' in installWeb.stdout
assert info_box + ' Installing index.php' in installWeb.stdout
assert info_box + ' Installing index.js' in installWeb.stdout
assert 'detected index.js, not overwriting' in installWeb.stdout
assert info_box + ' Installing blockingpage.css' in installWeb.stdout
assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout
assert 'index.php missing, replacing...' in installWeb.stdout assert tick_box + ' Installing sudoer file' in installWeb.stdout
assert 'Existing index.js detected, not overwriting' in installWeb.stdout
assert 'blockingpage.css missing, replacing...' in installWeb.stdout
web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout
assert 'index.php' in web_directory assert 'index.php' in web_directory
assert 'index.js' in web_directory assert 'index.js' in web_directory
@ -241,11 +255,13 @@ def test_installPiholeWeb_blockingpage_css_no_errors(Pihole):
touch /var/www/html/pihole/blockingpage.css touch /var/www/html/pihole/blockingpage.css
installPiholeWeb installPiholeWeb
''') ''')
assert 'Installing pihole custom index page...' in installWeb.stdout assert info_box + ' Installing blocking page...' in installWeb.stdout
assert info_box + ' Installing index.php' in installWeb.stdout
assert info_box + ' Installing index.js' in installWeb.stdout
assert info_box + ' Installing blockingpage.css' in installWeb.stdout
assert 'detected blockingpage.css, not overwriting' in installWeb.stdout
assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout
assert 'index.php missing, replacing...' in installWeb.stdout assert tick_box + ' Installing sudoer file' in installWeb.stdout
assert 'index.js missing, replacing...' in installWeb.stdout
assert 'Existing blockingpage.css detected, not overwriting' in installWeb.stdout
web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout
assert 'index.php' in web_directory assert 'index.php' in web_directory
assert 'index.js' in web_directory assert 'index.js' in web_directory
@ -261,14 +277,14 @@ def test_installPiholeWeb_already_populated_no_errors(Pihole):
touch /var/www/html/pihole/blockingpage.css touch /var/www/html/pihole/blockingpage.css
installPiholeWeb installPiholeWeb
''') ''')
assert 'Installing pihole custom index page...' in installWeb.stdout assert info_box + ' Installing blocking page...' in installWeb.stdout
assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout assert info_box + ' Installing index.php' in installWeb.stdout
assert 'Existing index.php detected, not overwriting' in installWeb.stdout assert 'detected index.php, not overwriting' in installWeb.stdout
assert 'index.php missing, replacing...' not in installWeb.stdout assert info_box + ' Installing index.js' in installWeb.stdout
assert 'Existing index.js detected, not overwriting' in installWeb.stdout assert 'detected index.js, not overwriting' in installWeb.stdout
assert 'index.js missing, replacing...' not in installWeb.stdout assert info_box + ' Installing blockingpage.css' in installWeb.stdout
assert 'Existing blockingpage.css detected, not overwriting' in installWeb.stdout assert 'detected blockingpage.css, not overwriting' in installWeb.stdout
assert 'blockingpage.css missing, replacing... ' not in installWeb.stdout assert tick_box + ' Installing sudoer file' in installWeb.stdout
web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout
assert 'index.php' in web_directory assert 'index.php' in web_directory
assert 'index.js' in web_directory assert 'index.js' in web_directory
@ -281,9 +297,8 @@ def test_update_package_cache_success_no_errors(Pihole):
distro_check distro_check
update_package_cache update_package_cache
''') ''')
assert 'Updating local cache of available packages...' in updateCache.stdout assert tick_box + ' Update local cache of available packages' in updateCache.stdout
assert 'ERROR' not in updateCache.stdout assert 'Error: Unable to update package cache.' not in updateCache.stdout
assert 'done!' in updateCache.stdout
def test_update_package_cache_failure_no_errors(Pihole): def test_update_package_cache_failure_no_errors(Pihole):
''' confirms package cache was not updated''' ''' confirms package cache was not updated'''
@ -293,9 +308,8 @@ def test_update_package_cache_failure_no_errors(Pihole):
distro_check distro_check
update_package_cache update_package_cache
''') ''')
assert 'Updating local cache of available packages...' in updateCache.stdout assert cross_box + ' Update local cache of available packages' in updateCache.stdout
assert 'ERROR' in updateCache.stdout assert 'Error: Unable to update package cache.' in updateCache.stdout
assert 'done!' not in updateCache.stdout
def test_FTL_detect_aarch64_no_errors(Pihole): def test_FTL_detect_aarch64_no_errors(Pihole):
''' confirms only aarch64 package is downloaded for FTL engine ''' ''' confirms only aarch64 package is downloaded for FTL engine '''
@ -307,7 +321,11 @@ def test_FTL_detect_aarch64_no_errors(Pihole):
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
FTLdetect FTLdetect
''') ''')
expected_stdout = 'Detected ARM-aarch64 architecture' expected_stdout = info_box + ' FTL Checks...'
assert expected_stdout in detectPlatform.stdout
expected_stdout = tick_box + ' Detected ARM-aarch64 architecture'
assert expected_stdout in detectPlatform.stdout
expected_stdout = tick_box + ' Downloading and Installing FTL'
assert expected_stdout in detectPlatform.stdout assert expected_stdout in detectPlatform.stdout
def test_FTL_detect_armv6l_no_errors(Pihole): def test_FTL_detect_armv6l_no_errors(Pihole):
@ -320,7 +338,11 @@ def test_FTL_detect_armv6l_no_errors(Pihole):
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
FTLdetect FTLdetect
''') ''')
expected_stdout = 'Detected ARM-hf architecture (armv6 or lower)' expected_stdout = info_box + ' FTL Checks...'
assert expected_stdout in detectPlatform.stdout
expected_stdout = tick_box + ' Detected ARM-hf architecture (armv6 or lower)'
assert expected_stdout in detectPlatform.stdout
expected_stdout = tick_box + ' Downloading and Installing FTL'
assert expected_stdout in detectPlatform.stdout assert expected_stdout in detectPlatform.stdout
def test_FTL_detect_armv7l_no_errors(Pihole): def test_FTL_detect_armv7l_no_errors(Pihole):
@ -333,7 +355,11 @@ def test_FTL_detect_armv7l_no_errors(Pihole):
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
FTLdetect FTLdetect
''') ''')
expected_stdout = 'Detected ARM-hf architecture (armv7+)' expected_stdout = info_box + ' FTL Checks...'
assert expected_stdout in detectPlatform.stdout
expected_stdout = tick_box + ' Detected ARM-hf architecture (armv7+)'
assert expected_stdout in detectPlatform.stdout
expected_stdout = tick_box + ' Downloading and Installing FTL'
assert expected_stdout in detectPlatform.stdout assert expected_stdout in detectPlatform.stdout
def test_FTL_detect_x86_64_no_errors(Pihole): def test_FTL_detect_x86_64_no_errors(Pihole):
@ -342,7 +368,11 @@ def test_FTL_detect_x86_64_no_errors(Pihole):
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
FTLdetect FTLdetect
''') ''')
expected_stdout = 'Detected x86_64 architecture' expected_stdout = info_box + ' FTL Checks...'
assert expected_stdout in detectPlatform.stdout
expected_stdout = tick_box + ' Detected x86_64 architecture'
assert expected_stdout in detectPlatform.stdout
expected_stdout = tick_box + ' Downloading and Installing FTL'
assert expected_stdout in detectPlatform.stdout assert expected_stdout in detectPlatform.stdout
def test_FTL_detect_unknown_no_errors(Pihole): def test_FTL_detect_unknown_no_errors(Pihole):
@ -363,9 +393,12 @@ def test_FTL_download_aarch64_no_errors(Pihole):
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
FTLinstall pihole-FTL-aarch64-linux-gnu FTLinstall pihole-FTL-aarch64-linux-gnu
''') ''')
expected_stdout = 'done' expected_stdout = tick_box + ' Downloading and Installing FTL'
assert expected_stdout in download_binary.stdout assert expected_stdout in download_binary.stdout
assert 'failed' not in download_binary.stdout error = 'Error: Download of binary from Github failed'
assert error not in download_binary.stdout
error = 'Error: URL not found'
assert error not in download_binary.stdout
def test_FTL_download_unknown_fails_no_errors(Pihole): def test_FTL_download_unknown_fails_no_errors(Pihole):
''' confirms unknown binary is not downloaded for FTL engine ''' ''' confirms unknown binary is not downloaded for FTL engine '''
@ -374,9 +407,10 @@ def test_FTL_download_unknown_fails_no_errors(Pihole):
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
FTLinstall pihole-FTL-mips FTLinstall pihole-FTL-mips
''') ''')
expected_stdout = 'failed' expected_stdout = cross_box + ' Downloading and Installing FTL'
assert expected_stdout in download_binary.stdout assert expected_stdout in download_binary.stdout
assert 'done' not in download_binary.stdout error = 'Error: URL not found'
assert error in download_binary.stdout
def test_FTL_binary_installed_and_responsive_no_errors(Pihole): def test_FTL_binary_installed_and_responsive_no_errors(Pihole):
''' confirms FTL binary is copied and functional in installed location ''' ''' confirms FTL binary is copied and functional in installed location '''
@ -402,6 +436,61 @@ def test_FTL_binary_installed_and_responsive_no_errors(Pihole):
# assert '644 /run/pihole-FTL.pid' in support_files.stdout # assert '644 /run/pihole-FTL.pid' in support_files.stdout
# assert '644 /var/log/pihole-FTL.log' in support_files.stdout # assert '644 /var/log/pihole-FTL.log' in support_files.stdout
def test_IPv6_only_link_local(Pihole):
''' confirms IPv6 blocking is disabled for Link-local address '''
# mock ip -6 address to return Link-local address
mock_command_2('ip', {'-6 address':('inet6 fe80::d210:52fa:fe00:7ad7/64 scope link', '0')}, Pihole)
detectPlatform = Pihole.run('''
source /opt/pihole/basic-install.sh
useIPv6dialog
''')
expected_stdout = 'Unable to find IPv6 ULA/GUA address, IPv6 adblocking will not be enabled'
assert expected_stdout in detectPlatform.stdout
def test_IPv6_only_ULA(Pihole):
''' confirms IPv6 blocking is enabled for ULA addresses '''
# mock ip -6 address to return ULA address
mock_command_2('ip', {'-6 address':('inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global', '0')}, Pihole)
detectPlatform = Pihole.run('''
source /opt/pihole/basic-install.sh
useIPv6dialog
''')
expected_stdout = 'Found IPv6 ULA address, using it for blocking IPv6 ads'
assert expected_stdout in detectPlatform.stdout
def test_IPv6_only_GUA(Pihole):
''' confirms IPv6 blocking is enabled for GUA addresses '''
# mock ip -6 address to return GUA address
mock_command_2('ip', {'-6 address':('inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global', '0')}, Pihole)
detectPlatform = Pihole.run('''
source /opt/pihole/basic-install.sh
useIPv6dialog
''')
expected_stdout = 'Found IPv6 GUA address, using it for blocking IPv6 ads'
assert expected_stdout in detectPlatform.stdout
def test_IPv6_GUA_ULA_test(Pihole):
''' confirms IPv6 blocking is enabled for GUA and ULA addresses '''
# mock ip -6 address to return GUA and ULA addresses
mock_command_2('ip', {'-6 address':('inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global\ninet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global', '0')}, Pihole)
detectPlatform = Pihole.run('''
source /opt/pihole/basic-install.sh
useIPv6dialog
''')
expected_stdout = 'Found IPv6 ULA address, using it for blocking IPv6 ads'
assert expected_stdout in detectPlatform.stdout
def test_IPv6_ULA_GUA_test(Pihole):
''' confirms IPv6 blocking is enabled for GUA and ULA addresses '''
# mock ip -6 address to return ULA and GUA addresses
mock_command_2('ip', {'-6 address':('inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global\ninet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global', '0')}, Pihole)
detectPlatform = Pihole.run('''
source /opt/pihole/basic-install.sh
useIPv6dialog
''')
expected_stdout = 'Found IPv6 ULA address, using it for blocking IPv6 ads'
assert expected_stdout in detectPlatform.stdout
# Helper functions # Helper functions
def mock_command(script, args, container): def mock_command(script, args, container):
''' Allows for setup of commands we don't really want to have to run for real in unit tests ''' ''' Allows for setup of commands we don't really want to have to run for real in unit tests '''
@ -424,6 +513,27 @@ def mock_command(script, args, container):
chmod +x {script} chmod +x {script}
rm -f /var/log/{scriptlog}'''.format(script=full_script_path, content=mock_script, scriptlog=script)) rm -f /var/log/{scriptlog}'''.format(script=full_script_path, content=mock_script, scriptlog=script))
def mock_command_2(script, args, container):
''' Allows for setup of commands we don't really want to have to run for real in unit tests '''
full_script_path = '/usr/local/bin/{}'.format(script)
mock_script = dedent('''\
#!/bin/bash -e
echo "\$0 \$@" >> /var/log/{script}
case "\$1 \$2" in'''.format(script=script))
for k, v in args.iteritems():
case = dedent('''
\"{arg}\")
echo \"{res}\"
exit {retcode}
;;'''.format(arg=k, res=v[0], retcode=v[1]))
mock_script += case
mock_script += dedent('''
esac''')
container.run('''
cat <<EOF> {script}\n{content}\nEOF
chmod +x {script}
rm -f /var/log/{scriptlog}'''.format(script=full_script_path, content=mock_script, scriptlog=script))
def run_script(Pihole, script): def run_script(Pihole, script):
result = Pihole.run(script) result = Pihole.run(script)
assert result.rc == 0 assert result.rc == 0

@ -7,7 +7,7 @@ run_local = testinfra.get_backend(
def test_scripts_pass_shellcheck(): def test_scripts_pass_shellcheck():
''' Make sure shellcheck does not find anything wrong with our shell scripts ''' ''' Make sure shellcheck does not find anything wrong with our shell scripts '''
shellcheck = "find . -type f \( -name 'update.sh' -o -name 'piholeDebug.sh' \) | while read file; do shellcheck \"$file\"; done;" shellcheck = "find . -type f -name 'update.sh' | while read file; do shellcheck -x \"$file\" -e SC1090,SC1091; done;"
results = run_local(shellcheck) results = run_local(shellcheck)
print results.stdout print results.stdout
assert '' == results.stdout assert '' == results.stdout

Loading…
Cancel
Save