feat: WAN IP Guard - dynamic DNS updater with WhatsApp notifications
Checks public WAN IP every 5 minutes via systemd timer. On change: - Updates A-records via DirectAdmin API (login key auth) - Sends WhatsApp notification via wwebjs-api
This commit is contained in:
commit
c4c80e98af
9 changed files with 461 additions and 0 deletions
114
README.md
Normal file
114
README.md
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
# WAN IP Guard
|
||||
|
||||
Bewaakt het publieke WAN IP en update automatisch DNS records bij wijziging, plus WhatsApp notificatie.
|
||||
|
||||
## Wat doet het?
|
||||
|
||||
- Controleert elke 5 minuten het publieke WAN IP
|
||||
- Bij wijziging:
|
||||
- Updatet A-records via de DirectAdmin API
|
||||
- Stuurt een WhatsApp notificatie naar de admin
|
||||
- Draait als systemd timer
|
||||
|
||||
## Installatie
|
||||
|
||||
### 1. Clone op je server
|
||||
|
||||
```bash
|
||||
cd ~
|
||||
git clone <jouw-repo-url> wan-ip-guard
|
||||
cd wan-ip-guard
|
||||
```
|
||||
|
||||
### 2. Configureer
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
# Edit .env met je credentials
|
||||
nano .env
|
||||
```
|
||||
|
||||
### 3. Installeer dependencies
|
||||
|
||||
```bash
|
||||
npm install --omit=dev
|
||||
```
|
||||
|
||||
### 4. Systemd setup
|
||||
|
||||
```bash
|
||||
# State directory
|
||||
sudo mkdir -p /var/lib/wan-ip-guard
|
||||
sudo chown $USER:$USER /var/lib/wan-ip-guard
|
||||
|
||||
# Pas de paden in systemd/*.service aan naar jouw setup
|
||||
# (gebruiker, WorkingDirectory, ExecStart, EnvironmentFile)
|
||||
|
||||
# Systemd units
|
||||
sudo cp systemd/wan-ip-guard.service /etc/systemd/system/
|
||||
sudo cp systemd/wan-ip-guard.timer /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now wan-ip-guard.timer
|
||||
```
|
||||
|
||||
## Configuratie (.env)
|
||||
|
||||
| Variabele | Beschrijving | Voorbeeld |
|
||||
|-----------|-------------|-----------|
|
||||
| `DA_LOGIN_KEY` | DirectAdmin Login Key | `your_login_key` |
|
||||
| `DA_USERNAME` | DirectAdmin gebruiker | `your_username` |
|
||||
| `DA_BASE_URL` | DirectAdmin base URL | `https://panel.example.com:2222` |
|
||||
| `DA_DOMAIN` | Domeinnaam | `example.com` |
|
||||
| `WHATSAPP_API_ENDPOINT` | wwebjs-api URL | `http://localhost:3001` |
|
||||
| `WHATSAPP_SESSION` | WhatsApp sessie naam | `your_session` |
|
||||
| `ADMIN_PHONE` | Admin telefoonnummer | `31600000000` |
|
||||
| `DNS_RECORDS` | Komma-gescheiden records | `example.com,git,www` |
|
||||
| `STATE_FILE` | Pad naar state file | `/var/lib/wan-ip-guard/current_ip` |
|
||||
|
||||
## DirectAdmin Login Key aanmaken
|
||||
|
||||
1. Log in op het DirectAdmin panel
|
||||
2. Ga naar **Accountbeheer** → **Login Keys**
|
||||
3. Maak een nieuwe key aan met rechten voor **DNS Control**
|
||||
4. Sla de key op (het wordt maar één keer getoond)
|
||||
|
||||
## Beheer
|
||||
|
||||
```bash
|
||||
# Timer status
|
||||
systemctl status wan-ip-guard.timer
|
||||
|
||||
# Logs volgen
|
||||
journalctl -u wan-ip-guard -f
|
||||
|
||||
# Handmatig draaien
|
||||
cd ~/wan-ip-guard && node index.js
|
||||
|
||||
# Timer herstarten
|
||||
sudo systemctl restart wan-ip-guard.timer
|
||||
|
||||
# State bestand resetten (forceer update bij volgende run)
|
||||
rm /var/lib/wan-ip-guard/current_ip
|
||||
```
|
||||
|
||||
## Hoe het werkt
|
||||
|
||||
1. **IP detectie:** Haalt het WAN IP op via `ifconfig.me` met fallback naar `api.ipify.org` en `icanhazip.com`
|
||||
2. **State vergelijking:** Vergelijkt met het laatst opgeslagen IP in de state file
|
||||
3. **DNS update:** Voor elke record: verwijder oud A-record + voeg nieuw A-record toe via DirectAdmin API
|
||||
4. **Notificatie:** Stuurt WhatsApp bericht met oud/nieuw IP en status per record
|
||||
|
||||
## Files
|
||||
|
||||
```
|
||||
wan-ip-guard/
|
||||
├── index.js # Hoofdscript
|
||||
├── package.json
|
||||
├── .env.example # Config template
|
||||
├── deploy.sh # Deployment script
|
||||
├── systemd/
|
||||
│ ├── wan-ip-guard.service
|
||||
│ └── wan-ip-guard.timer
|
||||
└── docs/
|
||||
└── design-spec.md
|
||||
```
|
||||
Loading…
Reference in a new issue