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();
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){

@ -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}
});
}

@ -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": "",

Loading…
Cancel
Save