1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 00:09:16 +08:00

fix(website):Fix Reverse Proxy Deletion Failure in Certain Scenarios (#7709)

Refs https://github.com/1Panel-dev/1Panel/issues/7701
This commit is contained in:
zhengkunwang 2025-01-13 23:08:04 +08:00 committed by GitHub
parent 4dee4e1cc2
commit 99f62b7230
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 72 additions and 4 deletions

View File

@ -571,6 +571,28 @@ func (b *BaseApi) GetProxyConfig(c *gin.Context) {
helper.SuccessWithData(c, res) 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 // @Tags Website
// @Summary Update proxy conf // @Summary Update proxy conf
// @Accept json // @Accept json

View File

@ -193,6 +193,11 @@ type WebsiteProxyConfig struct {
ProxySSLName string `json:"proxySSLName"` ProxySSLName string `json:"proxySSLName"`
} }
type WebsiteProxyDel struct {
ID uint `json:"id" validate:"required"`
Name string `json:"name" validate:"required"`
}
type WebsiteProxyReq struct { type WebsiteProxyReq struct {
ID uint `json:"id" validate:"required"` ID uint `json:"id" validate:"required"`
} }

View File

@ -87,9 +87,12 @@ type IWebsiteService interface {
LoadWebsiteDirConfig(req request.WebsiteCommonReq) (*response.WebsiteDirConfig, error) LoadWebsiteDirConfig(req request.WebsiteCommonReq) (*response.WebsiteDirConfig, error)
UpdateSiteDir(req request.WebsiteUpdateDir) error UpdateSiteDir(req request.WebsiteUpdateDir) error
UpdateSitePermission(req request.WebsiteUpdateDirPermission) error UpdateSitePermission(req request.WebsiteUpdateDirPermission) error
OperateProxy(req request.WebsiteProxyConfig) (err error) OperateProxy(req request.WebsiteProxyConfig) (err error)
GetProxies(id uint) (res []request.WebsiteProxyConfig, err error) GetProxies(id uint) (res []request.WebsiteProxyConfig, err error)
UpdateProxyFile(req request.NginxProxyUpdate) (err error) UpdateProxyFile(req request.NginxProxyUpdate) (err error)
DeleteProxy(req request.WebsiteProxyDel) (err error)
GetAuthBasics(req request.NginxAuthReq) (res response.NginxAuthRes, err error) GetAuthBasics(req request.NginxAuthReq) (res response.NginxAuthRes, err error)
UpdateAuthBasic(req request.NginxAuthUpdate) (err error) UpdateAuthBasic(req request.NginxAuthUpdate) (err error)
GetAntiLeech(id uint) (*response.NginxAntiLeechRes, error) GetAntiLeech(id uint) (*response.NginxAntiLeechRes, error)
@ -1553,6 +1556,29 @@ func (w WebsiteService) UpdateSitePermission(req request.WebsiteUpdateDirPermiss
return websiteRepo.Save(context.Background(), &website) 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) { func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) {
var ( var (
website model.Website website model.Website

View File

@ -54,6 +54,7 @@ func (a *WebsiteRouter) InitRouter(Router *gin.RouterGroup) {
websiteRouter.POST("/proxies", baseApi.GetProxyConfig) websiteRouter.POST("/proxies", baseApi.GetProxyConfig)
websiteRouter.POST("/proxies/update", baseApi.UpdateProxyConfig) websiteRouter.POST("/proxies/update", baseApi.UpdateProxyConfig)
websiteRouter.POST("/proxies/file", baseApi.UpdateProxyConfigFile) websiteRouter.POST("/proxies/file", baseApi.UpdateProxyConfigFile)
websiteRouter.POST("/proxies/del", baseApi.DeleteProxyConfig)
websiteRouter.POST("/auths", baseApi.GetAuthConfig) websiteRouter.POST("/auths", baseApi.GetAuthConfig)
websiteRouter.POST("/auths/update", baseApi.UpdateAuthConfig) websiteRouter.POST("/auths/update", baseApi.UpdateAuthConfig)

View File

@ -356,6 +356,11 @@ export namespace Website {
id: number; id: number;
} }
export interface ProxyDel {
id: number;
name: string;
}
export interface ProxyConfig { export interface ProxyConfig {
id: number; id: number;
operate: string; operate: string;

View File

@ -198,6 +198,10 @@ export const UpdateProxyConfigFile = (req: Website.ProxyFileUpdate) => {
return http.post<any>(`/websites/proxies/file`, req); return http.post<any>(`/websites/proxies/file`, req);
}; };
export const DelProxy = (req: Website.ProxyDel) => {
return http.post<any>(`/websites/proxies/del`, req);
};
export const GetAuthConfig = (req: Website.AuthReq) => { export const GetAuthConfig = (req: Website.AuthReq) => {
return http.post<Website.AuthConfig>(`/websites/auths`, req); return http.post<Website.AuthConfig>(`/websites/auths`, req);
}; };

View File

@ -38,7 +38,7 @@
<script lang="ts" setup name="proxy"> <script lang="ts" setup name="proxy">
import { Website } from '@/api/interface/website'; import { Website } from '@/api/interface/website';
import { OperateProxyConfig, GetProxyConfig } from '@/api/modules/website'; import { OperateProxyConfig, GetProxyConfig, DelProxy } from '@/api/modules/website';
import { computed, onMounted, ref } from 'vue'; import { computed, onMounted, ref } from 'vue';
import Create from './create/index.vue'; import Create from './create/index.vue';
import File from './file/index.vue'; import File from './file/index.vue';
@ -108,6 +108,8 @@ const initData = (id: number): Website.ProxyConfig => ({
proxyPass: 'http://', proxyPass: 'http://',
proxyHost: '$host', proxyHost: '$host',
replaces: {}, replaces: {},
sni: false,
proxySSLName: '',
}); });
const openCreate = () => { const openCreate = () => {
@ -128,7 +130,10 @@ const openEditFile = (proxyConfig: Website.ProxyConfig) => {
}; };
const deleteProxy = async (proxyConfig: Website.ProxyConfig) => { const deleteProxy = async (proxyConfig: Website.ProxyConfig) => {
proxyConfig.operate = 'delete'; const del = {
id: proxyConfig.id,
name: proxyConfig.name,
};
opRef.value.acceptParams({ opRef.value.acceptParams({
title: i18n.global.t('commons.msg.deleteTitle'), title: i18n.global.t('commons.msg.deleteTitle'),
names: [proxyConfig.name], names: [proxyConfig.name],
@ -136,8 +141,8 @@ const deleteProxy = async (proxyConfig: Website.ProxyConfig) => {
i18n.global.t('website.proxy'), i18n.global.t('website.proxy'),
i18n.global.t('commons.button.delete'), i18n.global.t('commons.button.delete'),
]), ]),
api: OperateProxyConfig, api: DelProxy,
params: proxyConfig, params: del,
}); });
}; };