feat: support probe shell generation

This commit is contained in:
ReaJason
2025-08-13 23:53:40 +08:00
parent 3102f10d7b
commit 4a3bc0c40a
304 changed files with 59084 additions and 1454 deletions
+20
View File
@@ -0,0 +1,20 @@
import { InfoIcon } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip.tsx";
export function JreTip() {
const { t } = useTranslation();
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<InfoIcon className="cursor-pointer h-4" />
</TooltipTrigger>
<TooltipContent>
<p>{t("tips.jreTip")}</p>
<p>{t("tips.jreTip2")}</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
);
}
@@ -0,0 +1,391 @@
import {
ArrowUpRightIcon,
AxeIcon,
CommandIcon,
NetworkIcon,
ServerIcon,
ShieldOffIcon,
SwordIcon,
WaypointsIcon,
ZapIcon,
} from "lucide-react";
import { type JSX, useCallback, useEffect, useId, useState } from "react";
import { FormProvider, type UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { AntSwordTabContent } from "@/components/memshell/tabs/antsword-tab";
import { BehinderTabContent } from "@/components/memshell/tabs/behinder-tab";
import { CommandTabContent } from "@/components/memshell/tabs/command-tab";
import CustomTabContent from "@/components/memshell/tabs/custom-tab";
import { GodzillaTabContent } from "@/components/memshell/tabs/godzilla-tab";
import { NeoRegTabContent } from "@/components/memshell/tabs/neoreg-tab";
import { Suo5TabContent } from "@/components/memshell/tabs/suo5-tab";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card.tsx";
import {
FormControl,
FormDescription,
FormField,
FormFieldItem,
FormFieldLabel,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form.tsx";
import { Label } from "@/components/ui/label.tsx";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select.tsx";
import { Switch } from "@/components/ui/switch.tsx";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
import type { ShellFormSchema } from "@/types/schema.ts";
import { type MainConfig, type ServerConfig, ShellToolType } from "@/types/shell.ts";
const shellToolIcons: Record<ShellToolType, JSX.Element> = {
[ShellToolType.Behinder]: <ShieldOffIcon className="h-4 w-4" />,
[ShellToolType.Godzilla]: <AxeIcon className="h-4 w-4" />,
[ShellToolType.Command]: <CommandIcon className="h-4 w-4" />,
[ShellToolType.AntSword]: <SwordIcon className="h-4 w-4" />,
[ShellToolType.Suo5]: <WaypointsIcon className="h-4 w-4" />,
[ShellToolType.NeoreGeorg]: <NetworkIcon className="h-4 w-4" />,
[ShellToolType.Custom]: <ZapIcon className="h-4 w-4" />,
};
const defaultServerVersionOptions = [
{
name: "Unknown",
value: "unknown",
},
];
export default function MainConfigCard({
mainConfig,
form,
servers,
}: Readonly<{
mainConfig: MainConfig | undefined;
form: UseFormReturn<ShellFormSchema>;
servers?: ServerConfig;
}>) {
const [shellToolMap, setShellToolMap] = useState<{
[toolName: string]: string[];
}>();
const [shellTools, setShellTools] = useState<ShellToolType[]>([
ShellToolType.Godzilla,
ShellToolType.Behinder,
ShellToolType.AntSword,
ShellToolType.Command,
ShellToolType.Suo5,
ShellToolType.NeoreGeorg,
ShellToolType.Custom,
]);
const [shellTypes, setShellTypes] = useState<string[]>([]);
const shellTool = form.watch("shellTool");
const { t } = useTranslation();
const [serverVersionOptions, setServerVersionOptions] = useState(defaultServerVersionOptions);
// 处理一下 shellTypes 由于 server 或 shellTool 变更时无法正常为 form.shellType 赋值的问题
useEffect(() => {
if (shellTypes.length > 0) {
form.setValue("shellType", shellTypes[0]);
}
}, [shellTypes, form]);
const handleServerChange = useCallback(
(value: string) => {
if (mainConfig) {
const newShellToolMap = mainConfig[value];
setShellToolMap(newShellToolMap);
const newShellTools = Object.keys(newShellToolMap);
setShellTools([...newShellTools.map((tool) => tool as ShellToolType), ShellToolType.Custom]);
const currentShellTool = form.getValues("shellTool");
const firstTool = newShellTools[0];
let currentShellTypes = null;
if (!newShellToolMap[currentShellTool]) {
form.setValue("shellTool", firstTool);
currentShellTypes = newShellToolMap[firstTool];
} else {
currentShellTypes = newShellToolMap[currentShellTool];
}
setShellTypes(currentShellTypes);
// 特殊环境的 JDK 版本
if (
(value === "SpringWebFlux" || value === "XXLJOB") &&
Number.parseInt(form.getValues("targetJdkVersion") as string) < 52
) {
form.setValue("targetJdkVersion", "52");
} else {
form.resetField("targetJdkVersion");
}
// 特殊的服务需要指定版本
if (value === "TongWeb") {
setServerVersionOptions([
...defaultServerVersionOptions,
{
name: "6",
value: "6",
},
{
name: "7",
value: "7",
},
{
name: "8",
value: "8",
},
]);
} else {
setServerVersionOptions(defaultServerVersionOptions);
}
form.resetField("serverVersion");
form.resetField("byPassJavaModule");
form.resetField("urlPattern");
}
},
[form, mainConfig],
);
// 处理一下默认值 server 不刷新 shellType 的问题
useEffect(() => {
if (mainConfig) {
const initialServer = form.getValues("server");
if (initialServer && mainConfig[initialServer]) {
handleServerChange(initialServer);
}
}
}, [mainConfig, form, handleServerChange]);
const handleShellToolChange = useCallback(
(value: string) => {
const resetCommand = () => {
form.resetField("commandParamName");
form.resetField("implementationClass");
form.resetField("encryptor");
};
const resetGodzilla = () => {
form.resetField("godzillaKey");
form.resetField("godzillaPass");
form.resetField("headerName");
form.resetField("headerValue");
};
const resetBehinder = () => {
form.resetField("behinderPass");
form.resetField("headerName");
form.resetField("headerValue");
};
const resetSuo5 = () => {
form.resetField("headerName");
form.resetField("headerValue");
};
const resetAntSword = () => {
form.resetField("antSwordPass");
form.resetField("headerName");
form.resetField("headerValue");
};
const resetNeoreGeorg = () => {
form.setValue("headerName", "Referer");
form.resetField("headerValue");
};
const resetCustom = () => {
form.resetField("shellClassBase64");
};
if (shellToolMap) {
let currentShellTypes = null;
if (value === ShellToolType.Custom) {
currentShellTypes = servers?.[form.getValues("server")] as string[];
} else {
currentShellTypes = shellToolMap[value];
}
setShellTypes(currentShellTypes);
form.resetField("urlPattern");
form.resetField("shellClassName");
form.resetField("injectorClassName");
if (value === ShellToolType.Godzilla) {
resetGodzilla();
} else if (value === ShellToolType.Behinder) {
resetBehinder();
} else if (value === ShellToolType.Command) {
resetCommand();
} else if (value === ShellToolType.Suo5) {
resetSuo5();
} else if (value === ShellToolType.AntSword) {
resetAntSword();
} else if (value === ShellToolType.NeoreGeorg) {
resetNeoreGeorg();
} else if (value === ShellToolType.Custom) {
resetCustom();
}
}
form.setValue("shellTool", value);
},
[form, servers, shellToolMap],
);
const debugId = useId();
const bypassId = useId();
const shrinkId = useId();
return (
<FormProvider {...form}>
<Card>
<CardHeader className="pb-1">
<CardTitle className="text-md flex items-center gap-2">
<ServerIcon className="h-5" />
<span>{t("configs.main-config")}</span>
</CardTitle>
</CardHeader>
<CardContent>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<FormField
control={form.control}
name="server"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("mainConfig.server")}</FormFieldLabel>
<Select
onValueChange={(v) => {
field.onChange(v);
handleServerChange(v);
}}
value={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder={t("placeholders.select")} />
</SelectTrigger>
</FormControl>
<SelectContent>
{Object.keys(servers ?? {}).map((server: string) => (
<SelectItem key={server} value={server}>
{server}
</SelectItem>
))}
</SelectContent>
</Select>
<FormDescription className="flex items-center">
{t("tips.targetServerNotFound")}&nbsp;
<a
href="https://github.com/ReaJason/MemShellParty/issues/new?template=%E8%AF%B7%E6%B1%82%E9%80%82%E9%85%8D.md"
target="_blank"
rel="noreferrer"
className="flex items-center underline"
>
{t("tips.targetServerRequest")}
<ArrowUpRightIcon className="h-4" />
</a>
</FormDescription>
</FormFieldItem>
)}
/>
<FormField
control={form.control}
name="serverVersion"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("mainConfig.serverVersion")}</FormFieldLabel>
<Select onValueChange={field.onChange} value={field.value}>
<FormControl>
<SelectTrigger>
<SelectValue placeholder={t("placeholders.select")} />
</SelectTrigger>
</FormControl>
<SelectContent>
{serverVersionOptions.map((v) => (
<SelectItem key={v.value} value={v.value}>
{v.name}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormFieldItem>
)}
/>
</div>
<div className="flex gap-4 mt-4 flex-col sm:flex-row">
<FormField
control={form.control}
name="debug"
render={({ field }) => (
<FormItem className="flex items-center space-x-2 space-y-0">
<FormControl>
<Switch id={debugId} checked={field.value} onCheckedChange={field.onChange} />
</FormControl>
<FormLabel htmlFor={debugId}>{t("mainConfig.debug")}</FormLabel>
</FormItem>
)}
/>
<FormField
control={form.control}
name="byPassJavaModule"
render={({ field }) => (
<FormItem className="flex items-center space-x-2 space-y-0">
<FormControl>
<Switch id={bypassId} checked={field.value} onCheckedChange={field.onChange} />
</FormControl>
<Label htmlFor={bypassId}>{t("mainConfig.byPassJavaModule")}</Label>
</FormItem>
)}
/>
<FormField
control={form.control}
name="shrink"
render={({ field }) => (
<FormItem className="flex items-center space-x-2 space-y-0">
<FormControl>
<Switch id={shrinkId} checked={field.value} onCheckedChange={field.onChange} />
</FormControl>
<Label htmlFor={shrinkId}>{t("mainConfig.shrink")}</Label>
</FormItem>
)}
/>
</div>
</CardContent>
</Card>
<Tabs
value={shellTool}
onValueChange={(v) => {
handleShellToolChange(v);
}}
className="w-full"
>
<div className="relative bg-muted rounded-lg">
<TabsList className="flex flex-wrap gap-1 w-full bg-transparent overflow-x-auto tabs-list">
{shellTools.map((shellTool) => (
<TabsTrigger
key={shellTool}
value={shellTool}
className="flex-1 min-w-24 data-[state=active]:bg-background"
>
<span className="flex items-center gap-2">
{shellToolIcons[shellTool]}
{shellTool}
</span>
</TabsTrigger>
))}
</TabsList>
</div>
<GodzillaTabContent form={form} shellTypes={shellTypes} />
<CommandTabContent form={form} shellTypes={shellTypes} />
<BehinderTabContent form={form} shellTypes={shellTypes} />
<AntSwordTabContent form={form} shellTypes={shellTypes} />
<Suo5TabContent form={form} shellTypes={shellTypes} />
<NeoRegTabContent form={form} shellTypes={shellTypes} />
<CustomTabContent form={form} shellTypes={shellTypes} />
</Tabs>
</FormProvider>
);
}
@@ -0,0 +1,105 @@
import { PackageIcon } from "lucide-react";
import { useEffect, useState } from "react";
import { FormProvider, type UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card.tsx";
import { FormControl, FormField, FormItem, FormLabel } from "@/components/ui/form.tsx";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group.tsx";
import type { ShellFormSchema } from "@/types/schema.ts";
import type { PackerConfig } from "@/types/shell.ts";
type Option = {
name: string;
value: string;
};
export default function PackageConfigCard({
packerConfig,
form,
}: Readonly<{
packerConfig: PackerConfig | undefined;
form: UseFormReturn<ShellFormSchema>;
}>) {
const [options, setOptions] = useState<Array<Option>>([]);
const shellType = form.watch("shellType");
const server = form.watch("server");
const { t } = useTranslation();
useEffect(() => {
const filteredOptions = (packerConfig ?? []).filter((name) => {
if (!shellType || shellType === " ") {
return true;
}
if (shellType.startsWith("Agent")) {
return name.startsWith("Agent");
}
if (server.startsWith("XXL")) {
return !name.startsWith("Agent");
}
return !name.startsWith("Agent") && !name.toLowerCase().startsWith("xxl");
});
const mappedOptions = filteredOptions.map((name) => {
return {
name: t(`packageConfig.packer.${name}`),
value: name,
};
});
setOptions(mappedOptions);
const currentValue = form.getValues("packingMethod");
if (filteredOptions.length > 0 && (!currentValue || !filteredOptions.includes(currentValue))) {
form.setValue("packingMethod", filteredOptions[0]);
}
}, [form, packerConfig, server, shellType, t]);
return (
<Card className="w-full">
<CardHeader className="pb-1">
<CardTitle className="text-md flex items-center gap-2">
<PackageIcon className="h-5" />
<span>{t("configs.package-config")}</span>
</CardTitle>
</CardHeader>
<CardContent>
{options.length > 0 ? (
<FormProvider {...form}>
<FormField
control={form.control}
name="packingMethod"
render={({ field }) => (
<FormItem className="space-y-3">
<FormLabel>{t("packageConfig.title")}</FormLabel>
<FormControl>
<RadioGroup
onValueChange={field.onChange}
value={field.value}
className="grid grid-cols-2 md:grid-cols-3"
>
{options.map(({ name, value }) => (
<FormItem key={value} className="flex items-center space-x-3 space-y-0">
<FormControl>
<RadioGroupItem value={value} id={value} />
</FormControl>
<FormLabel className="text-xs" htmlFor={value}>
{name}
</FormLabel>
</FormItem>
))}
</RadioGroup>
</FormControl>
</FormItem>
)}
/>
</FormProvider>
) : (
<div className="flex items-center justify-center p-4 space-x-2">
<div className="h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent" />
<span className="text-sm text-muted-foreground">{t("loading")}</span>
</div>
)}
</CardContent>
</Card>
);
}
@@ -0,0 +1,26 @@
import { ScrollTextIcon } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card.tsx";
export function QuickUsage() {
const { t } = useTranslation();
return (
<Card>
<CardHeader>
<CardTitle className="text-md flex items-center gap-2">
<ScrollTextIcon className="h-5" />
<span>{t("quickUsage.title")}</span>
</CardTitle>
</CardHeader>
<CardContent>
<ol className="list-decimal list-inside space-y-4 text-sm">
<li>{t("quickUsage.step1")}</li>
<li>{t("quickUsage.step2")}</li>
<li>{t("quickUsage.step3")}</li>
<li>{t("quickUsage.step4")}</li>
<li>{t("quickUsage.step5")}</li>
</ol>
</CardContent>
</Card>
);
}
@@ -0,0 +1,69 @@
import { ScrollTextIcon } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Separator } from "@/components/ui/separator";
import { downloadBytes, formatBytes } from "@/lib/utils";
import type { GenerateResult } from "@/types/shell";
export function AgentResult({
packMethod,
packResult,
generateResult,
}: Readonly<{ packMethod: string; packResult: string; generateResult?: GenerateResult }>) {
const { t } = useTranslation();
const isPureAgent = packMethod === "AgentJar";
return (
<Card>
<CardHeader>
<CardTitle className="text-md flex items-center gap-2">
<ScrollTextIcon className="h-5" />
<span>{t("generateResult.usage")}</span>
</CardTitle>
</CardHeader>
<CardContent>
<ol className="list-decimal list-inside space-y-4 text-sm">
<li className="flex items-center justify-between">
<span>
{t("download")} MemShellAgent.jar ({formatBytes(atob(packResult).length)})
</span>
<Button
size="sm"
variant="outline"
className="w-28"
type="button"
onClick={() =>
downloadBytes(
packResult,
undefined,
`${generateResult?.shellConfig.server}${generateResult?.shellConfig.shellTool}MemShellAgent`,
)
}
>
{t("download")}
</Button>
</li>
{isPureAgent && (
<li className="flex items-center justify-between">
<span>{t("tips.download-jattach")}</span>
<Button
size="sm"
variant="outline"
className="w-28"
type="button"
onClick={() => window.open("https://github.com/jattach/jattach/releases")}
>
{t("download")}
</Button>
</li>
)}
<Separator />
<li>{isPureAgent ? t("tips.agent-move-to-target") : t("tips.agent-move-to-target1")}</li>
<li>{t("tips.get-pid")}</li>
<li>{isPureAgent ? t("tips.execute-command") : t("tips.execute-command1")}</li>
<li>{t("tips.try-to-use-shell")}</li>
</ol>
</CardContent>
</Card>
);
}
@@ -0,0 +1,141 @@
import { FileTextIcon } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Separator } from "@/components/ui/separator";
import { shouldHidden } from "@/lib/utils";
import {
type AntSwordShellToolConfig,
type BehinderShellToolConfig,
type CommandShellToolConfig,
type GenerateResult,
type GodzillaShellToolConfig,
type NeoreGeorgShellToolConfig,
ShellToolType,
type Suo5ShellToolConfig,
} from "@/types/shell";
import { CopyableField } from "../../copyable-field";
import { FeedbackAlert } from "./feedback-alert";
export function BasicInfo({ generateResult }: Readonly<{ generateResult?: GenerateResult }>) {
const { t } = useTranslation();
return (
<Card>
<CardHeader>
<CardTitle className="flex items-center justify-between">
<div className="text-md flex items-center gap-2">
<FileTextIcon className="h-5" />
<span>{t("generateResult.basicInfo")}</span>
</div>
<FeedbackAlert />
</CardTitle>
</CardHeader>
<CardContent>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<CopyableField label={t("mainConfig.server")} text={generateResult?.shellConfig.server} />
<CopyableField label={t("mainConfig.shellTool")} text={generateResult?.shellConfig.shellTool} />
<CopyableField label={t("mainConfig.shellMountType")} text={generateResult?.shellConfig.shellType} />
{!shouldHidden(generateResult?.shellConfig?.shellType) && (
<CopyableField
label={t("mainConfig.urlPattern")}
text={generateResult?.injectorConfig.urlPattern}
value={generateResult?.injectorConfig.urlPattern}
/>
)}
</div>
{generateResult?.shellConfig.shellTool !== ShellToolType.Custom && <Separator className="my-1" />}
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
{generateResult?.shellConfig.shellTool === ShellToolType.Behinder && (
<>
<CopyableField label={t("shellToolConfig.behinderScriptType")} text="jsp" />
<CopyableField
label={t("shellToolConfig.behinderEncryptType")}
text={t("shellToolConfig.behinderDefaultEncryptType")}
/>
<CopyableField
label={t("shellToolConfig.behinderPass")}
text={(generateResult?.shellToolConfig as BehinderShellToolConfig).pass}
value={(generateResult?.shellToolConfig as BehinderShellToolConfig).pass}
/>
<CopyableField
label={t("shellToolConfig.customHeader")}
text={`${(generateResult?.shellToolConfig as BehinderShellToolConfig).headerName}: ${(generateResult?.shellToolConfig as BehinderShellToolConfig).headerValue}`}
value={`${(generateResult?.shellToolConfig as BehinderShellToolConfig).headerName}: ${(generateResult?.shellToolConfig as BehinderShellToolConfig).headerValue}`}
/>
</>
)}
{generateResult?.shellConfig.shellTool === ShellToolType.Godzilla && (
<>
<CopyableField
label={t("shellToolConfig.pass")}
text={(generateResult?.shellToolConfig as GodzillaShellToolConfig).pass}
value={(generateResult?.shellToolConfig as GodzillaShellToolConfig).pass}
/>
<CopyableField
label={t("shellToolConfig.key")}
text={(generateResult?.shellToolConfig as GodzillaShellToolConfig).key}
value={(generateResult?.shellToolConfig as GodzillaShellToolConfig).key}
/>
<CopyableField label={t("shellToolConfig.godzillaEncryptor")} text="JAVA_AES_BASE64" />
<CopyableField
label={t("shellToolConfig.godzillaHeader")}
text={`${(generateResult?.shellToolConfig as GodzillaShellToolConfig).headerName}: ${(generateResult?.shellToolConfig as GodzillaShellToolConfig).headerValue}`}
value={`${(generateResult?.shellToolConfig as GodzillaShellToolConfig).headerName}: ${(generateResult?.shellToolConfig as GodzillaShellToolConfig).headerValue}`}
/>
</>
)}
{generateResult?.shellConfig.shellTool === ShellToolType.Command && (
<CopyableField
label={t("shellToolConfig.paramName")}
text={(generateResult?.shellToolConfig as CommandShellToolConfig).paramName}
value={(generateResult?.shellToolConfig as CommandShellToolConfig).paramName}
/>
)}
{generateResult?.shellConfig.shellTool === ShellToolType.Suo5 && (
<CopyableField
label={t("shellToolConfig.suo5Header")}
text={`${(generateResult?.shellToolConfig as Suo5ShellToolConfig).headerName}: ${(generateResult?.shellToolConfig as Suo5ShellToolConfig).headerValue}`}
value={`${(generateResult?.shellToolConfig as Suo5ShellToolConfig).headerName}: ${(generateResult?.shellToolConfig as Suo5ShellToolConfig).headerValue}`}
/>
)}
{generateResult?.shellConfig.shellTool === ShellToolType.AntSword && (
<>
<CopyableField
label={t("shellToolConfig.antSwordPass")}
text={(generateResult?.shellToolConfig as AntSwordShellToolConfig).pass}
value={(generateResult?.shellToolConfig as AntSwordShellToolConfig).pass}
/>
<CopyableField
label={t("shellToolConfig.httpHeader")}
text={`${(generateResult?.shellToolConfig as AntSwordShellToolConfig).headerName}: ${(generateResult?.shellToolConfig as AntSwordShellToolConfig).headerValue}`}
value={`${(generateResult?.shellToolConfig as AntSwordShellToolConfig).headerName}: ${(generateResult?.shellToolConfig as AntSwordShellToolConfig).headerValue}`}
/>
</>
)}
{generateResult?.shellConfig.shellTool === ShellToolType.NeoreGeorg && (
<>
<CopyableField label={t("shellToolConfig.neoreGeorgKey")} text="key" value="key" />
<CopyableField
label={t("shellToolConfig.neoreGeorgHeader")}
text={`${(generateResult?.shellToolConfig as NeoreGeorgShellToolConfig).headerName}: ${(generateResult?.shellToolConfig as NeoreGeorgShellToolConfig).headerValue}`}
value={`${(generateResult?.shellToolConfig as NeoreGeorgShellToolConfig).headerName}: ${(generateResult?.shellToolConfig as NeoreGeorgShellToolConfig).headerValue}`}
/>
</>
)}
</div>
<Separator className="my-1" />
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<CopyableField
label={t("mainConfig.injectorClassName")}
value={generateResult?.injectorClassName}
text={`${generateResult?.injectorClassName} (${generateResult?.injectorSize} bytes)`}
/>
<CopyableField
label={t("mainConfig.shellClassName")}
value={generateResult?.shellClassName}
text={`${generateResult?.shellClassName} (${generateResult?.shellSize} bytes)`}
/>
</div>
</CardContent>
</Card>
);
}
@@ -0,0 +1,50 @@
import { CircleHelpIcon } from "lucide-react";
import { useTranslation } from "react-i18next";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
export function FeedbackAlert() {
const { t } = useTranslation();
return (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant="outline" type="button">
<CircleHelpIcon /> {t("shellNotWork.title")}
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{t("shellNotWork.title")}</AlertDialogTitle>
<AlertDialogDescription>
<ol>
<li>{t("shellNotWork.step1")}</li>
<li>{t("shellNotWork.step2")}</li>
</ol>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t("cancel")}</AlertDialogCancel>
<AlertDialogAction
onClick={() =>
window.open(
"https://github.com/ReaJason/MemShellParty/issues/new?template=%E5%86%85%E5%AD%98%E9%A9%AC%E7%94%9F%E6%88%90-bug-%E4%B8%8A%E6%8A%A5.md",
)
}
>
{t("feedback")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}
@@ -0,0 +1,27 @@
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { downloadBytes } from "@/lib/utils";
import type { GenerateResult } from "@/types/shell";
export function JarResult({
packResult,
generateResult,
}: Readonly<{ packResult: string; generateResult?: GenerateResult }>) {
const { t } = useTranslation();
return (
<div className="flex items-center justify-center">
<Button
type="button"
onClick={() =>
downloadBytes(
packResult,
undefined,
`${generateResult?.shellConfig.server}${generateResult?.shellConfig.shellTool}MemShell`,
)
}
>
{t("download")} Jar
</Button>
</div>
);
}
@@ -0,0 +1,58 @@
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import CodeViewer from "@/components/code-viewer";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
export function MultiPackResult({
allPackResults,
packMethod,
}: Readonly<{
allPackResults: object | undefined;
packMethod: string;
}>) {
const showCode = packMethod === "JSP";
const {t} = useTranslation();
const packMethods = Object.keys(allPackResults ?? {});
const [selectedMethod, setSelectedMethod] = useState(packMethods[0]);
const [packResult, setPackResult] = useState(allPackResults?.[selectedMethod as keyof typeof allPackResults] ?? "");
useEffect(() => {
const methods = Object.keys(allPackResults ?? {});
const firstMethod = methods[0];
setSelectedMethod(firstMethod);
setPackResult(allPackResults?.[firstMethod as keyof typeof allPackResults] ?? "");
}, [allPackResults]);
return (
<CodeViewer
code={packResult ?? ""}
header={
<div className="flex items-center justify-between text-xs gap-2">
<Select
onValueChange={(value) => {
setSelectedMethod(value);
setPackResult(allPackResults?.[value as keyof typeof allPackResults] ?? "");
}}
value={selectedMethod}
>
<SelectTrigger className="h-7 text-xs [&_svg]:h-4 [&_svg]:w-4">
<span className="text-muted-foreground">{t("packageConfig.title")}:&nbsp;</span>
<SelectValue />
</SelectTrigger>
<SelectContent>
{packMethods.map((method) => (
<SelectItem key={method} value={method} className="text-xs">
{method}
</SelectItem>
))}
</SelectContent>
</Select>
<span className="text-muted-foreground">({packResult?.length})</span>
</div>
}
wrapLongLines={!showCode}
showLineNumbers={showCode}
language={showCode ? "java" : "text"}
height={350}
/>
);
}
@@ -0,0 +1,53 @@
import { useTranslation } from "react-i18next";
import CodeViewer from "@/components/code-viewer";
import type { GenerateResult } from "@/types/shell";
import { AgentResult } from "./agent";
import { JarResult } from "./jar-result";
import { MultiPackResult } from "./multi-packer";
export function ResultComponent({
packResult,
allPackResults,
packMethod,
generateResult,
}: Readonly<{
packResult: string | undefined;
allPackResults: Map<string, string> | undefined;
packMethod: string;
generateResult?: GenerateResult;
}>) {
const showCode = packMethod === "JSP";
const isAgent = packMethod.startsWith("Agent");
const isJar = packMethod === "Jar";
const { t } = useTranslation();
if (allPackResults) {
return <MultiPackResult allPackResults={allPackResults} packMethod={packMethod} />;
}
if (isAgent) {
return <AgentResult packMethod={packMethod} packResult={packResult ?? ""} generateResult={generateResult} />;
}
if (isJar) {
return <JarResult packResult={packResult ?? ""} generateResult={generateResult} />;
}
if (!isAgent && !isJar) {
return (
<CodeViewer
code={packResult ?? ""}
header={
<div className="flex items-center justify-between text-xs gap-2">
<span>
{t("packageConfig.title")}{packMethod}
</span>
<span className="text-muted-foreground">({packResult?.length})</span>
</div>
}
wrapLongLines={!showCode}
showLineNumbers={showCode}
language={showCode ? "java" : "text"}
height={350}
/>
);
}
return null;
}
@@ -0,0 +1,101 @@
import { DownloadIcon } from "lucide-react";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";
import { QuickUsage } from "@/components/memshell/quick-usage";
import { Button } from "@/components/ui/button.tsx";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs.tsx";
import { downloadBytes } from "@/lib/utils.ts";
import type { GenerateResult } from "@/types/shell.ts";
import CodeViewer from "../code-viewer";
import { BasicInfo } from "./results/basic-info";
import { ResultComponent } from "./results/result-component";
export default function ShellResult({
packResult,
allPackResults,
packMethod,
generateResult,
}: Readonly<{
packResult: string | undefined;
allPackResults: Map<string, string> | undefined;
packMethod: string;
generateResult?: GenerateResult;
}>) {
const { t } = useTranslation();
if (!generateResult) {
return <QuickUsage />;
}
return (
<Tabs defaultValue="packResult">
<TabsList className="grid w-full grid-cols-3">
<TabsTrigger value="packResult">{t("generateResult.title1")}</TabsTrigger>
<TabsTrigger value="shell">{t("generateResult.title2")}</TabsTrigger>
<TabsTrigger value="injector">{t("generateResult.title3")}</TabsTrigger>
</TabsList>
<TabsContent value="packResult" className="my-2 space-y-4">
<BasicInfo generateResult={generateResult} />
<ResultComponent
packResult={packResult}
allPackResults={allPackResults}
packMethod={packMethod}
generateResult={generateResult}
/>
</TabsContent>
<TabsContent value="shell" className="mt-4">
<CodeViewer
showLineNumbers={false}
header={<div className="text-xs truncate">{generateResult?.shellClassName}</div>}
button={
<Button
variant="ghost"
size="icon"
type="button"
className="h-7 w-7 [&_svg]:h-4 [&_svg]:w-4"
onClick={() => {
if (!generateResult?.shellBytesBase64Str) {
toast.warning(t("tips.shellBytesEmpty"));
return;
}
downloadBytes(generateResult?.shellBytesBase64Str, generateResult?.shellClassName);
}}
>
<DownloadIcon className="h-4 w-4" />
</Button>
}
wrapLongLines={true}
height={600}
code={generateResult?.shellBytesBase64Str ?? ""}
language="text"
/>
</TabsContent>
<TabsContent value="injector" className="mt-4">
<CodeViewer
showLineNumbers={false}
wrapLongLines={true}
header={<div className="text-xs">{generateResult?.injectorClassName}</div>}
button={
<Button
variant="ghost"
size="icon"
type="button"
className="h-7 w-7 [&_svg]:h-4 [&_svg]:w-4"
onClick={() => {
if (!generateResult?.injectorBytesBase64Str) {
toast.warning(t("tips.shellBytesEmpty"));
return;
}
downloadBytes(generateResult?.injectorBytesBase64Str, generateResult?.injectorClassName);
}}
>
<DownloadIcon className="h-4 w-4" />
</Button>
}
height={600}
code={generateResult?.injectorBytesBase64Str ?? ""}
language="text"
/>
</TabsContent>
</Tabs>
);
}
@@ -0,0 +1,70 @@
import { FormProvider, type UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { Card, CardContent } from "@/components/ui/card";
import { FormControl, FormField, FormFieldItem, FormFieldLabel } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { TabsContent } from "@/components/ui/tabs";
import type { ShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export function AntSwordTabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<ShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
return (
<FormProvider {...form}>
<TabsContent value="AntSword">
<Card>
<CardContent className="space-y-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<FormField
control={form.control}
name="antSwordPass"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.antSwordPass")} {t("optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<FormField
control={form.control}
name="headerName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.headerName")}</FormFieldLabel>
<FormControl>
<Input {...field} placeholder={t("placeholders.input")} />
</FormControl>
</FormFieldItem>
)}
/>
<FormField
control={form.control}
name="headerValue"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.headerValue")} {t("optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
</div>
<OptionalClassFormField form={form} />
</CardContent>
</Card>
</TabsContent>
</FormProvider>
);
}
@@ -0,0 +1,68 @@
import { FormProvider, type UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { Card, CardContent } from "@/components/ui/card";
import { FormField, FormFieldItem, FormFieldLabel } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { TabsContent } from "@/components/ui/tabs";
import type { ShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export function BehinderTabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<ShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
return (
<FormProvider {...form}>
<TabsContent value="Behinder">
<Card>
<CardContent className="space-y-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<FormField
control={form.control}
name="behinderPass"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.behinderPass")} {t("optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<FormField
control={form.control}
name="headerName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.headerName")}</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
<FormField
control={form.control}
name="headerValue"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.headerValue")} {t("optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
</div>
<OptionalClassFormField form={form} />
</CardContent>
</Card>
</TabsContent>
</FormProvider>
);
}
@@ -0,0 +1,60 @@
import { ChevronDown, ChevronUp, Settings } from "lucide-react";
import { Fragment, useId, useState } from "react";
import { FormProvider, type UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { FormField, FormFieldItem, FormFieldLabel } from "@/components/ui/form.tsx";
import { Input } from "@/components/ui/input.tsx";
import type { ShellFormSchema } from "@/types/schema.ts";
export function OptionalClassFormField({ form }: Readonly<{ form: UseFormReturn<ShellFormSchema> }>) {
const { t } = useTranslation();
const [showAdvanced, setShowAdvanced] = useState(false);
const shellClassNameId = useId();
const injectClassNameId = useId();
return (
<Fragment>
<div className="pt-2">
<Button
type="button"
variant="outline"
size="sm"
onClick={() => setShowAdvanced(!showAdvanced)}
className="flex items-center gap-2"
>
<Settings className="h-4 w-4" />
{t("classNameOptions")}
{showAdvanced ? <ChevronUp className="h-4 w-4" /> : <ChevronDown className="h-4 w-4" />}
</Button>
</div>
{showAdvanced && (
<FormProvider {...form}>
<FormField
control={form.control}
name="shellClassName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel htmlFor={shellClassNameId}>
{t("mainConfig.shellClassName")} {t("optional")}
</FormFieldLabel>
<Input id={shellClassNameId} {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
<FormField
control={form.control}
name="injectorClassName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel htmlFor={injectClassNameId}>
{t("mainConfig.injectorClassName")} {t("optional")}
</FormFieldLabel>
<Input id={injectClassNameId} {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
</FormProvider>
)}
</Fragment>
);
}
@@ -0,0 +1,105 @@
import { useQuery } from "@tanstack/react-query";
import { FormProvider, type UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { Card, CardContent } from "@/components/ui/card";
import { FormControl, FormField, FormFieldItem, FormFieldLabel } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { TabsContent } from "@/components/ui/tabs";
import { env } from "@/config";
import type { ShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export function CommandTabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<ShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
const { data } = useQuery<{ encryptors: Array<string>; implementationClasses: Array<string> }>({
queryKey: ["commandConfigs"],
queryFn: async () => {
const response = await fetch(`${env.API_URL}/config/command/configs`);
return await response.json();
},
});
return (
<FormProvider {...form}>
<TabsContent value="Command">
<Card>
<CardContent className="space-y-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<FormField
control={form.control}
name="commandParamName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.paramName")} {t("optional")}
</FormFieldLabel>
<FormControl>
<Input {...field} placeholder={t("placeholders.input")} />
</FormControl>
</FormFieldItem>
)}
/>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<FormField
control={form.control}
name="encryptor"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.encryptor")}</FormFieldLabel>
<Select onValueChange={field.onChange} value={field.value} defaultValue="RAW">
<FormControl>
<SelectTrigger>
<SelectValue placeholder={t("placeholders.select")} />
</SelectTrigger>
</FormControl>
<SelectContent>
{data?.encryptors?.map((v) => (
<SelectItem key={v} value={v}>
{v}
</SelectItem>
))}
</SelectContent>
</Select>
</FormFieldItem>
)}
/>
<FormField
control={form.control}
name="implementationClass"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.implementationClass")}</FormFieldLabel>
<Select onValueChange={field.onChange} value={field.value} defaultValue="RuntimeExec">
<FormControl>
<SelectTrigger>
<SelectValue placeholder={t("placeholders.select")} />
</SelectTrigger>
</FormControl>
<SelectContent>
{data?.implementationClasses?.map((v) => (
<SelectItem key={v} value={v}>
{v}
</SelectItem>
))}
</SelectContent>
</Select>
</FormFieldItem>
)}
/>
</div>
<OptionalClassFormField form={form} />
</CardContent>
</Card>
</TabsContent>
</FormProvider>
);
}
@@ -0,0 +1,87 @@
import { t } from "i18next";
import { useId, useState } from "react";
import { FormProvider, type UseFormReturn } from "react-hook-form";
import { Card, CardContent } from "@/components/ui/card";
import { FormControl, FormField, FormFieldItem, FormFieldLabel, FormMessage } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import { TabsContent } from "@/components/ui/tabs";
import { Textarea } from "@/components/ui/textarea";
import type { ShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export default function CustomTabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<ShellFormSchema>; shellTypes: Array<string> }>) {
const [isFile, setIsFile] = useState(false);
const optionOneId = useId();
const optionTwoId = useId();
return (
<FormProvider {...form}>
<TabsContent value="Custom">
<Card>
<CardContent className="space-y-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<FormField
control={form.control}
name="shellClassBase64"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.base64String")}</FormFieldLabel>
<RadioGroup
value={isFile ? "file" : "base64"}
onValueChange={(value) => {
field.onChange("");
setIsFile(value === "file");
}}
className="flex items-center space-x-2"
>
<div className="flex items-center space-x-2">
<RadioGroupItem value="base64" id={optionOneId} />
<Label htmlFor={optionOneId}>Base64</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="file" id={optionTwoId} />
<Label htmlFor={optionTwoId}>File</Label>
</div>
</RadioGroup>
<FormControl className="mt-2">
{isFile ? (
<Input
onChange={(e) => {
const file = e.target.files?.[0];
if (file) {
const reader = new FileReader();
reader.onload = (event) => {
const base64String = (event.target?.result as string)?.split(",")[1] || "";
field.onChange(base64String);
};
reader.readAsDataURL(file);
}
}}
accept=".class"
placeholder={t("placeholders.input")}
type="file"
/>
) : (
<Textarea {...field} placeholder={t("placeholders.input")} className="h-24" />
)}
</FormControl>
<FormMessage />
</FormFieldItem>
)}
/>
<OptionalClassFormField form={form} />
</CardContent>
</Card>
</TabsContent>
</FormProvider>
);
}
@@ -0,0 +1,80 @@
import { FormProvider, type UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { Card, CardContent } from "@/components/ui/card";
import { FormField, FormFieldItem, FormFieldLabel } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { TabsContent } from "@/components/ui/tabs";
import type { ShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export function GodzillaTabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<ShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
return (
<FormProvider {...form}>
<TabsContent value="Godzilla">
<Card>
<CardContent className="space-y-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<FormField
control={form.control}
name="godzillaPass"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.pass")} {t("optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
<FormField
control={form.control}
name="godzillaKey"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.key")} {t("optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
<FormField
control={form.control}
name="headerName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.headerName")}</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
<FormField
control={form.control}
name="headerValue"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.headerValue")} {t("optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
</div>
<OptionalClassFormField form={form} />
</CardContent>
</Card>
</TabsContent>
</FormProvider>
);
}
@@ -0,0 +1,56 @@
import { FormProvider, type UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { Card, CardContent } from "@/components/ui/card";
import { FormField, FormFieldItem, FormFieldLabel } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { TabsContent } from "@/components/ui/tabs";
import type { ShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export function NeoRegTabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<ShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
return (
<FormProvider {...form}>
<TabsContent value="NeoreGeorg">
<Card>
<CardContent className="space-y-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<FormField
control={form.control}
name="headerName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.headerName")}</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
<FormField
control={form.control}
name="headerValue"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.headerValue")} {t("optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
</div>
<OptionalClassFormField form={form} />
</CardContent>
</Card>
</TabsContent>
</FormProvider>
);
}
@@ -0,0 +1,49 @@
import { FormProvider, type UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { FormControl, FormField, FormFieldItem, FormFieldLabel } from "@/components/ui/form.tsx";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select.tsx";
import type { ShellFormSchema } from "@/types/schema.ts";
export function ShellTypeFormField({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<ShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
return (
<FormProvider {...form}>
<FormField
control={form.control}
name="shellType"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("mainConfig.shellMountType")}</FormFieldLabel>
<Select
onValueChange={(e) => {
form.resetField("urlPattern");
field.onChange(e);
}}
value={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder={t("placeholders.select")} />
</SelectTrigger>
</FormControl>
<SelectContent key={shellTypes?.join(",")}>
{shellTypes?.length ? (
shellTypes.map((v) => (
<SelectItem key={v} value={v}>
{v}
</SelectItem>
))
) : (
<SelectItem value=" ">{t("tips.shellToolNotSelected")}</SelectItem>
)}
</SelectContent>
</Select>
</FormFieldItem>
)}
/>
</FormProvider>
);
}
@@ -0,0 +1,56 @@
import { FormProvider, type UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { Card, CardContent } from "@/components/ui/card";
import { FormField, FormFieldItem, FormFieldLabel } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { TabsContent } from "@/components/ui/tabs";
import type { ShellFormSchema } from "@/types/schema";
import { OptionalClassFormField } from "./classname-field";
import { ShellTypeFormField } from "./shelltype-field";
import { UrlPatternFormField } from "./urlpattern-field";
export function Suo5TabContent({
form,
shellTypes,
}: Readonly<{ form: UseFormReturn<ShellFormSchema>; shellTypes: Array<string> }>) {
const { t } = useTranslation();
return (
<FormProvider {...form}>
<TabsContent value="Suo5">
<Card>
<CardContent className="space-y-2 mt-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<ShellTypeFormField form={form} shellTypes={shellTypes} />
<UrlPatternFormField form={form} />
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<FormField
control={form.control}
name="headerName"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>{t("shellToolConfig.headerName")}</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
<FormField
control={form.control}
name="headerValue"
render={({ field }) => (
<FormFieldItem>
<FormFieldLabel>
{t("shellToolConfig.headerValue")} {t("optional")}
</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
</FormFieldItem>
)}
/>
</div>
<OptionalClassFormField form={form} />
</CardContent>
</Card>
</TabsContent>
</FormProvider>
);
}
@@ -0,0 +1,26 @@
import { FormProvider, type UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { FormField, FormFieldItem, FormFieldLabel, FormMessage } from "@/components/ui/form.tsx";
import { Input } from "@/components/ui/input.tsx";
import { shouldHidden } from "@/lib/utils";
import type { ShellFormSchema } from "@/types/schema.ts";
export function UrlPatternFormField({ form }: Readonly<{ form: UseFormReturn<ShellFormSchema> }>) {
const { t } = useTranslation();
const shellType = form.watch("shellType");
return (
<FormProvider {...form}>
<FormField
control={form.control}
name="urlPattern"
render={({ field }) => (
<FormFieldItem className={shouldHidden(shellType) ? "hidden" : "grid"}>
<FormFieldLabel>{t("mainConfig.urlPattern")}</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<FormMessage />
</FormFieldItem>
)}
/>
</FormProvider>
);
}