Merge pull request 'wip - v1 => It's working !!' (#1) from wip into main
Reviewed-on: #1
This commit is contained in:
commit
e1b43dc895
@ -1,6 +1,6 @@
|
|||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
RUN apk add --no-cache curl bash busybox-cron
|
RUN apk add --no-cache curl bash busybox tzdata
|
||||||
|
|
||||||
COPY update-blocklist.sh /usr/local/bin/update-blocklist.sh
|
COPY update-blocklist.sh /usr/local/bin/update-blocklist.sh
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
21
README.md
21
README.md
@ -2,19 +2,21 @@
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
<a href="https://discord.gg/gxffg3GA96">
|
<a href="https://discord.gg/gxffg3GA96">
|
||||||
<img src="https://img.shields.io/badge/JV%20hardware-rejoindre-green?style=flat-square&logo=discord&logoColor=%23fff" alt="JV Hardware">
|
<img src="https://img.shields.io/badge/JV%20hardware-rejoindre-green?style=flat-square&logo=discord&logoColor=%23fff" alt="JV Hardware">
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
🤖 **Adguard CIDRE Sync** - A bot to synchronize adguard clients disallow list with countries CIDR list of your choices.
|
**Adguard CIDRE Sync** - A bot to synchronize adguard clients disallow list with countries CIDR list of your choices.
|
||||||
|
|
||||||
*The code is partially generated by AI*
|
*The code is partially generated by AI*
|
||||||
|
|
||||||
## 📌 Sommaire
|
## Sommaire
|
||||||
|
|
||||||
- [Features](#features)
|
- [Features](#features)
|
||||||
- [Install with Docker and our image](#install-with-docker)
|
- [Environment Variables](#environment-variables)
|
||||||
- [Install with git and build (développeur)](#install-with-git-and-build)
|
- [File Structure](#file-structure)
|
||||||
|
- [Installation and Usage](#nstallation-and-usage)
|
||||||
|
|
||||||
## ✨ Features
|
## Features
|
||||||
|
|
||||||
- Automatically downloads IP CIDR blocks for specified countries to block.
|
- Automatically downloads IP CIDR blocks for specified countries to block.
|
||||||
- Supports additional manually blocked IPs from a configurable file.
|
- Supports additional manually blocked IPs from a configurable file.
|
||||||
@ -26,9 +28,12 @@
|
|||||||
|
|
||||||
| Variable | Description | Default |
|
| Variable | Description | Default |
|
||||||
| ------------------- | ---------------------------------------------------------- | --------------------------------- |
|
| ------------------- | ---------------------------------------------------------- | --------------------------------- |
|
||||||
|
| `TZ` | Your Time Zone | (required) |
|
||||||
| `BLOCK_COUNTRIES` | Comma-separated country codes to block (e.g., `CN,RU,IR`) | (required) |
|
| `BLOCK_COUNTRIES` | Comma-separated country codes to block (e.g., `CN,RU,IR`) | (required) |
|
||||||
| `BLOCKLIST_CRON` | Cron expression for update frequency (e.g., `0 6 * * *`) | `0 6 * * *` (at 6:00 everydays) |
|
| `BLOCKLIST_CRON` | Cron expression for update frequency (e.g., `0 6 * * *`) | `0 6 * * *` (at 6:00 everydays) |
|
||||||
| `DOCKER_API_URL` | URL of Docker socket proxy to restart AdGuard container | `http://docker-socket-proxy:2375` |
|
| `DOCKER_API_URL` | URL of Docker socket proxy to restart AdGuard container | `http://socket-proxy-adguard:2375` |
|
||||||
|
| `ADGUARD_CONTAINER_NAME` | Name of your adguard container | `adguardhome` |
|
||||||
|
|
||||||
|
|
||||||
## File Structure
|
## File Structure
|
||||||
|
|
||||||
@ -43,8 +48,8 @@
|
|||||||
1. **Clone the repository:**
|
1. **Clone the repository:**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/your-username/adguard-blocklist-updater.git
|
git clone https://git.djeex.fr/Djeex/adguard-cidre
|
||||||
cd adguard-blocklist-updater
|
cd adguard-cidre
|
||||||
```
|
```
|
||||||
2. **Modify docker-compose.yml**
|
2. **Modify docker-compose.yml**
|
||||||
|
|
||||||
|
@ -2,10 +2,13 @@
|
|||||||
services:
|
services:
|
||||||
adguard-cidre:
|
adguard-cidre:
|
||||||
build: .
|
build: .
|
||||||
|
container_name: adguard-cidre
|
||||||
environment:
|
environment:
|
||||||
- BLOCK_COUNTRIES=CN,RU,IR # choose countries listed IP to block. Full lists here https://github.com/vulnebify/cidre/tree/main/output/cidr/ipv4
|
- TZ=Europe/Paris # change to your timezone
|
||||||
|
- BLOCK_COUNTRIES=cn,ru,ir # choose countries listed IP to block. Full lists here https://github.com/vulnebify/cidre/tree/main/output/cidr/ipv4
|
||||||
- BLOCKLIST_CRON=0 6 * * * # at 6:00 every days
|
- BLOCKLIST_CRON=0 6 * * * # at 6:00 every days
|
||||||
- DOCKER_API_URL=http://socket-proxy-adguard:2375
|
- DOCKER_API_URL=http://socket-proxy-adguard:2375 # docker socket proxy
|
||||||
|
- ADGUARD_CONTAINER_NAME=adguardhome # adguard container name
|
||||||
volumes:
|
volumes:
|
||||||
- /path/to/adguard/confdir:/adguard
|
- /path/to/adguard/confdir:/adguard
|
||||||
|
|
||||||
@ -16,6 +19,7 @@ services:
|
|||||||
- no-new-privileges:true
|
- no-new-privileges:true
|
||||||
environment:
|
environment:
|
||||||
- CONTAINERS=1
|
- CONTAINERS=1
|
||||||
|
- ALLOW_RESTARTS=1
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
CRON_EXPR="${BLOCKLIST_CRON:-"0 6 * * *"}" # default: every hour
|
if [ -n "$TZ" ]; then
|
||||||
SCRIPT_PATH="/usr/local/bin/update-blocklist.sh"
|
if [ -f "/usr/share/zoneinfo/$TZ" ]; then
|
||||||
|
cp "/usr/share/zoneinfo/$TZ" /etc/localtime
|
||||||
|
echo "$TZ" > /etc/timezone
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Installing cron job with expression: $CRON_EXPR"
|
CRON_EXPR="${BLOCKLIST_CRON:-"0 6 * * *"}"
|
||||||
|
echo "$CRON_EXPR /usr/local/bin/update-blocklist.sh" > /etc/crontabs/root
|
||||||
|
|
||||||
echo "$CRON_EXPR root $SCRIPT_PATH" > /etc/crontabs/root
|
exec crond -f -c /etc/crontabs
|
||||||
|
|
||||||
echo "Starting cron..."
|
|
||||||
crond -f -L /dev/stdout
|
|
@ -7,7 +7,8 @@ TMP_YAML="/tmp/AdGuardHome.yaml"
|
|||||||
MANUAL_IPS_FILE="/adguard/manually_blocked_ips.conf"
|
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://docker-socket-proxy:2375"}
|
DOCKER_API_URL=${DOCKER_API_URL:-"http://socket-proxy-adguard:2375"}
|
||||||
|
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."
|
||||||
@ -20,8 +21,8 @@ mkdir -p /tmp/cidr
|
|||||||
IFS=',' read -ra CODES <<< "$COUNTRIES"
|
IFS=',' read -ra CODES <<< "$COUNTRIES"
|
||||||
for CODE in "${CODES[@]}"; do
|
for CODE in "${CODES[@]}"; do
|
||||||
echo "Downloading CIDR list for $CODE..."
|
echo "Downloading CIDR list for $CODE..."
|
||||||
curl -sf "$CIDR_BASE_URL/${CODE^^}.txt" -o "/tmp/cidr/${CODE}.txt" || continue
|
curl -sf "$CIDR_BASE_URL/${CODE,,}.cidr" -o "/tmp/cidr/${CODE}.cidr" || continue
|
||||||
cat "/tmp/cidr/${CODE}.txt" >> /tmp/cidr/all.txt
|
cat "/tmp/cidr/${CODE}.cidr" >> /tmp/cidr/all.txt
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -f "$MANUAL_IPS_FILE" ]; then
|
if [ -f "$MANUAL_IPS_FILE" ]; then
|
||||||
@ -29,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-home container..."
|
echo "Restarting $CONTAINER_NAME container..."
|
||||||
curl -s -X POST "$DOCKER_API_URL/containers/adguard-home/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