mirror of https://github.com/1Panel-dev/1Panel
feat: 增加nginx源文设置
parent
93123bbaa7
commit
c30f39185e
|
@ -40,5 +40,7 @@ var (
|
|||
websiteSSLService = service.ServiceGroupApp.WebSiteSSLService
|
||||
websiteAcmeAccountService = service.ServiceGroupApp.WebSiteAcmeAccountService
|
||||
|
||||
nginxService = service.ServiceGroupApp.NginxService
|
||||
|
||||
logService = service.ServiceGroupApp.LogService
|
||||
)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (b *BaseApi) GetNginx(c *gin.Context) {
|
||||
|
||||
fileInfo, err := nginxService.GetNginxConfig()
|
||||
if err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||
return
|
||||
}
|
||||
helper.SuccessWithData(c, fileInfo)
|
||||
}
|
|
@ -33,6 +33,8 @@ type ServiceGroup struct {
|
|||
WebSiteSSLService
|
||||
WebSiteAcmeAccountService
|
||||
|
||||
NginxService
|
||||
|
||||
LogService
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
||||
"path"
|
||||
)
|
||||
|
||||
type NginxService struct {
|
||||
}
|
||||
|
||||
func (w NginxService) GetNginxConfig() (dto.FileInfo, error) {
|
||||
nginxApp, err := appRepo.GetFirst(appRepo.WithKey("nginx"))
|
||||
if err != nil {
|
||||
return dto.FileInfo{}, err
|
||||
}
|
||||
nginxInstall, err := appInstallRepo.GetFirst(appInstallRepo.WithAppId(nginxApp.ID))
|
||||
if err != nil {
|
||||
return dto.FileInfo{}, err
|
||||
}
|
||||
|
||||
configPath := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name, "conf", "nginx.conf")
|
||||
|
||||
info, err := files.NewFileInfo(files.FileOption{
|
||||
Path: configPath,
|
||||
Expand: true,
|
||||
})
|
||||
if err != nil {
|
||||
return dto.FileInfo{}, err
|
||||
}
|
||||
return dto.FileInfo{FileInfo: *info}, nil
|
||||
}
|
|
@ -85,6 +85,7 @@ func Routers() *gin.Engine {
|
|||
systemRouter.InitDatabaseRouter(PrivateGroup)
|
||||
systemRouter.InitWebsiteSSLRouter(PrivateGroup)
|
||||
systemRouter.InitWebsiteAcmeAccountRouter(PrivateGroup)
|
||||
systemRouter.InitNginxRouter(PrivateGroup)
|
||||
}
|
||||
|
||||
return Router
|
||||
|
|
|
@ -20,6 +20,7 @@ type RouterGroup struct {
|
|||
WebsiteAcmeAccountRouter
|
||||
WebsiteSSLRouter
|
||||
DatabaseRouter
|
||||
NginxRouter
|
||||
}
|
||||
|
||||
var RouterGroupApp = new(RouterGroup)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
v1 "github.com/1Panel-dev/1Panel/backend/app/api/v1"
|
||||
"github.com/1Panel-dev/1Panel/backend/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type NginxRouter struct {
|
||||
}
|
||||
|
||||
func (a *NginxRouter) InitNginxRouter(Router *gin.RouterGroup) {
|
||||
groupRouter := Router.Group("nginx")
|
||||
groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth())
|
||||
|
||||
baseApi := v1.ApiGroupApp.BaseApi
|
||||
{
|
||||
groupRouter.GET("", baseApi.GetNginx)
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
export namespace Nginx {}
|
|
@ -0,0 +1,6 @@
|
|||
import http from '@/api';
|
||||
import { File } from '../interface/file';
|
||||
|
||||
export const GetNginx = () => {
|
||||
return http.get<File.File>(`/nginx`);
|
||||
};
|
|
@ -753,5 +753,10 @@ export default {
|
|||
lastBackupAt: '上次备份时间',
|
||||
null: '无',
|
||||
nginxConfig: 'Nginx配置',
|
||||
websiteConfig: '网站设置',
|
||||
basic: '基本',
|
||||
source: '源文',
|
||||
security: '安全',
|
||||
backup: '备份',
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
<template>
|
||||
<LayoutContent :header="'网站设置'" :back-name="'Website'">
|
||||
<el-tabs v-model="index" @click="changeTab(index)">
|
||||
<el-tab-pane label="基本" name="basic">
|
||||
<Basic :key="id" :id="id" v-if="index === 'basic'"></Basic>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="安全" name="safety">
|
||||
<Safety :key="id" :id="id" v-if="index === 'safety'"></Safety>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="备份">反代</el-tab-pane>
|
||||
<el-tab-pane label="源文" name="resource">
|
||||
<Resource :key="id" :id="id" v-if="index === 'resource'"></Resource>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</LayoutContent>
|
||||
<el-card>
|
||||
<LayoutContent :header="$t('website.websiteConfig')" :back-name="'Website'">
|
||||
<el-tabs v-model="index" @click="changeTab(index)">
|
||||
<el-tab-pane :label="$t('website.basic')" name="basic">
|
||||
<Basic :key="id" :id="id" v-if="index === 'basic'"></Basic>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="$t('website.security')" name="safety">
|
||||
<Safety :key="id" :id="id" v-if="index === 'safety'"></Safety>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="$t('website.backup')">反代</el-tab-pane>
|
||||
<el-tab-pane :label="$t('website.source')" name="resource">
|
||||
<Resource :key="id" :id="id" v-if="index === 'resource'"></Resource>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</LayoutContent>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
<template>
|
||||
<LayoutContent :header="$t('website.nginxConfig')" :reload="true"></LayoutContent>
|
||||
<LayoutContent :header="$t('website.nginxConfig')" :reload="true">
|
||||
<el-collapse v-model="activeName" accordion>
|
||||
<el-collapse-item :title="$t('website.source')" name="1">
|
||||
<Source></Source>
|
||||
</el-collapse-item>
|
||||
</el-collapse>
|
||||
</LayoutContent>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import LayoutContent from '@/layout/layout-content.vue';
|
||||
import Source from './source/index.vue';
|
||||
import { ref } from 'vue';
|
||||
|
||||
let activeName = ref('1');
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
<template>
|
||||
<div>
|
||||
<codemirror
|
||||
:autofocus="true"
|
||||
placeholder="None data"
|
||||
:indent-with-tab="true"
|
||||
:tabSize="4"
|
||||
style="margin-top: 10px; max-height: 500px"
|
||||
:lineWrapping="true"
|
||||
:matchBrackets="true"
|
||||
theme="cobalt"
|
||||
:styleActiveLine="true"
|
||||
:extensions="extensions"
|
||||
v-model="content"
|
||||
:readOnly="true"
|
||||
/>
|
||||
<div style="float: right; margin-top: 10px">
|
||||
<el-button type="primary" @click="submit()" :loading="loading">
|
||||
{{ $t('commons.button.save') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { GetNginx } from '@/api/modules/nginx';
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { Codemirror } from 'vue-codemirror';
|
||||
import { javascript } from '@codemirror/lang-javascript';
|
||||
import { oneDark } from '@codemirror/theme-one-dark';
|
||||
import { SaveFileContent } from '@/api/modules/files';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import i18n from '@/lang';
|
||||
|
||||
const extensions = [javascript(), oneDark];
|
||||
|
||||
let data = ref();
|
||||
let content = ref('');
|
||||
let loading = ref(false);
|
||||
|
||||
const submit = () => {
|
||||
loading.value = true;
|
||||
SaveFileContent({
|
||||
path: data.value.path,
|
||||
content: content.value,
|
||||
})
|
||||
.then(() => {
|
||||
ElMessage.success(i18n.global.t('commons.msg.updateSuccess'));
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
};
|
||||
|
||||
const getNginx = async () => {
|
||||
const res = await GetNginx();
|
||||
data.value = res.data;
|
||||
content.value = data.value.content;
|
||||
console.log(content.value);
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getNginx();
|
||||
});
|
||||
</script>
|
Loading…
Reference in New Issue