mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +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>
|
||||
</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.
|
||||
|
||||
- Web Browsers
|
||||
- Cell Phones
|
||||
- Smart TV's
|
||||
- Internet-connected home automation
|
||||
- Anything that communicates with the Internet
|
||||
Block ads for **all** your devices _without_ the need to install client-side software.
|
||||
|
||||
<p align="center">
|
||||
<a href=http://www.digitalocean.com/?refcode=344d234950e1><img src="https://assets.pi-hole.net/static/DOHostingSlug.png"></a>
|
||||
</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)
|
||||
- ![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 +53,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
|
||||
[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/)
|
||||
- [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 +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)
|
||||
- [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)
|
||||
|
|
|
@ -7,6 +7,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 +33,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 +122,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"
|
||||
}
|
||||
}
|
||||
|
||||
# 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 +178,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 +189,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 +219,95 @@ 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
|
||||
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 +315,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 +329,199 @@ 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[1]#* }"
|
||||
dns_queries_today_raw="${stats_raw[3]#* }"
|
||||
ads_blocked_today_raw="${stats_raw[5]#* }"
|
||||
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
|
||||
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}")
|
||||
|
||||
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}"
|
||||
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")
|
||||
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 +542,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 +561,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.
|
||||
|
@ -154,7 +154,7 @@ fetch_checkout_pull_branch() {
|
|||
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
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ checkout_pull_branch() {
|
|||
|
||||
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
|
||||
update="true"
|
||||
|
@ -180,7 +180,7 @@ checkout_pull_branch() {
|
|||
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"
|
||||
fi
|
||||
|
@ -239,19 +239,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
|
||||
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..."
|
||||
|
@ -261,13 +262,11 @@ 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"
|
||||
|
||||
get_binary_name
|
||||
#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"
|
||||
|
|
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"
|
||||
|
@ -43,7 +40,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,7 +49,7 @@ 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."
|
||||
|
@ -82,7 +79,6 @@ GitCheckUpdateAvail() {
|
|||
}
|
||||
|
||||
FTLcheckUpdate() {
|
||||
|
||||
local FTLversion
|
||||
FTLversion=$(/usr/bin/pihole-FTL tag)
|
||||
local FTLlatesttag
|
||||
|
@ -131,7 +127,7 @@ 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
|
||||
|
|
|
@ -31,7 +31,7 @@ Options:
|
|||
-k, kelvin Set Kelvin as preferred temperature unit
|
||||
-h, --help Show this help dialog
|
||||
-i, interface Specify dnsmasq's interface listening behavior
|
||||
Add '-h' for more info on interface usage"
|
||||
Add '-h' for more info on interface usage"
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,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 ""
|
||||
|
||||
|
@ -218,18 +221,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}"
|
||||
|
||||
if [[ -z "${output}" ]]; then
|
||||
[[ -t 1 ]] && echo -e "${OVER} ${TICK} ${str}"
|
||||
else
|
||||
echo -e "${OVER} ${CROSS} ${str}"
|
||||
[[ ! -t 1 ]] && OVER=""
|
||||
echo -e "${OVER} ${CROSS} ${output}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -402,7 +406,7 @@ SetHostRecord() {
|
|||
|
||||
SetListeningMode() {
|
||||
source "${setupVars}"
|
||||
|
||||
|
||||
if [[ "$3" == "-h" ]] || [[ "$3" == "--help" ]]; then
|
||||
echo "Usage: pihole -a -i [interface]
|
||||
Example: 'pihole -a -i local'
|
||||
|
@ -415,7 +419,7 @@ Interfaces:
|
|||
all Listen on all interfaces, permit all origins"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
if [[ "${args[2]}" == "all" ]]; then
|
||||
echo -e " ${INFO} Listening on all interfaces, permiting all origins. Please use a firewall!"
|
||||
change_setting "DNSMASQ_LISTENING" "all"
|
||||
|
|
File diff suppressed because it is too large
Load diff
275
pihole
275
pihole
|
@ -87,10 +87,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 +114,210 @@ 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\|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
|
||||
# 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 " [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
|
||||
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 " ${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
|
||||
}
|
||||
|
||||
|
@ -173,24 +341,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
|
||||
}
|
||||
|
||||
|
@ -340,8 +516,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
|
||||
}
|
||||
|
||||
|
@ -425,7 +606,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
|
||||
|
|
Loading…
Reference in a new issue