Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions agent/app/api/v2/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions agent/app/dto/request/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions agent/app/service/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 30 additions & 7 deletions agent/app/service/website_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 2 additions & 0 deletions agent/router/ro_website.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
143 changes: 143 additions & 0 deletions core/cmd/server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down
Loading
Loading