started using of the ddns.loopback setting

This commit is contained in:
tigerbot 2017-10-18 13:48:08 -06:00
parent 6b2b91ba26
commit c55c034f11
2 changed files with 22 additions and 5 deletions

View File

@ -5,6 +5,19 @@ module.exports.create = function (deps, conf) {
var loopback = require('./loopback').create(deps, conf);
var dnsCtrl = require('./dns-ctrl').create(deps, conf);
var loopbackDomain;
function updateConf() {
loopbackDomain = 'oauth3.org';
if (conf.ddns && conf.ddns.loopback) {
if (conf.ddns.loopback.type === 'tunnel@oauth3.org' && conf.ddns.loopback.domain) {
loopbackDomain = conf.ddns.loopback.domain;
} else {
console.warn('invalid loopback configuration: bad type or missing domain');
}
}
}
updateConf();
var localAddr, gateway;
var tunnelActive = false;
async function checkNetworkEnv() {
@ -19,7 +32,7 @@ module.exports.create = function (deps, conf) {
localAddr = addr;
gateway = gw;
var loopResult = await loopback('seth.daplie.me');
var loopResult = await loopback(loopbackDomain);
var notLooped = Object.keys(loopResult.ports).filter(function (port) {
return !loopResult.ports[port];
});
@ -74,8 +87,7 @@ module.exports.create = function (deps, conf) {
return;
}
var session = await getSession();
var directives = await deps.OAUTH3.discover(session.token.aud);
var addr = await loopback.checkPublicAddr(directives.api);
var addr = await loopback.checkPublicAddr(loopbackDomain);
if (publicAddress === addr) {
return;
@ -97,5 +109,6 @@ module.exports.create = function (deps, conf) {
, setDeviceAddress: dnsCtrl.setDeviceAddress
, getDeviceAddresses: dnsCtrl.getDeviceAddresses
, recheckPubAddr: recheckPubAddr
, updateConf: updateConf
};
};

View File

@ -3,7 +3,7 @@
module.exports.create = function (deps, conf) {
var pending = {};
async function checkPublicAddr(host) {
async function _checkPublicAddr(host) {
var result = await deps.request({
method: 'GET'
, url: deps.OAUTH3.url.normalize(host)+'/api/org.oauth3.tunnel/checkip'
@ -19,6 +19,10 @@ module.exports.create = function (deps, conf) {
}
return result.body.address;
}
async function checkPublicAddr(provider) {
var directives = await deps.OAUTH3.discover(provider);
return _checkPublicAddr(directives.api);
}
async function checkSinglePort(host, address, port) {
var crypto = require('crypto');
@ -61,7 +65,7 @@ module.exports.create = function (deps, conf) {
async function loopback(provider) {
var directives = await deps.OAUTH3.discover(provider);
var address = await checkPublicAddr(directives.api);
var address = await _checkPublicAddr(directives.api);
if (conf.debug) {
console.log('checking to see if', address, 'gets back to us');
}