Monitors WAN IP changes and updates DNS records + sends WhatsApp notification
  • JavaScript 77.3%
  • Shell 22.7%
Find a file
2026-06-22 07:37:35 +02:00
systemd feat: WAN IP Guard - dynamic DNS updater with WhatsApp notifications 2026-06-21 09:53:28 +02:00
.env.example feat: WAN IP Guard - dynamic DNS updater with WhatsApp notifications 2026-06-21 09:53:28 +02:00
.gitignore feat: WAN IP Guard - dynamic DNS updater with WhatsApp notifications 2026-06-21 09:53:28 +02:00
deploy.sh feat: WAN IP Guard - dynamic DNS updater with WhatsApp notifications 2026-06-21 09:53:28 +02:00
index.js fix: only save state after successful DNS update 2026-06-22 07:36:26 +02:00
package-lock.json feat: WAN IP Guard - dynamic DNS updater with WhatsApp notifications 2026-06-21 09:53:28 +02:00
package.json feat: WAN IP Guard - dynamic DNS updater with WhatsApp notifications 2026-06-21 09:53:28 +02:00
README.md docs: update README with retry-on-failure behavior and remove stale docs ref 2026-06-22 07:37:35 +02:00

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

cd ~
git clone <jouw-repo-url> wan-ip-guard
cd wan-ip-guard

2. Configureer

cp .env.example .env
# Edit .env met je credentials
nano .env

3. Installeer dependencies

npm install --omit=dev

4. Systemd setup

# 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 AccountbeheerLogin Keys
  3. Maak een nieuwe key aan met rechten voor DNS Control
  4. Sla de key op (het wordt maar één keer getoond)

Beheer

# 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. Per-record foutafhandeling — één falende record blokkeert de rest niet.
  4. State persist: Het nieuwe IP wordt pas opgeslagen als alle DNS-updates gelukt zijn. Bij gedeeltelijke mislukking retried de volgende timer-run.
  5. 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