From aa181ababc5f83e7f5db63b4fad6d3441141a39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Thu, 4 Dec 2025 13:33:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=8C=E6=AD=A5=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/webserver/types/redirect.go | 10 +- pkg/webserver/types/vhost.go | 30 +++--- web/src/views/website/EditView.vue | 144 ++++++++++++++++------------- 3 files changed, 98 insertions(+), 86 deletions(-) diff --git a/pkg/webserver/types/redirect.go b/pkg/webserver/types/redirect.go index afd71823..efc35936 100644 --- a/pkg/webserver/types/redirect.go +++ b/pkg/webserver/types/redirect.go @@ -11,9 +11,9 @@ const ( // Redirect 重定向配置 type Redirect struct { - Type RedirectType // 重定向类型 - From string // 源地址,如: "example.com", "http://example.com", "/old" - To string // 目标地址,如: "https://example.com" - KeepURI bool // 是否保持 URI 不变(即保留请求参数) - StatusCode int // 自定义状态码,如: 301, 302, 307, 308,默认 308 + Type RedirectType `json:"type"` // 重定向类型 + From string `json:"from"` // 源地址,如: "example.com", "http://example.com", "/old" + To string `json:"to"` // 目标地址,如: "https://example.com" + KeepURI bool `json:"keep_uri"` // 是否保持 URI 不变(即保留请求参数) + StatusCode int `json:"status_code"` // 自定义状态码,如: 301, 302, 307, 308,默认 308 } diff --git a/pkg/webserver/types/vhost.go b/pkg/webserver/types/vhost.go index 0d8712a5..659ffb72 100644 --- a/pkg/webserver/types/vhost.go +++ b/pkg/webserver/types/vhost.go @@ -142,33 +142,33 @@ type VhostProxy interface { // Listen 监听配置 type Listen struct { - Address string // 监听地址,如: "80", "0.0.0.0:80", "[::]:443" - Args []string // 其他参数,如: ["default_server", "ssl", "quic"] + Address string `form:"address" json:"address"` // 监听地址,如: "80", "0.0.0.0:80", "[::]:443" + Args []string `form:"args" json:"args"` // 其他参数,如: ["default_server", "ssl", "quic"] } // SSLConfig SSL/TLS 配置 type SSLConfig struct { - Cert string // 证书路径 - Key string // 私钥路径 - Protocols []string // 支持的协议,如: ["TLSv1.2", "TLSv1.3"] - Ciphers string // 加密套件 + Cert string `json:"cert"` // 证书路径 + Key string `json:"key"` // 私钥路径 + Protocols []string `json:"protocols"` // 支持的协议,如: ["TLSv1.2", "TLSv1.3"] + Ciphers string `json:"ciphers"` // 加密套件 // 高级选项 - HSTS bool // HTTP 严格传输安全 - OCSP bool // OCSP Stapling - HTTPRedirect bool // HTTP 强制跳转 HTTPS - AltSvc string // Alt-Svc 配置,如: 'h3=":443"; ma=86400' + HSTS bool `json:"hsts"` // HTTP 严格传输安全 + OCSP bool `json:"ocsp"` // OCSP Stapling + HTTPRedirect bool `json:"http_redirect"` // HTTP 强制跳转 HTTPS + AltSvc string `json:"alt_svc"` // Alt-Svc 配置,如: 'h3=":443"; ma=86400' } // RateLimit 限流限速配置 type RateLimit struct { - Rate string // 速率限制,如: "512k", "10r/s" - Concurrent int // 并发连接数限制 - Zone map[string]string // 条件配置,如: map["perip"] = "10" + Rate string `json:"rate"` // 速率限制,如: "512k", "10r/s" + Concurrent int `json:"concurrent"` // 并发连接数限制 + Zone map[string]string `json:"zone"` // 条件配置,如: map["perip"] = "10" } // IncludeFile 包含文件配置 type IncludeFile struct { - Path string // 文件路径 - Comment []string // 注释说明 + Path string `json:"path"` // 文件路径 + Comment []string `json:"comment"` // 注释说明 } diff --git a/web/src/views/website/EditView.vue b/web/src/views/website/EditView.vue index 99638a30..71da78c2 100644 --- a/web/src/views/website/EditView.vue +++ b/web/src/views/website/EditView.vue @@ -11,7 +11,6 @@ import { useGettext } from 'vue3-gettext' import cert from '@/api/panel/cert' import home from '@/api/panel/home' import website from '@/api/panel/website' -import ProxyBuilderModal from '@/views/website/ProxyBuilderModal.vue' const { $gettext } = useGettext() let messageReactive: MessageReactive | null = null @@ -23,28 +22,32 @@ const { data: setting, send: fetchSetting } = useRequest(website.config(Number(i initialData: { id: 0, name: '', + type: 'proxy', listens: [], domains: [], - root: '', path: '', + root: '', index: [], - php: 0, - open_basedir: false, - https: false, - ssl_certificate: '', - ssl_certificate_key: '', + ssl: false, + ssl_cert: '', + ssl_key: '', + hsts: false, + ocsp: false, + http_redirect: false, + ssl_protocols: [], + ssl_ciphers: '', ssl_not_before: '', ssl_not_after: '', ssl_dns_names: [], ssl_issuer: '', ssl_ocsp_server: [], - http_redirect: false, - hsts: false, - ocsp: false, + access_log: '', + error_log: '', + php: 0, rewrite: '', - raw: '', - log: '', - error_log: '' + open_basedir: false, + upstreams: {}, + proxies: [] } }) const { data: installedDbAndPhp } = useRequest(home.installedDbAndPhp, { @@ -67,7 +70,6 @@ const certs = ref([]) useRequest(cert.certs(1, 10000)).onSuccess(({ data }) => { certs.value = data.items }) -const proxyBuilderModal = ref(false) const { data: rewrites } = useRequest(website.rewrites, { initialData: {} }) @@ -97,16 +99,14 @@ const handleSave = () => { if (setting.value.https && !setting.value.listens.some((item: any) => item.https)) { setting.value.listens.push({ address: '443', - https: true, - quic: true + args: ['ssl', 'quic'] }) } // 如果关闭了https,自动禁用所有https和quic if (!setting.value.https) { setting.value.listens = setting.value.listens.filter((item: any) => item.address !== '443') // 443直接删掉 setting.value.listens.forEach((item: any) => { - item.https = false - item.quic = false + item.args = [] }) } @@ -164,10 +164,22 @@ const clearLog = async () => { const onCreateListen = () => { return { address: '', - https: false, - quic: false + args: [] } } + +const toggleArg = (args: string[], arg: string, checked: boolean) => { + const index = args.indexOf(arg) + if (checked && index === -1) { + args.push(arg) + } else if (!checked && index !== -1) { + args.splice(index, 1) + } +} + +const hasArg = (args: string[], arg: string) => { + return args.includes(arg) +}