mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-02-01 06:28:06 +08:00
feat: 修改网站nginx配置文件 reload
This commit is contained in:
parent
78a437d0ca
commit
0f739b4afa
@ -304,3 +304,16 @@ func (b *BaseApi) UpdateWebsiteWafConfig(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
helper.SuccessWithData(c, nil)
|
helper.SuccessWithData(c, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BaseApi) UpdateWebsiteNginxConfig(c *gin.Context) {
|
||||||
|
var req request.WebsiteNginxUpdate
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := websiteService.UpdateNginxConfigFile(req); err != nil {
|
||||||
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
helper.SuccessWithData(c, nil)
|
||||||
|
}
|
||||||
|
@ -103,3 +103,8 @@ type WebsiteHTTPSOp struct {
|
|||||||
PrivateKey string `json:"privateKey"`
|
PrivateKey string `json:"privateKey"`
|
||||||
Certificate string `json:"certificate"`
|
Certificate string `json:"certificate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type WebsiteNginxUpdate struct {
|
||||||
|
ID uint `json:"id" validate:"required"`
|
||||||
|
Content string `json:"content" validate:"required"`
|
||||||
|
}
|
||||||
|
@ -653,7 +653,7 @@ func (w WebsiteService) GetWafConfig(req request.WebsiteWafReq) (response.Websit
|
|||||||
func (w WebsiteService) UpdateWafConfig(req request.WebsiteWafUpdate) error {
|
func (w WebsiteService) UpdateWafConfig(req request.WebsiteWafUpdate) error {
|
||||||
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID))
|
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
updateValue := "on"
|
updateValue := "on"
|
||||||
if !req.Enable {
|
if !req.Enable {
|
||||||
@ -663,3 +663,19 @@ func (w WebsiteService) UpdateWafConfig(req request.WebsiteWafUpdate) error {
|
|||||||
{Name: "set", Params: []string{req.Key, updateValue}},
|
{Name: "set", Params: []string{req.Key, updateValue}},
|
||||||
}, &website)
|
}, &website)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w WebsiteService) UpdateNginxConfigFile(req request.WebsiteNginxUpdate) error {
|
||||||
|
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
nginxFull, err := getNginxFull(&website)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
filePath := nginxFull.SiteConfig.FilePath
|
||||||
|
if err := files.NewFileOp().WriteFile(filePath, strings.NewReader(req.Content), 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nginxCheckAndReload(nginxFull.SiteConfig.OldContent, filePath, nginxFull.Install.ContainerName)
|
||||||
|
}
|
||||||
|
@ -38,5 +38,6 @@ func (a *WebsiteRouter) InitWebsiteRouter(Router *gin.RouterGroup) {
|
|||||||
groupRouter.POST("/:id/https", baseApi.UpdateHTTPSConfig)
|
groupRouter.POST("/:id/https", baseApi.UpdateHTTPSConfig)
|
||||||
groupRouter.POST("/waf/config", baseApi.GetWebsiteWafConfig)
|
groupRouter.POST("/waf/config", baseApi.GetWebsiteWafConfig)
|
||||||
groupRouter.POST("/waf/update", baseApi.UpdateWebsiteWafConfig)
|
groupRouter.POST("/waf/update", baseApi.UpdateWebsiteWafConfig)
|
||||||
|
groupRouter.POST("/nginx/update", baseApi.UpdateWebsiteNginxConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,4 +247,9 @@ export namespace Website {
|
|||||||
export interface BackupReq {
|
export interface BackupReq {
|
||||||
id: number;
|
id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface NginxUpdate {
|
||||||
|
id: number;
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,3 +162,7 @@ export const GetWafConfig = (req: Website.WafReq) => {
|
|||||||
export const UpdateWafEnable = (req: Website.WafUpdate) => {
|
export const UpdateWafEnable = (req: Website.WafUpdate) => {
|
||||||
return http.post<any>(`/websites/waf/update`, req);
|
return http.post<any>(`/websites/waf/update`, req);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const UpdateNginxFile = (req: Website.NginxUpdate) => {
|
||||||
|
return http.post<any>(`/websites/nginx/update`, req);
|
||||||
|
};
|
||||||
|
@ -939,6 +939,7 @@ export default {
|
|||||||
status: '当前状态',
|
status: '当前状态',
|
||||||
nginxConfig: 'OpenResty 设置',
|
nginxConfig: 'OpenResty 设置',
|
||||||
configResource: '配置修改',
|
configResource: '配置修改',
|
||||||
|
saveAndReload: '保存并重载',
|
||||||
},
|
},
|
||||||
ssl: {
|
ssl: {
|
||||||
provider: '类型',
|
provider: '类型',
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
/>
|
/>
|
||||||
<div style="margin-top: 10px">
|
<div style="margin-top: 10px">
|
||||||
<el-button type="primary" @click="submit()" :loading="loading">
|
<el-button type="primary" @click="submit()" :loading="loading">
|
||||||
{{ $t('commons.button.save') }}
|
{{ $t('nginx.saveAndReload') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -24,10 +24,9 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { Codemirror } from 'vue-codemirror';
|
import { Codemirror } from 'vue-codemirror';
|
||||||
import { oneDark } from '@codemirror/theme-one-dark';
|
import { oneDark } from '@codemirror/theme-one-dark';
|
||||||
import { GetWebsiteNginx } from '@/api/modules/website';
|
import { GetWebsiteNginx, UpdateNginxFile } from '@/api/modules/website';
|
||||||
import { computed, onMounted, ref } from 'vue';
|
import { computed, onMounted, ref } from 'vue';
|
||||||
import { File } from '@/api/interface/file';
|
import { File } from '@/api/interface/file';
|
||||||
import { SaveFileContent } from '@/api/modules/files';
|
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
||||||
import i18n from '@/lang';
|
import i18n from '@/lang';
|
||||||
import { StreamLanguage } from '@codemirror/language';
|
import { StreamLanguage } from '@codemirror/language';
|
||||||
@ -64,8 +63,8 @@ const get = () => {
|
|||||||
|
|
||||||
const submit = () => {
|
const submit = () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
SaveFileContent({
|
UpdateNginxFile({
|
||||||
path: data.value.path,
|
id: id.value,
|
||||||
content: content.value,
|
content: content.value,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user