Skip to content

Commit 539bafb

Browse files
committed
Add code to detect duplicate country codes in refill-sets.conf
The new code detects blank and duplicate country codes in define-ipv4 and define-ipv6 lines in the configuration file. README.md: Correct URL link to feature article at LinuxSecurity.com.
1 parent 2852d10 commit 539bafb

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ awk, curl, grep, gunzip, sed, sort, stat
4444
Please see our [Discussions Page](https://github.com/wirefalls/geo-nft/discussions) to ask for help, share ideas, or for questions about the project.
4545

4646
#### Around the Web
47-
Feature Article - LinuxSecurity.com - [Geolocation for nftables Brings Simplicity & Flexibility to Geolocation Matching](https://linuxsecurity.com/features/features/geolocation-for-nftables)
47+
Feature Article - LinuxSecurity.com - [Geolocation for nftables Brings Simplicity & Flexibility to Geolocation Matching](https://linuxsecurity.com/features/geolocation-for-nftables)
4848

4949
Slashdot.org - [Should You Block Connections to Your Network From Foreign Countries?](https://news.slashdot.org/story/21/02/13/2231248/should-you-block-connections-to-your-network-from-foreign-countries)
5050

geo-nft.sh

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# Standard script variables.
2525

2626
# Semantic version number of this script.
27-
geo_nft_ver=v2.2.8
27+
geo_nft_ver=v2.2.9
2828

2929
# Filename of this script.
3030
script_name="geo-nft.sh"
@@ -553,6 +553,23 @@ check_refill_config() {
553553
# Capitalize the country code.
554554
cc="$(awk '{print toupper($0)}' <<<"$cc")"
555555

556+
# Test if the country code is blank.
557+
if [ -z "$cc" ]; then
558+
error_log "There's a blank country code in your 'define-ipv4' line in $refill_conf." \
559+
"Remove the blank country code from the line shown below. The blank entry will be skipped." \
560+
"Bad line: $line"
561+
continue
562+
fi
563+
564+
# Test if the country code is already in the array (country code repeated in refill-sets.conf list).
565+
if [[ "${cc4_array[*]}" =~ (^|[^[:alpha:]])$cc([^[:alpha:]]|$) ]]; then
566+
#if [[ -v $cc4_array[$cc] ]]; then
567+
error_log "Country code '$cc' is duplicated in your 'define-ipv4' line in $refill_conf." \
568+
"Remove any duplicates from the line shown below. The duplicate entry will be skipped." \
569+
"Bad line: $line"
570+
continue
571+
fi
572+
556573
# Verify that the country code definition file exists in the countrysets directory.
557574
if [ -s "$cc_dir/$cc.ipv4" ]; then
558575
cc4_array+=("\$$cc.ipv4")
@@ -562,6 +579,7 @@ check_refill_config() {
562579
"The missing country code was not added to the set." \
563580
"Line: $line"
564581
cc_line="yes"
582+
continue
565583
fi
566584
done <<<"$country_codes"
567585

@@ -644,6 +662,22 @@ check_refill_config() {
644662
# Capitalize the country code.
645663
cc="$(awk '{print toupper($0)}' <<<"$cc")"
646664

665+
# Test if the country code is blank.
666+
if [ -z "$cc" ]; then
667+
error_log "There's a blank country code in your 'define-ipv6' line in $refill_conf." \
668+
"Remove the blank country code from the line shown below. The blank entry will be skipped." \
669+
"Bad line: $line"
670+
continue
671+
fi
672+
673+
# Test if the country code is already in the array (country code repeated in refill-sets.conf list).
674+
if [[ "${cc6_array[*]}" =~ (^|[^[:alpha:]])$cc([^[:alpha:]]|$) ]]; then
675+
error_log "Country code $cc is duplicated in your 'define-ipv6' line in $refill_conf." \
676+
"Remove any duplicates from the line shown below. The duplicate entry will be skipped." \
677+
"Bad line: $line"
678+
continue
679+
fi
680+
647681
# Verify that the country code definition file exists in the countrysets directory.
648682
if [ -s "$cc_dir/$cc.ipv6" ]; then
649683
cc6_array+=("\$$cc.ipv6")
@@ -653,6 +687,7 @@ check_refill_config() {
653687
"The missing country code was not added to the set." \
654688
"Line: $line"
655689
cc_line="yes"
690+
continue
656691
fi
657692
done <<<"$country_codes"
658693

0 commit comments

Comments
 (0)