Compare commits

..

6 Commits

Author SHA1 Message Date
4ad4cf29f4 v3.0.1: fix typo in URL 2019-09-21 14:34:08 -06:00
d9b9b0fcd6 v3.0.0: NameCheap DNS + Let's Encrypt for Node.js 2019-07-23 02:25:11 -06:00
705902ff32 bugfix: list all zones 2019-07-23 02:24:47 -06:00
91a8c8b237 doc and cleanup 2019-07-23 02:24:03 -06:00
4b8a7d2e00 minor cleanup 2019-07-23 02:12:08 -06:00
ff8c41b994 make prettier 2019-07-23 01:59:52 -06:00
5 changed files with 73 additions and 70 deletions

View File

@ -1,4 +1,4 @@
# [acme-dns-01-namecheap](https://git.rootprojects.org/root/acme-dns-01-namecheap) | a [Root](https://rootrpojects.org) project
# [acme-dns-01-namecheap](https://git.rootprojects.org/root/acme-dns-01-namecheap.js) | a [Root](https://rootrpojects.org) project
NameCheap DNS + Let's Encrypt
@ -17,11 +17,11 @@ First you create an instance with your credentials:
```js
var dns01 = require('acme-dns-01-namecheap').create({
apiUser: 'username',
apiKey: 'xxxx',
clientIp: 'public ip',
username: 'api user',
baseUrl: 'sandbox or production' // default production
apiUser: 'jdoe',
apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
clientIp: '121.22.123.22',
username: 'jdoe',
baseUrl: 'https://api.namecheap.com/xml.response' // default
});
```

View File

@ -1,6 +1,6 @@
ZONE=example.co.uk
API_USER=exampleuser
API_KEY=xxxxxxxxxxxxxxx
API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
USERNAME=exampleuser
CLIENT_IP=121.22.123.22

View File

