diff --git a/src/components/setting/mods/sysproxy-viewer.tsx b/src/components/setting/mods/sysproxy-viewer.tsx index ca8805d..4e564ca 100644 --- a/src/components/setting/mods/sysproxy-viewer.tsx +++ b/src/components/setting/mods/sysproxy-viewer.tsx @@ -1,7 +1,7 @@ import { forwardRef, useImperativeHandle, useState } from "react"; import { useLockFn } from "ahooks"; import { useTranslation } from "react-i18next"; -import { IconButton, Tooltip } from "@mui/material"; +import { Box, IconButton, Tooltip } from "@mui/material"; import { InfoRounded } from "@mui/icons-material"; import { InputAdornment, @@ -19,12 +19,21 @@ import { BaseDialog, DialogRef, Notice, Switch } from "@/components/base"; import { Edit } from "@mui/icons-material"; import { EditorViewer } from "@/components/profile/editor-viewer"; import { BaseFieldset } from "@/components/base/base-fieldset"; +import getSystem from "@/utils/get-system"; const DEFAULT_PAC = `function FindProxyForURL(url, host) { return "PROXY 127.0.0.1:%mixed-port%; SOCKS5 127.0.0.1:%mixed-port%; DIRECT;"; }`; export const SysproxyViewer = forwardRef((props, ref) => { const { t } = useTranslation(); + let validReg; + if (getSystem() === "windows") { + validReg = + /^(\*?\w+(\.\w+)*|\d{1,3}(\.\d{1,3}){0,2}\.\*|\d{1,3}(\.\d{1,3}){3})(;(\*?\w+(\.\w+)*|\d{1,3}(\.\d{1,3}){0,2}\.\*|\d{1,3}(\.\d{1,3}){3}))*$/; + } else { + validReg = + /^((\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}|(\d{1,3}\.){3}\d{1,3}(\/\d{1,2})?|([a-fA-F0-9:]+:+)+[a-fA-F0-9]+(\/\d{1,3})?)(,((\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}|(\d{1,3}\.){3}\d{1,3}(\/\d{1,2})?|([a-fA-F0-9:]+:+)+[a-fA-F0-9]+(\/\d{1,3})?))*$/; + } const [open, setOpen] = useState(false); const [editorOpen, setEditorOpen] = useState(false); @@ -92,7 +101,10 @@ export const SysproxyViewer = forwardRef((props, ref) => { if (value.pac_content !== pac_file_content) { patch.pac_file_content = value.pac_content; } - + if (value.bypass && !validReg.test(value.bypass)) { + Notice.error(t("Invalid Bypass Format")); + return; + } try { await patchVerge(patch); setOpen(false); @@ -136,6 +148,12 @@ export const SysproxyViewer = forwardRef((props, ref) => { )} + {value.pac && ( + + {t("PAC URL")} + {autoproxy?.url || "-"} + + )} @@ -183,30 +201,23 @@ export const SysproxyViewer = forwardRef((props, ref) => { }} /> - {!value.pac && ( <> - - {t("Proxy Bypass")} - - - - setValue((v) => ({ ...v, bypass: e.target.value })) - } - /> - - - {t("Bypass")} - + + { + setValue((v) => ({ ...v, bypass: e.target.value })); + }} + /> + ((props, ref) => { )} - {value.pac && ( <> @@ -257,13 +267,6 @@ export const SysproxyViewer = forwardRef((props, ref) => { )} - - {value.pac && ( - - {t("PAC URL")} - {autoproxy?.url || "-"} - - )} );