|
37 | 37 | find "$GEOBLOCK_DIR" -type f -regex \ |
38 | 38 | "*.dat" -delete |
39 | 39 | rm -f "$GEOBLOCK_DIR"/IPInfo-Country.mmdb |
| 40 | + # Remove old csv files |
| 41 | + rm -f "$SCRIPTS/iso3166.csv" |
| 42 | + rm -f "$SCRIPTS/country-codes.csv" |
40 | 43 | # Remove Apache2 mod |
41 | 44 | if [ -f "$GEOBLOCK_MOD" ] |
42 | 45 | then |
@@ -121,25 +124,25 @@ then |
121 | 124 | msg_box "Failed to compile MaxMindDB module. Please report this to $ISSUES" |
122 | 125 | exit 1 |
123 | 126 | fi |
124 | | - |
| 127 | + |
125 | 128 | # Delete conf made by module |
126 | 129 | rm -f /etc/apache2/mods-enabled/maxminddb.conf |
127 | | - |
| 130 | + |
128 | 131 | # Check if module is enabled |
129 | 132 | if ! apachectl -M | grep -i "maxminddb" |
130 | 133 | then |
131 | 134 | msg_box "Couldn't load the Apache module for MaxMind after installation. Please report this to $ISSUES" |
132 | 135 | exit 1 |
133 | 136 | fi |
134 | | - |
| 137 | + |
135 | 138 | print_text_in_color "$IGreen" "MaxMindDB module loaded in Apache successfully!" |
136 | | - |
| 139 | + |
137 | 140 | # Cleanup |
138 | 141 | cd /tmp |
139 | 142 | rm -rf mod_maxminddb-1.2.0 mod_maxminddb-1.2.0.tar.gz |
140 | 143 | else |
141 | 144 | msg_box "Failed to configure MaxMindDB module compilation. |
142 | | - |
| 145 | +
|
143 | 146 | This usually means apxs/apxs2 is not properly installed. |
144 | 147 | Please report this issue to: $ISSUES" |
145 | 148 | exit 1 |
|
166 | 169 | if [[ "$choice" = *"Countries"* ]] |
167 | 170 | then |
168 | 171 | # Download csv file |
169 | | - if ! curl_to_dir "https://dev.maxmind.com/static/csv/codes" "iso3166.csv" "$SCRIPTS" |
| 172 | + if ! curl_to_dir "https://raw.githubusercontent.com/datasets/country-codes/main/data" "country-codes.csv" "$SCRIPTS" |
170 | 173 | then |
171 | | - msg_box "Could not download the iso3166.csv file. |
| 174 | + msg_box "Could not download the country-codes.csv file. |
172 | 175 | Please report this to $ISSUES" |
173 | 176 | exit 1 |
174 | 177 | fi |
175 | 178 |
|
| 179 | + # Extract country codes (column 10: ISO3166-1-Alpha-2) and |
| 180 | + # names (column 41: official_name_en) from the CSV to CODE,"Name" format. |
| 181 | + # Custom field parser handles quoted fields that contain commas. |
| 182 | + awk 'NR>1{n=split($0,c,"");q=0;f=1;v="";for(i=1;i<=n;i++){if(c[i]=="\"")q=!q;else if(c[i]==","&&!q){if(f==10)code=v;if(f==41)name=v;f++;v=""}else v=v c[i]}if(f==10)code=v;if(f==41)name=v;if(code!=""&&name!="")print code",\""name"\""}' "$SCRIPTS/country-codes.csv" | sort > "$SCRIPTS/country-codes.csv.tmp" |
| 183 | + mv "$SCRIPTS/country-codes.csv.tmp" "$SCRIPTS/country-codes.csv" |
| 184 | + |
176 | 185 | # Get country names |
177 | | - COUNTRY_NAMES=$(sed 's|.*,"||;s|"$||' "$SCRIPTS/iso3166.csv") |
| 186 | + COUNTRY_NAMES=$(sed 's|.*,"||;s|"$||' "$SCRIPTS/country-codes.csv") |
178 | 187 | mapfile -t COUNTRY_NAMES <<< "$COUNTRY_NAMES" |
179 | 188 |
|
180 | 189 | # Get country codes |
181 | | - COUNTRY_CODES=$(sed 's|,.*||' "$SCRIPTS/iso3166.csv") |
| 190 | + COUNTRY_CODES=$(sed 's|,.*||' "$SCRIPTS/country-codes.csv") |
182 | 191 | mapfile -t COUNTRY_CODES <<< "$COUNTRY_CODES" |
183 | 192 |
|
184 | 193 | # Remove the csv file since no longer needed |
185 | | - check_command rm "$SCRIPTS/iso3166.csv" |
| 194 | + check_command rm "$SCRIPTS/country-codes.csv" |
186 | 195 |
|
187 | 196 | # Check if both arrays match |
188 | 197 | if [ "${#COUNTRY_NAMES[@]}" != "${#COUNTRY_CODES[@]}" ] |
|
0 commit comments