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:
parent
4dee4e1cc2
commit
99f62b7230
@ -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
|
||||
|
@ -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"`
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -356,6 +356,11 @@ export namespace Website {
|
||||
id: number;
|
||||
}
|
||||
|
||||
export interface ProxyDel {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface ProxyConfig {
|
||||
id: number;
|
||||
operate: string;
|
||||
|
@ -198,6 +198,10 @@ export const UpdateProxyConfigFile = (req: Website.ProxyFileUpdate) => {
|
||||
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) => {
|
||||
return http.post<Website.AuthConfig>(`/websites/auths`, req);
|
||||
};
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
<script lang="ts" setup name="proxy">
|
||||
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 Create from './create/index.vue';
|
||||
import File from './file/index.vue';
|
||||
@ -108,6 +108,8 @@ const initData = (id: number): Website.ProxyConfig => ({
|
||||
proxyPass: 'http://',
|
||||
proxyHost: '$host',
|
||||
replaces: {},
|
||||
sni: false,
|
||||
proxySSLName: '',
|
||||
});
|
||||
|
||||
const openCreate = () => {
|
||||
@ -128,7 +130,10 @@ const openEditFile = (proxyConfig: Website.ProxyConfig) => {
|
||||
};
|
||||
|
||||
const deleteProxy = async (proxyConfig: Website.ProxyConfig) => {
|
||||
proxyConfig.operate = 'delete';
|
||||
const del = {
|
||||
id: proxyConfig.id,
|
||||
name: proxyConfig.name,
|
||||
};
|
||||
opRef.value.acceptParams({
|
||||
title: i18n.global.t('commons.msg.deleteTitle'),
|
||||
names: [proxyConfig.name],
|
||||
@ -136,8 +141,8 @@ const deleteProxy = async (proxyConfig: Website.ProxyConfig) => {
|
||||
i18n.global.t('website.proxy'),
|
||||
i18n.global.t('commons.button.delete'),
|
||||
]),
|
||||
api: OperateProxyConfig,
|
||||
params: proxyConfig,
|
||||
api: DelProxy,
|
||||
params: del,
|
||||
});
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user