chore: Add support for manually specifying the IP address to listen on.
This commit is contained in:
parent
758c92ded8
commit
3b55ce1207
1 changed files with 74 additions and 52 deletions
|
@ -8,6 +8,13 @@ import type {
|
|||
ParameterReturnedValue,
|
||||
} from "./base.js";
|
||||
|
||||
import {
|
||||
TcpConnectionDetails,
|
||||
AcceptConnection,
|
||||
ClientChannel,
|
||||
RejectConnection,
|
||||
} from "ssh2";
|
||||
|
||||
type ForwardRuleExt = ForwardRule & {
|
||||
enabled: boolean;
|
||||
};
|
||||
|
@ -19,6 +26,8 @@ type BackendParsedProviderString = {
|
|||
|
||||
username: string;
|
||||
privateKey: string;
|
||||
|
||||
listenOnIPs: string[];
|
||||
};
|
||||
|
||||
function parseBackendProviderString(data: string): BackendParsedProviderString {
|
||||
|
@ -46,12 +55,22 @@ function parseBackendProviderString(data: string): BackendParsedProviderString {
|
|||
throw new Error("Private key is not a string");
|
||||
}
|
||||
|
||||
let listenOnIPs: string[] = [];
|
||||
|
||||
if (!Array.isArray(jsonData.listenOnIPs)) {
|
||||
listenOnIPs.push("0.0.0.0");
|
||||
} else {
|
||||
listenOnIPs = jsonData.listenOnIPs;
|
||||
}
|
||||
|
||||
return {
|
||||
ip: jsonData.ip,
|
||||
port: jsonData.port,
|
||||
|
||||
username: jsonData.username,
|
||||
privateKey: jsonData.privateKey,
|
||||
|
||||
listenOnIPs,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -121,6 +140,7 @@ export class SSHBackendProvider implements BackendBaseClass {
|
|||
|
||||
for (const proxy of proxies) {
|
||||
if (!proxy.enabled) continue;
|
||||
|
||||
this.addConnection(
|
||||
proxy.sourceIP,
|
||||
proxy.sourcePort,
|
||||
|
@ -178,11 +198,11 @@ export class SSHBackendProvider implements BackendBaseClass {
|
|||
|
||||
if (foundProxyEntry) return;
|
||||
|
||||
(async () => {
|
||||
await this.sshInstance.forwardIn(
|
||||
"0.0.0.0",
|
||||
destPort,
|
||||
(info, accept, reject) => {
|
||||
const connCallback = (
|
||||
info: TcpConnectionDetails,
|
||||
accept: AcceptConnection<ClientChannel>,
|
||||
reject: RejectConnection,
|
||||
) => {
|
||||
const foundProxyEntry = this.proxies.find(
|
||||
i =>
|
||||
i.sourceIP == sourceIP &&
|
||||
|
@ -228,9 +248,11 @@ export class SSHBackendProvider implements BackendBaseClass {
|
|||
this.clients.splice(this.clients.indexOf(client), 1);
|
||||
destConn.end();
|
||||
});
|
||||
},
|
||||
);
|
||||
})();
|
||||
};
|
||||
|
||||
for (const ip of this.options.listenOnIPs) {
|
||||
this.sshInstance.forwardIn(ip, destPort, connCallback);
|
||||
}
|
||||
|
||||
this.proxies.push({
|
||||
sourceIP,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue