diff --git a/backend/app/api/v1/website.go b/backend/app/api/v1/website.go index 471e71bb7..9efc8546e 100644 --- a/backend/app/api/v1/website.go +++ b/backend/app/api/v1/website.go @@ -571,6 +571,28 @@ func (b *BaseApi) GetProxyConfig(c *gin.Context) { helper.SuccessWithData(c, res) } +// @Tags Website +// @Summary Delete proxy conf +// @Accept json +// @Param request body request.WebsiteProxyDel true "request" +// @Success 200 +// @Security ApiKeyAuth +// @Security Timestamp +// @Router /websites/proxies/del [post] +// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":false,"db":"websites","output_column":"primary_domain","output_value":"domain"}],"formatZH":"删除网站 [domain] 反向代理配置","formatEN":"Delete domain [domain] proxy config"} +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.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithOutData(c) +} + // @Tags Website // @Summary Update proxy conf // @Accept json diff --git a/backend/app/dto/request/website.go b/backend/app/dto/request/website.go index 4dbe8cc65..24ab62d17 100644 --- a/backend/app/dto/request/website.go +++ b/backend/app/dto/request/website.go @@ -193,6 +193,11 @@ type WebsiteProxyConfig struct { ProxySSLName string `json:"proxySSLName"` } +type WebsiteProxyDel struct { + ID uint `json:"id" validate:"required"` + Name string `json:"name" validate:"required"` +} + type WebsiteProxyReq struct { ID uint `json:"id" validate:"required"` } diff --git a/backend/app/service/website.go b/backend/app/service/website.go index 2ee218215..becb5687f 100644 --- a/backend/app/service/website.go +++ b/backend/app/service/website.go @@ -87,9 +87,12 @@ type IWebsiteService interface { LoadWebsiteDirConfig(req request.WebsiteCommonReq) (*response.WebsiteDirConfig, error) UpdateSiteDir(req request.WebsiteUpdateDir) error UpdateSitePermission(req request.WebsiteUpdateDirPermission) error + OperateProxy(req request.WebsiteProxyConfig) (err error) GetProxies(id uint) (res []request.WebsiteProxyConfig, err error) UpdateProxyFile(req request.NginxProxyUpdate) (err error) + DeleteProxy(req request.WebsiteProxyDel) (err error) + GetAuthBasics(req request.NginxAuthReq) (res response.NginxAuthRes, err error) UpdateAuthBasic(req request.NginxAuthUpdate) (err error) GetAntiLeech(id uint) (*response.NginxAntiLeechRes, error) @@ -1553,6 +1556,29 @@ func (w WebsiteService) UpdateSitePermission(req request.WebsiteUpdateDirPermiss return websiteRepo.Save(context.Background(), &website) } +func (w WebsiteService) DeleteProxy(req request.WebsiteProxyDel) (err error) { + fileOp := files.NewFileOp() + website, err := websiteRepo.GetFirst(commonRepo.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") + if !fileOp.Stat(includeDir) { + _ = fileOp.CreateDir(includeDir, 0755) + } + 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) OperateProxy(req request.WebsiteProxyConfig) (err error) { var ( website model.Website diff --git a/backend/router/ro_website.go b/backend/router/ro_website.go index 7931c8003..55b9eb6d1 100644 --- a/backend/router/ro_website.go +++ b/backend/router/ro_website.go @@ -54,6 +54,7 @@ func (a *WebsiteRouter) InitRouter(Router *gin.RouterGroup) { websiteRouter.POST("/proxies", baseApi.GetProxyConfig) websiteRouter.POST("/proxies/update", baseApi.UpdateProxyConfig) websiteRouter.POST("/proxies/file", baseApi.UpdateProxyConfigFile) + websiteRouter.POST("/proxies/del", baseApi.DeleteProxyConfig) websiteRouter.POST("/auths", baseApi.GetAuthConfig) websiteRouter.POST("/auths/update", baseApi.UpdateAuthConfig) diff --git a/frontend/src/api/interface/website.ts b/frontend/src/api/interface/website.ts index 1864971cb..215a9b2c3 100644 --- a/frontend/src/api/interface/website.ts +++ b/frontend/src/api/interface/website.ts @@ -356,6 +356,11 @@ export namespace Website { id: number; } + export interface ProxyDel { + id: number; + name: string; + } + export interface ProxyConfig { id: number; operate: string; diff --git a/frontend/src/api/modules/website.ts b/frontend/src/api/modules/website.ts index f07984b98..96f28296c 100644 --- a/frontend/src/api/modules/website.ts +++ b/frontend/src/api/modules/website.ts @@ -198,6 +198,10 @@ export const UpdateProxyConfigFile = (req: Website.ProxyFileUpdate) => { return http.post(`/websites/proxies/file`, req); }; +export const DelProxy = (req: Website.ProxyDel) => { + return http.post(`/websites/proxies/del`, req); +}; + export const GetAuthConfig = (req: Website.AuthReq) => { return http.post(`/websites/auths`, 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 638038fc4..ee9968922 100644 --- a/frontend/src/views/website/website/config/basic/proxy/index.vue +++ b/frontend/src/views/website/website/config/basic/proxy/index.vue @@ -38,7 +38,7 @@