-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(website):Fix Reverse Proxy Deletion Failure in Certain Scenarios #7709
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet contains several discrepancies that need to be addressed:
Here's an updated version with some basic improvements: package website_service
import (
"fmt"
)
// type definitions omitted for brevity
type WebsiteService struct {
...
}
// Other methods remain unchanged ...
func (w *WebsiteService) DeleteProxy(req request.WebsiteProxyDel) error {
// Add necessary logic here...
err := fileOp.DeleteFile(path.Join(includeDir, req.Name+".conf"))
if err != nil {
return err
}
log.Info("Deleted Proxy File:", includePath)
return nil
}
// Similarly, add log statements and other necessary checks for OperateProxy method Ensure you have the appropriate imports and handle all potential edge cases such as directory existence checks before operations like reading or writing files. Adjust logging levels based on your application's needs. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,16 +130,19 @@ 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], | ||
msg: i18n.global.t('commons.msg.operatorHelper', [ | ||
i18n.global.t('website.proxy'), | ||
i18n.global.t('commons.button.delete'), | ||
]), | ||
api: OperateProxyConfig, | ||
params: proxyConfig, | ||
api: DelProxy, | ||
params: del, | ||
}); | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code has a few adjustments and optimizations that can be made. Here's a concise analysis:
Here's an optimized version of the relevant section: const openCreate = () => {...};
const openEditFile = (proxyConfig: Website.ProxyConfig) => {...};
const deleteProxy = async (proxyConfig: Website.ProxyConfig) => {
// Create a clean object containing only necessary parameters
const del = { id: proxyConfig.id, name: proxyConfig.name };
opRef.value.acceptParams({
title: i18n.global.t('commons.msg.deleteTitle'),
names: [proxyConfig.name],
msg: i18n.global.t('commons.msg.operatorHelper', [
i18n.global.t('website.proxy'),
i18n.global.t('commons.button.delete')
]),
api: DelProxy,
params: del, // Use this cleaned-up object for deletion
});
}; By making these adjustments, the code will be clearer and potentially slightly faster due to reduced redundancy in parameter passing. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, there are no irregularities or significant issues with this code. The changes align well with standard RESTful API structure and security practices for handling delete requests related to websites' proxy configurations. However, here is a suggestion:
websiteService.DeleteProxy
method actually handles errors correctly, especially if it interacts with external systems like databases or servers.