fix config, OvhApi, DynDnsBot

master
adb 3 years ago
parent 231805f373
commit 6e0d4164c1

@ -12,9 +12,11 @@ export class DynDnsBot{
let newIp = await this.getIp(); let newIp = await this.getIp();
if (newIp === this.lastIp) return; if (newIp === this.lastIp) return;
this.lastIp = newIp; this.lastIp = newIp;
this.config.records.forEach(record => { Object.keys(this.config.records).forEach(domain => {
record.target = newIp; this.config.records[domain].forEach(record => {
this.dns.updateRecord(record); record.target = newIp;
this.dns.updateRecord(record, domain);
})
}); });
} }
setInterval(seconds = this.config.updateInterval, random = this.config.randomInterval){ setInterval(seconds = this.config.updateInterval, random = this.config.randomInterval){

@ -45,11 +45,12 @@ export class OvhApi{
header['X-Ovh-Signature'] = await this.getSignature({ header['X-Ovh-Signature'] = await this.getSignature({
method: getMethod(this.methods), method: getMethod(this.methods),
query: this.baseUrl+path, query: this.baseUrl+path,
body, timestamp body: JSON.stringify(body),
timestamp
}); });
header['X-Ovh-Consumer'] = this.credentials.consumerKey; header['X-Ovh-Consumer'] = this.credentials.consumerKey;
header['X-Ovh-Application'] = this.credentials.applicationName; header['X-Ovh-Application'] = this.credentials.applicationKey;
await this.sendRequest({path, body, getMethod, header}); return await this.sendRequest({path, body, getMethod, header});
} }
async getSignature({method = 'GET', query, body='', timestamp}){ 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({ return await this.sendSignedRequest({
path: `/domain/zone/${domain}/record/${recordId}`, path: `/domain/zone/${domain}/record/${id}`,
getMethod: rest=>rest.put, getMethod: rest=>rest.put,
body: {subDomain, target, ttl} body: {subDomain, target, ttl, fieldType}
}); });
} }

@ -2,12 +2,18 @@
"ipApi": "https://api.ipify.org/", "ipApi": "https://api.ipify.org/",
"updateInterval": 300, "updateInterval": 300,
"randomInterval": true, "randomInterval": true,
"records": [{ "records": {
"domain": "foo.bar", "foo.bar": [
"subDomain": "foo.foo.bar", {
"recordId": 0, "fieldType": "A",
"ttl": 300 "subDomain": "sub",
}], "id": 0,
"target": "127.0.0.1",
"ttl": 300,
"zone": "foo.bar"
}
]
},
"ovhCredentials": { "ovhCredentials": {
"applicationKey": "", "applicationKey": "",
"applicationSecret": "", "applicationSecret": "",

Loading…
Cancel
Save