add remove

This commit is contained in:
nyaundi brian 2019-07-18 08:13:31 +00:00
parent 366fd523ae
commit 0aa6f28f85
1 changed files with 33 additions and 3 deletions

View File

@ -136,10 +136,40 @@ module.exports.create = function (config) {
},
remove: function (data) {
var domainname = data.challenge.altname;
var zone = domainname;
var ch = data.challenge;
throw new Error('not supported');
var params = {};
var zone = ch.dnsZone;
// the domain is the first part
params['SLD'] = zone.split('.')[0];
// the rest of the components are the TLD
params['TLD'] = zone.split('.').splice(1).join('.');
// setting a host record overwrites all existing,
// removing a new records means you've have to send back all previous records without removed
return api('namecheap.domains.dns.getHosts',params).then(function (hostsResponse) {
var currentHostRecordsCount = hostsResponse['DomainDNSGetHostsResult'][0]['host'].length;
for (var i = 0; i < currentHostRecordsCount; i++) {
// console.log(hostsResponse['DomainDNSGetHostsResult'][i]['host'][0]);
var currentEntry = hostsResponse['DomainDNSGetHostsResult'][0]['host'][i]['$'];
if(currentEntry['Address'] != ch.dnsAuthorization){
params['HostName'+(i+1)] = currentEntry['Name'];
params['RecordType'+(i+1)] = currentEntry['Type'];
params['Address'+(i+1)] = currentEntry['Address'];
params['TTL'+(i+1)] = currentEntry['TTL'];
}
}
return api('namecheap.domains.dns.setHosts',params).then(function (setHostResponse) {
// console.log('setHost');
// console.log(setHostResponse);
return true
}).catch(function (err) {
throw new Error('record did not remove. check subdomain, api key, etc');
});
});
},
get: function (data) {