mirror of
https://github.com/netbirdio/dashboard.git
synced 2026-01-26 01:21:04 +00:00
Increase ssh detection timeout (#512)
This commit is contained in:
@@ -108,6 +108,7 @@ function SSHTerminal({ username, port, peer }: Props) {
|
|||||||
if (!peer.id) return;
|
if (!peer.id) return;
|
||||||
if (connected.current) return;
|
if (connected.current) return;
|
||||||
connected.current = true;
|
connected.current = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const aclPort = isNativeSSHSupported(peer.version) ? "22022" : port;
|
const aclPort = isNativeSSHSupported(peer.version) ? "22022" : port;
|
||||||
const rules = [`tcp/${aclPort}`];
|
const rules = [`tcp/${aclPort}`];
|
||||||
@@ -121,7 +122,7 @@ function SSHTerminal({ username, port, peer }: Props) {
|
|||||||
sshConnectedOnce.current = true;
|
sshConnectedOnce.current = true;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Connection failed:", error);
|
console.error("Connection error:", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ export enum SSHStatus {
|
|||||||
export const SSH_DOCS_LINK =
|
export const SSH_DOCS_LINK =
|
||||||
"https://docs.netbird.io/how-to/browser-client#ssh-connection";
|
"https://docs.netbird.io/how-to/browser-client#ssh-connection";
|
||||||
|
|
||||||
|
const SSH_DETECTION_TIMEOUT_MS = 20000;
|
||||||
|
|
||||||
export const useSSH = (client: any) => {
|
export const useSSH = (client: any) => {
|
||||||
const [status, setStatus] = useState(SSHStatus.DISCONNECTED);
|
const [status, setStatus] = useState(SSHStatus.DISCONNECTED);
|
||||||
const [config, setConfig] = useState<SSHConfig | null>(null);
|
const [config, setConfig] = useState<SSHConfig | null>(null);
|
||||||
@@ -38,12 +40,31 @@ export const useSSH = (client: any) => {
|
|||||||
|
|
||||||
setStatus(SSHStatus.CONNECTING);
|
setStatus(SSHStatus.CONNECTING);
|
||||||
setConfig(config);
|
setConfig(config);
|
||||||
|
setError("");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const requiresJwt = await client.detectSSHServerType(
|
let requiresJwt = false;
|
||||||
config.hostname,
|
try {
|
||||||
config.port,
|
requiresJwt = await client.detectSSHServerType(
|
||||||
);
|
config.hostname,
|
||||||
|
config.port,
|
||||||
|
SSH_DETECTION_TIMEOUT_MS,
|
||||||
|
);
|
||||||
|
console.log("Detection:", { requiresJwt, hasToken: !!accessToken });
|
||||||
|
} catch (detectionErr) {
|
||||||
|
console.error(
|
||||||
|
"Detection failed, falling back to pubkey:",
|
||||||
|
detectionErr,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requiresJwt && !accessToken) {
|
||||||
|
console.error("No access token available");
|
||||||
|
setError("No access token available");
|
||||||
|
setStatus(SSHStatus.DISCONNECTED);
|
||||||
|
setConfig(null);
|
||||||
|
return SSHStatus.DISCONNECTED;
|
||||||
|
}
|
||||||
|
|
||||||
const ssh = await client.createSSHConnection(
|
const ssh = await client.createSSHConnection(
|
||||||
config.hostname,
|
config.hostname,
|
||||||
@@ -63,7 +84,7 @@ export const useSSH = (client: any) => {
|
|||||||
setStatus(SSHStatus.CONNECTED);
|
setStatus(SSHStatus.CONNECTED);
|
||||||
return SSHStatus.CONNECTED;
|
return SSHStatus.CONNECTED;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("SSH connection failed:", err);
|
console.error("Connection failed:", err);
|
||||||
session.current = null;
|
session.current = null;
|
||||||
setStatus(SSHStatus.DISCONNECTED);
|
setStatus(SSHStatus.DISCONNECTED);
|
||||||
setError("SSH connection failed. Check the console for details.");
|
setError("SSH connection failed. Check the console for details.");
|
||||||
|
|||||||
@@ -209,11 +209,11 @@ export const useNetBirdClient = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const detectSSHServerType = useCallback(
|
const detectSSHServerType = useCallback(
|
||||||
async (host: string, port: number): Promise<boolean> => {
|
async (host: string, port: number, timeoutMs: number): Promise<boolean> => {
|
||||||
if (!netBirdClient.current?.detectSSHServerType) {
|
if (!netBirdClient.current?.detectSSHServerType) {
|
||||||
throw new Error("NetBird client not ready");
|
throw new Error("NetBird client not ready");
|
||||||
}
|
}
|
||||||
return netBirdClient.current.detectSSHServerType(host, port);
|
return netBirdClient.current.detectSSHServerType(host, port, timeoutMs);
|
||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
@@ -228,7 +228,12 @@ export const useNetBirdClient = () => {
|
|||||||
if (!netBirdClient.current?.createSSHConnection) {
|
if (!netBirdClient.current?.createSSHConnection) {
|
||||||
throw new Error("Go client not ready");
|
throw new Error("Go client not ready");
|
||||||
}
|
}
|
||||||
return netBirdClient.current.createSSHConnection(host, port, username);
|
return netBirdClient.current.createSSHConnection(
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
username,
|
||||||
|
jwtToken,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ const loadConfig = (): Config => {
|
|||||||
googleAnalyticsID: configJson?.googleAnalyticsID || undefined,
|
googleAnalyticsID: configJson?.googleAnalyticsID || undefined,
|
||||||
googleTagManagerID: configJson?.googleTagManagerID || undefined,
|
googleTagManagerID: configJson?.googleTagManagerID || undefined,
|
||||||
wasmPath:
|
wasmPath:
|
||||||
configJson?.wasmPath || "https://pkgs.netbird.io/wasm/client/v0.60.0",
|
configJson?.wasmPath || "https://pkgs.netbird.io/wasm/client/v0.60.2",
|
||||||
} as Config;
|
} as Config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user