Compare commits

...

150 Commits

Author SHA1 Message Date
Adam Warner
0034538794 v5.14.2 (#5040) 2022-11-27 21:31:19 +00:00
Dan Schaper
82dfcbcd83 Fix pihole updatecheck reboot (#5035) 2022-11-23 11:08:46 -08:00
RD WebDesign
233453267e Using shift to allow passing multiple arguments
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2022-11-23 15:33:49 -03:00
RD WebDesign
f3c27f706f Pass only the correct argument
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2022-11-23 14:07:30 -03:00
Dan Schaper
983d79b3e6 Don't install which (#5028) 2022-11-18 17:40:12 -08:00
Christian König
6d8abc2e30 Don't install which
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-11-18 23:50:34 +01:00
Adam Warner
38775cffdf Ensure local hash is always of length 8, for consistency.
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-11-14 22:51:39 +00:00
Adam Warner
b13a75a223 sync: master to development (#5017) 2022-11-14 22:46:26 +00:00
Adam Warner
21026d9414 Fix odd behaviour introduced into new version checking script (#5016) 2022-11-14 22:21:16 +00:00
Adam Warner
ba74051502 Grab local FTL hash correctly from FTL's own version output, and grab one digit less for remote hashes (also in debug log)
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-11-14 22:09:26 +00:00
Adam Warner
cdbe4c9b86 Get only the precise tag number when getting local version, do not show branch name when on master branch(es)
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-11-14 20:39:34 +00:00
Adam Warner
ca04c13315 sync: master to development (#5013) 2022-11-14 19:03:11 +00:00
Adam Warner
3c86af0e59 Pi-hole core v5.14 (#5012) 2022-11-14 19:00:40 +00:00
Adam Warner
ddaa1bf0d4 Correctly identify process status in debug script on docker (#5011) 2022-11-14 18:15:57 +00:00
Adam Warner
6b8ba3c15e Replace deprecated shell commands (#4907) 2022-11-14 17:52:31 +00:00
Christian König
7536c312ee Correctly identify process status in debug script on docker
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-11-13 21:53:59 +01:00
Adam Warner
a8b6eb9b70 Touch files before addKey or addOrEditKeyValPair (#4999) 2022-11-09 23:37:30 +00:00
Christian König
67385b7ed4 Touch files before addKey or addOrEditKeyValPair
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-11-09 21:25:09 +01:00
Adam Warner
64e61aac4a Simplify versions.sh (#4959) 2022-11-09 17:15:51 +00:00
Christian König
2fd5b944ad Touch setupVars before writing to it
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-11-03 22:09:12 +01:00
Dan Schaper
f91606bb17 Fix static IP not set because of in-line comment in dhcpcd.conf (#4998) 2022-11-02 15:17:36 -07:00
Stephan Pillhofer
122bc6b927 Fix static IP not set because of in-line comment
Signed-off-by: Stephan Pillhofer <43667664+StephanPillhofer@users.noreply.github.com>
2022-11-02 22:35:39 +01:00
Dan Schaper
3491dbfd04 Check versions file on the debug log (#4977) 2022-10-31 13:25:15 -07:00
Dan Schaper
871067acd8 Fix static IP not set if IP is already present in any way inside dhcpcd.conf (#4995)
Use grep and regex to find uncommented use of `static ip_address` with IP.
2022-10-31 13:23:35 -07:00
Stephan Pillhofer
06cf7afbc2 Fix static IP not set
Signed-off-by: Stephan Pillhofer <43667664+StephanPillhofer@users.noreply.github.com>
2022-10-30 20:19:38 +01:00
yubiuser
01bf9ca42a Prevent CNAME loop (#4988) 2022-10-29 15:44:03 +02:00
Christian König
c8c6533440 Add small explanation.
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-29 15:09:14 +02:00
Dan Schaper
f1b15f7e92 Remove check for latest component version in debug log (#4973) 2022-10-28 17:27:05 -07:00
DL6ER
e0c351f0e4 Remove unused possibility to obfuscate pihole.log in debug log (#4974) 2022-10-28 13:16:30 -04:00
DL6ER
7957acf42f Remove unused old code from gravity.sh (#4985) 2022-10-28 13:15:02 -04:00
Dan Schaper
c3e8d76d63 Escape dots in local DNS records/CNAMES before removing them (#4990) 2022-10-24 13:21:07 -07:00
Christian König
128a3ab1be Go POSIX
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-22 22:39:42 +02:00
Christian König
df3e9e5f51 Disable shellcheck as it suggests a bashism
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-22 22:25:40 +02:00
Christian König
c322458dcb Escape dots in local DNS records/CNAMES before removing them
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-21 13:02:21 +02:00
Christian König
21be1bd58e Prevent CNAME loop
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-20 07:29:14 +02:00
Adam Warner
469a267150 Adding CentOS Stream 9 tests (#4984) 2022-10-19 19:14:00 +01:00
RD WebDesign
090727b1d3 Remove unnecessary return
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2022-10-17 15:24:49 -03:00
RD WebDesign
85ffbcf05e Allow replacing conflicting existing packages from testing image
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2022-10-17 14:58:42 -03:00
RD WebDesign
528abc9c97 Adding CentOS Stream 9 tests
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2022-10-16 19:36:56 -03:00
RD WebDesign
8b98fd06ed Remove unused old code
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2022-10-16 15:54:24 -03:00
Adam Warner
bc6fb0c934 sync: master to development (#4981) 2022-10-15 15:46:53 +01:00
Adam Warner
e773e3302c Bump actions/setup-python from 4.2.0 to 4.3.0 (#4980) 2022-10-15 15:45:44 +01:00
Adam Warner
0cf59cf0fa Bump actions/setup-python from 4.2.0 to 4.3.0
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.2.0 to 4.3.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](actions/setup-python@v4.2.0...v4.3.0)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-minor
...


Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-10-15 15:36:20 +01:00
Adam Warner
bc471cb0bd Fix errors in README.md (#4818) 2022-10-15 15:06:06 +01:00
Adam Warner
429510e168 Update README.md
Signed-off-by: Adam Warner <github@adamwarner.co.uk>
2022-10-15 15:03:35 +01:00
Christian König
4c9401175c Remove check for latest version
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-15 09:06:57 +02:00
Christian König
235673dac8 Remove unused possibility to obfuscate pihole.log
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-15 08:58:12 +02:00
RD WebDesign
d737948f64 Add versions file to the REQUIRED_FILES list
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2022-10-14 14:11:19 -03:00
Christian König
52283478c8 Run pihole updatechecker if versions file is not found
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-14 13:26:06 +02:00
Christian König
c84be5de61 Reorganize by component rather then source
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-14 13:18:12 +02:00
Christian König
d85982dc51 Use versions file instead of github api to get latest version
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-14 10:29:14 +02:00
Christian König
5c61f6cb65 Remove checkout hint
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-14 08:43:39 +02:00
Christian König
4c0a94d2b9 Don't rely on pihole -v output but query github to get the lastest versions in debug script
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-13 14:44:13 +02:00
MichaIng
5c090d25e1 Fix ldd sh mock in tests
Since "command" is a shell internal, it cannot be mocked, done via /usr/local/bin override. Since Debian containers ship without /bin => /usr/bin symlink, while all other containers do, the "ldd" mock needs to be applied for both paths, then.

Signed-off-by: MichaIng <micha@dietpi.com>
2022-10-12 12:49:50 +02:00
Adam Warner
89c0706abc master -> dev (#4970) 2022-10-12 11:32:30 +01:00
a1346054
e5695f862f test_any_automated_install.py: Use command -v instead of which
Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com>
2022-10-11 14:36:26 +00:00
a1346054
e3db5fc601 basic-install.sh: Use command -v instead of which
`command -v` is the standardized version of `which` and doesn't require
any extra packages

Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com>
2022-10-11 14:33:30 +00:00
a1346054
9c51050283 basic-install.sh: Use grep -E instead of egrep
Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com>
2022-10-11 14:33:30 +00:00
Adam Warner
17779bad94 Pi-hole v5.13 (#4960) 2022-10-10 22:00:47 +01:00
Dan Schaper
fed58f03bf Fix pihole -r dialog exit (#4965) 2022-10-09 21:10:23 -07:00
RD WebDesign
c5b3b8dd68 Fix pihole -r dialog exit
- if an option is selected: Get option (repair/reconfigure);
- if exit or ESC: Get exit code (1/255)

Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2022-10-10 00:27:03 -03:00
Adam Warner
46986714d4 Bump actions/stale from 6.0.0 to 6.0.1 (#4963) 2022-10-09 20:03:21 +01:00
Adam Warner
4f3debcb5b Bump actions/checkout from 3.0.2 to 3.1.0 (#4964) 2022-10-09 20:03:10 +01:00
dependabot[bot]
223ef72250 Bump actions/checkout from 3.0.2 to 3.1.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 3.0.2 to 3.1.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3.0.2...v3.1.0)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-09 18:46:02 +00:00
dependabot[bot]
cf467db61d Bump actions/stale from 6.0.0 to 6.0.1
Bumps [actions/stale](https://github.com/actions/stale) from 6.0.0 to 6.0.1.
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/stale/compare/v6.0.0...v6.0.1)

---
updated-dependencies:
- dependency-name: actions/stale
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-09 18:45:54 +00:00
Adam Warner
fae1d13892 Add initscripts to CentOS8 dockerfile (#4966) 2022-10-09 19:45:13 +01:00
Christian König
4265bcb178 Add initscripts to CentOS8 dockerfile
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-08 22:08:39 +02:00
Christian König
9471c69882 Fix spelling
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-07 09:34:05 +02:00
Christian König
79c0b446e1 Set missing data to N/A
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-06 21:55:49 +02:00
Christian König
a478f2460b POSIX
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-06 21:50:07 +02:00
Christian König
2dc599f266 Simplify version.sh
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-06 17:58:58 +02:00
Christian König
d7f7ef9965 Only create VERSION_FILE if it does not exist
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-06 14:37:56 +02:00
Christian König
888e44e53d Add hash functions to updatecheck
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-06 14:34:34 +02:00
Christian König
18d28533eb Update local and remote versions at the same time
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-06 12:36:17 +02:00
Christian König
56527e5dd9 Add get_remote_version() to updatechecker
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-06 12:03:12 +02:00
Adam Warner
997a771dc8 Fix Deepsource.io warning message for index.php file (#4953) 2022-10-01 22:57:32 +01:00
Adam Warner
77f0012f6b Fix default DHCPv4 leasetime value (#4956) 2022-10-01 22:50:39 +01:00
Adam Warner
b7b5ffa8dd remove old code per review from @yubiuser and @dschaper
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-10-01 22:31:03 +01:00
Adam Warner
34b66002e9 leasetime (local) should have an h after it to signify 24h lease, else it will be read as two minutes (minimum integer value)
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-10-01 22:31:00 +01:00
Dan Schaper
71b560667b Add Fedora 35 and 36, remove 34 to/from the test suite (#4952) 2022-10-01 13:43:13 -07:00
Adam Warner
9dd51b79b5 Remove pihole-FTL.port file (#4945) 2022-10-01 14:30:23 +01:00
Adam Warner
7fd062c4d8 Update Amazon support URL to HTTPS in README (#4954) 2022-10-01 14:28:26 +01:00
Christian König
3731b65bd5 Remoce Fedora 34 from tests
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-01 10:04:26 +02:00
Christian König
6057b134ae Add initscripts to Fedora 35 and 36 dockerfile
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-10-01 10:03:13 +02:00
David Beitey
0749de3d1f Update Amazon support URL to HTTPS in README
Signed-off-by: David Beitey <david@davidjb.com>
2022-10-01 09:39:04 +10:00
RD WebDesign
d48c557134 Fix Deepsource warning message for index.php file
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2022-09-30 17:13:08 -03:00
Christian König
a705fbca73 Add Fedora 35 and 36 to the test suite
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-29 19:13:23 +02:00
Christian König
276c480f50 Return default port if non-numeric characters are set in pihole-FTL.conf for FTLPORT. FTL does the same in such case and provide the API on 4711
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-26 23:40:09 +02:00
Christian König
25ba68104b Remove last traces
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-26 22:55:34 +02:00
Christian König
3d01e4d0cf No detour - use pihole-FTL.conf to get the API port number
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-26 22:55:30 +02:00
Adam Warner
1b0b0ca445 Update python tests and add black code formatter action (#4926) 2022-09-26 20:00:27 +01:00
Christian König
e1a2591c4d Format test.yml
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-26 10:40:39 +02:00
Dan Schaper
f8a12917e2 Handle more than one default gateway in debug script (#4934) 2022-09-25 11:09:26 -07:00
Dan Schaper
37b45d411d Read docker tag from file in root, not the previously set environment variable (#4929) 2022-09-25 11:05:08 -07:00
Christian König
22ebf21487 Use POSIX
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-25 18:20:01 +02:00
Christian König
bf5fffaca7 Better wording and test with color
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-25 18:03:44 +02:00
Adam Warner
9debd22179 If, after reading /pihole.docker.tag into DOCKER_TAG, it does not match an expected pattern, unset it - this should prevent arbitary code from being run
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-09-25 15:51:09 +01:00
Dan Schaper
a8ce1354c8 Set connection timeout for curl (#4884) 2022-09-24 18:19:15 -07:00
Adam Warner
0a780a959a Fix issue in #4872 missed in review (#4940) 2022-09-24 16:18:49 +01:00
Peter Russell
951b4ed002 Remove cronjob that checks local versions every 10 minutes - only check when required (#4939)
* eliminate updatechecker local from pihole cron job

Signed-off-by: jpgpi250 <jpgpi250@gmail.com>

* resolving stickler-ci items

Signed-off-by: jpgpi250 <jpgpi250@gmail.com>

* undo changes to updatecheck.sh (request from PromoFaux)

Signed-off-by: jpgpi250 <jpgpi250@gmail.com>

* applied recommendation from PromoFaux

Signed-off-by: jpgpi250 <jpgpi250@gmail.com>

* Indent the code inside the function

Signed-off-by: jpgpi250 <jpgpi250@gmail.com>

* removed unnecessary updatecheck for core

Signed-off-by: jpgpi250 <jpgpi250@gmail.com>

* eliminate updatechecker local from pihole cron job

Co-authored-by: jpgpi250 <jpgpi250@gmail.com>
Signed-off-by: Adam Warner <me@adamwarner.co.uk>

Signed-off-by: jpgpi250 <jpgpi250@gmail.com>
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
Co-authored-by: Adam Warner <me@adamwarner.co.uk>
2022-09-24 16:14:44 +01:00
Adam Warner
755ec8bf2f $$ != $
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-09-24 16:08:45 +01:00
Adam Warner
1c1407e083 Use utils.sh in install script (#4872) 2022-09-24 14:00:22 +01:00
Adam Warner
9463c3c69f Change wording in chronometer (#4910) 2022-09-24 13:53:08 +01:00
Adam Warner
54bcf5626f Bump actions/stale from 5.2.0 to 6.0.0 (#4938) 2022-09-24 13:07:51 +01:00
dependabot[bot]
ba8a50c829 Bump actions/stale from 5.2.0 to 6.0.0
Bumps [actions/stale](https://github.com/actions/stale) from 5.2.0 to 6.0.0.
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/stale/compare/v5.2.0...v6.0.0)

---
updated-dependencies:
- dependency-name: actions/stale
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-09-24 10:08:26 +00:00
Christian König
bb57a9e616 Handle more than one default gateway in debug script
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-22 22:33:11 +02:00
yubiuser
4f4dfe3ac0 Fix tabs in dialog boxes (#4932) 2022-09-22 22:02:45 +02:00
Christian König
d4ce5b1c2a Fix tabs in dialog boxes
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-22 14:49:25 +02:00
Adam Warner
b6d1bd7335 Read docker tag from file in root, not the previously set environment variable
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-09-19 22:01:05 +01:00
Christian König
17ec88d96f Remove installed_binary variable which was leftover from https://github.com/pi-hole/pi-hole/pull/4893
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-19 14:50:35 +02:00
Christian König
0df38cd64e Format all /test files with black
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-19 14:50:35 +02:00
Christian König
0932c5c498 Add black python code formatter action
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-19 14:50:35 +02:00
Christian König
73ca4ebdbc Update test requirements
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-19 14:50:35 +02:00
Adam Warner
da6596e516 Master -> Dev (#4925) 2022-09-19 11:15:59 +01:00
Adam Warner
d88629e23f v5.12.2 (#4922) 2022-09-19 11:00:09 +01:00
yubiuser
d581401f4e Fix gravity database integrity check (#4921) 2022-09-18 13:35:03 +02:00
Christian König
60c35cb93c Remove unused check_database_integrity()
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-18 13:08:44 +02:00
Christian König
2c3fea321b Remove FAQ_ULA as it is unused in core
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-18 09:10:24 +02:00
Christian König
40f00c6f0b Fix gravity database integrity check
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-18 09:01:22 +02:00
Christian König
00e51f32b5 Blcked => Block
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-17 16:46:31 +02:00
Christian König
f90fb8b946 Change wording in chronometer
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-17 16:24:31 +02:00
yubiuser
2ff1fa1b85 Merge branch 'development' into use_utils 2022-09-17 16:14:31 +02:00
yubiuser
7eff36b3bb Update workflow python to 3.10 and allow any python3 version in tests (#4914) 2022-09-17 16:13:48 +02:00
yubiuser
5332b31b92 Add comment in lighttpd.conf how to change the server port (#4917) 2022-09-17 14:05:13 +02:00
yubiuser
16640ee174 Bump actions/stale from 5.1.1 to 5.2.0 (#4918) 2022-09-17 14:04:25 +02:00
dependabot[bot]
5fe170666a Bump actions/stale from 5.1.1 to 5.2.0
Bumps [actions/stale](https://github.com/actions/stale) from 5.1.1 to 5.2.0.
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/stale/compare/v5.1.1...v5.2.0)

---
updated-dependencies:
- dependency-name: actions/stale
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-09-17 10:08:40 +00:00
Christian König
7e6f81f814 Add comment in lighttpd.conf how to change the server port
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-17 12:00:33 +02:00
yubiuser
80c770357c Fixing texts forgotten after Blocking Page removal (#4915) 2022-09-16 08:25:15 +02:00
RD WebDesign
5cc317de5b Change texts after Block Page removal
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
2022-09-16 03:16:54 -03:00
Adam Warner
515e5f8c8a Store docker version in versions file (If PIHOLE_DOCKER_TAG variable is set) (#4913) 2022-09-15 18:05:42 +01:00
Adam Warner
3d53bda121 Update advanced/Scripts/updatecheck.sh
Co-authored-by: yubiuser <ckoenig@posteo.de>
Signed-off-by: Adam Warner <github@adamwarner.co.uk>
2022-09-15 17:54:54 +01:00
Christian König
8bc5b16527 Set tox envlist to py3
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-15 13:55:45 +02:00
Christian König
c1a927fff1 Run test workflows on python 3.10
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-15 13:55:45 +02:00
Adam Warner
760325eb76 Update piholeDebug to source versions file for DOCKER_VERSION instead of reading PIHOLE_DOCKER_TAG
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-09-14 22:49:37 +01:00
Adam Warner
bf256aa5a7 If docker version env var is set, store it in /etc/pihole/versions file for later use
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-09-14 22:38:41 +01:00
Adam Warner
8dbe6fc0b7 master-> Dev (#4912) 2022-09-14 22:08:15 +01:00
Adam Warner
fe8b0e98ab v5.12.1 (#4908) 2022-09-14 21:28:44 +01:00
yubiuser
ef45578af3 Fix 4898 (#4899) 2022-09-06 19:43:24 +02:00
Christian König
89b88416b3 Fix 4898
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-06 17:09:52 +02:00
Adam Warner
5d913ad192 Release 5.12 (#4889) (#4897) 2022-09-05 08:48:37 +01:00
yubiuser
711035fd8f Update FTL Binary test to ensure we catch incompatibility issues early (#4893) 2022-09-03 14:44:16 +02:00
Adam Warner
0f74165c9d Drop Ubuntu 18 tests
Tweek version_check to only output 1st char of the reported version

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-09-03 12:55:17 +01:00
Adam Warner
46e1a87e9e Tweak FTL test to ensure we don't get false positives on incompatible OS (Will remote Ub18 in a separate commit)
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-09-03 12:09:37 +01:00
Christian König
230d6a435f Semi hardcode the connection_timeout value
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-08-31 21:41:57 +02:00
Christian König
53c0982c8b Set connection timeout for curl
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-08-31 14:43:20 +02:00
Christian König
9b5ea13a33 Use utils.sh in install script
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-08-24 08:49:20 +02:00
Rauf Shimarov
c90d8284ef Update README.md
Signed-off-by: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com>
2022-07-12 16:20:17 -07:00
Rauf Shimarov
7ab9664255 Update README.md
Co-authored-by: Adam Warner <github@adamwarner.co.uk>

Signed-off-by: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com>
2022-07-11 14:55:15 -07:00
Rauf Shimarov
3a22657645 Update README.md
Co-authored-by: Adam Warner <github@adamwarner.co.uk>

Signed-off-by: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com>
2022-07-11 14:54:19 -07:00
Rauf Shimarov
4567f264b4 Fix errors in README.md
Signed-off-by: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com>
2022-07-11 11:45:09 -07:00
43 changed files with 1235 additions and 1210 deletions

View File

@@ -25,7 +25,7 @@ jobs:
steps: steps:
- -
name: Checkout repository name: Checkout repository
uses: actions/checkout@v3.0.2 uses: actions/checkout@v3.1.0
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- -
name: Initialize CodeQL name: Initialize CodeQL

View File

@@ -13,7 +13,7 @@ jobs:
issues: write issues: write
steps: steps:
- uses: actions/stale@v5.1.1 - uses: actions/stale@v6.0.1
with: with:
repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 30 days-before-stale: 30

View File

@@ -11,7 +11,7 @@ jobs:
name: Syncing branches name: Syncing branches
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3.0.2 uses: actions/checkout@v3.1.0
- name: Opening pull request - name: Opening pull request
id: pull id: pull
uses: tretuna/sync-branches@1.4.0 uses: tretuna/sync-branches@1.4.0

View File

@@ -12,29 +12,33 @@ jobs:
if: github.event.pull_request.draft == false if: github.event.pull_request.draft == false
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- - name: Checkout repository
name: Checkout repository uses: actions/checkout@v3.1.0
uses: actions/checkout@v3.0.2
-
name: Check scripts in repository are executable
run: |
IFS=$'\n';
for f in $(find . -name '*.sh'); do if [[ ! -x $f ]]; then echo "$f is not executable" && FAIL=1; fi ;done
unset IFS;
# If FAIL is 1 then we fail.
[[ $FAIL == 1 ]] && exit 1 || echo "Scripts are executable!"
-
name: Spell-Checking
uses: codespell-project/actions-codespell@master
with:
ignore_words_file: .codespellignore
-
name: Get editorconfig-checker
uses: editorconfig-checker/action-editorconfig-checker@main # tag v1.0.0 is really out of date
-
name: Run editorconfig-checker
run: editorconfig-checker
- name: Check scripts in repository are executable
run: |
IFS=$'\n';
for f in $(find . -name '*.sh'); do if [[ ! -x $f ]]; then echo "$f is not executable" && FAIL=1; fi ;done
unset IFS;
# If FAIL is 1 then we fail.
[[ $FAIL == 1 ]] && exit 1 || echo "Scripts are executable!"
- name: Spell-Checking
uses: codespell-project/actions-codespell@master
with:
ignore_words_file: .codespellignore
- name: Get editorconfig-checker
uses: editorconfig-checker/action-editorconfig-checker@main # tag v1.0.0 is really out of date
- name: Run editorconfig-checker
run: editorconfig-checker
- name: Check python code formatting with black
uses: psf/black@stable
with:
src: "./test"
options: "--check --diff --color"
distro-test: distro-test:
if: github.event.pull_request.draft == false if: github.event.pull_request.draft == false
@@ -43,21 +47,30 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
distro: [debian_10, debian_11, ubuntu_18, ubuntu_20, ubuntu_22, centos_8, fedora_34] distro:
[
debian_10,
debian_11,
ubuntu_20,
ubuntu_22,
centos_8,
centos_9,
fedora_35,
fedora_36,
]
env: env:
DISTRO: ${{matrix.distro}} DISTRO: ${{matrix.distro}}
steps: steps:
- - name: Checkout repository
name: Checkout repository uses: actions/checkout@v3.1.0
uses: actions/checkout@v3.0.2
- - name: Set up Python 3.10
name: Set up Python 3.8 uses: actions/setup-python@v4.3.0
uses: actions/setup-python@v4.2.0 with:
with: python-version: "3.10"
python-version: 3.8
- - name: Install dependencies
name: Install dependencies run: pip install -r test/requirements.txt
run: pip install -r test/requirements.txt
- - name: Test with tox
name: Test with tox run: tox -c test/tox.${DISTRO}.ini
run: tox -c test/tox.${DISTRO}.ini

View File

@@ -16,11 +16,11 @@
The Pi-hole® is a [DNS sinkhole](https://en.wikipedia.org/wiki/DNS_Sinkhole) that protects your devices from unwanted content without installing any client-side software. The Pi-hole® is a [DNS sinkhole](https://en.wikipedia.org/wiki/DNS_Sinkhole) that protects your devices from unwanted content without installing any client-side software.
- **Easy-to-install**: our versatile installer walks you through the process and takes less than ten minutes - **Easy-to-install**: our dialogs walk you through the simple installation process in less than ten minutes
- **Resolute**: content is blocked in _non-browser locations_, such as ad-laden mobile apps and smart TVs - **Resolute**: content is blocked in _non-browser locations_, such as ad-laden mobile apps and smart TVs
- **Responsive**: seamlessly speeds up the feel of everyday browsing by caching DNS queries - **Responsive**: seamlessly speeds up the feel of everyday browsing by caching DNS queries
- **Lightweight**: runs smoothly with [minimal hardware and software requirements](https://docs.pi-hole.net/main/prerequisites/) - **Lightweight**: runs smoothly with [minimal hardware and software requirements](https://docs.pi-hole.net/main/prerequisites/)
- **Robust**: a command line interface that is quality assured for interoperability - **Robust**: a command-line interface that is quality assured for interoperability
- **Insightful**: a beautiful responsive Web Interface dashboard to view and control your Pi-hole - **Insightful**: a beautiful responsive Web Interface dashboard to view and control your Pi-hole
- **Versatile**: can optionally function as a [DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026), ensuring _all_ your devices are protected automatically - **Versatile**: can optionally function as a [DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026), ensuring _all_ your devices are protected automatically
- **Scalable**: [capable of handling hundreds of millions of queries](https://pi-hole.net/2017/05/24/how-much-traffic-can-pi-hole-handle/) when installed on server-grade hardware - **Scalable**: [capable of handling hundreds of millions of queries](https://pi-hole.net/2017/05/24/how-much-traffic-can-pi-hole-handle/) when installed on server-grade hardware
@@ -60,7 +60,7 @@ Please refer to the [Pi-hole docker repo](https://github.com/pi-hole/docker-pi-h
## [Post-install: Make your network take advantage of Pi-hole](https://docs.pi-hole.net/main/post-install/) ## [Post-install: Make your network take advantage of Pi-hole](https://docs.pi-hole.net/main/post-install/)
Once the installer has been run, you will need to [configure your router to have **DHCP clients use Pi-hole as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245) which ensures that all devices connecting to your network will have content blocked without any further intervention. Once the installer has been run, you will need to [configure your router to have **DHCP clients use Pi-hole as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245). This router configuration will ensure that all devices connecting to your network will have content blocked without any further intervention.
If your router does not support setting the DNS server, you can [use Pi-hole's built-in DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026); be sure to disable DHCP on your router first (if it has that feature available). If your router does not support setting the DNS server, you can [use Pi-hole's built-in DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026); be sure to disable DHCP on your router first (if it has that feature available).
@@ -70,7 +70,7 @@ As a last resort, you can manually set each device to use Pi-hole as their DNS s
## Pi-hole is free but powered by your support ## Pi-hole is free but powered by your support
There are many reoccurring costs involved with maintaining free, open source, and privacy-respecting software; expenses which [our volunteer developers](https://github.com/orgs/pi-hole/people) pitch in to cover out-of-pocket. This is just one example of how strongly we feel about our software and the importance of keeping it maintained. There are many reoccurring costs involved with maintaining free, open-source, and privacy-respecting software; expenses which [our volunteer developers](https://github.com/orgs/pi-hole/people) pitch in to cover out-of-pocket. This is just one example of how strongly we feel about our software and the importance of keeping it maintained.
Make no mistake: **your support is absolutely vital to help keep us innovating!** Make no mistake: **your support is absolutely vital to help keep us innovating!**
@@ -87,7 +87,7 @@ If you'd rather not donate (_which is okay!_), there are other ways you can help
- [Hetzner Cloud](https://hetzner.cloud/?ref=7aceisRX3AzA) _affiliate link_ - [Hetzner Cloud](https://hetzner.cloud/?ref=7aceisRX3AzA) _affiliate link_
- [Digital Ocean](https://www.digitalocean.com/?refcode=344d234950e1) _affiliate link_ - [Digital Ocean](https://www.digitalocean.com/?refcode=344d234950e1) _affiliate link_
- [Stickermule](https://www.stickermule.com/unlock?ref_id=9127301701&utm_medium=link&utm_source=invite) _earn a $10 credit after your first purchase_ - [Stickermule](https://www.stickermule.com/unlock?ref_id=9127301701&utm_medium=link&utm_source=invite) _earn a $10 credit after your first purchase_
- [Amazon US](http://www.amazon.com/exec/obidos/redirect-home/pihole09-20) _affiliate link_ - [Amazon US](https://www.amazon.com/exec/obidos/redirect-home/pihole09-20) _affiliate link_
- Spreading the word about our software and how you have benefited from it - Spreading the word about our software and how you have benefited from it
### Contributing via GitHub ### Contributing via GitHub
@@ -132,9 +132,9 @@ Some of the statistics you can integrate include:
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 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).
### The Command Line Interface ### The Command-Line Interface
The [pihole](https://docs.pi-hole.net/core/pihole-command/) command has all the functionality necessary to fully administer the Pi-hole, without the need of the Web Interface. It's fast, user-friendly, and auditable by anyone with an understanding of `bash`. The [pihole](https://docs.pi-hole.net/core/pihole-command/) command has all the functionality necessary to fully administer the Pi-hole, without the need for the Web Interface. It's fast, user-friendly, and auditable by anyone with an understanding of `bash`.
Some notable features include: Some notable features include:

View File

@@ -29,13 +29,6 @@ bogus-priv
no-resolv no-resolv
server=@DNS1@
server=@DNS2@
interface=@INT@
cache-size=@CACHE_SIZE@
log-queries log-queries
log-facility=/var/log/pihole/pihole.log log-facility=/var/log/pihole/pihole.log

View File

@@ -14,7 +14,9 @@ LC_NUMERIC=C
# Retrieve stats from FTL engine # Retrieve stats from FTL engine
pihole-FTL() { pihole-FTL() {
local ftl_port LINE local ftl_port LINE
ftl_port=$(cat /run/pihole-FTL.port 2> /dev/null) # shellcheck disable=SC1091
. /opt/pihole/utils.sh
ftl_port=$(getFTLAPIPort)
if [[ -n "$ftl_port" ]]; then if [[ -n "$ftl_port" ]]; then
# Open connection to FTL # Open connection to FTL
exec 3<>"/dev/tcp/127.0.0.1/$ftl_port" exec 3<>"/dev/tcp/127.0.0.1/$ftl_port"
@@ -503,11 +505,11 @@ chronoFunc() {
fi fi
printFunc " Pi-hole: " "$ph_status" "$ph_info" printFunc " Pi-hole: " "$ph_status" "$ph_info"
printFunc " Ads Today: " "$ads_percentage_today%" "$ads_info" printFunc " Blocked: " "$ads_percentage_today%" "$ads_info"
printFunc "Local Qrys: " "$queries_cached_percentage%" "$dns_info" printFunc "Local Qrys: " "$queries_cached_percentage%" "$dns_info"
printFunc " Blocked: " "$recent_blocked" printFunc "Last Block: " "$recent_blocked"
printFunc "Top Advert: " "$top_ad" printFunc " Top Block: " "$top_ad"
# Provide more stats on screens with more lines # Provide more stats on screens with more lines
if [[ "$scr_lines" -eq 17 ]]; then if [[ "$scr_lines" -eq 17 ]]; then

View File

@@ -164,6 +164,8 @@ checkout() {
exit 1 exit 1
fi fi
checkout_pull_branch "${webInterfaceDir}" "${2}" checkout_pull_branch "${webInterfaceDir}" "${2}"
# Update local and remote versions via updatechecker
/opt/pihole/updatecheck.sh
elif [[ "${1}" == "ftl" ]] ; then elif [[ "${1}" == "ftl" ]] ; then
local path local path
local oldbranch local oldbranch
@@ -178,6 +180,8 @@ checkout() {
FTLinstall "${binary}" FTLinstall "${binary}"
restart_service pihole-FTL restart_service pihole-FTL
enable_service pihole-FTL enable_service pihole-FTL
# Update local and remote versions via updatechecker
/opt/pihole/updatecheck.sh
else else
echo " ${CROSS} Requested branch \"${2}\" is not available" echo " ${CROSS} Requested branch \"${2}\" is not available"
ftlbranches=( $(git ls-remote https://github.com/pi-hole/ftl | grep 'heads' | sed 's/refs\/heads\///;s/ //g' | awk '{print $2}') ) ftlbranches=( $(git ls-remote https://github.com/pi-hole/ftl | grep 'heads' | sed 's/refs\/heads\///;s/ //g' | awk '{print $2}') )

View File

@@ -41,18 +41,15 @@ else
#OVER="\r\033[K" #OVER="\r\033[K"
fi fi
OBFUSCATED_PLACEHOLDER="<DOMAIN OBFUSCATED>" # shellcheck disable=SC1091
. /etc/pihole/versions
# FAQ URLs for use in showing the debug log # FAQ URLs for use in showing the debug log
FAQ_UPDATE_PI_HOLE="${COL_CYAN}https://discourse.pi-hole.net/t/how-do-i-update-pi-hole/249${COL_NC}"
FAQ_CHECKOUT_COMMAND="${COL_CYAN}https://discourse.pi-hole.net/t/the-pihole-command-with-examples/738#checkout${COL_NC}"
FAQ_HARDWARE_REQUIREMENTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/${COL_NC}" 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}" FAQ_HARDWARE_REQUIREMENTS_PORTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#ports${COL_NC}"
FAQ_HARDWARE_REQUIREMENTS_FIREWALLD="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#firewalld${COL_NC}" FAQ_HARDWARE_REQUIREMENTS_FIREWALLD="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#firewalld${COL_NC}"
FAQ_GATEWAY="${COL_CYAN}https://discourse.pi-hole.net/t/why-is-a-default-gateway-important-for-pi-hole/3546${COL_NC}" FAQ_GATEWAY="${COL_CYAN}https://discourse.pi-hole.net/t/why-is-a-default-gateway-important-for-pi-hole/3546${COL_NC}"
FAQ_ULA="${COL_CYAN}https://discourse.pi-hole.net/t/use-ipv6-ula-addresses-for-pi-hole/2127${COL_NC}"
FAQ_FTL_COMPATIBILITY="${COL_CYAN}https://github.com/pi-hole/FTL#compatibility-list${COL_NC}" FAQ_FTL_COMPATIBILITY="${COL_CYAN}https://github.com/pi-hole/FTL#compatibility-list${COL_NC}"
FAQ_BAD_ADDRESS="${COL_CYAN}https://discourse.pi-hole.net/t/why-do-i-see-bad-address-at-in-pihole-log/3972${COL_NC}"
# Other URLs we may use # Other URLs we may use
FORUMS_URL="${COL_CYAN}https://discourse.pi-hole.net${COL_NC}" FORUMS_URL="${COL_CYAN}https://discourse.pi-hole.net${COL_NC}"
@@ -71,7 +68,6 @@ WEB_SERVER_LOG_DIRECTORY="/var/log/lighttpd"
WEB_SERVER_CONFIG_DIRECTORY="/etc/lighttpd" WEB_SERVER_CONFIG_DIRECTORY="/etc/lighttpd"
HTML_DIRECTORY="/var/www/html" HTML_DIRECTORY="/var/www/html"
WEB_GIT_DIRECTORY="${HTML_DIRECTORY}/admin" WEB_GIT_DIRECTORY="${HTML_DIRECTORY}/admin"
#BLOCK_PAGE_DIRECTORY="${HTML_DIRECTORY}/pihole"
SHM_DIRECTORY="/dev/shm" SHM_DIRECTORY="/dev/shm"
ETC="/etc" ETC="/etc"
@@ -89,6 +85,7 @@ PIHOLE_LOGROTATE_FILE="${PIHOLE_DIRECTORY}/logrotate"
PIHOLE_SETUP_VARS_FILE="${PIHOLE_DIRECTORY}/setupVars.conf" PIHOLE_SETUP_VARS_FILE="${PIHOLE_DIRECTORY}/setupVars.conf"
PIHOLE_FTL_CONF_FILE="${PIHOLE_DIRECTORY}/pihole-FTL.conf" PIHOLE_FTL_CONF_FILE="${PIHOLE_DIRECTORY}/pihole-FTL.conf"
PIHOLE_CUSTOM_HOSTS_FILE="${PIHOLE_DIRECTORY}/custom.list" PIHOLE_CUSTOM_HOSTS_FILE="${PIHOLE_DIRECTORY}/custom.list"
PIHOLE_VERSIONS_FILE="${PIHOLE_DIRECTORY}/versions"
# Read the value of an FTL config key. The value is printed to stdout. # Read the value of an FTL config key. The value is printed to stdout.
# #
@@ -124,7 +121,6 @@ PIHOLE_COMMAND="${BIN_DIRECTORY}/pihole"
PIHOLE_COLTABLE_FILE="${BIN_DIRECTORY}/COL_TABLE" PIHOLE_COLTABLE_FILE="${BIN_DIRECTORY}/COL_TABLE"
FTL_PID="${RUN_DIRECTORY}/pihole-FTL.pid" FTL_PID="${RUN_DIRECTORY}/pihole-FTL.pid"
FTL_PORT="${RUN_DIRECTORY}/pihole-FTL.port"
PIHOLE_LOG="${LOG_DIRECTORY}/pihole.log" PIHOLE_LOG="${LOG_DIRECTORY}/pihole.log"
PIHOLE_LOG_GZIPS="${LOG_DIRECTORY}/pihole.log.[0-9].*" PIHOLE_LOG_GZIPS="${LOG_DIRECTORY}/pihole.log.[0-9].*"
@@ -153,7 +149,6 @@ REQUIRED_FILES=("${PIHOLE_CRON_FILE}"
"${PIHOLE_COMMAND}" "${PIHOLE_COMMAND}"
"${PIHOLE_COLTABLE_FILE}" "${PIHOLE_COLTABLE_FILE}"
"${FTL_PID}" "${FTL_PID}"
"${FTL_PORT}"
"${PIHOLE_LOG}" "${PIHOLE_LOG}"
"${PIHOLE_LOG_GZIPS}" "${PIHOLE_LOG_GZIPS}"
"${PIHOLE_DEBUG_LOG}" "${PIHOLE_DEBUG_LOG}"
@@ -162,7 +157,8 @@ REQUIRED_FILES=("${PIHOLE_CRON_FILE}"
"${PIHOLE_WEB_SERVER_ERROR_LOG_FILE}" "${PIHOLE_WEB_SERVER_ERROR_LOG_FILE}"
"${RESOLVCONF}" "${RESOLVCONF}"
"${DNSMASQ_CONF}" "${DNSMASQ_CONF}"
"${PIHOLE_CUSTOM_HOSTS_FILE}") "${PIHOLE_CUSTOM_HOSTS_FILE}"
"${PIHOLE_VERSIONS_FILE}")
DISCLAIMER="This process collects information from your Pi-hole, and optionally uploads it to a unique and random directory on tricorder.pi-hole.net. DISCLAIMER="This process collects information from your Pi-hole, and optionally uploads it to a unique and random directory on tricorder.pi-hole.net.
@@ -240,15 +236,7 @@ compare_local_version_to_git_version() {
local git_dir="${1}" local git_dir="${1}"
# The named component of the project (Core or Web) # The named component of the project (Core or Web)
local pihole_component="${2}" local pihole_component="${2}"
# If we are checking the Core versions,
if [[ "${pihole_component}" == "Core" ]]; then
# We need to search for "Pi-hole" when using pihole -v
local search_term="Pi-hole"
elif [[ "${pihole_component}" == "Web" ]]; then
# We need to search for "AdminLTE" so store it in a variable as well
#shellcheck disable=2034
local search_term="AdminLTE"
fi
# Display what we are checking # Display what we are checking
echo_current_diagnostic "${pihole_component} version" echo_current_diagnostic "${pihole_component} version"
# Store the error message in a variable in case we want to change and/or reuse it # Store the error message in a variable in case we want to change and/or reuse it
@@ -261,43 +249,35 @@ compare_local_version_to_git_version() {
log_write "${COL_RED}Could not cd into ${git_dir}$COL_NC" log_write "${COL_RED}Could not cd into ${git_dir}$COL_NC"
if git status &> /dev/null; then if git status &> /dev/null; then
# The current version the user is on # The current version the user is on
local remote_version local local_version
remote_version=$(git describe --tags --abbrev=0); local_version=$(git describe --tags --abbrev=0);
# What branch they are on # What branch they are on
local remote_branch local local_branch
remote_branch=$(git rev-parse --abbrev-ref HEAD); local_branch=$(git rev-parse --abbrev-ref HEAD);
# The commit they are on # The commit they are on
local remote_commit local local_commit
remote_commit=$(git describe --long --dirty --tags --always) local_commit=$(git describe --long --dirty --tags --always)
# Status of the repo # Status of the repo
local local_status local local_status
local_status=$(git status -s) local_status=$(git status -s)
# echo this information out to the user in a nice format # echo this information out to the user in a nice format
# If the current version matches what pihole -v produces, the user is up-to-date log_write "${TICK} Version: ${local_version}"
if [[ "${remote_version}" == "$(pihole -v | awk '/${search_term}/ {print $6}' | cut -d ')' -f1)" ]]; then
log_write "${TICK} ${pihole_component}: ${COL_GREEN}${remote_version}${COL_NC}"
# If not,
else
# echo the current version in yellow, signifying it's something to take a look at, but not a critical error
# Also add a URL to an FAQ
log_write "${INFO} ${pihole_component}: ${COL_YELLOW}${remote_version:-Untagged}${COL_NC} (${FAQ_UPDATE_PI_HOLE})"
fi
# Print the repo upstreams # Print the repo upstreams
remotes=$(git remote -v) remotes=$(git remote -v)
log_write "${INFO} Remotes: ${remotes//$'\n'/'\n '}" log_write "${INFO} Remotes: ${remotes//$'\n'/'\n '}"
# If the repo is on the master branch, they are on the stable codebase # If the repo is on the master branch, they are on the stable codebase
if [[ "${remote_branch}" == "master" ]]; then if [[ "${local_branch}" == "master" ]]; then
# so the color of the text is green # so the color of the text is green
log_write "${INFO} Branch: ${COL_GREEN}${remote_branch}${COL_NC}" log_write "${INFO} Branch: ${COL_GREEN}${local_branch}${COL_NC}"
# If it is any other branch, they are in a development branch # If it is any other branch, they are in a development branch
else else
# So show that in yellow, signifying it's something to take a look at, but not a critical error # So show that in yellow, signifying it's something to take a look at, but not a critical error
log_write "${INFO} Branch: ${COL_YELLOW}${remote_branch:-Detached}${COL_NC} (${FAQ_CHECKOUT_COMMAND})" log_write "${INFO} Branch: ${COL_YELLOW}${local_branch:-Detached}${COL_NC}"
fi fi
# echo the current commit # echo the current commit
log_write "${INFO} Commit: ${remote_commit}" log_write "${INFO} Commit: ${local_commit}"
# if `local_status` is non-null, then the repo is not clean, display details here # if `local_status` is non-null, then the repo is not clean, display details here
if [[ ${local_status} ]]; then if [[ ${local_status} ]]; then
# Replace new lines in the status with 12 spaces to make the output cleaner # Replace new lines in the status with 12 spaces to make the output cleaner
@@ -331,22 +311,15 @@ compare_local_version_to_git_version() {
} }
check_ftl_version() { check_ftl_version() {
local ftl_name="FTL"
local FTL_VERSION FTL_COMMIT FTL_BRANCH local FTL_VERSION FTL_COMMIT FTL_BRANCH
echo_current_diagnostic "${ftl_name} version" echo_current_diagnostic "FTL version"
# Use the built in command to check FTL's version # Use the built in command to check FTL's version
FTL_VERSION=$(pihole-FTL -vv | grep -m 1 Version | awk '{printf $2}') FTL_VERSION=$(pihole-FTL version)
FTL_BRANCH=$(pihole-FTL -vv | grep -m 1 Branch | awk '{printf $2}') FTL_BRANCH=$(pihole-FTL branch)
FTL_COMMIT=$(pihole-FTL -vv | grep -m 1 Commit | awk '{printf $2}') FTL_COMMIT=$(pihole-FTL --hash)
# Compare the current FTL version to the remote version
if [[ "${FTL_VERSION}" == "$(pihole -v | awk '/FTL/ {print $6}' | cut -d ')' -f1)" ]]; then log_write "${TICK} Version: ${FTL_VERSION}"
# If they are the same, FTL is up-to-date
log_write "${TICK} ${ftl_name}: ${COL_GREEN}${FTL_VERSION}${COL_NC}"
else
# If not, show it in yellow, signifying there is an update
log_write "${INFO} ${ftl_name}: ${COL_YELLOW}${FTL_VERSION}${COL_NC} (${FAQ_UPDATE_PI_HOLE})"
fi
# If they use the master branch, they are on the stable codebase # If they use the master branch, they are on the stable codebase
if [[ "${FTL_BRANCH}" == "master" ]]; then if [[ "${FTL_BRANCH}" == "master" ]]; then
@@ -355,7 +328,7 @@ check_ftl_version() {
# If it is any other branch, they are in a development branch # If it is any other branch, they are in a development branch
else else
# So show that in yellow, signifying it's something to take a look at, but not a critical error # So show that in yellow, signifying it's something to take a look at, but not a critical error
log_write "${INFO} Branch: ${COL_YELLOW}${FTL_BRANCH}${COL_NC} (${FAQ_CHECKOUT_COMMAND})" log_write "${INFO} Branch: ${COL_YELLOW}${FTL_BRANCH}${COL_NC}"
fi fi
# echo the current commit # echo the current commit
@@ -465,8 +438,8 @@ diagnose_operating_system() {
# Display the current test that is running # Display the current test that is running
echo_current_diagnostic "Operating system" echo_current_diagnostic "Operating system"
# If the PIHOLE_DOCKER_TAG variable is set, include this information in the debug output # If DOCKER_VERSION is set (Sourced from /etc/pihole/versions at start of script), include this information in the debug output
[ -n "${PIHOLE_DOCKER_TAG}" ] && log_write "${INFO} Pi-hole Docker Container: ${PIHOLE_DOCKER_TAG}" [ -n "${DOCKER_VERSION}" ] && log_write "${INFO} Pi-hole Docker Container: ${DOCKER_VERSION}"
# If there is a /etc/*release file, it's probably a supported operating system, so we can # 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 if ls /etc/*release 1> /dev/null 2>&1; then
@@ -676,15 +649,20 @@ ping_gateway() {
local protocol="${1}" local protocol="${1}"
ping_ipv4_or_ipv6 "${protocol}" ping_ipv4_or_ipv6 "${protocol}"
# Check if we are using IPv4 or IPv6 # Check if we are using IPv4 or IPv6
# Find the default gateway using IPv4 or IPv6 # Find the default gateways using IPv4 or IPv6
local gateway local gateway
gateway="$(ip -"${protocol}" route | grep default | grep "${PIHOLE_INTERFACE}" | cut -d ' ' -f 3)"
# If the gateway variable has a value (meaning a gateway was found), log_write "${INFO} Default IPv${protocol} gateway(s):"
if [[ -n "${gateway}" ]]; then
log_write "${INFO} Default IPv${protocol} gateway: ${gateway}" while IFS= read -r gateway; do
log_write " ${gateway}"
done < <(ip -"${protocol}" route | grep default | grep "${PIHOLE_INTERFACE}" | cut -d ' ' -f 3)
gateway=$(ip -"${protocol}" route | grep default | grep "${PIHOLE_INTERFACE}" | cut -d ' ' -f 3 | head -n 1)
# If there was at least one gateway
if [ -n "${gateway}" ]; then
# Let the user know we will ping the gateway for a response # Let the user know we will ping the gateway for a response
log_write " * Pinging ${gateway}..." log_write " * Pinging first gateway ${gateway}..."
# Try to quietly ping the gateway 3 times, with a timeout of 3 seconds, using numeric output only, # Try to quietly ping the gateway 3 times, with a timeout of 3 seconds, using numeric output only,
# on the pihole interface, and tail the last three lines of the output # on the pihole interface, and tail the last three lines of the output
# If pinging the gateway is not successful, # If pinging the gateway is not successful,
@@ -802,7 +780,7 @@ check_networking() {
ping_gateway "6" ping_gateway "6"
# Skip the following check if installed in docker container. Unpriv'ed containers do not have access to the information required # Skip the following check if installed in docker container. Unpriv'ed containers do not have access to the information required
# to resolve the service name listening - and the container should not start if there was a port conflict anyway # to resolve the service name listening - and the container should not start if there was a port conflict anyway
[ -z "${PIHOLE_DOCKER_TAG}" ] && check_required_ports [ -z "${DOCKER_VERSION}" ] && check_required_ports
} }
check_x_headers() { check_x_headers() {
@@ -812,7 +790,7 @@ check_x_headers() {
# Similarly, it will show "X-Pi-hole: The Pi-hole Web interface is working!" if you view the header returned # Similarly, it will show "X-Pi-hole: The Pi-hole Web interface is working!" if you view the header returned
# when accessing the dashboard (i.e curl -I pi.hole/admin/) # when accessing the dashboard (i.e curl -I pi.hole/admin/)
# server is operating correctly # server is operating correctly
echo_current_diagnostic "Dashboard and block page" echo_current_diagnostic "Dashboard headers"
# Use curl -I to get the header and parse out just the X-Pi-hole one # Use curl -I to get the header and parse out just the X-Pi-hole one
local full_curl_output_dashboard local full_curl_output_dashboard
local dashboard local dashboard
@@ -822,7 +800,7 @@ check_x_headers() {
local dashboard_working local dashboard_working
dashboard_working="X-Pi-hole: The Pi-hole Web interface is working!" dashboard_working="X-Pi-hole: The Pi-hole Web interface is working!"
# Same logic applies to the dashboard as above, if the X-Header matches what a working system should have, # If the X-Header matches what a working system should have,
if [[ $dashboard == "$dashboard_working" ]]; then if [[ $dashboard == "$dashboard_working" ]]; then
# then we can show a success # then we can show a success
log_write "$TICK Web interface X-Header: ${COL_GREEN}${dashboard}${COL_NC}" log_write "$TICK Web interface X-Header: ${COL_GREEN}${dashboard}${COL_NC}"
@@ -947,10 +925,21 @@ process_status(){
else else
# Otherwise, use the service command and mock the output of `systemctl is-active` # Otherwise, use the service command and mock the output of `systemctl is-active`
local status_of_process local status_of_process
if service "${i}" status | grep -E 'is\srunning' &> /dev/null; then
status_of_process="active" # If DOCKER_VERSION is set, the output is slightly different (s6 init system on Docker)
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 else
status_of_process="inactive" # non-Docker system
if service "${i}" status | grep -E 'is\srunning' &> /dev/null; then
status_of_process="active"
else
status_of_process="inactive"
fi
fi fi
fi fi
# and print it out to the user # and print it out to the user
@@ -1274,7 +1263,7 @@ analyze_gravity_list() {
# if users want to check database integrity # if users want to check database integrity
if [[ "${CHECK_DATABASE}" = true ]]; then if [[ "${CHECK_DATABASE}" = true ]]; then
database_integrity_check "${PIHOLE_FTL_DB_FILE}" database_integrity_check "${PIHOLE_GRAVITY_DB_FILE}"
fi fi
show_db_entries "Info table" "SELECT property,value FROM info" "20 40" show_db_entries "Info table" "SELECT property,value FROM info" "20 40"
@@ -1337,16 +1326,6 @@ database_integrity_check(){
} }
check_database_integrity() {
echo_current_diagnostic "Gravity Database"
database_permissions "${PIHOLE_GRAVITY_DB_FILE}"
database_integrity_check "${PIHOLE_GRAVITY_DB_FILE}"
echo_current_diagnostic "Pi-hole FTL Query Database"
database_permissions "${PIHOLE_FTL_DB_FILE}"
database_integrity_check "${PIHOLE_FTL_DB_FILE}"
}
# Show a text spinner during a long process run # Show a text spinner during a long process run
spinner(){ spinner(){
# Show the spinner only if there is a tty # Show the spinner only if there is a tty
@@ -1386,49 +1365,8 @@ spinner(){
fi fi
} }
obfuscated_pihole_log() {
local pihole_log=("$@")
local line
local error_to_check_for
local line_to_obfuscate
local obfuscated_line
for line in "${pihole_log[@]}"; do
# A common error in the pihole.log is when there is a non-hosts formatted file
# that the DNS server is attempting to read. Since it's not formatted
# correctly, there will be an entry for "bad address at line n"
# So we can check for that here and highlight it in red so the user can see it easily
error_to_check_for=$(echo "${line}" | grep 'bad address at')
# Some users may not want to have the domains they visit sent to us
# To that end, we check for lines in the log that would contain a domain name
line_to_obfuscate=$(echo "${line}" | grep ': query\|: forwarded\|: reply')
# If the variable contains a value, it found an error in the log
if [[ -n ${error_to_check_for} ]]; then
# So we can print it in red to make it visible to the user
log_write " ${CROSS} ${COL_RED}${line}${COL_NC} (${FAQ_BAD_ADDRESS})"
else
# If the variable does not a value (the current default behavior), so do not obfuscate anything
if [[ -z ${OBFUSCATE} ]]; then
log_write " ${line}"
# Otherwise, a flag was passed to this command to obfuscate domains in the log
else
# So first check if there are domains in the log that should be obfuscated
if [[ -n ${line_to_obfuscate} ]]; then
# If there are, we need to use awk to replace only the domain name (the 6th field in the log)
# so we substitute the domain for the placeholder value
obfuscated_line=$(echo "${line_to_obfuscate}" | awk -v placeholder="${OBFUSCATED_PLACEHOLDER}" '{sub($6,placeholder); print $0}')
log_write " ${obfuscated_line}"
else
log_write " ${line}"
fi
fi
fi
done
}
analyze_pihole_log() { analyze_pihole_log() {
echo_current_diagnostic "Pi-hole log" echo_current_diagnostic "Pi-hole log"
local pihole_log_head=()
local pihole_log_tail=()
local pihole_log_permissions local pihole_log_permissions
local logging_enabled local logging_enabled
@@ -1438,22 +1376,10 @@ analyze_pihole_log() {
log_write "${INFO} Query logging is disabled" log_write "${INFO} Query logging is disabled"
log_write "" log_write ""
fi fi
# Put the current Internal Field Separator into another variable so it can be restored later
OLD_IFS="$IFS"
# Get the lines that are in the file(s) and store them in an array for parsing later
IFS=$'\r\n'
pihole_log_permissions=$(ls -lhd "${PIHOLE_LOG}") pihole_log_permissions=$(ls -lhd "${PIHOLE_LOG}")
log_write "${COL_GREEN}${pihole_log_permissions}${COL_NC}" log_write "${COL_GREEN}${pihole_log_permissions}${COL_NC}"
mapfile -t pihole_log_head < <(head -n 20 ${PIHOLE_LOG}) head_tail_log "${PIHOLE_LOG}" 20
log_write " ${COL_CYAN}-----head of $(basename ${PIHOLE_LOG})------${COL_NC}"
obfuscated_pihole_log "${pihole_log_head[@]}"
log_write ""
mapfile -t pihole_log_tail < <(tail -n 20 ${PIHOLE_LOG})
log_write " ${COL_CYAN}-----tail of $(basename ${PIHOLE_LOG})------${COL_NC}"
obfuscated_pihole_log "${pihole_log_tail[@]}"
log_write ""
# Set the IFS back to what it was
IFS="$OLD_IFS"
} }
curl_to_tricorder() { curl_to_tricorder() {

View File

@@ -216,9 +216,8 @@ main() {
fi fi
if [[ "${FTL_update}" == true || "${core_update}" == true || "${web_update}" == true ]]; then if [[ "${FTL_update}" == true || "${core_update}" == true || "${web_update}" == true ]]; then
# Force an update of the updatechecker # Update local and remote versions via updatechecker
/opt/pihole/updatecheck.sh /opt/pihole/updatecheck.sh
/opt/pihole/updatecheck.sh x remote
echo -e " ${INFO} Local version file information updated." echo -e " ${INFO} Local version file information updated."
fi fi

View File

@@ -15,16 +15,30 @@ function get_local_branch() {
} }
function get_local_version() { function get_local_version() {
# Return active branch # Return active version
cd "${1}" 2> /dev/null || return 1 cd "${1}" 2> /dev/null || return 1
git describe --long --dirty --tags 2> /dev/null || return 1 git describe --tags --always 2> /dev/null || return 1
}
function get_local_hash() {
cd "${1}" 2> /dev/null || return 1
git rev-parse --short=8 HEAD || return 1
}
function get_remote_version() {
curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1
}
function get_remote_hash(){
git ls-remote "https://github.com/pi-hole/${1}" --tags "${2}" | awk '{print substr($0, 0,8);}' || return 1
} }
# Source the setupvars config file # Source the setupvars config file
# shellcheck disable=SC1091 # shellcheck disable=SC1091
. /etc/pihole/setupVars.conf . /etc/pihole/setupVars.conf
# Source the utils file # Source the utils file for addOrEditKeyValPair()
# shellcheck disable=SC1091 # shellcheck disable=SC1091
. /opt/pihole/utils.sh . /opt/pihole/utils.sh
@@ -38,50 +52,82 @@ VERSION_FILE="/etc/pihole/versions"
touch "${VERSION_FILE}" touch "${VERSION_FILE}"
chmod 644 "${VERSION_FILE}" chmod 644 "${VERSION_FILE}"
if [[ "$2" == "remote" ]]; then # if /pihole.docker.tag file exists, we will use it's value later in this script
DOCKER_TAG=$(cat /pihole.docker.tag 2>/dev/null)
regex='^([0-9]+\.){1,2}(\*|[0-9]+)(-.*)?$|(^nightly$)|(^dev.*$)'
if [[ ! "${DOCKER_TAG}" =~ $regex ]]; then
# DOCKER_TAG does not match the pattern (see https://regex101.com/r/RsENuz/1), so unset it.
unset DOCKER_TAG
fi
if [[ "$3" == "reboot" ]]; then # used in cronjob
if [[ "$1" == "reboot" ]]; then
sleep 30 sleep 30
fi fi
GITHUB_CORE_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/pi-hole/releases/latest' 2> /dev/null | jq --raw-output .tag_name)"
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}"
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then # get Core versions
GITHUB_WEB_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/AdminLTE/releases/latest' 2> /dev/null | jq --raw-output .tag_name)"
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}"
fi
GITHUB_FTL_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/FTL/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" CORE_VERSION="$(get_local_version /etc/.pihole)"
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}"
if [[ "${PIHOLE_DOCKER_TAG}" ]]; then CORE_BRANCH="$(get_local_branch /etc/.pihole)"
GITHUB_DOCKER_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/docker-pi-hole/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}"
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}"
fi
else CORE_HASH="$(get_local_hash /etc/.pihole)"
addOrEditKeyValPair "${VERSION_FILE}" "CORE_HASH" "${CORE_HASH}"
CORE_BRANCH="$(get_local_branch /etc/.pihole)" GITHUB_CORE_VERSION="$(get_remote_version pi-hole)"
addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}"
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then GITHUB_CORE_HASH="$(get_remote_hash pi-hole "${CORE_BRANCH}")"
WEB_BRANCH="$(get_local_branch /var/www/html/admin)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_HASH" "${GITHUB_CORE_HASH}"
addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}"
fi
FTL_BRANCH="$(pihole-FTL branch)"
addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}"
CORE_VERSION="$(get_local_version /etc/.pihole)" # get Web versions
addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}"
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then
WEB_VERSION="$(get_local_version /var/www/html/admin)"
addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}"
fi
FTL_VERSION="$(pihole-FTL version)" WEB_VERSION="$(get_local_version /var/www/html/admin)"
addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}"
WEB_BRANCH="$(get_local_branch /var/www/html/admin)"
addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}"
WEB_HASH="$(get_local_hash /var/www/html/admin)"
addOrEditKeyValPair "${VERSION_FILE}" "WEB_HASH" "${WEB_HASH}"
GITHUB_WEB_VERSION="$(get_remote_version AdminLTE)"
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}"
GITHUB_WEB_HASH="$(get_remote_hash AdminLTE "${WEB_BRANCH}")"
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_HASH" "${GITHUB_WEB_HASH}"
fi fi
# get FTL versions
FTL_VERSION="$(pihole-FTL version)"
addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}"
FTL_BRANCH="$(pihole-FTL branch)"
addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}"
FTL_HASH="$(pihole-FTL --hash)"
addOrEditKeyValPair "${VERSION_FILE}" "FTL_HASH" "${FTL_HASH}"
GITHUB_FTL_VERSION="$(get_remote_version FTL)"
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}"
GITHUB_FTL_HASH="$(get_remote_hash FTL "${FTL_BRANCH}")"
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_HASH" "${GITHUB_FTL_HASH}"
# get Docker versions
if [[ "${DOCKER_TAG}" ]]; then
addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${DOCKER_TAG}"
GITHUB_DOCKER_VERSION="$(get_remote_version docker-pi-hole)"
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}"
fi

View File

@@ -31,9 +31,12 @@ addOrEditKeyValPair() {
local key="${2}" local key="${2}"
local value="${3}" local value="${3}"
# touch file to prevent grep error if file does not exist yet
touch "${file}"
if grep -q "^${key}=" "${file}"; then if grep -q "^${key}=" "${file}"; then
# Key already exists in file, modify the value # Key already exists in file, modify the value
sed -i "/^${key}=/c\\${key}=${value}" "${file}" sed -i "/^${key}=/c\\${key}=${value}" "${file}"
else else
# Key does not already exist, add it and it's value # Key does not already exist, add it and it's value
echo "${key}=${value}" >> "${file}" echo "${key}=${value}" >> "${file}"
@@ -51,9 +54,12 @@ addKey(){
local file="${1}" local file="${1}"
local key="${2}" local key="${2}"
# touch file to prevent grep error if file does not exist yet
touch "${file}"
if ! grep -q "^${key}" "${file}"; then if ! grep -q "^${key}" "${file}"; then
# Key does not exist, add it. # Key does not exist, add it.
echo "${key}" >> "${file}" echo "${key}" >> "${file}"
fi fi
} }
@@ -70,47 +76,27 @@ removeKey() {
sed -i "/^${key}/d" "${file}" sed -i "/^${key}/d" "${file}"
} }
#######################
# returns path of FTL's port file
#######################
getFTLAPIPortFile() {
local FTLCONFFILE="/etc/pihole/pihole-FTL.conf"
local DEFAULT_PORT_FILE="/run/pihole-FTL.port"
local FTL_APIPORT_FILE
if [ -s "${FTLCONFFILE}" ]; then
# if PORTFILE is not set in pihole-FTL.conf, use the default path
FTL_APIPORT_FILE="$({ grep '^PORTFILE=' "${FTLCONFFILE}" || echo "${DEFAULT_PORT_FILE}"; } | cut -d'=' -f2-)"
else
# if there is no pihole-FTL.conf, use the default path
FTL_APIPORT_FILE="${DEFAULT_PORT_FILE}"
fi
echo "${FTL_APIPORT_FILE}"
}
####################### #######################
# returns FTL's current telnet API port based on the content of the pihole-FTL.port file # returns FTL's current telnet API port based on the setting in /etc/pihole-FTL.conf
# ########################
# Takes one argument: path to pihole-FTL.port
# Example getFTLAPIPort "/run/pihole-FTL.port"
#######################
getFTLAPIPort(){ getFTLAPIPort(){
local PORTFILE="${1}" local FTLCONFFILE="/etc/pihole/pihole-FTL.conf"
local DEFAULT_FTL_PORT=4711 local DEFAULT_FTL_PORT=4711
local ftl_api_port local ftl_api_port
if [ -s "$PORTFILE" ]; then if [ -s "$FTLCONFFILE" ]; then
# -s: FILE exists and has a size greater than zero # if FTLPORT is not set in pihole-FTL.conf, use the default port
ftl_api_port=$(cat "${PORTFILE}") ftl_api_port="$({ grep '^FTLPORT=' "${FTLCONFFILE}" || echo "${DEFAULT_FTL_PORT}"; } | cut -d'=' -f2-)"
# Exploit prevention: unset the variable if there is malicious content # Exploit prevention: set the port to the default port if there is malicious (non-numeric)
# Verify that the value read from the file is numeric # content set in pihole-FTL.conf
expr "$ftl_api_port" : "[^[:digit:]]" > /dev/null && unset ftl_api_port expr "${ftl_api_port}" : "[^[:digit:]]" > /dev/null && ftl_api_port="${DEFAULT_FTL_PORT}"
else
# if there is no pihole-FTL.conf, use the default port
ftl_api_port="${DEFAULT_FTL_PORT}"
fi fi
# echo the port found in the portfile or default to the default port echo "${ftl_api_port}"
echo "${ftl_api_port:=$DEFAULT_FTL_PORT}"
} }
####################### #######################

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env sh
# Pi-hole: A black hole for Internet advertisements # Pi-hole: A black hole for Internet advertisements
# (c) 2017 Pi-hole, LLC (https://pi-hole.net) # (c) 2017 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware. # Network-wide ad blocking via your own hardware.
@@ -8,179 +8,104 @@
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
# Variables
DEFAULT="-1"
COREGITDIR="/etc/.pihole/"
WEBGITDIR="/var/www/html/admin/"
# Source the setupvars config file # Source the setupvars config file
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source /etc/pihole/setupVars.conf . /etc/pihole/setupVars.conf
# Source the versions file poupulated by updatechecker.sh
cachedVersions="/etc/pihole/versions"
if [ -f ${cachedVersions} ]; then
# shellcheck disable=SC1090
. "$cachedVersions"
else
echo "Could not find /etc/pihole/versions. Running update now."
pihole updatechecker
# shellcheck disable=SC1090
. "$cachedVersions"
fi
getLocalVersion() { getLocalVersion() {
# FTL requires a different method case ${1} in
if [[ "$1" == "FTL" ]]; then "Pi-hole" ) echo "${CORE_VERSION:=N/A}";;
pihole-FTL version "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_VERSION:=N/A}";;
return 0 "FTL" ) echo "${FTL_VERSION:=N/A}";;
fi esac
# Get the tagged version of the local repository
local directory="${1}"
local version
cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; }
version=$(git describe --tags --always || echo "$DEFAULT")
if [[ "${version}" =~ ^v ]]; then
echo "${version}"
elif [[ "${version}" == "${DEFAULT}" ]]; then
echo "ERROR"
return 1
else
echo "Untagged"
fi
return 0
} }
getLocalHash() { getLocalHash() {
# Local FTL hash does not exist on filesystem case ${1} in
if [[ "$1" == "FTL" ]]; then "Pi-hole" ) echo "${CORE_HASH:=N/A}";;
echo "N/A" "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_HASH:=N/A}";;
return 0 "FTL" ) echo "${FTL_HASH:=N/A}";;
fi esac
# Get the short hash of the local repository
local directory="${1}"
local hash
cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; }
hash=$(git rev-parse --short HEAD || echo "$DEFAULT")
if [[ "${hash}" == "${DEFAULT}" ]]; then
echo "ERROR"
return 1
else
echo "${hash}"
fi
return 0
} }
getRemoteHash(){ getRemoteHash(){
# Remote FTL hash is not applicable case ${1} in
if [[ "$1" == "FTL" ]]; then "Pi-hole" ) echo "${GITHUB_CORE_HASH:=N/A}";;
echo "N/A" "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_HASH:=N/A}";;
return 0 "FTL" ) echo "${GITHUB_FTL_HASH:=N/A}";;
fi esac
local daemon="${1}"
local branch="${2}"
hash=$(git ls-remote --heads "https://github.com/pi-hole/${daemon}" | \
awk -v bra="$branch" '$0~bra {print substr($0,0,8);exit}')
if [[ -n "$hash" ]]; then
echo "$hash"
else
echo "ERROR"
return 1
fi
return 0
} }
getRemoteVersion(){ getRemoteVersion(){
# Get the version from the remote origin case ${1} in
local daemon="${1}" "Pi-hole" ) echo "${GITHUB_CORE_VERSION:=N/A}";;
local version "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_VERSION:=N/A}";;
local cachedVersions "FTL" ) echo "${GITHUB_FTL_VERSION:=N/A}";;
cachedVersions="/etc/pihole/versions" esac
#If the above file exists, then we can read from that. Prevents overuse of GitHub API
if [[ -f "$cachedVersions" ]]; then
# shellcheck disable=SC1090
. "$cachedVersions"
case $daemon in
"pi-hole" ) echo "${GITHUB_CORE_VERSION}";;
"AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_VERSION}";;
"FTL" ) echo "${GITHUB_FTL_VERSION}";;
esac
return 0
fi
version=$(curl --silent --fail "https://api.github.com/repos/pi-hole/${daemon}/releases/latest" | \
awk -F: '$1 ~/tag_name/ { print $2 }' | \
tr -cd '[[:alnum:]]._-')
if [[ "${version}" =~ ^v ]]; then
echo "${version}"
else
echo "ERROR"
return 1
fi
return 0
} }
getLocalBranch(){ getLocalBranch(){
# Get the checked out branch of the local directory case ${1} in
local directory="${1}" "Pi-hole" ) echo "${CORE_BRANCH:=N/A}";;
local branch "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_BRANCH:=N/A}";;
"FTL" ) echo "${FTL_BRANCH:=N/A}";;
# Local FTL btranch is stored in /etc/pihole/ftlbranch esac
if [[ "$1" == "FTL" ]]; then
branch="$(pihole-FTL branch)"
else
cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; }
branch=$(git rev-parse --abbrev-ref HEAD || echo "$DEFAULT")
fi
if [[ ! "${branch}" =~ ^v ]]; then
if [[ "${branch}" == "master" ]]; then
echo ""
elif [[ "${branch}" == "HEAD" ]]; then
echo "in detached HEAD state at "
else
echo "${branch} "
fi
else
# Branch started in "v"
echo "release "
fi
return 0
} }
versionOutput() { versionOutput() {
if [[ "$1" == "AdminLTE" && "${INSTALL_WEB_INTERFACE}" != true ]]; then if [ "$1" = "AdminLTE" ] && [ "${INSTALL_WEB_INTERFACE}" != true ]; then
echo " WebAdmin not installed" echo " WebAdmin not installed"
return 1 return 1
fi fi
[[ "$1" == "pi-hole" ]] && GITDIR=$COREGITDIR [ "$2" = "-c" ] || [ "$2" = "--current" ] || [ -z "$2" ] && current=$(getLocalVersion "${1}") && branch=$(getLocalBranch "${1}")
[[ "$1" == "AdminLTE" ]] && GITDIR=$WEBGITDIR [ "$2" = "-l" ] || [ "$2" = "--latest" ] || [ -z "$2" ] && latest=$(getRemoteVersion "${1}")
[[ "$1" == "FTL" ]] && GITDIR="FTL" if [ "$2" = "--hash" ]; then
[ "$3" = "-c" ] || [ "$3" = "--current" ] || [ -z "$3" ] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}")
[[ "$2" == "-c" ]] || [[ "$2" == "--current" ]] || [[ -z "$2" ]] && current=$(getLocalVersion $GITDIR) && branch=$(getLocalBranch $GITDIR) [ "$3" = "-l" ] || [ "$3" = "--latest" ] || [ -z "$3" ] && latHash=$(getRemoteHash "${1}") && branch=$(getLocalBranch "${1}")
[[ "$2" == "-l" ]] || [[ "$2" == "--latest" ]] || [[ -z "$2" ]] && latest=$(getRemoteVersion "$1")
if [[ "$2" == "-h" ]] || [[ "$2" == "--hash" ]]; then
[[ "$3" == "-c" ]] || [[ "$3" == "--current" ]] || [[ -z "$3" ]] && curHash=$(getLocalHash "$GITDIR") && branch=$(getLocalBranch $GITDIR)
[[ "$3" == "-l" ]] || [[ "$3" == "--latest" ]] || [[ -z "$3" ]] && latHash=$(getRemoteHash "$1" "$(cd "$GITDIR" 2> /dev/null && git rev-parse --abbrev-ref HEAD)")
fi fi
if [[ -n "$current" ]] && [[ -n "$latest" ]]; then
output="${1^} version is $branch$current (Latest: $latest)" # We do not want to show the branch name when we are on master,
elif [[ -n "$current" ]] && [[ -z "$latest" ]]; then # blank out the variable in this case
output="Current ${1^} version is $branch$current" if [ "$branch" = "master" ]; then
elif [[ -z "$current" ]] && [[ -n "$latest" ]]; then branch=""
output="Latest ${1^} version is $latest" else
elif [[ "$curHash" == "N/A" ]] || [[ "$latHash" == "N/A" ]]; then branch="$branch "
output="${1^} hash is not applicable" fi
elif [[ -n "$curHash" ]] && [[ -n "$latHash" ]]; then
output="${1^} hash is $curHash (Latest: $latHash)" if [ -n "$current" ] && [ -n "$latest" ]; then
elif [[ -n "$curHash" ]] && [[ -z "$latHash" ]]; then output="${1} version is $branch$current (Latest: $latest)"
output="Current ${1^} hash is $curHash" elif [ -n "$current" ] && [ -z "$latest" ]; then
elif [[ -z "$curHash" ]] && [[ -n "$latHash" ]]; then output="Current ${1} version is $branch$current"
output="Latest ${1^} hash is $latHash" elif [ -z "$current" ] && [ -n "$latest" ]; then
output="Latest ${1} version is $latest"
elif [ -n "$curHash" ] && [ -n "$latHash" ]; then
output="Local ${1} hash is $curHash (Remote: $latHash)"
elif [ -n "$curHash" ] && [ -z "$latHash" ]; then
output="Current local ${1} hash is $curHash"
elif [ -z "$curHash" ] && [ -n "$latHash" ]; then
output="Latest remote ${1} hash is $latHash"
elif [ -z "$curHash" ] && [ -z "$latHash" ]; then
output="Hashes for ${1} not available"
else else
errorOutput errorOutput
return 1 return 1
fi fi
[[ -n "$output" ]] && echo " $output" [ -n "$output" ] && echo " $output"
} }
errorOutput() { errorOutput() {
@@ -189,9 +114,9 @@ errorOutput() {
} }
defaultOutput() { defaultOutput() {
versionOutput "pi-hole" "$@" versionOutput "Pi-hole" "$@"
if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then if [ "${INSTALL_WEB_INTERFACE}" = true ]; then
versionOutput "AdminLTE" "$@" versionOutput "AdminLTE" "$@"
fi fi
@@ -217,7 +142,7 @@ Options:
} }
case "${1}" in case "${1}" in
"-p" | "--pihole" ) shift; versionOutput "pi-hole" "$@";; "-p" | "--pihole" ) shift; versionOutput "Pi-hole" "$@";;
"-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";; "-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";;
"-f" | "--ftl" ) shift; versionOutput "FTL" "$@";; "-f" | "--ftl" ) shift; versionOutput "FTL" "$@";;
"-h" | "--help" ) helpFunc;; "-h" | "--help" ) helpFunc;;

View File

@@ -393,13 +393,8 @@ ProcessDHCPSettings() {
if [[ "${DHCP_LEASETIME}" == "0" ]]; then if [[ "${DHCP_LEASETIME}" == "0" ]]; then
leasetime="infinite" leasetime="infinite"
elif [[ "${DHCP_LEASETIME}" == "" ]]; then elif [[ "${DHCP_LEASETIME}" == "" ]]; then
leasetime="24" leasetime="24h"
addOrEditKeyValPair "${setupVars}" "DHCP_LEASETIME" "${leasetime}" addOrEditKeyValPair "${setupVars}" "DHCP_LEASETIME" "24"
elif [[ "${DHCP_LEASETIME}" == "24h" ]]; then
#Installation is affected by known bug, introduced in a previous version.
#This will automatically clean up setupVars.conf and remove the unnecessary "h"
leasetime="24"
addOrEditKeyValPair "${setupVars}" "DHCP_LEASETIME" "${leasetime}"
else else
leasetime="${DHCP_LEASETIME}h" leasetime="${DHCP_LEASETIME}h"
fi fi
@@ -632,6 +627,14 @@ checkDomain()
echo "${validDomain}" echo "${validDomain}"
} }
escapeDots()
{
# SC suggest bashism ${variable//search/replace}
# shellcheck disable=SC2001
escaped=$(echo "$1" | sed 's/\./\\./g')
echo "${escaped}"
}
addAudit() addAudit()
{ {
shift # skip "-a" shift # skip "-a"
@@ -707,6 +710,7 @@ RemoveCustomDNSAddress() {
validHost="$(checkDomain "${host}")" validHost="$(checkDomain "${host}")"
if [[ -n "${validHost}" ]]; then if [[ -n "${validHost}" ]]; then
if valid_ip "${ip}" || valid_ip6 "${ip}" ; then if valid_ip "${ip}" || valid_ip6 "${ip}" ; then
validHost=$(escapeDots "${validHost}")
sed -i "/^${ip} ${validHost}$/Id" "${dnscustomfile}" sed -i "/^${ip} ${validHost}$/Id" "${dnscustomfile}"
else else
echo -e " ${CROSS} Invalid IP has been passed" echo -e " ${CROSS} Invalid IP has been passed"
@@ -734,7 +738,12 @@ AddCustomCNAMERecord() {
if [[ -n "${validDomain}" ]]; then if [[ -n "${validDomain}" ]]; then
validTarget="$(checkDomain "${target}")" validTarget="$(checkDomain "${target}")"
if [[ -n "${validTarget}" ]]; then if [[ -n "${validTarget}" ]]; then
echo "cname=${validDomain},${validTarget}" >> "${dnscustomcnamefile}" if [ "${validDomain}" = "${validTarget}" ]; then
echo " ${CROSS} Domain and target are the same. This would cause a DNS loop."
exit 1
else
echo "cname=${validDomain},${validTarget}" >> "${dnscustomcnamefile}"
fi
else else
echo " ${CROSS} Invalid Target Passed!" echo " ${CROSS} Invalid Target Passed!"
exit 1 exit 1
@@ -760,7 +769,9 @@ RemoveCustomCNAMERecord() {
if [[ -n "${validDomain}" ]]; then if [[ -n "${validDomain}" ]]; then
validTarget="$(checkDomain "${target}")" validTarget="$(checkDomain "${target}")"
if [[ -n "${validTarget}" ]]; then if [[ -n "${validTarget}" ]]; then
sed -i "/cname=${validDomain},${validTarget}$/Id" "${dnscustomcnamefile}" validDomain=$(escapeDots "${validDomain}")
validTarget=$(escapeDots "${validTarget}")
sed -i "/^cname=${validDomain},${validTarget}$/Id" "${dnscustomcnamefile}"
else else
echo " ${CROSS} Invalid Target Passed!" echo " ${CROSS} Invalid Target Passed!"
exit 1 exit 1

View File

@@ -9,7 +9,7 @@
# Description: Enable service provided by pihole-FTL daemon # Description: Enable service provided by pihole-FTL daemon
### END INIT INFO ### END INIT INFO
#source utils.sh for getFTLPIDFile(), getFTLPID (), getFTLAPIPortFile() #source utils.sh for getFTLPIDFile(), getFTLPID ()
PI_HOLE_SCRIPT_DIR="/opt/pihole" PI_HOLE_SCRIPT_DIR="/opt/pihole"
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh" utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
. "${utilsfile}" . "${utilsfile}"
@@ -31,7 +31,6 @@ start() {
# Touch files to ensure they exist (create if non-existing, preserve if existing) # Touch files to ensure they exist (create if non-existing, preserve if existing)
mkdir -pm 0755 /run/pihole /var/log/pihole mkdir -pm 0755 /run/pihole /var/log/pihole
[ ! -f "${FTL_PID_FILE}" ] && install -D -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}" [ ! -f "${FTL_PID_FILE}" ] && install -D -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}"
[ ! -f "${FTL_PORT_FILE}" ] && install -D -m 644 -o pihole -g pihole /dev/null "${FTL_PORT_FILE}"
[ ! -f /var/log/pihole/FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/FTL.log [ ! -f /var/log/pihole/FTL.log ] && install -m 644 -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/pihole.log ] && install -m 640 -o pihole -g pihole /dev/null /var/log/pihole/pihole.log
[ ! -f /etc/pihole/dhcp.leases ] && install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases [ ! -f /etc/pihole/dhcp.leases ] && install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases
@@ -91,7 +90,7 @@ stop() {
echo "Not running" echo "Not running"
fi fi
# Cleanup # Cleanup
rm -f /run/pihole/FTL.sock /dev/shm/FTL-* "${FTL_PID_FILE}" "${FTL_PORT_FILE}" rm -f /run/pihole/FTL.sock /dev/shm/FTL-* "${FTL_PID_FILE}"
echo echo
} }
@@ -111,7 +110,6 @@ status() {
# Get file paths # Get file paths
FTL_PID_FILE="$(getFTLPIDFile)" FTL_PID_FILE="$(getFTLPIDFile)"
FTL_PORT_FILE="$(getFTLAPIPortFile)"
# Get FTL's current PID # Get FTL's current PID
FTL_PID="$(getFTLPID ${FTL_PID_FILE})" FTL_PID="$(getFTLPID ${FTL_PID_FILE})"

View File

@@ -28,9 +28,6 @@
@reboot root /usr/sbin/logrotate --state /var/lib/logrotate/pihole /etc/pihole/logrotate @reboot root /usr/sbin/logrotate --state /var/lib/logrotate/pihole /etc/pihole/logrotate
# Pi-hole: Grab local version and branch every 10 minutes # Pi-hole: Grab remote and local version every 24 hours
*/10 * * * * root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker local 59 17 * * * root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker
@reboot root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker reboot
# Pi-hole: Grab remote version every 24 hours
59 17 * * * root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker remote
@reboot root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker remote reboot

View File

@@ -29,7 +29,8 @@ if (!empty($_SERVER["FQDN"])) {
if ($serverName === "pi.hole" if ($serverName === "pi.hole"
|| (!empty($_SERVER["VIRTUAL_HOST"]) && $serverName === $_SERVER["VIRTUAL_HOST"])) { || (!empty($_SERVER["VIRTUAL_HOST"]) && $serverName === $_SERVER["VIRTUAL_HOST"])) {
// Redirect to Web Interface // Redirect to Web Interface
exit(header("Location: /admin")); header("Location: /admin");
exit();
} elseif (filter_var($serverName, FILTER_VALIDATE_IP) || in_array($serverName, $authorizedHosts)) { } elseif (filter_var($serverName, FILTER_VALIDATE_IP) || in_array($serverName, $authorizedHosts)) {
// When directly browsing via IP or authorized hostname // When directly browsing via IP or authorized hostname
// Render splash/landing page based off presence of $landPage file // Render splash/landing page based off presence of $landPage file
@@ -75,6 +76,6 @@ EOT;
exit($splashPage); exit($splashPage);
} }
exit(header("HTTP/1.1 404 Not Found")); header("HTTP/1.1 404 Not Found");
exit();
?> ?>

View File

@@ -32,6 +32,8 @@ server.errorlog = "/var/log/lighttpd/error-pihole.log"
server.pid-file = "/run/lighttpd.pid" server.pid-file = "/run/lighttpd.pid"
server.username = "www-data" server.username = "www-data"
server.groupname = "www-data" server.groupname = "www-data"
# For lighttpd version 1.4.46 or above, the port can be overwritten in `/etc/lighttpd/external.conf` using the := operator
# e.g. server.port := 8000
server.port = 80 server.port = 80
accesslog.filename = "/var/log/lighttpd/access-pihole.log" accesslog.filename = "/var/log/lighttpd/access-pihole.log"
accesslog.format = "%{%s}t|%V|%r|%s|%b" accesslog.format = "%{%s}t|%V|%r|%s|%b"

View File

@@ -33,6 +33,8 @@ server.errorlog = "/var/log/lighttpd/error-pihole.log"
server.pid-file = "/run/lighttpd.pid" server.pid-file = "/run/lighttpd.pid"
server.username = "lighttpd" server.username = "lighttpd"
server.groupname = "lighttpd" server.groupname = "lighttpd"
# For lighttpd version 1.4.46 or above, the port can be overwritten in `/etc/lighttpd/external.conf` using the := operator
# e.g. server.port := 8000
server.port = 80 server.port = 80
accesslog.filename = "/var/log/lighttpd/access-pihole.log" accesslog.filename = "/var/log/lighttpd/access-pihole.log"
accesslog.format = "%{%s}t|%V|%r|%s|%b" accesslog.format = "%{%s}t|%V|%r|%s|%b"

View File

@@ -83,6 +83,7 @@ PI_HOLE_INSTALL_DIR="/opt/pihole"
PI_HOLE_CONFIG_DIR="/etc/pihole" PI_HOLE_CONFIG_DIR="/etc/pihole"
PI_HOLE_BIN_DIR="/usr/local/bin" PI_HOLE_BIN_DIR="/usr/local/bin"
PI_HOLE_404_DIR="${webroot}/pihole" PI_HOLE_404_DIR="${webroot}/pihole"
FTL_CONFIG_FILE="${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf"
if [ -z "$useUpdateVars" ]; then if [ -z "$useUpdateVars" ]; then
useUpdateVars=false useUpdateVars=false
fi fi
@@ -357,9 +358,9 @@ package_manager_detect() {
# These variable names match the ones for apt-get. See above for an explanation of what they are for. # These variable names match the ones for apt-get. See above for an explanation of what they are for.
PKG_INSTALL=("${PKG_MANAGER}" install -y) PKG_INSTALL=("${PKG_MANAGER}" install -y)
# CentOS package manager returns 100 when there are packages to update so we need to || true to prevent the script from exiting. # CentOS package manager returns 100 when there are packages to update so we need to || true to prevent the script from exiting.
PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l || true" PKG_COUNT="${PKG_MANAGER} check-update | grep -E '(.i686|.x86|.noarch|.arm|.src)' | wc -l || true"
OS_CHECK_DEPS=(grep bind-utils) OS_CHECK_DEPS=(grep bind-utils)
INSTALLER_DEPS=(git dialog iproute newt procps-ng which chkconfig ca-certificates) INSTALLER_DEPS=(git dialog iproute newt procps-ng chkconfig ca-certificates)
PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc libcap nmap-ncat jq) PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc libcap nmap-ncat jq)
PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php-common php-cli php-pdo php-xml php-json php-intl) PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php-common php-cli php-pdo php-xml php-json php-intl)
LIGHTTPD_USER="lighttpd" LIGHTTPD_USER="lighttpd"
@@ -827,8 +828,11 @@ It is also possible to use a DHCP reservation, but if you are going to do that,
# Configure networking via dhcpcd # Configure networking via dhcpcd
setDHCPCD() { setDHCPCD() {
# Check if the IP is already in the file # Regex for matching a non-commented static ip address setting
if grep -q "${IPV4_ADDRESS}" /etc/dhcpcd.conf; then local regex="^[ \t]*static ip_address[ \t]*=[ \t]*${IPV4_ADDRESS}"
# Check if static IP is already set in file
if grep -q "${regex}" /etc/dhcpcd.conf; then
printf " %b Static IP already configured\\n" "${INFO}" printf " %b Static IP already configured\\n" "${INFO}"
# If it's not, # If it's not,
else else
@@ -999,10 +1003,10 @@ If you want to specify a port other than 53, separate it with a hash.\
# and continue the loop. # and continue the loop.
DNSSettingsCorrect=False DNSSettingsCorrect=False
else else
dialog --no-shadow --keep-tite \ dialog --no-shadow --no-collapse --keep-tite \
--backtitle "Specify Upstream DNS Provider(s)" \ --backtitle "Specify Upstream DNS Provider(s)" \
--title "Upstream DNS Provider(s)" \ --title "Upstream DNS Provider(s)" \
--yesno "Are these settings correct?\\n\\tDNS Server 1:\\t${PIHOLE_DNS_1}\\n\\tDNS Server 2:\\t${PIHOLE_DNS_2}" \ --yesno "Are these settings correct?\\n"$'\t'"DNS Server 1:"$'\t'"${PIHOLE_DNS_1}\\n"$'\t'"DNS Server 2:"$'\t'"${PIHOLE_DNS_2}" \
"${r}" "${c}" && result=0 || result=$? "${r}" "${c}" && result=0 || result=$?
case ${result} in case ${result} in
@@ -1264,35 +1268,30 @@ version_check_dnsmasq() {
# Copy the new Pi-hole DNS config file into the dnsmasq.d directory # Copy the new Pi-hole DNS config file into the dnsmasq.d directory
install -D -m 644 -T "${dnsmasq_pihole_01_source}" "${dnsmasq_pihole_01_target}" install -D -m 644 -T "${dnsmasq_pihole_01_source}" "${dnsmasq_pihole_01_target}"
printf "%b %b Installed %s\n" "${OVER}" "${TICK}" "${dnsmasq_pihole_01_target}" printf "%b %b Installed %s\n" "${OVER}" "${TICK}" "${dnsmasq_pihole_01_target}"
# Replace our placeholder values with the GLOBAL DNS variables that we populated earlier # Add settings with the GLOBAL DNS variables that we populated earlier
# First, swap in the interface to listen on, # First, set the interface to listen on
sed -i "s/@INT@/$PIHOLE_INTERFACE/" "${dnsmasq_pihole_01_target}" addOrEditKeyValPair "${dnsmasq_pihole_01_target}" "interface" "$PIHOLE_INTERFACE"
if [[ "${PIHOLE_DNS_1}" != "" ]]; then if [[ "${PIHOLE_DNS_1}" != "" ]]; then
# then swap in the primary DNS server. # then add in the primary DNS server.
sed -i "s/@DNS1@/$PIHOLE_DNS_1/" "${dnsmasq_pihole_01_target}" addOrEditKeyValPair "${dnsmasq_pihole_01_target}" "server" "$PIHOLE_DNS_1"
else
# Otherwise, remove the line which sets DNS1.
sed -i '/^server=@DNS1@/d' "${dnsmasq_pihole_01_target}"
fi fi
# Ditto if DNS2 is not empty # Ditto if DNS2 is not empty
if [[ "${PIHOLE_DNS_2}" != "" ]]; then if [[ "${PIHOLE_DNS_2}" != "" ]]; then
sed -i "s/@DNS2@/$PIHOLE_DNS_2/" "${dnsmasq_pihole_01_target}" addKey "${dnsmasq_pihole_01_target}" "server=$PIHOLE_DNS_2"
else
sed -i '/^server=@DNS2@/d' "${dnsmasq_pihole_01_target}"
fi fi
# Set the cache size # Set the cache size
sed -i "s/@CACHE_SIZE@/$CACHE_SIZE/" "${dnsmasq_pihole_01_target}" addOrEditKeyValPair "${dnsmasq_pihole_01_target}" "cache-size" "$CACHE_SIZE"
sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' "${dnsmasq_conf}" sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' "${dnsmasq_conf}"
# If the user does not want to enable logging, # If the user does not want to enable logging,
if [[ "${QUERY_LOGGING}" == false ]] ; then if [[ "${QUERY_LOGGING}" == false ]] ; then
# disable it by commenting out the directive in the DNS config file # remove itfrom the DNS config file
sed -i 's/^log-queries/#log-queries/' "${dnsmasq_pihole_01_target}" removeKey "${dnsmasq_pihole_01_target}" "log-queries"
else else
# Otherwise, enable it by uncommenting the directive in the DNS config file # Otherwise, enable it by adding the directive to the DNS config file
sed -i 's/^#log-queries/log-queries/' "${dnsmasq_pihole_01_target}" addKey "${dnsmasq_pihole_01_target}" "log-queries"
fi fi
printf " %b Installing %s..." "${INFO}" "${dnsmasq_rfc6761_06_source}" printf " %b Installing %s..." "${INFO}" "${dnsmasq_rfc6761_06_source}"
@@ -1365,9 +1364,9 @@ installConfigs() {
chmod 644 "${PI_HOLE_CONFIG_DIR}/dns-servers.conf" chmod 644 "${PI_HOLE_CONFIG_DIR}/dns-servers.conf"
# Install template file if it does not exist # Install template file if it does not exist
if [[ ! -r "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" ]]; then if [[ ! -r "${FTL_CONFIG_FILE}" ]]; then
install -d -m 0755 ${PI_HOLE_CONFIG_DIR} install -d -m 0755 ${PI_HOLE_CONFIG_DIR}
if ! install -T -o pihole -m 664 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.conf" "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" &>/dev/null; then if ! install -T -o pihole -m 664 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.conf" "${FTL_CONFIG_FILE}" &>/dev/null; then
printf " %b Error: Unable to initialize configuration file %s/pihole-FTL.conf\\n" "${COL_LIGHT_RED}" "${PI_HOLE_CONFIG_DIR}" printf " %b Error: Unable to initialize configuration file %s/pihole-FTL.conf\\n" "${COL_LIGHT_RED}" "${PI_HOLE_CONFIG_DIR}"
return 1 return 1
fi fi
@@ -1784,30 +1783,24 @@ create_pihole_user() {
# This function saves any changes to the setup variables into the setupvars.conf file for future runs # This function saves any changes to the setup variables into the setupvars.conf file for future runs
finalExports() { finalExports() {
# If the setup variable file exists, # set or update the variables in the file
if [[ -e "${setupVars}" ]]; then
# update the variables in the file addOrEditKeyValPair "${setupVars}" "PIHOLE_INTERFACE" "${PIHOLE_INTERFACE}"
sed -i.update.bak '/PIHOLE_INTERFACE/d;/PIHOLE_DNS_1\b/d;/PIHOLE_DNS_2\b/d;/QUERY_LOGGING/d;/INSTALL_WEB_SERVER/d;/INSTALL_WEB_INTERFACE/d;/LIGHTTPD_ENABLED/d;/CACHE_SIZE/d;/DNS_FQDN_REQUIRED/d;/DNS_BOGUS_PRIV/d;/DNSMASQ_LISTENING/d;' "${setupVars}" addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_1" "${PIHOLE_DNS_1}"
fi addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_2" "${PIHOLE_DNS_2}"
# echo the information to the user addOrEditKeyValPair "${setupVars}" "QUERY_LOGGING" "${QUERY_LOGGING}"
{ addOrEditKeyValPair "${setupVars}" "INSTALL_WEB_SERVER" "${INSTALL_WEB_SERVER}"
echo "PIHOLE_INTERFACE=${PIHOLE_INTERFACE}" addOrEditKeyValPair "${setupVars}" "INSTALL_WEB_INTERFACE" "${INSTALL_WEB_INTERFACE}"
echo "PIHOLE_DNS_1=${PIHOLE_DNS_1}" addOrEditKeyValPair "${setupVars}" "LIGHTTPD_ENABLED" "${LIGHTTPD_ENABLED}"
echo "PIHOLE_DNS_2=${PIHOLE_DNS_2}" addOrEditKeyValPair "${setupVars}" "CACHE_SIZE" "${CACHE_SIZE}"
echo "QUERY_LOGGING=${QUERY_LOGGING}" addOrEditKeyValPair "${setupVars}" "DNS_FQDN_REQUIRED" "${DNS_FQDN_REQUIRED:-true}"
echo "INSTALL_WEB_SERVER=${INSTALL_WEB_SERVER}" addOrEditKeyValPair "${setupVars}" "DNS_BOGUS_PRIV" "${DNS_BOGUS_PRIV:-true}"
echo "INSTALL_WEB_INTERFACE=${INSTALL_WEB_INTERFACE}" addOrEditKeyValPair "${setupVars}" "DNSMASQ_LISTENING" "${DNSMASQ_LISTENING:-local}"
echo "LIGHTTPD_ENABLED=${LIGHTTPD_ENABLED}"
echo "CACHE_SIZE=${CACHE_SIZE}"
echo "DNS_FQDN_REQUIRED=${DNS_FQDN_REQUIRED:-true}"
echo "DNS_BOGUS_PRIV=${DNS_BOGUS_PRIV:-true}"
echo "DNSMASQ_LISTENING=${DNSMASQ_LISTENING:-local}"
}>> "${setupVars}"
chmod 644 "${setupVars}" chmod 644 "${setupVars}"
# Set the privacy level # Set the privacy level
sed -i '/PRIVACYLEVEL/d' "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" addOrEditKeyValPair "${FTL_CONFIG_FILE}" "PRIVACYLEVEL" "${PRIVACY_LEVEL}"
echo "PRIVACYLEVEL=${PRIVACY_LEVEL}" >> "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf"
# Bring in the current settings and the functions to manipulate them # Bring in the current settings and the functions to manipulate them
source "${setupVars}" source "${setupVars}"
@@ -1895,6 +1888,16 @@ installPihole() {
printf " %b Failure in dependent script copy function.\\n" "${CROSS}" printf " %b Failure in dependent script copy function.\\n" "${CROSS}"
exit 1 exit 1
fi fi
# /opt/pihole/utils.sh should be installed by installScripts now, so we can use it
if [ -f "${PI_HOLE_INSTALL_DIR}/utils.sh" ]; then
# shellcheck disable=SC1091
source "${PI_HOLE_INSTALL_DIR}/utils.sh"
else
printf " %b Failure: /opt/pihole/utils.sh does not exist .\\n" "${CROSS}"
exit 1
fi
# Install config files # Install config files
if ! installConfigs; then if ! installConfigs; then
printf " %b Failure in dependent config copy function.\\n" "${CROSS}" printf " %b Failure in dependent config copy function.\\n" "${CROSS}"
@@ -2022,9 +2025,8 @@ update_dialogs() {
\\n($strAdd)"\ \\n($strAdd)"\
"${r}" "${c}" 2 \ "${r}" "${c}" 2 \
"${opt1a}" "${opt1b}" \ "${opt1a}" "${opt1b}" \
"${opt2a}" "${opt2b}" || true) "${opt2a}" "${opt2b}") || result=$?
result=$?
case ${result} in case ${result} in
"${DIALOG_CANCEL}" | "${DIALOG_ESC}") "${DIALOG_CANCEL}" | "${DIALOG_ESC}")
printf " %b Cancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" printf " %b Cancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}"
@@ -2268,7 +2270,7 @@ get_binary_name() {
local rev local rev
rev=$(uname -m | sed "s/[^0-9]//g;") rev=$(uname -m | sed "s/[^0-9]//g;")
local lib local lib
lib=$(ldd "$(which sh)" | grep -E '^\s*/lib' | awk '{ print $1 }') lib=$(ldd "$(command -v sh)" | grep -E '^\s*/lib' | awk '{ print $1 }')
if [[ "${lib}" == "/lib/ld-linux-aarch64.so.1" ]]; then if [[ "${lib}" == "/lib/ld-linux-aarch64.so.1" ]]; then
printf "%b %b Detected AArch64 (64 Bit ARM) processor\\n" "${OVER}" "${TICK}" printf "%b %b Detected AArch64 (64 Bit ARM) processor\\n" "${OVER}" "${TICK}"
# set the binary to be used # set the binary to be used
@@ -2569,8 +2571,8 @@ main() {
source "${setupVars}" source "${setupVars}"
# Get the privacy level if it exists (default is 0) # Get the privacy level if it exists (default is 0)
if [[ -f "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" ]]; then if [[ -f "${FTL_CONFIG_FILE}" ]]; then
PRIVACY_LEVEL=$(sed -ne 's/PRIVACYLEVEL=\(.*\)/\1/p' "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf") PRIVACY_LEVEL=$(sed -ne 's/PRIVACYLEVEL=\(.*\)/\1/p' "${FTL_CONFIG_FILE}")
# If no setting was found, default to 0 # If no setting was found, default to 0
PRIVACY_LEVEL="${PRIVACY_LEVEL:-0}" PRIVACY_LEVEL="${PRIVACY_LEVEL:-0}"
@@ -2694,9 +2696,8 @@ main() {
# Download and compile the aggregated block list # Download and compile the aggregated block list
runGravity runGravity
# Force an update of the updatechecker # Update local and remote versions via updatechecker
/opt/pihole/updatecheck.sh /opt/pihole/updatecheck.sh
/opt/pihole/updatecheck.sh x remote
if [[ "${useUpdateVars}" == false ]]; then if [[ "${useUpdateVars}" == false ]]; then
displayFinalMessage "${pw}" displayFinalMessage "${pw}"

View File

@@ -40,6 +40,7 @@ gravityDBschema="${piholeGitDir}/advanced/Templates/gravity.db.sql"
gravityDBcopy="${piholeGitDir}/advanced/Templates/gravity_copy.sql" gravityDBcopy="${piholeGitDir}/advanced/Templates/gravity_copy.sql"
domainsExtension="domains" domainsExtension="domains"
curl_connect_timeout=10
# Source setupVars from install script # Source setupVars from install script
setupVars="${piholeDir}/setupVars.conf" setupVars="${piholeDir}/setupVars.conf"
@@ -641,7 +642,7 @@ gravity_DownloadBlocklistFromUrl() {
fi fi
# shellcheck disable=SC2086 # shellcheck disable=SC2086
httpCode=$(curl -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" -A "${agent}" "${url}" -o "${patternBuffer}" 2> /dev/null) httpCode=$(curl --connect-timeout ${curl_connect_timeout} -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" -A "${agent}" "${url}" -o "${patternBuffer}" 2> /dev/null)
case $url in case $url in
# Did we "download" a local file? # Did we "download" a local file?
@@ -719,72 +720,25 @@ gravity_DownloadBlocklistFromUrl() {
# Parse source files into domains format # Parse source files into domains format
gravity_ParseFileIntoDomains() { gravity_ParseFileIntoDomains() {
local src="${1}" destination="${2}" firstLine local src="${1}" destination="${2}"
# Determine if we are parsing a consolidated list # Remove comments and print only the domain name
#if [[ "${src}" == "${piholeDir}/${matterAndLight}" ]]; then # Most of the lists downloaded are already in hosts file format but the spacing/formatting is not contiguous
# Remove comments and print only the domain name # This helps with that and makes it easier to read
# Most of the lists downloaded are already in hosts file format but the spacing/formatting is not contiguous # It also helps with debugging so each stage of the script can be researched more in depth
# This helps with that and makes it easier to read # 1) Remove carriage returns
# It also helps with debugging so each stage of the script can be researched more in depth # 2) Convert all characters to lowercase
# 1) Remove carriage returns # 3) Remove comments (text starting with "#", include possible spaces before the hash sign)
# 2) Convert all characters to lowercase # 4) Remove lines containing "/"
# 3) Remove comments (text starting with "#", include possible spaces before the hash sign) # 5) Remove leading tabs, spaces, etc.
# 4) Remove lines containing "/" # 6) Delete lines not matching domain names
# 5) Remove leading tabs, spaces, etc. < "${src}" tr -d '\r' | \
# 6) Delete lines not matching domain names tr '[:upper:]' '[:lower:]' | \
< "${src}" tr -d '\r' | \ sed 's/\s*#.*//g' | \
tr '[:upper:]' '[:lower:]' | \ sed -r '/(\/).*$/d' | \
sed 's/\s*#.*//g' | \ sed -r 's/^.*\s+//g' | \
sed -r '/(\/).*$/d' | \ sed -r '/([^\.]+\.)+[^\.]{2,}/!d' > "${destination}"
sed -r 's/^.*\s+//g' | \ chmod 644 "${destination}"
sed -r '/([^\.]+\.)+[^\.]{2,}/!d' > "${destination}"
chmod 644 "${destination}"
return 0
#fi
# Individual file parsing: Keep comments, while parsing domains from each line
# We keep comments to respect the list maintainer's licensing
read -r firstLine < "${src}"
# Determine how to parse individual source file formats
if [[ "${firstLine,,}" =~ (adblock|ublock|^!) ]]; then
# Compare $firstLine against lower case words found in Adblock lists
echo -e " ${CROSS} Format: Adblock (list type not supported)"
elif grep -q "^address=/" "${src}" &> /dev/null; then
# Parse Dnsmasq format lists
echo -e " ${CROSS} Format: Dnsmasq (list type not supported)"
elif grep -q -E "^https?://" "${src}" &> /dev/null; then
# Parse URL list if source file contains "http://" or "https://"
# Scanning for "^IPv4$" is too slow with large (1M) lists on low-end hardware
echo -ne " ${INFO} Format: URL"
awk '
# Remove URL scheme, optional "username:password@", and ":?/;"
# The scheme must be matched carefully to avoid blocking the wrong URL
# in cases like:
# http://www.evil.com?http://www.good.com
# See RFC 3986 section 3.1 for details.
/[:?\/;]/ { gsub(/(^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/(.*:.*@)?|[:?\/;].*)/, "", $0) }
# Skip lines which are only IPv4 addresses
/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ { next }
# Print if nonempty
length { print }
' "${src}" 2> /dev/null > "${destination}"
chmod 644 "${destination}"
echo -e "${OVER} ${TICK} Format: URL"
else
# Default: Keep hosts/domains file in same format as it was downloaded
output=$( { mv "${src}" "${destination}"; } 2>&1 )
chmod 644 "${destination}"
if [[ ! -e "${destination}" ]]; then
echo -e "\\n ${CROSS} Unable to move tmp file to ${piholeDir}
${output}"
gravity_Cleanup "error"
fi
fi
} }
# Report number of entries in a table # Report number of entries in a table

13
pihole
View File

@@ -104,6 +104,9 @@ restartDNS() {
local svcOption svc str output status pid icon FTL_PID_FILE local svcOption svc str output status pid icon FTL_PID_FILE
svcOption="${1:-restart}" svcOption="${1:-restart}"
# get the current path to the pihole-FTL.pid
FTL_PID_FILE="$(getFTLPIDFile)"
# Determine if we should reload or restart # Determine if we should reload or restart
if [[ "${svcOption}" =~ "reload-lists" ]]; then if [[ "${svcOption}" =~ "reload-lists" ]]; then
# Reloading of the lists has been requested # Reloading of the lists has been requested
@@ -111,9 +114,6 @@ restartDNS() {
# Note 2: We cannot use killall here as it does # Note 2: We cannot use killall here as it does
# not know about real-time signals # not know about real-time signals
# get the current path to the pihole-FTL.pid
FTL_PID_FILE="$(getFTLPIDFile)"
pid="$(getFTLPID ${FTL_PID_FILE})" pid="$(getFTLPID ${FTL_PID_FILE})"
if [[ "$pid" -eq "-1" ]]; then if [[ "$pid" -eq "-1" ]]; then
svc="true" svc="true"
@@ -303,14 +303,13 @@ analyze_ports() {
statusFunc() { statusFunc() {
# Determine if there is pihole-FTL service is listening # Determine if there is pihole-FTL service is listening
local pid port ftl_api_port ftl_pid_file ftl_apiport_file local pid port ftl_api_port ftl_pid_file
ftl_pid_file="$(getFTLPIDFile)" ftl_pid_file="$(getFTLPIDFile)"
pid="$(getFTLPID ${ftl_pid_file})" pid="$(getFTLPID ${ftl_pid_file})"
ftl_apiport_file="${getFTLAPIPortFile}" ftl_api_port="$(getFTLAPIPort)"
ftl_api_port="$(getFTLAPIPort ${ftl_apiport_file})"
if [[ "$pid" -eq "-1" ]]; then if [[ "$pid" -eq "-1" ]]; then
case "${1}" in case "${1}" in
"web") echo "-1";; "web") echo "-1";;
@@ -554,7 +553,7 @@ case "${1}" in
"restartdns" ) restartDNS "$2";; "restartdns" ) restartDNS "$2";;
"-a" | "admin" ) webpageFunc "$@";; "-a" | "admin" ) webpageFunc "$@";;
"checkout" ) piholeCheckoutFunc "$@";; "checkout" ) piholeCheckoutFunc "$@";;
"updatechecker" ) updateCheckFunc "$@";; "updatechecker" ) shift; updateCheckFunc "$@";;
"arpflush" ) arpFunc "$@";; "arpflush" ) arpFunc "$@";;
"-t" | "tail" ) tailFunc "$2";; "-t" | "tail" ) tailFunc "$2";;
esac esac

View File

@@ -1,5 +1,5 @@
FROM quay.io/centos/centos:stream8 FROM quay.io/centos/centos:stream8
RUN yum install -y git RUN yum install -y git initscripts
ENV GITDIR /etc/.pihole ENV GITDIR /etc/.pihole
ENV SCRIPTDIR /opt/pihole ENV SCRIPTDIR /opt/pihole

18
test/_centos_9.Dockerfile Normal file
View File

@@ -0,0 +1,18 @@
FROM quay.io/centos/centos:stream9
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 $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
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 && \

View File

@@ -1,5 +1,5 @@
FROM fedora:34 FROM fedora:35
RUN dnf install -y git RUN dnf install -y git initscripts
ENV GITDIR /etc/.pihole ENV GITDIR /etc/.pihole
ENV SCRIPTDIR /opt/pihole ENV SCRIPTDIR /opt/pihole

View File

@@ -1,4 +1,5 @@
FROM buildpack-deps:bionic-scm FROM fedora:36
RUN dnf install -y git initscripts
ENV GITDIR /etc/.pihole ENV GITDIR /etc/.pihole
ENV SCRIPTDIR /opt/pihole ENV SCRIPTDIR /opt/pihole

View File

@@ -6,12 +6,12 @@ from textwrap import dedent
SETUPVARS = { SETUPVARS = {
'PIHOLE_INTERFACE': 'eth99', "PIHOLE_INTERFACE": "eth99",
'PIHOLE_DNS_1': '4.2.2.1', "PIHOLE_DNS_1": "4.2.2.1",
'PIHOLE_DNS_2': '4.2.2.2' "PIHOLE_DNS_2": "4.2.2.2",
} }
IMAGE = 'pytest_pihole:test_container' IMAGE = "pytest_pihole:test_container"
tick_box = "[\x1b[1;32m\u2713\x1b[0m]" tick_box = "[\x1b[1;32m\u2713\x1b[0m]"
cross_box = "[\x1b[1;31m\u2717\x1b[0m]" cross_box = "[\x1b[1;31m\u2717\x1b[0m]"
@@ -38,132 +38,187 @@ testinfra.backend.docker.DockerBackend.run = run_bash
@pytest.fixture @pytest.fixture
def host(): def host():
# run a container # run a container
docker_id = subprocess.check_output( docker_id = (
['docker', 'run', '-t', '-d', '--cap-add=ALL', IMAGE]).decode().strip() subprocess.check_output(["docker", "run", "-t", "-d", "--cap-add=ALL", IMAGE])
.decode()
.strip()
)
# return a testinfra connection to the container # return a testinfra connection to the container
docker_host = testinfra.get_host("docker://" + docker_id) docker_host = testinfra.get_host("docker://" + docker_id)
yield docker_host yield docker_host
# at the end of the test suite, destroy the container # at the end of the test suite, destroy the container
subprocess.check_call(['docker', 'rm', '-f', docker_id]) subprocess.check_call(["docker", "rm", "-f", docker_id])
# Helper functions # Helper functions
def mock_command(script, args, container): def mock_command(script, args, container):
''' """
Allows for setup of commands we don't really want to have to run for real Allows for setup of commands we don't really want to have to run for real
in unit tests in unit tests
''' """
full_script_path = '/usr/local/bin/{}'.format(script) full_script_path = "/usr/local/bin/{}".format(script)
mock_script = dedent(r'''\ mock_script = dedent(
r"""\
#!/bin/bash -e #!/bin/bash -e
echo "\$0 \$@" >> /var/log/{script} echo "\$0 \$@" >> /var/log/{script}
case "\$1" in'''.format(script=script)) case "\$1" in""".format(
script=script
)
)
for k, v in args.items(): for k, v in args.items():
case = dedent(''' case = dedent(
"""
{arg}) {arg})
echo {res} echo {res}
exit {retcode} exit {retcode}
;;'''.format(arg=k, res=v[0], retcode=v[1])) ;;""".format(
arg=k, res=v[0], retcode=v[1]
)
)
mock_script += case mock_script += case
mock_script += dedent(''' mock_script += dedent(
esac''') """
container.run(''' esac"""
)
container.run(
"""
cat <<EOF> {script}\n{content}\nEOF cat <<EOF> {script}\n{content}\nEOF
chmod +x {script} chmod +x {script}
rm -f /var/log/{scriptlog}'''.format(script=full_script_path, rm -f /var/log/{scriptlog}""".format(
content=mock_script, script=full_script_path, content=mock_script, scriptlog=script
scriptlog=script)) )
)
def mock_command_passthrough(script, args, container): def mock_command_passthrough(script, args, container):
''' """
Per other mock_command* functions, allows intercepting of commands we don't want to run for real Per other mock_command* functions, allows intercepting of commands we don't want to run for real
in unit tests, however also allows only specific arguments to be mocked. Anything not defined will in unit tests, however also allows only specific arguments to be mocked. Anything not defined will
be passed through to the actual command. be passed through to the actual command.
Example use-case: mocking `git pull` but still allowing `git clone` to work as intended Example use-case: mocking `git pull` but still allowing `git clone` to work as intended
''' """
orig_script_path = container.check_output('command -v {}'.format(script)) orig_script_path = container.check_output("command -v {}".format(script))
full_script_path = '/usr/local/bin/{}'.format(script) full_script_path = "/usr/local/bin/{}".format(script)
mock_script = dedent(r'''\ mock_script = dedent(
r"""\
#!/bin/bash -e #!/bin/bash -e
echo "\$0 \$@" >> /var/log/{script} echo "\$0 \$@" >> /var/log/{script}
case "\$1" in'''.format(script=script)) case "\$1" in""".format(
script=script
)
)
for k, v in args.items(): for k, v in args.items():
case = dedent(''' case = dedent(
"""
{arg}) {arg})
echo {res} echo {res}
exit {retcode} exit {retcode}
;;'''.format(arg=k, res=v[0], retcode=v[1])) ;;""".format(
arg=k, res=v[0], retcode=v[1]
)
)
mock_script += case mock_script += case
mock_script += dedent(r''' mock_script += dedent(
r"""
*) *)
{orig_script_path} "\$@" {orig_script_path} "\$@"
;;'''.format(orig_script_path=orig_script_path)) ;;""".format(
mock_script += dedent(''' orig_script_path=orig_script_path
esac''') )
container.run(''' )
mock_script += dedent(
"""
esac"""
)
container.run(
"""
cat <<EOF> {script}\n{content}\nEOF cat <<EOF> {script}\n{content}\nEOF
chmod +x {script} chmod +x {script}
rm -f /var/log/{scriptlog}'''.format(script=full_script_path, rm -f /var/log/{scriptlog}""".format(
content=mock_script, script=full_script_path, content=mock_script, scriptlog=script
scriptlog=script)) )
)
def mock_command_run(script, args, container): def mock_command_run(script, args, container):
''' """
Allows for setup of commands we don't really want to have to run for real Allows for setup of commands we don't really want to have to run for real
in unit tests in unit tests
''' """
full_script_path = '/usr/local/bin/{}'.format(script) full_script_path = "/usr/local/bin/{}".format(script)
mock_script = dedent(r'''\ mock_script = dedent(
r"""\
#!/bin/bash -e #!/bin/bash -e
echo "\$0 \$@" >> /var/log/{script} echo "\$0 \$@" >> /var/log/{script}
case "\$1 \$2" in'''.format(script=script)) case "\$1 \$2" in""".format(
script=script
)
)
for k, v in args.items(): for k, v in args.items():
case = dedent(''' case = dedent(
"""
\"{arg}\") \"{arg}\")
echo {res} echo {res}
exit {retcode} exit {retcode}
;;'''.format(arg=k, res=v[0], retcode=v[1])) ;;""".format(
arg=k, res=v[0], retcode=v[1]
)
)
mock_script += case mock_script += case
mock_script += dedent(''' mock_script += dedent(
esac''') """
container.run(''' esac"""
)
container.run(
"""
cat <<EOF> {script}\n{content}\nEOF cat <<EOF> {script}\n{content}\nEOF
chmod +x {script} chmod +x {script}
rm -f /var/log/{scriptlog}'''.format(script=full_script_path, rm -f /var/log/{scriptlog}""".format(
content=mock_script, script=full_script_path, content=mock_script, scriptlog=script
scriptlog=script)) )
)
def mock_command_2(script, args, container): def mock_command_2(script, args, container):
''' """
Allows for setup of commands we don't really want to have to run for real Allows for setup of commands we don't really want to have to run for real
in unit tests in unit tests
''' """
full_script_path = '/usr/local/bin/{}'.format(script) full_script_path = "/usr/local/bin/{}".format(script)
mock_script = dedent(r'''\ mock_script = dedent(
r"""\
#!/bin/bash -e #!/bin/bash -e
echo "\$0 \$@" >> /var/log/{script} echo "\$0 \$@" >> /var/log/{script}
case "\$1 \$2" in'''.format(script=script)) case "\$1 \$2" in""".format(
script=script
)
)
for k, v in args.items(): for k, v in args.items():
case = dedent(''' case = dedent(
"""
\"{arg}\") \"{arg}\")
echo \"{res}\" echo \"{res}\"
exit {retcode} exit {retcode}
;;'''.format(arg=k, res=v[0], retcode=v[1])) ;;""".format(
arg=k, res=v[0], retcode=v[1]
)
)
mock_script += case mock_script += case
mock_script += dedent(''' mock_script += dedent(
esac''') """
container.run(''' esac"""
)
container.run(
"""
cat <<EOF> {script}\n{content}\nEOF cat <<EOF> {script}\n{content}\nEOF
chmod +x {script} chmod +x {script}
rm -f /var/log/{scriptlog}'''.format(script=full_script_path, rm -f /var/log/{scriptlog}""".format(
content=mock_script, script=full_script_path, content=mock_script, scriptlog=script
scriptlog=script)) )
)
def run_script(Pihole, script): def run_script(Pihole, script):

View File

@@ -1,6 +1,5 @@
docker-compose docker-compose
pytest pytest
pytest-xdist pytest-xdist
pytest-cov
pytest-testinfra pytest-testinfra
tox tox

View File

@@ -1,6 +1,7 @@
from setuptools import setup from setuptools import setup
setup( setup(
setup_requires=['pytest-runner'], py_modules=[],
tests_require=['pytest'], setup_requires=["pytest-runner"],
tests_require=["pytest"],
) )

File diff suppressed because it is too large Load Diff

View File

@@ -1,22 +1,27 @@
def test_key_val_replacement_works(host): def test_key_val_replacement_works(host):
''' Confirms addOrEditKeyValPair either adds or replaces a key value pair in a given file ''' """Confirms addOrEditKeyValPair either adds or replaces a key value pair in a given file"""
host.run(''' host.run(
"""
source /opt/pihole/utils.sh source /opt/pihole/utils.sh
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1" addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1"
addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2" addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2"
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value3" addOrEditKeyValPair "./testoutput" "KEY_ONE" "value3"
addOrEditKeyValPair "./testoutput" "KEY_FOUR" "value4" addOrEditKeyValPair "./testoutput" "KEY_FOUR" "value4"
''') """
output = host.run(''' )
output = host.run(
"""
cat ./testoutput cat ./testoutput
''') """
expected_stdout = 'KEY_ONE=value3\nKEY_TWO=value2\nKEY_FOUR=value4\n' )
expected_stdout = "KEY_ONE=value3\nKEY_TWO=value2\nKEY_FOUR=value4\n"
assert expected_stdout == output.stdout assert expected_stdout == output.stdout
def test_key_addition_works(host): def test_key_addition_works(host):
''' Confirms addKey adds a key (no value) to a file without duplicating it ''' """Confirms addKey adds a key (no value) to a file without duplicating it"""
host.run(''' host.run(
"""
source /opt/pihole/utils.sh source /opt/pihole/utils.sh
addKey "./testoutput" "KEY_ONE" addKey "./testoutput" "KEY_ONE"
addKey "./testoutput" "KEY_ONE" addKey "./testoutput" "KEY_ONE"
@@ -24,17 +29,21 @@ def test_key_addition_works(host):
addKey "./testoutput" "KEY_TWO" addKey "./testoutput" "KEY_TWO"
addKey "./testoutput" "KEY_THREE" addKey "./testoutput" "KEY_THREE"
addKey "./testoutput" "KEY_THREE" addKey "./testoutput" "KEY_THREE"
''') """
output = host.run(''' )
output = host.run(
"""
cat ./testoutput cat ./testoutput
''') """
expected_stdout = 'KEY_ONE\nKEY_TWO\nKEY_THREE\n' )
expected_stdout = "KEY_ONE\nKEY_TWO\nKEY_THREE\n"
assert expected_stdout == output.stdout assert expected_stdout == output.stdout
def test_key_removal_works(host): def test_key_removal_works(host):
''' Confirms removeKey removes a key or key/value pair ''' """Confirms removeKey removes a key or key/value pair"""
host.run(''' host.run(
"""
source /opt/pihole/utils.sh source /opt/pihole/utils.sh
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1" addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1"
addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2" addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2"
@@ -42,81 +51,102 @@ def test_key_removal_works(host):
addKey "./testoutput" "KEY_FOUR" addKey "./testoutput" "KEY_FOUR"
removeKey "./testoutput" "KEY_TWO" removeKey "./testoutput" "KEY_TWO"
removeKey "./testoutput" "KEY_FOUR" removeKey "./testoutput" "KEY_FOUR"
''') """
output = host.run(''' )
output = host.run(
"""
cat ./testoutput cat ./testoutput
''') """
expected_stdout = 'KEY_ONE=value1\nKEY_THREE=value3\n' )
assert expected_stdout == output.stdout expected_stdout = "KEY_ONE=value1\nKEY_THREE=value3\n"
def test_getFTLAPIPortFile_default(host):
''' Confirms getFTLAPIPortFile returns the default API port file path '''
output = host.run('''
source /opt/pihole/utils.sh
getFTLAPIPortFile
''')
expected_stdout = '/run/pihole-FTL.port\n'
assert expected_stdout == output.stdout assert expected_stdout == output.stdout
def test_getFTLAPIPort_default(host): def test_getFTLAPIPort_default(host):
''' Confirms getFTLAPIPort returns the default API port ''' """Confirms getFTLAPIPort returns the default API port"""
output = host.run(''' output = host.run(
"""
source /opt/pihole/utils.sh source /opt/pihole/utils.sh
getFTLAPIPort "/run/pihole-FTL.port" getFTLAPIPort
''') """
expected_stdout = '4711\n' )
expected_stdout = "4711\n"
assert expected_stdout == output.stdout assert expected_stdout == output.stdout
def test_getFTLAPIPortFile_and_getFTLAPIPort_custom(host): def test_getFTLAPIPort_custom(host):
''' Confirms getFTLAPIPort returns a custom API port in a custom PORTFILE location ''' """Confirms getFTLAPIPort returns a custom API port"""
host.run(''' host.run(
tmpfile=$(mktemp) """
echo "PORTFILE=${tmpfile}" > /etc/pihole/pihole-FTL.conf echo "FTLPORT=1234" > /etc/pihole/pihole-FTL.conf
echo "1234" > ${tmpfile} """
''') )
output = host.run(''' output = host.run(
"""
source /opt/pihole/utils.sh source /opt/pihole/utils.sh
FTL_API_PORT_FILE=$(getFTLAPIPortFile) getFTLAPIPort
getFTLAPIPort "${FTL_API_PORT_FILE}" """
''') )
expected_stdout = '1234\n' expected_stdout = "1234\n"
assert expected_stdout == output.stdout
def test_getFTLAPIPort_malicious(host):
"""Confirms getFTLAPIPort returns 4711 if the setting in pihole-FTL.conf contains non-digits"""
host.run(
"""
echo "FTLPORT=*$ssdfsd" > /etc/pihole/pihole-FTL.conf
"""
)
output = host.run(
"""
source /opt/pihole/utils.sh
getFTLAPIPort
"""
)
expected_stdout = "4711\n"
assert expected_stdout == output.stdout assert expected_stdout == output.stdout
def test_getFTLPIDFile_default(host): def test_getFTLPIDFile_default(host):
''' Confirms getFTLPIDFile returns the default PID file path ''' """Confirms getFTLPIDFile returns the default PID file path"""
output = host.run(''' output = host.run(
"""
source /opt/pihole/utils.sh source /opt/pihole/utils.sh
getFTLPIDFile getFTLPIDFile
''') """
expected_stdout = '/run/pihole-FTL.pid\n' )
expected_stdout = "/run/pihole-FTL.pid\n"
assert expected_stdout == output.stdout assert expected_stdout == output.stdout
def test_getFTLPID_default(host): def test_getFTLPID_default(host):
''' Confirms getFTLPID returns the default value if FTL is not running ''' """Confirms getFTLPID returns the default value if FTL is not running"""
output = host.run(''' output = host.run(
"""
source /opt/pihole/utils.sh source /opt/pihole/utils.sh
getFTLPID getFTLPID
''') """
expected_stdout = '-1\n' )
expected_stdout = "-1\n"
assert expected_stdout == output.stdout assert expected_stdout == output.stdout
def test_getFTLPIDFile_and_getFTLPID_custom(host): def test_getFTLPIDFile_and_getFTLPID_custom(host):
''' Confirms getFTLPIDFile returns a custom PID file path ''' """Confirms getFTLPIDFile returns a custom PID file path"""
host.run(''' host.run(
"""
tmpfile=$(mktemp) tmpfile=$(mktemp)
echo "PIDFILE=${tmpfile}" > /etc/pihole/pihole-FTL.conf echo "PIDFILE=${tmpfile}" > /etc/pihole/pihole-FTL.conf
echo "1234" > ${tmpfile} echo "1234" > ${tmpfile}
''') """
output = host.run(''' )
output = host.run(
"""
source /opt/pihole/utils.sh source /opt/pihole/utils.sh
FTL_PID_FILE=$(getFTLPIDFile) FTL_PID_FILE=$(getFTLPIDFile)
getFTLPID "${FTL_PID_FILE}" getFTLPID "${FTL_PID_FILE}"
''') """
expected_stdout = '1234\n' )
expected_stdout = "1234\n"
assert expected_stdout == output.stdout assert expected_stdout == output.stdout

View File

@@ -8,17 +8,20 @@ from .conftest import (
def test_enable_epel_repository_centos(host): def test_enable_epel_repository_centos(host):
''' """
confirms the EPEL package repository is enabled when installed on CentOS confirms the EPEL package repository is enabled when installed on CentOS
''' """
package_manager_detect = host.run(''' package_manager_detect = host.run(
"""
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
package_manager_detect package_manager_detect
''') """
expected_stdout = info_box + (' Enabling EPEL package repository ' )
'(https://fedoraproject.org/wiki/EPEL)') expected_stdout = info_box + (
" Enabling EPEL package repository " "(https://fedoraproject.org/wiki/EPEL)"
)
assert expected_stdout in package_manager_detect.stdout assert expected_stdout in package_manager_detect.stdout
expected_stdout = tick_box + ' Installed' expected_stdout = tick_box + " Installed"
assert expected_stdout in package_manager_detect.stdout assert expected_stdout in package_manager_detect.stdout
epel_package = host.package('epel-release') epel_package = host.package("epel-release")
assert epel_package.is_installed assert epel_package.is_installed

View File

@@ -6,60 +6,70 @@ from .conftest import (
def mock_selinux_config(state, host): def mock_selinux_config(state, host):
''' """
Creates a mock SELinux config file with expected content Creates a mock SELinux config file with expected content
''' """
# validate state string # validate state string
valid_states = ['enforcing', 'permissive', 'disabled'] valid_states = ["enforcing", "permissive", "disabled"]
assert state in valid_states assert state in valid_states
# getenforce returns the running state of SELinux # getenforce returns the running state of SELinux
mock_command('getenforce', {'*': (state.capitalize(), '0')}, host) mock_command("getenforce", {"*": (state.capitalize(), "0")}, host)
# create mock configuration with desired content # create mock configuration with desired content
host.run(''' host.run(
"""
mkdir /etc/selinux mkdir /etc/selinux
echo "SELINUX={state}" > /etc/selinux/config echo "SELINUX={state}" > /etc/selinux/config
'''.format(state=state.lower())) """.format(
state=state.lower()
)
)
def test_selinux_enforcing_exit(host): def test_selinux_enforcing_exit(host):
''' """
confirms installer prompts to exit when SELinux is Enforcing by default confirms installer prompts to exit when SELinux is Enforcing by default
''' """
mock_selinux_config("enforcing", host) mock_selinux_config("enforcing", host)
check_selinux = host.run(''' check_selinux = host.run(
"""
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
checkSelinux checkSelinux
''') """
expected_stdout = cross_box + ' Current SELinux: enforcing' )
expected_stdout = cross_box + " Current SELinux: enforcing"
assert expected_stdout in check_selinux.stdout assert expected_stdout in check_selinux.stdout
expected_stdout = 'SELinux Enforcing detected, exiting installer' expected_stdout = "SELinux Enforcing detected, exiting installer"
assert expected_stdout in check_selinux.stdout assert expected_stdout in check_selinux.stdout
assert check_selinux.rc == 1 assert check_selinux.rc == 1
def test_selinux_permissive(host): def test_selinux_permissive(host):
''' """
confirms installer continues when SELinux is Permissive confirms installer continues when SELinux is Permissive
''' """
mock_selinux_config("permissive", host) mock_selinux_config("permissive", host)
check_selinux = host.run(''' check_selinux = host.run(
"""
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
checkSelinux checkSelinux
''') """
expected_stdout = tick_box + ' Current SELinux: permissive' )
expected_stdout = tick_box + " Current SELinux: permissive"
assert expected_stdout in check_selinux.stdout assert expected_stdout in check_selinux.stdout
assert check_selinux.rc == 0 assert check_selinux.rc == 0
def test_selinux_disabled(host): def test_selinux_disabled(host):
''' """
confirms installer continues when SELinux is Disabled confirms installer continues when SELinux is Disabled
''' """
mock_selinux_config("disabled", host) mock_selinux_config("disabled", host)
check_selinux = host.run(''' check_selinux = host.run(
"""
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
checkSelinux checkSelinux
''') """
expected_stdout = tick_box + ' Current SELinux: disabled' )
expected_stdout = tick_box + " Current SELinux: disabled"
assert expected_stdout in check_selinux.stdout assert expected_stdout in check_selinux.stdout
assert check_selinux.rc == 0 assert check_selinux.rc == 0

View File

@@ -1,13 +1,15 @@
def test_epel_and_remi_not_installed_fedora(host): def test_epel_and_remi_not_installed_fedora(host):
''' """
confirms installer does not attempt to install EPEL/REMI repositories confirms installer does not attempt to install EPEL/REMI repositories
on Fedora on Fedora
''' """
package_manager_detect = host.run(''' package_manager_detect = host.run(
"""
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
package_manager_detect package_manager_detect
''') """
assert package_manager_detect.stdout == '' )
assert package_manager_detect.stdout == ""
epel_package = host.package('epel-release') epel_package = host.package("epel-release")
assert not epel_package.is_installed assert not epel_package.is_installed

View File

@@ -1,8 +1,8 @@
[tox] [tox]
envlist = py38 envlist = py3
[testenv] [testenv]
whitelist_externals = docker allowlist_externals = docker
deps = -rrequirements.txt deps = -rrequirements.txt
commands = docker build -f _centos_8.Dockerfile -t pytest_pihole:test_container ../ commands = docker build -f _centos_8.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 ./test_centos_common_support.py pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py

8
test/tox.centos_9.ini Normal file
View File

@@ -0,0 +1,8 @@
[tox]
envlist = py3
[testenv]
allowlist_externals = docker
deps = -rrequirements.txt
commands = docker build -f _centos_9.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 ./test_centos_common_support.py

View File

@@ -1,8 +1,8 @@
[tox] [tox]
envlist = py38 envlist = py3
[testenv] [testenv]
whitelist_externals = docker allowlist_externals = docker
deps = -rrequirements.txt deps = -rrequirements.txt
commands = docker build -f _debian_10.Dockerfile -t pytest_pihole:test_container ../ commands = docker build -f _debian_10.Dockerfile -t pytest_pihole:test_container ../
pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py

View File

@@ -1,8 +1,8 @@
[tox] [tox]
envlist = py38 envlist = py3
[testenv] [testenv]
whitelist_externals = docker allowlist_externals = docker
deps = -rrequirements.txt deps = -rrequirements.txt
commands = docker build -f _debian_11.Dockerfile -t pytest_pihole:test_container ../ commands = docker build -f _debian_11.Dockerfile -t pytest_pihole:test_container ../
pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py

View File

@@ -1,8 +1,8 @@
[tox] [tox]
envlist = py38 envlist = py3
[testenv] [testenv]
whitelist_externals = docker allowlist_externals = docker
deps = -rrequirements.txt deps = -rrequirements.txt
commands = docker build -f _fedora_34.Dockerfile -t pytest_pihole:test_container ../ commands = docker build -f _fedora_35.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 ./test_fedora_support.py pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py

8
test/tox.fedora_36.ini Normal file
View File

@@ -0,0 +1,8 @@
[tox]
envlist = py3
[testenv]
allowlist_externals = docker
deps = -rrequirements.txt
commands = docker build -f _fedora_36.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 ./test_fedora_support.py

View File

@@ -1,8 +0,0 @@
[tox]
envlist = py38
[testenv]
whitelist_externals = docker
deps = -rrequirements.txt
commands = docker build -f _ubuntu_18.Dockerfile -t pytest_pihole:test_container ../
pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py

View File

@@ -1,8 +1,8 @@
[tox] [tox]
envlist = py38 envlist = py3
[testenv] [testenv]
whitelist_externals = docker allowlist_externals = docker
deps = -rrequirements.txt deps = -rrequirements.txt
commands = docker build -f _ubuntu_20.Dockerfile -t pytest_pihole:test_container ../ commands = docker build -f _ubuntu_20.Dockerfile -t pytest_pihole:test_container ../
pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py

View File

@@ -1,8 +1,8 @@
[tox] [tox]
envlist = py38 envlist = py3
[testenv] [testenv]
whitelist_externals = docker allowlist_externals = docker
deps = -rrequirements.txt deps = -rrequirements.txt
commands = docker build -f _ubuntu_22.Dockerfile -t pytest_pihole:test_container ../ commands = docker build -f _ubuntu_22.Dockerfile -t pytest_pihole:test_container ../
pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py