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() { + 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 }); }