wip - v1 => It's working !! #1
@ -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"
|
||||
COUNTRIES=${BLOCK_COUNTRIES:-""}
|
||||
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
|
||||
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
|
||||
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" '
|
||||
BEGIN { inside=0 }
|
||||
/^ disallowed_clients:/ { print; inside=1; next }
|
||||
/^ [^ ]/ && inside==1 { print ips; inside=0 }
|
||||
{ if (!inside) print }
|
||||
END { if (inside==1) print ips }
|
||||
awk '
|
||||
BEGIN {
|
||||
# Read formatted IPs into array
|
||||
while ((getline line < "/tmp/cidr/ips_formatted.txt") > 0) {
|
||||
ips[++count] = line
|
||||
}
|
||||
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"
|
||||
|
||||
mv "$TMP_YAML" "$ADGUARD_YAML"
|
||||
|
||||
echo "Restarting adguard..."
|
||||
curl -s -X POST "$DOCKER_API_URL/containers/$ADGUARD_CONTAINER_NAME/restart" -o /dev/null
|
||||
echo "Restarting $CONTAINER_NAME container..."
|
||||
curl -s -X POST "$DOCKER_API_URL/containers/$CONTAINER_NAME/restart" -o /dev/null
|
||||
|
||||
echo "Done."
|
||||
|
Loading…
x
Reference in New Issue
Block a user