some fixes

This commit is contained in:
OfficialDakari 2024-04-30 11:28:45 +05:00
parent 056f7eef54
commit 2036c3be62
1 changed files with 52 additions and 72 deletions

View File

@ -32,7 +32,7 @@ tun.on('data', (buff) => {
const user = Object.values(config.users).find(x => x.addr == p.destinationIp); const user = Object.values(config.users).find(x => x.addr == p.destinationIp);
//(user); //(user);
if (!user) return; if (!user) return;
const targetIp = Object.entries(conns).find(x => x[1] == user.username)[0]; const targetIp = ips[user.username];
const targetPort = ports[user.username]; const targetPort = ports[user.username];
//(targetIp, targetPort); //(targetIp, targetPort);
if (!targetIp || !targetPort) return; if (!targetIp || !targetPort) return;
@ -45,40 +45,21 @@ sock.on('listening', () => {
}); });
sock.on('message', (msg, info) => { sock.on('message', (msg, info) => {
if (!conns[info.address]) { var dec;
for (const uname in config.users) { var uname;
const u = config.users[uname]; var acc;
const dec = decrypt(msg, u.key, config.iv, config.algorithm); for (const un in config.users) {
if (dec.length == 2 && dec[0] == 0x13 && dec[1] == 0x37) { const u = config.users[un];
conns[info.address] = uname; dec = decrypt(msg, u.key, config.iv, config.algorithm);
if (dec.length != 0) {
uname = un;
acc = u;
break;
}
}
ips[uname] = info.address; ips[uname] = info.address;
const spl = u.addr.split('.').map(s => parseInt(s));
const buff = Buffer.from([
0x13,
0xb4,
0x37,
...spl
]);
const enc = encrypt(buff, u.key, config.iv, config.algorithm);
sock.send(enc, info.port, info.address);
return;
}
}
const buff = Buffer.from([
0xe7,
0x5a,
0x3d,
0xed
]);
const enc = encrypt(buff, config.globalKey, config.iv, config.algorithm);
sock.send(enc, info.port, info.address);
return;
} else {
const uname = conns[info.address];
ports[uname] = info.port; ports[uname] = info.port;
ips[uname] = info.address; //const dec = decrypt(msg, acc.key, config.iv, config.algorithm);
const acc = config.users[uname];
const dec = decrypt(msg, acc.key, config.iv, config.algorithm);
//(dec); //(dec);
if (dec.length == 0) { if (dec.length == 0) {
console.error(`Empty or malformed packet from ${uname}`); console.error(`Empty or malformed packet from ${uname}`);
@ -120,11 +101,10 @@ sock.on('message', (msg, info) => {
} }
const user = Object.values(config.users).find(x => x.addr == packet.destinationIp); const user = Object.values(config.users).find(x => x.addr == packet.destinationIp);
if (!user) return; if (!user) return;
const targetIp = conns[user.username]; const targetIp = ips[user.username];
const targetPort = ports[user.username]; const targetPort = ports[user.username];
if (!targetIp || !targetPort) return; if (!targetIp || !targetPort) return;
sock.send(encrypt(dec, user.key, config.iv, config.algorithm), targetPort, targetIp); sock.send(encrypt(dec, user.key, config.iv, config.algorithm), targetPort, targetIp);
}
}); });
sock.bind(config.port); sock.bind(config.port);