feat: mirror WAN reports to Matrix

This commit is contained in:
Eddy de Vink 2026-08-31 15:51:34 +02:00
commit dc57990bca
3 changed files with 39 additions and 1 deletions

View file

@ -9,6 +9,11 @@ WHATSAPP_API_ENDPOINT=http://localhost:3001
WHATSAPP_SESSION=your_session WHATSAPP_SESSION=your_session
ADMIN_PHONE=31600000000 ADMIN_PHONE=31600000000
# Matrix report delivery via sherpa
MATRIX_API_ENDPOINT=https://whatsed.eddydevink.nl
MATRIX_TOKEN_FILE=/home/aiaiaiaiagent/whatsed-new/secrets/sherpa-token
MATRIX_ROOM_FILE=/home/aiaiaiaiagent/whatsed-new/secrets/eddy-report-room
# 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,weegschaal,whatsed,auth.whatsed DNS_RECORDS=example.com,git,www,weegschaal,whatsed,auth.whatsed

View file

@ -63,9 +63,14 @@ sudo systemctl enable --now wan-ip-guard.timer
| `WHATSAPP_API_ENDPOINT` | wwebjs-api URL | `http://localhost:3001` | | `WHATSAPP_API_ENDPOINT` | wwebjs-api URL | `http://localhost:3001` |
| `WHATSAPP_SESSION` | WhatsApp sessie naam | `your_session` | | `WHATSAPP_SESSION` | WhatsApp sessie naam | `your_session` |
| `ADMIN_PHONE` | Admin telefoonnummer | `31600000000` | | `ADMIN_PHONE` | Admin telefoonnummer | `31600000000` |
| `MATRIX_API_ENDPOINT` | Matrix homeserver API | `https://whatsed.eddydevink.nl` |
| `MATRIX_TOKEN_FILE` | Bestand met Sherpa compat-token | `/home/aiaiaiaiagent/whatsed-new/secrets/sherpa-token` |
| `MATRIX_ROOM_FILE` | Bestand met DM-room voor Eddy | `/home/aiaiaiaiagent/whatsed-new/secrets/eddy-report-room` |
| `DNS_RECORDS` | Komma-gescheiden records | `example.com,git,www` | | `DNS_RECORDS` | Komma-gescheiden records | `example.com,git,www` |
| `STATE_FILE` | Pad naar state file | `/var/lib/wan-ip-guard/current_ip` | | `STATE_FILE` | Pad naar state file | `/var/lib/wan-ip-guard/current_ip` |
WAN IP Guard verstuurt het rapport naast WhatsApp ook via de Matrix-bot `@sherpa:whatsed.eddydevink.nl` naar de bestaande DM-room met `@eddy:whatsed.eddydevink.nl`. Het compat-token en room-ID staan uitsluitend in de aangegeven bestanden en worden niet in de repository opgeslagen.
## DirectAdmin Login Key aanmaken ## DirectAdmin Login Key aanmaken
1. Log in op het DirectAdmin panel 1. Log in op het DirectAdmin panel

View file

@ -15,6 +15,9 @@ const CONFIG = {
whatsappApi: process.env.WHATSAPP_API_ENDPOINT || 'http://localhost:3001', whatsappApi: process.env.WHATSAPP_API_ENDPOINT || 'http://localhost:3001',
whatsappSession: process.env.WHATSAPP_SESSION || 'EdGpt', whatsappSession: process.env.WHATSAPP_SESSION || 'EdGpt',
adminPhone: process.env.ADMIN_PHONE, adminPhone: process.env.ADMIN_PHONE,
matrixApi: process.env.MATRIX_API_ENDPOINT || 'https://whatsed.eddydevink.nl',
matrixTokenFile: process.env.MATRIX_TOKEN_FILE || '/home/aiaiaiaiagent/whatsed-new/secrets/sherpa-token',
matrixRoomFile: process.env.MATRIX_ROOM_FILE || '/home/aiaiaiaiagent/whatsed-new/secrets/eddy-report-room',
dnsRecords: (process.env.DNS_RECORDS || '').split(',').map(s => s.trim()).filter(Boolean), dnsRecords: (process.env.DNS_RECORDS || '').split(',').map(s => s.trim()).filter(Boolean),
}; };
@ -133,6 +136,31 @@ async function sendWhatsApp(message) {
} }
} }
async function sendMatrix(message) {
try {
const token = fs.readFileSync(CONFIG.matrixTokenFile, 'utf8').trim();
const room = fs.readFileSync(CONFIG.matrixRoomFile, 'utf8').trim();
if (!token || !room) throw new Error('Matrix token or room is empty');
const txn = `${Date.now()}-${process.pid}`;
const url = `${CONFIG.matrixApi}/_matrix/client/v3/rooms/${encodeURIComponent(room)}/send/m.room.message/${txn}`;
const resp = await fetchWithTimeout(url, {
method: 'PUT',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ msgtype: 'm.text', body: message }),
}, 10000);
if (!resp.ok) {
logError(`Matrix notification failed: ${resp.status}`);
} else {
log('Matrix notification sent.');
}
} catch (e) {
logError(`Matrix notification error: ${e.message}`);
}
}
async function main() { async function main() {
log('WAN IP Guard check starting.'); log('WAN IP Guard check starting.');
@ -193,7 +221,7 @@ async function main() {
].join('\n'); ].join('\n');
await sendWhatsApp(message); await sendWhatsApp(message);
await sendMatrix(message);
if (failCount === 0) { if (failCount === 0) {
writeState(currentIp); writeState(currentIp);
log(`State saved: ${currentIp}`); log(`State saved: ${currentIp}`);