fix: track all configured DNS records
This commit is contained in:
parent
17ae9b4796
commit
7142c4cef8
4 changed files with 40 additions and 10 deletions
|
|
@ -10,7 +10,7 @@ WHATSAPP_SESSION=your_session
|
||||||
ADMIN_PHONE=31600000000
|
ADMIN_PHONE=31600000000
|
||||||
|
|
||||||
# DNS records to update (comma-separated, use domain name for apex)
|
# DNS records to update (comma-separated, use domain name for apex)
|
||||||
DNS_RECORDS=example.com,git,www
|
DNS_RECORDS=example.com,git,www,weegschaal,whatsed,auth.whatsed
|
||||||
|
|
||||||
# State file path (where to store last known IP)
|
# State file path (where to store last known IP)
|
||||||
STATE_FILE=/var/lib/wan-ip-guard/current_ip
|
STATE_FILE=/var/lib/wan-ip-guard/current_ip
|
||||||
|
|
|
||||||
37
README.md
37
README.md
|
|
@ -23,9 +23,10 @@ cd wan-ip-guard
|
||||||
### 2. Configureer
|
### 2. Configureer
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cp .env.example .env
|
# .env naar /etc (nodig vanwege systemd beperkingen op nieuwere Fedora)
|
||||||
# Edit .env met je credentials
|
sudo mkdir -p /etc/wan-ip-guard
|
||||||
nano .env
|
sudo cp .env.example /etc/wan-ip-guard/.env
|
||||||
|
sudo nano /etc/wan-ip-guard/.env
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. Installeer dependencies
|
### 3. Installeer dependencies
|
||||||
|
|
@ -42,7 +43,7 @@ sudo mkdir -p /var/lib/wan-ip-guard
|
||||||
sudo chown $USER:$USER /var/lib/wan-ip-guard
|
sudo chown $USER:$USER /var/lib/wan-ip-guard
|
||||||
|
|
||||||
# Pas de paden in systemd/*.service aan naar jouw setup
|
# Pas de paden in systemd/*.service aan naar jouw setup
|
||||||
# (gebruiker, WorkingDirectory, ExecStart, EnvironmentFile)
|
# (gebruiker, WorkingDirectory, ExecStart)
|
||||||
|
|
||||||
# Systemd units
|
# Systemd units
|
||||||
sudo cp systemd/wan-ip-guard.service /etc/systemd/system/
|
sudo cp systemd/wan-ip-guard.service /etc/systemd/system/
|
||||||
|
|
@ -91,6 +92,20 @@ sudo systemctl restart wan-ip-guard.timer
|
||||||
rm /var/lib/wan-ip-guard/current_ip
|
rm /var/lib/wan-ip-guard/current_ip
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Probleemoplossing
|
||||||
|
|
||||||
|
### "Failed to load environment files: Permission denied"
|
||||||
|
|
||||||
|
Systemd (met name versie 259+ op Fedora 44) kan soms geen `EnvironmentFile` lezen vanuit een user home directory met beperkte rechten (`drwx------`).
|
||||||
|
|
||||||
|
**Symptoom:** Timer is actief, maar de service faalt elke run met:
|
||||||
|
```
|
||||||
|
wan-ip-guard.service: Failed to load environment files: Permission denied
|
||||||
|
wan-ip-guard.service: Failed to spawn 'start' task: Permission denied
|
||||||
|
```
|
||||||
|
|
||||||
|
**Oplossing:** Verplaats `.env` naar `/etc/wan-ip-guard/.env` (zoals de installatie instructies voorschrijven). Systemd kan bestanden in `/etc` altijd lezen ongeacht user-rechten.
|
||||||
|
|
||||||
## Hoe het werkt
|
## Hoe het werkt
|
||||||
|
|
||||||
1. **IP detectie:** Haalt het WAN IP op via `ifconfig.me` met fallback naar `api.ipify.org` en `icanhazip.com`
|
1. **IP detectie:** Haalt het WAN IP op via `ifconfig.me` met fallback naar `api.ipify.org` en `icanhazip.com`
|
||||||
|
|
@ -110,5 +125,19 @@ wan-ip-guard/
|
||||||
├── systemd/
|
├── systemd/
|
||||||
│ ├── wan-ip-guard.service
|
│ ├── wan-ip-guard.service
|
||||||
│ └── wan-ip-guard.timer
|
│ └── wan-ip-guard.timer
|
||||||
|
```
|
||||||
|
|
||||||
|
## Serverstructuur (nextcloud)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
/etc/wan-ip-guard/
|
||||||
|
├── .env # Config (door root beheerd)
|
||||||
|
|
||||||
|
/var/lib/wan-ip-guard/
|
||||||
|
├── current_ip # Huidig opgeslagen IP
|
||||||
|
|
||||||
|
/home/aiaiaiaiagent/wan-ip-guard/
|
||||||
|
├── index.js # Broncode
|
||||||
|
├── node_modules/
|
||||||
|
└── ...
|
||||||
|
```
|
||||||
|
|
|
||||||
9
index.js
9
index.js
|
|
@ -96,7 +96,8 @@ async function getDnsRecords() {
|
||||||
if (name === `${CONFIG.daDomain}.` || name === CONFIG.daDomain) {
|
if (name === `${CONFIG.daDomain}.` || name === CONFIG.daDomain) {
|
||||||
name = '';
|
name = '';
|
||||||
}
|
}
|
||||||
records[name] = match[2];
|
if (!records[name]) records[name] = [];
|
||||||
|
records[name].push(match[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return records;
|
return records;
|
||||||
|
|
@ -161,15 +162,15 @@ async function main() {
|
||||||
for (const record of CONFIG.dnsRecords) {
|
for (const record of CONFIG.dnsRecords) {
|
||||||
const name = record === CONFIG.daDomain ? '' : record;
|
const name = record === CONFIG.daDomain ? '' : record;
|
||||||
const label = name || '(apex)';
|
const label = name || '(apex)';
|
||||||
const oldIp = dnsRecords[name] || dnsRecords[record];
|
const oldIps = dnsRecords[name] || dnsRecords[record] || [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (oldIp) {
|
for (const oldIp of oldIps) {
|
||||||
await deleteDnsRecord(name, oldIp);
|
await deleteDnsRecord(name, oldIp);
|
||||||
}
|
}
|
||||||
await addDnsRecord(name, currentIp);
|
await addDnsRecord(name, currentIp);
|
||||||
results.push(`✅ ${label}`);
|
results.push(`✅ ${label}`);
|
||||||
log(`Updated ${label}: ${oldIp || '(none)'} -> ${currentIp}`);
|
log(`Updated ${label}: ${oldIps.join(', ') || '(none)'} -> ${currentIp}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
results.push(`❌ ${label}: ${e.message}`);
|
results.push(`❌ ${label}: ${e.message}`);
|
||||||
logError(`Failed to update ${label}: ${e.message}`);
|
logError(`Failed to update ${label}: ${e.message}`);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,6 @@ Wants=network-online.target
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
# Change 'your-user' and paths to match your setup
|
# Change 'your-user' and paths to match your setup
|
||||||
User=your-user
|
User=your-user
|
||||||
EnvironmentFile=/home/your-user/wan-ip-guard/.env
|
EnvironmentFile=/etc/wan-ip-guard/.env
|
||||||
WorkingDirectory=/home/your-user/wan-ip-guard
|
WorkingDirectory=/home/your-user/wan-ip-guard
|
||||||
ExecStart=/usr/bin/node /home/your-user/wan-ip-guard/index.js
|
ExecStart=/usr/bin/node /home/your-user/wan-ip-guard/index.js
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue