diff --git a/src/components/pages/admin/users/deployment-user/(partials)/download-private-ssh-key.tsx b/src/components/pages/admin/users/deployment-user/(partials)/download-private-ssh-key.tsx
index d9c2f36..a7ad791 100644
--- a/src/components/pages/admin/users/deployment-user/(partials)/download-private-ssh-key.tsx
+++ b/src/components/pages/admin/users/deployment-user/(partials)/download-private-ssh-key.tsx
@@ -5,7 +5,7 @@ import LucideIcon from "@/twui/components/elements/lucide-icon";
import useStatus from "@/twui/components/hooks/useStatus";
import downloadFile from "@/src/utils/download-file";
-export default function DownloadPrivateSSHKey() {
+export default function DownloadPrivateSSHKeyButton() {
const { pageProps } = useContext(AppContext);
const { deployment_user, deployment } = pageProps;
@@ -21,7 +21,7 @@ export default function DownloadPrivateSSHKey() {
}
+ beforeIcon={}
loading={loading}
onClick={() => {
setLoading(true);
@@ -29,7 +29,13 @@ export default function DownloadPrivateSSHKey() {
downloadFile({
file_name: `${deployment_user.username}-private-key`,
url: `/api/admin/download-private-ssh-key?user_id=${deployment_user.id}`,
- });
+ })
+ .then((res) => {})
+ .finally(() => {
+ setTimeout(() => {
+ setLoading(false);
+ }, 2000);
+ });
}}
>
Download Private Key
diff --git a/src/components/pages/admin/users/deployment-user/(sections)/ssh-connection.tsx b/src/components/pages/admin/users/deployment-user/(sections)/ssh-connection.tsx
index 77a6172..205ccf5 100644
--- a/src/components/pages/admin/users/deployment-user/(sections)/ssh-connection.tsx
+++ b/src/components/pages/admin/users/deployment-user/(sections)/ssh-connection.tsx
@@ -9,6 +9,7 @@ import TurboCICodeBlock from "@/src/components/general/code-block";
import H3 from "@/twui/components/layout/H3";
import Button from "@/twui/components/layout/Button";
import LucideIcon from "@/twui/components/elements/lucide-icon";
+import DownloadPrivateSSHKeyButton from "../(partials)/download-private-ssh-key";
export default function SSHConnection() {
const { pageProps } = useContext(AppContext);
@@ -56,15 +57,7 @@ export default function SSHConnection() {
{deployment_user.username}
-
- }
- >
- Download Private Key
-
+
diff --git a/src/functions/deployment-users/setup-deployment-user.ts b/src/functions/deployment-users/setup-deployment-user.ts
index b0da6de..0b61a01 100644
--- a/src/functions/deployment-users/setup-deployment-user.ts
+++ b/src/functions/deployment-users/setup-deployment-user.ts
@@ -73,10 +73,12 @@ export default async function setupDeploymentUser({ user_id }: Params) {
cmd += `Match User ${username}\n`;
cmd += ` PasswordAuthentication no\n`;
cmd += ` PubkeyAuthentication yes\n`;
- cmd += ` AuthenticationMethods publickey\n\n`;
+ cmd += ` AuthenticationMethods publickey\n`;
cmd += ` AllowTcpForwarding yes\n`;
- cmd += ` X11Forwarding no\n\n`;
+ cmd += ` X11Forwarding no\n`;
cmd += ` ForceCommand ${force_command_file}\n`;
+ cmd += ` PermitOpen localhost:80\n`;
+ cmd += ` PermitTTY no\n`;
cmd += `EOF\n`;
cmd += `TURBOCIHEREDOC\n`;
diff --git a/src/pages/api/admin/download-private-ssh-key.ts b/src/pages/api/admin/download-private-ssh-key.ts
index 007f442..7938361 100644
--- a/src/pages/api/admin/download-private-ssh-key.ts
+++ b/src/pages/api/admin/download-private-ssh-key.ts
@@ -1,23 +1,16 @@
-import loginUser from "@/src/functions/auth/login-user";
import { NSQLITE_TURBOCI_ADMIN_USERS } from "@/src/db/types";
import userAuth from "@/src/utils/user-auth";
import NSQLite from "@moduletrace/nsqlite";
import { APIResponseObject } from "@moduletrace/datasquirel/dist/package-shared/types";
import type { NextApiRequest, NextApiResponse } from "next";
import { APIReqObject } from "@/src/types";
+import { createReadStream, existsSync } from "fs";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
try {
- if (req.method !== "POST") {
- return res.json({
- success: false,
- msg: "Wrong Method",
- });
- }
-
const { singleRes: user } = await userAuth({ req });
if (!user?.id || !user.super_admin) {
@@ -37,9 +30,19 @@ export default async function handler(
const target_user = target_user_res.singleRes;
- const updated = await loginUser({ res, user_id: user.id });
+ if (!target_user?.username) {
+ throw new Error(`Couldn't grab user`);
+ }
- return res.json(updated);
+ const file_path = `/home/${target_user.username}/.ssh/${target_user.username}`;
+
+ if (!existsSync(file_path)) {
+ throw new Error(`No Private SSH key file found`);
+ }
+
+ const read_stream = createReadStream(file_path);
+
+ read_stream.pipe(res);
} catch (error: any) {
return res.json({ success: false, msg: error.message });
}