mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-21 22:50:42 +08:00
refactor: simplify server options
This commit is contained in:
Binary file not shown.
@@ -22,6 +22,7 @@ import {
|
||||
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";
|
||||
@@ -47,6 +48,13 @@ const shellToolIcons: Record<ShellToolType, JSX.Element> = {
|
||||
[ShellToolType.Custom]: <ZapIcon className="h-4 w-4" />,
|
||||
};
|
||||
|
||||
const defaultServerVersionOptions = [
|
||||
{
|
||||
name: "Unknown",
|
||||
value: "unknown",
|
||||
},
|
||||
];
|
||||
|
||||
export default function MainConfigCard({
|
||||
mainConfig,
|
||||
form,
|
||||
@@ -72,6 +80,8 @@ export default function MainConfigCard({
|
||||
const shellTool = form.watch("shellTool");
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [serverVersionOptions, setServerVersionOptions] = useState(defaultServerVersionOptions);
|
||||
|
||||
// 处理一下 shellTypes 由于 server 或 shellTool 变更时无法正常为 form.shellType 赋值的问题
|
||||
useEffect(() => {
|
||||
if (shellTypes.length > 0) {
|
||||
@@ -110,6 +120,29 @@ export default function MainConfigCard({
|
||||
} 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");
|
||||
}
|
||||
@@ -257,6 +290,32 @@ export default function MainConfigCard({
|
||||
</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="grid grid-cols-1">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="targetJdkVersion"
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
"mainConfig.injectorClassName": "Injector ClassName",
|
||||
"mainConfig.jre": "Target JRE Version",
|
||||
"mainConfig.server": "Target Server",
|
||||
"mainConfig.serverVersion": "Target Server Version",
|
||||
"mainConfig.shellClassName": "Shell ClassName",
|
||||
"mainConfig.shellMountType": "Shell Mount Type",
|
||||
"mainConfig.shellTool": "Shell Tool",
|
||||
@@ -112,6 +113,7 @@
|
||||
"tips.try-to-use-shell": "Try to use the memory shell",
|
||||
"tips.waitingForGeneration": "// Waiting for generation...",
|
||||
"tips.customShellClass": "Custom shell class is required, base64 or classfile",
|
||||
"tips.serverVersion": "serverVersion is required for TongWeb Valve",
|
||||
"version.updateAvailable": "Update Available",
|
||||
"version.updateAvailableTooltip": "Click to Open Github Release Page ( v{{currentVersion}} -> v{{latestVersion}})",
|
||||
"generator": "Generator",
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
"mainConfig.injectorClassName": "注入器类名",
|
||||
"mainConfig.jre": "目标 JRE 版本",
|
||||
"mainConfig.server": "目标服务",
|
||||
"mainConfig.serverVersion": "目标服务版本",
|
||||
"mainConfig.shellClassName": "内存马类名",
|
||||
"mainConfig.shellMountType": "内存马挂载类型",
|
||||
"mainConfig.shellTool": "内存马功能",
|
||||
@@ -111,6 +112,7 @@
|
||||
"tips.waitingForGeneration": "// 等待填写参数生成中...",
|
||||
"tips.customShellClass": "请输入自定义内存马类,base64 或类文件",
|
||||
"tips.specificUrlPattern": "必须指定 URL Pattern,例如 /hello",
|
||||
"tips.serverVersion": "TongWeb Valve 需要指定 serverVersion",
|
||||
"version.updateAvailable": "有可用升级",
|
||||
"version.updateAvailableTooltip": "点击前往 GitHub Release ( v{{currentVersion}} -> v{{latestVersion}})",
|
||||
"about": "关于",
|
||||
|
||||
@@ -55,6 +55,7 @@ export default function MemShellPage() {
|
||||
resolver: useYupValidationResolver(formSchema, t),
|
||||
defaultValues: {
|
||||
server: urlParams.server ?? "Tomcat",
|
||||
serverVersion: urlParams.serverVersion ?? "unknown",
|
||||
targetJdkVersion: urlParams.targetJdkVersion ?? "50",
|
||||
debug: urlParams.debug ?? false,
|
||||
bypassJavaModule: urlParams.bypassJavaModule ?? false,
|
||||
|
||||
@@ -6,6 +6,7 @@ import { ShellToolType } from "./shell";
|
||||
|
||||
export const formSchema = yup.object({
|
||||
server: yup.string().required().min(1),
|
||||
serverVersion: yup.string().required().min(1),
|
||||
targetJdkVersion: yup.string().optional(),
|
||||
debug: yup.boolean().optional(),
|
||||
bypassJavaModule: yup.boolean().optional(),
|
||||
@@ -59,6 +60,7 @@ export const useYupValidationResolver = (validationSchema: yup.ObjectSchema<any>
|
||||
|
||||
const urlPattern: keyof FormSchema = "urlPattern";
|
||||
const shellClassBase64: keyof FormSchema = "shellClassBase64";
|
||||
const serverVersion: keyof FormSchema = "serverVersion";
|
||||
const errors = {} as any;
|
||||
|
||||
if (urlPatternIsNeeded(values?.shellType) && isInvalidUrl(values?.urlPattern)) {
|
||||
@@ -73,6 +75,12 @@ export const useYupValidationResolver = (validationSchema: yup.ObjectSchema<any>
|
||||
message: t("tips.customShellClass"),
|
||||
};
|
||||
}
|
||||
if (values.server === "TongWeb" && values.shellType === "Valve" && values.serverVersion === "unknown") {
|
||||
errors[serverVersion] = {
|
||||
type: "custom",
|
||||
message: t("tips.serverVersion"),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
values,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export interface ShellConfig {
|
||||
server: string;
|
||||
serverVersion: string;
|
||||
shellTool: string;
|
||||
shellType: string;
|
||||
targetJreVersion?: string;
|
||||
|
||||
@@ -4,6 +4,7 @@ import { InjectorConfig, ShellConfig, ShellToolConfig } from "@/types/shell.ts";
|
||||
export function transformToPostData(formValue: FormSchema) {
|
||||
const shellConfig: ShellConfig = {
|
||||
server: formValue.server,
|
||||
serverVersion: formValue.serverVersion,
|
||||
shellTool: formValue.shellTool,
|
||||
shellType: formValue.shellType,
|
||||
debug: formValue.debug,
|
||||
|
||||
Reference in New Issue
Block a user