Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to ignore unknown DHCP clients #1980

Merged
merged 3 commits into from
Jun 1, 2024

Conversation

DL6ER
Copy link
Member

@DL6ER DL6ER commented May 30, 2024

What does this implement/fix?

Add new dhcp.ignoreUnknownClients option which has been requested on Discourse. It works as follows:

Screenshot from 2024-05-30 19-04-33

This PR also features a second commit updating forgotten changes into test/pihole.toml and adds a CI test to prevent forgetting to update this file in the future.


Related issue or feature (if applicable): https://discourse.pi-hole.net/t/add-checkbox-to-block-dhcp-for-unknown-hosts/70485

Pull request in docs with documentation (if applicable): N/A


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)

Checklist:

  • The code change is tested and works locally.
  • I based my code and PRs against the repositories developmental branch.
  • I signed off all commits. Pi-hole enforces the DCO for all contributions
  • I signed all my commits. Pi-hole requires signatures to verify authorship
  • I have read the above and my PR is ready for review.

Signed-off-by: DL6ER <dl6er@dl6er.de>
@pralor-bot
Copy link

This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there:

https://discourse.pi-hole.net/t/add-checkbox-to-block-dhcp-for-unknown-hosts/70485/5

@DL6ER DL6ER changed the title New/dhcp ignore unknown clients Add option to ignore unknown DHCP clients May 30, 2024
…ave been made in between and add a test ensuring they remain in sync in the future

Signed-off-by: DL6ER <dl6er@dl6er.de>
@DL6ER DL6ER force-pushed the new/dhcp_ignoreUnknownClients branch from 4bd3364 to 96da0d4 Compare May 30, 2024 17:16
@@ -23,13 +23,12 @@ done
rm -rf /etc/pihole /var/log/pihole /dev/shm/FTL-*

# Create necessary directories and files
mkdir -p /home/pihole /etc/pihole /run/pihole /var/log/pihole
mkdir -p /home/pihole /etc/pihole /run/pihole /var/log/pihole /etc/pihole/config_backups
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/etc/pihole/config_backups was not created, causing:

2024-05-30 17:09:24.091 [1119/T1132] DEBUG_CONFIG: Copying /etc/pihole/pihole.toml -> /etc/pihole/config_backups/pihole.toml.1
2024-05-30 17:09:24.091 [1119/T1132] WARNING: copy_file(): Failed to open "/etc/pihole/config_backups/pihole.toml.1" for writing: Permission denied
2024-05-30 17:09:24.091 [1119/T1132] WARNING: Rotation /etc/pihole/pihole.toml -(COPY)> /etc/pihole/config_backups/pihole.toml.1 failed
2024-05-30 17:09:24.091 [1119/T1132] WARNING: chown_pihole(): Failed to change ownership of "/etc/pihole/config_backups/pihole.toml.1" to 1000:1000: Permission denied

during CI runs. It just looked like worth fixing

test/run.sh Outdated
touch /var/log/pihole/HTTP_info.log /var/log/pihole/PH7.log /etc/pihole/dhcp.leases
chown pihole:pihole /etc/pihole /run/pihole /var/log/pihole/pihole.log /var/log/pihole/FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port
chown pihole:pihole /var/log/pihole/HTTP_info.log /var/log/pihole/PH7.log /etc/pihole/dhcp.leases
touch /var/log/pihole/HTTP_info.log /etc/pihole/dhcp.leases
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed PH7.log

chown pihole:pihole /etc/pihole /run/pihole /var/log/pihole/pihole.log /var/log/pihole/FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port
chown pihole:pihole /var/log/pihole/HTTP_info.log /var/log/pihole/PH7.log /etc/pihole/dhcp.leases
touch /var/log/pihole/HTTP_info.log /etc/pihole/dhcp.leases
chown -R pihole:pihole /etc/pihole /run/pihole /var/log/pihole
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified chown by recursively chowning the same directories which are also owned by pihole:pihole on regular installs, ensures we cannot forget to set appropriate permissions if we add new files

test/run.sh Outdated
Comment on lines 131 to 133
echo -n "PH7.log: "
curl_to_tricorder /var/log/pihole/PH7.log
echo ""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed PH7.log here as well

Comment on lines -3 to -27
#@test "Version, Tag, Branch, Hash, Date is reported" {
# run bash -c 'echo ">version >quit" | nc -v 127.0.0.1 4711'
# printf "%s\n" "${lines[@]}"
# [[ ${lines[1]} == "version "* ]]
# [[ ${lines[2]} == "tag "* ]]
# [[ ${lines[3]} == "branch "* ]]
# [[ ${lines[4]} == "hash "* ]]
# [[ ${lines[5]} == "date "* ]]
# [[ ${lines[6]} == "" ]]
#}
#
#@test "DNS server port is reported over Telnet API" {
# run bash -c 'echo ">dns-port >quit" | nc -v 127.0.0.1 4711'
# printf "%s\n" "${lines[@]}"
# [[ ${lines[1]} == "53" ]]
# [[ ${lines[2]} == "" ]]
#}
#
#@test "Maxlogage value is reported over Telnet API" {
# run bash -c 'echo ">maxlogage >quit" | nc -v 127.0.0.1 4711'
# printf "%s\n" "${lines[@]}"
# [[ ${lines[1]} == "86400" ]]
# [[ ${lines[2]} == "" ]]
#}
#
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed old cruft

run bash -c 'grep -c "DEBUG_CONFIG: pihole.toml unchanged" /var/log/pihole/FTL.log'
printf "%s\n" "${lines[@]}"
[[ ${lines[0]} == "3" ]]
[[ ${lines[0]} == "4" ]]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As test/pihole.toml is now in the expected format, there is no initial reformatting and the file stays unchanged one time more

Signed-off-by: DL6ER <dl6er@dl6er.de>
@rdwebdesign
Copy link
Member

Should we add this option on the web interface, Settings > DHCP page?

Something like this?

Or this should be only in "All settings" page?

@DL6ER
Copy link
Member Author

DL6ER commented May 31, 2024

@rdwebdesign In the end, yes. But it'll be a separate PR and I haven't had the chance to do it myself, so far. Please go ahead :-)

@DL6ER DL6ER merged commit f4b9ca2 into development-v6 Jun 1, 2024
17 checks passed
@DL6ER DL6ER deleted the new/dhcp_ignoreUnknownClients branch June 1, 2024 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants