feature: Adds start and stop routes.

This commit is contained in:
greysoh 2024-04-27 16:34:14 -04:00
parent 5bfbf5cb05
commit 18b13d4aa3
No known key found for this signature in database
GPG key ID: FE0F173B8FC01571
6 changed files with 203 additions and 4 deletions

View file

@ -3,6 +3,10 @@ import { Socket } from "node:net";
import type { BackendBaseClass, ForwardRule, ConnectedClient, ParameterReturnedValue } from "./base.js";
type ForwardRuleExt = ForwardRule & {
enabled: boolean
}
// Fight me (for better naming)
type BackendParsedProviderString = {
ip: string,
@ -40,7 +44,7 @@ export class SSHBackendProvider implements BackendBaseClass {
state: "stopped" | "stopping" | "started" | "starting";
clients: ConnectedClient[];
proxies: ForwardRule[];
proxies: ForwardRuleExt[];
logs: string[];
sshInstance: NodeSSH;
@ -118,6 +122,7 @@ export class SSHBackendProvider implements BackendBaseClass {
await this.sshInstance.forwardIn("0.0.0.0", destPort, (info, accept, reject) => {
const foundProxyEntry = this.proxies.find((i) => i.sourceIP == sourceIP && i.sourcePort == sourcePort && i.destPort == destPort);
if (!foundProxyEntry) return reject();
if (!foundProxyEntry.enabled) return reject();
const client: ConnectedClient = {
ip: info.srcIP,
@ -161,7 +166,9 @@ export class SSHBackendProvider implements BackendBaseClass {
this.proxies.push({
sourceIP,
sourcePort,
destPort
destPort,
enabled: true
});
};
@ -172,8 +179,7 @@ export class SSHBackendProvider implements BackendBaseClass {
const foundProxyEntry = this.proxies.find((i) => i.sourceIP == sourceIP && i.sourcePort == sourcePort && i.destPort == destPort);
if (!foundProxyEntry) return;
const proxyIndex = this.proxies.indexOf(foundProxyEntry);
this.proxies.splice(proxyIndex, 1);
foundProxyEntry.enabled = false;
};
getAllConnections(): ConnectedClient[] {