From c30f39185ed82163dcbd48973d3b36619f781934 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Wed, 23 Nov 2022 16:19:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0nginx=E6=BA=90?= =?UTF-8?q?=E6=96=87=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/entry.go | 2 + backend/app/api/v1/nginx.go | 17 +++++ backend/app/service/entry.go | 2 + backend/app/service/nginx.go | 33 ++++++++++ backend/init/router/router.go | 1 + backend/router/entry.go | 1 + backend/router/ro_nginx.go | 20 ++++++ frontend/src/api/interface/nginx.ts | 1 + frontend/src/api/modules/nginx.ts | 6 ++ frontend/src/lang/modules/zh.ts | 5 ++ .../views/website/website/config/index.vue | 30 +++++---- .../src/views/website/website/nginx/index.vue | 12 +++- .../website/website/nginx/source/index.vue | 64 +++++++++++++++++++ 13 files changed, 179 insertions(+), 15 deletions(-) create mode 100644 backend/app/api/v1/nginx.go create mode 100644 backend/app/service/nginx.go create mode 100644 backend/router/ro_nginx.go create mode 100644 frontend/src/api/interface/nginx.ts create mode 100644 frontend/src/api/modules/nginx.ts create mode 100644 frontend/src/views/website/website/nginx/source/index.vue diff --git a/backend/app/api/v1/entry.go b/backend/app/api/v1/entry.go index 6810e2398..beda05032 100644 --- a/backend/app/api/v1/entry.go +++ b/backend/app/api/v1/entry.go @@ -40,5 +40,7 @@ var ( websiteSSLService = service.ServiceGroupApp.WebSiteSSLService websiteAcmeAccountService = service.ServiceGroupApp.WebSiteAcmeAccountService + nginxService = service.ServiceGroupApp.NginxService + logService = service.ServiceGroupApp.LogService ) diff --git a/backend/app/api/v1/nginx.go b/backend/app/api/v1/nginx.go new file mode 100644 index 000000000..33b687361 --- /dev/null +++ b/backend/app/api/v1/nginx.go @@ -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) +} diff --git a/backend/app/service/entry.go b/backend/app/service/entry.go index eb5155273..2689c0efd 100644 --- a/backend/app/service/entry.go +++ b/backend/app/service/entry.go @@ -33,6 +33,8 @@ type ServiceGroup struct { WebSiteSSLService WebSiteAcmeAccountService + NginxService + LogService } diff --git a/backend/app/service/nginx.go b/backend/app/service/nginx.go new file mode 100644 index 000000000..fefab2841 --- /dev/null +++ b/backend/app/service/nginx.go @@ -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 +} diff --git a/backend/init/router/router.go b/backend/init/router/router.go index 316ed8a95..65afafac4 100644 --- a/backend/init/router/router.go +++ b/backend/init/router/router.go @@ -85,6 +85,7 @@ func Routers() *gin.Engine { systemRouter.InitDatabaseRouter(PrivateGroup) systemRouter.InitWebsiteSSLRouter(PrivateGroup) systemRouter.InitWebsiteAcmeAccountRouter(PrivateGroup) + systemRouter.InitNginxRouter(PrivateGroup) } return Router diff --git a/backend/router/entry.go b/backend/router/entry.go index ae033ab12..04a6cef4c 100644 --- a/backend/router/entry.go +++ b/backend/router/entry.go @@ -20,6 +20,7 @@ type RouterGroup struct { WebsiteAcmeAccountRouter WebsiteSSLRouter DatabaseRouter + NginxRouter } var RouterGroupApp = new(RouterGroup) diff --git a/backend/router/ro_nginx.go b/backend/router/ro_nginx.go new file mode 100644 index 000000000..afd91218e --- /dev/null +++ b/backend/router/ro_nginx.go @@ -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) + } +} diff --git a/frontend/src/api/interface/nginx.ts b/frontend/src/api/interface/nginx.ts new file mode 100644 index 000000000..a7785ba70 --- /dev/null +++ b/frontend/src/api/interface/nginx.ts @@ -0,0 +1 @@ +export namespace Nginx {} diff --git a/frontend/src/api/modules/nginx.ts b/frontend/src/api/modules/nginx.ts new file mode 100644 index 000000000..8c0525bdc --- /dev/null +++ b/frontend/src/api/modules/nginx.ts @@ -0,0 +1,6 @@ +import http from '@/api'; +import { File } from '../interface/file'; + +export const GetNginx = () => { + return http.get(`/nginx`); +}; diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 07943f463..b8a085653 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -753,5 +753,10 @@ export default { lastBackupAt: '上次备份时间', null: '无', nginxConfig: 'Nginx配置', + websiteConfig: '网站设置', + basic: '基本', + source: '源文', + security: '安全', + backup: '备份', }, }; diff --git a/frontend/src/views/website/website/config/index.vue b/frontend/src/views/website/website/config/index.vue index f2f24d582..ae8da9954 100644 --- a/frontend/src/views/website/website/config/index.vue +++ b/frontend/src/views/website/website/config/index.vue @@ -1,18 +1,20 @@ diff --git a/frontend/src/views/website/website/nginx/source/index.vue b/frontend/src/views/website/website/nginx/source/index.vue new file mode 100644 index 000000000..2ceb43219 --- /dev/null +++ b/frontend/src/views/website/website/nginx/source/index.vue @@ -0,0 +1,64 @@ + +