tested handling dns updates with token
This commit is contained in:
parent
ed4e23e924
commit
c6034b3992
|
@ -1,38 +1,52 @@
|
|||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
// dig -p 53 @redirect-www.org pi.nadal.daplie.com A
|
||||
var updateIp = require('./holepunch/helpers/update-ip.js').update;
|
||||
// TODO have a quick timeout
|
||||
require('ipify')(function (err, ip) {
|
||||
console.log('ip', ip);
|
||||
|
||||
var redirects = require('./redirects');
|
||||
var ddns = [];
|
||||
var ddnsMap = {};
|
||||
var path = require('path');
|
||||
// dig -p 53 @redirect-www.org pi.nadal.daplie.com A
|
||||
var updateIp = require('./holepunch/helpers/update-ip.js').update;
|
||||
|
||||
function add(hostname) {
|
||||
var redirects = require('./redirects');
|
||||
var ddns = [];
|
||||
var ddnsMap = {};
|
||||
|
||||
function add(hostname) {
|
||||
ddns.push({
|
||||
"name": hostname
|
||||
, "answer": ip
|
||||
});
|
||||
}
|
||||
redirects.forEach(function (r) {
|
||||
}
|
||||
|
||||
redirects.forEach(function (r) {
|
||||
if (!ddnsMap[r.from.hostname.toLowerCase()]) {
|
||||
add(r.from.hostname);
|
||||
}
|
||||
if (!ddnsMap[r.to.hostname.toLowerCase()]) {
|
||||
add(r.to.hostname);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return updateIp({
|
||||
updater: 'redirect-www.org'
|
||||
, port: 65443
|
||||
, cacert: null
|
||||
, ddns: ddns
|
||||
}).then(function (data) {
|
||||
if ('string') {
|
||||
return updateIp({
|
||||
updater: 'ns1.redirect-www.org'
|
||||
, port: 65443
|
||||
, cacert: path.join(__dirname, 'certs/ca/ns1-test.root.crt.pem')
|
||||
, ddns: ddns
|
||||
, token: require('./dyndns-token').token
|
||||
}).then(function (data) {
|
||||
if ('string' === typeof data) {
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
} catch(e) {
|
||||
console.error('[ERROR] bad json response');
|
||||
console.error(data);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(JSON.stringify(data, null, ' '));
|
||||
console.log('Test with');
|
||||
console.log('dig <<hostname>> A');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -20,12 +20,31 @@ module.exports.update = function (opts) {
|
|||
'Content-Type': 'application/json'
|
||||
}
|
||||
, path: '/api/ddns'
|
||||
, auth: opts.auth || 'admin:secret'
|
||||
, ca: [ fs.readFileSync(path.join(__dirname, '..', 'certs', 'ca', 'my-root-ca.crt.pem')) ]
|
||||
//, auth: opts.auth || 'admin:secret'
|
||||
};
|
||||
|
||||
if (opts.jwt) {
|
||||
options.headers['Authorization'] = 'Bearer ' + opts.jwt;
|
||||
if (opts.cacert) {
|
||||
if (!Array.isArray(opts.cacert)) {
|
||||
opts.cacert = [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) {
|
||||
if ('string' === typeof str && str.length < 1000) {
|
||||
str = fs.readFileSync(str);
|
||||
}
|
||||
return str;
|
||||
});
|
||||
|
||||
if (opts.token || opts.jwt) {
|
||||
options.headers['Authorization'] = 'Bearer ' + (opts.token || opts.jwt);
|
||||
}
|
||||
|
||||
if (false === opts.cacert) {
|
||||
options.rejectUnauthorized = false;
|
||||
}
|
||||
|
||||
options.agent = new https.Agent(options);
|
||||
|
|
|
@ -73,6 +73,7 @@
|
|||
"fresh": "^0.2.4",
|
||||
"human-readable-ids": "1.x",
|
||||
"inherits": "^2.0.1",
|
||||
"ipify": "^1.0.5",
|
||||
"jarson": "1.x",
|
||||
"json-storage": "2.x",
|
||||
"knex": "^0.6.23",
|
||||
|
|
Loading…
Reference in New Issue