Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
0b387a150f | |||
d93093fe00 | |||
|
9071b0c048 |
12
README.md
12
README.md
@ -1,4 +1,4 @@
|
||||
# [acme-dns-01-namecheap](https://git.rootprojects.org/root/acme-dns-01-namecheap.js) | a [Root](https://rootrpojects.org) project
|
||||
# [acme-dns-01-namecheap](https://git.rootprojects.org/root/acme-dns-01-namecheap) | 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: 'jdoe',
|
||||
apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||
clientIp: '121.22.123.22',
|
||||
username: 'jdoe',
|
||||
baseUrl: 'https://api.namecheap.com/xml.response' // default
|
||||
apiUser: 'username',
|
||||
apiKey: 'xxxx',
|
||||
clientIp: 'public ip',
|
||||
username: 'api user',
|
||||
baseUrl: 'sandbox or production' // default production
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
ZONE=example.co.uk
|
||||
|
||||
API_USER=exampleuser
|
||||
API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
API_KEY=xxxxxxxxxxxxxxx
|
||||
USERNAME=exampleuser
|
||||
CLIENT_IP=121.22.123.22
|
||||
|
100
lib/index.js
100
lib/index.js
@ -2,15 +2,14 @@
|
||||
var util = require('util');
|
||||
|
||||
var request; // = require('@root/request');
|
||||
//var querystring = require('querystring');
|
||||
var parseString = require('xml2js').parseString;
|
||||
parseString = util.promisify(parseString);
|
||||
|
||||
var SANDBOX_URL = 'https://api.sandbox.namecheap.com/xml.response';
|
||||
var PRODUCTION_URL = 'https://api.namecheap.com/xml.response';
|
||||
const SANDBOX_URL = 'https://api.sandbox.namecheap.com/xml.response';
|
||||
const PRODUCTION_URL = 'https://api.namecheap.com/xml.response';
|
||||
|
||||
var defaults = {
|
||||
baseUrl: PRODUCTION_URL
|
||||
baseUrl: SANDBOX_URL
|
||||
};
|
||||
|
||||
function extend(obj) {
|
||||
@ -49,7 +48,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) {
|
||||
@ -58,7 +57,11 @@ module.exports.create = function(config) {
|
||||
assign(requestParams, params);
|
||||
|
||||
var url = requestUrl(baseUrl, requestParams);
|
||||
// console.log(url);
|
||||
console.log('DEBUG >>> url: ' + url);
|
||||
console.log(
|
||||
'DEBUG >>> requestParams: ' + JSON.stringify(requestParams, null, 2)
|
||||
);
|
||||
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: url
|
||||
@ -67,17 +70,28 @@ module.exports.create = function(config) {
|
||||
// console.log(responseBody);
|
||||
return parseString(responseBody).then(function(result) {
|
||||
// check response status
|
||||
if (result['ApiResponse']['$']['Status'] === 'OK') {
|
||||
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"
|
||||
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');
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -94,29 +108,36 @@ module.exports.create = function(config) {
|
||||
) {
|
||||
// console.log('zones');
|
||||
// console.log(zonesResponse);
|
||||
var zones = zonesResponse['DomainGetListResult'][0][
|
||||
'Domain'
|
||||
].map(function(el) {
|
||||
return el['$']['Name'];
|
||||
return zonesResponse['DomainGetListResult'].map(function(x) {
|
||||
return x['Domain'][0]['$']['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.dnsZone;
|
||||
var zone = ch.identifier.value;
|
||||
console.log(`DEBUG >>> zone: ${zone}`);
|
||||
|
||||
// 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('.');
|
||||
// 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']}`);
|
||||
|
||||
// setting a host record overwrites all existing,
|
||||
// adding a new records means you've have to send back all previous records too
|
||||
@ -165,14 +186,11 @@ module.exports.create = function(config) {
|
||||
var ch = data.challenge;
|
||||
|
||||
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('.');
|
||||
var zone = ch.identifier.value;
|
||||
var domains = zone.split('.');
|
||||
|
||||
params['TLD'] = domains[domains.length - 1];
|
||||
params['SLD'] = domains[domains.length - 2];
|
||||
|
||||
// setting a host record overwrites all existing,
|
||||
// removing a new records means you've have to send back all previous records without removed
|
||||
@ -214,15 +232,11 @@ module.exports.create = function(config) {
|
||||
var ch = data.challenge;
|
||||
|
||||
var params = {};
|
||||
var zone = ch.dnsZone;
|
||||
var zone = ch.identifier.value;
|
||||
var domains = zone.split('.');
|
||||
|
||||
// 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('.');
|
||||
params['TLD'] = domains[domains.length - 1];
|
||||
params['SLD'] = domains[domains.length - 2];
|
||||
|
||||
return api('namecheap.domains.dns.getHosts', params).then(function(
|
||||
hostsResponse
|
||||
|
15
package-lock.json
generated
15
package-lock.json
generated
@ -26,21 +26,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"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",
|
||||
|
14
package.json
14
package.json
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "acme-dns-01-namecheap",
|
||||
"version": "3.0.1",
|
||||
"version": "3.0.0",
|
||||
"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,8 +34,6 @@
|
||||
"xml2js": "^0.4.19"
|
||||
},
|
||||
"devDependencies": {
|
||||
"acme-challenge-test": "^3.3.2",
|
||||
"acme-dns-01-test": "^3.2.1",
|
||||
"dotenv": "^8.0.0"
|
||||
"acme-challenge-test": "^3.3.2"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user