walnut.js/ddns-redirects.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-02-14 09:15:29 +00:00
#!/usr/bin/env node
'use strict';
2015-08-14 21:09:32 +00:00
// TODO have a quick timeout
require('ipify')(function (err, ip) {
console.log('ip', ip);
2015-02-14 09:15:29 +00:00
2015-08-14 21:09:32 +00:00
var path = require('path');
// dig -p 53 @redirect-www.org pi.nadal.daplie.com A
var updateIp = require('./holepunch/helpers/update-ip.js').update;
2015-02-14 09:15:29 +00:00
2015-08-14 21:09:32 +00:00
var redirects = require('./redirects');
var ddns = [];
var ddnsMap = {};
2015-02-14 09:15:29 +00:00
2015-08-14 21:09:32 +00:00
function add(hostname) {
ddns.push({
"name": hostname
, "answer": ip
});
2015-02-14 09:15:29 +00:00
}
2015-08-14 21:09:32 +00:00
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: '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');
});
2015-02-14 09:15:29 +00:00
});