mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 10:43:55 +00:00
Merge branch 'development' into tweak/checkout_FTL
Signed-off-by: Adam Warner <adamw@rner.email> # Conflicts: # advanced/Scripts/piholeCheckout.sh
This commit is contained in:
commit
783f50657b
9 changed files with 2482 additions and 930 deletions
312
README.md
312
README.md
|
@ -8,37 +8,37 @@
|
||||||
<a href=https://discourse.pi-hole.net><img src="https://assets.pi-hole.net/static/Vortex_with_text_and_TM.png" width=210></a>
|
<a href=https://discourse.pi-hole.net><img src="https://assets.pi-hole.net/static/Vortex_with_text_and_TM.png" width=210></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## The multi-platform, network-wide ad blocker
|
## Pi-hole®: The multi-platform, network-wide ad blocker
|
||||||
|
|
||||||
Block ads for **all** your devices _without_ the need to install client-side software. The Pi-hole™ blocks ads at the DNS-level, so all your devices are protected.
|
Block ads for **all** your devices _without_ the need to install client-side software.
|
||||||
|
|
||||||
- Web Browsers
|
|
||||||
- Cell Phones
|
|
||||||
- Smart TV's
|
|
||||||
- Internet-connected home automation
|
|
||||||
- Anything that communicates with the Internet
|
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href=http://www.digitalocean.com/?refcode=344d234950e1><img src="https://assets.pi-hole.net/static/DOHostingSlug.png"></a>
|
<a href=http://www.digitalocean.com/?refcode=344d234950e1><img src="https://assets.pi-hole.net/static/DOHostingSlug.png"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Your Support Still Matters
|
## Executive Summary
|
||||||
|
The Pi-hole blocks ads at the DNS-level, so all your devices are protected.
|
||||||
|
|
||||||
Digital Ocean helps with our infrastructure, but our developers are all volunteers so *your donations help keep us innovating*. Sending a donation using our links below helps us offset a portion of our monthly costs.
|
- **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
|
||||||
|
|
||||||
- ![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)
|
# One-Step Automated Install
|
||||||
- ![Bitcoin](https://assets.pi-hole.net/static/Bitcoin.png) Bitcoin Address: 1GKnevUnVaQM2pQieMyeHkpr8DXfkpfAtL
|
|
||||||
|
|
||||||
### One-Step Automated Install
|
|
||||||
1. Install a [supported operating system](https://discourse.pi-hole.net/t/hardware-software-requirements/273/1)
|
1. Install a [supported operating system](https://discourse.pi-hole.net/t/hardware-software-requirements/273/1)
|
||||||
2. Run the command below (it downloads [this script](https://github.com/pi-hole/pi-hole/blob/master/automated%20install/basic-install.sh) in case you want to read over it first!)
|
2. Run the command below (it downloads [this script](https://github.com/pi-hole/pi-hole/blob/master/automated%20install/basic-install.sh) in case you want to read over it first!)
|
||||||
|
|
||||||
### `curl -sSL https://install.pi-hole.net | bash`
|
#### `curl -sSL https://install.pi-hole.net | bash`
|
||||||
|
|
||||||
#### Alternative Semi-Automated Install Methods
|
## Alternative Semi-Automated Install Methods
|
||||||
_If you wish to read over the script before running it, run `nano basic-install.sh` to open the file in a text viewer._
|
_If you wish to read over the script before running it, run `nano basic-install.sh` to open the file in a text viewer._
|
||||||
|
|
||||||
##### Clone our repository and run the automated installer from your device.
|
### Clone our repository and run the automated installer from your device.
|
||||||
|
|
||||||
```
|
```
|
||||||
git clone --depth 1 https://github.com/pi-hole/pi-hole.git Pi-hole
|
git clone --depth 1 https://github.com/pi-hole/pi-hole.git Pi-hole
|
||||||
|
@ -53,91 +53,233 @@ wget -O basic-install.sh https://install.pi-hole.net
|
||||||
bash basic-install.sh
|
bash basic-install.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245) and then any device that connects to your network will have ads blocked without any further configuration. Alternatively, you can manually set each device to use Pi-hole™ as their DNS server.
|
Once installed, [configure your router to have **DHCP clients use the Pi-hole as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245) and then any device that connects to your network will have ads blocked without any further configuration.
|
||||||
|
|
||||||
## 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">
|
<p align="center">
|
||||||
<a href=https://www.youtube.com/watch?v=vKWjx1AQYgs><img src="https://assets.pi-hole.net/static/video-explainer.png"></a>
|
<a href=https://www.youtube.com/watch?v=vKWjx1AQYgs><img src="https://assets.pi-hole.net/static/video-explainer.png"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
# Pi-hole Is Free, But Powered By Your Donations
|
||||||
|
|
||||||
## Get Help Or Connect With Us On The Web
|
[Digital Ocean](http://www.digitalocean.com/?refcode=344d234950e1) helps with our infrastructure, but [our developers](https://github.com/orgs/pi-hole/people) are all volunteers so *your donations help keep us innovating*.
|
||||||
|
|
||||||
|
- ![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/)
|
- [Users Forum](https://discourse.pi-hole.net/)
|
||||||
- [FAQs](https://discourse.pi-hole.net/c/faqs)
|
- [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)
|
- [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)
|
- ![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/)
|
- ![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)
|
- ![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)
|
- [![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.
|
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.
|
||||||
|
|
||||||
### 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`.
|
|
||||||
|
|
||||||
|
|
||||||
|
# Pi-hole Projects
|
||||||
#### 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
|
|
||||||
|
|
||||||
- [An ad blocking Magic Mirror](https://zonksec.com/blog/magic-mirror-dns-filtering/#dnssoftware)
|
- [An ad blocking Magic Mirror](https://zonksec.com/blog/magic-mirror-dns-filtering/#dnssoftware)
|
||||||
- [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py)
|
- [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py)
|
||||||
|
@ -158,7 +300,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)
|
- [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)
|
- [Windows DNS Swapper](https://github.com/roots84/DNS-Swapper), see [#1400](https://github.com/pi-hole/pi-hole/issues/1400)
|
||||||
|
|
||||||
## Coverage
|
# Coverage
|
||||||
|
|
||||||
- [Adafruit livestream install](https://www.youtube.com/watch?v=eg4u2j1HYlI)
|
- [Adafruit livestream install](https://www.youtube.com/watch?v=eg4u2j1HYlI)
|
||||||
- [TekThing: 5 fun, easy projects for a Raspberry Pi](https://youtu.be/QwrKlyC2kdM?t=1m42s)
|
- [TekThing: 5 fun, easy projects for a Raspberry Pi](https://youtu.be/QwrKlyC2kdM?t=1m42s)
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#
|
#
|
||||||
# This file is copyright under the latest version of the EUPL.
|
# This file is copyright under the latest version of the EUPL.
|
||||||
# Please see LICENSE file for your rights under this license.
|
# Please see LICENSE file for your rights under this license.
|
||||||
|
LC_NUMERIC=C
|
||||||
|
|
||||||
# Retrieve stats from FTL engine
|
# Retrieve stats from FTL engine
|
||||||
pihole-FTL() {
|
pihole-FTL() {
|
||||||
|
@ -32,43 +33,74 @@ pihole-FTL() {
|
||||||
exec 3<&-
|
exec 3<&-
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo -e "${COL_LIGHT_RED}FTL offline${COL_NC}"
|
echo "0"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Print spaces to align right-side content
|
# Print spaces to align right-side additional text
|
||||||
printFunc() {
|
printFunc() {
|
||||||
txt_len="${#2}"
|
local text_last
|
||||||
|
|
||||||
# Reduce string length when using colour code
|
title="$1"
|
||||||
[ "${2:0:1}" == "" ] && txt_len=$((txt_len-7))
|
title_len="${#title}"
|
||||||
|
|
||||||
if [[ "$3" == "last" ]]; then
|
text_main="$2"
|
||||||
# Prevent final line from printing trailing newline
|
text_main_nocol="$text_main"
|
||||||
scr_size=( $(stty size 2>/dev/null || echo 24 80) )
|
if [[ "${text_main:0:1}" == "" ]]; then
|
||||||
scr_width="${scr_size[1]}"
|
text_main_nocol=$(sed 's/\[[0-9;]\{1,5\}m//g' <<< "$text_main")
|
||||||
|
fi
|
||||||
|
text_main_len="${#text_main_nocol}"
|
||||||
|
|
||||||
title_len="${#1}"
|
text_addn="$3"
|
||||||
spc_num=$(( (scr_width - title_len) - txt_len ))
|
if [[ "$text_addn" == "last" ]]; then
|
||||||
[[ "$spc_num" -lt 0 ]] && spc_num="0"
|
text_addn=""
|
||||||
spc=$(printf "%${spc_num}s")
|
text_last="true"
|
||||||
|
fi
|
||||||
|
|
||||||
printf "%s%s$spc" "$1" "$2"
|
# 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
|
else
|
||||||
# Determine number of spaces for padding
|
spc_num=$(( text_main_max_len - text_main_len ))
|
||||||
spc_num=$(( 20 - txt_len ))
|
fi
|
||||||
[[ "$spc_num" -lt 0 ]] && spc_num="0"
|
|
||||||
spc=$(printf "%${spc_num}s")
|
|
||||||
|
|
||||||
# Print string (Max 20 characters, prevents overflow)
|
[[ "$spc_num" -le 0 ]] && spc_num="0"
|
||||||
printf "%s%s$spc" "$1" "${2:0:20}"
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Perform on first Chrono run (not for JSON formatted string)
|
# Perform on first Chrono run (not for JSON formatted string)
|
||||||
get_init_stats() {
|
get_init_stats() {
|
||||||
LC_NUMERIC=C
|
calcFunc(){ awk "BEGIN {print $*}" 2> /dev/null; }
|
||||||
calcFunc(){ awk "BEGIN {print $*}"; }
|
|
||||||
|
|
||||||
# Convert bytes to human-readable format
|
# Convert bytes to human-readable format
|
||||||
hrBytes() {
|
hrBytes() {
|
||||||
|
@ -90,7 +122,8 @@ get_init_stats() {
|
||||||
|
|
||||||
# Convert seconds to human-readable format
|
# Convert seconds to human-readable format
|
||||||
hrSecs() {
|
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 "2" ]] && plu="s"
|
||||||
[[ "$day" -ge "1" ]] && days="$day day${plu}, " || days=""
|
[[ "$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"
|
||||||
|
@ -101,22 +134,41 @@ get_init_stats() {
|
||||||
if [[ -f "${coltable}" ]]; then
|
if [[ -f "${coltable}" ]]; then
|
||||||
source ${coltable}
|
source ${coltable}
|
||||||
else
|
else
|
||||||
COL_NC='[0m'
|
COL_NC="[0m"
|
||||||
COL_DARK_GRAY='[1;30m'
|
COL_DARK_GRAY="[1;30m"
|
||||||
COL_LIGHT_GREEN='[1;32m'
|
COL_LIGHT_GREEN="[1;32m"
|
||||||
COL_LIGHT_BLUE='[1;34m'
|
COL_LIGHT_BLUE="[1;34m"
|
||||||
COL_LIGHT_RED='[1;31m'
|
COL_LIGHT_RED="[1;31m"
|
||||||
COL_YELLOW='[1;33m'
|
COL_YELLOW="[1;33m"
|
||||||
COL_LIGHT_RED='[1;31m'
|
COL_LIGHT_RED="[1;31m"
|
||||||
COL_URG_RED='[39;41m'
|
COL_URG_RED="[39;41m"
|
||||||
fi
|
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
|
if command -v vcgencmd &> /dev/null; then
|
||||||
sys_rev=$(awk '/Revision/ {print $3}' < /proc/cpuinfo)
|
local sys_throttle_raw
|
||||||
case "$sys_rev" in
|
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[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
|
000d|000e|000f) sys_model=" 1, Model B";; # 512MB
|
||||||
0010|0013) sys_model=" 1, Model B+";; # 512MB
|
0010|0013) sys_model=" 1, Model B+";; # 512MB
|
||||||
0012|0015) sys_model=" 1, Model A+";; # 256MB
|
0012|0015) sys_model=" 1, Model A+";; # 256MB
|
||||||
|
@ -126,7 +178,7 @@ get_init_stats() {
|
||||||
90009[2-3]|920093) sys_model=" Zero";; # 512MB
|
90009[2-3]|920093) sys_model=" Zero";; # 512MB
|
||||||
9000c1) sys_model=" Zero W";; # 512MB
|
9000c1) sys_model=" Zero W";; # 512MB
|
||||||
a02082|a[2-3]2082) sys_model=" 3, Model B";; # 1GB
|
a02082|a[2-3]2082) sys_model=" 3, Model B";; # 1GB
|
||||||
*) sys_model="" ;;
|
*) sys_model="";;
|
||||||
esac
|
esac
|
||||||
sys_type="Raspberry Pi$sys_model"
|
sys_type="Raspberry Pi$sys_model"
|
||||||
else
|
else
|
||||||
|
@ -137,7 +189,6 @@ get_init_stats() {
|
||||||
|
|
||||||
# Get core count
|
# Get core count
|
||||||
sys_cores=$(grep -c "^processor" /proc/cpuinfo)
|
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
|
# Test existence of clock speed file for ARM CPU
|
||||||
if [[ -f "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]]; then
|
if [[ -f "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]]; then
|
||||||
|
@ -168,16 +219,16 @@ get_sys_stats() {
|
||||||
# Update every 12 refreshes (Def: every 60s)
|
# Update every 12 refreshes (Def: every 60s)
|
||||||
count=$((count+1))
|
count=$((count+1))
|
||||||
if [[ "$count" == "1" ]] || (( "$count" % 12 == 0 )); then
|
if [[ "$count" == "1" ]] || (( "$count" % 12 == 0 )); then
|
||||||
|
# Do not source setupVars if file does not exist
|
||||||
[[ -n "$setupVars" ]] && source "$setupVars"
|
[[ -n "$setupVars" ]] && source "$setupVars"
|
||||||
|
|
||||||
|
mapfile -t ph_ver_raw < <(pihole -v -c 2> /dev/null | sed -n 's/^.* v/v/p')
|
||||||
ph_ver_raw=($(pihole -v -c 2> /dev/null | sed -n 's/^.* v/v/p'))
|
|
||||||
if [[ -n "${ph_ver_raw[0]}" ]]; then
|
if [[ -n "${ph_ver_raw[0]}" ]]; then
|
||||||
ph_core_ver="${ph_ver_raw[0]}"
|
ph_core_ver="${ph_ver_raw[0]}"
|
||||||
ph_lte_ver="${ph_ver_raw[1]}"
|
ph_lte_ver="${ph_ver_raw[1]}"
|
||||||
ph_ftl_ver="${ph_ver_raw[2]}"
|
ph_ftl_ver="${ph_ver_raw[2]}"
|
||||||
else
|
else
|
||||||
ph_core_ver="${COL_LIGHT_RED}API unavailable${COL_NC}"
|
ph_core_ver="-1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sys_name=$(hostname)
|
sys_name=$(hostname)
|
||||||
|
@ -185,7 +236,7 @@ get_sys_stats() {
|
||||||
[[ -n "$TEMPERATUREUNIT" ]] && temp_unit="$TEMPERATUREUNIT" || temp_unit="c"
|
[[ -n "$TEMPERATUREUNIT" ]] && temp_unit="$TEMPERATUREUNIT" || temp_unit="c"
|
||||||
|
|
||||||
# Get storage stats for partition mounted on /
|
# 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_used="${disk_raw[0]}"
|
||||||
disk_total="${disk_raw[1]}"
|
disk_total="${disk_raw[1]}"
|
||||||
disk_perc="${disk_raw[2]}"
|
disk_perc="${disk_raw[2]}"
|
||||||
|
@ -194,31 +245,46 @@ get_sys_stats() {
|
||||||
|
|
||||||
# Get DHCP stats, if feature is enabled
|
# Get DHCP stats, if feature is enabled
|
||||||
if [[ "$DHCP_ACTIVE" == "true" ]]; then
|
if [[ "$DHCP_ACTIVE" == "true" ]]; then
|
||||||
ph_dhcp_eip="${DHCP_END##*.}"
|
|
||||||
ph_dhcp_max=$(( ${DHCP_END##*.} - ${DHCP_START##*.} + 1 ))
|
ph_dhcp_max=$(( ${DHCP_END##*.} - ${DHCP_START##*.} + 1 ))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get alt DNS server, or print total count of alt DNS servers
|
# Get DNS server count
|
||||||
if [[ -z "${PIHOLE_DNS_3}" ]]; then
|
dns_count="0"
|
||||||
ph_alts="${PIHOLE_DNS_2}"
|
[[ -n "${PIHOLE_DNS_1}" ]] && dns_count=$((dns_count+1))
|
||||||
else
|
[[ -n "${PIHOLE_DNS_2}" ]] && dns_count=$((dns_count+1))
|
||||||
dns_count="0"
|
[[ -n "${PIHOLE_DNS_3}" ]] && dns_count=$((dns_count+1))
|
||||||
[[ -n "${PIHOLE_DNS_2}" ]] && dns_count=$((dns_count+1))
|
[[ -n "${PIHOLE_DNS_4}" ]] && dns_count=$((dns_count+1))
|
||||||
[[ -n "${PIHOLE_DNS_3}" ]] && dns_count=$((dns_count+1))
|
[[ -n "${PIHOLE_DNS_5}" ]] && dns_count=$((dns_count+1))
|
||||||
[[ -n "${PIHOLE_DNS_4}" ]] && dns_count=$((dns_count+1))
|
[[ -n "${PIHOLE_DNS_6}" ]] && dns_count=$((dns_count+1))
|
||||||
[[ -n "${PIHOLE_DNS_5}" ]] && dns_count=$((dns_count+1))
|
[[ -n "${PIHOLE_DNS_7}" ]] && dns_count=$((dns_count+1))
|
||||||
[[ -n "${PIHOLE_DNS_6}" ]] && dns_count=$((dns_count+1))
|
[[ -n "${PIHOLE_DNS_8}" ]] && dns_count=$((dns_count+1))
|
||||||
[[ -n "${PIHOLE_DNS_7}" ]] && dns_count=$((dns_count+1))
|
[[ -n "${PIHOLE_DNS_9}" ]] && dns_count="$dns_count+"
|
||||||
[[ -n "${PIHOLE_DNS_8}" ]] && dns_count=$((dns_count+1))
|
|
||||||
[[ -n "${PIHOLE_DNS_9}" ]] && dns_count="$dns_count+"
|
|
||||||
ph_alts="${dns_count} others"
|
|
||||||
fi
|
|
||||||
fi
|
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_uptime=$(hrSecs "$(cut -d. -f1 /proc/uptime)")
|
||||||
sys_loadavg=$(cut -d " " -f1,2,3 /proc/loadavg)
|
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
|
||||||
cpu_raw=$(ps -eo pcpu,rss --no-headers | grep -E -v " 0")
|
cpu_raw=$(ps -eo pcpu,rss --no-headers | grep -E -v " 0")
|
||||||
cpu_tasks=$(wc -l <<< "$cpu_raw")
|
cpu_tasks=$(wc -l <<< "$cpu_raw")
|
||||||
cpu_taskact=$(sed -r "/(^ 0.)/d" <<< "$cpu_raw" | wc -l)
|
cpu_taskact=$(sed -r "/(^ 0.)/d" <<< "$cpu_raw" | wc -l)
|
||||||
|
@ -228,19 +294,19 @@ get_sys_stats() {
|
||||||
if [[ -n "$scaling_freq_file" ]]; then
|
if [[ -n "$scaling_freq_file" ]]; then
|
||||||
cpu_mhz=$(( $(< /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) / 1000 ))
|
cpu_mhz=$(( $(< /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) / 1000 ))
|
||||||
else
|
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
|
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
|
if [[ -n "$cpu_mhz" ]]; then
|
||||||
[[ "$cpu_mhz" -le "999" ]] && cpu_freq="$cpu_mhz MHz" || cpu_freq="$(calcFunc "$cpu_mhz"/1000) Ghz"
|
[[ "$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=""
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Determine colour for temperature
|
# Determine colour for temperature
|
||||||
if [[ -n "$temp_file" ]]; then
|
if [[ -n "$temp_file" ]]; then
|
||||||
if [[ "$temp_unit" == "C" ]]; 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
|
case "${cpu_temp::-1}" in
|
||||||
-*|[0-9]|[1-3][0-9]) cpu_col="$COL_LIGHT_BLUE";;
|
-*|[0-9]|[1-3][0-9]) cpu_col="$COL_LIGHT_BLUE";;
|
||||||
|
@ -251,10 +317,10 @@ get_sys_stats() {
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# $COL_NC$COL_DARK_GRAY is needed for $COL_URG_RED
|
# $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
|
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
|
case "${cpu_temp::-1}" in
|
||||||
-*|[0-9]|[0-9][0-9]) cpu_col="$COL_LIGHT_BLUE";;
|
-*|[0-9]|[0-9][0-9]) cpu_col="$COL_LIGHT_BLUE";;
|
||||||
|
@ -264,16 +330,16 @@ get_sys_stats() {
|
||||||
*) cpu_col="$COL_URG_RED";;
|
*) cpu_col="$COL_URG_RED";;
|
||||||
esac
|
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
|
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
|
fi
|
||||||
else
|
else
|
||||||
cpu_temp_str=""
|
cpu_temp_str=""
|
||||||
fi
|
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_perc="${ram_raw[0]}"
|
||||||
ram_used="${ram_raw[1]}"
|
ram_used="${ram_raw[1]}"
|
||||||
ram_total="${ram_raw[2]}"
|
ram_total="${ram_raw[2]}"
|
||||||
|
@ -281,114 +347,181 @@ get_sys_stats() {
|
||||||
if [[ "$(pihole status web 2> /dev/null)" == "1" ]]; then
|
if [[ "$(pihole status web 2> /dev/null)" == "1" ]]; then
|
||||||
ph_status="${COL_LIGHT_GREEN}Active"
|
ph_status="${COL_LIGHT_GREEN}Active"
|
||||||
else
|
else
|
||||||
ph_status="${COL_LIGHT_RED}Inactive"
|
ph_status="${COL_LIGHT_RED}Offline"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$DHCP_ACTIVE" == "true" ]]; then
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_ftl_stats() {
|
get_ftl_stats() {
|
||||||
local stats_raw
|
local stats_raw
|
||||||
|
|
||||||
stats_raw=($(pihole-FTL "stats"))
|
mapfile -t stats_raw < <(pihole-FTL "stats")
|
||||||
domains_being_blocked_raw="${stats_raw[1]}"
|
domains_being_blocked_raw="${stats_raw[1]#* }"
|
||||||
dns_queries_today_raw="${stats_raw[3]}"
|
dns_queries_today_raw="${stats_raw[3]#* }"
|
||||||
ads_blocked_today_raw="${stats_raw[5]}"
|
ads_blocked_today_raw="${stats_raw[5]#* }"
|
||||||
ads_percentage_today_raw="${stats_raw[7]}"
|
ads_percentage_today_raw="${stats_raw[7]#* }"
|
||||||
|
queries_forwarded_raw="${stats_raw[11]#* }"
|
||||||
|
queries_cached_raw="${stats_raw[13]#* }"
|
||||||
|
|
||||||
# Only retrieve these stats when not called from jsonFunc
|
# Only retrieve these stats when not called from jsonFunc
|
||||||
if [[ -z "$1" ]]; then
|
if [[ -z "$1" ]]; then
|
||||||
local recent_blocked_raw
|
|
||||||
local top_ad_raw
|
local top_ad_raw
|
||||||
local top_domain_raw
|
local top_domain_raw
|
||||||
local top_client_raw
|
local top_client_raw
|
||||||
|
|
||||||
domains_being_blocked=$(printf "%'.0f\n" "${domains_being_blocked_raw}")
|
domains_being_blocked=$(printf "%.0f\n" "${domains_being_blocked_raw}")
|
||||||
dns_queries_today=$(printf "%'.0f\n" "${dns_queries_today_raw}")
|
dns_queries_today=$(printf "%.0f\n" "${dns_queries_today_raw}")
|
||||||
ads_blocked_today=$(printf "%'.0f\n" "${ads_blocked_today_raw}")
|
ads_blocked_today=$(printf "%.0f\n" "${ads_blocked_today_raw}")
|
||||||
ads_percentage_today=$(printf "%'.0f\n" "${ads_percentage_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)")"
|
||||||
|
|
||||||
recent_blocked_raw=$(pihole-FTL recentBlocked)
|
top_ad="${top_ad_raw[2]}"
|
||||||
top_ad_raw=($(pihole-FTL "top-ads (1)"))
|
top_domain="${top_domain_raw[2]}"
|
||||||
top_domain_raw=($(pihole-FTL "top-domains (1)"))
|
if [[ "${top_client_raw[3]}" ]]; then
|
||||||
top_client_raw=($(pihole-FTL "top-clients (1)"))
|
top_client="${top_client_raw[3]}"
|
||||||
|
else
|
||||||
# Limit strings to 40 characters to prevent overflow
|
top_client="${top_client_raw[2]}"
|
||||||
recent_blocked="${recent_blocked_raw:0:40}"
|
fi
|
||||||
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}"
|
|
||||||
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")
|
||||||
|
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() {
|
chronoFunc() {
|
||||||
get_init_stats
|
get_init_stats
|
||||||
|
|
||||||
for (( ; ; )); do
|
for (( ; ; )); do
|
||||||
get_sys_stats
|
get_sys_stats
|
||||||
get_ftl_stats
|
get_ftl_stats
|
||||||
|
get_strings
|
||||||
|
|
||||||
# Do not print LTE/FTL strings if API is unavailable
|
# Strip excess development version numbers
|
||||||
ph_core_str=" ${COL_DARK_GRAY}Pi-hole: $ph_core_ver${COL_NC}"
|
if [[ "$ph_core_ver" != "-1" ]]; then
|
||||||
if [[ -n "$ph_lte_ver" ]]; then
|
phc_ver_str="$phc_str: ${ph_core_ver%-*}${COL_NC}"
|
||||||
ph_lte_str=" ${COL_DARK_GRAY}AdminLTE: $ph_lte_ver${COL_NC}"
|
lte_ver_str="$lte_str: ${ph_lte_ver%-*}${COL_NC}"
|
||||||
ph_ftl_str=" ${COL_DARK_GRAY}FTL: $ph_ftl_ver${COL_NC}"
|
ftl_ver_str="$ftl_str: ${ph_ftl_ver%-*}${COL_NC}"
|
||||||
|
else
|
||||||
|
phc_ver_str="$phc_str: $api_str${COL_NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get refresh number
|
||||||
|
if [[ "$*" == *"-r"* ]]; then
|
||||||
|
num="$*"
|
||||||
|
num="${num/*-r /}"
|
||||||
|
num="${num/ */}"
|
||||||
|
num_str="Refresh set for every $num seconds"
|
||||||
|
else
|
||||||
|
num_str=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
clear
|
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
|
# Remove exit message heading on third refresh
|
||||||
[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
|
if [[ "$count" -le 2 ]] && [[ "$*" != *"-e"* ]]; then
|
||||||
[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
|
echo -e " ${COL_LIGHT_GREEN}Pi-hole Chronometer${COL_NC}
|
||||||
${COL_DARK_GRAY}——————————————————————————————————————————————————————————${COL_NC}"
|
$num_str
|
||||||
|
${COL_LIGHT_RED}Press Ctrl-C to exit${COL_NC}
|
||||||
printFunc " Hostname: " "$sys_name"
|
${COL_DARK_GRAY}$scr_line_str${COL_NC}"
|
||||||
[ -n "$sys_type" ] && printf "%s(%s)%s\n" "$COL_DARK_GRAY" "$sys_type" "$COL_NC" || printf "\n"
|
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
|
||||||
printf "%s\n" " Uptime: $sys_uptime"
|
[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
|
||||||
printFunc " Task Load: " "$sys_loadavg"
|
${COL_DARK_GRAY}$scr_line_str${COL_NC}"
|
||||||
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"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printFunc " Pi-hole: " "$ph_status"
|
printFunc " Hostname: " "$sys_name" "$host_info"
|
||||||
printf "%s(%s)%s\n" "$COL_DARK_GRAY" "Blocking: $domains_being_blocked sites" "$COL_NC"
|
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"
|
||||||
|
|
||||||
printFunc " Ads Today: " "$ads_percentage_today%"
|
if [[ "$scr_lines" -gt 17 ]] && [[ "$chrono_width" != "small" ]]; then
|
||||||
printf "%s(%s)%s\n" "$COL_DARK_GRAY" "$ads_blocked_today of $dns_queries_today queries" "$COL_NC"
|
printFunc " LAN addr: " "${IPV4_ADDRESS/\/*/}" "$lan_info"
|
||||||
|
fi
|
||||||
|
|
||||||
printFunc " Fwd DNS: " "$PIHOLE_DNS_1"
|
if [[ "$DHCP_ACTIVE" == "true" ]]; then
|
||||||
printf "%s(%s)%s\n" "$COL_DARK_GRAY" "Alt DNS: $ph_alts" "$COL_NC"
|
printFunc "DHCP usage: " "$ph_dhcp_percent%" "$dhcp_info"
|
||||||
|
fi
|
||||||
|
|
||||||
echo -e " ${COL_DARK_GRAY}——————————————————————————————————————————————————————————${COL_NC}"
|
printFunc " Pi-hole: " "$ph_status" "$ph_info"
|
||||||
echo " Recently blocked: $recent_blocked"
|
printFunc " Ads Today: " "$ads_percentage_today%" "$ads_info"
|
||||||
echo " Top Advertiser: $top_ad"
|
printFunc "Local Qrys: " "$queries_cached_percentage%" "$dns_info"
|
||||||
echo " Top Domain: $top_domain"
|
|
||||||
printFunc " Top Client: " "$top_client" "last"
|
|
||||||
|
|
||||||
if [[ "$1" == "exit" ]]; then
|
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
|
exit 0
|
||||||
else
|
else
|
||||||
if [[ -n "$1" ]]; then
|
if [[ "$*" == *"-r"* ]]; then
|
||||||
sleep "${1}"
|
sleep "$num"
|
||||||
else
|
else
|
||||||
sleep 5
|
sleep 5
|
||||||
fi
|
fi
|
||||||
|
@ -428,8 +561,8 @@ for var in "$@"; do
|
||||||
case "$var" in
|
case "$var" in
|
||||||
"-j" | "--json" ) jsonFunc;;
|
"-j" | "--json" ) jsonFunc;;
|
||||||
"-h" | "--help" ) helpFunc;;
|
"-h" | "--help" ) helpFunc;;
|
||||||
"-r" | "--refresh" ) chronoFunc "$2";;
|
"-r" | "--refresh" ) chronoFunc "$@";;
|
||||||
"-e" | "--exit" ) chronoFunc "exit";;
|
"-e" | "--exit" ) chronoFunc "$@";;
|
||||||
* ) helpFunc "?";;
|
* ) helpFunc "?";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
|
@ -62,11 +62,14 @@ EscapeRegexp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleOther() {
|
HandleOther() {
|
||||||
# First, convert everything to lowercase
|
# Convert to lowercase
|
||||||
domain=$(sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" <<< "$1")
|
domain="${1,,}"
|
||||||
|
|
||||||
# Check validity of domain
|
# Check validity of domain
|
||||||
validDomain=$(echo "${domain}" | perl -lne 'print if /(?!.*[^a-z0-9-\.].*)^((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9-]+\.)*[a-z]{2,63}/')
|
validDomain=$(perl -lne 'print if /^((-|_)*[a-z\d]((-|_)*[a-z\d])*(-|_)*)(\.(-|_)*([a-z\d]((-|_)*[a-z\d])*))*$/' <<< "${domain}") # Valid chars check
|
||||||
|
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
|
if [[ -z "${validDomain}" ]]; then
|
||||||
echo -e " ${CROSS} $1 is not a valid argument or domain name!"
|
echo -e " ${CROSS} $1 is not a valid argument or domain name!"
|
||||||
else
|
else
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||||
# Network-wide ad blocking via your own hardware.
|
# Network-wide ad blocking via your own hardware.
|
||||||
#
|
#
|
||||||
# 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.
|
# This file is copyright under the latest version of the EUPL.
|
||||||
# Please see LICENSE file for your rights under this license.
|
# Please see LICENSE file for your rights under this license.
|
||||||
|
@ -154,7 +154,7 @@ fetch_checkout_pull_branch() {
|
||||||
cd "${directory}" || return 1
|
cd "${directory}" || return 1
|
||||||
git remote set-branches origin "${branch}" || return 1
|
git remote set-branches origin "${branch}" || return 1
|
||||||
git stash --all --quiet &> /dev/null || true
|
git stash --all --quiet &> /dev/null || true
|
||||||
git clean --force -d || true
|
git clean --quiet --force -d || true
|
||||||
git fetch --quiet || return 1
|
git fetch --quiet || return 1
|
||||||
checkout_pull_branch "${directory}" "${branch}" || return 1
|
checkout_pull_branch "${directory}" "${branch}" || return 1
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ checkout_pull_branch() {
|
||||||
|
|
||||||
oldbranch="$(git symbolic-ref HEAD)"
|
oldbranch="$(git symbolic-ref HEAD)"
|
||||||
|
|
||||||
git checkout "${branch}" || return 1
|
git checkout "${branch}" --quiet || return 1
|
||||||
|
|
||||||
if [[ "$(git diff "${oldbranch}" | grep -c "^")" -gt "0" ]]; then
|
if [[ "$(git diff "${oldbranch}" | grep -c "^")" -gt "0" ]]; then
|
||||||
update="true"
|
update="true"
|
||||||
|
@ -180,7 +180,7 @@ checkout_pull_branch() {
|
||||||
git_pull=$(git pull || return 1)
|
git_pull=$(git pull || return 1)
|
||||||
|
|
||||||
if [[ "$git_pull" == *"up-to-date"* ]]; then
|
if [[ "$git_pull" == *"up-to-date"* ]]; then
|
||||||
echo -e "\n ${INFO} $(git pull)"
|
echo -e " ${INFO} $(git pull)"
|
||||||
else
|
else
|
||||||
echo -e "$git_pull\n"
|
echo -e "$git_pull\n"
|
||||||
fi
|
fi
|
||||||
|
@ -239,19 +239,20 @@ checkout() {
|
||||||
if [[ "${1}" == "dev" ]] ; then
|
if [[ "${1}" == "dev" ]] ; then
|
||||||
# Shortcut to check out development branches
|
# Shortcut to check out development branches
|
||||||
echo -e " ${INFO} Shortcut \"dev\" detected - checking out development / devel 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; }
|
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"
|
echo -e " ${INFO} Web interface"
|
||||||
fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo " ${CROSS} Unable to pull Web development branch"; exit 1; }
|
fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo " ${CROSS} Unable to pull Web development branch"; exit 1; }
|
||||||
fi
|
fi
|
||||||
echo -e " ${TICK} Pi-hole core"
|
#echo -e " ${TICK} Pi-hole Core"
|
||||||
|
|
||||||
get_binary_name
|
get_binary_name
|
||||||
local path
|
local path
|
||||||
path="development/${binary}"
|
path="development/${binary}"
|
||||||
FTLinstall "${binary}" "${path}"
|
FTLinstall "${binary}" "${path}"
|
||||||
|
|
||||||
elif [[ "${1}" == "master" ]] ; then
|
elif [[ "${1}" == "master" ]] ; then
|
||||||
# Shortcut to check out master branches
|
# Shortcut to check out master branches
|
||||||
echo -e " ${INFO} Shortcut \"master\" detected - checking out master branches..."
|
echo -e " ${INFO} Shortcut \"master\" detected - checking out master branches..."
|
||||||
|
@ -261,13 +262,11 @@ checkout() {
|
||||||
echo -e " ${INFO} Web interface"
|
echo -e " ${INFO} Web interface"
|
||||||
fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo " ${CROSS} Unable to pull Web master branch"; exit 1; }
|
fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo " ${CROSS} Unable to pull Web master branch"; exit 1; }
|
||||||
fi
|
fi
|
||||||
echo -e " ${TICK} Web interface"
|
#echo -e " ${TICK} Web Interface"
|
||||||
|
get_binary_name
|
||||||
get_binary_name
|
|
||||||
local path
|
local path
|
||||||
path="master/${binary}"
|
path="master/${binary}"
|
||||||
FTLinstall "${binary}" "${path}"
|
FTLinstall "${binary}" "${path}"
|
||||||
|
|
||||||
elif [[ "${1}" == "core" ]] ; then
|
elif [[ "${1}" == "core" ]] ; then
|
||||||
str="Fetching branches from ${piholeGitUrl}"
|
str="Fetching branches from ${piholeGitUrl}"
|
||||||
echo -ne " ${INFO} $str"
|
echo -ne " ${INFO} $str"
|
||||||
|
|
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.
|
# This file is copyright under the latest version of the EUPL.
|
||||||
# Please see LICENSE file for your rights under this license.
|
# Please see LICENSE file for your rights under this license.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
|
|
||||||
readonly ADMIN_INTERFACE_GIT_URL="https://github.com/pi-hole/AdminLTE.git"
|
readonly ADMIN_INTERFACE_GIT_URL="https://github.com/pi-hole/AdminLTE.git"
|
||||||
readonly ADMIN_INTERFACE_DIR="/var/www/html/admin"
|
readonly ADMIN_INTERFACE_DIR="/var/www/html/admin"
|
||||||
readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git"
|
readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git"
|
||||||
|
@ -43,7 +40,7 @@ GitCheckUpdateAvail() {
|
||||||
|
|
||||||
# @ alone is a shortcut for HEAD. Older versions of git
|
# @ alone is a shortcut for HEAD. Older versions of git
|
||||||
# need @{0}
|
# need @{0}
|
||||||
LOCAL="$("git rev-parse @{0}")"
|
LOCAL="$(git rev-parse "@{0}")"
|
||||||
|
|
||||||
# The suffix @{upstream} to a branchname
|
# The suffix @{upstream} to a branchname
|
||||||
# (short form <branchname>@{u}) refers
|
# (short form <branchname>@{u}) refers
|
||||||
|
@ -52,7 +49,7 @@ GitCheckUpdateAvail() {
|
||||||
# (configured with branch.<name>.remote and
|
# (configured with branch.<name>.remote and
|
||||||
# branch.<name>.merge). A missing branchname
|
# branch.<name>.merge). A missing branchname
|
||||||
# defaults to the current one.
|
# defaults to the current one.
|
||||||
REMOTE="$("git rev-parse @{upstream}")"
|
REMOTE="$(git rev-parse "@{upstream}")"
|
||||||
|
|
||||||
if [[ ${#LOCAL} == 0 ]]; then
|
if [[ ${#LOCAL} == 0 ]]; then
|
||||||
echo -e " ${COL_LIGHT_RED}Error: Local revision could not be obtained, ask Pi-hole support."
|
echo -e " ${COL_LIGHT_RED}Error: Local revision could not be obtained, ask Pi-hole support."
|
||||||
|
@ -82,7 +79,6 @@ GitCheckUpdateAvail() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FTLcheckUpdate() {
|
FTLcheckUpdate() {
|
||||||
|
|
||||||
local FTLversion
|
local FTLversion
|
||||||
FTLversion=$(/usr/bin/pihole-FTL tag)
|
FTLversion=$(/usr/bin/pihole-FTL tag)
|
||||||
local FTLlatesttag
|
local FTLlatesttag
|
||||||
|
@ -131,7 +127,7 @@ main() {
|
||||||
# re-install (i.e. update) FTL
|
# re-install (i.e. update) FTL
|
||||||
if ${FTL_update} && ! ${core_update}; then
|
if ${FTL_update} && ! ${core_update}; then
|
||||||
echo ""
|
echo ""
|
||||||
echo -e " ${INFO} FTL out of date"
|
echo -e " ${INFO} FTL out of date"
|
||||||
FTLdetect
|
FTLdetect
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -89,6 +89,9 @@ SetWebPassword() {
|
||||||
readonly PASSWORD="${args[2]}"
|
readonly PASSWORD="${args[2]}"
|
||||||
readonly CONFIRM="${PASSWORD}"
|
readonly CONFIRM="${PASSWORD}"
|
||||||
else
|
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
|
read -s -p "Enter New Password (Blank for no password): " PASSWORD
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
@ -218,18 +221,19 @@ Reboot() {
|
||||||
}
|
}
|
||||||
|
|
||||||
RestartDNS() {
|
RestartDNS() {
|
||||||
local str="Restarting dnsmasq"
|
local str="Restarting DNS service"
|
||||||
echo -ne " ${INFO} ${str}..."
|
[[ -t 1 ]] && echo -ne " ${INFO} ${str}"
|
||||||
if [[ -x "$(command -v systemctl)" ]]; then
|
if command -v systemctl &> /dev/null; then
|
||||||
systemctl restart dnsmasq
|
output=$( { systemctl restart dnsmasq; } 2>&1 )
|
||||||
else
|
else
|
||||||
service dnsmasq restart
|
output=$( { service dnsmasq restart; } 2>&1 )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$?" == 0 ]]; then
|
if [[ -z "${output}" ]]; then
|
||||||
echo -e "${OVER} ${TICK} ${str}"
|
[[ -t 1 ]] && echo -e "${OVER} ${TICK} ${str}"
|
||||||
else
|
else
|
||||||
echo -e "${OVER} ${CROSS} ${str}"
|
[[ ! -t 1 ]] && OVER=""
|
||||||
|
echo -e "${OVER} ${CROSS} ${output}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
269
pihole
269
pihole
|
@ -87,10 +87,14 @@ scanList(){
|
||||||
domain="${1}"
|
domain="${1}"
|
||||||
list="${2}"
|
list="${2}"
|
||||||
method="${3}"
|
method="${3}"
|
||||||
if [[ ${method} == "-exact" ]] ; then
|
|
||||||
grep -i -E "(^|\s)${domain}($|\s)" "${list}"
|
# Switch folder, preventing grep from printing file path
|
||||||
|
cd "/etc/pihole" || return 1
|
||||||
|
|
||||||
|
if [[ -n "${method}" ]]; then
|
||||||
|
grep -i -E -l "(^|\s|\/)${domain}($|\s|\/)" ${list} /dev/null 2> /dev/null
|
||||||
else
|
else
|
||||||
grep -i "${domain}" "${list}"
|
grep -i "${domain}" ${list} /dev/null 2> /dev/null
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,46 +114,210 @@ processWildcards() {
|
||||||
}
|
}
|
||||||
|
|
||||||
queryFunc() {
|
queryFunc() {
|
||||||
domain="${2}"
|
options="$*"
|
||||||
|
options="${options/-q /}"
|
||||||
|
|
||||||
if [[ -z "${domain}" ]]; then
|
if [[ "${options}" == "-h" ]] || [[ "${options}" == "--help" ]]; then
|
||||||
echo -e " ${COL_LIGHT_RED}Invalid option${COL_NC}
|
echo "Usage: pihole -q [option] <domain>
|
||||||
Try 'pihole query --help' for more information."
|
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\|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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
method="${3}"
|
# If domain contains non ASCII characters, convert domain to punycode if python is available
|
||||||
lists=( /etc/pihole/list.* /etc/pihole/blacklist.txt)
|
# Cr: https://serverfault.com/a/335079
|
||||||
for list in ${lists[@]}; do
|
if [[ "$options" = *[![:ascii:]]* ]]; then
|
||||||
if [ -e "${list}" ]; then
|
if command -v python &> /dev/null; then
|
||||||
result=$(scanList ${domain} ${list} ${method})
|
query=$(python -c 'import sys;print sys.argv[1].decode("utf-8").encode("idna")' "${options}")
|
||||||
# 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
|
fi
|
||||||
done
|
else
|
||||||
|
query="${options}"
|
||||||
|
fi
|
||||||
|
|
||||||
# Scan for possible wildcard matches
|
# Scan Whitelist and Blacklist
|
||||||
if [ -e "${wildcardlist}" ]; then
|
lists="whitelist.txt blacklist.txt"
|
||||||
local wildcards=($(processWildcards "${domain}"))
|
results=($(scanList "${query}" "${lists}" "${method}"))
|
||||||
for domain in ${wildcards[@]}; do
|
|
||||||
result=$(scanList "\/${domain}\/" ${wildcardlist})
|
if [[ -n "${results[*]}" ]]; then
|
||||||
# Remove empty lines before couting number of results
|
# Loop through each scanList line to print appropriate title
|
||||||
count=$(sed '/^\s*$/d' <<< "$result" | wc -l)
|
for result in "${results[@]}"; do
|
||||||
if [[ ${count} > 0 ]]; then
|
filename="${result/:*/}"
|
||||||
echo -e " ${TICK} Wildcard blocking ${domain} (${count} results)"
|
if [[ -n "$exact" ]]; then
|
||||||
echo "${result}"
|
printf " Exact result in %s\n" "${filename}"
|
||||||
echo ""
|
elif [[ -n "$blockpage" ]]; then
|
||||||
|
printf " [i] %s\n" "${filename}"
|
||||||
|
else
|
||||||
|
domain="${result/*:/}"
|
||||||
|
if [[ ! "${filename}" == "${filename_prev:-}" ]]; then
|
||||||
|
printf " Result from %s\n" "${filename}"
|
||||||
|
fi
|
||||||
|
printf " %s\n" "${domain}"
|
||||||
|
filename_prev="${filename}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
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 " ${INFO} ${match}"
|
||||||
|
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]}"
|
||||||
|
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
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,24 +341,32 @@ versionFunc() {
|
||||||
|
|
||||||
restartDNS() {
|
restartDNS() {
|
||||||
dnsmasqPid=$(pidof dnsmasq)
|
dnsmasqPid=$(pidof dnsmasq)
|
||||||
|
local str="Restarting DNS service"
|
||||||
|
echo -ne " ${INFO} ${str}"
|
||||||
if [[ "${dnsmasqPid}" ]]; then
|
if [[ "${dnsmasqPid}" ]]; then
|
||||||
# Service already running - reload config
|
# Service already running - reload config
|
||||||
echo -ne " ${INFO} Restarting dnsmasq"
|
|
||||||
if [[ -x "$(command -v systemctl)" ]]; then
|
if [[ -x "$(command -v systemctl)" ]]; then
|
||||||
systemctl restart dnsmasq
|
output=$( { systemctl restart dnsmasq; } 2>&1 )
|
||||||
else
|
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
|
fi
|
||||||
[[ "$?" == 0 ]] && echo -e "${OVER} ${TICK} Restarted dnsmasq" || echo -e "${OVER} ${CROSS} Failed to restart dnsmasq"
|
|
||||||
else
|
else
|
||||||
# Service not running, start it up
|
# Service not running, start it up
|
||||||
echo -ne " ${INFO} Starting dnsmasq"
|
|
||||||
if [[ -x "$(command -v systemctl)" ]]; then
|
if [[ -x "$(command -v systemctl)" ]]; then
|
||||||
systemctl start dnsmasq
|
output=$( { systemctl start dnsmasq; } 2>&1 )
|
||||||
else
|
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
|
fi
|
||||||
[[ "$?" == 0 ]] && echo -e "${OVER} ${TICK} Restarted dnsmasq" || echo -e "${OVER} ${CROSS} Failed to restart dnsmasq"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,8 +516,13 @@ piholeStatus() {
|
||||||
}
|
}
|
||||||
|
|
||||||
tailFunc() {
|
tailFunc() {
|
||||||
|
date=$(date +'%b %d ')
|
||||||
echo -e " ${INFO} Press Ctrl-C to exit"
|
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
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,7 +606,7 @@ Options:
|
||||||
-l, logging Specify whether the Pi-hole log should be used
|
-l, logging Specify whether the Pi-hole log should be used
|
||||||
Add '-h' for more info on logging usage
|
Add '-h' for more info on logging usage
|
||||||
-q, query Query the adlists for a specified domain
|
-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
|
-up, updatePihole Update Pi-hole subsystems
|
||||||
-v, version Show installed versions of Pi-hole, Admin Console & FTL
|
-v, version Show installed versions of Pi-hole, Admin Console & FTL
|
||||||
Add '-h' for more info on version usage
|
Add '-h' for more info on version usage
|
||||||
|
|
Loading…
Reference in a new issue