Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
4ad4cf29f4 | |||
d9b9b0fcd6 | |||
705902ff32 | |||
91a8c8b237 | |||
4b8a7d2e00 | |||
ff8c41b994 |
12
README.md
12
README.md
@ -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
|
NameCheap DNS + Let's Encrypt
|
||||||
|
|
||||||
@ -17,11 +17,11 @@ First you create an instance with your credentials:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
var dns01 = require('acme-dns-01-namecheap').create({
|
var dns01 = require('acme-dns-01-namecheap').create({
|
||||||
apiUser: 'username',
|
apiUser: 'jdoe',
|
||||||
apiKey: 'xxxx',
|
apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
||||||
clientIp: 'public ip',
|
clientIp: '121.22.123.22',
|
||||||
username: 'api user',
|
username: 'jdoe',
|
||||||
baseUrl: 'sandbox or production' // default production
|
baseUrl: 'https://api.namecheap.com/xml.response' // default
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
ZONE=example.co.uk
|
ZONE=example.co.uk
|
||||||
|
|
||||||
API_USER=exampleuser
|
API_USER=exampleuser
|
||||||
API_KEY=xxxxxxxxxxxxxxx
|
API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
USERNAME=exampleuser
|
USERNAME=exampleuser
|
||||||
CLIENT_IP=121.22.123.22
|
CLIENT_IP=121.22.123.22
|
||||||
|
100
lib/index.js
100
lib/index.js
@ -2,14 +2,15 @@
|
|||||||
var util = require('util');
|
var util = require('util');
|
||||||
|
|
||||||
var request; // = require('@root/request');
|
var request; // = require('@root/request');
|
||||||
|
//var querystring = require('querystring');
|
||||||
var parseString = require('xml2js').parseString;
|
var parseString = require('xml2js').parseString;
|
||||||
parseString = util.promisify(parseString);
|
parseString = util.promisify(parseString);
|
||||||
|
|
||||||
const SANDBOX_URL = 'https://api.sandbox.namecheap.com/xml.response';
|
var SANDBOX_URL = 'https://api.sandbox.namecheap.com/xml.response';
|
||||||
const PRODUCTION_URL = 'https://api.namecheap.com/xml.response';
|
var PRODUCTION_URL = 'https://api.namecheap.com/xml.response';
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
baseUrl: SANDBOX_URL
|
baseUrl: PRODUCTION_URL
|
||||||
};
|
};
|
||||||
|
|
||||||
function extend(obj) {
|
function extend(obj) {
|
||||||
@ -48,7 +49,7 @@ module.exports.create = function(config) {
|
|||||||
apiUser: config.apiUser,
|
apiUser: config.apiUser,
|
||||||
apiKey: config.apiKey,
|
apiKey: config.apiKey,
|
||||||
username: config.username,
|
username: config.username,
|
||||||
ClientIp: config.clientIp
|
clientIp: config.clientIp
|
||||||
};
|
};
|
||||||
|
|
||||||
function api(command, params) {
|
function api(command, params) {
|
||||||
@ -57,11 +58,7 @@ module.exports.create = function(config) {
|
|||||||
assign(requestParams, params);
|
assign(requestParams, params);
|
||||||
|
|
||||||
var url = requestUrl(baseUrl, requestParams);
|
var url = requestUrl(baseUrl, requestParams);
|
||||||
console.log('DEBUG >>> url: ' + url);
|
// console.log(url);
|
||||||
console.log(
|
|
||||||
'DEBUG >>> requestParams: ' + JSON.stringify(requestParams, null, 2)
|
|
||||||
);
|
|
||||||
|
|
||||||
return request({
|
return request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: url
|
url: url
|
||||||
@ -70,28 +67,17 @@ module.exports.create = function(config) {
|
|||||||
// console.log(responseBody);
|
// console.log(responseBody);
|
||||||
return parseString(responseBody).then(function(result) {
|
return parseString(responseBody).then(function(result) {
|
||||||
// check response status
|
// check response status
|
||||||
if (result['ApiResponse']['$']['Status'] === 'ERROR') {
|
if (result['ApiResponse']['$']['Status'] === 'OK') {
|
||||||
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];
|
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('zones');
|
||||||
// console.log(zonesResponse);
|
// console.log(zonesResponse);
|
||||||
return zonesResponse['DomainGetListResult'].map(function(x) {
|
var zones = zonesResponse['DomainGetListResult'][0][
|
||||||
return x['Domain'][0]['$']['Name'];
|
'Domain'
|
||||||
|
].map(function(el) {
|
||||||
|
return el['$']['Name'];
|
||||||
});
|
});
|
||||||
|
//console.log(zones);
|
||||||
|
return zones;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
set: function(data) {
|
set: function(data) {
|
||||||
console.log(`DEBUG >>> data: ${JSON.stringify(data, null, 2)}`);
|
|
||||||
var ch = data.challenge;
|
var ch = data.challenge;
|
||||||
var txt = ch.dnsAuthorization;
|
var txt = ch.dnsAuthorization;
|
||||||
|
|
||||||
var params = {};
|
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
|
// the domain is the first part
|
||||||
// params['SLD'] = zone.split('.')[0];
|
params['SLD'] = zone.split('.')[0];
|
||||||
// the rest of the components are the TLD
|
// the rest of the components are the TLD
|
||||||
// params['TLD'] = zone.split('.').splice(1).join('.');
|
params['TLD'] = zone
|
||||||
|
.split('.')
|
||||||
var domains = zone.split('.');
|
.splice(1)
|
||||||
console.log('DEBUG >>> ' + domains);
|
.join('.');
|
||||||
|
|
||||||
// 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,
|
// setting a host record overwrites all existing,
|
||||||
// adding a new records means you've have to send back all previous records too
|
// 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 ch = data.challenge;
|
||||||
|
|
||||||
var params = {};
|
var params = {};
|
||||||
var zone = ch.identifier.value;
|
var zone = ch.dnsZone;
|
||||||
var domains = zone.split('.');
|
// the domain is the first part
|
||||||
|
params['SLD'] = zone.split('.')[0];
|
||||||
params['TLD'] = domains[domains.length - 1];
|
// the rest of the components are the TLD
|
||||||
params['SLD'] = domains[domains.length - 2];
|
params['TLD'] = zone
|
||||||
|
.split('.')
|
||||||
|
.splice(1)
|
||||||
|
.join('.');
|
||||||
|
|
||||||
// setting a host record overwrites all existing,
|
// setting a host record overwrites all existing,
|
||||||
// removing a new records means you've have to send back all previous records without removed
|
// 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 ch = data.challenge;
|
||||||
|
|
||||||
var params = {};
|
var params = {};
|
||||||
var zone = ch.identifier.value;
|
var zone = ch.dnsZone;
|
||||||
var domains = zone.split('.');
|
|
||||||
|
|
||||||
params['TLD'] = domains[domains.length - 1];
|
// the domain is the first part
|
||||||
params['SLD'] = domains[domains.length - 2];
|
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(
|
return api('namecheap.domains.dns.getHosts', params).then(function(
|
||||||
hostsResponse
|
hostsResponse
|
||||||
|
15
package-lock.json
generated
15
package-lock.json
generated
@ -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": {
|
"sax": {
|
||||||
"version": "1.2.4",
|
"version": "1.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "acme-dns-01-namecheap",
|
"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",
|
"description": "Namecheap DNS for Let's Encrypt / ACME dns-01 challenges with ACME.js and Greenlock.js",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"files": [
|
"files": [
|
||||||
@ -34,6 +34,8 @@
|
|||||||
"xml2js": "^0.4.19"
|
"xml2js": "^0.4.19"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"acme-challenge-test": "^3.3.2"
|
"acme-challenge-test": "^3.3.2",
|
||||||
|
"acme-dns-01-test": "^3.2.1",
|
||||||
|
"dotenv": "^8.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user