From 6e0d4164c128483f93f7787ac6b266b168d1aa50 Mon Sep 17 00:00:00 2001 From: adb Date: Sun, 11 Apr 2021 17:46:08 +0200 Subject: [PATCH] fix config, OvhApi, DynDnsBot --- DynDnsBot.js | 8 +++++--- OvhApi.js | 13 +++++++------ example.config.json | 18 ++++++++++++------ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/DynDnsBot.js b/DynDnsBot.js index 76502e7..ff35377 100644 --- a/DynDnsBot.js +++ b/DynDnsBot.js @@ -12,9 +12,11 @@ export class DynDnsBot{ let newIp = await this.getIp(); if (newIp === this.lastIp) return; this.lastIp = newIp; - this.config.records.forEach(record => { - record.target = newIp; - this.dns.updateRecord(record); + Object.keys(this.config.records).forEach(domain => { + this.config.records[domain].forEach(record => { + record.target = newIp; + this.dns.updateRecord(record, domain); + }) }); } setInterval(seconds = this.config.updateInterval, random = this.config.randomInterval){ diff --git a/OvhApi.js b/OvhApi.js index b76acc1..f96044e 100644 --- a/OvhApi.js +++ b/OvhApi.js @@ -45,11 +45,12 @@ export class OvhApi{ header['X-Ovh-Signature'] = await this.getSignature({ method: getMethod(this.methods), query: this.baseUrl+path, - body, timestamp + body: JSON.stringify(body), + timestamp }); header['X-Ovh-Consumer'] = this.credentials.consumerKey; - header['X-Ovh-Application'] = this.credentials.applicationName; - await this.sendRequest({path, body, getMethod, header}); + header['X-Ovh-Application'] = this.credentials.applicationKey; + return await this.sendRequest({path, body, getMethod, header}); } async getSignature({method = 'GET', query, body='', timestamp}){ @@ -87,11 +88,11 @@ export class OvhApi{ }); } - async updateRecord({domain, subDomain, recordId, target, ttl = 3600}){ + async updateRecord({zone, subDomain, id, target, ttl = 3600, fieldType = 'A'}, domain = zone){ return await this.sendSignedRequest({ - path: `/domain/zone/${domain}/record/${recordId}`, + path: `/domain/zone/${domain}/record/${id}`, getMethod: rest=>rest.put, - body: {subDomain, target, ttl} + body: {subDomain, target, ttl, fieldType} }); } diff --git a/example.config.json b/example.config.json index 87a9aa8..b73f6d1 100644 --- a/example.config.json +++ b/example.config.json @@ -2,12 +2,18 @@ "ipApi": "https://api.ipify.org/", "updateInterval": 300, "randomInterval": true, - "records": [{ - "domain": "foo.bar", - "subDomain": "foo.foo.bar", - "recordId": 0, - "ttl": 300 - }], + "records": { + "foo.bar": [ + { + "fieldType": "A", + "subDomain": "sub", + "id": 0, + "target": "127.0.0.1", + "ttl": 300, + "zone": "foo.bar" + } + ] + }, "ovhCredentials": { "applicationKey": "", "applicationSecret": "",