@ -2,14 +2,15 @@
var util = require('util');
var request; // = require('@root/request');
//var querystring = require('querystring');
var parseString = require('xml2js').parseString;
parseString = util.promisify(parseString);
const SANDBOX_URL = 'https://api.sandbox.namecheap.com/xml.response';
const PRODUCTION_URL = 'https://api.namecheap.com/xml.response';
var SANDBOX_URL = 'https://api.sandbox.namecheap.com/xml.response';
var PRODUCTION_URL = 'https://api.namecheap.com/xml.response';
var defaults = {
baseUrl: SANDBOX_URL
baseUrl: PRODUCTION_URL
};
function extend(obj) {
@ -48,7 +49,7 @@ module.exports.create = function(config) {
apiUser: config.apiUser,
apiKey: config.apiKey,
username: config.username,
ClientIp: config.clientIp
clientIp: config.clientIp
};
function api(command, params) {
@ -57,11 +58,7 @@ module.exports.create = function(config) {
assign(requestParams, params);
var url = requestUrl(baseUrl, requestParams);
console.log('DEBUG >>> url: ' + url);
console.log(
'DEBUG >>> requestParams: ' + JSON.stringify(requestParams, null, 2)
);
// console.log(url);
return request({
method: 'POST',
url: url
@ -70,28 +67,17 @@ module.exports.create = function(config) {
// console.log(responseBody);
return parseString(responseBody).then(function(result) {
// check response status
if (result['ApiResponse']['$']['Status'] === 'ERROR') {
for (
let i = 0;
i < result['ApiResponse']['Errors'].length;
i++
) {
console.log(
'DEBUG >>> error: ' +
JSON.stringify(
result['ApiResponse']['Errors'][i][
'Error'
][0],
null,
2
)
);
}
throw new Error('API Error');
} else {
// Status="OK"
if (result['ApiResponse']['$']['Status'] === 'OK') {
return result['ApiResponse']['CommandResponse'][0];
}
// Status="ERROR"
var i;
var len = result['ApiResponse']['Errors'].length;
for (i = 0; i < len; i += 1) {
console.error(result['ApiResponse']['Errors'][i]);
}
throw new Error('API Error');
});
});
}
@ -108,36 +94,29 @@ module.exports.create = function(config) {
) {
// console.log('zones');
// console.log(zonesResponse);
return zonesResponse['DomainGetListResult'].map(function(x) {
return x['Domain'][0]['$']['Name'];
var zones = zonesResponse['DomainGetListResult'][0][
'Domain'
].map(function(el) {
return el['$']['Name'];
});
//console.log(zones);
return zones;
});
},
set: function(data) {
console.log(`DEBUG >>> data: ${JSON.stringify(data, null, 2)}`);
var ch = data.challenge;
var txt = ch.dnsAuthorization;
var params = {};
// var zone = ch.dnsZone;
var zone = ch.identifier.value;
console.log(`DEBUG >>> zone: ${zone}`);
var zone = ch.dnsZone;
// the domain is the first part
// params['SLD'] = zone.split('.')[0];
params['SLD'] = zone.split('.')[0];
// the rest of the components are the TLD
// params['TLD'] = zone.split('.').splice(1).join('.');
var domains = zone.split('.');
console.log('DEBUG >>> ' + domains);
// if you have subdomain foo.blah.com, SLD = blah and TLD = com
params['TLD'] = domains[domains.length - 1];
params['SLD'] = domains[domains.length - 2];
console.log(`DEBUG >>> SLD: ${params['SLD']}`);
console.log(`DEBUG >>> TLD: ${params['TLD']}`);
params['TLD'] = zone
.split('.')
.splice(1)
.join('.');
// setting a host record overwrites all existing,
// adding a new records means you've have to send back all previous records too
@ -186,11 +165,14 @@ module.exports.create = function(config) {
var ch = data.challenge;
var params = {};
var zone = ch.identifier.value;
var domains = zone.split('.');
params['TLD'] = domains[domains.length - 1];
params['SLD'] = domains[domains.length - 2];
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
@ -232,11 +214,15 @@ module.exports.create = function(config) {
var ch = data.challenge;
var params = {};
var zone = ch.identifier.value;
var domains = zone.split('.');
var zone = ch.dnsZone;
params['TLD'] = domains[domains.length - 1];
params['SLD'] = domains[domains.length - 2];
// 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('.');
return api('namecheap.domains.dns.getHosts', params).then(function(
hostsResponse

15
package-lock.json generated
View File

@ -26,6 +26,21 @@
}
}
},
"acme-dns-01-test": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/acme-dns-01-test/-/acme-dns-01-test-3.3.1.tgz",
"integrity": "sha512-di2/n19FDLc/pe4CDxd/FpxuuCZG7CHEQVjWr96vvtxe5XNNgdHi2eJqVP0z9WBf9s61zxslyRPrAWzTN8ZVWw==",
"dev": true,
"requires": {
"acme-challenge-test": "^3.3.1"
}
},
"dotenv": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.0.0.tgz",
"integrity": "sha512-30xVGqjLjiUOArT4+M5q9sYdvuR4riM6yK9wMcas9Vbp6zZa+ocC9dp6QoftuhTPhFAiLK/0C5Ni2nou/Bk8lg==",
"dev": true
},
"sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",

View File

@ -1,12 +1,12 @@
{
"name": "acme-dns-01-namecheap",
"version": "3.0.0",
"version": "3.0.1",
"description": "Namecheap DNS for Let's Encrypt / ACME dns-01 challenges with ACME.js and Greenlock.js",
"main": "index.js",
"files": [
"lib",
"test.js"
],
"files": [
"lib",
"test.js"
],
"scripts": {
"test": "node ./test.js"
},
@ -34,6 +34,8 @@
"xml2js": "^0.4.19"
},
"devDependencies": {
"acme-challenge-test": "^3.3.2"
"acme-challenge-test": "^3.3.2",
"acme-dns-01-test": "^3.2.1",
"dotenv": "^8.0.0"
}
}