add remove
This commit is contained in:
		
							parent
							
								
									366fd523ae
								
							
						
					
					
						commit
						0aa6f28f85
					
				
							
								
								
									
										36
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								lib/index.js
									
									
									
									
									
								
							| @ -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) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user