mirror of
https://github.com/RetroShare/RSNewWebUI.git
synced 2026-09-14 11:05:47 +05:00
fix: fixed NAT mode not working
This commit is contained in:
parent
472eb2dd41
commit
44f725652e
@ -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: () =>
|
||||
|
||||
@ -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,
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user