diff --git a/agent/app/api/v2/website.go b/agent/app/api/v2/website.go index 2db6b61ee5e1..7a81ace3d0e1 100644 --- a/agent/app/api/v2/website.go +++ b/agent/app/api/v2/website.go @@ -520,6 +520,50 @@ func (b *BaseApi) UpdateProxyConfig(c *gin.Context) { helper.Success(c) } +// @Tags Website +// @Summary Delete proxy config +// @Accept json +// @Param request body request.WebsiteProxyDel true "request" +// @Success 200 +// @Security ApiKeyAuth +// @Security Timestamp +// @Router /websites/proxies/delete [post] +// @x-panel-log {"bodyKeys":["id","name"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":false,"db":"websites","output_column":"primary_domain","output_value":"domain"}],"formatZH":"删除网站 [domain] 反向代理配置 [name] ","formatEN":"Delete domain [domain] proxy config [name]"} +func (b *BaseApi) DeleteProxyConfig(c *gin.Context) { + var req request.WebsiteProxyDel + if err := helper.CheckBindAndValidate(&req, c); err != nil { + return + } + err := websiteService.DeleteProxy(req) + if err != nil { + helper.InternalServer(c, err) + return + } + helper.Success(c) +} + +// @Tags Website +// @Summary Update proxy config status +// @Accept json +// @Param request body request.WebsiteProxyStatusUpdate true "request" +// @Success 200 +// @Security ApiKeyAuth +// @Security Timestamp +// @Router /websites/proxies/status [post] +// @x-panel-log {"bodyKeys":["id","name","status"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":false,"db":"websites","output_column":"primary_domain","output_value":"domain"}],"formatZH":"更新网站 [domain] 反向代理配置 [name] 状态 [status] ","formatEN":"Update domain [domain] proxy config [name] status [status]"} +func (b *BaseApi) UpdateProxyConfigStatus(c *gin.Context) { + var req request.WebsiteProxyStatusUpdate + if err := helper.CheckBindAndValidate(&req, c); err != nil { + return + } + err := websiteService.UpdateProxyStatus(req) + if err != nil { + helper.InternalServer(c, err) + return + } + helper.Success(c) +} + // @Tags Website // @Summary Update proxy file // @Accept json diff --git a/agent/app/dto/request/website.go b/agent/app/dto/request/website.go index 8b747a4afd82..2e133643dae8 100644 --- a/agent/app/dto/request/website.go +++ b/agent/app/dto/request/website.go @@ -272,6 +272,17 @@ type WebsiteProxyConfig struct { CorsConfig } +type WebsiteProxyDelete struct { + ID uint `json:"id" validate:"required"` + Name string `json:"name" validate:"required"` +} + +type WebsiteProxyStatusUpdate struct { + ID uint `json:"id" validate:"required"` + Name string `json:"name" validate:"required"` + Status string `json:"status" validate:"required"` +} + type CorsConfig struct { Cors bool `json:"cors"` AllowOrigins string `json:"allowOrigins"` diff --git a/agent/app/service/website.go b/agent/app/service/website.go index 16a67a480c12..4341d10e8d00 100644 --- a/agent/app/service/website.go +++ b/agent/app/service/website.go @@ -110,6 +110,7 @@ type IWebsiteService interface { GetProxyCache(id uint) (res response.NginxProxyCache, err error) ClearProxyCache(req request.NginxCommonReq) error DeleteProxy(req request.WebsiteProxyDel) (err error) + UpdateProxyStatus(req request.WebsiteProxyStatusUpdate) (err error) CreateWebsiteDomain(create request.WebsiteDomainCreate) ([]model.WebsiteDomain, error) GetWebsiteDomain(websiteId uint) ([]model.WebsiteDomain, error) diff --git a/agent/app/service/website_proxy.go b/agent/app/service/website_proxy.go index ba5bd196d769..b9a3a12ab854 100644 --- a/agent/app/service/website_proxy.go +++ b/agent/app/service/website_proxy.go @@ -411,24 +411,47 @@ func (w WebsiteService) ClearProxyCache(req request.NginxCommonReq) error { } func (w WebsiteService) DeleteProxy(req request.WebsiteProxyDel) (err error) { - fileOp := files.NewFileOp() website, err := websiteRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return } - nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) - if err != nil { - return - } - includeDir := path.Join(nginxInstall.GetPath(), "www", "sites", website.Alias, "proxy") + includeDir := GetSitePath(website, SiteProxyDir) + fileOp := files.NewFileOp() if !fileOp.Stat(includeDir) { - _ = fileOp.CreateDir(includeDir, 0755) + return } fileName := fmt.Sprintf("%s.conf", req.Name) includePath := path.Join(includeDir, fileName) backName := fmt.Sprintf("%s.bak", req.Name) backPath := path.Join(includeDir, backName) + _ = fileOp.DeleteFile(includePath) _ = fileOp.DeleteFile(backPath) return updateNginxConfig(constant.NginxScopeServer, nil, &website) } + +func (w WebsiteService) UpdateProxyStatus(req request.WebsiteProxyStatusUpdate) (err error) { + website, err := websiteRepo.GetFirst(repo.WithByID(req.ID)) + if err != nil { + return + } + includeDir := GetSitePath(website, SiteProxyDir) + fileOp := files.NewFileOp() + if !fileOp.Stat(includeDir) { + return + } + fileName := fmt.Sprintf("%s.conf", req.Name) + includePath := path.Join(includeDir, fileName) + backName := fmt.Sprintf("%s.bak", req.Name) + backPath := path.Join(includeDir, backName) + + switch req.Status { + case "disable": + _ = fileOp.Rename(includePath, backPath) + return updateNginxConfig(constant.NginxScopeServer, nil, &website) + case "enable": + _ = fileOp.Rename(backPath, includePath) + return updateNginxConfig(constant.NginxScopeServer, nil, &website) + } + return errors.New("unknown status") +} diff --git a/agent/router/ro_website.go b/agent/router/ro_website.go index 6e2c177977a4..474db572134f 100644 --- a/agent/router/ro_website.go +++ b/agent/router/ro_website.go @@ -54,6 +54,8 @@ func (a *WebsiteRouter) InitRouter(Router *gin.RouterGroup) { websiteRouter.POST("/proxies", baseApi.GetProxyConfig) websiteRouter.POST("/proxies/update", baseApi.UpdateProxyConfig) + websiteRouter.POST("/proxies/delete", baseApi.DeleteProxyConfig) + websiteRouter.POST("/proxies/status", baseApi.UpdateProxyConfigStatus) websiteRouter.POST("/proxies/file", baseApi.UpdateProxyConfigFile) websiteRouter.POST("/proxy/config", baseApi.UpdateProxyCache) websiteRouter.GET("/proxy/config/:id", baseApi.GetProxyCache) diff --git a/core/cmd/server/docs/docs.go b/core/cmd/server/docs/docs.go index b0ee87206df5..b2cd7c2ef223 100644 --- a/core/cmd/server/docs/docs.go +++ b/core/cmd/server/docs/docs.go @@ -20510,6 +20510,60 @@ const docTemplate = `{ ] } }, + "/websites/proxies/delete": { + "post": { + "consumes": [ + "application/json" + ], + "parameters": [ + { + "description": "request", + "in": "body", + "name": "request", + "required": true, + "schema": { + "$ref": "#/definitions/request.WebsiteProxyDel" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + }, + "security": [ + { + "ApiKeyAuth": [] + }, + { + "Timestamp": [] + } + ], + "summary": "Delete proxy config", + "tags": [ + "Website" + ], + "x-panel-log": { + "BeforeFunctions": [ + { + "db": "websites", + "input_column": "id", + "input_value": "id", + "isList": false, + "output_column": "primary_domain", + "output_value": "domain" + } + ], + "bodyKeys": [ + "id", + "name" + ], + "formatEN": "Delete domain [domain] proxy config [name]", + "formatZH": "删除网站 [domain] 反向代理配置 [name] ", + "paramKeys": [] + } + } + }, "/websites/proxies/file": { "post": { "consumes": [ @@ -20563,6 +20617,61 @@ const docTemplate = `{ } } }, + "/websites/proxies/status": { + "post": { + "consumes": [ + "application/json" + ], + "parameters": [ + { + "description": "request", + "in": "body", + "name": "request", + "required": true, + "schema": { + "$ref": "#/definitions/request.WebsiteProxyStatusUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + }, + "security": [ + { + "ApiKeyAuth": [] + }, + { + "Timestamp": [] + } + ], + "summary": "Update proxy config status", + "tags": [ + "Website" + ], + "x-panel-log": { + "BeforeFunctions": [ + { + "db": "websites", + "input_column": "id", + "input_value": "id", + "isList": false, + "output_column": "primary_domain", + "output_value": "domain" + } + ], + "bodyKeys": [ + "id", + "name", + "status" + ], + "formatEN": "Update domain [domain] proxy config [name] status [status]", + "formatZH": "更新网站 [domain] 反向代理配置 [name] 状态 [status] ", + "paramKeys": [] + } + } + }, "/websites/proxies/update": { "post": { "consumes": [ @@ -32463,6 +32572,21 @@ const docTemplate = `{ ], "type": "object" }, + "request.WebsiteProxyDel": { + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + }, + "required": [ + "id", + "name" + ], + "type": "object" + }, "request.WebsiteProxyReq": { "properties": { "id": { @@ -32474,6 +32598,25 @@ const docTemplate = `{ ], "type": "object" }, + "request.WebsiteProxyStatusUpdate": { + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "status": { + "type": "string" + } + }, + "required": [ + "id", + "name", + "status" + ], + "type": "object" + }, "request.WebsiteRealIP": { "properties": { "ipFrom": { diff --git a/core/cmd/server/docs/swagger.json b/core/cmd/server/docs/swagger.json index 817f1571f59e..45ef9ff82924 100644 --- a/core/cmd/server/docs/swagger.json +++ b/core/cmd/server/docs/swagger.json @@ -20506,6 +20506,60 @@ ] } }, + "/websites/proxies/delete": { + "post": { + "consumes": [ + "application/json" + ], + "parameters": [ + { + "description": "request", + "in": "body", + "name": "request", + "required": true, + "schema": { + "$ref": "#/definitions/request.WebsiteProxyDel" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + }, + "security": [ + { + "ApiKeyAuth": [] + }, + { + "Timestamp": [] + } + ], + "summary": "Delete proxy config", + "tags": [ + "Website" + ], + "x-panel-log": { + "BeforeFunctions": [ + { + "db": "websites", + "input_column": "id", + "input_value": "id", + "isList": false, + "output_column": "primary_domain", + "output_value": "domain" + } + ], + "bodyKeys": [ + "id", + "name" + ], + "formatEN": "Delete domain [domain] proxy config [name]", + "formatZH": "删除网站 [domain] 反向代理配置 [name] ", + "paramKeys": [] + } + } + }, "/websites/proxies/file": { "post": { "consumes": [ @@ -20559,6 +20613,61 @@ } } }, + "/websites/proxies/status": { + "post": { + "consumes": [ + "application/json" + ], + "parameters": [ + { + "description": "request", + "in": "body", + "name": "request", + "required": true, + "schema": { + "$ref": "#/definitions/request.WebsiteProxyStatusUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + }, + "security": [ + { + "ApiKeyAuth": [] + }, + { + "Timestamp": [] + } + ], + "summary": "Update proxy config status", + "tags": [ + "Website" + ], + "x-panel-log": { + "BeforeFunctions": [ + { + "db": "websites", + "input_column": "id", + "input_value": "id", + "isList": false, + "output_column": "primary_domain", + "output_value": "domain" + } + ], + "bodyKeys": [ + "id", + "name", + "status" + ], + "formatEN": "Update domain [domain] proxy config [name] status [status]", + "formatZH": "更新网站 [domain] 反向代理配置 [name] 状态 [status] ", + "paramKeys": [] + } + } + }, "/websites/proxies/update": { "post": { "consumes": [ @@ -32459,6 +32568,21 @@ ], "type": "object" }, + "request.WebsiteProxyDel": { + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + }, + "required": [ + "id", + "name" + ], + "type": "object" + }, "request.WebsiteProxyReq": { "properties": { "id": { @@ -32470,6 +32594,25 @@ ], "type": "object" }, + "request.WebsiteProxyStatusUpdate": { + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "status": { + "type": "string" + } + }, + "required": [ + "id", + "name", + "status" + ], + "type": "object" + }, "request.WebsiteRealIP": { "properties": { "ipFrom": { diff --git a/core/cmd/server/docs/x-log.json b/core/cmd/server/docs/x-log.json index 34803dd8b653..f312f4a729dd 100644 --- a/core/cmd/server/docs/x-log.json +++ b/core/cmd/server/docs/x-log.json @@ -3008,6 +3008,25 @@ "formatZH": "php 版本变更 [domain]", "formatEN": "php version update [domain]" }, + "/websites/proxies/delete": { + "bodyKeys": [ + "id", + "name" + ], + "paramKeys": [], + "beforeFunctions": [ + { + "input_column": "id", + "input_value": "id", + "isList": false, + "db": "websites", + "output_column": "primary_domain", + "output_value": "domain" + } + ], + "formatZH": "删除网站 [domain] 反向代理配置 [name] ", + "formatEN": "Delete domain [domain] proxy config [name]" + }, "/websites/proxies/file": { "bodyKeys": [ "websiteID" @@ -3026,6 +3045,26 @@ "formatZH": "更新反向代理文件 [domain]", "formatEN": "Nginx conf proxy file update [domain]" }, + "/websites/proxies/status": { + "bodyKeys": [ + "id", + "name", + "status" + ], + "paramKeys": [], + "beforeFunctions": [ + { + "input_column": "id", + "input_value": "id", + "isList": false, + "db": "websites", + "output_column": "primary_domain", + "output_value": "domain" + } + ], + "formatZH": "更新网站 [domain] 反向代理配置 [name] 状态 [status] ", + "formatEN": "Update domain [domain] proxy config [name] status [status]" + }, "/websites/proxies/update": { "bodyKeys": [ "id" diff --git a/frontend/src/api/interface/website.ts b/frontend/src/api/interface/website.ts index 23c399ef27dd..718dd90b9a45 100644 --- a/frontend/src/api/interface/website.ts +++ b/frontend/src/api/interface/website.ts @@ -448,6 +448,17 @@ export namespace Website { browserCache?: 'enable' | 'disable' | 'noModify'; } + export interface ProxyDel { + id: number; + name: string; + } + + export interface ProxyStatusUpdate { + id: number; + name: string; + status: string; + } + export interface ProxReplace { [key: string]: string; } diff --git a/frontend/src/api/modules/website.ts b/frontend/src/api/modules/website.ts index 77af614cde7a..67d852268681 100644 --- a/frontend/src/api/modules/website.ts +++ b/frontend/src/api/modules/website.ts @@ -188,6 +188,14 @@ export const operateProxyConfig = (req: Website.ProxyReq) => { return http.post(`/websites/proxies/update`, req); }; +export const deleteProxyConfig = (req: Website.ProxyDel) => { + return http.post(`/websites/proxies/delete`, req); +}; + +export const updateProxyConfigStatus = (req: Website.ProxyStatusUpdate) => { + return http.post(`/websites/proxies/status`, req); +}; + export const updateProxyConfigFile = (req: Website.ProxyFileUpdate) => { return http.post(`/websites/proxies/file`, req); }; diff --git a/frontend/src/views/website/website/config/basic/proxy/index.vue b/frontend/src/views/website/website/config/basic/proxy/index.vue index 0d7446d85840..9463d2a805c0 100644 --- a/frontend/src/views/website/website/config/basic/proxy/index.vue +++ b/frontend/src/views/website/website/config/basic/proxy/index.vue @@ -45,7 +45,7 @@