mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
feat: 增加nginx源文设置
This commit is contained in:
parent
93123bbaa7
commit
c30f39185e
@ -40,5 +40,7 @@ var (
|
|||||||
websiteSSLService = service.ServiceGroupApp.WebSiteSSLService
|
websiteSSLService = service.ServiceGroupApp.WebSiteSSLService
|
||||||
websiteAcmeAccountService = service.ServiceGroupApp.WebSiteAcmeAccountService
|
websiteAcmeAccountService = service.ServiceGroupApp.WebSiteAcmeAccountService
|
||||||
|
|
||||||
|
nginxService = service.ServiceGroupApp.NginxService
|
||||||
|
|
||||||
logService = service.ServiceGroupApp.LogService
|
logService = service.ServiceGroupApp.LogService
|
||||||
)
|
)
|
||||||
|
17
backend/app/api/v1/nginx.go
Normal file
17
backend/app/api/v1/nginx.go
Normal file
@ -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
|
WebSiteSSLService
|
||||||
WebSiteAcmeAccountService
|
WebSiteAcmeAccountService
|
||||||
|
|
||||||
|
NginxService
|
||||||
|
|
||||||
LogService
|
LogService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
33
backend/app/service/nginx.go
Normal file
33
backend/app/service/nginx.go
Normal file
@ -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.InitDatabaseRouter(PrivateGroup)
|
||||||
systemRouter.InitWebsiteSSLRouter(PrivateGroup)
|
systemRouter.InitWebsiteSSLRouter(PrivateGroup)
|
||||||
systemRouter.InitWebsiteAcmeAccountRouter(PrivateGroup)
|
systemRouter.InitWebsiteAcmeAccountRouter(PrivateGroup)
|
||||||
|
systemRouter.InitNginxRouter(PrivateGroup)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Router
|
return Router
|
||||||
|
@ -20,6 +20,7 @@ type RouterGroup struct {
|
|||||||
WebsiteAcmeAccountRouter
|
WebsiteAcmeAccountRouter
|
||||||
WebsiteSSLRouter
|
WebsiteSSLRouter
|
||||||
DatabaseRouter
|
DatabaseRouter
|
||||||
|
NginxRouter
|
||||||
}
|
}
|
||||||
|
|
||||||
var RouterGroupApp = new(RouterGroup)
|
var RouterGroupApp = new(RouterGroup)
|
||||||
|
20
backend/router/ro_nginx.go
Normal file
20
backend/router/ro_nginx.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
1
frontend/src/api/interface/nginx.ts
Normal file
1
frontend/src/api/interface/nginx.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export namespace Nginx {}
|
6
frontend/src/api/modules/nginx.ts
Normal file
6
frontend/src/api/modules/nginx.ts
Normal file
@ -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: '上次备份时间',
|
lastBackupAt: '上次备份时间',
|
||||||
null: '无',
|
null: '无',
|
||||||
nginxConfig: 'Nginx配置',
|
nginxConfig: 'Nginx配置',
|
||||||
|
websiteConfig: '网站设置',
|
||||||
|
basic: '基本',
|
||||||
|
source: '源文',
|
||||||
|
security: '安全',
|
||||||
|
backup: '备份',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
<template>
|
<template>
|
||||||
<LayoutContent :header="'网站设置'" :back-name="'Website'">
|
<el-card>
|
||||||
<el-tabs v-model="index" @click="changeTab(index)">
|
<LayoutContent :header="$t('website.websiteConfig')" :back-name="'Website'">
|
||||||
<el-tab-pane label="基本" name="basic">
|
<el-tabs v-model="index" @click="changeTab(index)">
|
||||||
<Basic :key="id" :id="id" v-if="index === 'basic'"></Basic>
|
<el-tab-pane :label="$t('website.basic')" name="basic">
|
||||||
</el-tab-pane>
|
<Basic :key="id" :id="id" v-if="index === 'basic'"></Basic>
|
||||||
<el-tab-pane label="安全" name="safety">
|
</el-tab-pane>
|
||||||
<Safety :key="id" :id="id" v-if="index === 'safety'"></Safety>
|
<el-tab-pane :label="$t('website.security')" name="safety">
|
||||||
</el-tab-pane>
|
<Safety :key="id" :id="id" v-if="index === 'safety'"></Safety>
|
||||||
<el-tab-pane label="备份">反代</el-tab-pane>
|
</el-tab-pane>
|
||||||
<el-tab-pane label="源文" name="resource">
|
<el-tab-pane :label="$t('website.backup')">反代</el-tab-pane>
|
||||||
<Resource :key="id" :id="id" v-if="index === 'resource'"></Resource>
|
<el-tab-pane :label="$t('website.source')" name="resource">
|
||||||
</el-tab-pane>
|
<Resource :key="id" :id="id" v-if="index === 'resource'"></Resource>
|
||||||
</el-tabs>
|
</el-tab-pane>
|
||||||
</LayoutContent>
|
</el-tabs>
|
||||||
|
</LayoutContent>
|
||||||
|
</el-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
@ -1,7 +1,17 @@
|
|||||||
<template>
|
<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>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import LayoutContent from '@/layout/layout-content.vue';
|
import LayoutContent from '@/layout/layout-content.vue';
|
||||||
|
import Source from './source/index.vue';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
let activeName = ref('1');
|
||||||
</script>
|
</script>
|
||||||
|
64
frontend/src/views/website/website/nginx/source/index.vue
Normal file
64
frontend/src/views/website/website/nginx/source/index.vue
Normal file
@ -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…
x
Reference in New Issue
Block a user