mirror of
https://github.com/pi-hole/pi-hole
synced 2025-01-08 23:20:56 +00:00
Merge branch 'development' into gedetil-development
Signed-off-by: DL6ER <dl6er@dl6er.de> Conflicts: advanced/Scripts/webpage.sh
This commit is contained in:
commit
0d037e96fb
36
.github/ISSUE_TEMPLATE.md
vendored
36
.github/ISSUE_TEMPLATE.md
vendored
@ -1,33 +1,37 @@
|
||||
**In raising this issue, I confirm the following (please check boxes, eg [X]) Failure to fill the template will close your issue:**
|
||||
**In raising this issue, I confirm the following:** `{please fill the checkboxes, e.g: [X]}`
|
||||
|
||||
- [] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md).
|
||||
- [] The issue I am reporting can be *replicated*
|
||||
- [] The issue I am reporting can be *replicated*.
|
||||
- [] The issue I am reporting isn't a duplicate (see [FAQs](https://github.com/pi-hole/pi-hole/wiki/FAQs), [closed issues](https://github.com/pi-hole/pi-hole/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), and [open issues](https://github.com/pi-hole/pi-hole/issues)).
|
||||
|
||||
**How familiar are you with the codebase?:**
|
||||
**How familiar are you with the the source code relevant to this issue?:**
|
||||
|
||||
_{replace this text with a number from 1 to 10, with 1 being not familiar, and 10 being very familiar}_
|
||||
`{Replace this with a number from 1 to 10. 1 being not familiar, and 10 being very familiar}`
|
||||
|
||||
---
|
||||
**[BUG REPORT | OTHER]:**
|
||||
**Expected behaviour:**
|
||||
|
||||
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.
|
||||
`{A detailed description of what you expect to see}`
|
||||
|
||||
**[BUG | ISSUE] Expected Behaviour:**
|
||||
**Actual behaviour:**
|
||||
|
||||
`{A detailed description and/or screenshots of what you do see}`
|
||||
|
||||
**[BUG | ISSUE] Actual Behaviour:**
|
||||
**Steps to reproduce:**
|
||||
|
||||
`{Detailed steps of how we can reproduce this}`
|
||||
|
||||
**[BUG | ISSUE] Steps to reproduce:**
|
||||
**Debug token provided by [uploading `pihole -d` log](https://discourse.pi-hole.net/t/the-pihole-command-with-examples/738#debug):**
|
||||
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
`{Alphanumeric token}`
|
||||
|
||||
**(Optional) Debug token generated by `pihole -d`:**
|
||||
**Troubleshooting undertaken, and/or other relevant information:**
|
||||
|
||||
`<token>`
|
||||
`{Steps of what you have done to fix this}`
|
||||
|
||||
_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._
|
||||
> * `{Please delete this quoted section when opening your issue}`
|
||||
> * You must follow the template instructions. Failure to do so will result in your issue being closed.
|
||||
> * Please [submit any feature requests here](https://discourse.pi-hole.net/c/feature-requests), so it is votable and trackable by the community.
|
||||
> * Please respect that Pi-hole is developed by volunteers, who can only reply in their spare time.
|
||||
> * Detail helps us understand and resolve an issue quicker, but please ensure it's relevant.
|
||||
> * _This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._
|
||||
|
37
.github/PULL_REQUEST_TEMPLATE.md
vendored
37
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -1,19 +1,32 @@
|
||||
**By submitting this pull request, I confirm the following (please check boxes, eg [X]) _Failure to fill the template will close your PR_:**
|
||||
**By submitting this pull request, I confirm the following:** `{please fill any appropriate checkboxes, e.g: [X]}`
|
||||
|
||||
***Please submit all pull requests against the `development` branch. Failure to do so will delay or deny your request***
|
||||
`{Please ensure that your pull request is for the 'development' branch!}`
|
||||
|
||||
- [] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md).
|
||||
- [] I have written tests and verified that they fail without my change.
|
||||
- [] I have squashed any insignificant commits.
|
||||
- [] This change has comments for package types, values, functions, and non-obvious lines of code.
|
||||
- [] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md), as well as this entire template.
|
||||
- [] I have made only one major change in my proposed changes.
|
||||
- [] I have commented my proposed changes within the code.
|
||||
- [] I have tested my proposed changes, and have included unit tests where possible.
|
||||
- [] 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`)
|
||||
- [] I give this submission freely and claim no ownership.
|
||||
- [] It is compatible with the [EUPL 1.2 license](https://opensource.org/licenses/EUPL-1.1)
|
||||
- [] I have squashed any insignificant commits. ([`git rebase`](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html))
|
||||
- [] I have Signed Off all commits. ([`git commit --signoff`](https://git-scm.com/docs/git-commit#git-commit---signoff))
|
||||
|
||||
***Please explain what you have done and wish to accomplish with this Pull Request***
|
||||
---
|
||||
|
||||
1. What does this change do, exactly?
|
||||
**What does this PR aim to accomplish?:**
|
||||
|
||||
2. Please link to the relevant issues.
|
||||
`{A detailed description, screenshots (if necessary), as well as links to any relevant GitHub issues}`
|
||||
|
||||
3. Which documentation changes (if any) need to be made because of this PR?
|
||||
**How does this PR accomplish the above?:**
|
||||
|
||||
`{A detailed description (such as a changelog) and screenshots (if necessary) of the implemented fix}`
|
||||
|
||||
**What documentation changes (if any) are needed to support this PR?:**
|
||||
|
||||
`{A detailed list of any necessary changes}`
|
||||
|
||||
> * `{Please delete this quoted section when opening your pull request}`
|
||||
> * You must follow the template instructions. Failure to do so will result in your issue being closed.
|
||||
> * Please respect that Pi-hole is developed by volunteers, who can only reply in their spare time.
|
||||
> * Detail helps us understand an issue quicker, but please ensure it's relevant.
|
||||
|
316
README.md
316
README.md
@ -8,37 +8,33 @@
|
||||
<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>
|
||||
|
||||
## 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
|
||||
## Executive Summary
|
||||
The Pi-hole blocks ads at the DNS-level, so all your devices are protected.
|
||||
|
||||
<p align="center">
|
||||
<a href=http://www.digitalocean.com/?refcode=344d234950e1><img src="https://assets.pi-hole.net/static/DOHostingSlug.png"></a>
|
||||
</p>
|
||||
- **Easy-to-install** - our intelligent installer walks you through the process with no additional software needed on client devices
|
||||
- **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
|
||||
|
||||
## Your Support Still Matters
|
||||
|
||||
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)
|
||||
- ![Bitcoin](https://assets.pi-hole.net/static/Bitcoin.png) Bitcoin Address: 1GKnevUnVaQM2pQieMyeHkpr8DXfkpfAtL
|
||||
|
||||
### 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)
|
||||
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._
|
||||
|
||||
##### 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
|
||||
@ -53,91 +49,233 @@ wget -O basic-install.sh https://install.pi-hole.net
|
||||
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.
|
||||
|
||||
## What is Pi-hole™ and how do I install it?
|
||||
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?
|
||||
<p align="center">
|
||||
<a href=https://www.youtube.com/watch?v=vKWjx1AQYgs><img src="https://assets.pi-hole.net/static/video-explainer.png"></a>
|
||||
</p>
|
||||
|
||||
# Pi-hole Is Free, But Powered By Your Donations
|
||||
|
||||
## Get Help Or Connect With Us On The Web
|
||||
All [our developers](https://github.com/orgs/pi-hole/people) are 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)
|
||||
- ![Bitcoin](https://assets.pi-hole.net/static/Bitcoin.png) Bitcoin Address: 1GKnevUnVaQM2pQieMyeHkpr8DXfkpfAtL
|
||||
|
||||
## Other Ways To Support Us
|
||||
### Affiliate Links
|
||||
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.
|
||||
|
||||
### 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
|
||||
|
||||
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.
|
||||
|
||||
# Overview Of Features
|
||||
|
||||
## The Dashboard (Web Interface)
|
||||
|
||||
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):
|
||||
|
||||
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 Query Log
|
||||
|
||||
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.
|
||||
|
||||
<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/).
|
||||
|
||||
#### 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>
|
||||
|
||||
### 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).
|
||||
|
||||
<p align="center">
|
||||
<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>
|
||||
|
||||
#### 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
|
||||
|
||||
The settings page lets you control and configure your Pi-hole. You can do things like:
|
||||
|
||||
- view networking information
|
||||
- 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
|
||||
- restart Pi-hole's services
|
||||
- back up some of Pi-hole's important files
|
||||
- and more!
|
||||
|
||||
<p align="center">
|
||||
<img src="https://assets.pi-hole.net/static/settings-page.png">
|
||||
</p>
|
||||
|
||||
|
||||
## 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.
|
||||
|
||||
<p align="center">
|
||||
<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>
|
||||
|
||||
## The FTL Engine: Our API
|
||||
|
||||
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
|
||||
{
|
||||
"domains_being_blocked":111175,
|
||||
"dns_queries_today":15669,
|
||||
"ads_blocked_today":1752,
|
||||
"ads_percentage_today":11.181314,
|
||||
"unique_domains":1178,
|
||||
"queries_forwarded":9177,
|
||||
"queries_cached":4740,
|
||||
"unique_clients":18
|
||||
}
|
||||
```
|
||||
|
||||
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
|
||||
# Technical Details
|
||||
|
||||
The Pi-hole™ is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement.
|
||||
|
||||
### Gravity
|
||||
|
||||
The [gravity.sh](https://github.com/pi-hole/pi-hole/blob/master/gravity.sh) does most of the magic. The script pulls in ad domains from many sources and compiles them into a single list of [over 1.6 million entries](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0) (if you decide to use the [mahakala list](https://github.com/pi-hole/pi-hole/commit/963eacfe0537a7abddf30441c754c67ca1e40965)). This script is controlled by the `pihole` command. Please run `pihole -h` to see what commands can be run via `pihole`.
|
||||
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.
|
||||
|
||||
|
||||
|
||||
#### Other Operating Systems
|
||||
|
||||
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.
|
||||
|
||||
### Web Interface
|
||||
|
||||
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:
|
||||
|
||||
`http://192.168.1.x/admin/index.php` or `http://pi.hole/admin`
|
||||
|
||||
![Pi-hole Advanced Stats Dashboard](https://assets.pi-hole.net/static/dashboard212.png)
|
||||
|
||||
### Whitelist and blacklist
|
||||
|
||||
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">
|
||||
<a href=https://github.com/pi-hole/pi-hole/wiki/Whitelisting-and-Blacklisting><img src="https://assets.pi-hole.net/static/whitelist212.png"></a>
|
||||
</p>
|
||||
|
||||
### Settings
|
||||
|
||||
The settings page lets you control and configure your Pi-hole™. You can do things like:
|
||||
|
||||
- enable Pi-hole's built-in DHCP server
|
||||
- exclude domains from the graphs
|
||||
- configure upstream DNS servers
|
||||
- and more!
|
||||
|
||||
![Settings page](https://assets.pi-hole.net/static/settings212.png)
|
||||
|
||||
#### Built-in DHCP Server
|
||||
|
||||
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">
|
||||
<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>
|
||||
</p>
|
||||
|
||||
## API
|
||||
|
||||
A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON:
|
||||
|
||||
``` json
|
||||
{
|
||||
"domains_being_blocked": "136708",
|
||||
"dns_queries_today": "18108",
|
||||
"ads_blocked_today": "14648",
|
||||
"ads_percentage_today": "80.89"
|
||||
}
|
||||
```
|
||||
|
||||
The same output can be achieved on the CLI by running `chronometer.sh -j`
|
||||
|
||||
## Real-time Statistics
|
||||
|
||||
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)
|
||||
- [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py)
|
||||
@ -158,7 +296,7 @@ You can view [real-time stats](https://discourse.pi-hole.net/t/how-do-i-view-my-
|
||||
- [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)
|
||||
- [TekThing: 5 fun, easy projects for a Raspberry Pi](https://youtu.be/QwrKlyC2kdM?t=1m42s)
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1090,SC1091
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||
# Network-wide ad blocking via your own hardware.
|
||||
@ -7,6 +8,7 @@
|
||||
#
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
LC_NUMERIC=C
|
||||
|
||||
# Retrieve stats from FTL engine
|
||||
pihole-FTL() {
|
||||
@ -32,43 +34,74 @@ pihole-FTL() {
|
||||
exec 3<&-
|
||||
fi
|
||||
else
|
||||
echo -e "${COL_LIGHT_RED}FTL offline${COL_NC}"
|
||||
echo "0"
|
||||
fi
|
||||
}
|
||||
|
||||
# Print spaces to align right-side content
|
||||
# Print spaces to align right-side additional text
|
||||
printFunc() {
|
||||
txt_len="${#2}"
|
||||
|
||||
# Reduce string length when using colour code
|
||||
[ "${2:0:1}" == "" ] && txt_len=$((txt_len-7))
|
||||
|
||||
if [[ "$3" == "last" ]]; then
|
||||
# Prevent final line from printing trailing newline
|
||||
scr_size=( $(stty size 2>/dev/null || echo 24 80) )
|
||||
scr_width="${scr_size[1]}"
|
||||
|
||||
title_len="${#1}"
|
||||
spc_num=$(( (scr_width - title_len) - txt_len ))
|
||||
[[ "$spc_num" -lt 0 ]] && spc_num="0"
|
||||
spc=$(printf "%${spc_num}s")
|
||||
|
||||
printf "%s%s$spc" "$1" "$2"
|
||||
else
|
||||
# Determine number of spaces for padding
|
||||
spc_num=$(( 20 - txt_len ))
|
||||
[[ "$spc_num" -lt 0 ]] && spc_num="0"
|
||||
spc=$(printf "%${spc_num}s")
|
||||
local text_last
|
||||
|
||||
# Print string (Max 20 characters, prevents overflow)
|
||||
printf "%s%s$spc" "$1" "${2:0:20}"
|
||||
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
|
||||
}
|
||||
|
||||
# Perform on first Chrono run (not for JSON formatted string)
|
||||
get_init_stats() {
|
||||
LC_NUMERIC=C
|
||||
calcFunc(){ awk "BEGIN {print $*}"; }
|
||||
calcFunc(){ awk "BEGIN {print $*}" 2> /dev/null; }
|
||||
|
||||
# Convert bytes to human-readable format
|
||||
hrBytes() {
|
||||
@ -90,33 +123,53 @@ get_init_stats() {
|
||||
|
||||
# Convert seconds to human-readable format
|
||||
hrSecs() {
|
||||
day=$(( $1/60/60/24 )); hrs=$(( $1/3600%24 )); mins=$(( ($1%3600)/60 )); secs=$(( $1%60 ))
|
||||
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"
|
||||
}
|
||||
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='[0m'
|
||||
COL_DARK_GRAY='[1;30m'
|
||||
COL_LIGHT_GREEN='[1;32m'
|
||||
COL_LIGHT_BLUE='[1;34m'
|
||||
COL_LIGHT_RED='[1;31m'
|
||||
COL_YELLOW='[1;33m'
|
||||
COL_LIGHT_RED='[1;31m'
|
||||
COL_URG_RED='[39;41m'
|
||||
COL_NC="[0m"
|
||||
COL_DARK_GRAY="[1;30m"
|
||||
COL_LIGHT_GREEN="[1;32m"
|
||||
COL_LIGHT_BLUE="[1;34m"
|
||||
COL_LIGHT_RED="[1;31m"
|
||||
COL_YELLOW="[1;33m"
|
||||
COL_LIGHT_RED="[1;31m"
|
||||
COL_URG_RED="[39;41m"
|
||||
fi
|
||||
|
||||
# Get RPi model number, or OS distro info
|
||||
# Get RPi throttle state (RPi 3B only) & model number, or OS distro info
|
||||
if command -v vcgencmd &> /dev/null; then
|
||||
sys_rev=$(awk '/Revision/ {print $3}' < /proc/cpuinfo)
|
||||
case "$sys_rev" in
|
||||
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
|
||||
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
|
||||
@ -126,7 +179,7 @@ get_init_stats() {
|
||||
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="" ;;
|
||||
*) sys_model="";;
|
||||
esac
|
||||
sys_type="Raspberry Pi$sys_model"
|
||||
else
|
||||
@ -137,7 +190,6 @@ get_init_stats() {
|
||||
|
||||
# Get core count
|
||||
sys_cores=$(grep -c "^processor" /proc/cpuinfo)
|
||||
[[ "$sys_cores" -ne 1 ]] && sys_cores_plu="cores" || sys_cores_plu="core"
|
||||
|
||||
# Test existence of clock speed file for ARM CPU
|
||||
if [[ -f "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]]; then
|
||||
@ -168,80 +220,96 @@ get_sys_stats() {
|
||||
# Update every 12 refreshes (Def: every 60s)
|
||||
count=$((count+1))
|
||||
if [[ "$count" == "1" ]] || (( "$count" % 12 == 0 )); then
|
||||
# Do not source setupVars if file does not exist
|
||||
[[ -n "$setupVars" ]] && source "$setupVars"
|
||||
|
||||
|
||||
ph_ver_raw=($(pihole -v -c 2> /dev/null | sed -n 's/^.* v/v/p'))
|
||||
|
||||
mapfile -t ph_ver_raw < <(pihole -v -c 2> /dev/null | sed -n 's/^.* v/v/p')
|
||||
if [[ -n "${ph_ver_raw[0]}" ]]; then
|
||||
ph_core_ver="${ph_ver_raw[0]}"
|
||||
ph_lte_ver="${ph_ver_raw[1]}"
|
||||
ph_ftl_ver="${ph_ver_raw[2]}"
|
||||
else
|
||||
ph_core_ver="${COL_LIGHT_RED}API unavailable${COL_NC}"
|
||||
ph_core_ver="-1"
|
||||
fi
|
||||
|
||||
|
||||
sys_name=$(hostname)
|
||||
|
||||
|
||||
[[ -n "$TEMPERATUREUNIT" ]] && temp_unit="$TEMPERATUREUNIT" || temp_unit="c"
|
||||
|
||||
|
||||
# Get storage stats for partition mounted on /
|
||||
disk_raw=($(df -B1 / 2> /dev/null | awk 'END{ print $3,$2,$5 }'))
|
||||
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_eip="${DHCP_END##*.}"
|
||||
ph_dhcp_max=$(( ${DHCP_END##*.} - ${DHCP_START##*.} + 1 ))
|
||||
fi
|
||||
|
||||
# Get alt DNS server, or print total count of alt DNS servers
|
||||
if [[ -z "${PIHOLE_DNS_3}" ]]; then
|
||||
ph_alts="${PIHOLE_DNS_2}"
|
||||
else
|
||||
dns_count="0"
|
||||
[[ -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+"
|
||||
ph_alts="${dns_count} others"
|
||||
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% CPU as active
|
||||
|
||||
# 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 $4;exit}')
|
||||
cpu_mhz=$(lscpu | awk -F ":" '/MHz/ {print $2;exit}')
|
||||
cpu_mhz=$(printf "%.0f" "${cpu_mhz//[[:space:]]/}")
|
||||
fi
|
||||
|
||||
# Determine correct string format for CPU clock speed
|
||||
|
||||
# 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"
|
||||
[[ -n "$cpu_freq" ]] && cpu_freq_str=" @ $cpu_freq" || cpu_freq_str=""
|
||||
[[ "$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")")
|
||||
|
||||
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="";;
|
||||
@ -249,13 +317,13 @@ get_sys_stats() {
|
||||
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"
|
||||
|
||||
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")")
|
||||
|
||||
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="";;
|
||||
@ -263,132 +331,201 @@ get_sys_stats() {
|
||||
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"
|
||||
|
||||
|
||||
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")")
|
||||
cpu_temp_str=$(printf " @ %.0fk\\n" "$(calcFunc "($(< $temp_file) / 1000) + 273.15")")
|
||||
fi
|
||||
else
|
||||
cpu_temp_str=""
|
||||
fi
|
||||
|
||||
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))
|
||||
|
||||
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}Inactive"
|
||||
ph_status="${COL_LIGHT_RED}Offline"
|
||||
fi
|
||||
|
||||
|
||||
if [[ "$DHCP_ACTIVE" == "true" ]]; then
|
||||
ph_dhcp_num=$(wc -l 2> /dev/null < "/etc/pihole/dhcp.leases")
|
||||
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
|
||||
|
||||
stats_raw=($(pihole-FTL "stats"))
|
||||
domains_being_blocked_raw="${stats_raw[1]}"
|
||||
dns_queries_today_raw="${stats_raw[3]}"
|
||||
ads_blocked_today_raw="${stats_raw[5]}"
|
||||
ads_percentage_today_raw="${stats_raw[7]}"
|
||||
|
||||
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 recent_blocked_raw
|
||||
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}")
|
||||
|
||||
recent_blocked_raw=$(pihole-FTL recentBlocked)
|
||||
top_ad_raw=($(pihole-FTL "top-ads (1)"))
|
||||
top_domain_raw=($(pihole-FTL "top-domains (1)"))
|
||||
top_client_raw=($(pihole-FTL "top-clients (1)"))
|
||||
|
||||
# Limit strings to 40 characters to prevent overflow
|
||||
recent_blocked="${recent_blocked_raw:0:40}"
|
||||
top_ad="${top_ad_raw[2]:0:40}"
|
||||
top_domain="${top_domain_raw[2]:0:40}"
|
||||
[[ "${top_client_raw[3]}" ]] && top_client="${top_client_raw[3]:0:40}" || top_client="${top_client_raw[2]:0:40}"
|
||||
|
||||
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}"
|
||||
}
|
||||
|
||||
chronoFunc() {
|
||||
get_init_stats
|
||||
|
||||
|
||||
for (( ; ; )); do
|
||||
get_sys_stats
|
||||
get_ftl_stats
|
||||
|
||||
# Do not print LTE/FTL strings if API is unavailable
|
||||
ph_core_str=" ${COL_DARK_GRAY}Pi-hole: $ph_core_ver${COL_NC}"
|
||||
if [[ -n "$ph_lte_ver" ]]; then
|
||||
ph_lte_str=" ${COL_DARK_GRAY}AdminLTE: $ph_lte_ver${COL_NC}"
|
||||
ph_ftl_str=" ${COL_DARK_GRAY}FTL: $ph_ftl_ver${COL_NC}"
|
||||
fi
|
||||
|
||||
clear
|
||||
|
||||
echo -e "[0;1;31;91m|¯[0;1;33;93m¯[0;1;32;92m¯[0;1;32;92m(¯[0;1;36;96m)_[0;1;34;94m_[0;1;35;95m|[0;1;33;93m¯[0;1;31;91m|_ [0;1;32;92m__[0;1;36;96m_|[0;1;31;91m¯[0;1;34;94m|[0;1;35;95m__[0;1;31;91m_[0m$ph_core_str
|
||||
[0;1;33;93m| ¯[0;1;32;92m_[0;1;36;96m/¯[0;1;34;94m|_[0;1;35;95m_[0;1;31;91m| [0;1;33;93m' [0;1;32;92m\/ [0;1;36;96m_ [0;1;34;94m\ [0;1;35;95m/ [0;1;31;91m-[0;1;33;93m_)[0m$ph_lte_str
|
||||
[0;1;32;92m|_[0;1;36;96m| [0;1;34;94m|_[0;1;35;95m| [0;1;33;93m|_[0;1;32;92m||[0;1;36;96m_\[0;1;34;94m__[0;1;35;95m_/[0;1;31;91m_\[0;1;33;93m__[0;1;32;92m_|[0m$ph_ftl_str
|
||||
${COL_DARK_GRAY}——————————————————————————————————————————————————————————${COL_NC}"
|
||||
get_strings
|
||||
|
||||
printFunc " Hostname: " "$sys_name"
|
||||
[ -n "$sys_type" ] && printf "%s(%s)%s\n" "$COL_DARK_GRAY" "$sys_type" "$COL_NC" || printf "\n"
|
||||
|
||||
printf "%s\n" " Uptime: $sys_uptime"
|
||||
|
||||
printFunc " Task Load: " "$sys_loadavg"
|
||||
printf "%s(%s)%s\n" "$COL_DARK_GRAY" "Active: $cpu_taskact of $cpu_tasks tasks" "$COL_NC"
|
||||
|
||||
printFunc " CPU usage: " "$cpu_perc%"
|
||||
printf "%s(%s)%s\n" "$COL_DARK_GRAY" "$sys_cores $sys_cores_plu$cpu_freq_str$cpu_temp_str" "$COL_NC"
|
||||
|
||||
printFunc " RAM usage: " "$ram_perc%"
|
||||
printf "%s(%s)%s\n" "$COL_DARK_GRAY" "Used: $(hrBytes "$ram_used") of $(hrBytes "$ram_total")" "$COL_NC"
|
||||
|
||||
printFunc " HDD usage: " "$disk_perc"
|
||||
printf "%s(%s)%s\n" "$COL_DARK_GRAY" "Used: $(hrBytes "$disk_used") of $(hrBytes "$disk_total")" "$COL_NC"
|
||||
|
||||
printFunc " LAN addr: " "${IPV4_ADDRESS/\/*/}"
|
||||
printf "%s(%s)%s\n" "$COL_DARK_GRAY" "Gateway: $net_gateway" "$COL_NC"
|
||||
|
||||
if [[ "$DHCP_ACTIVE" == "true" ]]; then
|
||||
printFunc " DHCP: " "$DHCP_START to $ph_dhcp_eip"
|
||||
printf "%s(%s)%s\n" "$COL_DARK_GRAY" "Leased: $ph_dhcp_num of $ph_dhcp_max" "$COL_NC"
|
||||
# Strip excess development version numbers
|
||||
if [[ "$ph_core_ver" != "-1" ]]; then
|
||||
phc_ver_str="$phc_str: ${ph_core_ver%-*}${COL_NC}"
|
||||
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
|
||||
|
||||
printFunc " Pi-hole: " "$ph_status"
|
||||
printf "%s(%s)%s\n" "$COL_DARK_GRAY" "Blocking: $domains_being_blocked sites" "$COL_NC"
|
||||
|
||||
printFunc " Ads Today: " "$ads_percentage_today%"
|
||||
printf "%s(%s)%s\n" "$COL_DARK_GRAY" "$ads_blocked_today of $dns_queries_today queries" "$COL_NC"
|
||||
|
||||
printFunc " Fwd DNS: " "$PIHOLE_DNS_1"
|
||||
printf "%s(%s)%s\n" "$COL_DARK_GRAY" "Alt DNS: $ph_alts" "$COL_NC"
|
||||
|
||||
echo -e " ${COL_DARK_GRAY}——————————————————————————————————————————————————————————${COL_NC}"
|
||||
echo " Recently blocked: $recent_blocked"
|
||||
echo " Top Advertiser: $top_ad"
|
||||
echo " Top Domain: $top_domain"
|
||||
printFunc " Top Client: " "$top_client" "last"
|
||||
|
||||
if [[ "$1" == "exit" ]]; then
|
||||
|
||||
# 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 "[0;1;31;91m|¯[0;1;33;93m¯[0;1;32;92m¯[0;1;32;92m(¯[0;1;36;96m)[0;1;34;94m_[0;1;35;95m|[0;1;33;93m¯[0;1;31;91m|_ [0;1;32;92m__[0;1;36;96m_|[0;1;31;91m¯[0;1;34;94m|[0;1;35;95m__[0;1;31;91m_[0m$phc_ver_str
|
||||
[0;1;33;93m| ¯[0;1;32;92m_[0;1;36;96m/¯[0;1;34;94m|[0;1;35;95m_[0;1;31;91m| [0;1;33;93m' [0;1;32;92m\\/ [0;1;36;96m_ [0;1;34;94m\\ [0;1;35;95m/ [0;1;31;91m-[0;1;33;93m_)[0m$lte_ver_str
|
||||
[0;1;32;92m|_[0;1;36;96m| [0;1;34;94m|_[0;1;35;95m| [0;1;33;93m|_[0;1;32;92m||[0;1;36;96m_\\[0;1;34;94m__[0;1;35;95m_/[0;1;31;91m_\\[0;1;33;93m__[0;1;32;92m_|[0m$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 [[ -n "$1" ]]; then
|
||||
sleep "${1}"
|
||||
if [[ "$*" == *"-r"* ]]; then
|
||||
sleep "$num"
|
||||
else
|
||||
sleep 5
|
||||
fi
|
||||
@ -409,14 +546,14 @@ helpFunc() {
|
||||
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
|
||||
}
|
||||
|
||||
@ -428,8 +565,8 @@ for var in "$@"; do
|
||||
case "$var" in
|
||||
"-j" | "--json" ) jsonFunc;;
|
||||
"-h" | "--help" ) helpFunc;;
|
||||
"-r" | "--refresh" ) chronoFunc "$2";;
|
||||
"-e" | "--exit" ) chronoFunc "exit";;
|
||||
"-r" | "--refresh" ) chronoFunc "$@";;
|
||||
"-e" | "--exit" ) chronoFunc "$@";;
|
||||
* ) helpFunc "?";;
|
||||
esac
|
||||
done
|
||||
|
@ -62,11 +62,14 @@ EscapeRegexp() {
|
||||
}
|
||||
|
||||
HandleOther() {
|
||||
# First, convert everything to lowercase
|
||||
domain=$(sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" <<< "$1")
|
||||
# Convert to lowercase
|
||||
domain="${1,,}"
|
||||
|
||||
# Check validity of domain
|
||||
validDomain=$(echo "${domain}" | perl -lne 'print if /(?!.*[^a-z0-9-\.].*)^((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9-]+\.)*[a-z]{2,63}/')
|
||||
validDomain=$(perl -lne 'print if /^((-|_)*[a-z\d]((-|_)*[a-z\d])*(-|_)*)(\.(-|_)*([a-z\d]((-|_)*[a-z\d])*))*$/' <<< "${domain}") # Valid chars check
|
||||
validDomain=$(perl -lne 'print if /^.{1,253}$/' <<< "${validDomain}") # Overall length check
|
||||
validDomain=$(perl -lne 'print if /^[^\.]{1,63}(\.[^\.]{1,63})*$/' <<< "${validDomain}") # Length of each label
|
||||
|
||||
if [[ -z "${validDomain}" ]]; then
|
||||
echo -e " ${CROSS} $1 is not a valid argument or domain name!"
|
||||
else
|
||||
@ -98,7 +101,7 @@ PoplistFile() {
|
||||
AddDomain() {
|
||||
list="$2"
|
||||
domain=$(EscapeRegexp "$1")
|
||||
|
||||
|
||||
[[ "${list}" == "${whitelist}" ]] && listname="whitelist"
|
||||
[[ "${list}" == "${blacklist}" ]] && listname="blacklist"
|
||||
[[ "${list}" == "${wildcardlist}" ]] && listname="wildcard blacklist"
|
||||
@ -151,7 +154,7 @@ AddDomain() {
|
||||
RemoveDomain() {
|
||||
list="$2"
|
||||
domain=$(EscapeRegexp "$1")
|
||||
|
||||
|
||||
[[ "${list}" == "${whitelist}" ]] && listname="whitelist"
|
||||
[[ "${list}" == "${blacklist}" ]] && listname="blacklist"
|
||||
[[ "${list}" == "${wildcardlist}" ]] && listname="wildcard blacklist"
|
||||
|
@ -3,7 +3,7 @@
|
||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||
# Network-wide ad blocking via your own hardware.
|
||||
#
|
||||
# Switch Pi-hole subsystems to a different Github branch
|
||||
# Switch Pi-hole subsystems to a different Github branch.
|
||||
#
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
@ -24,6 +24,98 @@ 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() {
|
||||
# Add upstream branches to shallow clone
|
||||
local directory="${1}"
|
||||
@ -40,7 +132,8 @@ fully_fetch_repo() {
|
||||
|
||||
get_available_branches() {
|
||||
# Return available branches
|
||||
local directory="${1}"
|
||||
local directory
|
||||
directory="${1}"
|
||||
local output
|
||||
|
||||
cd "${directory}" || return 1
|
||||
@ -50,45 +143,52 @@ get_available_branches() {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
fetch_checkout_pull_branch() {
|
||||
# Check out specified branch
|
||||
local directory="${1}"
|
||||
local branch="${2}"
|
||||
local directory
|
||||
directory="${1}"
|
||||
local branch
|
||||
branch="${2}"
|
||||
|
||||
# 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 stash --all --quiet &> /dev/null || true
|
||||
git clean --force -d || true
|
||||
git clean --quiet --force -d || true
|
||||
git fetch --quiet || return 1
|
||||
checkout_pull_branch "${directory}" "${branch}" || return 1
|
||||
}
|
||||
|
||||
checkout_pull_branch() {
|
||||
# Check out specified branch
|
||||
local directory="${1}"
|
||||
local branch="${2}"
|
||||
local directory
|
||||
directory="${1}"
|
||||
local branch
|
||||
branch="${2}"
|
||||
local oldbranch
|
||||
|
||||
cd "${directory}" || return 1
|
||||
|
||||
oldbranch="$(git symbolic-ref HEAD)"
|
||||
|
||||
git checkout "${branch}" || return 1
|
||||
|
||||
str="Switching to branch: '${branch}' from '${oldbranch}'"
|
||||
echo -ne " ${INFO} $str"
|
||||
git checkout "${branch}" --quiet || return 1
|
||||
echo -e "${OVER} ${TICK} $str"
|
||||
|
||||
|
||||
if [[ "$(git diff "${oldbranch}" | grep -c "^")" -gt "0" ]]; then
|
||||
update="true"
|
||||
fi
|
||||
|
||||
git_pull=$(git pull || return 1)
|
||||
|
||||
|
||||
if [[ "$git_pull" == *"up-to-date"* ]]; then
|
||||
echo -e "\n ${INFO} $(git pull)"
|
||||
echo -e " ${INFO} ${git_pull}"
|
||||
else
|
||||
echo -e "$git_pull\n"
|
||||
echo -e "$git_pull\\n"
|
||||
fi
|
||||
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -97,13 +197,13 @@ warning1() {
|
||||
echo " Features that work on the master branch, may not on a development branch"
|
||||
echo -e " ${COL_LIGHT_RED}This feature is NOT supported unless a Pi-hole developer explicitly asks!${COL_NC}"
|
||||
read -r -p " Have you read and understood this? [y/N] " response
|
||||
case ${response} in
|
||||
case "${response}" in
|
||||
[yY][eE][sS]|[yY])
|
||||
echo ""
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
echo -e "\n ${INFO} Branch change has been cancelled"
|
||||
echo -e "\\n ${INFO} Branch change has been cancelled"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
@ -122,7 +222,7 @@ checkout() {
|
||||
Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}"
|
||||
exit 1;
|
||||
fi
|
||||
if [[ ${INSTALL_WEB} == "true" ]]; then
|
||||
if [[ "${INSTALL_WEB}" == "true" ]]; then
|
||||
if ! is_repo "${webInterfaceDir}" ; then
|
||||
echo -e " ${COL_LIGHT_RED}Error: Web Admin repo is missing from system!
|
||||
Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}"
|
||||
@ -143,13 +243,20 @@ checkout() {
|
||||
if [[ "${1}" == "dev" ]] ; then
|
||||
# Shortcut to check out development branches
|
||||
echo -e " ${INFO} Shortcut \"dev\" detected - checking out development / devel branches..."
|
||||
echo -e " ${INFO} Pi-hole core"
|
||||
echo ""
|
||||
echo -e " ${INFO} Pi-hole Core"
|
||||
fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo " ${CROSS} Unable to pull Core developement branch"; exit 1; }
|
||||
if [[ ${INSTALL_WEB} == "true" ]]; then
|
||||
if [[ "${INSTALL_WEB}" == "true" ]]; then
|
||||
echo ""
|
||||
echo -e " ${INFO} Web interface"
|
||||
fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo " ${CROSS} Unable to pull Web development branch"; exit 1; }
|
||||
fi
|
||||
echo -e " ${TICK} Pi-hole core"
|
||||
#echo -e " ${TICK} Pi-hole Core"
|
||||
|
||||
get_binary_name
|
||||
local path
|
||||
path="development/${binary}"
|
||||
FTLinstall "${binary}" "${path}"
|
||||
elif [[ "${1}" == "master" ]] ; then
|
||||
# Shortcut to check out master branches
|
||||
echo -e " ${INFO} Shortcut \"master\" detected - checking out master branches..."
|
||||
@ -159,23 +266,26 @@ checkout() {
|
||||
echo -e " ${INFO} Web interface"
|
||||
fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo " ${CROSS} Unable to pull Web master branch"; exit 1; }
|
||||
fi
|
||||
echo -e " ${TICK} Web interface"
|
||||
|
||||
#echo -e " ${TICK} Web Interface"
|
||||
get_binary_name
|
||||
local path
|
||||
path="master/${binary}"
|
||||
FTLinstall "${binary}" "${path}"
|
||||
elif [[ "${1}" == "core" ]] ; then
|
||||
str="Fetching branches from ${piholeGitUrl}"
|
||||
echo -ne " ${INFO} $str"
|
||||
if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then
|
||||
echo -e " ${CROSS} $str"
|
||||
echo -e "${OVER} ${CROSS} $str"
|
||||
exit 1
|
||||
fi
|
||||
corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}"))
|
||||
|
||||
if [[ "${corebranches[@]}" == *"master"* ]]; then
|
||||
if [[ "${corebranches[*]}" == *"master"* ]]; then
|
||||
echo -e "${OVER} ${TICK} $str
|
||||
${INFO} ${#corebranches[@]} branches available for Pi-hole Core"
|
||||
else
|
||||
# Print STDERR output from get_available_branches
|
||||
echo -e "${OVER} ${CROSS} $str\n\n${corebranches[*]}"
|
||||
echo -e "${OVER} ${CROSS} $str\\n\\n${corebranches[*]}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -192,17 +302,17 @@ checkout() {
|
||||
str="Fetching branches from ${webInterfaceGitUrl}"
|
||||
echo -ne " ${INFO} $str"
|
||||
if ! fully_fetch_repo "${webInterfaceDir}" ; then
|
||||
echo -e " ${CROSS} $str"
|
||||
echo -e "${OVER} ${CROSS} $str"
|
||||
exit 1
|
||||
fi
|
||||
webbranches=($(get_available_branches "${webInterfaceDir}"))
|
||||
|
||||
if [[ "${corebranches[@]}" == *"master"* ]]; then
|
||||
|
||||
if [[ "${webbranches[*]}" == *"master"* ]]; then
|
||||
echo -e "${OVER} ${TICK} $str
|
||||
${INFO} ${#webbranches[@]} branches available for Web Admin"
|
||||
else
|
||||
# Print STDERR output from get_available_branches
|
||||
echo -e "${OVER} ${CROSS} $str\n\n${corebranches[*]}"
|
||||
echo -e "${OVER} ${CROSS} $str\\n\\n${webbranches[*]}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -215,13 +325,29 @@ checkout() {
|
||||
exit 1
|
||||
fi
|
||||
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
|
||||
echo -e " ${INFO} Requested option \"${1}\" is not available"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Force updating everything
|
||||
if [[ ! "${1}" == "web" && "${update}" == "true" ]]; then
|
||||
if [[ ( ! "${1}" == "web" && ! "${1}" == "ftl" ) && "${update}" == "true" ]]; then
|
||||
echo -e " ${INFO} Running installer to upgrade your installation"
|
||||
if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then
|
||||
exit 0
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -10,10 +10,7 @@
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
|
||||
|
||||
# Variables
|
||||
|
||||
readonly ADMIN_INTERFACE_GIT_URL="https://github.com/pi-hole/AdminLTE.git"
|
||||
readonly ADMIN_INTERFACE_DIR="/var/www/html/admin"
|
||||
readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git"
|
||||
@ -22,10 +19,9 @@ readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
||||
# shellcheck disable=SC2034
|
||||
PH_TEST=true
|
||||
|
||||
# Have to ignore the following rule as spaces in paths are not supported by ShellCheck
|
||||
#shellcheck disable=SC1090
|
||||
# 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
|
||||
@ -43,7 +39,7 @@ GitCheckUpdateAvail() {
|
||||
|
||||
# @ alone is a shortcut for HEAD. Older versions of git
|
||||
# need @{0}
|
||||
LOCAL="$("git rev-parse @{0}")"
|
||||
LOCAL="$(git rev-parse "@{0}")"
|
||||
|
||||
# The suffix @{upstream} to a branchname
|
||||
# (short form <branchname>@{u}) refers
|
||||
@ -52,17 +48,17 @@ GitCheckUpdateAvail() {
|
||||
# (configured with branch.<name>.remote and
|
||||
# branch.<name>.merge). A missing branchname
|
||||
# defaults to the current one.
|
||||
REMOTE="$("git rev-parse @{upstream}")"
|
||||
REMOTE="$(git rev-parse "@{upstream}")"
|
||||
|
||||
if [[ ${#LOCAL} == 0 ]]; then
|
||||
echo -e " ${COL_LIGHT_RED}Error: Local revision could not be obtained, ask Pi-hole support."
|
||||
echo -e " Additional debugging output:${COL_NC}"
|
||||
if [[ "${#LOCAL}" == 0 ]]; then
|
||||
echo -e "\\n ${COL_LIGHT_RED}Error: Local revision could not be obtained, please contact Pi-hole Support
|
||||
Additional debugging output:${COL_NC}"
|
||||
git status
|
||||
exit
|
||||
fi
|
||||
if [[ ${#REMOTE} == 0 ]]; then
|
||||
echo -e " ${COL_LIGHT_RED}Error: Remote revision could not be obtained, ask Pi-hole support."
|
||||
echo -e " Additional debugging output:${COL_NC}"
|
||||
if [[ "${#REMOTE}" == 0 ]]; then
|
||||
echo -e "\\n ${COL_LIGHT_RED}Error: Remote revision could not be obtained, please contact Pi-hole Support
|
||||
Additional debugging output:${COL_NC}"
|
||||
git status
|
||||
exit
|
||||
fi
|
||||
@ -82,7 +78,6 @@ GitCheckUpdateAvail() {
|
||||
}
|
||||
|
||||
FTLcheckUpdate() {
|
||||
|
||||
local FTLversion
|
||||
FTLversion=$(/usr/bin/pihole-FTL tag)
|
||||
local FTLlatesttag
|
||||
@ -98,13 +93,15 @@ FTLcheckUpdate() {
|
||||
main() {
|
||||
local pihole_version_current
|
||||
local web_version_current
|
||||
#shellcheck disable=1090,2154
|
||||
local basicError="\\n ${COL_LIGHT_RED}Unable to complete update, please contact Pi-hole Support${COL_NC}"
|
||||
|
||||
# shellcheck disable=1090,2154
|
||||
source "${setupVars}"
|
||||
|
||||
#This is unlikely
|
||||
# This is unlikely
|
||||
if ! is_repo "${PI_HOLE_FILES_DIR}" ; then
|
||||
echo -e " ${COL_LIGHT_RED}Critical Error: Core Pi-hole repo is missing from system!"
|
||||
echo -e " Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}"
|
||||
echo -e "\\n ${COL_LIGHT_RED}Error: Core Pi-hole repo is missing from system!
|
||||
Please re-run install script from https://pi-hole.net${COL_NC}"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
@ -112,18 +109,18 @@ main() {
|
||||
|
||||
if GitCheckUpdateAvail "${PI_HOLE_FILES_DIR}" ; then
|
||||
core_update=true
|
||||
echo -e " ${INFO} Pi-hole Core:\t${COL_YELLOW}update available${COL_NC}"
|
||||
echo -e " ${INFO} Pi-hole Core:\\t${COL_YELLOW}update available${COL_NC}"
|
||||
else
|
||||
core_update=false
|
||||
echo -e " ${INFO} Pi-hole Core:\t${COL_LIGHT_GREEN}up to date${COL_NC}"
|
||||
echo -e " ${INFO} Pi-hole Core:\\t${COL_LIGHT_GREEN}up to date${COL_NC}"
|
||||
fi
|
||||
|
||||
if FTLcheckUpdate ; then
|
||||
FTL_update=true
|
||||
echo -e " ${INFO} FTL:\t\t${COL_YELLOW}update available${COL_NC}"
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_YELLOW}update available${COL_NC}"
|
||||
else
|
||||
FTL_update=false
|
||||
echo -e " ${INFO} FTL:\t\t${COL_LIGHT_GREEN}up to date${COL_NC}"
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_LIGHT_GREEN}up to date${COL_NC}"
|
||||
fi
|
||||
|
||||
# Logic: Don't update FTL when there is a core update available
|
||||
@ -131,24 +128,24 @@ main() {
|
||||
# re-install (i.e. update) FTL
|
||||
if ${FTL_update} && ! ${core_update}; then
|
||||
echo ""
|
||||
echo -e " ${INFO} FTL out of date"
|
||||
echo -e " ${INFO} FTL out of date"
|
||||
FTLdetect
|
||||
echo ""
|
||||
fi
|
||||
|
||||
if [[ ${INSTALL_WEB} == true ]]; then
|
||||
if [[ "${INSTALL_WEB}" == true ]]; then
|
||||
if ! is_repo "${ADMIN_INTERFACE_DIR}" ; then
|
||||
echo -e " ${COL_LIGHT_RED}Critical Error: Web Admin repo is missing from system!"
|
||||
echo -e " Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}"
|
||||
echo -e "\\n ${COL_LIGHT_RED}Error: Web Admin repo is missing from system!
|
||||
Please re-run install script from https://pi-hole.net${COL_NC}"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if GitCheckUpdateAvail "${ADMIN_INTERFACE_DIR}" ; then
|
||||
web_update=true
|
||||
echo -e " ${INFO} Web Interface:\t${COL_YELLOW}update available${COL_NC}"
|
||||
echo -e " ${INFO} Web Interface:\\t${COL_YELLOW}update available${COL_NC}"
|
||||
else
|
||||
web_update=false
|
||||
echo -e " ${INFO} Web Interface:\t${COL_LIGHT_GREEN}up to date${COL_NC}"
|
||||
echo -e " ${INFO} Web Interface:\\t${COL_LIGHT_GREEN}up to date${COL_NC}"
|
||||
fi
|
||||
|
||||
# Logic
|
||||
@ -167,25 +164,24 @@ main() {
|
||||
echo -e " ${TICK} Everything is up to date!"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
elif ! ${core_update} && ${web_update} ; then
|
||||
echo ""
|
||||
echo -e " ${INFO} Pi-hole Web Admin files out of date"
|
||||
getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}"
|
||||
|
||||
elif ${core_update} && ! ${web_update} ; then
|
||||
echo ""
|
||||
echo -e " ${INFO} Pi-hole core files out of date"
|
||||
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
|
||||
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || echo -e " ${COL_LIGHT_RED}Unable to complete update, contact Pi-hole${COL_NC}" && exit 1
|
||||
|
||||
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || \
|
||||
echo -e "${basicError}" && exit 1
|
||||
elif ${core_update} && ${web_update} ; then
|
||||
echo ""
|
||||
echo -e " ${INFO} Updating Pi-hole core and web admin files"
|
||||
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
|
||||
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended || echo -e " ${COL_LIGHT_RED}Unable to complete update, contact Pi-hole${COL_NC}" && exit 1
|
||||
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended || \
|
||||
echo -e "${basicError}" && exit 1
|
||||
else
|
||||
echo -e " ${COL_LIGHT_RED}Update script has malfunctioned, fallthrough reached. Please contact support${COL_NC}"
|
||||
echo -e " ${COL_LIGHT_RED}Update script has malfunctioned, please contact Pi-hole Support${COL_NC}"
|
||||
exit 1
|
||||
fi
|
||||
else # Web Admin not installed, so only verify if core is up to date
|
||||
@ -197,38 +193,36 @@ main() {
|
||||
fi
|
||||
else
|
||||
echo ""
|
||||
echo -e " ${INFO} 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}"
|
||||
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || echo -e " ${COL_LIGHT_RED}Unable to complete update, contact Pi-hole${COL_NC}" && exit 1
|
||||
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || \
|
||||
echo -e "${basicError}" && exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${web_update}" == true ]]; then
|
||||
web_version_current="$(/usr/local/bin/pihole version --admin --current)"
|
||||
echo ""
|
||||
echo -e " ${INFO} Web Admin version is now at ${web_version_current/* v/v}"
|
||||
echo -e " ${INFO} If you had made any changes in '/var/www/html/admin/', they have been stashed using 'git stash'"
|
||||
echo -e " ${INFO} Web Admin version is now at ${web_version_current/* v/v}
|
||||
${INFO} If you had made any changes in '/var/www/html/admin/', they have been stashed using 'git stash'"
|
||||
fi
|
||||
|
||||
if [[ "${core_update}" == true ]]; then
|
||||
pihole_version_current="$(/usr/local/bin/pihole version --pihole --current)"
|
||||
echo ""
|
||||
echo -e " ${INFO} Pi-hole version is now at ${pihole_version_current/* v/v}"
|
||||
echo -e " ${INFO} If you had made any changes in '/etc/.pihole/', they have been stashed using 'git stash'"
|
||||
echo -e " ${INFO} Pi-hole version is now at ${pihole_version_current/* v/v}
|
||||
${INFO} If you had made any changes in '/etc/.pihole/', they have been stashed using 'git stash'"
|
||||
fi
|
||||
|
||||
if [[ ${FTL_update} == true ]]; then
|
||||
if [[ "${FTL_update}" == true ]]; then
|
||||
FTL_version_current="$(/usr/bin/pihole-FTL tag)"
|
||||
echo ""
|
||||
echo -e " ${INFO} FTL version is now at ${FTL_version_current/* v/v}"
|
||||
echo -e "\\n ${INFO} FTL version is now at ${FTL_version_current/* v/v}"
|
||||
start_service pihole-FTL
|
||||
enable_service pihole-FTL
|
||||
fi
|
||||
|
||||
|
||||
echo ""
|
||||
exit 0
|
||||
|
||||
}
|
||||
|
||||
main
|
||||
|
@ -29,6 +29,7 @@ Options:
|
||||
-c, celsius Set Celsius as preferred temperature unit
|
||||
-f, fahrenheit Set Fahrenheit as preferred temperature unit
|
||||
-k, kelvin Set Kelvin as preferred temperature unit
|
||||
-r, hostrecord Add a name to the DNS associated to an IPv4/IPv6 address
|
||||
-h, --help Show this help dialog
|
||||
-i, interface Specify dnsmasq's interface listening behavior
|
||||
Add '-h' for more info on interface usage"
|
||||
@ -89,6 +90,9 @@ SetWebPassword() {
|
||||
readonly PASSWORD="${args[2]}"
|
||||
readonly CONFIRM="${PASSWORD}"
|
||||
else
|
||||
# Prevents a bug if the user presses Ctrl+C and it continues to hide the text typed.
|
||||
# So we reset the terminal via stty if the user does press Ctrl+C
|
||||
trap '{ echo -e "\nNo password will be set" ; stty sane ; exit 1; }' INT
|
||||
read -s -p "Enter New Password (Blank for no password): " PASSWORD
|
||||
echo ""
|
||||
|
||||
@ -222,18 +226,19 @@ Reboot() {
|
||||
}
|
||||
|
||||
RestartDNS() {
|
||||
local str="Restarting dnsmasq"
|
||||
echo -ne " ${INFO} ${str}..."
|
||||
if [[ -x "$(command -v systemctl)" ]]; then
|
||||
systemctl restart dnsmasq
|
||||
local str="Restarting DNS service"
|
||||
[[ -t 1 ]] && echo -ne " ${INFO} ${str}"
|
||||
if command -v systemctl &> /dev/null; then
|
||||
output=$( { systemctl restart dnsmasq; } 2>&1 )
|
||||
else
|
||||
service dnsmasq restart
|
||||
output=$( { service dnsmasq restart; } 2>&1 )
|
||||
fi
|
||||
|
||||
if [[ "$?" == 0 ]]; then
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
else
|
||||
echo -e "${OVER} ${CROSS} ${str}"
|
||||
[[ ! -t 1 ]] && OVER=""
|
||||
echo -e "${OVER} ${CROSS} ${output}"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -260,7 +265,12 @@ ProcessDHCPSettings() {
|
||||
if [[ "${DHCP_LEASETIME}" == "0" ]]; then
|
||||
leasetime="infinite"
|
||||
elif [[ "${DHCP_LEASETIME}" == "" ]]; then
|
||||
leasetime="24h"
|
||||
leasetime="24"
|
||||
change_setting "DHCP_LEASETIME" "${leasetime}"
|
||||
elif [[ "${DHCP_LEASETIME}" == "24h" ]]; then
|
||||
#Installation is affected by known bug, introduced in a previous version.
|
||||
#This will automatically clean up setupVars.conf and remove the unnecessary "h"
|
||||
leasetime="24"
|
||||
change_setting "DHCP_LEASETIME" "${leasetime}"
|
||||
else
|
||||
leasetime="${DHCP_LEASETIME}h"
|
||||
@ -292,7 +302,9 @@ ra-param=*,0,0
|
||||
fi
|
||||
|
||||
else
|
||||
rm "${dhcpconfig}" &> /dev/null
|
||||
if [[ -f "${dhcpconfig}" ]]; then
|
||||
rm "${dhcpconfig}" &> /dev/null
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@ -390,12 +402,23 @@ RemoveDHCPStaticAddress() {
|
||||
}
|
||||
|
||||
SetHostRecord() {
|
||||
if [ -n "${args[3]}" ]; then
|
||||
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
|
||||
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
|
||||
change_setting "HOSTRECORD" ""
|
||||
echo "Removing host record"
|
||||
echo -e " ${TICK} Removing host record"
|
||||
fi
|
||||
|
||||
ProcessDNSSettings
|
||||
@ -473,7 +496,7 @@ main() {
|
||||
"resolve" ) ResolutionSettings;;
|
||||
"addstaticdhcp" ) AddDHCPStaticAddress;;
|
||||
"removestaticdhcp" ) RemoveDHCPStaticAddress;;
|
||||
"hostrecord" ) SetHostRecord;;
|
||||
"-r" | "hostrecord" ) SetHostRecord "$3";;
|
||||
"-i" | "interface" ) SetListeningMode "$@";;
|
||||
"-t" | "teleporter" ) Teleporter;;
|
||||
"adlist" ) CustomizeAdLists;;
|
||||
|
@ -21,8 +21,9 @@ if ($serverName === 'pi.hole')
|
||||
}
|
||||
|
||||
// Retrieve server URI extension (EG: jpg, exe, php)
|
||||
// strtok($uri, '\?') splits the querystring from the path (if there is a querystring)
|
||||
ini_set('pcre.recursion_limit',100);
|
||||
$uriExt = pathinfo($uri, PATHINFO_EXTENSION);
|
||||
$uriExt = pathinfo(strtok($uri,'\?'), PATHINFO_EXTENSION);
|
||||
|
||||
// Define which URL extensions get rendered as "Website Blocked"
|
||||
$webExt = array('asp', 'htm', 'html', 'php', 'rss', 'xml');
|
||||
|
File diff suppressed because it is too large
Load Diff
358
pihole
358
pihole
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||
# Network-wide ad blocking via your own hardware.
|
||||
@ -8,11 +9,11 @@
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
colfile="/opt/pihole/COL_TABLE"
|
||||
source ${colfile}
|
||||
|
||||
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
||||
readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
||||
|
||||
source ${colfile}
|
||||
|
||||
# Must be root to use this tool
|
||||
if [[ ! $EUID -eq 0 ]];then
|
||||
@ -87,10 +88,14 @@ scanList(){
|
||||
domain="${1}"
|
||||
list="${2}"
|
||||
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
|
||||
grep -i "${domain}" "${list}"
|
||||
grep -i "${domain}" ${list} /dev/null 2> /dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
@ -110,46 +115,217 @@ processWildcards() {
|
||||
}
|
||||
|
||||
queryFunc() {
|
||||
domain="${2}"
|
||||
|
||||
if [[ -z "${domain}" ]]; then
|
||||
echo -e " ${COL_LIGHT_RED}Invalid option${COL_NC}
|
||||
Try 'pihole query --help' for more information."
|
||||
options="$*"
|
||||
options="${options/-q /}"
|
||||
|
||||
if [[ "${options}" == "-h" ]] || [[ "${options}" == "--help" ]]; then
|
||||
echo "Usage: pihole -q [option] <domain>
|
||||
Example: 'pihole -q -exact domain.com'
|
||||
Query the adlists for a specified domain
|
||||
|
||||
Options:
|
||||
-adlist Print the name of the block list URL
|
||||
-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
|
||||
|
||||
method="${3}"
|
||||
lists=( /etc/pihole/list.* /etc/pihole/blacklist.txt)
|
||||
for list in ${lists[@]}; do
|
||||
if [ -e "${list}" ]; then
|
||||
result=$(scanList ${domain} ${list} ${method})
|
||||
# Remove empty lines before couting number of results
|
||||
count=$(sed '/^\s*$/d' <<< "$result" | wc -l)
|
||||
echo "${list} (${count} results)"
|
||||
if [[ ${count} > 0 ]]; then
|
||||
echo "${result}"
|
||||
fi
|
||||
echo ""
|
||||
else
|
||||
echo -e " ${CROSS} List does not exist"
|
||||
echo ""
|
||||
fi
|
||||
done
|
||||
|
||||
# Scan for possible wildcard matches
|
||||
if [ -e "${wildcardlist}" ]; then
|
||||
local wildcards=($(processWildcards "${domain}"))
|
||||
for domain in ${wildcards[@]}; do
|
||||
result=$(scanList "\/${domain}\/" ${wildcardlist})
|
||||
# Remove empty lines before couting number of results
|
||||
count=$(sed '/^\s*$/d' <<< "$result" | wc -l)
|
||||
if [[ ${count} > 0 ]]; then
|
||||
echo -e " ${TICK} Wildcard blocking ${domain} (${count} results)"
|
||||
echo "${result}"
|
||||
echo ""
|
||||
# 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
|
||||
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
|
||||
echo -e " ${COL_LIGHT_RED}The file '/etc/pihole/adlists.list' was not found${COL_NC}"
|
||||
exit 1
|
||||
fi
|
||||
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
|
||||
|
||||
if [[ -n "${exact}" ]]; then
|
||||
printf " %s\n" "${filename}"
|
||||
elif [[ -n "${blockpage}" ]]; then
|
||||
printf "%s %s\n" "${filenum}" "${filename}"
|
||||
else # Standard query output
|
||||
|
||||
# Print filename heading once per file, not for every match
|
||||
if [[ ! "${filename}" == "${filename_prev:-}" ]]; then
|
||||
unset count
|
||||
printf " Result from %s\n" "${filename}"
|
||||
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
|
||||
done
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
@ -173,24 +349,32 @@ versionFunc() {
|
||||
|
||||
restartDNS() {
|
||||
dnsmasqPid=$(pidof dnsmasq)
|
||||
local str="Restarting DNS service"
|
||||
echo -ne " ${INFO} ${str}"
|
||||
if [[ "${dnsmasqPid}" ]]; then
|
||||
# Service already running - reload config
|
||||
echo -ne " ${INFO} Restarting dnsmasq"
|
||||
if [[ -x "$(command -v systemctl)" ]]; then
|
||||
systemctl restart dnsmasq
|
||||
output=$( { systemctl restart dnsmasq; } 2>&1 )
|
||||
else
|
||||
service dnsmasq restart
|
||||
output=$( { service dnsmasq restart; } 2>&1 )
|
||||
fi
|
||||
if [[ -z "${output}" ]]; then
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
else
|
||||
echo -e "${OVER} ${CROSS} ${output}"
|
||||
fi
|
||||
[[ "$?" == 0 ]] && echo -e "${OVER} ${TICK} Restarted dnsmasq" || echo -e "${OVER} ${CROSS} Failed to restart dnsmasq"
|
||||
else
|
||||
# Service not running, start it up
|
||||
echo -ne " ${INFO} Starting dnsmasq"
|
||||
if [[ -x "$(command -v systemctl)" ]]; then
|
||||
systemctl start dnsmasq
|
||||
output=$( { systemctl start dnsmasq; } 2>&1 )
|
||||
else
|
||||
service dnsmasq start
|
||||
output=$( { service dnsmasq start; } 2>&1 )
|
||||
fi
|
||||
if [[ -z "${output}" ]]; then
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
else
|
||||
echo -e "${OVER} ${CROSS} ${output}"
|
||||
fi
|
||||
[[ "$?" == 0 ]] && echo -e "${OVER} ${TICK} Restarted dnsmasq" || echo -e "${OVER} ${CROSS} Failed to restart dnsmasq"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -253,15 +437,15 @@ Time:
|
||||
# Enable Pi-hole
|
||||
echo -e " ${INFO} Enabling blocking"
|
||||
local str="Pi-hole Enabled"
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
restartDNS
|
||||
|
||||
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
}
|
||||
|
||||
@ -298,41 +482,43 @@ Options:
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
}
|
||||
|
||||
piholeStatus() {
|
||||
if [[ "$(netstat -plnt | grep -c ':53 ')" -gt "0" ]]; then
|
||||
statusFunc() {
|
||||
local addnConfigs
|
||||
|
||||
# Determine if service is running on port 53 (Cr: https://superuser.com/a/806331)
|
||||
if (echo > /dev/tcp/localhost/53) >/dev/null 2>&1; then
|
||||
if [[ "${1}" != "web" ]]; then
|
||||
echo -e " ${TICK} DNS service is running"
|
||||
fi
|
||||
else
|
||||
if [[ "${1}" == "web" ]]; then
|
||||
echo "-1";
|
||||
else
|
||||
echo -e " ${CROSS} DNS service is NOT running"
|
||||
fi
|
||||
return
|
||||
case "${1}" in
|
||||
"web") echo "-1";;
|
||||
*) echo -e " ${CROSS} DNS service is NOT running";;
|
||||
esac
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "$(grep -i "^#addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)" ]]; then
|
||||
# List is commented out
|
||||
if [[ "${1}" == "web" ]]; then
|
||||
echo 0;
|
||||
else
|
||||
echo -e " ${CROSS} Pi-hole blocking is Disabled";
|
||||
fi
|
||||
elif [[ "$(grep -i "^addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)" ]]; then
|
||||
# List set
|
||||
if [[ "${1}" == "web" ]]; then
|
||||
echo 1;
|
||||
else
|
||||
echo -e " ${TICK} Pi-hole blocking is Enabled";
|
||||
fi
|
||||
# Determine if Pi-hole's addn-hosts configs are commented out
|
||||
addnConfigs=$(grep -i "addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)
|
||||
|
||||
if [[ "${addnConfigs}" =~ "#" ]]; then
|
||||
# A config is commented out
|
||||
case "${1}" in
|
||||
"web") echo 0;;
|
||||
*) echo -e " ${CROSS} Pi-hole blocking is Disabled";;
|
||||
esac
|
||||
elif [[ -n "${addnConfigs}" ]]; then
|
||||
# Configs are set
|
||||
case "${1}" in
|
||||
"web") echo 1;;
|
||||
*) echo -e " ${TICK} Pi-hole blocking is Enabled";;
|
||||
esac
|
||||
else
|
||||
# Addn-host not found
|
||||
if [[ "${1}" == "web" ]]; then
|
||||
echo 99
|
||||
else
|
||||
echo -e " ${INFO} No hosts file linked to dnsmasq, adding it in enabled state"
|
||||
fi
|
||||
# No configs were found
|
||||
case "${1}" in
|
||||
"web") echo 99;;
|
||||
*) echo -e " ${INFO} No hosts file linked to dnsmasq, adding it in enabled state";;
|
||||
esac
|
||||
# Add addn-host= to dnsmasq
|
||||
echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf
|
||||
restartDNS
|
||||
@ -340,8 +526,13 @@ piholeStatus() {
|
||||
}
|
||||
|
||||
tailFunc() {
|
||||
date=$(date +'%b %d ')
|
||||
echo -e " ${INFO} Press Ctrl-C to exit"
|
||||
tail -F /var/log/pihole.log
|
||||
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
|
||||
}
|
||||
|
||||
@ -354,6 +545,7 @@ 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
|
||||
@ -372,7 +564,7 @@ tricorderFunc() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! timeout 2 nc -z tricorder.pi-hole.net 9998 &> /dev/null; then
|
||||
if ! (echo > /dev/tcp/tricorder.pi-hole.net/9998) >/dev/null 2>&1; then
|
||||
echo -e " ${CROSS} Unable to connect to Pi-hole's Tricorder server"
|
||||
exit 1
|
||||
fi
|
||||
@ -425,7 +617,7 @@ Options:
|
||||
-l, logging Specify whether the Pi-hole log should be used
|
||||
Add '-h' for more info on logging usage
|
||||
-q, query Query the adlists for a specified domain
|
||||
Add '-exact' AFTER a specified domain for exact match
|
||||
Add '-h' for more info on query usage
|
||||
-up, updatePihole Update Pi-hole subsystems
|
||||
-v, version Show installed versions of Pi-hole, Admin Console & FTL
|
||||
Add '-h' for more info on version usage
|
||||
@ -462,7 +654,7 @@ case "${1}" in
|
||||
"uninstall" ) uninstallFunc;;
|
||||
"enable" ) piholeEnable 1;;
|
||||
"disable" ) piholeEnable 0 "$2";;
|
||||
"status" ) piholeStatus "$2";;
|
||||
"status" ) statusFunc "$2";;
|
||||
"restartdns" ) restartDNS;;
|
||||
"-a" | "admin" ) webpageFunc "$@";;
|
||||
"-t" | "tail" ) tailFunc;;
|
||||
|
@ -59,6 +59,8 @@ def test_setupVars_saved_to_file(Pihole):
|
||||
TERM=xterm
|
||||
source /opt/pihole/basic-install.sh
|
||||
{}
|
||||
mkdir -p /etc/dnsmasq.d
|
||||
version_check_dnsmasq
|
||||
finalExports
|
||||
cat /etc/pihole/setupVars.conf
|
||||
'''.format(set_setup_vars))
|
||||
@ -78,7 +80,7 @@ def test_configureFirewall_firewalld_running_no_errors(Pihole):
|
||||
source /opt/pihole/basic-install.sh
|
||||
configureFirewall
|
||||
''')
|
||||
expected_stdout = 'Configuring FirewallD for httpd and dnsmasq.'
|
||||
expected_stdout = 'Configuring FirewallD for httpd and dnsmasq'
|
||||
assert expected_stdout in configureFirewall.stdout
|
||||
firewall_calls = Pihole.run('cat /var/log/firewall-cmd').stdout
|
||||
assert 'firewall-cmd --state' in firewall_calls
|
||||
@ -93,7 +95,7 @@ def test_configureFirewall_firewalld_disabled_no_errors(Pihole):
|
||||
source /opt/pihole/basic-install.sh
|
||||
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
|
||||
|
||||
def test_configureFirewall_firewalld_enabled_declined_no_errors(Pihole):
|
||||
@ -319,11 +321,11 @@ def test_FTL_detect_aarch64_no_errors(Pihole):
|
||||
source /opt/pihole/basic-install.sh
|
||||
FTLdetect
|
||||
''')
|
||||
expected_stdout = info_box + ' Downloading latest version of FTL...'
|
||||
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 + ' Installing FTL'
|
||||
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
||||
assert expected_stdout in detectPlatform.stdout
|
||||
|
||||
def test_FTL_detect_armv6l_no_errors(Pihole):
|
||||
@ -336,11 +338,11 @@ def test_FTL_detect_armv6l_no_errors(Pihole):
|
||||
source /opt/pihole/basic-install.sh
|
||||
FTLdetect
|
||||
''')
|
||||
expected_stdout = info_box + ' Downloading latest version of FTL...'
|
||||
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 + ' Installing FTL'
|
||||
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
||||
assert expected_stdout in detectPlatform.stdout
|
||||
|
||||
def test_FTL_detect_armv7l_no_errors(Pihole):
|
||||
@ -353,11 +355,11 @@ def test_FTL_detect_armv7l_no_errors(Pihole):
|
||||
source /opt/pihole/basic-install.sh
|
||||
FTLdetect
|
||||
''')
|
||||
expected_stdout = info_box + ' Downloading latest version of FTL...'
|
||||
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 + ' Installing FTL'
|
||||
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
||||
assert expected_stdout in detectPlatform.stdout
|
||||
|
||||
def test_FTL_detect_x86_64_no_errors(Pihole):
|
||||
@ -366,11 +368,11 @@ def test_FTL_detect_x86_64_no_errors(Pihole):
|
||||
source /opt/pihole/basic-install.sh
|
||||
FTLdetect
|
||||
''')
|
||||
expected_stdout = info_box + ' Downloading latest version of FTL...'
|
||||
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 + ' Installing FTL'
|
||||
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
||||
assert expected_stdout in detectPlatform.stdout
|
||||
|
||||
def test_FTL_detect_unknown_no_errors(Pihole):
|
||||
@ -391,7 +393,7 @@ def test_FTL_download_aarch64_no_errors(Pihole):
|
||||
source /opt/pihole/basic-install.sh
|
||||
FTLinstall pihole-FTL-aarch64-linux-gnu
|
||||
''')
|
||||
expected_stdout = tick_box + ' Installing FTL'
|
||||
expected_stdout = tick_box + ' Downloading and Installing FTL'
|
||||
assert expected_stdout in download_binary.stdout
|
||||
error = 'Error: Download of binary from Github failed'
|
||||
assert error not in download_binary.stdout
|
||||
@ -405,7 +407,7 @@ def test_FTL_download_unknown_fails_no_errors(Pihole):
|
||||
source /opt/pihole/basic-install.sh
|
||||
FTLinstall pihole-FTL-mips
|
||||
''')
|
||||
expected_stdout = cross_box + ' Installing FTL'
|
||||
expected_stdout = cross_box + ' Downloading and Installing FTL'
|
||||
assert expected_stdout in download_binary.stdout
|
||||
error = 'Error: URL not found'
|
||||
assert error in download_binary.stdout
|
||||
@ -442,7 +444,7 @@ def test_IPv6_only_link_local(Pihole):
|
||||
source /opt/pihole/basic-install.sh
|
||||
useIPv6dialog
|
||||
''')
|
||||
expected_stdout = 'Found neither IPv6 ULA nor GUA address, blocking IPv6 ads will not be enabled'
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user