mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 15:02:34 +00:00
#591 - server-ssh-keys
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
export default function HeaderContainer({ children }: { children: ReactNode }) {
|
||||
return <div className="flex items-center justify-between">{children}</div>;
|
||||
return <div className="flex items-start justify-between gap-2">{children}</div>;
|
||||
}
|
||||
|
@ -20,9 +20,12 @@ export default function LogOutput({ children }: { children: ReactNode }) {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<ScrollArea ref={scrollRef} className="bg-accent/50 text-accent-foreground relative h-[500px] w-full p-4 font-mono text-sm whitespace-pre-line">
|
||||
{children}
|
||||
<div className="relative w-full">
|
||||
<ScrollArea
|
||||
ref={scrollRef}
|
||||
className="bg-accent/50 text-accent-foreground relative h-[500px] w-full overflow-auto p-4 font-mono text-sm break-all whitespace-pre-wrap"
|
||||
>
|
||||
<div>{children}</div>
|
||||
<div ref={endRef} />
|
||||
<ScrollBar orientation="vertical" />
|
||||
</ScrollArea>
|
||||
@ -37,7 +40,7 @@ export default function LogOutput({ children }: { children: ReactNode }) {
|
||||
<TooltipTrigger asChild>
|
||||
<div>{autoScroll ? <ClockArrowDownIcon className="h-4 w-4" /> : <ArrowDown className="h-4 w-4" />}</div>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{autoScroll ? 'Turn off auto scroll' : 'Auto scroll down'}</TooltipContent>
|
||||
<TooltipContent side="left">{autoScroll ? 'Turn off auto scroll' : 'Auto scroll down'}</TooltipContent>
|
||||
</Tooltip>
|
||||
</Button>
|
||||
</div>
|
||||
|
@ -40,7 +40,7 @@ function DialogContent({ className, children, ...props }: React.ComponentProps<t
|
||||
<DialogPrimitive.Content
|
||||
data-slot="dialog-content"
|
||||
className={cn(
|
||||
'bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] rounded-lg border shadow-lg duration-200 sm:max-w-lg',
|
||||
'bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] overflow-x-hidden rounded-lg border shadow-lg duration-200 sm:max-w-lg',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
|
@ -6,6 +6,7 @@ import {
|
||||
DatabaseIcon,
|
||||
FlameIcon,
|
||||
HomeIcon,
|
||||
KeyIcon,
|
||||
ListEndIcon,
|
||||
MousePointerClickIcon,
|
||||
RocketIcon,
|
||||
@ -103,11 +104,12 @@ export default function ServerLayout({ children }: { children: ReactNode }) {
|
||||
icon: ListEndIcon,
|
||||
isDisabled: isMenuDisabled,
|
||||
},
|
||||
// {
|
||||
// title: 'SSH Keys',
|
||||
// href: '#',
|
||||
// icon: KeyIcon,
|
||||
// },
|
||||
{
|
||||
title: 'SSH Keys',
|
||||
href: route('server-ssh-keys', { server: page.props.server.id }),
|
||||
icon: KeyIcon,
|
||||
isDisabled: isMenuDisabled,
|
||||
},
|
||||
// {
|
||||
// title: 'Services',
|
||||
// href: '#',
|
||||
|
@ -5,7 +5,7 @@ import ServerLayout from '@/layouts/server/layout';
|
||||
import HeaderContainer from '@/components/header-container';
|
||||
import Heading from '@/components/heading';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { PlusIcon } from 'lucide-react';
|
||||
import { BookOpenIcon, PlusIcon } from 'lucide-react';
|
||||
import Container from '@/components/container';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { CronJob } from '@/types/cronjob';
|
||||
@ -26,6 +26,12 @@ export default function CronJobIndex() {
|
||||
<HeaderContainer>
|
||||
<Heading title="Cron jobs" description="Here you can manage server's cron jobs" />
|
||||
<div className="flex items-center gap-2">
|
||||
<a href="https://vitodeploy.com/docs/servers/cronjobs" target="_blank">
|
||||
<Button variant="outline">
|
||||
<BookOpenIcon />
|
||||
<span className="hidden lg:block">Docs</span>
|
||||
</Button>
|
||||
</a>
|
||||
<CronJobForm serverId={page.props.server.id}>
|
||||
<Button>
|
||||
<PlusIcon />
|
||||
|
@ -6,7 +6,7 @@ import ServerLayout from '@/layouts/server/layout';
|
||||
import HeaderContainer from '@/components/header-container';
|
||||
import Heading from '@/components/heading';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { PlusIcon } from 'lucide-react';
|
||||
import { BookOpenIcon, PlusIcon } from 'lucide-react';
|
||||
import Container from '@/components/container';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { columns } from '@/pages/firewall/components/columns';
|
||||
@ -26,6 +26,12 @@ export default function Firewall() {
|
||||
<HeaderContainer>
|
||||
<Heading title="Firewall" description="Here you can manage server's firewall rules" />
|
||||
<div className="flex items-center gap-2">
|
||||
<a href="https://vitodeploy.com/docs/servers/firewall" target="_blank">
|
||||
<Button variant="outline">
|
||||
<BookOpenIcon />
|
||||
<span className="hidden lg:block">Docs</span>
|
||||
</Button>
|
||||
</a>
|
||||
<RuleForm serverId={page.props.server.id}>
|
||||
<Button>
|
||||
<PlusIcon />
|
||||
|
125
resources/js/pages/server-ssh-keys/components/columns.tsx
Normal file
125
resources/js/pages/server-ssh-keys/components/columns.tsx
Normal file
@ -0,0 +1,125 @@
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import DateTime from '@/components/date-time';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useForm, usePage } from '@inertiajs/react';
|
||||
import { LoaderCircleIcon, MoreVerticalIcon } from 'lucide-react';
|
||||
import FormSuccessful from '@/components/form-successful';
|
||||
import { useState } from 'react';
|
||||
import { SshKey } from '@/types/ssh-key';
|
||||
import { Server } from '@/types/server';
|
||||
|
||||
function Delete({ sshKey }: { sshKey: SshKey }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const form = useForm();
|
||||
const page = usePage<{
|
||||
server: Server;
|
||||
}>();
|
||||
|
||||
const submit = () => {
|
||||
form.delete(
|
||||
route('server-ssh-keys.destroy', {
|
||||
server: page.props.server.id,
|
||||
sshKey: sshKey.id,
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
},
|
||||
},
|
||||
);
|
||||
};
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<DropdownMenuItem variant="destructive" onSelect={(e) => e.preventDefault()}>
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
Delete {sshKey.name} from {page.props.server.name}
|
||||
</DialogTitle>
|
||||
<DialogDescription className="sr-only">Delete ssh key</DialogDescription>
|
||||
</DialogHeader>
|
||||
<p className="p-4">
|
||||
Are you sure you want to delete this key from <b>{page.props.server.name}</b>?
|
||||
</p>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button variant="destructive" disabled={form.processing} onClick={submit}>
|
||||
{form.processing && <LoaderCircleIcon className="animate-spin" />}
|
||||
<FormSuccessful successful={form.recentlySuccessful} />
|
||||
Delete
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export const columns: ColumnDef<SshKey>[] = [
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: 'Name',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: 'user',
|
||||
header: 'User',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<span>
|
||||
{row.original.user?.name} ({row.original.user?.email})
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'created_at',
|
||||
header: 'Created at',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return <DateTime date={row.original.created_at} />;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
enableColumnFilter: false,
|
||||
enableSorting: false,
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<div className="flex items-center justify-end">
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreVerticalIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<Delete sshKey={row.original} />
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
75
resources/js/pages/server-ssh-keys/components/deploy-key.tsx
Normal file
75
resources/js/pages/server-ssh-keys/components/deploy-key.tsx
Normal file
@ -0,0 +1,75 @@
|
||||
import { LoaderCircle } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { useForm, usePage } from '@inertiajs/react';
|
||||
import { FormEventHandler, ReactNode, useState } from 'react';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { Server } from '@/types/server';
|
||||
import SshKeySelect from '@/pages/ssh-keys/components/ssh-key-select';
|
||||
|
||||
export default function DeployKey({ children }: { children: ReactNode }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const page = usePage<{
|
||||
server: Server;
|
||||
}>();
|
||||
|
||||
const form = useForm<
|
||||
Required<{
|
||||
key: string;
|
||||
}>
|
||||
>({
|
||||
key: '',
|
||||
});
|
||||
|
||||
const submit: FormEventHandler = (e) => {
|
||||
e.preventDefault();
|
||||
form.post(route('server-ssh-keys.store', { server: page.props.server.id }), {
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>{children}</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Deploy ssh key</DialogTitle>
|
||||
<DialogDescription className="sr-only">Deploy ssh key</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form id="deploy-ssh-key-form" onSubmit={submit} className="p-4">
|
||||
<FormFields>
|
||||
<FormField>
|
||||
<Label htmlFor="name">Key</Label>
|
||||
<SshKeySelect value={form.data.key} onValueChange={(value) => form.setData('key', value)} />
|
||||
<InputError message={form.errors.key} />
|
||||
</FormField>
|
||||
</FormFields>
|
||||
</Form>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button type="button" variant="outline">
|
||||
Cancel
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<Button form="deploy-ssh-key-form" onClick={submit} disabled={form.processing}>
|
||||
{form.processing && <LoaderCircle className="animate-spin" />}
|
||||
Deploy
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
47
resources/js/pages/server-ssh-keys/index.tsx
Normal file
47
resources/js/pages/server-ssh-keys/index.tsx
Normal file
@ -0,0 +1,47 @@
|
||||
import { Head, usePage } from '@inertiajs/react';
|
||||
import Container from '@/components/container';
|
||||
import Heading from '@/components/heading';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { SshKey } from '@/types/ssh-key';
|
||||
import { columns } from '@/pages/server-ssh-keys/components/columns';
|
||||
import { PaginatedData } from '@/types';
|
||||
import DeployKey from '@/pages/server-ssh-keys/components/deploy-key';
|
||||
import ServerLayout from '@/layouts/server/layout';
|
||||
import HeaderContainer from '@/components/header-container';
|
||||
import { BookOpenIcon, RocketIcon } from 'lucide-react';
|
||||
|
||||
type Page = {
|
||||
sshKeys: PaginatedData<SshKey>;
|
||||
};
|
||||
|
||||
export default function SshKeys() {
|
||||
const page = usePage<Page>();
|
||||
|
||||
return (
|
||||
<ServerLayout>
|
||||
<Head title="SSH Keys" />
|
||||
<Container className="max-w-5xl">
|
||||
<HeaderContainer>
|
||||
<Heading title="SSH Keys" description="Here you can manage the ssh keys deployed to the server" />
|
||||
<div className="flex items-center gap-2">
|
||||
<a href="https://vitodeploy.com/docs/servers/ssh-keys" target="_blank">
|
||||
<Button variant="outline">
|
||||
<BookOpenIcon />
|
||||
<span className="hidden lg:block">Docs</span>
|
||||
</Button>
|
||||
</a>
|
||||
<DeployKey>
|
||||
<Button>
|
||||
<RocketIcon />
|
||||
Deploy key
|
||||
</Button>
|
||||
</DeployKey>
|
||||
</div>
|
||||
</HeaderContainer>
|
||||
|
||||
<DataTable columns={columns} paginatedData={page.props.sshKeys} />
|
||||
</Container>
|
||||
</ServerLayout>
|
||||
);
|
||||
}
|
@ -23,7 +23,7 @@ type SshKeyForm = {
|
||||
public_key: string;
|
||||
};
|
||||
|
||||
export default function AddSshKey({ children }: { children: ReactNode }) {
|
||||
export default function AddSshKey({ children, onKeyAdded }: { children: ReactNode; onKeyAdded?: () => void }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const form = useForm<Required<SshKeyForm>>({
|
||||
@ -36,6 +36,9 @@ export default function AddSshKey({ children }: { children: ReactNode }) {
|
||||
form.post(route('ssh-keys.store'), {
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
if (onKeyAdded) {
|
||||
onKeyAdded();
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
@ -16,9 +16,9 @@ import { useForm } from '@inertiajs/react';
|
||||
import { LoaderCircleIcon, MoreVerticalIcon } from 'lucide-react';
|
||||
import FormSuccessful from '@/components/form-successful';
|
||||
import { useState } from 'react';
|
||||
import { SSHKey } from '@/types/ssh-key';
|
||||
import { SshKey } from '@/types/ssh-key';
|
||||
|
||||
function Delete({ sshKey }: { sshKey: SSHKey }) {
|
||||
function Delete({ sshKey }: { sshKey: SshKey }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const form = useForm();
|
||||
|
||||
@ -57,7 +57,7 @@ function Delete({ sshKey }: { sshKey: SSHKey }) {
|
||||
);
|
||||
}
|
||||
|
||||
export const columns: ColumnDef<SSHKey>[] = [
|
||||
export const columns: ColumnDef<SshKey>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
|
50
resources/js/pages/ssh-keys/components/ssh-key-select.tsx
Normal file
50
resources/js/pages/ssh-keys/components/ssh-key-select.tsx
Normal file
@ -0,0 +1,50 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import axios from 'axios';
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import React from 'react';
|
||||
import { SelectTriggerProps } from '@radix-ui/react-select';
|
||||
import { SshKey } from '@/types/ssh-key';
|
||||
import AddSshKey from '@/pages/ssh-keys/components/add-ssh-key';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { PlusIcon } from 'lucide-react';
|
||||
|
||||
export default function SshKeySelect({
|
||||
value,
|
||||
onValueChange,
|
||||
...props
|
||||
}: {
|
||||
value: string;
|
||||
onValueChange: (value: string) => void;
|
||||
} & SelectTriggerProps) {
|
||||
const query = useQuery<SshKey[]>({
|
||||
queryKey: ['sshKey'],
|
||||
queryFn: async () => {
|
||||
return (await axios.get(route('ssh-keys.json'))).data;
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<Select value={value} onValueChange={onValueChange} disabled={query.isFetching}>
|
||||
<SelectTrigger {...props}>
|
||||
<SelectValue placeholder={query.isFetching ? 'Loading...' : 'Select a key'} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
{query.isSuccess &&
|
||||
query.data.map((sshKey: SshKey) => (
|
||||
<SelectItem key={`db-${sshKey.name}`} value={sshKey.id.toString()}>
|
||||
{sshKey.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<AddSshKey onKeyAdded={() => query.refetch()}>
|
||||
<Button variant="outline">
|
||||
<PlusIcon />
|
||||
</Button>
|
||||
</AddSshKey>
|
||||
</div>
|
||||
);
|
||||
}
|
@ -4,13 +4,13 @@ import Container from '@/components/container';
|
||||
import Heading from '@/components/heading';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { SSHKey } from '@/types/ssh-key';
|
||||
import { SshKey } from '@/types/ssh-key';
|
||||
import { columns } from '@/pages/ssh-keys/components/columns';
|
||||
import AddSshKey from '@/pages/ssh-keys/components/add-ssh-key';
|
||||
import { PaginatedData } from '@/types';
|
||||
|
||||
type Page = {
|
||||
sshKeys: PaginatedData<SSHKey>;
|
||||
sshKeys: PaginatedData<SshKey>;
|
||||
};
|
||||
|
||||
export default function SshKeys() {
|
||||
|
@ -5,7 +5,7 @@ import ServerLayout from '@/layouts/server/layout';
|
||||
import HeaderContainer from '@/components/header-container';
|
||||
import Heading from '@/components/heading';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { PlusIcon } from 'lucide-react';
|
||||
import { BookOpenIcon, PlusIcon } from 'lucide-react';
|
||||
import Container from '@/components/container';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { Worker } from '@/types/worker';
|
||||
@ -26,6 +26,12 @@ export default function WorkerIndex() {
|
||||
<HeaderContainer>
|
||||
<Heading title="Workers" description="Here you can manage server's workers" />
|
||||
<div className="flex items-center gap-2">
|
||||
<a href="https://vitodeploy.com/docs/servers/workers" target="_blank">
|
||||
<Button variant="outline">
|
||||
<BookOpenIcon />
|
||||
<span className="hidden lg:block">Docs</span>
|
||||
</Button>
|
||||
</a>
|
||||
<WorkerForm serverId={page.props.server.id}>
|
||||
<Button>
|
||||
<PlusIcon />
|
||||
|
2
resources/js/types/ssh-key.d.ts
vendored
2
resources/js/types/ssh-key.d.ts
vendored
@ -1,6 +1,6 @@
|
||||
import { User } from '@/types/user';
|
||||
|
||||
export interface SSHKey {
|
||||
export interface SshKey {
|
||||
id: number;
|
||||
user?: User;
|
||||
name: string;
|
||||
|
Reference in New Issue
Block a user