Compare commits
413 Commits
fix/migrat
...
5ed52554d7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ed52554d7 | ||
|
|
75286a1626 | ||
|
|
9bc17a1f2b | ||
|
|
86850e9020 | ||
|
|
d4562a1deb | ||
|
|
62ccfc77de | ||
|
|
0df3b41ca0 | ||
|
|
5cb601200c | ||
|
|
342c8b693b | ||
|
|
24d8754033 | ||
|
|
966e466c9e | ||
|
|
37ec67e9a3 | ||
|
|
364ba99b1f | ||
|
|
9252e90bd6 | ||
|
|
ae0fef4626 | ||
|
|
5b4a7b8b74 | ||
|
|
a9680db218 | ||
|
|
7aa57e154e | ||
|
|
05f4ae7719 | ||
|
|
29b6252935 | ||
|
|
f324d4cc7d | ||
|
|
310f0711fa | ||
|
|
9580dc6560 | ||
|
|
70e317f373 | ||
|
|
285b3c37f9 | ||
|
|
41f6738e97 | ||
|
|
22e6ff2cdf | ||
|
|
be36432f24 | ||
|
|
4bea9a1d12 | ||
|
|
35ce3580e5 | ||
|
|
90eb5778ca | ||
|
|
c0539a4fb0 | ||
|
|
da85a7a2a7 | ||
|
|
3c52ce98d4 | ||
|
|
ae048201a2 | ||
|
|
dad27f8d06 | ||
|
|
c0b512be60 | ||
|
|
cef7fd4b02 | ||
|
|
c09da77e2b | ||
|
|
18e8396a44 | ||
|
|
1bef0415db | ||
|
|
d6a83baf4f | ||
|
|
605ff8183a | ||
|
|
e231107e81 | ||
|
|
9494dc6061 | ||
|
|
71501e15e5 | ||
|
|
0187087da0 | ||
|
|
9605ccc178 | ||
|
|
86bdae0076 | ||
|
|
05ad3d7155 | ||
|
|
ea8272d7d4 | ||
|
|
1e88ce4975 | ||
|
|
bb60e2e346 | ||
|
|
3977a312f0 | ||
|
|
b3d193b34c | ||
|
|
0a36e9d949 | ||
|
|
6db6c68a4e | ||
|
|
5b5e02d492 | ||
|
|
a2dd0e2f50 | ||
|
|
3d75ea6df2 | ||
|
|
080e1ccf8a | ||
|
|
24f32d48af | ||
|
|
8486cfd95a | ||
|
|
c81d5019a3 | ||
|
|
c5c5116e53 | ||
|
|
2f9fa80d7a | ||
|
|
f2280eb330 | ||
|
|
f24fc9573a | ||
|
|
3a35e589f2 | ||
|
|
19d5943440 | ||
|
|
f90677a1ff | ||
|
|
daec6f8c02 | ||
|
|
a48665c7bb | ||
|
|
8a97a1433a | ||
|
|
f94d9f2540 | ||
|
|
830c4bc049 | ||
|
|
1dbe425146 | ||
|
|
fc2f7795e9 | ||
|
|
0bc06ed204 | ||
|
|
700c892dff | ||
|
|
405053692a | ||
|
|
04d9d32444 | ||
|
|
c19e907c0c | ||
|
|
7a16024020 | ||
|
|
5777497f52 | ||
|
|
404dc7cb88 | ||
|
|
2f3dfef862 | ||
|
|
b39c9956e8 | ||
|
|
70bcb0bb2b | ||
|
|
2c1032090d | ||
|
|
b5adc981c2 | ||
|
|
3933cb0575 | ||
|
|
6964cd124e | ||
|
|
d16c049768 | ||
|
|
5ff4f000d5 | ||
|
|
93ecfb9504 | ||
|
|
ea61755881 | ||
|
|
6130b800e3 | ||
|
|
ec892ec096 | ||
|
|
4d4195ed4e | ||
|
|
260fa5ea40 | ||
|
|
03b3b69617 | ||
|
|
8c81335004 | ||
|
|
e1b05028a7 | ||
|
|
89c4976da4 | ||
|
|
4fed49c5e5 | ||
|
|
cad0d0bf1f | ||
|
|
42aba32ceb | ||
|
|
6f429d82b4 | ||
|
|
fd40fa6f39 | ||
|
|
d177c4c776 | ||
|
|
888556278e | ||
|
|
69473a7b54 | ||
|
|
f3166d7a78 | ||
|
|
137338e6a8 | ||
|
|
b707890f10 | ||
|
|
822e677c5c | ||
|
|
5aadc5f475 | ||
|
|
6ba6b0f015 | ||
|
|
5f60860a17 | ||
|
|
86d9ac5f8f | ||
|
|
a04ed13d0a | ||
|
|
04e52daaf3 | ||
|
|
88934ec818 | ||
|
|
9aa005ad4c | ||
|
|
f6d477f228 | ||
|
|
3c1d8690fa | ||
|
|
3314887e65 | ||
|
|
c1a5b902fb | ||
|
|
a590b77431 | ||
|
|
dee44cb3da | ||
|
|
de31858950 | ||
|
|
13848f2da1 | ||
|
|
e01d49b3ee | ||
|
|
190798e572 | ||
|
|
1bdbc26a07 | ||
|
|
842afc2475 | ||
|
|
398405c303 | ||
|
|
189da82614 | ||
|
|
99d00e0ed0 | ||
|
|
3c6c3d3a15 | ||
|
|
3c0ff57660 | ||
|
|
9f3e71b0b6 | ||
|
|
d45003a8ca | ||
|
|
7aaaa49cf0 | ||
|
|
fc103af050 | ||
|
|
46fbd931b5 | ||
|
|
96437dc913 | ||
|
|
cae558d5d4 | ||
|
|
65fd0b099d | ||
|
|
95d27ac985 | ||
|
|
744ac6ad88 | ||
|
|
b82487ee6a | ||
|
|
0a72e517b6 | ||
|
|
09368a77b4 | ||
|
|
0e6439c6c0 | ||
|
|
0c533ec71b | ||
|
|
5355e9e084 | ||
|
|
54c8dd3d77 | ||
|
|
d9f4ee7aaa | ||
|
|
40da3a40ec | ||
|
|
3cbaee7b76 | ||
|
|
3bd6a41795 | ||
|
|
4303a5868f | ||
|
|
215003899d | ||
|
|
cf3b7d0d8e | ||
|
|
454f96d0ea | ||
|
|
1bea6db50a | ||
|
|
72a52807d1 | ||
|
|
d7b6d6aa33 | ||
|
|
7a641f4c35 | ||
|
|
ce0bdac1bd | ||
|
|
13d76abff7 | ||
|
|
76e41aeefa | ||
|
|
774037834b | ||
|
|
89c4248315 | ||
|
|
6fc5bf83f4 | ||
|
|
4a1bcda6f1 | ||
|
|
60485fdc51 | ||
|
|
6fe77ebeed | ||
|
|
8733b429dd | ||
|
|
1432568d17 | ||
|
|
cff7f40739 | ||
|
|
248d25b8d0 | ||
|
|
95c1b1a542 | ||
|
|
9e62625f83 | ||
|
|
faeba69090 | ||
|
|
48272f3393 | ||
|
|
195e65855d | ||
|
|
0f511ad574 | ||
|
|
323dbbe5d9 | ||
|
|
bda81cb2f5 | ||
|
|
b271dbf606 | ||
|
|
5002ce8ba7 | ||
|
|
135b0cce14 | ||
|
|
23fc53c618 | ||
|
|
3732ea7365 | ||
|
|
ca1bab3c1b | ||
|
|
36e6c9921e | ||
|
|
6c5bc1de39 | ||
|
|
9f5e18b1cd | ||
|
|
d28e795266 | ||
|
|
e579397f51 | ||
|
|
2088601148 | ||
|
|
48c59cb6cf | ||
|
|
f01e8c70d9 | ||
|
|
3a9b9c027e | ||
|
|
f5dc337d1b | ||
|
|
63623c4353 | ||
|
|
59d2177271 | ||
|
|
a624d3be8d | ||
|
|
39f5115135 | ||
|
|
e018a37a8c | ||
|
|
6e06a93c31 | ||
|
|
7e5d9db6b7 | ||
|
|
5afab5e96c | ||
|
|
ab8b8da9c3 | ||
|
|
07864032de | ||
|
|
bdcb6fc88c | ||
|
|
f403468450 | ||
|
|
097ac8336e | ||
|
|
fe2b22c570 | ||
|
|
2477d6b184 | ||
|
|
f98b9520e4 | ||
|
|
65b42c1c8f | ||
|
|
e548ed043f | ||
|
|
4108c817dc | ||
|
|
8fd2ebd3d7 | ||
|
|
4efe4dfd4b | ||
|
|
557bc6f179 | ||
|
|
8fce8f6149 | ||
|
|
3cb6ea503a | ||
|
|
7886cfc80b | ||
|
|
8797a0df05 | ||
|
|
0f7803b775 | ||
|
|
0f482396ee | ||
|
|
73074f1557 | ||
|
|
bc23303788 | ||
|
|
49fbdc4c00 | ||
|
|
315528d740 | ||
|
|
71ec0a0244 | ||
|
|
e5cb0efd61 | ||
|
|
dec670a6d6 | ||
|
|
3a592471c6 | ||
|
|
3f5c00919b | ||
|
|
349544b24a | ||
|
|
387ec3a3c2 | ||
|
|
6b873b2d7f | ||
|
|
46e5b3b02e | ||
|
|
27aeed76f0 | ||
|
|
80d63eca93 | ||
|
|
72404c983d | ||
|
|
9b4502a7a9 | ||
|
|
5de9b6ae69 | ||
|
|
f3dc202e36 | ||
|
|
9050e47049 | ||
|
|
45cb722e50 | ||
|
|
98b17edfd7 | ||
|
|
d094b197e3 | ||
|
|
e437e3a805 | ||
|
|
4df5c0bb96 | ||
|
|
411b9fcb6d | ||
|
|
9fe687bd62 | ||
|
|
bef8227cbd | ||
|
|
edf336067a | ||
|
|
196a84721f | ||
|
|
978694f262 | ||
|
|
7eef780fbc | ||
|
|
df814ece91 | ||
|
|
9c7e02f213 | ||
|
|
0130f7be74 | ||
|
|
f207385269 | ||
|
|
ce73691082 | ||
|
|
8874757958 | ||
|
|
821c953216 | ||
|
|
53e241f057 | ||
|
|
a9650ae287 | ||
|
|
7282aada25 | ||
|
|
c5d66c2162 | ||
|
|
869411a514 | ||
|
|
d1b5f95aa7 | ||
|
|
ad6a48b219 | ||
|
|
83a38bb71d | ||
|
|
232d581916 | ||
|
|
002536ae09 | ||
|
|
8a788ad755 | ||
|
|
0b380d671d | ||
|
|
65bcb24d0e | ||
|
|
e70981d80f | ||
|
|
9840b42847 | ||
|
|
b59ab5852a | ||
|
|
a0541dd7fb | ||
|
|
48c4efd7b0 | ||
|
|
729a44f82a | ||
|
|
9c995962a5 | ||
|
|
5da5d0d4c1 | ||
|
|
a7e414aca4 | ||
|
|
567bb724b1 | ||
|
|
bc3c78f4fa | ||
|
|
ce18de3d6d | ||
|
|
8e706e4a16 | ||
|
|
667a25574a | ||
|
|
8f5296536e | ||
|
|
da4048ba5d | ||
|
|
1764f99333 | ||
|
|
cadee26dba | ||
|
|
b64a54bba1 | ||
|
|
5d5bddc979 | ||
|
|
bd3a0f4891 | ||
|
|
cd269cbca1 | ||
|
|
8290e414ce | ||
|
|
0e6d9e74d9 | ||
|
|
f38332409f | ||
|
|
cd4efc3141 | ||
|
|
99bd142dd5 | ||
|
|
49bb6dc0da | ||
|
|
6f82ec5121 | ||
|
|
9de976cbbd | ||
|
|
0890f67322 | ||
|
|
f7403e2ee6 | ||
|
|
51a9412c4b | ||
|
|
2d81552f9f | ||
|
|
2faad0b60a | ||
|
|
c9e58adc48 | ||
|
|
d1639740d9 | ||
|
|
abb94cafe4 | ||
|
|
1bebeff720 | ||
|
|
dfc2b32248 | ||
|
|
49cf5bb221 | ||
|
|
9d53ad7668 | ||
|
|
8fb3ccc147 | ||
|
|
9212a4a514 | ||
|
|
2ae78e02bd | ||
|
|
330698878a | ||
|
|
8e298df1e8 | ||
|
|
894a9e157f | ||
|
|
88cfda7210 | ||
|
|
0da97e762f | ||
|
|
94e772378e | ||
|
|
7dbf408c26 | ||
|
|
ec805f9543 | ||
|
|
7162be18e2 | ||
|
|
9cd32bf2b7 | ||
|
|
9da1e9ab88 | ||
|
|
37718c65e9 | ||
|
|
aadea31e52 | ||
|
|
9faef22061 | ||
|
|
bf899fa57f | ||
|
|
68b03e114c | ||
|
|
e682f69a1d | ||
|
|
f50c696253 | ||
|
|
6e0b16ed1a | ||
|
|
4322299c39 | ||
|
|
cee021c358 | ||
|
|
c381109dcd | ||
|
|
9a3fcf2a85 | ||
|
|
6d4d35e848 | ||
|
|
69bfb3ff3b | ||
|
|
f7727f98bd | ||
|
|
05f8bb128c | ||
|
|
66757de3fb | ||
|
|
08e3257f37 | ||
|
|
0f318027fc | ||
|
|
254b67bca3 | ||
|
|
0ae50eab87 | ||
|
|
cc25ee940e | ||
|
|
12927f8a3d | ||
|
|
efaa0f4287 | ||
|
|
83d464e85f | ||
|
|
27fb2bbe3a | ||
|
|
c78be8a89d | ||
|
|
0590bbba2d | ||
|
|
733dce1c4c | ||
|
|
bd9cc7cbb7 | ||
|
|
4902c70063 | ||
|
|
4be130971e | ||
|
|
211a881888 | ||
|
|
4d23187f86 | ||
|
|
b544b74f7a | ||
|
|
6e633e4cfd | ||
|
|
364281354c | ||
|
|
4c5285e469 | ||
|
|
79087fb252 | ||
|
|
fab1ca3a40 | ||
|
|
4fd77f57fa | ||
|
|
bd9cb00574 | ||
|
|
b0e0bdc436 | ||
|
|
1835827371 | ||
|
|
cb32a7f81c | ||
|
|
2cf046d559 | ||
|
|
a1ccee6694 | ||
|
|
dff0c0105d | ||
|
|
d972ffa53a | ||
|
|
22b6dc7dae | ||
|
|
3406915917 | ||
|
|
50645c2924 | ||
|
|
d14273f958 | ||
|
|
47d5a08565 | ||
|
|
e08f65d1c4 | ||
|
|
b964657b62 | ||
|
|
a2a22c4e13 | ||
|
|
8faa28d8a0 | ||
|
|
a9948304db | ||
|
|
3011d48b6f | ||
|
|
c777152c04 | ||
|
|
579dc07046 | ||
|
|
633c971a44 | ||
|
|
9a9af719f0 | ||
|
|
fdf44355d2 | ||
|
|
a5cb07c76e | ||
|
|
59e9bac794 | ||
|
|
b2ad878f4a | ||
|
|
6ff30f7294 |
5
.github/CODEOWNERS
vendored
Normal file
5
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
# see https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#codeowners-syntax
|
||||
|
||||
# These owners will be the default owners for everything in
|
||||
# the repo. Unless a later match takes precedence,
|
||||
* @pi-hole/core-maintainers
|
||||
12
.github/dependabot.yml
vendored
12
.github/dependabot.yml
vendored
@@ -8,8 +8,10 @@ updates:
|
||||
time: "10:00"
|
||||
open-pull-requests-limit: 10
|
||||
target-branch: development
|
||||
reviewers:
|
||||
- "pi-hole/core-maintainers"
|
||||
groups:
|
||||
github-actions-dependencies:
|
||||
patterns:
|
||||
- "*"
|
||||
- package-ecosystem: pip
|
||||
directory: "/test"
|
||||
schedule:
|
||||
@@ -18,5 +20,7 @@ updates:
|
||||
time: "10:00"
|
||||
open-pull-requests-limit: 10
|
||||
target-branch: development
|
||||
reviewers:
|
||||
- "pi-hole/core-maintainers"
|
||||
groups:
|
||||
python-dependencies:
|
||||
patterns:
|
||||
- "*"
|
||||
|
||||
1
.github/release.yml
vendored
1
.github/release.yml
vendored
@@ -2,6 +2,7 @@ changelog:
|
||||
exclude:
|
||||
labels:
|
||||
- internal
|
||||
- dependencies
|
||||
authors:
|
||||
- dependabot
|
||||
- github-actions
|
||||
|
||||
2
.github/workflows/merge-conflict.yml
vendored
2
.github/workflows/merge-conflict.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check if PRs are have merge conflicts
|
||||
uses: eps1lon/actions-label-merge-conflict@v3.0.2
|
||||
uses: eps1lon/actions-label-merge-conflict@v3.0.3
|
||||
with:
|
||||
dirtyLabel: "PR: Merge Conflict"
|
||||
repoToken: "${{ secrets.GITHUB_TOKEN }}"
|
||||
|
||||
4
.github/workflows/stale.yml
vendored
4
.github/workflows/stale.yml
vendored
@@ -17,14 +17,14 @@ jobs:
|
||||
issues: write
|
||||
|
||||
steps:
|
||||
- uses: actions/stale@v9.0.0
|
||||
- uses: actions/stale@v9.1.0
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
days-before-stale: 30
|
||||
days-before-close: 5
|
||||
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Please comment or update this issue or it will be closed in 5 days.'
|
||||
stale-issue-label: '${{ env.stale_label }}'
|
||||
exempt-issue-labels: 'Internal, Fixed in next release, Bug: Confirmed, Documentation Needed'
|
||||
exempt-issue-labels: 'Internal, Fixed in next release, Bug: Confirmed, Documentation Needed, never-stale'
|
||||
exempt-all-issue-assignees: true
|
||||
operations-per-run: 300
|
||||
close-issue-reason: 'not_planned'
|
||||
|
||||
2
.github/workflows/stale_pr.yml
vendored
2
.github/workflows/stale_pr.yml
vendored
@@ -17,7 +17,7 @@ jobs:
|
||||
pull-requests: write
|
||||
|
||||
steps:
|
||||
- uses: actions/stale@v9.0.0
|
||||
- uses: actions/stale@v9.1.0
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Do not automatically mark PR/issue as stale
|
||||
|
||||
20
.github/workflows/test.yml
vendored
20
.github/workflows/test.yml
vendored
@@ -19,6 +19,8 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
fetch-depth: 0 # Differential ShellCheck requires full git history
|
||||
|
||||
- name: Check scripts in repository are executable
|
||||
run: |
|
||||
@@ -28,12 +30,12 @@ jobs:
|
||||
# If FAIL is 1 then we fail.
|
||||
[[ $FAIL == 1 ]] && exit 1 || echo "Scripts are executable!"
|
||||
|
||||
- name: Run shellcheck
|
||||
uses: ludeeus/action-shellcheck@master
|
||||
- name: Differential ShellCheck
|
||||
uses: redhat-plumbers-in-action/differential-shellcheck@v5
|
||||
with:
|
||||
check_together: 'yes'
|
||||
format: tty
|
||||
severity: error
|
||||
severity: warning
|
||||
display-engine: sarif-fmt
|
||||
|
||||
|
||||
- name: Spell-Checking
|
||||
uses: codespell-project/actions-codespell@master
|
||||
@@ -67,8 +69,10 @@ jobs:
|
||||
ubuntu_22,
|
||||
ubuntu_24,
|
||||
centos_9,
|
||||
centos_10,
|
||||
fedora_40,
|
||||
fedora_41,
|
||||
fedora_42,
|
||||
]
|
||||
env:
|
||||
DISTRO: ${{matrix.distro}}
|
||||
@@ -76,10 +80,10 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4.2.2
|
||||
|
||||
- name: Set up Python 3.10
|
||||
uses: actions/setup-python@v5.3.0
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5.6.0
|
||||
with:
|
||||
python-version: "3.10"
|
||||
python-version: "3.13"
|
||||
|
||||
- name: Install wheel
|
||||
run: pip install wheel
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -10,3 +10,6 @@ __pycache__
|
||||
.idea/
|
||||
*.iml
|
||||
.vscode/
|
||||
.venv/
|
||||
.fleet/
|
||||
.cache/
|
||||
|
||||
2
.shellcheckrc
Normal file
2
.shellcheckrc
Normal file
@@ -0,0 +1,2 @@
|
||||
external-sources=true # allow shellcheck to read external sources
|
||||
disable=SC3043 #disable SC3043: In POSIX sh, local is undefined.
|
||||
17
README.md
17
README.md
@@ -3,13 +3,9 @@
|
||||
#
|
||||
|
||||
<p align="center">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://pi-hole.github.io/graphics/Vortex/Vortex_Vertical_wordmark_darkmode.png">
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://pi-hole.github.io/graphics/Vortex/Vortex_Vertical_wordmark_lightmode.png">
|
||||
<img src="https://pi-hole.github.io/graphics/Vortex/Vortex_Vertical_wordmark_lightmode.png" width="168" height="270" alt="Pi-hole website">
|
||||
</picture>
|
||||
<br>
|
||||
<strong>Network-wide ad blocking via your own Linux hardware</strong>
|
||||
<img src="https://raw.githubusercontent.com/pi-hole/graphics/refs/heads/master/Vortex/vortex_with_text.svg" alt="Pi-hole website" width="168" height="270">
|
||||
<br>
|
||||
<strong>Network-wide ad blocking via your own Linux hardware</strong>
|
||||
</p>
|
||||
|
||||
<!-- markdownlint-enable MD033 -->
|
||||
@@ -132,7 +128,10 @@ Some of the statistics you can integrate include:
|
||||
- Queries cached
|
||||
- Unique clients
|
||||
|
||||
Access the API via [`telnet`](https://github.com/pi-hole/FTL), the Web (`admin/api.php`) and Command Line (`pihole -c -j`). You can find out [more details over here](https://discourse.pi-hole.net/t/pi-hole-api/1863).
|
||||
Access the API using:
|
||||
- your browser: http://pi.hole/api/docs
|
||||
- `curl`: `curl --connect-timeout 2 -ks "https://pi.hole/api/stats/summary" -H "Accept: application/json"`;
|
||||
- the command line - examples: `pihole api config/webserver/port` or `pihole api stats/summary`.
|
||||
|
||||
### The Command-Line Interface
|
||||
|
||||
@@ -140,7 +139,7 @@ The [pihole](https://docs.pi-hole.net/core/pihole-command/) command has all the
|
||||
|
||||
Some notable features include:
|
||||
|
||||
- [Whitelisting, Blacklisting, and Regex](https://docs.pi-hole.net/core/pihole-command/#whitelisting-blacklisting-and-regex)
|
||||
- [Allowlisting, Denylisting (fka Whitelisting, Blacklisting), and Regex](https://docs.pi-hole.net/core/pihole-command/#allowlisting-denylisting-and-regex)
|
||||
- [Debugging utility](https://docs.pi-hole.net/core/pihole-command/#debugger)
|
||||
- [Viewing the live log file](https://docs.pi-hole.net/core/pihole-command/#tail)
|
||||
- [Updating Ad Lists](https://docs.pi-hole.net/core/pihole-command/#gravity)
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#!/usr/bin/env sh
|
||||
# shellcheck disable=SC2034 # Disable warning about unused variables
|
||||
|
||||
# Determine if terminal is capable of showing colors
|
||||
if ([ -t 1 ] && [ $(tput colors) -ge 8 ]) || [ "${WEBCALL}" ]; then
|
||||
# When COL_TABLE is sourced via gravity invoked by FTL, FORCE_COLOR is set to true
|
||||
if { [ -t 1 ] && [ "$(tput colors)" -ge 8 ]; } || [ "${FORCE_COLOR}" ]; then
|
||||
# Bold and underline may not show up on all clients
|
||||
# If something MUST be emphasized, use both
|
||||
COL_BOLD='[1m'
|
||||
COL_ULINE='[4m'
|
||||
|
||||
COL_NC='[0m'
|
||||
COL_GRAY='[90m'
|
||||
COL_RED='[91m'
|
||||
@@ -16,8 +18,6 @@ if ([ -t 1 ] && [ $(tput colors) -ge 8 ]) || [ "${WEBCALL}" ]; then
|
||||
else
|
||||
# Provide empty variables for `set -u`
|
||||
COL_BOLD=""
|
||||
COL_ULINE=""
|
||||
|
||||
COL_NC=""
|
||||
COL_GRAY=""
|
||||
COL_RED=""
|
||||
@@ -28,22 +28,8 @@ else
|
||||
COL_CYAN=""
|
||||
fi
|
||||
|
||||
# Deprecated variables
|
||||
COL_WHITE="${COL_BOLD}"
|
||||
COL_BLACK="${COL_NC}"
|
||||
COL_LIGHT_BLUE="${COL_BLUE}"
|
||||
COL_LIGHT_GREEN="${COL_GREEN}"
|
||||
COL_LIGHT_CYAN="${COL_CYAN}"
|
||||
COL_LIGHT_RED="${COL_RED}"
|
||||
COL_URG_RED="${COL_RED}${COL_BOLD}${COL_ULINE}"
|
||||
COL_LIGHT_PURPLE="${COL_PURPLE}"
|
||||
COL_BROWN="${COL_YELLOW}"
|
||||
COL_LIGHT_GRAY="${COL_GRAY}"
|
||||
COL_DARK_GRAY="${COL_GRAY}"
|
||||
|
||||
TICK="[${COL_GREEN}✓${COL_NC}]"
|
||||
CROSS="[${COL_RED}✗${COL_NC}]"
|
||||
INFO="[i]"
|
||||
QST="[?]"
|
||||
DONE="${COL_GREEN} done!${COL_NC}"
|
||||
OVER="\\r[K"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
# shellcheck disable=SC3043 #https://github.com/koalaman/shellcheck/wiki/SC3043#exceptions
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||
@@ -20,13 +19,20 @@
|
||||
|
||||
TestAPIAvailability() {
|
||||
|
||||
local chaos_api_list authResponse authStatus authData apiAvailable DNSport
|
||||
|
||||
# as we are running locally, we can get the port value from FTL directly
|
||||
local chaos_api_list availabilityResponse
|
||||
PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source=./advanced/Scripts/utils.sh
|
||||
. "${utilsfile}"
|
||||
|
||||
DNSport=$(getFTLConfigValue dns.port)
|
||||
|
||||
# Query the API URLs from FTL using CHAOS TXT local.api.ftl
|
||||
# The result is a space-separated enumeration of full URLs
|
||||
# e.g., "http://localhost:80/api/" "https://localhost:443/api/"
|
||||
chaos_api_list="$(dig +short chaos txt local.api.ftl @127.0.0.1)"
|
||||
chaos_api_list="$(dig +short -p "${DNSport}" chaos txt local.api.ftl @127.0.0.1)"
|
||||
|
||||
# If the query was not successful, the variable is empty
|
||||
if [ -z "${chaos_api_list}" ]; then
|
||||
@@ -34,6 +40,12 @@ TestAPIAvailability() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If an error occurred, the variable starts with ;;
|
||||
if [ "${chaos_api_list#;;}" != "${chaos_api_list}" ]; then
|
||||
echo "Communication error. Is FTL running?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Iterate over space-separated list of URLs
|
||||
while [ -n "${chaos_api_list}" ]; do
|
||||
# Get the first URL
|
||||
@@ -42,39 +54,50 @@ TestAPIAvailability() {
|
||||
API_URL="${API_URL%\"}"
|
||||
API_URL="${API_URL#\"}"
|
||||
|
||||
# Test if the API is available at this URL
|
||||
availabilityResponse=$(curl -skS -o /dev/null -w "%{http_code}" "${API_URL}auth")
|
||||
# Test if the API is available at this URL, include delimiter for ease in splitting payload
|
||||
authResponse=$(curl --connect-timeout 2 -skS -w ">>%{http_code}" "${API_URL}auth")
|
||||
|
||||
# authStatus is the response http_code, eg. 200, 401.
|
||||
# Shell parameter expansion, remove everything up to and including the >> delim
|
||||
authStatus=${authResponse#*>>}
|
||||
# data is everything from response
|
||||
# Shell parameter expansion, remove the >> delim and everything after
|
||||
authData=${authResponse%>>*}
|
||||
|
||||
# Test if http status code was 200 (OK) or 401 (authentication required)
|
||||
if [ ! "${availabilityResponse}" = 200 ] && [ ! "${availabilityResponse}" = 401 ]; then
|
||||
# API is not available at this port/protocol combination
|
||||
API_PORT=""
|
||||
else
|
||||
# API is available at this URL combination
|
||||
|
||||
if [ "${availabilityResponse}" = 200 ]; then
|
||||
# API is available without authentication
|
||||
needAuth=false
|
||||
fi
|
||||
|
||||
if [ "${authStatus}" = 200 ]; then
|
||||
# API is available without authentication
|
||||
apiAvailable=true
|
||||
needAuth=false
|
||||
break
|
||||
fi
|
||||
|
||||
# Remove the first URL from the list
|
||||
local last_api_list
|
||||
last_api_list="${chaos_api_list}"
|
||||
chaos_api_list="${chaos_api_list#* }"
|
||||
elif [ "${authStatus}" = 401 ]; then
|
||||
# API is available with authentication
|
||||
apiAvailable=true
|
||||
needAuth=true
|
||||
# Check if 2FA is required
|
||||
needTOTP=$(echo "${authData}"| jq --raw-output .session.totp 2>/dev/null)
|
||||
break
|
||||
|
||||
# If the list did not change, we are at the last element
|
||||
if [ "${last_api_list}" = "${chaos_api_list}" ]; then
|
||||
# Remove the last element
|
||||
chaos_api_list=""
|
||||
else
|
||||
# API is not available at this port/protocol combination
|
||||
apiAvailable=false
|
||||
# Remove the first URL from the list
|
||||
local last_api_list
|
||||
last_api_list="${chaos_api_list}"
|
||||
chaos_api_list="${chaos_api_list#* }"
|
||||
|
||||
# If the list did not change, we are at the last element
|
||||
if [ "${last_api_list}" = "${chaos_api_list}" ]; then
|
||||
# Remove the last element
|
||||
chaos_api_list=""
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# if API_PORT is empty, no working API port was found
|
||||
if [ -n "${API_PORT}" ]; then
|
||||
echo "API not available at: ${API_URL}"
|
||||
# if apiAvailable is false, no working API was found
|
||||
if [ "${apiAvailable}" = false ]; then
|
||||
echo "API not available. Please check FTL.log"
|
||||
echo "Exiting."
|
||||
exit 1
|
||||
fi
|
||||
@@ -102,22 +125,58 @@ LoginAPI() {
|
||||
echo "API Authentication: Trying to use CLI password"
|
||||
fi
|
||||
|
||||
# Try to authenticate using the CLI password
|
||||
Authentication "${1}"
|
||||
|
||||
# If we can read the CLI password, we can skip 2FA even when it's required otherwise
|
||||
needTOTP=false
|
||||
elif [ "${1}" = "verbose" ]; then
|
||||
echo "API Authentication: CLI password not available"
|
||||
fi
|
||||
|
||||
if [ -z "${password}" ]; then
|
||||
# no password read from CLI file
|
||||
echo "Please enter your password:"
|
||||
# secretly read the password
|
||||
secretRead; printf '\n'
|
||||
fi
|
||||
|
||||
if [ "${needTOTP}" = true ]; then
|
||||
# 2FA required
|
||||
echo "Please enter the correct second factor."
|
||||
echo "(Can be any number if you used the app password)"
|
||||
read -r totp
|
||||
fi
|
||||
|
||||
# If this did not work, ask the user for the password
|
||||
while [ "${validSession}" = false ] || [ -z "${validSession}" ] ; do
|
||||
echo "Authentication failed. Please enter your Pi-hole password"
|
||||
# Try to authenticate using the supplied password (CLI file or user input) and TOTP
|
||||
Authentication "${1}"
|
||||
|
||||
# Try to login again until the session is valid
|
||||
while [ ! "${validSession}" = true ] ; do
|
||||
|
||||
# Print the error message if there is one
|
||||
if [ ! "${sessionError}" = "null" ] && [ "${1}" = "verbose" ]; then
|
||||
echo "Error: ${sessionError}"
|
||||
fi
|
||||
# Print the session message if there is one
|
||||
if [ ! "${sessionMessage}" = "null" ] && [ "${1}" = "verbose" ]; then
|
||||
echo "Error: ${sessionMessage}"
|
||||
fi
|
||||
|
||||
if [ "${1}" = "verbose" ]; then
|
||||
# If we are not in verbose mode, no need to print the error message again
|
||||
echo "Please enter your Pi-hole password"
|
||||
else
|
||||
|
||||
echo "Authentication failed. Please enter your Pi-hole password"
|
||||
fi
|
||||
|
||||
# secretly read the password
|
||||
secretRead; printf '\n'
|
||||
|
||||
if [ "${needTOTP}" = true ]; then
|
||||
echo "Please enter the correct second factor:"
|
||||
echo "(Can be any number if you used the app password)"
|
||||
read -r totp
|
||||
fi
|
||||
|
||||
# Try to authenticate again
|
||||
Authentication "${1}"
|
||||
done
|
||||
@@ -125,23 +184,34 @@ LoginAPI() {
|
||||
}
|
||||
|
||||
Authentication() {
|
||||
sessionResponse="$(curl -skS -X POST "${API_URL}auth" --user-agent "Pi-hole cli " --data "{\"password\":\"${password}\"}" )"
|
||||
sessionResponse="$(curl --connect-timeout 2 -skS -X POST "${API_URL}auth" --user-agent "Pi-hole cli" --data "{\"password\":\"${password}\", \"totp\":${totp:-null}}" )"
|
||||
|
||||
if [ -z "${sessionResponse}" ]; then
|
||||
echo "No response from FTL server. Please check connectivity"
|
||||
exit 1
|
||||
fi
|
||||
# obtain validity and session ID from session response
|
||||
validSession=$(echo "${sessionResponse}"| jq .session.valid 2>/dev/null)
|
||||
SID=$(echo "${sessionResponse}"| jq --raw-output .session.sid 2>/dev/null)
|
||||
|
||||
if [ "${1}" = "verbose" ]; then
|
||||
if [ "${validSession}" = true ]; then
|
||||
echo "API Authentication: ${COL_GREEN}Success${COL_NC}"
|
||||
else
|
||||
echo "API Authentication: ${COL_RED}Failed${COL_NC}"
|
||||
if [ -z "${sessionResponse}" ]; then
|
||||
echo "No response from FTL server. Please check connectivity"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# obtain validity, session ID, sessionMessage and error message from
|
||||
# session response, apply default values if none returned
|
||||
result=$(echo "${sessionResponse}" | jq -r '
|
||||
(.session.valid // false),
|
||||
(.session.sid // null),
|
||||
(.session.message // null),
|
||||
(.error.message // null)
|
||||
' 2>/dev/null)
|
||||
|
||||
validSession=$(echo "${result}" | sed -n '1p')
|
||||
SID=$(echo "${result}" | sed -n '2p')
|
||||
sessionMessage=$(echo "${result}" | sed -n '3p')
|
||||
sessionError=$(echo "${result}" | sed -n '4p')
|
||||
|
||||
if [ "${1}" = "verbose" ]; then
|
||||
if [ "${validSession}" = true ]; then
|
||||
echo "API Authentication: ${COL_GREEN}Success${COL_NC}"
|
||||
else
|
||||
echo "API Authentication: ${COL_RED}Failed${COL_NC}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
LogoutAPI() {
|
||||
@@ -165,19 +235,21 @@ GetFTLData() {
|
||||
# get the data from querying the API as well as the http status code
|
||||
response=$(curl -skS -w "%{http_code}" -X GET "${API_URL}$1" -H "Accept: application/json" -H "sid: ${SID}" )
|
||||
|
||||
# status are the last 3 characters
|
||||
status="${response#"${response%???}"}"
|
||||
# data is everything from response without the last 3 characters
|
||||
data="${response%???}"
|
||||
|
||||
if [ "${2}" = "raw" ]; then
|
||||
# return the raw response
|
||||
echo "${response}"
|
||||
else
|
||||
|
||||
# status are the last 3 characters
|
||||
# not using ${response#"${response%???}"}" here because it's extremely slow on big responses
|
||||
status=$(printf "%s" "${response}" | tail -c 3)
|
||||
# data is everything from response without the last 3 characters
|
||||
data="${response%???}"
|
||||
|
||||
# return only the data
|
||||
if [ "${status}" = 200 ]; then
|
||||
# response OK
|
||||
echo "${data}"
|
||||
printf %s "${data}"
|
||||
else
|
||||
# connection lost
|
||||
echo "${status}"
|
||||
@@ -251,20 +323,30 @@ secretRead() {
|
||||
}
|
||||
|
||||
apiFunc() {
|
||||
local data response status status_col
|
||||
local data response status status_col verbosity
|
||||
|
||||
# Define if the output will be silent (default) or verbose
|
||||
verbosity="silent"
|
||||
if [ "$1" = "verbose" ]; then
|
||||
verbosity="verbose"
|
||||
shift
|
||||
fi
|
||||
|
||||
# Authenticate with the API
|
||||
LoginAPI verbose
|
||||
echo ""
|
||||
LoginAPI "${verbosity}"
|
||||
|
||||
echo "Requesting: ${COL_PURPLE}GET ${COL_CYAN}${API_URL}${COL_YELLOW}$1${COL_NC}"
|
||||
echo ""
|
||||
if [ "${verbosity}" = "verbose" ]; then
|
||||
echo ""
|
||||
echo "Requesting: ${COL_PURPLE}GET ${COL_CYAN}${API_URL}${COL_YELLOW}$1${COL_NC}"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Get the data from the API
|
||||
response=$(GetFTLData "$1" raw)
|
||||
|
||||
# status are the last 3 characters
|
||||
status="${response#"${response%???}"}"
|
||||
# not using ${response#"${response%???}"}" here because it's extremely slow on big responses
|
||||
status=$(printf "%s" "${response}" | tail -c 3)
|
||||
# data is everything from response without the last 3 characters
|
||||
data="${response%???}"
|
||||
|
||||
@@ -274,17 +356,21 @@ apiFunc() {
|
||||
else
|
||||
status_col="${COL_RED}"
|
||||
fi
|
||||
echo "Status: ${status_col}${status}${COL_NC}"
|
||||
|
||||
# Only print the status in verbose mode or if the status is not 200
|
||||
if [ "${verbosity}" = "verbose" ] || [ "${status}" != 200 ]; then
|
||||
echo "Status: ${status_col}${status}${COL_NC}"
|
||||
fi
|
||||
|
||||
# Output the data. Format it with jq if available and data is actually JSON.
|
||||
# Otherwise just print it
|
||||
echo "Data:"
|
||||
if command -v jq >/dev/null && echo "${data}" | jq . >/dev/null 2>&1; then
|
||||
echo "${data}" | jq .
|
||||
else
|
||||
echo "${data}"
|
||||
if [ "${verbosity}" = "verbose" ]; then
|
||||
echo "Data:"
|
||||
fi
|
||||
# Attempt to print the data with jq, if it is not valid JSON, or not installed
|
||||
# then print the plain text.
|
||||
echo "${data}" | jq . 2>/dev/null || echo "${data}"
|
||||
|
||||
# Delete the session
|
||||
LogoutAPI verbose
|
||||
LogoutAPI "${verbosity}"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1090
|
||||
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2019 Pi-hole, LLC (https://pi-hole.net)
|
||||
@@ -13,9 +13,8 @@
|
||||
readonly scriptPath="/etc/.pihole/advanced/Scripts/database_migration/gravity"
|
||||
|
||||
upgrade_gravityDB(){
|
||||
local database piholeDir version
|
||||
local database version
|
||||
database="${1}"
|
||||
piholeDir="${2}"
|
||||
|
||||
# Exit early if the database does not exist (e.g. in CI tests)
|
||||
if [[ ! -f "${database}" ]]; then
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1090
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||
@@ -10,11 +9,13 @@
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
readonly utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
source "${utilsfile}"
|
||||
|
||||
readonly apifile="${PI_HOLE_SCRIPT_DIR}/api.sh"
|
||||
apifile="${PI_HOLE_SCRIPT_DIR}/api.sh"
|
||||
# shellcheck source="./advanced/Scripts/api.sh"
|
||||
source "${apifile}"
|
||||
|
||||
# Determine database location
|
||||
@@ -39,6 +40,7 @@ typeId=""
|
||||
comment=""
|
||||
|
||||
colfile="/opt/pihole/COL_TABLE"
|
||||
# shellcheck source="./advanced/Scripts/COL_TABLE"
|
||||
source ${colfile}
|
||||
|
||||
helpFunc() {
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1090
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2019 Pi-hole, LLC (https://pi-hole.net)
|
||||
# Network-wide ad blocking via your own hardware.
|
||||
#
|
||||
# ARP table interaction
|
||||
#
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
coltable="/opt/pihole/COL_TABLE"
|
||||
if [[ -f ${coltable} ]]; then
|
||||
source ${coltable}
|
||||
fi
|
||||
|
||||
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
source "${utilsfile}"
|
||||
|
||||
# Determine database location
|
||||
DBFILE=$(getFTLConfigValue "files.database")
|
||||
if [ -z "$DBFILE" ]; then
|
||||
DBFILE="/etc/pihole/pihole-FTL.db"
|
||||
fi
|
||||
|
||||
flushARP(){
|
||||
local output
|
||||
if [[ "${args[1]}" != "quiet" ]]; then
|
||||
echo -ne " ${INFO} Flushing network table ..."
|
||||
fi
|
||||
|
||||
# Stop FTL to prevent database access
|
||||
if ! output=$(service pihole-FTL stop 2>&1); then
|
||||
echo -e "${OVER} ${CROSS} Failed to stop FTL"
|
||||
echo " Output: ${output}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Truncate network_addresses table in pihole-FTL.db
|
||||
# This needs to be done before we can truncate the network table due to
|
||||
# foreign key constraints
|
||||
if ! output=$(pihole-FTL sqlite3 -ni "${DBFILE}" "DELETE FROM network_addresses" 2>&1); then
|
||||
echo -e "${OVER} ${CROSS} Failed to truncate network_addresses table"
|
||||
echo " Database location: ${DBFILE}"
|
||||
echo " Output: ${output}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Truncate network table in pihole-FTL.db
|
||||
if ! output=$(pihole-FTL sqlite3 -ni "${DBFILE}" "DELETE FROM network" 2>&1); then
|
||||
echo -e "${OVER} ${CROSS} Failed to truncate network table"
|
||||
echo " Database location: ${DBFILE}"
|
||||
echo " Output: ${output}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Flush ARP cache of the host
|
||||
if ! output=$(ip -s -s neigh flush all 2>&1); then
|
||||
echo -e "${OVER} ${CROSS} Failed to flush ARP cache"
|
||||
echo " Output: ${output}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Start FTL again
|
||||
if ! output=$(service pihole-FTL restart 2>&1); then
|
||||
echo -e "${OVER} ${CROSS} Failed to restart FTL"
|
||||
echo " Output: ${output}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ "${args[1]}" != "quiet" ]]; then
|
||||
echo -e "${OVER} ${TICK} Flushed network table"
|
||||
fi
|
||||
}
|
||||
|
||||
args=("$@")
|
||||
|
||||
case "${args[0]}" in
|
||||
"arpflush" ) flushARP;;
|
||||
esac
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
||||
SKIP_INSTALL="true"
|
||||
# shellcheck source="./automated install/basic-install.sh"
|
||||
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
||||
|
||||
# webInterfaceGitUrl set in basic-install.sh
|
||||
@@ -25,7 +26,7 @@ source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
||||
warning1() {
|
||||
echo " Please note that changing branches severely alters your Pi-hole subsystems"
|
||||
echo " Features that work on the master branch, may not on a development branch"
|
||||
echo -e " ${COL_LIGHT_RED}This feature is NOT supported unless a Pi-hole developer explicitly asks!${COL_NC}"
|
||||
echo -e " ${COL_RED}This feature is NOT supported unless a Pi-hole developer explicitly asks!${COL_NC}"
|
||||
read -r -p " Have you read and understood this? [y/N] " response
|
||||
case "${response}" in
|
||||
[yY][eE][sS]|[yY])
|
||||
@@ -54,19 +55,19 @@ checkout() {
|
||||
|
||||
# This is unlikely
|
||||
if ! is_repo "${PI_HOLE_FILES_DIR}" ; then
|
||||
echo -e " ${COL_LIGHT_RED}Error: Core Pi-hole repo is missing from system!"
|
||||
echo -e " ${COL_RED}Error: Core Pi-hole repo is missing from system!"
|
||||
echo -e " Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if ! is_repo "${webInterfaceDir}" ; then
|
||||
echo -e " ${COL_LIGHT_RED}Error: Web Admin repo is missing from system!"
|
||||
echo -e " ${COL_RED}Error: Web Admin repo is missing from system!"
|
||||
echo -e " Please re-run install script from https://github.com/pi-hole/pi-hole${COL_NC}"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [[ -z "${1}" ]]; then
|
||||
echo -e " ${COL_LIGHT_RED}Invalid option${COL_NC}"
|
||||
echo -e " ${COL_RED}Invalid option${COL_NC}"
|
||||
echo -e " Try 'pihole checkout --help' for more information."
|
||||
exit 1
|
||||
fi
|
||||
@@ -109,7 +110,7 @@ checkout() {
|
||||
echo -e "${OVER} ${CROSS} $str"
|
||||
exit 1
|
||||
fi
|
||||
corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}"))
|
||||
mapfile -t corebranches < <(get_available_branches "${PI_HOLE_FILES_DIR}")
|
||||
|
||||
if [[ "${corebranches[*]}" == *"master"* ]]; then
|
||||
echo -e "${OVER} ${TICK} $str"
|
||||
@@ -136,7 +137,7 @@ checkout() {
|
||||
echo -e "${OVER} ${CROSS} $str"
|
||||
exit 1
|
||||
fi
|
||||
webbranches=($(get_available_branches "${webInterfaceDir}"))
|
||||
mapfile -t webbranches < <(get_available_branches "${webInterfaceDir}")
|
||||
|
||||
if [[ "${webbranches[*]}" == *"master"* ]]; then
|
||||
echo -e "${OVER} ${TICK} $str"
|
||||
@@ -167,7 +168,7 @@ checkout() {
|
||||
|
||||
# Check if requested branch is available
|
||||
echo -e " ${INFO} Checking for availability of branch ${COL_CYAN}${2}${COL_NC} on GitHub"
|
||||
ftlbranches=( $(git ls-remote https://github.com/pi-hole/ftl | grep "refs/heads" | cut -d'/' -f3- -) )
|
||||
mapfile -t ftlbranches < <(git ls-remote https://github.com/pi-hole/ftl | grep "refs/heads" | cut -d'/' -f3- -)
|
||||
# If returned array is empty -> connectivity issue
|
||||
if [[ ${#ftlbranches[@]} -eq 0 ]]; then
|
||||
echo -e " ${CROSS} Unable to fetch branches from GitHub. Please check your Internet connection and try again later."
|
||||
@@ -209,13 +210,15 @@ checkout() {
|
||||
# Update local and remote versions via updatechecker
|
||||
/opt/pihole/updatecheck.sh
|
||||
else
|
||||
if [ $? -eq 1 ]; then
|
||||
local status
|
||||
status=$?
|
||||
if [ $status -eq 1 ]; then
|
||||
# Binary for requested branch is not available, may still be
|
||||
# int he process of being built or CI build job failed
|
||||
printf " %b Binary for requested branch is not available, please try again later.\\n" ${CROSS}
|
||||
printf " %b Binary for requested branch is not available, please try again later.\\n" "${CROSS}"
|
||||
printf " If the issue persists, please contact Pi-hole Support and ask them to re-generate the binary.\\n"
|
||||
exit 1
|
||||
elif [ $? -eq 2 ]; then
|
||||
elif [ $status -eq 2 ]; then
|
||||
printf " %b Unable to download from ftl.pi-hole.net. Please check your Internet connection and try again later.\\n" "${CROSS}"
|
||||
exit 1
|
||||
else
|
||||
@@ -235,7 +238,7 @@ checkout() {
|
||||
if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then
|
||||
exit 0
|
||||
else
|
||||
echo -e " ${COL_LIGHT_RED} Error: Unable to complete update, please contact support${COL_NC}"
|
||||
echo -e " ${COL_RED} Error: Unable to complete update, please contact support${COL_NC}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
|
||||
# -e option instructs bash to immediately exit if any command [1] has a non-zero exit status
|
||||
# -u a reference to any variable you haven't previously defined
|
||||
@@ -27,6 +26,7 @@ PIHOLE_COLTABLE_FILE="${PIHOLE_SCRIPTS_DIRECTORY}/COL_TABLE"
|
||||
|
||||
# These provide the colors we need for making the log more readable
|
||||
if [[ -f ${PIHOLE_COLTABLE_FILE} ]]; then
|
||||
# shellcheck source=./advanced/Scripts/COL_TABLE
|
||||
source ${PIHOLE_COLTABLE_FILE}
|
||||
else
|
||||
COL_NC='\e[0m' # No Color
|
||||
@@ -41,9 +41,17 @@ else
|
||||
#OVER="\r\033[K"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
# shellcheck source=/dev/null
|
||||
. /etc/pihole/versions
|
||||
|
||||
# Read the value of an FTL config key. The value is printed to stdout.
|
||||
get_ftl_conf_value() {
|
||||
local key=$1
|
||||
|
||||
# Obtain setting from FTL directly
|
||||
pihole-FTL --config "${key}"
|
||||
}
|
||||
|
||||
# FAQ URLs for use in showing the debug log
|
||||
FAQ_HARDWARE_REQUIREMENTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/${COL_NC}"
|
||||
FAQ_HARDWARE_REQUIREMENTS_PORTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#ports${COL_NC}"
|
||||
@@ -61,10 +69,10 @@ DNSMASQ_D_DIRECTORY="/etc/dnsmasq.d"
|
||||
PIHOLE_DIRECTORY="/etc/pihole"
|
||||
PIHOLE_SCRIPTS_DIRECTORY="/opt/pihole"
|
||||
BIN_DIRECTORY="/usr/local/bin"
|
||||
RUN_DIRECTORY="/run"
|
||||
LOG_DIRECTORY="/var/log/pihole"
|
||||
HTML_DIRECTORY="/var/www/html"
|
||||
WEB_GIT_DIRECTORY="${HTML_DIRECTORY}/admin"
|
||||
HTML_DIRECTORY="$(get_ftl_conf_value "webserver.paths.webroot")"
|
||||
WEBHOME_PATH="$(get_ftl_conf_value "webserver.paths.webhome")"
|
||||
WEB_GIT_DIRECTORY="${HTML_DIRECTORY}${WEBHOME_PATH}"
|
||||
SHM_DIRECTORY="/dev/shm"
|
||||
ETC="/etc"
|
||||
|
||||
@@ -79,14 +87,6 @@ PIHOLE_FTL_CONF_FILE="${PIHOLE_DIRECTORY}/pihole.toml"
|
||||
PIHOLE_DNSMASQ_CONF_FILE="${PIHOLE_DIRECTORY}/dnsmasq.conf"
|
||||
PIHOLE_VERSIONS_FILE="${PIHOLE_DIRECTORY}/versions"
|
||||
|
||||
# Read the value of an FTL config key. The value is printed to stdout.
|
||||
get_ftl_conf_value() {
|
||||
local key=$1
|
||||
|
||||
# Obtain setting from FTL directly
|
||||
pihole-FTL --config "${key}"
|
||||
}
|
||||
|
||||
PIHOLE_GRAVITY_DB_FILE="$(get_ftl_conf_value "files.gravity")"
|
||||
|
||||
PIHOLE_FTL_DB_FILE="$(get_ftl_conf_value "files.database")"
|
||||
@@ -94,7 +94,7 @@ PIHOLE_FTL_DB_FILE="$(get_ftl_conf_value "files.database")"
|
||||
PIHOLE_COMMAND="${BIN_DIRECTORY}/pihole"
|
||||
PIHOLE_COLTABLE_FILE="${BIN_DIRECTORY}/COL_TABLE"
|
||||
|
||||
FTL_PID="${RUN_DIRECTORY}/pihole-FTL.pid"
|
||||
FTL_PID="$(get_ftl_conf_value "files.pid")"
|
||||
|
||||
PIHOLE_LOG="${LOG_DIRECTORY}/pihole.log"
|
||||
PIHOLE_LOG_GZIPS="${LOG_DIRECTORY}/pihole.log.[0-9].*"
|
||||
@@ -202,7 +202,7 @@ compare_local_version_to_git_version() {
|
||||
if git status &> /dev/null; then
|
||||
# The current version the user is on
|
||||
local local_version
|
||||
local_version=$(git describe --tags --abbrev=0);
|
||||
local_version=$(git describe --tags --abbrev=0 2> /dev/null);
|
||||
# What branch they are on
|
||||
local local_branch
|
||||
local_branch=$(git rev-parse --abbrev-ref HEAD);
|
||||
@@ -213,7 +213,13 @@ compare_local_version_to_git_version() {
|
||||
local local_status
|
||||
local_status=$(git status -s)
|
||||
# echo this information out to the user in a nice format
|
||||
log_write "${TICK} Version: ${local_version}"
|
||||
if [ "${local_version}" ]; then
|
||||
log_write "${TICK} Version: ${local_version}"
|
||||
elif [ -n "${DOCKER_VERSION}" ]; then
|
||||
log_write "${TICK} Version: Pi-hole Docker Container ${COL_BOLD}${DOCKER_VERSION}${COL_NC}"
|
||||
else
|
||||
log_write "${CROSS} Version: not detected"
|
||||
fi
|
||||
|
||||
# Print the repo upstreams
|
||||
remotes=$(git remote -v)
|
||||
@@ -290,88 +296,12 @@ check_component_versions() {
|
||||
check_ftl_version
|
||||
}
|
||||
|
||||
os_check() {
|
||||
# This function gets a list of supported OS versions from a TXT record at versions.pi-hole.net
|
||||
# and determines whether or not the script is running on one of those systems
|
||||
local remote_os_domain valid_os valid_version detected_os detected_version cmdResult digReturnCode response
|
||||
remote_os_domain=${OS_CHECK_DOMAIN_NAME:-"versions.pi-hole.net"}
|
||||
|
||||
detected_os=$(grep "\bID\b" /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
detected_version=$(grep VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
|
||||
cmdResult="$(dig -4 +short -t txt "${remote_os_domain}" @ns1.pi-hole.net 2>&1; echo $?)"
|
||||
#Get the return code of the previous command (last line)
|
||||
digReturnCode="${cmdResult##*$'\n'}"
|
||||
|
||||
# Extract dig response
|
||||
response="${cmdResult%%$'\n'*}"
|
||||
|
||||
if [ "${digReturnCode}" -ne 0 ]; then
|
||||
log_write "${INFO} Distro: ${detected_os^}"
|
||||
log_write "${INFO} Version: ${detected_version}"
|
||||
log_write "${CROSS} dig IPv4 return code: ${COL_RED}${digReturnCode}${COL_NC}"
|
||||
log_write "${CROSS} dig response: ${response}"
|
||||
log_write "${INFO} Retrying via IPv6"
|
||||
|
||||
cmdResult="$(dig -6 +short -t txt "${remote_os_domain}" @ns1.pi-hole.net 2>&1; echo $?)"
|
||||
#Get the return code of the previous command (last line)
|
||||
digReturnCode="${cmdResult##*$'\n'}"
|
||||
|
||||
# Extract dig response
|
||||
response="${cmdResult%%$'\n'*}"
|
||||
fi
|
||||
# If also no success via IPv6
|
||||
if [ "${digReturnCode}" -ne 0 ]; then
|
||||
log_write "${CROSS} dig IPv6 return code: ${COL_RED}${digReturnCode}${COL_NC}"
|
||||
log_write "${CROSS} dig response: ${response}"
|
||||
log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}"
|
||||
else
|
||||
IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"')
|
||||
for distro_and_versions in "${supportedOS[@]}"
|
||||
do
|
||||
distro_part="${distro_and_versions%%=*}"
|
||||
versions_part="${distro_and_versions##*=}"
|
||||
|
||||
if [[ "${detected_os^^}" =~ ${distro_part^^} ]]; then
|
||||
valid_os=true
|
||||
IFS="," read -r -a supportedVer <<<"${versions_part}"
|
||||
for version in "${supportedVer[@]}"
|
||||
do
|
||||
if [[ "${detected_version}" =~ $version ]]; then
|
||||
valid_version=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
local finalmsg
|
||||
if [ "$valid_os" = true ]; then
|
||||
log_write "${TICK} Distro: ${COL_GREEN}${detected_os^}${COL_NC}"
|
||||
|
||||
if [ "$valid_version" = true ]; then
|
||||
log_write "${TICK} Version: ${COL_GREEN}${detected_version}${COL_NC}"
|
||||
finalmsg="${TICK} ${COL_GREEN}Distro and version supported${COL_NC}"
|
||||
else
|
||||
log_write "${CROSS} Version: ${COL_RED}${detected_version}${COL_NC}"
|
||||
finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported ${COL_NC}(${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}"
|
||||
fi
|
||||
else
|
||||
log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}"
|
||||
finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro ${COL_NC}(${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}"
|
||||
fi
|
||||
|
||||
# Print dig response and the final check result
|
||||
log_write "${TICK} dig return code: ${COL_GREEN}${digReturnCode}${COL_NC}"
|
||||
log_write "${INFO} dig response: ${response}"
|
||||
log_write "${finalmsg}"
|
||||
fi
|
||||
}
|
||||
|
||||
diagnose_operating_system() {
|
||||
# error message in a variable so we can easily modify it later (or reuse it)
|
||||
local error_msg="Distribution unknown -- most likely you are on an unsupported platform and may run into issues."
|
||||
local detected_os
|
||||
local detected_version
|
||||
|
||||
# Display the current test that is running
|
||||
echo_current_diagnostic "Operating system"
|
||||
|
||||
@@ -380,8 +310,13 @@ diagnose_operating_system() {
|
||||
|
||||
# If there is a /etc/*release file, it's probably a supported operating system, so we can
|
||||
if ls /etc/*release 1> /dev/null 2>&1; then
|
||||
# display the attributes to the user from the function made earlier
|
||||
os_check
|
||||
# display the attributes to the user
|
||||
|
||||
detected_os=$(grep "\bID\b" /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
detected_version=$(grep VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
|
||||
log_write "${INFO} Distro: ${detected_os^}"
|
||||
log_write "${INFO} Version: ${detected_version}"
|
||||
else
|
||||
# If it doesn't exist, it's not a system we currently support and link to FAQ
|
||||
log_write "${CROSS} ${COL_RED}${error_msg}${COL_NC} (${FAQ_HARDWARE_REQUIREMENTS})"
|
||||
@@ -432,7 +367,7 @@ check_firewalld() {
|
||||
# test common required service ports
|
||||
local firewalld_enabled_services
|
||||
firewalld_enabled_services=$(firewall-cmd --list-services)
|
||||
local firewalld_expected_services=("http" "dns" "dhcp" "dhcpv6")
|
||||
local firewalld_expected_services=("http" "https" "dns" "dhcp" "dhcpv6" "ntp")
|
||||
for i in "${firewalld_expected_services[@]}"; do
|
||||
if [[ "${firewalld_enabled_services}" =~ ${i} ]]; then
|
||||
log_write "${TICK} ${COL_GREEN} Allow Service: ${i}${COL_NC}";
|
||||
@@ -453,14 +388,6 @@ check_firewalld() {
|
||||
else
|
||||
log_write "${CROSS} ${COL_RED} Local Interface Not Detected${COL_NC} (${FAQ_HARDWARE_REQUIREMENTS_FIREWALLD})"
|
||||
fi
|
||||
# check FTL custom zone port: 4711
|
||||
local firewalld_ftl_zone_ports
|
||||
firewalld_ftl_zone_ports=$(firewall-cmd --zone=ftl --list-ports)
|
||||
if [[ "${firewalld_ftl_zone_ports}" =~ "4711/tcp" ]]; then
|
||||
log_write "${TICK} ${COL_GREEN} FTL Port 4711/tcp Detected${COL_NC}";
|
||||
else
|
||||
log_write "${CROSS} ${COL_RED} FTL Port 4711/tcp Not Detected${COL_NC} (${FAQ_HARDWARE_REQUIREMENTS_FIREWALLD})"
|
||||
fi
|
||||
else
|
||||
log_write "${CROSS} ${COL_RED}FTL Custom Zone Not Detected${COL_NC} (${FAQ_HARDWARE_REQUIREMENTS_FIREWALLD})"
|
||||
fi
|
||||
@@ -479,7 +406,9 @@ run_and_print_command() {
|
||||
local output
|
||||
output=$(${cmd} 2>&1)
|
||||
# If the command was successful,
|
||||
if [[ $? -eq 0 ]]; then
|
||||
local return_code
|
||||
return_code=$?
|
||||
if [[ "${return_code}" -eq 0 ]]; then
|
||||
# show the output
|
||||
log_write "${output}"
|
||||
else
|
||||
@@ -489,13 +418,25 @@ run_and_print_command() {
|
||||
}
|
||||
|
||||
hardware_check() {
|
||||
# Note: the checks are skipped if Pi-hole is running in a docker container
|
||||
|
||||
local skip_msg="${INFO} Not enough permissions inside Docker container ${COL_YELLOW}(skipped)${COL_NC}"
|
||||
|
||||
echo_current_diagnostic "System hardware configuration"
|
||||
# Store the output of the command in a variable
|
||||
run_and_print_command "lshw -short"
|
||||
if [ -n "${DOCKER_VERSION}" ]; then
|
||||
log_write "${skip_msg}"
|
||||
else
|
||||
# Store the output of the command in a variable
|
||||
run_and_print_command "lshw -short"
|
||||
fi
|
||||
|
||||
echo_current_diagnostic "Processor details"
|
||||
# Store the output of the command in a variable
|
||||
run_and_print_command "lscpu"
|
||||
if [ -n "${DOCKER_VERSION}" ]; then
|
||||
log_write "${skip_msg}"
|
||||
else
|
||||
# Store the output of the command in a variable
|
||||
run_and_print_command "lscpu"
|
||||
fi
|
||||
}
|
||||
|
||||
disk_usage() {
|
||||
@@ -548,16 +489,25 @@ ping_gateway() {
|
||||
ping_ipv4_or_ipv6 "${protocol}"
|
||||
# Check if we are using IPv4 or IPv6
|
||||
# Find the default gateways using IPv4 or IPv6
|
||||
local gateway gateway_addr gateway_iface
|
||||
local gateway gateway_addr gateway_iface default_route
|
||||
|
||||
log_write "${INFO} Default IPv${protocol} gateway(s):"
|
||||
|
||||
while IFS= read -r gateway; do
|
||||
log_write " $(cut -d ' ' -f 3 <<< "${gateway}")%$(cut -d ' ' -f 5 <<< "${gateway}")"
|
||||
done < <(ip -"${protocol}" route | grep default)
|
||||
while IFS= read -r default_route; do
|
||||
gateway_addr=$(jq -r '.gateway' <<< "${default_route}")
|
||||
gateway_iface=$(jq -r '.dev' <<< "${default_route}")
|
||||
log_write " ${gateway_addr}%${gateway_iface}"
|
||||
done < <(ip -j -"${protocol}" route | jq -c '.[] | select(.dst == "default")')
|
||||
|
||||
# Find the first default route
|
||||
default_route=$(ip -j -"${protocol}" route show default)
|
||||
if echo "$default_route" | grep 'gateway' | grep -q 'dev'; then
|
||||
gateway_addr=$(echo "$default_route" | jq -r -c '.[0].gateway')
|
||||
gateway_iface=$(echo "$default_route" | jq -r -c '.[0].dev')
|
||||
else
|
||||
log_write " Unable to determine gateway address for IPv${protocol}"
|
||||
fi
|
||||
|
||||
gateway_addr=$(ip -"${protocol}" route | grep default | cut -d ' ' -f 3 | head -n 1)
|
||||
gateway_iface=$(ip -"${protocol}" route | grep default | cut -d ' ' -f 5 | head -n 1)
|
||||
# If there was at least one gateway
|
||||
if [ -n "${gateway_addr}" ]; then
|
||||
# Append the interface to the gateway address if it is a link-local address
|
||||
@@ -808,26 +758,24 @@ dig_at() {
|
||||
process_status(){
|
||||
# Check to make sure Pi-hole's services are running and active
|
||||
echo_current_diagnostic "Pi-hole processes"
|
||||
|
||||
# Local iterator
|
||||
local i
|
||||
|
||||
# For each process,
|
||||
for i in "${PIHOLE_PROCESSES[@]}"; do
|
||||
local status_of_process
|
||||
|
||||
# If systemd
|
||||
if command -v systemctl &> /dev/null; then
|
||||
# get its status via systemctl
|
||||
local status_of_process
|
||||
status_of_process=$(systemctl is-active "${i}")
|
||||
else
|
||||
# Otherwise, use the service command and mock the output of `systemctl is-active`
|
||||
local status_of_process
|
||||
|
||||
# If DOCKER_VERSION is set, the output is slightly different (s6 init system on Docker)
|
||||
# If it is a docker container, there is no systemctl or service. Do nothing.
|
||||
if [ -n "${DOCKER_VERSION}" ]; then
|
||||
if service "${i}" status | grep -E '^up' &> /dev/null; then
|
||||
status_of_process="active"
|
||||
else
|
||||
status_of_process="inactive"
|
||||
fi
|
||||
:
|
||||
else
|
||||
# non-Docker system
|
||||
if service "${i}" status | grep -E 'is\srunning' &> /dev/null; then
|
||||
@@ -837,8 +785,12 @@ process_status(){
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# and print it out to the user
|
||||
if [[ "${status_of_process}" == "active" ]]; then
|
||||
if [ -n "${DOCKER_VERSION}" ]; then
|
||||
# If it's a Docker container, the test was skipped
|
||||
log_write "${INFO} systemctl/service not installed inside docker container ${COL_YELLOW}(skipped)${COL_NC}"
|
||||
elif [[ "${status_of_process}" == "active" ]]; then
|
||||
# If it's active, show it in green
|
||||
log_write "${TICK} ${COL_GREEN}${i}${COL_NC} daemon is ${COL_GREEN}${status_of_process}${COL_NC}"
|
||||
else
|
||||
@@ -855,6 +807,8 @@ ftl_full_status(){
|
||||
if command -v systemctl &> /dev/null; then
|
||||
FTL_status=$(systemctl status --full --no-pager pihole-FTL.service)
|
||||
log_write " ${FTL_status}"
|
||||
elif [ -n "${DOCKER_VERSION}" ]; then
|
||||
log_write "${INFO} systemctl/service not installed inside docker container ${COL_YELLOW}(skipped)${COL_NC}"
|
||||
else
|
||||
log_write "${INFO} systemctl: command not found"
|
||||
fi
|
||||
@@ -908,7 +862,6 @@ parse_file() {
|
||||
# Get the lines that are in the file(s) and store them in an array for parsing later
|
||||
local file_info
|
||||
if [[ -f "$filename" ]]; then
|
||||
#shellcheck disable=SC2016
|
||||
IFS=$'\r\n' command eval 'file_info=( $(cat "${filename}") )'
|
||||
else
|
||||
read -r -a file_info <<< "$filename"
|
||||
@@ -1112,7 +1065,7 @@ show_FTL_db_entries() {
|
||||
}
|
||||
|
||||
check_dhcp_servers() {
|
||||
echo_current_diagnostic "Discovering active DHCP servers (takes 10 seconds)"
|
||||
echo_current_diagnostic "Discovering active DHCP servers (takes 6 seconds)"
|
||||
|
||||
OLD_IFS="$IFS"
|
||||
IFS=$'\n'
|
||||
@@ -1196,7 +1149,7 @@ database_integrity_check(){
|
||||
local database="${1}"
|
||||
|
||||
log_write "${INFO} Checking integrity of ${database} ... (this can take several minutes)"
|
||||
result="$(pihole-FTL "${database}" "PRAGMA integrity_check" 2>&1 & spinner)"
|
||||
result="$(pihole-FTL sqlite3 -ni "${database}" "PRAGMA integrity_check" 2>&1 & spinner)"
|
||||
if [[ ${result} = "ok" ]]; then
|
||||
log_write "${TICK} Integrity of ${database} intact"
|
||||
|
||||
@@ -1317,19 +1270,16 @@ upload_to_tricorder() {
|
||||
curl_to_tricorder
|
||||
# If we're not running in automated mode,
|
||||
else
|
||||
# if not being called from the web interface
|
||||
if [[ ! "${WEBCALL}" ]]; then
|
||||
echo ""
|
||||
# give the user a choice of uploading it or not
|
||||
# Users can review the log file locally (or the output of the script since they are the same) and try to self-diagnose their problem
|
||||
read -r -p "[?] Would you like to upload the log? [y/N] " response
|
||||
case ${response} in
|
||||
# If they say yes, run our function for uploading the log
|
||||
[yY][eE][sS]|[yY]) curl_to_tricorder;;
|
||||
# If they choose no, just exit out of the script
|
||||
*) log_write " * Log will ${COL_GREEN}NOT${COL_NC} be uploaded to tricorder.\\n * A local copy of the debug log can be found at: ${COL_CYAN}${PIHOLE_DEBUG_LOG}${COL_NC}\\n";exit;
|
||||
esac
|
||||
fi
|
||||
echo ""
|
||||
# give the user a choice of uploading it or not
|
||||
# Users can review the log file locally (or the output of the script since they are the same) and try to self-diagnose their problem
|
||||
read -r -p "[?] Would you like to upload the log? [y/N] " response
|
||||
case ${response} in
|
||||
# If they say yes, run our function for uploading the log
|
||||
[yY][eE][sS]|[yY]) curl_to_tricorder;;
|
||||
# If they choose no, just exit out of the script
|
||||
*) log_write " * Log will ${COL_GREEN}NOT${COL_NC} be uploaded to tricorder.\\n * A local copy of the debug log can be found at: ${COL_CYAN}${PIHOLE_DEBUG_LOG}${COL_NC}\\n";exit;
|
||||
esac
|
||||
fi
|
||||
# Check if tricorder.pi-hole.net is reachable and provide token
|
||||
# along with some additional useful information
|
||||
@@ -1349,13 +1299,8 @@ upload_to_tricorder() {
|
||||
# If no token was generated
|
||||
else
|
||||
# Show an error and some help instructions
|
||||
# Skip this if being called from web interface and automatic mode was not chosen (users opt-out to upload)
|
||||
if [[ "${WEBCALL}" ]] && [[ ! "${AUTOMATED}" ]]; then
|
||||
:
|
||||
else
|
||||
log_write "${CROSS} ${COL_RED}There was an error uploading your debug log.${COL_NC}"
|
||||
log_write " * Please try again or contact the Pi-hole team for assistance."
|
||||
fi
|
||||
log_write "${CROSS} ${COL_RED}There was an error uploading your debug log.${COL_NC}"
|
||||
log_write " * Please try again or contact the Pi-hole team for assistance."
|
||||
fi
|
||||
# Finally, show where the log file is no matter the outcome of the function so users can look at it
|
||||
log_write " * A local copy of the debug log can be found at: ${COL_CYAN}${PIHOLE_DEBUG_LOG}${COL_NC}\\n"
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
colfile="/opt/pihole/COL_TABLE"
|
||||
# shellcheck source="./advanced/Scripts/COL_TABLE"
|
||||
source ${colfile}
|
||||
|
||||
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
source "${utilsfile}"
|
||||
|
||||
# In case we're running at the same time as a system logrotate, use a
|
||||
@@ -35,6 +37,46 @@ FTLFILE=$(getFTLConfigValue "files.log.ftl")
|
||||
if [ -z "$FTLFILE" ]; then
|
||||
FTLFILE="/var/log/pihole/FTL.log"
|
||||
fi
|
||||
WEBFILE=$(getFTLConfigValue "files.log.webserver")
|
||||
if [ -z "$WEBFILE" ]; then
|
||||
WEBFILE="/var/log/pihole/webserver.log"
|
||||
fi
|
||||
|
||||
# Helper function to handle log rotation for a single file
|
||||
rotate_log() {
|
||||
# This function copies x.log over to x.log.1
|
||||
# and then empties x.log
|
||||
# Note that moving the file is not an option, as
|
||||
# dnsmasq would happily continue writing into the
|
||||
# moved file (it will have the same file handler)
|
||||
local logfile="$1"
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Rotating ${logfile} ..."
|
||||
fi
|
||||
cp -p "${logfile}" "${logfile}.1"
|
||||
echo " " > "${logfile}"
|
||||
chmod 640 "${logfile}"
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -e "${OVER} ${TICK} Rotated ${logfile} ..."
|
||||
fi
|
||||
}
|
||||
|
||||
# Helper function to handle log flushing for a single file
|
||||
flush_log() {
|
||||
local logfile="$1"
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Flushing ${logfile} ..."
|
||||
fi
|
||||
echo " " > "${logfile}"
|
||||
chmod 640 "${logfile}"
|
||||
if [ -f "${logfile}.1" ]; then
|
||||
echo " " > "${logfile}.1"
|
||||
chmod 640 "${logfile}.1"
|
||||
fi
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -e "${OVER} ${TICK} Flushed ${logfile} ..."
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ "$*" == *"once"* ]]; then
|
||||
# Nightly logrotation
|
||||
@@ -46,62 +88,16 @@ if [[ "$*" == *"once"* ]]; then
|
||||
fi
|
||||
/usr/sbin/logrotate --force --state "${STATEFILE}" /etc/pihole/logrotate
|
||||
else
|
||||
# Copy pihole.log over to pihole.log.1
|
||||
# and empty out pihole.log
|
||||
# Note that moving the file is not an option, as
|
||||
# dnsmasq would happily continue writing into the
|
||||
# moved file (it will have the same file handler)
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Rotating ${LOGFILE} ..."
|
||||
fi
|
||||
cp -p "${LOGFILE}" "${LOGFILE}.1"
|
||||
echo " " > "${LOGFILE}"
|
||||
chmod 640 "${LOGFILE}"
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -e "${OVER} ${TICK} Rotated ${LOGFILE} ..."
|
||||
fi
|
||||
# Copy FTL.log over to FTL.log.1
|
||||
# and empty out FTL.log
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Rotating ${FTLFILE} ..."
|
||||
fi
|
||||
cp -p "${FTLFILE}" "${FTLFILE}.1"
|
||||
echo " " > "${FTLFILE}"
|
||||
chmod 640 "${FTLFILE}"
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -e "${OVER} ${TICK} Rotated ${FTLFILE} ..."
|
||||
fi
|
||||
# Handle rotation for each log file
|
||||
rotate_log "${LOGFILE}"
|
||||
rotate_log "${FTLFILE}"
|
||||
rotate_log "${WEBFILE}"
|
||||
fi
|
||||
else
|
||||
# Manual flushing
|
||||
|
||||
# Flush both pihole.log and pihole.log.1 (if existing)
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Flushing ${LOGFILE} ..."
|
||||
fi
|
||||
echo " " > "${LOGFILE}"
|
||||
chmod 640 "${LOGFILE}"
|
||||
if [ -f "${LOGFILE}.1" ]; then
|
||||
echo " " > "${LOGFILE}.1"
|
||||
chmod 640 "${LOGFILE}.1"
|
||||
fi
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -e "${OVER} ${TICK} Flushed ${LOGFILE} ..."
|
||||
fi
|
||||
|
||||
# Flush both FTL.log and FTL.log.1 (if existing)
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Flushing ${FTLFILE} ..."
|
||||
fi
|
||||
echo " " > "${FTLFILE}"
|
||||
chmod 640 "${FTLFILE}"
|
||||
if [ -f "${FTLFILE}.1" ]; then
|
||||
echo " " > "${FTLFILE}.1"
|
||||
chmod 640 "${FTLFILE}.1"
|
||||
fi
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -e "${OVER} ${TICK} Flushed ${FTLFILE} ..."
|
||||
fi
|
||||
flush_log "${LOGFILE}"
|
||||
flush_log "${FTLFILE}"
|
||||
flush_log "${WEBFILE}"
|
||||
|
||||
if [[ "$*" != *"quiet"* ]]; then
|
||||
echo -ne " ${INFO} Flushing database, DNS resolution temporarily unavailable ..."
|
||||
|
||||
84
advanced/Scripts/piholeNetworkFlush.sh
Executable file
84
advanced/Scripts/piholeNetworkFlush.sh
Executable file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2019 Pi-hole, LLC (https://pi-hole.net)
|
||||
# Network-wide ad blocking via your own hardware.
|
||||
#
|
||||
# Network table flush
|
||||
#
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
coltable="/opt/pihole/COL_TABLE"
|
||||
if [[ -f ${coltable} ]]; then
|
||||
# shellcheck source="./advanced/Scripts/COL_TABLE"
|
||||
source ${coltable}
|
||||
fi
|
||||
|
||||
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source=./advanced/Scripts/utils.sh
|
||||
source "${utilsfile}"
|
||||
|
||||
# Source api functions
|
||||
# shellcheck source="./advanced/Scripts/api.sh"
|
||||
. "${PI_HOLE_SCRIPT_DIR}/api.sh"
|
||||
|
||||
flushNetwork(){
|
||||
local output
|
||||
|
||||
echo -ne " ${INFO} Flushing network table ..."
|
||||
|
||||
local data status error
|
||||
# Authenticate with FTL
|
||||
LoginAPI
|
||||
|
||||
# send query again
|
||||
data=$(PostFTLData "action/flush/network" "" "status")
|
||||
|
||||
# Separate the status from the data
|
||||
status=$(printf %s "${data#"${data%???}"}")
|
||||
data=$(printf %s "${data%???}")
|
||||
|
||||
# If there is an .error object in the returned data, display it
|
||||
local error
|
||||
error=$(jq --compact-output <<< "${data}" '.error')
|
||||
if [[ $error != "null" && $error != "" ]]; then
|
||||
echo -e "${OVER} ${CROSS} Failed to flush the network table:"
|
||||
echo -e " $(jq <<< "${data}" '.error')"
|
||||
LogoutAPI
|
||||
exit 1
|
||||
elif [[ "${status}" == "200" ]]; then
|
||||
echo -e "${OVER} ${TICK} Flushed network table"
|
||||
fi
|
||||
|
||||
# Delete session
|
||||
LogoutAPI
|
||||
}
|
||||
|
||||
flushArp(){
|
||||
# Flush ARP cache of the host
|
||||
if ! output=$(ip -s -s neigh flush all 2>&1); then
|
||||
echo -e "${OVER} ${CROSS} Failed to flush ARP cache"
|
||||
echo " Output: ${output}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Process all options (if present)
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
"--arp" ) doARP=true ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
flushNetwork
|
||||
|
||||
if [[ "${doARP}" == true ]]; then
|
||||
echo -ne " ${INFO} Flushing ARP cache"
|
||||
if flushArp; then
|
||||
echo -e "${OVER} ${TICK} Flushed ARP cache"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
# shellcheck disable=SC1090
|
||||
|
||||
# Ignore warning about `local` being undefinded in POSIX
|
||||
# shellcheck disable=SC3043
|
||||
# https://github.com/koalaman/shellcheck/wiki/SC3043#exceptions
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2023 Pi-hole, LLC (https://pi-hole.net)
|
||||
@@ -22,9 +17,11 @@ domain=""
|
||||
|
||||
# Source color table
|
||||
colfile="/opt/pihole/COL_TABLE"
|
||||
# shellcheck source="./advanced/Scripts/COL_TABLE"
|
||||
. "${colfile}"
|
||||
|
||||
# Source api functions
|
||||
# shellcheck source="./advanced/Scripts/api.sh"
|
||||
. "${PI_HOLE_INSTALL_DIR}/api.sh"
|
||||
|
||||
Help() {
|
||||
@@ -40,19 +37,16 @@ Options:
|
||||
}
|
||||
|
||||
GenerateOutput() {
|
||||
local data gravity_data lists_data num_gravity num_lists search_type_str
|
||||
local gravity_data_csv lists_data_csv line current_domain url type color
|
||||
local counts data num_gravity num_lists search_type_str
|
||||
local gravity_data_csv lists_data_csv line url type color
|
||||
data="${1}"
|
||||
|
||||
# construct a new json for the list results where each object contains the domain and the related type
|
||||
lists_data=$(printf %s "${data}" | jq '.search.domains | [.[] | {domain: .domain, type: .type}]')
|
||||
|
||||
# construct a new json for the gravity results where each object contains the adlist URL and the related domains
|
||||
gravity_data=$(printf %s "${data}" | jq '.search.gravity | group_by(.address,.type) | map({ address: (.[0].address), type: (.[0].type), domains: [.[] | .domain] })')
|
||||
|
||||
# number of objects in each json
|
||||
num_gravity=$(printf %s "${gravity_data}" | jq length)
|
||||
num_lists=$(printf %s "${lists_data}" | jq length)
|
||||
# Get count of list and gravity matches
|
||||
# Use JQ to count number of entries in lists and gravity
|
||||
# (output is number of list matches then number of gravity matches)
|
||||
counts=$(printf %s "${data}" | jq --raw-output '(.search.domains | length), (.search.gravity | group_by(.address,.type) | length)')
|
||||
num_lists=$(echo "$counts" | sed -n '1p')
|
||||
num_gravity=$(echo "$counts" | sed -n '2p')
|
||||
|
||||
if [ "${partial}" = true ]; then
|
||||
search_type_str="partially"
|
||||
@@ -65,7 +59,7 @@ GenerateOutput() {
|
||||
if [ "${num_lists}" -gt 0 ]; then
|
||||
# Convert the data to a csv, each line is a "domain,type" string
|
||||
# not using jq's @csv here as it quotes each value individually
|
||||
lists_data_csv=$(printf %s "${lists_data}" | jq --raw-output '.[] | [.domain, .type] | join(",")')
|
||||
lists_data_csv=$(printf %s "${data}" | jq --raw-output '.search.domains | map([.domain, .type] | join(",")) | join("\n")')
|
||||
|
||||
# Generate output for each csv line, separating line in a domain and type substring at the ','
|
||||
echo "${lists_data_csv}" | while read -r line; do
|
||||
@@ -74,11 +68,11 @@ GenerateOutput() {
|
||||
fi
|
||||
|
||||
# Results from gravity
|
||||
printf "%s\n\n" "Found ${num_gravity} adlists ${search_type_str} matching '${COL_BLUE}${domain}${COL_NC}'."
|
||||
printf "%s\n\n" "Found ${num_gravity} lists ${search_type_str} matching '${COL_BLUE}${domain}${COL_NC}'."
|
||||
if [ "${num_gravity}" -gt 0 ]; then
|
||||
# Convert the data to a csv, each line is a "URL,domain,domain,...." string
|
||||
# Convert the data to a csv, each line is a "URL,type,domain,domain,...." string
|
||||
# not using jq's @csv here as it quotes each value individually
|
||||
gravity_data_csv=$(printf %s "${gravity_data}" | jq --raw-output '.[] | [.address, .type, .domains[]] | join(",")')
|
||||
gravity_data_csv=$(printf %s "${data}" | jq --raw-output '.search.gravity | group_by(.address,.type) | map([.[0].address, .[0].type, (.[] | .domain)] | join(",")) | join("\n")')
|
||||
|
||||
# Generate line-by-line output for each csv line
|
||||
echo "${gravity_data_csv}" | while read -r line; do
|
||||
@@ -100,15 +94,8 @@ GenerateOutput() {
|
||||
|
||||
# cut off type, leaving "domain,domain,...."
|
||||
line=${line#*,}
|
||||
# print each domain and remove it from the string until nothing is left
|
||||
while [ ${#line} -gt 0 ]; do
|
||||
current_domain=${line%%,*}
|
||||
printf ' - %s\n' "${COL_GREEN}${current_domain}${COL_NC}"
|
||||
# we need to remove the current_domain and the comma in two steps because
|
||||
# the last domain won't have a trailing comma and the while loop wouldn't exit
|
||||
line=${line#"${current_domain}"}
|
||||
line=${line#,}
|
||||
done
|
||||
# Replace commas with newlines and format output
|
||||
echo "${line}" | sed 's/,/\n/g' | sed "s/^/ - ${COL_GREEN}/" | sed "s/$/${COL_NC}/"
|
||||
printf "\n\n"
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -12,26 +12,31 @@
|
||||
|
||||
# Variables
|
||||
readonly ADMIN_INTERFACE_GIT_URL="https://github.com/pi-hole/web.git"
|
||||
readonly ADMIN_INTERFACE_DIR="/var/www/html/admin"
|
||||
readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git"
|
||||
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
SKIP_INSTALL=true
|
||||
|
||||
# when --check-only is passed to this script, it will not perform the actual update
|
||||
CHECK_ONLY=false
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
# shellcheck source="./automated install/basic-install.sh"
|
||||
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
||||
# shellcheck disable=SC1091
|
||||
# shellcheck source=./advanced/Scripts/COL_TABLE
|
||||
source "/opt/pihole/COL_TABLE"
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
source "${PI_HOLE_INSTALL_DIR}/utils.sh"
|
||||
|
||||
# is_repo() sourced from basic-install.sh
|
||||
# make_repo() sourced from basic-install.sh
|
||||
# update_repo() source from basic-install.sh
|
||||
# getGitFiles() sourced from basic-install.sh
|
||||
# FTLcheckUpdate() sourced from basic-install.sh
|
||||
# getFTLConfigValue() sourced from utils.sh
|
||||
|
||||
# Honour configured paths for the web application.
|
||||
ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome")
|
||||
readonly ADMIN_INTERFACE_DIR
|
||||
|
||||
GitCheckUpdateAvail() {
|
||||
local directory
|
||||
@@ -42,7 +47,7 @@ GitCheckUpdateAvail() {
|
||||
|
||||
# Fetch latest changes in this repo
|
||||
if ! git fetch --quiet origin ; then
|
||||
echo -e "\\n ${COL_LIGHT_RED}Error: Unable to update local repository. Contact Pi-hole Support.${COL_NC}"
|
||||
echo -e "\\n ${COL_RED}Error: Unable to update local repository. Contact Pi-hole Support.${COL_NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -71,13 +76,13 @@ GitCheckUpdateAvail() {
|
||||
|
||||
|
||||
if [[ "${#LOCAL}" == 0 ]]; then
|
||||
echo -e "\\n ${COL_LIGHT_RED}Error: Local revision could not be obtained, please contact Pi-hole Support"
|
||||
echo -e "\\n ${COL_RED}Error: Local revision could not be obtained, please contact Pi-hole Support"
|
||||
echo -e " Additional debugging output:${COL_NC}"
|
||||
git status
|
||||
exit 1
|
||||
fi
|
||||
if [[ "${#REMOTE}" == 0 ]]; then
|
||||
echo -e "\\n ${COL_LIGHT_RED}Error: Remote revision could not be obtained, please contact Pi-hole Support"
|
||||
echo -e "\\n ${COL_RED}Error: Remote revision could not be obtained, please contact Pi-hole Support"
|
||||
echo -e " Additional debugging output:${COL_NC}"
|
||||
git status
|
||||
exit 1
|
||||
@@ -98,7 +103,7 @@ GitCheckUpdateAvail() {
|
||||
}
|
||||
|
||||
main() {
|
||||
local basicError="\\n ${COL_LIGHT_RED}Unable to complete update, please contact Pi-hole Support${COL_NC}"
|
||||
local basicError="\\n ${COL_RED}Unable to complete update, please contact Pi-hole Support${COL_NC}"
|
||||
local core_update
|
||||
local web_update
|
||||
local FTL_update
|
||||
@@ -107,6 +112,7 @@ main() {
|
||||
web_update=false
|
||||
FTL_update=false
|
||||
|
||||
|
||||
# Install packages used by this installation script (necessary if users have removed e.g. git from their systems)
|
||||
package_manager_detect
|
||||
build_dependency_package
|
||||
@@ -114,7 +120,7 @@ main() {
|
||||
|
||||
# This is unlikely
|
||||
if ! is_repo "${PI_HOLE_FILES_DIR}" ; then
|
||||
echo -e "\\n ${COL_LIGHT_RED}Error: Core Pi-hole repo is missing from system!"
|
||||
echo -e "\\n ${COL_RED}Error: Core Pi-hole repo is missing from system!"
|
||||
echo -e " Please re-run install script from https://pi-hole.net${COL_NC}"
|
||||
exit 1;
|
||||
fi
|
||||
@@ -126,11 +132,11 @@ main() {
|
||||
echo -e " ${INFO} Pi-hole Core:\\t${COL_YELLOW}update available${COL_NC}"
|
||||
else
|
||||
core_update=false
|
||||
echo -e " ${INFO} Pi-hole Core:\\t${COL_LIGHT_GREEN}up to date${COL_NC}"
|
||||
echo -e " ${INFO} Pi-hole Core:\\t${COL_GREEN}up to date${COL_NC}"
|
||||
fi
|
||||
|
||||
if ! is_repo "${ADMIN_INTERFACE_DIR}" ; then
|
||||
echo -e "\\n ${COL_LIGHT_RED}Error: Web Admin repo is missing from system!"
|
||||
echo -e "\\n ${COL_RED}Error: Web Admin repo is missing from system!"
|
||||
echo -e " Please re-run install script from https://pi-hole.net${COL_NC}"
|
||||
exit 1;
|
||||
fi
|
||||
@@ -140,7 +146,7 @@ main() {
|
||||
echo -e " ${INFO} Web Interface:\\t${COL_YELLOW}update available${COL_NC}"
|
||||
else
|
||||
web_update=false
|
||||
echo -e " ${INFO} Web Interface:\\t${COL_LIGHT_GREEN}up to date${COL_NC}"
|
||||
echo -e " ${INFO} Web Interface:\\t${COL_GREEN}up to date${COL_NC}"
|
||||
fi
|
||||
|
||||
local funcOutput
|
||||
@@ -154,17 +160,18 @@ main() {
|
||||
else
|
||||
case $? in
|
||||
1)
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_LIGHT_GREEN}up to date${COL_NC}"
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_GREEN}up to date${COL_NC}"
|
||||
;;
|
||||
2)
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_LIGHT_RED}Branch is not available.${COL_NC}\\n\\t\\t\\tUse ${COL_LIGHT_GREEN}pihole checkout ftl [branchname]${COL_NC} to switch to a valid branch."
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_RED}Branch is not available.${COL_NC}\\n\\t\\t\\tUse ${COL_GREEN}pihole checkout ftl [branchname]${COL_NC} to switch to a valid branch."
|
||||
exit 1
|
||||
;;
|
||||
3)
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_LIGHT_RED}Something has gone wrong, cannot reach download server${COL_NC}"
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_RED}Something has gone wrong, cannot reach download server${COL_NC}"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_LIGHT_RED}Something has gone wrong, contact support${COL_NC}"
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_RED}Something has gone wrong, contact support${COL_NC}"
|
||||
exit 1
|
||||
esac
|
||||
FTL_update=false
|
||||
@@ -181,7 +188,7 @@ main() {
|
||||
if [[ ! "${ftlBranch}" == "master" && ! "${ftlBranch}" == "development" ]]; then
|
||||
# Notify user that they are on a custom branch which might mean they they are lost
|
||||
# behind if a branch was merged to development and got abandoned
|
||||
printf " %b %bWarning:%b You are using FTL from a custom branch (%s) and might be missing future releases.\\n" "${INFO}" "${COL_LIGHT_RED}" "${COL_NC}" "${ftlBranch}"
|
||||
printf " %b %bWarning:%b You are using FTL from a custom branch (%s) and might be missing future releases.\\n" "${INFO}" "${COL_RED}" "${COL_NC}" "${ftlBranch}"
|
||||
fi
|
||||
|
||||
if [[ "${core_update}" == false && "${web_update}" == false && "${FTL_update}" == false ]]; then
|
||||
@@ -206,7 +213,7 @@ main() {
|
||||
echo ""
|
||||
echo -e " ${INFO} Pi-hole Web Admin files out of date, updating local repo."
|
||||
getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}"
|
||||
echo -e " ${INFO} If you had made any changes in '/var/www/html/admin/', they have been stashed using 'git stash'"
|
||||
echo -e " ${INFO} If you had made any changes in '${ADMIN_INTERFACE_DIR}', they have been stashed using 'git stash'"
|
||||
fi
|
||||
|
||||
if [[ "${FTL_update}" == true ]]; then
|
||||
@@ -215,7 +222,7 @@ main() {
|
||||
fi
|
||||
|
||||
if [[ "${FTL_update}" == true || "${core_update}" == true ]]; then
|
||||
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || \
|
||||
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --repair --unattended || \
|
||||
echo -e "${basicError}" && exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -39,9 +39,12 @@ function get_remote_hash() {
|
||||
}
|
||||
|
||||
# Source the utils file for addOrEditKeyValPair()
|
||||
# shellcheck disable=SC1091
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
. /opt/pihole/utils.sh
|
||||
|
||||
ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome")
|
||||
readonly ADMIN_INTERFACE_DIR
|
||||
|
||||
# Remove the below three legacy files if they exist
|
||||
rm -f "/etc/pihole/GitHubVersions"
|
||||
rm -f "/etc/pihole/localbranches"
|
||||
@@ -85,13 +88,13 @@ addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_HASH" "${GITHUB_CORE_HASH}"
|
||||
|
||||
# get Web versions
|
||||
|
||||
WEB_VERSION="$(get_local_version /var/www/html/admin)"
|
||||
WEB_VERSION="$(get_local_version "${ADMIN_INTERFACE_DIR}")"
|
||||
addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}"
|
||||
|
||||
WEB_BRANCH="$(get_local_branch /var/www/html/admin)"
|
||||
WEB_BRANCH="$(get_local_branch "${ADMIN_INTERFACE_DIR}")"
|
||||
addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}"
|
||||
|
||||
WEB_HASH="$(get_local_hash /var/www/html/admin)"
|
||||
WEB_HASH="$(get_local_hash "${ADMIN_INTERFACE_DIR}")"
|
||||
addOrEditKeyValPair "${VERSION_FILE}" "WEB_HASH" "${WEB_HASH}"
|
||||
|
||||
GITHUB_WEB_VERSION="$(get_remote_version web "${WEB_BRANCH}")"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
# shellcheck disable=SC3043 #https://github.com/koalaman/shellcheck/wiki/SC3043#exceptions
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||
@@ -74,7 +73,9 @@ getFTLPID() {
|
||||
# Example getFTLConfigValue dns.piholePTR
|
||||
#######################
|
||||
getFTLConfigValue(){
|
||||
pihole-FTL --config -q "${1}"
|
||||
# Pipe to cat to avoid pihole-FTL assuming this is an interactive command
|
||||
# returning colored output.
|
||||
pihole-FTL --config -q "${1}" | cat
|
||||
}
|
||||
|
||||
#######################
|
||||
@@ -87,9 +88,17 @@ getFTLConfigValue(){
|
||||
# setFTLConfigValue dns.upstreams '[ "8.8.8.8" , "8.8.4.4" ]'
|
||||
#######################
|
||||
setFTLConfigValue(){
|
||||
pihole-FTL --config "${1}" "${2}" >/dev/null
|
||||
if [[ $? -eq 5 ]]; then
|
||||
echo -e " ${CROSS} ${1} set by environment variable. Please unset it to use this function"
|
||||
exit 5
|
||||
fi
|
||||
local err
|
||||
{ pihole-FTL --config "${1}" "${2}" >/dev/null; err="$?"; } || true
|
||||
|
||||
case $err in
|
||||
0) ;;
|
||||
5)
|
||||
# FTL returns 5 if the value was set by an environment variable and is therefore read-only
|
||||
printf " %s %s set by environment variable. Please unset it to use this function\n" "${CROSS}" "${1}";
|
||||
exit 5;;
|
||||
*)
|
||||
printf " %s Failed to set %s. Try with sudo power\n" "${CROSS}" "${1}"
|
||||
exit 1
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -8,20 +8,16 @@
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
# Ignore warning about `local` being undefinded in POSIX
|
||||
# shellcheck disable=SC3043
|
||||
# https://github.com/koalaman/shellcheck/wiki/SC3043#exceptions
|
||||
|
||||
# Source the versions file poupulated by updatechecker.sh
|
||||
# Source the versions file populated by updatechecker.sh
|
||||
cachedVersions="/etc/pihole/versions"
|
||||
|
||||
if [ -f ${cachedVersions} ]; then
|
||||
# shellcheck disable=SC1090
|
||||
# shellcheck source=/dev/null
|
||||
. "$cachedVersions"
|
||||
else
|
||||
echo "Could not find /etc/pihole/versions. Running update now."
|
||||
pihole updatechecker
|
||||
# shellcheck disable=SC1090
|
||||
# shellcheck source=/dev/null
|
||||
. "$cachedVersions"
|
||||
fi
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ CREATE TABLE adlist
|
||||
|
||||
CREATE TABLE adlist_by_group
|
||||
(
|
||||
adlist_id INTEGER NOT NULL REFERENCES adlist (id),
|
||||
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
||||
adlist_id INTEGER NOT NULL REFERENCES adlist (id) ON DELETE CASCADE,
|
||||
group_id INTEGER NOT NULL REFERENCES "group" (id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (adlist_id, group_id)
|
||||
);
|
||||
|
||||
@@ -67,11 +67,16 @@ CREATE TABLE info
|
||||
);
|
||||
|
||||
INSERT INTO "info" VALUES('version','19');
|
||||
/* This is a flag to indicate if gravity was restored from a backup
|
||||
false = not restored,
|
||||
failed = restoration failed due to no backup
|
||||
other string = restoration successful with the string being the backup file used */
|
||||
INSERT INTO "info" VALUES('gravity_restored','false');
|
||||
|
||||
CREATE TABLE domainlist_by_group
|
||||
(
|
||||
domainlist_id INTEGER NOT NULL REFERENCES domainlist (id),
|
||||
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
||||
domainlist_id INTEGER NOT NULL REFERENCES domainlist (id) ON DELETE CASCADE,
|
||||
group_id INTEGER NOT NULL REFERENCES "group" (id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (domainlist_id, group_id)
|
||||
);
|
||||
|
||||
@@ -86,8 +91,8 @@ CREATE TABLE client
|
||||
|
||||
CREATE TABLE client_by_group
|
||||
(
|
||||
client_id INTEGER NOT NULL REFERENCES client (id),
|
||||
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
||||
client_id INTEGER NOT NULL REFERENCES client (id) ON DELETE CASCADE,
|
||||
group_id INTEGER NOT NULL REFERENCES "group" (id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (client_id, group_id)
|
||||
);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Source utils.sh for getFTLConfigValue()
|
||||
PI_HOLE_SCRIPT_DIR='/opt/pihole'
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck disable=SC1090
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
. "${utilsfile}"
|
||||
|
||||
# Get file paths
|
||||
|
||||
@@ -3,32 +3,32 @@
|
||||
# Source utils.sh for getFTLConfigValue()
|
||||
PI_HOLE_SCRIPT_DIR='/opt/pihole'
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck disable=SC1090
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
. "${utilsfile}"
|
||||
|
||||
# Get file paths
|
||||
FTL_PID_FILE="$(getFTLConfigValue files.pid)"
|
||||
|
||||
# Ensure that permissions are set so that pihole-FTL can edit all necessary files
|
||||
# shellcheck disable=SC2174
|
||||
mkdir -pm 0640 /var/log/pihole
|
||||
chown -R pihole:pihole /etc/pihole /var/log/pihole
|
||||
chmod -R 0640 /var/log/pihole
|
||||
chmod -R 0660 /etc/pihole
|
||||
mkdir -p /var/log/pihole
|
||||
chown -R pihole:pihole /etc/pihole/ /var/log/pihole/
|
||||
|
||||
# Logrotate config file need to be owned by root and must not be writable by group and others
|
||||
chown root:root /etc/pihole/logrotate
|
||||
chmod 0644 /etc/pihole/logrotate
|
||||
|
||||
# allow all users to enter the directories
|
||||
chmod 0755 /etc/pihole /var/log/pihole
|
||||
# allow all users read version file (and use pihole -v)
|
||||
chmod 0644 /etc/pihole/versions
|
||||
|
||||
# allow pihole to access subdirs in /etc/pihole (sets execution bit on dirs)
|
||||
# credits https://stackoverflow.com/a/11512211
|
||||
find /etc/pihole -type d -exec chmod 0755 {} \;
|
||||
find /etc/pihole/ /var/log/pihole/ -type d -exec chmod 0755 {} +
|
||||
# Set all files (except TLS-related ones) to u+rw g+r
|
||||
find /etc/pihole/ /var/log/pihole/ -type f ! \( -name '*.pem' -o -name '*.crt' \) -exec chmod 0640 {} +
|
||||
# Set TLS-related files to a more restrictive u+rw *only* (they may contain private keys)
|
||||
find /etc/pihole/ -type f \( -name '*.pem' -o -name '*.crt' \) -exec chmod 0600 {} +
|
||||
|
||||
# Logrotate config file need to be owned by root
|
||||
chown root:root /etc/pihole/logrotate
|
||||
|
||||
# Touch files to ensure they exist (create if non-existing, preserve if existing)
|
||||
[ -f "${FTL_PID_FILE}" ] || install -D -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}"
|
||||
[ -f /var/log/pihole/FTL.log ] || install -m 640 -o pihole -g pihole /dev/null /var/log/pihole/FTL.log
|
||||
[ -f /var/log/pihole/pihole.log ] || install -m 640 -o pihole -g pihole /dev/null /var/log/pihole/pihole.log
|
||||
[ -f /var/log/pihole/webserver.log ] || install -m 640 -o pihole -g pihole /dev/null /var/log/pihole/webserver.log
|
||||
[ -f /etc/pihole/dhcp.leases ] || install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# Source utils.sh for getFTLConfigValue(), getFTLPID()
|
||||
PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck disable=SC1090
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
. "${utilsfile}"
|
||||
|
||||
|
||||
@@ -57,13 +57,16 @@ start() {
|
||||
stop() {
|
||||
if is_running; then
|
||||
kill "${FTL_PID}"
|
||||
for i in 1 2 3 4 5; do
|
||||
# Give FTL 60 seconds to gracefully stop
|
||||
i=1
|
||||
while [ "${i}" -le 60 ]; do
|
||||
if ! is_running; then
|
||||
break
|
||||
fi
|
||||
|
||||
printf "."
|
||||
sleep 1
|
||||
i=$((i + 1))
|
||||
done
|
||||
echo
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ ExecReload=/bin/kill -HUP $MAINPID
|
||||
ExecStopPost=/opt/pihole/pihole-FTL-poststop.sh
|
||||
|
||||
# Use graceful shutdown with a reasonable timeout
|
||||
TimeoutStopSec=10s
|
||||
TimeoutStopSec=60s
|
||||
|
||||
# Make /usr, /boot, /etc and possibly some more folders read-only...
|
||||
ProtectSystem=full
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
_pihole() {
|
||||
local cur prev opts opts_checkout opts_debug opts_logging opts_query opts_update opts_version
|
||||
local cur prev opts opts_lists opts_checkout opts_debug opts_logging opts_query opts_update opts_networkflush
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
@@ -7,7 +7,7 @@ _pihole() {
|
||||
|
||||
case "${prev}" in
|
||||
"pihole")
|
||||
opts="allow allow-regex allow-wild deny checkout debug disable enable flush help logging query reconfigure regex reloaddns reloadlists status tail uninstall updateGravity updatePihole version wildcard arpflush api"
|
||||
opts="allow allow-regex allow-wild deny checkout debug disable enable flush help logging query repair regex reloaddns reloadlists setpassword status tail uninstall updateGravity updatePihole version wildcard networkflush api"
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
;;
|
||||
"allow"|"deny"|"wildcard"|"regex"|"allow-regex"|"allow-wild")
|
||||
@@ -34,9 +34,13 @@ _pihole() {
|
||||
opts_update="--check-only"
|
||||
COMPREPLY=( $(compgen -W "${opts_update}" -- ${cur}) )
|
||||
;;
|
||||
"core"|"admin"|"ftl")
|
||||
"networkflush")
|
||||
opts_networkflush="--arp"
|
||||
COMPREPLY=( $(compgen -W "${opts_networkflush}" -- ${cur}) )
|
||||
;;
|
||||
"core"|"web"|"ftl")
|
||||
if [[ "$prev2" == "checkout" ]]; then
|
||||
opts_checkout="master dev"
|
||||
opts_checkout="master development"
|
||||
COMPREPLY=( $(compgen -W "${opts_checkout}" -- ${cur}) )
|
||||
else
|
||||
return 1
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,13 +8,19 @@
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
# shellcheck source="./advanced/Scripts/COL_TABLE"
|
||||
source "/opt/pihole/COL_TABLE"
|
||||
# shellcheck source="./advanced/Scripts/utils.sh"
|
||||
source "/opt/pihole/utils.sh"
|
||||
|
||||
ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome")
|
||||
readonly ADMIN_INTERFACE_DIR
|
||||
|
||||
while true; do
|
||||
read -rp " ${QST} Are you sure you would like to remove ${COL_WHITE}Pi-hole${COL_NC}? [y/N] " answer
|
||||
read -rp " ${QST} Are you sure you would like to remove ${COL_BOLD}Pi-hole${COL_NC}? [y/N] " answer
|
||||
case ${answer} in
|
||||
[Yy]* ) break;;
|
||||
* ) echo -e "${OVER} ${COL_LIGHT_GREEN}Uninstall has been canceled${COL_NC}"; exit 0;;
|
||||
* ) echo -e "${OVER} ${COL_GREEN}Uninstall has been canceled${COL_NC}"; exit 0;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -37,6 +43,7 @@ fi
|
||||
|
||||
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
||||
SKIP_INSTALL="true"
|
||||
# shellcheck source="./automated install/basic-install.sh"
|
||||
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
||||
|
||||
# package_manager_detect() sourced from basic-install.sh
|
||||
@@ -53,17 +60,9 @@ removeMetaPackage() {
|
||||
}
|
||||
|
||||
removePiholeFiles() {
|
||||
# Only web directories/files that are created by Pi-hole should be removed
|
||||
# Remove the web interface of Pi-hole
|
||||
echo -ne " ${INFO} Removing Web Interface..."
|
||||
${SUDO} rm -rf /var/www/html/admin &> /dev/null
|
||||
|
||||
|
||||
# If the web directory is empty after removing these files, then the parent html directory can be removed.
|
||||
if [ -d "/var/www/html" ]; then
|
||||
if [[ ! "$(ls -A /var/www/html)" ]]; then
|
||||
${SUDO} rm -rf /var/www/html &> /dev/null
|
||||
fi
|
||||
fi
|
||||
${SUDO} rm -rf "${ADMIN_INTERFACE_DIR}" &> /dev/null
|
||||
echo -e "${OVER} ${TICK} Removed Web Interface"
|
||||
|
||||
# Attempt to preserve backwards compatibility with older versions
|
||||
@@ -94,8 +93,9 @@ removePiholeFiles() {
|
||||
echo -e " ${TICK} Removed config files"
|
||||
|
||||
# Restore Resolved
|
||||
if [[ -e /etc/systemd/resolved.conf.orig ]]; then
|
||||
${SUDO} cp -p /etc/systemd/resolved.conf.orig /etc/systemd/resolved.conf
|
||||
if [[ -e /etc/systemd/resolved.conf.orig ]] || [[ -e /etc/systemd/resolved.conf.d/90-pi-hole-disable-stub-listener.conf ]]; then
|
||||
${SUDO} cp -p /etc/systemd/resolved.conf.orig /etc/systemd/resolved.conf &> /dev/null || true
|
||||
${SUDO} rm -f /etc/systemd/resolved.conf.d/90-pi-hole-disable-stub-listener.conf
|
||||
systemctl reload-or-restart systemd-resolved
|
||||
fi
|
||||
|
||||
@@ -150,11 +150,11 @@ removePiholeFiles() {
|
||||
|
||||
echo -e "\\n We're sorry to see you go, but thanks for checking out Pi-hole!
|
||||
If you need help, reach out to us on GitHub, Discourse, Reddit or Twitter
|
||||
Reinstall at any time: ${COL_WHITE}curl -sSL https://install.pi-hole.net | bash${COL_NC}
|
||||
Reinstall at any time: ${COL_BOLD}curl -sSL https://install.pi-hole.net | bash${COL_NC}
|
||||
|
||||
${COL_LIGHT_RED}Please reset the DNS on your router/clients to restore internet connectivity${COL_NC}
|
||||
${COL_RED}Please reset the DNS on your router/clients to restore internet connectivity${COL_NC}
|
||||
${INFO} Pi-hole's meta package has been removed, use the 'autoremove' function from your package manager to remove unused dependencies${COL_NC}
|
||||
${COL_LIGHT_GREEN}Uninstallation Complete! ${COL_NC}"
|
||||
${COL_GREEN}Uninstallation Complete! ${COL_NC}"
|
||||
}
|
||||
|
||||
######### SCRIPT ###########
|
||||
|
||||
415
gravity.sh
415
gravity.sh
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1090
|
||||
|
||||
# Pi-hole: A black hole for Internet advertisements
|
||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||
@@ -16,13 +15,13 @@ export LC_ALL=C
|
||||
PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
# Source utils.sh for GetFTLConfigValue
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck disable=SC1090
|
||||
# shellcheck source=./advanced/Scripts/utils.sh
|
||||
. "${utilsfile}"
|
||||
|
||||
coltable="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
||||
# shellcheck disable=SC1090
|
||||
# shellcheck source=./advanced/Scripts/COL_TABLE
|
||||
. "${coltable}"
|
||||
# shellcheck disable=SC1091
|
||||
# shellcheck source=./advanced/Scripts/database_migration/gravity-db.sh
|
||||
. "/etc/.pihole/advanced/Scripts/database_migration/gravity-db.sh"
|
||||
|
||||
basename="pihole"
|
||||
@@ -30,6 +29,9 @@ PIHOLE_COMMAND="/usr/local/bin/${basename}"
|
||||
|
||||
piholeDir="/etc/${basename}"
|
||||
|
||||
# Gravity aux files directory
|
||||
listsCacheDir="${piholeDir}/listsCache"
|
||||
|
||||
# Legacy (pre v5.0) list file locations
|
||||
whitelistFile="${piholeDir}/whitelist.txt"
|
||||
blacklistFile="${piholeDir}/blacklist.txt"
|
||||
@@ -44,20 +46,23 @@ gravityDBcopy="${piholeGitDir}/advanced/Templates/gravity_copy.sql"
|
||||
|
||||
domainsExtension="domains"
|
||||
curl_connect_timeout=10
|
||||
etag_support=false
|
||||
|
||||
# Check gravity temp directory
|
||||
if [ ! -d "${GRAVITY_TMPDIR}" ] || [ ! -w "${GRAVITY_TMPDIR}" ]; then
|
||||
echo -e " ${COL_LIGHT_RED}Gravity temporary directory does not exist or is not a writeable directory, falling back to /tmp. ${COL_NC}"
|
||||
echo -e " ${COL_RED}Gravity temporary directory does not exist or is not a writeable directory, falling back to /tmp. ${COL_NC}"
|
||||
GRAVITY_TMPDIR="/tmp"
|
||||
fi
|
||||
|
||||
# Set this only after sourcing pihole-FTL.conf as the gravity database path may
|
||||
# have changed
|
||||
gravityDBfile="${GRAVITYDB}"
|
||||
gravityDBfile_default="/etc/pihole/gravity.db"
|
||||
gravityDBfile_default="${piholeDir}/gravity.db"
|
||||
gravityTEMPfile="${GRAVITYDB}_temp"
|
||||
gravityDIR="$(dirname -- "${gravityDBfile}")"
|
||||
gravityOLDfile="${gravityDIR}/gravity_old.db"
|
||||
gravityBCKdir="${gravityDIR}/gravity_backups"
|
||||
gravityBCKfile="${gravityBCKdir}/gravity.db"
|
||||
|
||||
fix_owner_permissions() {
|
||||
# Fix ownership and permissions for the specified file
|
||||
@@ -91,11 +96,21 @@ gravity_build_tree() {
|
||||
|
||||
if [[ "${status}" -ne 0 ]]; then
|
||||
echo -e "\\n ${CROSS} Unable to build gravity tree in ${gravityTEMPfile}\\n ${output}"
|
||||
echo -e " ${INFO} If you have a large amount of domains, make sure your Pi-hole has enough RAM available\\n"
|
||||
return 1
|
||||
fi
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
}
|
||||
|
||||
# Rotate gravity backup files
|
||||
rotate_gravity_backup() {
|
||||
for i in {9..1}; do
|
||||
if [ -f "${gravityBCKfile}.${i}" ]; then
|
||||
mv "${gravityBCKfile}.${i}" "${gravityBCKfile}.$((i + 1))"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Copy data from old to new database file and swap them
|
||||
gravity_swap_databases() {
|
||||
str="Swapping databases"
|
||||
@@ -111,10 +126,32 @@ gravity_swap_databases() {
|
||||
oldAvail=false
|
||||
if [ "${availableBlocks}" -gt "$((gravityBlocks * 2))" ] && [ -f "${gravityDBfile}" ]; then
|
||||
oldAvail=true
|
||||
mv "${gravityDBfile}" "${gravityOLDfile}"
|
||||
else
|
||||
rm "${gravityDBfile}"
|
||||
cp -p "${gravityDBfile}" "${gravityOLDfile}"
|
||||
fi
|
||||
|
||||
# Drop the gravity and antigravity tables + subsequent VACUUM the current
|
||||
# database for compaction
|
||||
output=$({ printf ".timeout 30000\\nDROP TABLE IF EXISTS gravity;\\nDROP TABLE IF EXISTS antigravity;\\nVACUUM;\\n" | pihole-FTL sqlite3 -ni "${gravityDBfile}"; } 2>&1)
|
||||
status="$?"
|
||||
|
||||
if [[ "${status}" -ne 0 ]]; then
|
||||
echo -e "\\n ${CROSS} Unable to clean current database for backup\\n ${output}"
|
||||
else
|
||||
# Check if the backup directory exists
|
||||
if [ ! -d "${gravityBCKdir}" ]; then
|
||||
mkdir -p "${gravityBCKdir}" && chown pihole:pihole "${gravityBCKdir}"
|
||||
fi
|
||||
|
||||
# If multiple gravityBCKfile's are present (appended with a number), rotate them
|
||||
# We keep at most 10 backups
|
||||
rotate_gravity_backup
|
||||
|
||||
# Move the old database to the backup location
|
||||
mv "${gravityDBfile}" "${gravityBCKfile}.1"
|
||||
fi
|
||||
|
||||
|
||||
# Move the new database to the correct location
|
||||
mv "${gravityTEMPfile}" "${gravityDBfile}"
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
|
||||
@@ -268,7 +305,7 @@ migrate_to_database() {
|
||||
fi
|
||||
|
||||
# Check if gravity database needs to be updated
|
||||
upgrade_gravityDB "${gravityDBfile}" "${piholeDir}"
|
||||
upgrade_gravityDB "${gravityDBfile}"
|
||||
|
||||
# Migrate list files to new database
|
||||
if [ -e "${adListFile}" ]; then
|
||||
@@ -296,7 +333,7 @@ migrate_to_database() {
|
||||
fi
|
||||
|
||||
# Check if gravity database needs to be updated
|
||||
upgrade_gravityDB "${gravityDBfile}" "${piholeDir}"
|
||||
upgrade_gravityDB "${gravityDBfile}"
|
||||
}
|
||||
|
||||
# Determine if DNS resolution is available before proceeding
|
||||
@@ -311,17 +348,72 @@ gravity_CheckDNSResolutionAvailable() {
|
||||
echo -e " ${CROSS} DNS resolution is currently unavailable"
|
||||
fi
|
||||
|
||||
str="Waiting until DNS resolution is available..."
|
||||
str="Waiting up to 120 seconds for DNS resolution..."
|
||||
echo -ne " ${INFO} ${str}"
|
||||
until getent hosts github.com &> /dev/null; do
|
||||
# Append one dot for each second waiting
|
||||
str="${str}."
|
||||
echo -ne " ${OVER} ${INFO} ${str}"
|
||||
sleep 1
|
||||
|
||||
# Default DNS timeout is two seconds, plus 1 second for each dot > 120 seconds
|
||||
for ((i = 0; i < 40; i++)); do
|
||||
if getent hosts github.com &> /dev/null; then
|
||||
# If we reach this point, DNS resolution is available
|
||||
echo -e "${OVER} ${TICK} DNS resolution is available"
|
||||
return 0
|
||||
fi
|
||||
# Append one dot for each second waiting
|
||||
echo -ne "."
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# If we reach this point, DNS resolution is available
|
||||
echo -e "${OVER} ${TICK} DNS resolution is available"
|
||||
# DNS resolution is still unavailable after 120 seconds
|
||||
return 1
|
||||
|
||||
}
|
||||
|
||||
# Function: try_restore_backup
|
||||
# Description: Attempts to restore the previous Pi-hole gravity database from a
|
||||
# backup file. If a backup exists, it copies the backup to the
|
||||
# gravity database file and prepares a new gravity database. If the
|
||||
# restoration is successful, it returns 0. Otherwise, it returns 1.
|
||||
# Returns:
|
||||
# 0 - If the backup is successfully restored.
|
||||
# 1 - If no backup is available or if the restoration fails.
|
||||
try_restore_backup () {
|
||||
local num filename timestamp
|
||||
num=$1
|
||||
filename="${gravityBCKfile}.${num}"
|
||||
# Check if a backup exists
|
||||
if [ -f "${filename}" ]; then
|
||||
echo -e " ${INFO} Attempting to restore previous database from backup no. ${num}"
|
||||
cp "${filename}" "${gravityDBfile}"
|
||||
|
||||
# If the backup was successfully copied, prepare a new gravity database from
|
||||
# it
|
||||
if [ -f "${gravityDBfile}" ]; then
|
||||
output=$({ pihole-FTL sqlite3 -ni "${gravityTEMPfile}" <<<"${copyGravity}"; } 2>&1)
|
||||
status="$?"
|
||||
|
||||
# Error checking
|
||||
if [[ "${status}" -ne 0 ]]; then
|
||||
echo -e "\\n ${CROSS} Unable to copy data from ${gravityDBfile} to ${gravityTEMPfile}\\n ${output}"
|
||||
gravity_Cleanup "error"
|
||||
fi
|
||||
|
||||
# Get the timestamp of the backup file in a human-readable format
|
||||
# Note that this timestamp will be in the server timezone, this may be
|
||||
# GMT, e.g., on a Raspberry Pi where the default timezone has never been
|
||||
# changed
|
||||
timestamp=$(date -r "${filename}" "+%Y-%m-%d %H:%M:%S %Z")
|
||||
|
||||
# Add a record to the info table to indicate that the gravity database was restored
|
||||
pihole-FTL sqlite3 "${gravityTEMPfile}" "INSERT OR REPLACE INTO info (property,value) values ('gravity_restored','${timestamp}');"
|
||||
echo -e " ${TICK} Successfully restored from backup (${gravityBCKfile}.${num} at ${timestamp})"
|
||||
return 0
|
||||
else
|
||||
echo -e " ${CROSS} Unable to restore backup no. ${num}"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e " ${CROSS} Backup no. ${num} not available"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Retrieve blocklist URLs and parse domains from adlist.list
|
||||
@@ -332,33 +424,7 @@ gravity_DownloadBlocklists() {
|
||||
echo -e " ${INFO} Storing gravity database in ${COL_BOLD}${gravityDBfile}${COL_NC}"
|
||||
fi
|
||||
|
||||
# Retrieve source URLs from gravity database
|
||||
# We source only enabled adlists, SQLite3 stores boolean values as 0 (false) or 1 (true)
|
||||
mapfile -t sources <<<"$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT address FROM vw_adlist;" 2>/dev/null)"
|
||||
mapfile -t sourceIDs <<<"$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT id FROM vw_adlist;" 2>/dev/null)"
|
||||
mapfile -t sourceTypes <<<"$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT type FROM vw_adlist;" 2>/dev/null)"
|
||||
|
||||
# Parse source domains from $sources
|
||||
mapfile -t sourceDomains <<<"$(
|
||||
# Logic: Split by folder/port
|
||||
awk -F '[/:]' '{
|
||||
# Remove URL protocol & optional username:password@
|
||||
gsub(/(.*:\/\/|.*:.*@)/, "", $0)
|
||||
if(length($1)>0){print $1}
|
||||
else {print "local"}
|
||||
}' <<<"$(printf '%s\n' "${sources[@]}")" 2>/dev/null
|
||||
)"
|
||||
|
||||
local str="Pulling blocklist source list into range"
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
|
||||
if [[ -z "${sources[*]}" ]] || [[ -z "${sourceDomains[*]}" ]]; then
|
||||
echo -e " ${INFO} No source list found, or it is empty"
|
||||
echo ""
|
||||
unset sources
|
||||
fi
|
||||
|
||||
local url domain str target compression adlist_type directory
|
||||
local url domain str compression adlist_type directory success
|
||||
echo ""
|
||||
|
||||
# Prepare new gravity database
|
||||
@@ -390,10 +456,55 @@ gravity_DownloadBlocklists() {
|
||||
|
||||
if [[ "${status}" -ne 0 ]]; then
|
||||
echo -e "\\n ${CROSS} Unable to copy data from ${gravityDBfile} to ${gravityTEMPfile}\\n ${output}"
|
||||
return 1
|
||||
|
||||
# Try to attempt a backup restore
|
||||
success=false
|
||||
if [[ -d "${gravityBCKdir}" ]]; then
|
||||
for i in {1..10}; do
|
||||
if try_restore_backup "${i}"; then
|
||||
success=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# If none of the attempts worked, return 1
|
||||
if [[ "${success}" == false ]]; then
|
||||
pihole-FTL sqlite3 "${gravityTEMPfile}" "INSERT OR REPLACE INTO info (property,value) values ('gravity_restored','failed');"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo -e " ${TICK} ${str}"
|
||||
else
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
fi
|
||||
|
||||
# Retrieve source URLs from gravity database
|
||||
# We source only enabled adlists, SQLite3 stores boolean values as 0 (false) or 1 (true)
|
||||
mapfile -t sources <<<"$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT address FROM vw_adlist;" 2>/dev/null)"
|
||||
mapfile -t sourceIDs <<<"$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT id FROM vw_adlist;" 2>/dev/null)"
|
||||
mapfile -t sourceTypes <<<"$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT type FROM vw_adlist;" 2>/dev/null)"
|
||||
|
||||
# Parse source domains from $sources
|
||||
mapfile -t sourceDomains <<<"$(
|
||||
# Logic: Split by folder/port
|
||||
awk -F '[/:]' '{
|
||||
# Remove URL protocol & optional username:password@
|
||||
gsub(/(.*:\/\/|.*:.*@)/, "", $0)
|
||||
if(length($1)>0){print $1}
|
||||
else {print "local"}
|
||||
}' <<<"$(printf '%s\n' "${sources[@]}")" 2>/dev/null
|
||||
)"
|
||||
|
||||
local str="Pulling blocklist source list into range"
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
|
||||
if [[ -z "${sources[*]}" ]] || [[ -z "${sourceDomains[*]}" ]]; then
|
||||
echo -e " ${INFO} No source list found, or it is empty"
|
||||
echo ""
|
||||
unset sources
|
||||
fi
|
||||
|
||||
# Use compression to reduce the amount of data that is transferred
|
||||
# between the Pi-hole and the ad list provider. Use this feature
|
||||
# only if it is supported by the locally available version of curl
|
||||
@@ -404,6 +515,15 @@ gravity_DownloadBlocklists() {
|
||||
compression=""
|
||||
echo -e " ${INFO} Libz compression not available\n"
|
||||
fi
|
||||
|
||||
# Check if etag is supported by the locally available version of curl
|
||||
# (available as of curl 7.68.0, released Jan 2020)
|
||||
# https://github.com/curl/curl/pull/4543 +
|
||||
# https://github.com/curl/curl/pull/4678
|
||||
if curl --help all | grep -q "etag-save"; then
|
||||
etag_support=true
|
||||
fi
|
||||
|
||||
# Loop through $sources and download each one
|
||||
for ((i = 0; i < "${#sources[@]}"; i++)); do
|
||||
url="${sources[$i]}"
|
||||
@@ -420,8 +540,8 @@ gravity_DownloadBlocklists() {
|
||||
fi
|
||||
|
||||
# Save the file as list.#.domain
|
||||
saveLocation="${piholeDir}/list.${id}.${domain}.${domainsExtension}"
|
||||
activeDomains[$i]="${saveLocation}"
|
||||
saveLocation="${listsCacheDir}/list.${id}.${domain}.${domainsExtension}"
|
||||
activeDomains[i]="${saveLocation}"
|
||||
|
||||
# Check if we can write to the save location file without actually creating
|
||||
# it (in case it doesn't exist)
|
||||
@@ -453,12 +573,12 @@ gravity_DownloadBlocklists() {
|
||||
if [[ "${check_url}" =~ ${regex} ]]; then
|
||||
echo -e " ${CROSS} Invalid Target"
|
||||
else
|
||||
timeit gravity_DownloadBlocklistFromUrl "${url}" "${sourceIDs[$i]}" "${saveLocation}" "${target}" "${compression}" "${adlist_type}" "${domain}"
|
||||
timeit gravity_DownloadBlocklistFromUrl "${url}" "${sourceIDs[$i]}" "${saveLocation}" "${compression}" "${adlist_type}" "${domain}"
|
||||
fi
|
||||
echo ""
|
||||
done
|
||||
|
||||
gravity_Blackbody=true
|
||||
DownloadBlocklists_done=true
|
||||
}
|
||||
|
||||
compareLists() {
|
||||
@@ -487,9 +607,11 @@ compareLists() {
|
||||
|
||||
# Download specified URL and perform checks on HTTP status and file content
|
||||
gravity_DownloadBlocklistFromUrl() {
|
||||
local url="${1}" adlistID="${2}" saveLocation="${3}" target="${4}" compression="${5}" gravity_type="${6}" domain="${7}"
|
||||
local heisenbergCompensator="" listCurlBuffer str httpCode success="" ip cmd_ext
|
||||
local url="${1}" adlistID="${2}" saveLocation="${3}" compression="${4}" gravity_type="${5}" domain="${6}"
|
||||
local listCurlBuffer str httpCode success="" ip customUpstreamResolver=""
|
||||
local file_path permissions ip_addr port blocked=false download=true
|
||||
# modifiedOptions is an array to store all the options used to check if the adlist has been changed upstream
|
||||
local modifiedOptions=()
|
||||
|
||||
# Create temp file to store content on disk instead of RAM
|
||||
# We don't use '--suffix' here because not all implementations of mktemp support it, e.g. on Alpine
|
||||
@@ -497,43 +619,42 @@ gravity_DownloadBlocklistFromUrl() {
|
||||
mv "${listCurlBuffer}" "${listCurlBuffer%.*}.phgpb"
|
||||
listCurlBuffer="${listCurlBuffer%.*}.phgpb"
|
||||
|
||||
# Determine if $saveLocation has read permission
|
||||
if [[ -r "${saveLocation}" && $url != "file"* ]]; then
|
||||
# Have curl determine if a remote file has been modified since last retrieval
|
||||
# Uses "Last-Modified" header, which certain web servers do not provide (e.g: raw github urls)
|
||||
# Note: Don't do this for local files, always download them
|
||||
heisenbergCompensator="-z ${saveLocation}"
|
||||
# For all remote files, we try to determine if the file has changed to skip
|
||||
# downloading them whenever possible.
|
||||
if [[ $url != "file"* ]]; then
|
||||
# Use the HTTP ETag header to determine if the file has changed if supported
|
||||
# by curl. Using ETags is supported by raw.githubusercontent.com URLs.
|
||||
if [[ "${etag_support}" == true ]]; then
|
||||
# Save HTTP ETag to the specified file. An ETag is a caching related header,
|
||||
# usually returned in a response. If no ETag is sent by the server, an empty
|
||||
# file is created and can later be used consistently.
|
||||
modifiedOptions=("${modifiedOptions[@]}" --etag-save "${saveLocation}".etag)
|
||||
|
||||
if [[ -f "${saveLocation}.etag" ]]; then
|
||||
# This option makes a conditional HTTP request for the specific ETag read
|
||||
# from the given file by sending a custom If-None-Match header using the
|
||||
# stored ETag. This way, the server will only send the file if it has
|
||||
# changed since the last request.
|
||||
modifiedOptions=("${modifiedOptions[@]}" --etag-compare "${saveLocation}".etag)
|
||||
fi
|
||||
fi
|
||||
|
||||
# Add If-Modified-Since header to the request if we did already download the
|
||||
# file once
|
||||
if [[ -f "${saveLocation}" ]]; then
|
||||
# Request a file that has been modified later than the given time and
|
||||
# date. We provide a file here which makes curl use the modification
|
||||
# timestamp (mtime) of this file.
|
||||
# Interstingly, this option is not supported by raw.githubusercontent.com
|
||||
# URLs, however, it is still supported by many older web servers which may
|
||||
# not support the HTTP ETag method so we keep it as a fallback.
|
||||
modifiedOptions=("${modifiedOptions[@]}" -z "${saveLocation}")
|
||||
fi
|
||||
fi
|
||||
|
||||
str="Status:"
|
||||
echo -ne " ${INFO} ${str} Pending..."
|
||||
blocked=false
|
||||
case $(getFTLConfigValue dns.blocking.mode) in
|
||||
"IP-NODATA-AAAA" | "IP")
|
||||
# Get IP address of this domain
|
||||
ip="$(dig "${domain}" +short)"
|
||||
# Check if this IP matches any IP of the system
|
||||
if [[ -n "${ip}" && $(grep -Ec "inet(|6) ${ip}" <<<"$(ip a)") -gt 0 ]]; then
|
||||
blocked=true
|
||||
fi
|
||||
;;
|
||||
"NXDOMAIN")
|
||||
if [[ $(dig "${domain}" | grep "NXDOMAIN" -c) -ge 1 ]]; then
|
||||
blocked=true
|
||||
fi
|
||||
;;
|
||||
"NODATA")
|
||||
if [[ $(dig "${domain}" | grep "NOERROR" -c) -ge 1 ]] && [[ -z $(dig +short "${domain}") ]]; then
|
||||
blocked=true
|
||||
fi
|
||||
;;
|
||||
"NULL" | *)
|
||||
if [[ $(dig "${domain}" +short | grep "0.0.0.0" -c) -ge 1 ]]; then
|
||||
blocked=true
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# Check if this domain is blocked by Pi-hole but only if the domain is not a
|
||||
# local file or empty
|
||||
if [[ $url != "file"* ]] && [[ -n "${domain}" ]]; then
|
||||
@@ -593,7 +714,7 @@ gravity_DownloadBlocklistFromUrl() {
|
||||
fi
|
||||
echo -e "${OVER} ${CROSS} ${str} ${domain} is blocked by one of your lists. Using DNS server ${upstream} instead"
|
||||
echo -ne " ${INFO} ${str} Pending..."
|
||||
cmd_ext="--resolve $domain:$port:$ip"
|
||||
customUpstreamResolver="--resolve $domain:$port:$ip"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -631,8 +752,7 @@ gravity_DownloadBlocklistFromUrl() {
|
||||
fi
|
||||
|
||||
if [[ "${download}" == true ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
httpCode=$(curl --connect-timeout ${curl_connect_timeout} -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" "${url}" -o "${listCurlBuffer}" 2>/dev/null)
|
||||
httpCode=$(curl --connect-timeout ${curl_connect_timeout} -s -L ${compression:+${compression}} ${customUpstreamResolver:+${customUpstreamResolver}} "${modifiedOptions[@]}" -w "%{http_code}" "${url}" -o "${listCurlBuffer}" 2>/dev/null)
|
||||
fi
|
||||
|
||||
case $url in
|
||||
@@ -675,20 +795,21 @@ gravity_DownloadBlocklistFromUrl() {
|
||||
# Determine if the blocklist was downloaded and saved correctly
|
||||
if [[ "${success}" == true ]]; then
|
||||
if [[ "${httpCode}" == "304" ]]; then
|
||||
# Set list status to "unchanged/cached"
|
||||
database_adlist_status "${adlistID}" "2"
|
||||
# Add domains to database table file
|
||||
pihole-FTL "${gravity_type}" parseList "${saveLocation}" "${gravityTEMPfile}" "${adlistID}"
|
||||
database_adlist_status "${adlistID}" "2"
|
||||
done="true"
|
||||
# Check if $listCurlBuffer is a non-zero length file
|
||||
elif [[ -s "${listCurlBuffer}" ]]; then
|
||||
# Determine if blocklist is non-standard and parse as appropriate
|
||||
gravity_ParseFileIntoDomains "${listCurlBuffer}" "${saveLocation}"
|
||||
# Remove curl buffer file after its use
|
||||
rm "${listCurlBuffer}"
|
||||
# Move the downloaded list to the final location
|
||||
mv "${listCurlBuffer}" "${saveLocation}"
|
||||
# Ensure the file has the correct permissions
|
||||
fix_owner_permissions "${saveLocation}"
|
||||
# Compare lists if they are identical
|
||||
compareLists "${adlistID}" "${saveLocation}"
|
||||
# Add domains to database table file
|
||||
pihole-FTL "${gravity_type}" parseList "${saveLocation}" "${gravityTEMPfile}" "${adlistID}"
|
||||
# Compare lists, are they identical?
|
||||
compareLists "${adlistID}" "${saveLocation}"
|
||||
done="true"
|
||||
else
|
||||
# Fall back to previously cached list if $listCurlBuffer is empty
|
||||
@@ -700,12 +821,13 @@ gravity_DownloadBlocklistFromUrl() {
|
||||
if [[ "${done}" != "true" ]]; then
|
||||
# Determine if cached list has read permission
|
||||
if [[ -r "${saveLocation}" ]]; then
|
||||
echo -e " ${CROSS} List download failed: ${COL_LIGHT_GREEN}using previously cached list${COL_NC}"
|
||||
echo -e " ${CROSS} List download failed: ${COL_GREEN}using previously cached list${COL_NC}"
|
||||
# Set list status to "download-failed/cached"
|
||||
database_adlist_status "${adlistID}" "3"
|
||||
# Add domains to database table file
|
||||
pihole-FTL "${gravity_type}" parseList "${saveLocation}" "${gravityTEMPfile}" "${adlistID}"
|
||||
database_adlist_status "${adlistID}" "3"
|
||||
else
|
||||
echo -e " ${CROSS} List download failed: ${COL_LIGHT_RED}no cached list available${COL_NC}"
|
||||
echo -e " ${CROSS} List download failed: ${COL_RED}no cached list available${COL_NC}"
|
||||
# Manually reset these two numbers because we do not call parseList here
|
||||
database_adlist_number "${adlistID}" 0 0
|
||||
database_adlist_status "${adlistID}" "4"
|
||||
@@ -713,37 +835,6 @@ gravity_DownloadBlocklistFromUrl() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Parse source files into domains format
|
||||
gravity_ParseFileIntoDomains() {
|
||||
local src="${1}" destination="${2}"
|
||||
|
||||
# Remove comments and print only the domain name
|
||||
# Most of the lists downloaded are already in hosts file format but the spacing/formatting is not contiguous
|
||||
# This helps with that and makes it easier to read
|
||||
# It also helps with debugging so each stage of the script can be researched more in depth
|
||||
# 1) Convert all characters to lowercase
|
||||
tr '[:upper:]' '[:lower:]' <"${src}" >"${destination}"
|
||||
|
||||
# 2) Remove carriage returns
|
||||
# 3) Remove lines starting with ! (ABP Comments)
|
||||
# 4) Remove lines starting with [ (ABP Header)
|
||||
# 5) Remove lines containing ABP extended CSS selectors ("##", "#$#", "#@#", "#?#") and Adguard JavaScript (#%#) preceded by a letter
|
||||
# 6) Remove comments (text starting with "#", include possible spaces before the hash sign)
|
||||
# 7) Remove leading tabs, spaces, etc. (Also removes leading IP addresses)
|
||||
# 8) Remove empty lines
|
||||
|
||||
sed -i -r \
|
||||
-e 's/\r$//' \
|
||||
-e 's/\s*!.*//g' \
|
||||
-e 's/\s*\[.*//g' \
|
||||
-e '/[a-z]\#[$?@%]{0,3}\#/d' \
|
||||
-e 's/\s*#.*//g' \
|
||||
-e 's/^.*\s+//g' \
|
||||
-e '/^$/d' "${destination}"
|
||||
|
||||
fix_owner_permissions "${destination}"
|
||||
}
|
||||
|
||||
# Report number of entries in a table
|
||||
gravity_Table_Count() {
|
||||
local table="${1}"
|
||||
@@ -764,16 +855,16 @@ gravity_Table_Count() {
|
||||
gravity_ShowCount() {
|
||||
# Here we use the table "gravity" instead of the view "vw_gravity" for speed.
|
||||
# It's safe to replace it here, because right after a gravity run both will show the exactly same number of domains.
|
||||
gravity_Table_Count "gravity" "gravity domains" ""
|
||||
gravity_Table_Count "vw_blacklist" "exact denied domains"
|
||||
gravity_Table_Count "vw_regex_blacklist" "regex denied filters"
|
||||
gravity_Table_Count "vw_whitelist" "exact allowed domains"
|
||||
gravity_Table_Count "vw_regex_whitelist" "regex allowed filters"
|
||||
gravity_Table_Count "gravity" "gravity domains"
|
||||
gravity_Table_Count "domainlist WHERE type = 1 AND enabled = 1" "exact denied domains"
|
||||
gravity_Table_Count "domainlist WHERE type = 3 AND enabled = 1" "regex denied filters"
|
||||
gravity_Table_Count "domainlist WHERE type = 0 AND enabled = 1" "exact allowed domains"
|
||||
gravity_Table_Count "domainlist WHERE type = 2 AND enabled = 1" "regex allowed filters"
|
||||
}
|
||||
|
||||
# Trap Ctrl-C
|
||||
gravity_Trap() {
|
||||
trap '{ echo -e "\\n\\n ${INFO} ${COL_LIGHT_RED}User-abort detected${COL_NC}"; gravity_Cleanup "error"; }' INT
|
||||
trap '{ echo -e "\\n\\n ${INFO} ${COL_RED}User-abort detected${COL_NC}"; gravity_Cleanup "error"; }' INT
|
||||
}
|
||||
|
||||
# Clean up after Gravity upon exit or cancellation
|
||||
@@ -791,13 +882,13 @@ gravity_Cleanup() {
|
||||
# invalid_domains location
|
||||
rm "${GRAVITY_TMPDIR}"/*.ph-non-domains 2>/dev/null
|
||||
|
||||
# Ensure this function only runs when gravity_SetDownloadOptions() has completed
|
||||
if [[ "${gravity_Blackbody:-}" == true ]]; then
|
||||
# Remove any unused .domains files
|
||||
for file in "${piholeDir}"/*."${domainsExtension}"; do
|
||||
# If list is not in active array, then remove it
|
||||
# Ensure this function only runs when gravity_DownloadBlocklists() has completed
|
||||
if [[ "${DownloadBlocklists_done:-}" == true ]]; then
|
||||
# Remove any unused .domains/.etag/.sha files
|
||||
for file in "${listsCacheDir}"/*."${domainsExtension}"; do
|
||||
# If list is not in active array, then remove it and all associated files
|
||||
if [[ ! "${activeDomains[*]}" == *"${file}"* ]]; then
|
||||
rm -f "${file}" 2>/dev/null ||
|
||||
rm -f "${file}"* 2>/dev/null ||
|
||||
echo -e " ${CROSS} Failed to remove ${file##*/}"
|
||||
fi
|
||||
done
|
||||
@@ -917,11 +1008,33 @@ timeit(){
|
||||
elapsed_time=$((end_time - start_time))
|
||||
|
||||
# Display the elapsed time
|
||||
printf " %b--> took %d.%03d seconds%b\n" ${COL_BLUE} $((elapsed_time / 1000)) $((elapsed_time % 1000)) ${COL_NC}
|
||||
printf " %b--> took %d.%03d seconds%b\n" "${COL_BLUE}" $((elapsed_time / 1000)) $((elapsed_time % 1000)) "${COL_NC}"
|
||||
|
||||
return $ret
|
||||
}
|
||||
|
||||
migrate_to_listsCache_dir() {
|
||||
# If the ${listsCacheDir} directory already exists, this has been done before
|
||||
if [[ -d "${listsCacheDir}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# If not, we need to migrate the old files to the new directory
|
||||
local str="Migrating the list's cache directory to new location"
|
||||
echo -ne " ${INFO} ${str}..."
|
||||
mkdir -p "${listsCacheDir}" && chown pihole:pihole "${listsCacheDir}"
|
||||
|
||||
# Move the old files to the new directory
|
||||
if mv "${piholeDir}"/list.* "${listsCacheDir}/" 2>/dev/null; then
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
else
|
||||
echo -e "${OVER} ${CROSS} ${str}"
|
||||
fi
|
||||
|
||||
# Update the list's paths in the corresponding .sha1 files to the new location
|
||||
sed -i "s|${piholeDir}/|${listsCacheDir}/|g" "${listsCacheDir}"/*.sha1 2>/dev/null
|
||||
}
|
||||
|
||||
helpFunc() {
|
||||
echo "Usage: pihole -g
|
||||
Update domains from blocklists specified in adlists.list
|
||||
@@ -968,13 +1081,19 @@ for var in "$@"; do
|
||||
"-t" | "--timeit") timed=true ;;
|
||||
"-r" | "--repair") repairSelector "$3" ;;
|
||||
"-u" | "--upgrade")
|
||||
upgrade_gravityDB "${gravityDBfile}" "${piholeDir}"
|
||||
upgrade_gravityDB "${gravityDBfile}"
|
||||
exit 0
|
||||
;;
|
||||
"-h" | "--help") helpFunc ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if DNS is available, no need to do any database manipulation if we're not able to download adlists
|
||||
if ! timeit gravity_CheckDNSResolutionAvailable; then
|
||||
echo -e " ${CROSS} No DNS resolution available. Please contact support."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove OLD (backup) gravity file, if it exists
|
||||
if [[ -f "${gravityOLDfile}" ]]; then
|
||||
rm "${gravityOLDfile}"
|
||||
@@ -997,6 +1116,9 @@ if [[ "${recover_database:-}" == true ]]; then
|
||||
timeit database_recovery "$4"
|
||||
fi
|
||||
|
||||
# Migrate scattered list files to the new cache directory
|
||||
migrate_to_listsCache_dir
|
||||
|
||||
# Move possibly existing legacy files to the gravity database
|
||||
if ! timeit migrate_to_database; then
|
||||
echo -e " ${CROSS} Unable to migrate to database. Please contact support."
|
||||
@@ -1007,16 +1129,11 @@ if [[ "${forceDelete:-}" == true ]]; then
|
||||
str="Deleting existing list cache"
|
||||
echo -ne "${INFO} ${str}..."
|
||||
|
||||
rm /etc/pihole/list.* 2>/dev/null || true
|
||||
rm "${listsCacheDir}/list.*" 2>/dev/null || true
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
fi
|
||||
|
||||
# Gravity downloads blocklists next
|
||||
if ! timeit gravity_CheckDNSResolutionAvailable; then
|
||||
echo -e " ${CROSS} Can not complete gravity update, no DNS is available. Please contact support."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! gravity_DownloadBlocklists; then
|
||||
echo -e " ${CROSS} Unable to create gravity database. Please try again later. If the problem persists, please contact support."
|
||||
exit 1
|
||||
|
||||
@@ -23,7 +23,7 @@ pihole -r
|
||||
.br
|
||||
\fBpihole -g\fR
|
||||
.br
|
||||
\fBpihole\fR -\fBq\fR [options]
|
||||
\fBpihole\fR \fB-q\fR [options]
|
||||
.br
|
||||
\fBpihole\fR \fB-l\fR (\fBon|off|off noflush\fR)
|
||||
.br
|
||||
@@ -43,7 +43,7 @@ pihole -r
|
||||
.br
|
||||
\fBpihole\fR \fBcheckout\fR repo [branch]
|
||||
.br
|
||||
\fBpihole\fR \api\fR endpoint
|
||||
\fBpihole\fR \fBapi\fR [verbose] endpoint
|
||||
.br
|
||||
\fBpihole\fR \fBhelp\fR
|
||||
.br
|
||||
@@ -105,9 +105,9 @@ Available commands and options:
|
||||
Flush the Pi-hole log
|
||||
.br
|
||||
|
||||
\fB-r, reconfigure\fR
|
||||
\fB-r, repair\fR
|
||||
.br
|
||||
Reconfigure or Repair Pi-hole subsystems
|
||||
Repair Pi-hole subsystems
|
||||
.br
|
||||
|
||||
\fB-t, tail\fR [arg]
|
||||
@@ -234,10 +234,14 @@ Available commands and options:
|
||||
branchname Update subsystems to the specified branchname
|
||||
.br
|
||||
|
||||
\fBapi\fR endpoint
|
||||
\fBapi\fR [verbose] endpoint
|
||||
.br
|
||||
Query the Pi-hole API at <endpoint>
|
||||
.br
|
||||
|
||||
verbose Show authentication and status messages
|
||||
.br
|
||||
|
||||
.SH "EXAMPLE"
|
||||
|
||||
Some usage examples
|
||||
@@ -313,9 +317,10 @@ Switching Pi-hole subsystem branches
|
||||
Switch to core development branch
|
||||
.br
|
||||
|
||||
\fBpihole arpflush\fR
|
||||
\fBpihole networkflush\fR
|
||||
.br
|
||||
Flush information stored in Pi-hole's network tables
|
||||
Flush information stored in Pi-hole's network table
|
||||
Add '--arp' to additionally flush the ARP table
|
||||
.br
|
||||
|
||||
\fBpihole api stats/summary\fR
|
||||
@@ -323,6 +328,11 @@ Switching Pi-hole subsystem branches
|
||||
Queries FTL for the stats/summary endpoint
|
||||
.br
|
||||
|
||||
\fBpihole api verbose stats/summary\fR
|
||||
.br
|
||||
Same as above, but shows authentication and status messages
|
||||
.br
|
||||
|
||||
.SH "COLOPHON"
|
||||
|
||||
Get sucked into the latest news and community activity by entering Pi-hole's orbit. Information about Pi-hole, and the latest version of the software can be found at https://pi-hole.net.
|
||||
|
||||
139
pihole
139
pihole
@@ -9,7 +9,7 @@
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
|
||||
# PI_HOLE_BIN_DIR is not readonly here because in some functions (checkout),
|
||||
# they might get set again when the installer is sourced. This causes an
|
||||
@@ -17,13 +17,16 @@ readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||
PI_HOLE_BIN_DIR="/usr/local/bin"
|
||||
|
||||
readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
||||
# shellcheck source=./advanced/Scripts/COL_TABLE
|
||||
source "${colfile}"
|
||||
|
||||
readonly utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
||||
# shellcheck source=./advanced/Scripts/utils.sh
|
||||
source "${utilsfile}"
|
||||
|
||||
# Source api functions
|
||||
readonly apifile="${PI_HOLE_SCRIPT_DIR}/api.sh"
|
||||
# shellcheck source=./advanced/Scripts/api.sh
|
||||
source "${apifile}"
|
||||
|
||||
versionsfile="/etc/pihole/versions"
|
||||
@@ -31,6 +34,7 @@ if [ -f "${versionsfile}" ]; then
|
||||
# Only source versionsfile if the file exits
|
||||
# fixes a warning during installation where versionsfile does not exist yet
|
||||
# but gravity calls `pihole -status` and thereby sourcing the file
|
||||
# shellcheck source=/dev/null
|
||||
source "${versionsfile}"
|
||||
fi
|
||||
|
||||
@@ -73,19 +77,17 @@ listFunc() {
|
||||
|
||||
debugFunc() {
|
||||
local automated
|
||||
local web
|
||||
local check_database_integrity
|
||||
# Pull off the `debug` leaving passed call augmentation flags in $1
|
||||
shift
|
||||
|
||||
for value in "$@"; do
|
||||
[[ "$value" == *"-a"* ]] && automated="true"
|
||||
[[ "$value" == *"-w"* ]] && web="true"
|
||||
[[ "$value" == *"-c"* ]] && check_database_integrity="true"
|
||||
[[ "$value" == *"--check_database"* ]] && check_database_integrity="true"
|
||||
done
|
||||
|
||||
AUTOMATED=${automated:-} WEBCALL=${web:-} CHECK_DATABASE=${check_database_integrity:-} "${PI_HOLE_SCRIPT_DIR}"/piholeDebug.sh
|
||||
AUTOMATED=${automated:-} CHECK_DATABASE=${check_database_integrity:-} "${PI_HOLE_SCRIPT_DIR}"/piholeDebug.sh
|
||||
exit 0
|
||||
}
|
||||
|
||||
@@ -94,8 +96,18 @@ flushFunc() {
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Deprecated function, should be removed in the future
|
||||
# use networkFlush instead
|
||||
arpFunc() {
|
||||
"${PI_HOLE_SCRIPT_DIR}"/piholeARPTable.sh "$@"
|
||||
shift
|
||||
echo -e " ${INFO} The 'arpflush' command is deprecated, use 'networkflush' instead"
|
||||
"${PI_HOLE_SCRIPT_DIR}"/piholeNetworkFlush.sh "$@"
|
||||
exit 0
|
||||
}
|
||||
|
||||
networkFlush() {
|
||||
shift
|
||||
"${PI_HOLE_SCRIPT_DIR}"/piholeNetworkFlush.sh "$@"
|
||||
exit 0
|
||||
}
|
||||
|
||||
@@ -109,11 +121,11 @@ updatePiholeFunc() {
|
||||
fi
|
||||
}
|
||||
|
||||
reconfigurePiholeFunc() {
|
||||
repairPiholeFunc() {
|
||||
if [ -n "${DOCKER_VERSION}" ]; then
|
||||
unsupportedFunc
|
||||
else
|
||||
/etc/.pihole/automated\ install/basic-install.sh --reconfigure
|
||||
/etc/.pihole/automated\ install/basic-install.sh --repair
|
||||
exit 0;
|
||||
fi
|
||||
}
|
||||
@@ -145,10 +157,11 @@ uninstallFunc() {
|
||||
|
||||
versionFunc() {
|
||||
exec "${PI_HOLE_SCRIPT_DIR}"/version.sh
|
||||
exit 0
|
||||
}
|
||||
|
||||
reloadDNS() {
|
||||
local svcOption svc str output status pid icon FTL_PID_FILE
|
||||
local svcOption svc str output status pid icon FTL_PID_FILE sigrtmin
|
||||
svcOption="${1:-reload}"
|
||||
|
||||
# get the current path to the pihole-FTL.pid
|
||||
@@ -167,7 +180,10 @@ reloadDNS() {
|
||||
str="FTL is not running"
|
||||
icon="${INFO}"
|
||||
else
|
||||
svc="kill -RTMIN ${pid}"
|
||||
sigrtmin="$(pihole-FTL sigrtmin 2>/dev/null)"
|
||||
# Make sure sigrtmin is a number, otherwise fallback to RTMIN
|
||||
[[ "${sigrtmin}" =~ ^[0-9]+$ ]] || unset sigrtmin
|
||||
svc="kill -${sigrtmin:-RTMIN} ${pid}"
|
||||
str="Reloading DNS lists"
|
||||
icon="${TICK}"
|
||||
fi
|
||||
@@ -236,7 +252,7 @@ Time:
|
||||
fi
|
||||
|
||||
if [[ ${error} == true ]];then
|
||||
echo -e " ${COL_LIGHT_RED}Unknown format for blocking timer!${COL_NC}"
|
||||
echo -e " ${COL_RED}Unknown format for blocking timer!${COL_NC}"
|
||||
echo -e " Try 'pihole disable --help' for more information."
|
||||
exit 1
|
||||
fi
|
||||
@@ -249,17 +265,20 @@ Time:
|
||||
data=$(PostFTLData "dns/blocking" "{ \"blocking\": ${1}, \"timer\": ${tt} }")
|
||||
|
||||
# Check the response
|
||||
local extra=" forever"
|
||||
local timer="$(echo "${data}"| jq --raw-output '.timer' )"
|
||||
local extra timer
|
||||
extra=" forever"
|
||||
timer="$(echo "${data}"| jq --raw-output '.timer' )"
|
||||
if [[ "${timer}" != "null" ]]; then
|
||||
extra=" for ${timer}s"
|
||||
fi
|
||||
local str="Pi-hole $(echo "${data}" | jq --raw-output '.blocking')${extra}"
|
||||
local str
|
||||
str="Pi-hole $(echo "${data}" | jq --raw-output '.blocking')${extra}"
|
||||
|
||||
# Logout from the API
|
||||
LogoutAPI
|
||||
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
piholeLogging() {
|
||||
@@ -289,7 +308,7 @@ Options:
|
||||
echo -e " ${INFO} Enabling logging..."
|
||||
local str="Logging has been enabled!"
|
||||
else
|
||||
echo -e " ${COL_LIGHT_RED}Invalid option${COL_NC}
|
||||
echo -e " ${COL_RED}Invalid option${COL_NC}
|
||||
Try 'pihole logging --help' for more information."
|
||||
exit 1
|
||||
fi
|
||||
@@ -377,20 +396,22 @@ statusFunc() {
|
||||
|
||||
tailFunc() {
|
||||
# Warn user if Pi-hole's logging is disabled
|
||||
local logging_enabled=$(getFTLConfigValue dns.queryLogging)
|
||||
local logging_enabled
|
||||
logging_enabled=$(getFTLConfigValue dns.queryLogging)
|
||||
if [[ "${logging_enabled}" != "true" ]]; then
|
||||
echo " ${CROSS} Warning: Query logging is disabled"
|
||||
fi
|
||||
echo -e " ${INFO} Press Ctrl-C to exit"
|
||||
|
||||
# Get logfile path
|
||||
readonly LOGFILE=$(getFTLConfigValue files.log.dnsmasq)
|
||||
LOGFILE=$(getFTLConfigValue files.log.dnsmasq)
|
||||
readonly LOGFILE
|
||||
|
||||
# Strip date from each line
|
||||
# Color blocklist/denylist/wildcard entries as red
|
||||
# Color A/AAAA/DHCP strings as white
|
||||
# Color everything else as gray
|
||||
tail -f $LOGFILE | grep --line-buffered "${1}" | sed -E \
|
||||
tail -f $LOGFILE | grep --line-buffered -- "${1}" | sed -E \
|
||||
-e "s,($(date +'%b %d ')| dnsmasq\[[0-9]*\]),,g" \
|
||||
-e "s,(.*(denied |gravity blocked ).*),${COL_RED}&${COL_NC}," \
|
||||
-e "s,.*(query\\[A|DHCP).*,${COL_NC}&${COL_NC}," \
|
||||
@@ -400,7 +421,10 @@ tailFunc() {
|
||||
|
||||
piholeCheckoutFunc() {
|
||||
if [ -n "${DOCKER_VERSION}" ]; then
|
||||
unsupportedFunc
|
||||
echo -e "${CROSS} Function not supported in Docker images"
|
||||
echo "Please build a custom image following the steps at"
|
||||
echo "https://github.com/pi-hole/docker-pi-hole?tab=readme-ov-file#building-the-image-locally"
|
||||
exit 0
|
||||
else
|
||||
if [[ "$2" == "-h" ]] || [[ "$2" == "--help" ]]; then
|
||||
echo "Switch Pi-hole subsystems to a different GitHub branch
|
||||
@@ -422,6 +446,7 @@ piholeCheckoutFunc() {
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#shellcheck source=./advanced/Scripts/piholeCheckout.sh
|
||||
source "${PI_HOLE_SCRIPT_DIR}"/piholeCheckout.sh
|
||||
shift
|
||||
checkout "$@"
|
||||
@@ -478,11 +503,12 @@ Debugging Options:
|
||||
Add '-c' or '--check-database' to include a Pi-hole database integrity check
|
||||
Add '-a' to automatically upload the log to tricorder.pi-hole.net
|
||||
-f, flush Flush the Pi-hole log
|
||||
-r, reconfigure Reconfigure or Repair Pi-hole subsystems
|
||||
-r, repair Repair Pi-hole subsystems
|
||||
-t, tail [arg] View the live output of the Pi-hole log.
|
||||
Add an optional argument to filter the log
|
||||
(regular expressions are supported)
|
||||
api <endpoint> Query the Pi-hole API at <endpoint>
|
||||
Precede <endpoint> with 'verbose' option to show authentication and status messages
|
||||
|
||||
|
||||
Options:
|
||||
@@ -508,7 +534,8 @@ Options:
|
||||
reloadlists Update the lists WITHOUT flushing the cache or restarting the DNS server
|
||||
checkout Switch Pi-hole subsystems to a different GitHub branch
|
||||
Add '-h' for more info on checkout usage
|
||||
arpflush Flush information stored in Pi-hole's network tables";
|
||||
networkflush Flush information stored in Pi-hole's network tables
|
||||
Add '--arp' to additionally flush the ARP table ";
|
||||
exit 0
|
||||
}
|
||||
|
||||
@@ -517,7 +544,7 @@ if [[ $# = 0 ]]; then
|
||||
fi
|
||||
|
||||
# functions that do not require sudo power
|
||||
need_root=1
|
||||
need_root=
|
||||
case "${1}" in
|
||||
"-h" | "help" | "--help" ) helpFunc;;
|
||||
"-v" | "version" ) versionFunc;;
|
||||
@@ -525,31 +552,32 @@ case "${1}" in
|
||||
"-q" | "query" ) queryFunc "$@";;
|
||||
"status" ) statusFunc "$2";;
|
||||
"tricorder" ) tricorderFunc;;
|
||||
"allow" | "allowlist" ) listFunc "$@";;
|
||||
"deny" | "denylist" ) listFunc "$@";;
|
||||
"--wild" | "wildcard" ) listFunc "$@";;
|
||||
"--regex" | "regex" ) listFunc "$@";;
|
||||
"--allow-regex" | "allow-regex" ) listFunc "$@";;
|
||||
"--allow-wild" | "allow-wild" ) listFunc "$@";;
|
||||
"enable" ) piholeEnable true "$2";;
|
||||
"disable" ) piholeEnable false "$2";;
|
||||
"api" ) shift; apiFunc "$@"; exit 0;;
|
||||
|
||||
# we need to add all arguments that require sudo power to not trigger the * argument
|
||||
"allow" | "allowlist" ) need_root=0;;
|
||||
"deny" | "denylist" ) need_root=0;;
|
||||
"--wild" | "wildcard" ) need_root=0;;
|
||||
"--regex" | "regex" ) need_root=0;;
|
||||
"--allow-regex" | "allow-regex" ) need_root=0;;
|
||||
"--allow-wild" | "allow-wild" ) need_root=0;;
|
||||
"-f" | "flush" ) ;;
|
||||
"-up" | "updatePihole" ) ;;
|
||||
"-r" | "reconfigure" ) ;;
|
||||
"-l" | "logging" ) ;;
|
||||
"uninstall" ) ;;
|
||||
"enable" ) need_root=0;;
|
||||
"disable" ) need_root=0;;
|
||||
"-d" | "debug" ) ;;
|
||||
"-g" | "updateGravity" ) ;;
|
||||
"reloaddns" ) ;;
|
||||
"reloadlists" ) ;;
|
||||
"setpassword" ) ;;
|
||||
"checkout" ) ;;
|
||||
"updatechecker" ) ;;
|
||||
"arpflush" ) ;;
|
||||
"-t" | "tail" ) ;;
|
||||
"api" ) need_root=0;;
|
||||
"-f" | "flush" ) need_root=true;;
|
||||
"-up" | "updatePihole" ) need_root=true;;
|
||||
"-r" | "repair" ) need_root=true;;
|
||||
"-l" | "logging" ) need_root=true;;
|
||||
"uninstall" ) need_root=true;;
|
||||
"-d" | "debug" ) need_root=true;;
|
||||
"-g" | "updateGravity" ) need_root=true;;
|
||||
"reloaddns" ) need_root=true;;
|
||||
"reloadlists" ) need_root=true;;
|
||||
"setpassword" ) need_root=true;;
|
||||
"checkout" ) need_root=true;;
|
||||
"updatechecker" ) need_root=true;;
|
||||
"arpflush" ) need_root=true;; # Deprecated, use networkflush instead
|
||||
"networkflush" ) need_root=true;;
|
||||
"-t" | "tail" ) need_root=true;;
|
||||
* ) helpFunc;;
|
||||
esac
|
||||
|
||||
@@ -559,38 +587,31 @@ if [[ -z ${USER} ]]; then
|
||||
USER=$(whoami)
|
||||
fi
|
||||
|
||||
# Check if the current user is neither root nor pihole and if the command
|
||||
# Check if the current user is not root and if the command
|
||||
# requires root. If so, exit with an error message.
|
||||
if [[ $EUID -ne 0 && ${USER} != "pihole" && need_root -eq 1 ]];then
|
||||
echo -e " ${CROSS} The Pi-hole command requires root privileges, try:"
|
||||
# Add an exception for the user "pihole" to allow the webserver running gravity
|
||||
if [[ ( $EUID -ne 0 && ${USER} != "pihole" ) && -n "${need_root}" ]]; then
|
||||
echo -e " ${CROSS} This Pi-hole command requires root privileges, try:"
|
||||
echo -e " ${COL_GREEN}sudo pihole $*${COL_NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Handle redirecting to specific functions based on arguments
|
||||
case "${1}" in
|
||||
"allow" | "allowlist" ) listFunc "$@";;
|
||||
"deny" | "denylist" ) listFunc "$@";;
|
||||
"--wild" | "wildcard" ) listFunc "$@";;
|
||||
"--regex" | "regex" ) listFunc "$@";;
|
||||
"--allow-regex" | "allow-regex" ) listFunc "$@";;
|
||||
"--allow-wild" | "allow-wild" ) listFunc "$@";;
|
||||
"-d" | "debug" ) debugFunc "$@";;
|
||||
"-f" | "flush" ) flushFunc "$@";;
|
||||
"-up" | "updatePihole" ) updatePiholeFunc "$@";;
|
||||
"-r" | "reconfigure" ) reconfigurePiholeFunc;;
|
||||
"-r" | "repair" ) repairPiholeFunc;;
|
||||
"-g" | "updateGravity" ) updateGravityFunc "$@";;
|
||||
"-l" | "logging" ) piholeLogging "$@";;
|
||||
"uninstall" ) uninstallFunc;;
|
||||
"enable" ) piholeEnable true "$2";;
|
||||
"disable" ) piholeEnable false "$2";;
|
||||
"reloaddns" ) reloadDNS "reload";;
|
||||
"reloadlists" ) reloadDNS "reload-lists";;
|
||||
"setpassword" ) SetWebPassword "$@";;
|
||||
"checkout" ) piholeCheckoutFunc "$@";;
|
||||
"updatechecker" ) shift; updateCheckFunc "$@";;
|
||||
"arpflush" ) arpFunc "$@";;
|
||||
"arpflush" ) arpFunc "$@";; # Deprecated, use networkflush instead
|
||||
"networkflush" ) networkFlush "$@";;
|
||||
"-t" | "tail" ) tailFunc "$2";;
|
||||
"api" ) apiFunc "$2";;
|
||||
* ) helpFunc;;
|
||||
esac
|
||||
|
||||
19
test/_centos_10.Dockerfile
Normal file
19
test/_centos_10.Dockerfile
Normal file
@@ -0,0 +1,19 @@
|
||||
FROM quay.io/centos/centos:stream10
|
||||
# Disable SELinux
|
||||
RUN echo "SELINUX=disabled" > /etc/selinux/config
|
||||
RUN yum install -y --allowerasing curl git initscripts
|
||||
|
||||
ENV GITDIR=/etc/.pihole
|
||||
ENV SCRIPTDIR=/opt/pihole
|
||||
|
||||
RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole
|
||||
ADD . $GITDIR
|
||||
RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $GITDIR/advanced/Scripts/COL_TABLE $SCRIPTDIR/
|
||||
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR
|
||||
|
||||
RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
@@ -15,6 +15,5 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
||||
@@ -12,6 +12,5 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
||||
@@ -12,6 +12,5 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
||||
@@ -13,6 +13,5 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
||||
@@ -13,6 +13,5 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
FROM buildpack-deps:lunar-scm
|
||||
FROM fedora:42
|
||||
RUN dnf install -y git initscripts
|
||||
|
||||
ENV GITDIR=/etc/.pihole
|
||||
ENV SCRIPTDIR=/opt/pihole
|
||||
@@ -7,12 +8,10 @@ RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole
|
||||
ADD . $GITDIR
|
||||
RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $GITDIR/advanced/Scripts/COL_TABLE $SCRIPTDIR/
|
||||
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
@@ -12,6 +12,5 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
||||
@@ -13,6 +13,5 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
||||
@@ -13,6 +13,5 @@ RUN true && \
|
||||
chmod +x $SCRIPTDIR/*
|
||||
|
||||
ENV SKIP_INSTALL=true
|
||||
ENV OS_CHECK_DOMAIN_NAME=dev-supportedos.pi-hole.net
|
||||
|
||||
#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
pyyaml == 6.0.2
|
||||
pytest == 8.3.4
|
||||
pytest-xdist == 3.6.1
|
||||
pytest-testinfra == 10.1.1
|
||||
tox == 4.23.2
|
||||
pytest == 8.4.1
|
||||
pytest-xdist == 3.8.0
|
||||
pytest-testinfra == 10.2.2
|
||||
tox == 4.28.4
|
||||
pytest-clarity == 1.0.1
|
||||
|
||||
@@ -89,10 +89,8 @@ def test_installPihole_fresh_install_readableFiles(host):
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
umask 0027
|
||||
runUnattended=true
|
||||
useUpdateVars=true
|
||||
source /opt/pihole/basic-install.sh > /dev/null
|
||||
runUnattended=true
|
||||
useUpdateVars=true
|
||||
main
|
||||
/opt/pihole/pihole-FTL-prestart.sh
|
||||
"""
|
||||
@@ -119,11 +117,6 @@ def test_installPihole_fresh_install_readableFiles(host):
|
||||
assert exit_status_success == actual_rc
|
||||
check_leases = test_cmd.format("w", "/etc/pihole/dhcp.leases", piholeuser)
|
||||
actual_rc = host.run(check_leases).rc
|
||||
# readable dns-servers.conf
|
||||
assert exit_status_success == actual_rc
|
||||
check_servers = test_cmd.format("r", "/etc/pihole/dns-servers.conf", piholeuser)
|
||||
actual_rc = host.run(check_servers).rc
|
||||
assert exit_status_success == actual_rc
|
||||
# readable install.log
|
||||
check_install = test_cmd.format("r", "/etc/pihole/install.log", piholeuser)
|
||||
actual_rc = host.run(check_install).rc
|
||||
@@ -132,10 +125,6 @@ def test_installPihole_fresh_install_readableFiles(host):
|
||||
check_localversion = test_cmd.format("r", "/etc/pihole/versions", piholeuser)
|
||||
actual_rc = host.run(check_localversion).rc
|
||||
assert exit_status_success == actual_rc
|
||||
# readable logrotate
|
||||
check_logrotate = test_cmd.format("r", "/etc/pihole/logrotate", piholeuser)
|
||||
actual_rc = host.run(check_logrotate).rc
|
||||
assert exit_status_success == actual_rc
|
||||
# readable macvendor.db
|
||||
check_macvendor = test_cmd.format("r", "/etc/pihole/macvendor.db", piholeuser)
|
||||
actual_rc = host.run(check_macvendor).rc
|
||||
@@ -254,6 +243,7 @@ def test_FTL_detect_no_errors(host, arch, detected_string, supported):
|
||||
{
|
||||
"-A /bin/sh": ("Tag_CPU_arch: " + arch, "0"),
|
||||
"-A /usr/bin/sh": ("Tag_CPU_arch: " + arch, "0"),
|
||||
"-A /usr/sbin/sh": ("Tag_CPU_arch: " + arch, "0"),
|
||||
},
|
||||
host,
|
||||
)
|
||||
@@ -474,50 +464,6 @@ def test_validate_ip(host):
|
||||
test_address("0.0.0.0#00001", False)
|
||||
|
||||
|
||||
def test_os_check_fails(host):
|
||||
"""Confirms install fails on unsupported OS"""
|
||||
host.run(
|
||||
"""
|
||||
source /opt/pihole/basic-install.sh
|
||||
package_manager_detect
|
||||
build_dependency_package
|
||||
install_dependent_packages
|
||||
cat <<EOT > /etc/os-release
|
||||
ID=UnsupportedOS
|
||||
VERSION_ID="2"
|
||||
EOT
|
||||
"""
|
||||
)
|
||||
detectOS = host.run(
|
||||
"""t
|
||||
source /opt/pihole/basic-install.sh
|
||||
os_check
|
||||
"""
|
||||
)
|
||||
expected_stdout = "Unsupported OS detected: UnsupportedOS"
|
||||
assert expected_stdout in detectOS.stdout
|
||||
|
||||
|
||||
def test_os_check_passes(host):
|
||||
"""Confirms OS meets the requirements"""
|
||||
host.run(
|
||||
"""
|
||||
source /opt/pihole/basic-install.sh
|
||||
package_manager_detect
|
||||
build_dependency_package
|
||||
install_dependent_packages
|
||||
"""
|
||||
)
|
||||
detectOS = host.run(
|
||||
"""
|
||||
source /opt/pihole/basic-install.sh
|
||||
os_check
|
||||
"""
|
||||
)
|
||||
expected_stdout = "Supported OS detected"
|
||||
assert expected_stdout in detectOS.stdout
|
||||
|
||||
|
||||
def test_package_manager_has_pihole_deps(host):
|
||||
"""Confirms OS is able to install the required packages for Pi-hole"""
|
||||
mock_command("dialog", {"*": ("", "0")}, host)
|
||||
@@ -525,6 +471,7 @@ def test_package_manager_has_pihole_deps(host):
|
||||
"""
|
||||
source /opt/pihole/basic-install.sh
|
||||
package_manager_detect
|
||||
update_package_cache
|
||||
build_dependency_package
|
||||
install_dependent_packages
|
||||
"""
|
||||
@@ -541,6 +488,7 @@ def test_meta_package_uninstall(host):
|
||||
"""
|
||||
source /opt/pihole/basic-install.sh
|
||||
package_manager_detect
|
||||
update_package_cache
|
||||
build_dependency_package
|
||||
install_dependent_packages
|
||||
"""
|
||||
|
||||
10
test/tox.centos_10.ini
Normal file
10
test/tox.centos_10.ini
Normal file
@@ -0,0 +1,10 @@
|
||||
[tox]
|
||||
envlist = py3
|
||||
|
||||
[testenv:py3]
|
||||
allowlist_externals = docker
|
||||
deps = -rrequirements.txt
|
||||
setenv =
|
||||
COLUMNS=120
|
||||
commands = docker buildx build --load --progress plain -f _centos_10.Dockerfile -t pytest_pihole:test_container ../
|
||||
pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py
|
||||
10
test/tox.fedora_42.ini
Normal file
10
test/tox.fedora_42.ini
Normal file
@@ -0,0 +1,10 @@
|
||||
[tox]
|
||||
envlist = py3
|
||||
|
||||
[testenv]
|
||||
allowlist_externals = docker
|
||||
deps = -rrequirements.txt
|
||||
setenv =
|
||||
COLUMNS=120
|
||||
commands = docker buildx build --load --progress plain -f _fedora_42.Dockerfile -t pytest_pihole:test_container ../
|
||||
pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py
|
||||
Reference in New Issue
Block a user