started using of the ddns.loopback setting
This commit is contained in:
parent
6b2b91ba26
commit
c55c034f11
|
@ -5,6 +5,19 @@ module.exports.create = function (deps, conf) {
|
||||||
var loopback = require('./loopback').create(deps, conf);
|
var loopback = require('./loopback').create(deps, conf);
|
||||||
var dnsCtrl = require('./dns-ctrl').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 localAddr, gateway;
|
||||||
var tunnelActive = false;
|
var tunnelActive = false;
|
||||||
async function checkNetworkEnv() {
|
async function checkNetworkEnv() {
|
||||||
|
@ -19,7 +32,7 @@ module.exports.create = function (deps, conf) {
|
||||||
|
|
||||||
localAddr = addr;
|
localAddr = addr;
|
||||||
gateway = gw;
|
gateway = gw;
|
||||||
var loopResult = await loopback('seth.daplie.me');
|
var loopResult = await loopback(loopbackDomain);
|
||||||
var notLooped = Object.keys(loopResult.ports).filter(function (port) {
|
var notLooped = Object.keys(loopResult.ports).filter(function (port) {
|
||||||
return !loopResult.ports[port];
|
return !loopResult.ports[port];
|
||||||
});
|
});
|
||||||
|
@ -74,8 +87,7 @@ module.exports.create = function (deps, conf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var session = await getSession();
|
var session = await getSession();
|
||||||
var directives = await deps.OAUTH3.discover(session.token.aud);
|
var addr = await loopback.checkPublicAddr(loopbackDomain);
|
||||||
var addr = await loopback.checkPublicAddr(directives.api);
|
|
||||||
|
|
||||||
if (publicAddress === addr) {
|
if (publicAddress === addr) {
|
||||||
return;
|
return;
|
||||||
|
@ -97,5 +109,6 @@ module.exports.create = function (deps, conf) {
|
||||||
, setDeviceAddress: dnsCtrl.setDeviceAddress
|
, setDeviceAddress: dnsCtrl.setDeviceAddress
|
||||||
, getDeviceAddresses: dnsCtrl.getDeviceAddresses
|
, getDeviceAddresses: dnsCtrl.getDeviceAddresses
|
||||||
, recheckPubAddr: recheckPubAddr
|
, recheckPubAddr: recheckPubAddr
|
||||||
|
, updateConf: updateConf
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
module.exports.create = function (deps, conf) {
|
module.exports.create = function (deps, conf) {
|
||||||
var pending = {};
|
var pending = {};
|
||||||
|
|
||||||
async function checkPublicAddr(host) {
|
async function _checkPublicAddr(host) {
|
||||||
var result = await deps.request({
|
var result = await deps.request({
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
, url: deps.OAUTH3.url.normalize(host)+'/api/org.oauth3.tunnel/checkip'
|
, 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;
|
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) {
|
async function checkSinglePort(host, address, port) {
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
|
@ -61,7 +65,7 @@ module.exports.create = function (deps, conf) {
|
||||||
|
|
||||||
async function loopback(provider) {
|
async function loopback(provider) {
|
||||||
var directives = await deps.OAUTH3.discover(provider);
|
var directives = await deps.OAUTH3.discover(provider);
|
||||||
var address = await checkPublicAddr(directives.api);
|
var address = await _checkPublicAddr(directives.api);
|
||||||
if (conf.debug) {
|
if (conf.debug) {
|
||||||
console.log('checking to see if', address, 'gets back to us');
|
console.log('checking to see if', address, 'gets back to us');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue