fixed list issues with awk (too many arguments -> temp file)
This commit is contained in:
parent
02d891b6db
commit
0da63e9cc0
@ -8,7 +8,7 @@ MANUAL_IPS_FILE="/adguard/manually_blocked_ips.conf"
|
|||||||
CIDR_BASE_URL="https://raw.githubusercontent.com/vulnebify/cidre/main/output/cidr/ipv4"
|
CIDR_BASE_URL="https://raw.githubusercontent.com/vulnebify/cidre/main/output/cidr/ipv4"
|
||||||
COUNTRIES=${BLOCK_COUNTRIES:-""}
|
COUNTRIES=${BLOCK_COUNTRIES:-""}
|
||||||
DOCKER_API_URL=${DOCKER_API_URL:-"http://socket-proxy-adguard:2375"}
|
DOCKER_API_URL=${DOCKER_API_URL:-"http://socket-proxy-adguard:2375"}
|
||||||
ADGUARD_CONTAINER_NAME=${ADGUARD_CONTAINER_NAME:-"adguardhome"}
|
CONTAINER_NAME=${ADGUARD_CONTAINER_NAME:-"adguard-home"}
|
||||||
|
|
||||||
if [ -z "$COUNTRIES" ]; then
|
if [ -z "$COUNTRIES" ]; then
|
||||||
echo "No countries specified in BLOCK_COUNTRIES."
|
echo "No countries specified in BLOCK_COUNTRIES."
|
||||||
@ -30,19 +30,46 @@ if [ -f "$MANUAL_IPS_FILE" ]; then
|
|||||||
grep -E '^([0-9]{1,3}\.){3}[0-9]{1,3}(/[0-9]{1,2})?$' "$MANUAL_IPS_FILE" >> /tmp/cidr/all.txt
|
grep -E '^([0-9]{1,3}\.){3}[0-9]{1,3}(/[0-9]{1,2})?$' "$MANUAL_IPS_FILE" >> /tmp/cidr/all.txt
|
||||||
fi
|
fi
|
||||||
|
|
||||||
IPS_FORMATTED=$(sed 's/^/ - /' /tmp/cidr/all.txt)
|
# Format IPs as YAML list items
|
||||||
|
sed 's/^/ - /' /tmp/cidr/all.txt > /tmp/cidr/ips_formatted.txt
|
||||||
|
|
||||||
awk -v ips="$IPS_FORMATTED" '
|
awk '
|
||||||
BEGIN { inside=0 }
|
BEGIN {
|
||||||
/^ disallowed_clients:/ { print; inside=1; next }
|
# Read formatted IPs into array
|
||||||
/^ [^ ]/ && inside==1 { print ips; inside=0 }
|
while ((getline line < "/tmp/cidr/ips_formatted.txt") > 0) {
|
||||||
{ if (!inside) print }
|
ips[++count] = line
|
||||||
END { if (inside==1) print ips }
|
}
|
||||||
|
close("/tmp/cidr/ips_formatted.txt")
|
||||||
|
inside=0
|
||||||
|
}
|
||||||
|
|
||||||
|
/^ disallowed_clients:/ {
|
||||||
|
print
|
||||||
|
inside=1
|
||||||
|
next
|
||||||
|
}
|
||||||
|
|
||||||
|
/^ [^ ]/ && inside==1 {
|
||||||
|
# Insert all IPs here
|
||||||
|
for (i=1; i<=count; i++) print ips[i]
|
||||||
|
inside=0
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
if (!inside) print
|
||||||
|
}
|
||||||
|
|
||||||
|
END {
|
||||||
|
# If file ended while still inside disallowed_clients section
|
||||||
|
if (inside==1) {
|
||||||
|
for (i=1; i<=count; i++) print ips[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
' "$ADGUARD_YAML" > "$TMP_YAML"
|
' "$ADGUARD_YAML" > "$TMP_YAML"
|
||||||
|
|
||||||
mv "$TMP_YAML" "$ADGUARD_YAML"
|
mv "$TMP_YAML" "$ADGUARD_YAML"
|
||||||
|
|
||||||
echo "Restarting adguard..."
|
echo "Restarting $CONTAINER_NAME container..."
|
||||||
curl -s -X POST "$DOCKER_API_URL/containers/$ADGUARD_CONTAINER_NAME/restart" -o /dev/null
|
curl -s -X POST "$DOCKER_API_URL/containers/$CONTAINER_NAME/restart" -o /dev/null
|
||||||
|
|
||||||
echo "Done."
|
echo "Done."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user