change ddns api endpoint
This commit is contained in:
parent
b645f5fe09
commit
61bb3e63e7
|
@ -6,9 +6,10 @@ var updateIp = require('./holepunch/helpers/update-ip.js').update;
|
||||||
var cli = require('cli');
|
var cli = require('cli');
|
||||||
|
|
||||||
cli.parse({
|
cli.parse({
|
||||||
service: [ 's', 'The service to use for updates i.e. redirect-www.org', 'string', 'redirect-www.org' ]
|
service: [ 's', 'The service to use for updates i.e. ns1.example.org', 'string' ]
|
||||||
, hostname: [ 'h', 'The hostname you wish to update i.e. example.com', 'string' ]
|
, hostname: [ 'h', 'The hostname you wish to update i.e. example.com', 'string' ]
|
||||||
, type: [ 't', 'The record type i.e. A, MX, CNAME, etc', 'string', 'A' ]
|
, pathname: [ 'h', 'The api route to which to POST i.e. /api/ddns', 'string', '/api/com.daplie.dns/ddns' ]
|
||||||
|
, type: [ 't', 'The record type i.e. A, AAAA, MX, CNAME, ANAME, FWD, etc', 'string', 'A' ]
|
||||||
, priority: [ 'p', 'The priority (for MX and other records)', 'string' ]
|
, priority: [ 'p', 'The priority (for MX and other records)', 'string' ]
|
||||||
, port: [ false, 'The port (default https/443)', 'number', 443 ]
|
, port: [ false, 'The port (default https/443)', 'number', 443 ]
|
||||||
, insecure: [ false, '(deprecated) allow insecure non-https connections', 'boolean' ]
|
, insecure: [ false, '(deprecated) allow insecure non-https connections', 'boolean' ]
|
||||||
|
@ -19,8 +20,8 @@ cli.parse({
|
||||||
|
|
||||||
cli.main(function (args, options) {
|
cli.main(function (args, options) {
|
||||||
//console.log(options);
|
//console.log(options);
|
||||||
options.hostname = options.hostname || args[0]
|
options.hostname = options.hostname || args[0];
|
||||||
options.answer = options.answer || args[1]
|
options.answer = options.answer || args[1];
|
||||||
|
|
||||||
if (options.insecure) {
|
if (options.insecure) {
|
||||||
//console.error('--insecure is not supported. You must use secure connections.');
|
//console.error('--insecure is not supported. You must use secure connections.');
|
||||||
|
@ -40,9 +41,11 @@ cli.main(function (args, options) {
|
||||||
//console.log(options);
|
//console.log(options);
|
||||||
|
|
||||||
return updateIp({
|
return updateIp({
|
||||||
updater: options.service
|
hostname: options.service
|
||||||
|
, updater: options.service
|
||||||
, port: options.port
|
, port: options.port
|
||||||
, cacert: options.cacert
|
, cacert: options.cacert
|
||||||
|
, pathname: options.pathname
|
||||||
, token: options.token
|
, token: options.token
|
||||||
, ddns: [
|
, ddns: [
|
||||||
{ "name": options.hostname
|
{ "name": options.hostname
|
||||||
|
|
|
@ -3,16 +3,23 @@
|
||||||
|
|
||||||
var PromiseA = require('bluebird').Promise;
|
var PromiseA = require('bluebird').Promise;
|
||||||
var https = require('https');
|
var https = require('https');
|
||||||
var fs = require('fs');
|
var fs = PromiseA.promisifyAll(require('fs'));
|
||||||
var path = require('path');
|
|
||||||
|
|
||||||
module.exports.update = function (opts) {
|
module.exports.update = function (opts) {
|
||||||
return new PromiseA(function (resolve, reject) {
|
return new PromiseA(function (resolve, reject) {
|
||||||
var options;
|
var options;
|
||||||
var hostname = opts.updater || 'redirect-www.org';
|
var hostname = opts.hostname || opts.updater;
|
||||||
var port = opts.port || 65443;
|
var port = opts.port;
|
||||||
|
var pathname = opts.pathname;
|
||||||
var req;
|
var req;
|
||||||
|
|
||||||
|
if (!hostname) {
|
||||||
|
throw new Error('Please specify a DDNS host as opts.hostname');
|
||||||
|
}
|
||||||
|
if (!pathname) {
|
||||||
|
throw new Error('Please specify the api route as opts.pathname');
|
||||||
|
}
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
host: hostname
|
host: hostname
|
||||||
, port: port
|
, port: port
|
||||||
|
@ -20,7 +27,7 @@ module.exports.update = function (opts) {
|
||||||
, headers: {
|
, headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
, path: '/api/ddns'
|
, path: pathname
|
||||||
//, auth: opts.auth || 'admin:secret'
|
//, auth: opts.auth || 'admin:secret'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,25 +36,25 @@ module.exports.update = function (opts) {
|
||||||
opts.cacert = [opts.cacert];
|
opts.cacert = [opts.cacert];
|
||||||
}
|
}
|
||||||
options.ca = opts.cacert;
|
options.ca = opts.cacert;
|
||||||
} else {
|
|
||||||
options.ca = [path.join(__dirname, '..', 'certs', 'ca', 'my-root-ca.crt.pem')]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
options.ca = options.ca.map(function (str) {
|
options.ca = options.ca.map(function (str) {
|
||||||
if ('string' === typeof str && str.length < 1000) {
|
if ('string' === typeof str && str.length < 1000) {
|
||||||
str = fs.readFileSync(str);
|
str = fs.readFileAsync(str);
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (opts.token || opts.jwt) {
|
if (opts.token || opts.jwt) {
|
||||||
options.headers['Authorization'] = 'Bearer ' + (opts.token || opts.jwt);
|
options.headers.Authorization = 'Bearer ' + (opts.token || opts.jwt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false === opts.cacert) {
|
if (false === opts.cacert) {
|
||||||
options.rejectUnauthorized = false;
|
options.rejectUnauthorized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return PromiseA.all(options.ca).then(function (cas) {
|
||||||
|
options.ca = cas;
|
||||||
options.agent = new https.Agent(options);
|
options.agent = new https.Agent(options);
|
||||||
|
|
||||||
req = https.request(options, function(res) {
|
req = https.request(options, function(res) {
|
||||||
|
@ -78,5 +85,6 @@ module.exports.update = function (opts) {
|
||||||
});
|
});
|
||||||
|
|
||||||
req.end(JSON.stringify(opts.ddns, null, ' '));
|
req.end(JSON.stringify(opts.ddns, null, ' '));
|
||||||
|
}, reject);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,8 +15,9 @@ function update(hostnames, addresses) {
|
||||||
// TODO use API to add and remove nameservers
|
// TODO use API to add and remove nameservers
|
||||||
var services = [
|
var services = [
|
||||||
// TODO XXX don't disable cacert checking
|
// TODO XXX don't disable cacert checking
|
||||||
{ hostname: 'ns1.redirect-www.org', port: 65443, cacert: false }
|
{ hostname: 'ns1.redirect-www.org', port: 65443, cacert: false, pathname: '/api/dns' }
|
||||||
, { hostname: 'ns2.redirect-www.org', port: 65443, cacert: false }
|
, { hostname: 'ns2.redirect-www.org', port: 65443, cacert: false, pathname: '/api/dns' }
|
||||||
|
// { cacert = [path.join(__dirname, '..', 'certs', 'ca', 'my-root-ca.crt.pem')] };
|
||||||
];
|
];
|
||||||
var answers = [];
|
var answers = [];
|
||||||
var promises;
|
var promises;
|
||||||
|
|
Loading…
Reference in New Issue