From 11679a5188c1e29fcaa13fa5c29204443349a794 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 28 May 2023 23:31:51 +0100 Subject: [PATCH 1/3] @MrDuck2742 dropped a `]` on the floor without me seeing. I picked it up and put it back again Signed-off-by: Adam Warner --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 7680590f..c92d0458 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -664,7 +664,7 @@ checkDomain() local domain validDomain # Convert to lowercase domain="${1,,}" - validDomain=$(grep -P "^((-|_)*[a-z0-9]((-|_)*[a-z0-9)*(-|_)*)(\\.(-|_)*([a-z0-9]((-|_)*[a-z0-9])*))*$" <<< "${domain}") # Valid chars check + validDomain=$(grep -P "^((-|_)*[a-z0-9]((-|_)*[a-z0-9])*(-|_)*)(\\.(-|_)*([a-z0-9]((-|_)*[a-z0-9])*))*$" <<< "${domain}") # Valid chars check validDomain=$(grep -P "^[^\\.]{1,63}(\\.[^\\.]{1,63})*$" <<< "${validDomain}") # Length of each label echo "${validDomain}" } From 494734bf27f836d2e5f17df1567d79fc37ad9de0 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 28 May 2023 23:40:47 +0100 Subject: [PATCH 2/3] Add in a test case Signed-off-by: Adam Warner --- test/test_any_automated_install.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index c1288287..36a4f0d2 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -1151,3 +1151,30 @@ def test_package_manager_has_web_deps(host): assert "No package" not in output.stdout assert output.rc == 0 + + +def test_webpage_sh_valid_domain(host): + """Confirms checkDomain function in webpage.sh works as expected""" + check1 = host.run( + """ + source /opt/pihole/webpage.sh + checkDomain "pi-hole.net" + """ + ) + check2 = host.run( + """ + source /opt/pihole/webpage.sh + checkDomain "ab.pi-hole.net" + """ + ) + + check3 = host.run( + """ + source /opt/pihole/webpage.sh + checkDomain "abc.pi-hole.net" + """ + ) + + assert "pi-hole.net" in check1.stdout + assert "ab.pi-hole.net" in check2.stdout + assert "abc.pi-hole.net" in check3.stdout From 6c302c9bc811a944cc721f640e3f5429db25869e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 30 May 2023 17:01:58 +0200 Subject: [PATCH 3/3] Adlist properties need to be stored in the new ("temp") database rather than the old. Signed-off-by: DL6ER --- gravity.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gravity.sh b/gravity.sh index fe2097dd..2bd21d01 100755 --- a/gravity.sh +++ b/gravity.sh @@ -229,7 +229,7 @@ database_table_from_file() { # Check if a column with name ${2} exists in gravity table with name ${1} gravity_column_exists() { - output=$( { printf ".timeout 30000\\nSELECT EXISTS(SELECT * FROM pragma_table_info('%s') WHERE name='%s');\\n" "${1}" "${2}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\nSELECT EXISTS(SELECT * FROM pragma_table_info('%s') WHERE name='%s');\\n" "${1}" "${2}" | pihole-FTL sqlite3 "${gravityTEMPfile}"; } 2>&1 ) if [[ "${output}" == "1" ]]; then return 0 # Bash 0 is success fi @@ -244,11 +244,11 @@ database_adlist_number() { return; fi - output=$( { printf ".timeout 30000\\nUPDATE adlist SET number = %i, invalid_domains = %i WHERE id = %i;\\n" "${2}" "${3}" "${1}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\nUPDATE adlist SET number = %i, invalid_domains = %i WHERE id = %i;\\n" "${2}" "${3}" "${1}" | pihole-FTL sqlite3 "${gravityTEMPfile}"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then - echo -e "\\n ${CROSS} Unable to update number of domains in adlist with ID ${1} in database ${gravityDBfile}\\n ${output}" + echo -e "\\n ${CROSS} Unable to update number of domains in adlist with ID ${1} in database ${gravityTEMPfile}\\n ${output}" gravity_Cleanup "error" fi } @@ -260,11 +260,11 @@ database_adlist_status() { return; fi - output=$( { printf ".timeout 30000\\nUPDATE adlist SET status = %i WHERE id = %i;\\n" "${2}" "${1}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\nUPDATE adlist SET status = %i WHERE id = %i;\\n" "${2}" "${1}" | pihole-FTL sqlite3 "${gravityTEMPfile}"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then - echo -e "\\n ${CROSS} Unable to update status of adlist with ID ${1} in database ${gravityDBfile}\\n ${output}" + echo -e "\\n ${CROSS} Unable to update status of adlist with ID ${1} in database ${gravityTEMPfile}\\n ${output}" gravity_Cleanup "error" fi }