Updates
This commit is contained in:
parent
3663d91aa6
commit
e7414c75dd
@ -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() {
|
||||
<Button
|
||||
title="Download Private Key"
|
||||
variant="outlined"
|
||||
beforeIcon={<LucideIcon name="Download" size={20} />}
|
||||
beforeIcon={<LucideIcon name="Download" size={17} />}
|
||||
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
|
||||
|
||||
@ -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() {
|
||||
<code>{deployment_user.username}</code>
|
||||
</Span>
|
||||
</Stack>
|
||||
<Button
|
||||
title="Download Private Key"
|
||||
variant="outlined"
|
||||
beforeIcon={
|
||||
<LucideIcon name="Download" size={20} />
|
||||
}
|
||||
>
|
||||
Download Private Key
|
||||
</Button>
|
||||
<DownloadPrivateSSHKeyButton />
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Stack>
|
||||
|
||||
@ -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`;
|
||||
|
||||
|
||||
@ -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<APIResponseObject>,
|
||||
) {
|
||||
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 });
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user