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

Disable dhcp if DHCP_ACTIVE is set to false #1452

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/s6/debian-root/usr/local/bin/_startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ setup_blocklists
# FTL setup
# ===========================
setup_FTL_upstream_DNS
[[ -n "${DHCP_ACTIVE}" && ${DHCP_ACTIVE} == "true" ]] && echo "Setting DHCP server" && setup_FTL_dhcp
setup_FTL_dhcp
apply_FTL_Configs_From_Env
setup_FTL_User
setup_FTL_Interface
Expand Down
28 changes: 17 additions & 11 deletions src/s6/debian-root/usr/local/bin/bash_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,24 @@ apply_FTL_Configs_From_Env(){
}

setup_FTL_dhcp() {
if [ -z "${DHCP_START}" ] || [ -z "${DHCP_END}" ] || [ -z "${DHCP_ROUTER}" ]; then
echo " [!] ERROR: Won't enable DHCP server because mandatory Environment variables are missing: DHCP_START, DHCP_END and/or DHCP_ROUTER"
change_setting "DHCP_ACTIVE" "false"
if [[ -n "${DHCP_ACTIVE}" && ${DHCP_ACTIVE} == "true" ]]; then
if [ -z "${DHCP_START}" ] || [ -z "${DHCP_END}" ] || [ -z "${DHCP_ROUTER}" ]; then
echo " [!] ERROR: Won't enable DHCP server because mandatory Environment variables are missing: DHCP_START, DHCP_END and/or DHCP_ROUTER"
change_setting "DHCP_ACTIVE" "false"
else
echo " [i] Enabling DHCP server"
change_setting "DHCP_ACTIVE" "${DHCP_ACTIVE}"
change_setting "DHCP_START" "${DHCP_START}"
change_setting "DHCP_END" "${DHCP_END}"
change_setting "DHCP_ROUTER" "${DHCP_ROUTER}"
change_setting "DHCP_LEASETIME" "${DHCP_LEASETIME}"
change_setting "PIHOLE_DOMAIN" "${PIHOLE_DOMAIN}"
change_setting "DHCP_IPv6" "${DHCP_IPv6}"
change_setting "DHCP_rapid_commit" "${DHCP_rapid_commit}"
fi
else
change_setting "DHCP_ACTIVE" "${DHCP_ACTIVE}"
change_setting "DHCP_START" "${DHCP_START}"
change_setting "DHCP_END" "${DHCP_END}"
change_setting "DHCP_ROUTER" "${DHCP_ROUTER}"
change_setting "DHCP_LEASETIME" "${DHCP_LEASETIME}"
change_setting "PIHOLE_DOMAIN" "${PIHOLE_DOMAIN}"
change_setting "DHCP_IPv6" "${DHCP_IPv6}"
change_setting "DHCP_rapid_commit" "${DHCP_rapid_commit}"
echo " [i] Disabling DHCP server"
change_setting "DHCP_ACTIVE" "false"
fi
}

Expand Down
17 changes: 17 additions & 0 deletions test/tests/test_bash_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,20 @@ def test_setup_lighttpd_bind(
assert "server.bind" not in config.stdout
else:
assert f'server.bind = "{expected_bind}"' in config.stdout

@pytest.mark.parametrize(
"test_args,expected_stdout",
[
('-e "DHCP_ACTIVE=true"', "ERROR: Won't enable DHCP"),
('-e "DHCP_ACTIVE=false"', "Disabling DHCP server"),
(
'-e "DHCP_ACTIVE=true" -e "DHCP_START=192.168.1.2" -e "DHCP_END=192.168.1.99" -e "DHCP_ROUTER=192.168.1.1"',
"Enabling DHCP server",
),
],
)
def test_env_dhcp(docker, args_env, test_args, expected_stdout):
"""Ensure behaviour of DHCP_ACTIVE is correct"""
function = docker.run(". bash_functions.sh ; setup_FTL_dhcp")

assert expected_stdout in function.stdout