Commit 39175d1f authored by inso's avatar inso
Browse files

Add LAN addresses to suggested remote ips

parent c6c6740d
......@@ -220,6 +220,10 @@ function WebAdmin (dbConf, overConf) {
name: 'conf',
addresses: []
};
let lan = {
name: 'lan',
addresses: []
};
yield pluggedConfP;
let conf = server.conf;
if (conf.remoteipv4) {
......@@ -246,10 +250,24 @@ function WebAdmin (dbConf, overConf) {
} catch (e) {
logger.error(e.stack || e);
}
let lanIPv4 = network.getLANIPv4();
lanIPv4.forEach(function(addr) {
lan.addresses.push({
family: 'IPv4',
address: addr.value
});
});
let lanIPv6 = network.getLANIPv6();
lanIPv6.forEach(function(addr) {
lan.addresses.push({
family: 'IPv6',
address: addr.value
});
});
let randomPort = network.getRandomPort();
return {
local: network.listInterfaces(),
remote: [upnp, manual],
remote: [upnp, manual, lan],
auto: {
local: {
ipv4: network.getBestLocalIPv4(),
......
......@@ -19,6 +19,8 @@ module.exports = {
getBestLocalIPv4: () => getBestLocal('IPv4'),
getBestLocalIPv6: () => getBestLocal('IPv6'),
getLANIPv4: () => getLAN('IPv4'),
getLANIPv6: () => getLAN('IPv6'),
listInterfaces: () => {
let netInterfaces = os.networkInterfaces();
......@@ -264,3 +266,27 @@ function getBestLocal(family) {
return 10;
})[0].value;
}
function getLAN(family) {
let netInterfaces = os.networkInterfaces();
let keys = _.keys(netInterfaces);
let res = [];
for (let i = 0, len = keys.length; i < len; i++) {
let name = keys[i];
let addresses = netInterfaces[name];
for (let j = 0, len2 = addresses.length; j < len2; j++) {
let addr = addresses[j];
if ((addr.family == "IPv4" && family == "IPv4"
&& addr.address != "127.0.0.1" && addr.address != "lo" && addr.address != "localhost")
|| (addr.family == "IPv6" && family == "IPv6"
&& addr.address != "::1" && addr.address != "lo" && addr.address != "localhost"))
{
res.push({
name: name,
value: addr.address
});
}
}
}
return res;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment