From 44f725652eba11cdce086fa422f1a2ac3f1dc70f Mon Sep 17 00:00:00 2001 From: zelfroster Date: Fri, 9 Jun 2023 23:38:06 +0530 Subject: [PATCH] fix: fixed NAT mode not working --- webui-src/app/config/config_network.js | 71 +++++++++++++------------- webui-src/app/config/config_util.js | 8 +++ 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/webui-src/app/config/config_network.js b/webui-src/app/config/config_network.js index 2ee2834..49ca2fd 100644 --- a/webui-src/app/config/config_network.js +++ b/webui-src/app/config/config_network.js @@ -99,17 +99,22 @@ const SetNwMode = () => { }; }; -const NATmodes = ['Automatic (UPnP)', 'FireWalled', 'Manually Forwarded Port']; const SetNAT = () => { let sslId; - let selectedMode = NATmodes[0]; + let netMode; return { oninit: () => { - rs.rsJsonApiRequest('/rsIdentity/GetOwnSignedIds').then((res) => { + rs.rsJsonApiRequest('/rsAccounts/getCurrentAccountId').then((res) => { if (res.body.retval) { - sslId = res.body.ids[0]; - console.log(res, sslId); + sslId = res.body.id; + rs.rsJsonApiRequest('/rsPeers/getPeerDetails', { + sslId, + }).then((res) => { + if (res.body.retval) { + netMode = res.body.det.netMode; + } + }); } }); }, @@ -118,20 +123,20 @@ const SetNAT = () => { m( 'select', { - value: selectedMode, - onchange: (e) => { - selectedMode = NATmodes[e.target.selectedIndex]; - // console.log(selectedMode, e.target.selectedIndex); - if (e.target.selectedIndex === 0) { - // Automatic (UPnP) - } else if (e.target.selectedIndex === 1) { - // FireWalled - } else if (e.target.selectedIndex === 2) { - // Manually Forwarded Port - } + value: netMode, + oninput: (e) => (netMode = e.target.value), + onchange: () => { + rs.rsJsonApiRequest('/rsPeers/setNetworkMode', { + sslId, + netMode, + }); }, }, - [NATmodes.map((o) => m('option', { value: o }, o))] + [ + m('option', { value: util.RS_NETMODE_UPNP }, 'Automatic (UPnP)'), + m('option', { value: util.RS_NETMODE_UDP }, 'FireWalled'), + m('option', { value: util.RS_NETMODE_EXT }, 'Manually Forwarded Port'), + ] ), ], }; @@ -286,20 +291,24 @@ const SetSocksProxy = () => { tor: {}, i2p: {}, }; + const fetchOutgoing = () => { + Object.keys(socksProxyObj).forEach((proxyItem) => { + fetch(`http://${socksProxyObj[proxyItem].addr}:${socksProxyObj[proxyItem].port}`) + .then(() => { + socksProxyObj[proxyItem].outgoing = true; + m.redraw(); + }) + .catch(() => { + socksProxyObj[proxyItem].outgoing = false; + }); + }); + }; const handleProxyChange = (proxyItem) => { rs.rsJsonApiRequest('/rsPeers/setProxyServer', { type: util[`RS_HIDDEN_TYPE_${proxyItem.toUpperCase()}`], addr: socksProxyObj[proxyItem].addr, port: socksProxyObj[proxyItem].port, - }).then(() => - fetch(`http://${socksProxyObj[proxyItem].addr}:${socksProxyObj[proxyItem].port}`) - .then(() => { - socksProxyObj[proxyItem].outgoing = true; - }) - .catch(() => { - socksProxyObj[proxyItem].outgoing = false; - }) - ); + }).then(fetchOutgoing); }; return { oninit: () => { @@ -312,15 +321,7 @@ const SetSocksProxy = () => { socksProxyObj[proxyItem] = res.body; } }) - .then(() => - fetch(`http://${socksProxyObj[proxyItem].addr}:${socksProxyObj[proxyItem].port}`) - .then(() => { - socksProxyObj[proxyItem].outgoing = true; - }) - .catch(() => { - socksProxyObj[proxyItem].outgoing = false; - }) - ); + .then(fetchOutgoing); }); }, view: () => diff --git a/webui-src/app/config/config_util.js b/webui-src/app/config/config_util.js index 841745f..5e39f54 100644 --- a/webui-src/app/config/config_util.js +++ b/webui-src/app/config/config_util.js @@ -24,6 +24,11 @@ const RS_HIDDEN_TYPE_UNKNOWN = 1; const RS_HIDDEN_TYPE_TOR = 2; const RS_HIDDEN_TYPE_I2P = 4; +/* NAT Net Mode */ +const RS_NETMODE_UDP = 1; +const RS_NETMODE_UPNP = 2; +const RS_NETMODE_EXT = 3; + function getRandomId(tagArr) { const random = Math.floor(Math.random() * (MAX_TAG_ID_VAL - MIN_TAG_ID_VAL) + MIN_TAG_ID_VAL); tagArr.forEach((tag) => { @@ -54,4 +59,7 @@ module.exports = { RS_HIDDEN_TYPE_UNKNOWN, RS_HIDDEN_TYPE_TOR, RS_HIDDEN_TYPE_I2P, + RS_NETMODE_UDP, + RS_NETMODE_UPNP, + RS_NETMODE_EXT, };