mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
@@ -14,7 +14,6 @@ import {
|
||||
findSSHKeyById,
|
||||
removeSSHKeyById,
|
||||
updateSSHKeyById,
|
||||
execAsync,
|
||||
} from "@dokploy/builders";
|
||||
|
||||
export const sshRouter = createTRPCRouter({
|
||||
|
||||
@@ -3,30 +3,28 @@ import { z } from "zod";
|
||||
export const sshKeyCreate = z.object({
|
||||
name: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
publicKey: z.string(),
|
||||
// .refine(
|
||||
// (key) => {
|
||||
// // const rsaPubPattern = /^ssh-rsa\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
// // const ed25519PubPattern = /^ssh-ed25519\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
// // return rsaPubPattern.test(key) || ed25519PubPattern.test(key);
|
||||
// },
|
||||
// {
|
||||
// message: "Invalid public key format",
|
||||
// },
|
||||
// )
|
||||
privateKey: z.string(),
|
||||
// .refine(
|
||||
// (key) => {
|
||||
// // const rsaPrivPattern =
|
||||
// // /^-----BEGIN RSA PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END RSA PRIVATE KEY-----\s*$/;
|
||||
// // const ed25519PrivPattern =
|
||||
// // /^-----BEGIN OPENSSH PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END OPENSSH PRIVATE KEY-----\s*$/;
|
||||
// // return rsaPrivPattern.test(key) || ed25519PrivPattern.test(key);
|
||||
// },
|
||||
// {
|
||||
// message: "Invalid private key format",
|
||||
// },
|
||||
// ),
|
||||
publicKey: z.string().refine(
|
||||
(key) => {
|
||||
const rsaPubPattern = /^ssh-rsa\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
const ed25519PubPattern = /^ssh-ed25519\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
return rsaPubPattern.test(key) || ed25519PubPattern.test(key);
|
||||
},
|
||||
{
|
||||
message: "Invalid public key format",
|
||||
},
|
||||
),
|
||||
privateKey: z.string().refine(
|
||||
(key) => {
|
||||
const rsaPrivPattern =
|
||||
/^-----BEGIN RSA PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END RSA PRIVATE KEY-----\s*$/;
|
||||
const ed25519PrivPattern =
|
||||
/^-----BEGIN OPENSSH PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END OPENSSH PRIVATE KEY-----\s*$/;
|
||||
return rsaPrivPattern.test(key) || ed25519PrivPattern.test(key);
|
||||
},
|
||||
{
|
||||
message: "Invalid private key format",
|
||||
},
|
||||
),
|
||||
});
|
||||
|
||||
export const sshKeyUpdate = sshKeyCreate.pick({
|
||||
|
||||
@@ -2,7 +2,11 @@ import type http from "node:http";
|
||||
import { spawn } from "node-pty";
|
||||
import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import { findServerById, validateWebSocketRequest } from "@dokploy/builders";
|
||||
import {
|
||||
findServerById,
|
||||
readSSHKey,
|
||||
validateWebSocketRequest,
|
||||
} from "@dokploy/builders";
|
||||
import { getShell } from "./utils";
|
||||
|
||||
export const setupDockerContainerLogsWebSocketServer = (
|
||||
@@ -48,6 +52,7 @@ export const setupDockerContainerLogsWebSocketServer = (
|
||||
const server = await findServerById(serverId);
|
||||
|
||||
if (!server.sshKeyId) return;
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
const client = new Client();
|
||||
new Promise<void>((resolve, reject) => {
|
||||
client
|
||||
@@ -79,7 +84,7 @@ export const setupDockerContainerLogsWebSocketServer = (
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
privateKey: keys.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,11 @@ import type http from "node:http";
|
||||
import { spawn } from "node-pty";
|
||||
import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import { findServerById, validateWebSocketRequest } from "@dokploy/builders";
|
||||
import {
|
||||
findServerById,
|
||||
readSSHKey,
|
||||
validateWebSocketRequest,
|
||||
} from "@dokploy/builders";
|
||||
import { getShell } from "./utils";
|
||||
|
||||
export const setupDockerContainerTerminalWebSocketServer = (
|
||||
@@ -49,6 +53,7 @@ export const setupDockerContainerTerminalWebSocketServer = (
|
||||
if (!server.sshKeyId)
|
||||
throw new Error("No SSH key available for this server");
|
||||
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
const conn = new Client();
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
@@ -104,7 +109,7 @@ export const setupDockerContainerTerminalWebSocketServer = (
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
privateKey: keys.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -2,7 +2,11 @@ import { spawn } from "node:child_process";
|
||||
import type http from "node:http";
|
||||
import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import { findServerById, validateWebSocketRequest } from "@dokploy/builders";
|
||||
import {
|
||||
findServerById,
|
||||
readSSHKey,
|
||||
validateWebSocketRequest,
|
||||
} from "@dokploy/builders";
|
||||
|
||||
export const setupDeploymentLogsWebSocketServer = (
|
||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
||||
@@ -47,6 +51,7 @@ export const setupDeploymentLogsWebSocketServer = (
|
||||
const server = await findServerById(serverId);
|
||||
|
||||
if (!server.sshKeyId) return;
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
const client = new Client();
|
||||
new Promise<void>((resolve, reject) => {
|
||||
client
|
||||
@@ -78,7 +83,7 @@ export const setupDeploymentLogsWebSocketServer = (
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
privateKey: keys.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user