feat: deploy config to remote nodes #359
parent
e75dce92ad
commit
1c1da92363
@ -1,65 +1,97 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/config"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/config"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
func AddConfig(c *gin.Context) {
|
||||
var json struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
NewFilepath string `json:"new_filepath" binding:"required"`
|
||||
Content string `json:"content"`
|
||||
Overwrite bool `json:"overwrite"`
|
||||
}
|
||||
var json struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
NewFilepath string `json:"new_filepath" binding:"required"`
|
||||
Content string `json:"content"`
|
||||
Overwrite bool `json:"overwrite"`
|
||||
SyncNodeIds []int `json:"sync_node_ids"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
name := json.Name
|
||||
content := json.Content
|
||||
path := json.NewFilepath
|
||||
if !helper.IsUnderDirectory(path, nginx.GetConfPath()) {
|
||||
c.JSON(http.StatusForbidden, gin.H{
|
||||
"message": "new filepath is not under the nginx conf path",
|
||||
})
|
||||
return
|
||||
}
|
||||
name := json.Name
|
||||
content := json.Content
|
||||
path := json.NewFilepath
|
||||
if !helper.IsUnderDirectory(path, nginx.GetConfPath()) {
|
||||
c.JSON(http.StatusForbidden, gin.H{
|
||||
"message": "new filepath is not under the nginx conf path",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if !json.Overwrite && helper.FileExists(path) {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "File exists",
|
||||
})
|
||||
return
|
||||
}
|
||||
if !json.Overwrite && helper.FileExists(path) {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "File exists",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
err := os.WriteFile(path, []byte(content), 0644)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
// check if the dir exists, if not, use mkdirAll to create the dir
|
||||
dir := filepath.Dir(path)
|
||||
if !helper.FileExists(dir) {
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
output := nginx.Reload()
|
||||
if nginx.GetLogLevel(output) >= nginx.Warn {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": output,
|
||||
})
|
||||
return
|
||||
}
|
||||
err := os.WriteFile(path, []byte(content), 0644)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, config.Config{
|
||||
Name: name,
|
||||
Content: content,
|
||||
ChatGPTMessages: make([]openai.ChatCompletionMessage, 0),
|
||||
FilePath: path,
|
||||
ModifiedAt: time.Now(),
|
||||
})
|
||||
output := nginx.Reload()
|
||||
if nginx.GetLogLevel(output) >= nginx.Warn {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": output,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
q := query.Config
|
||||
_, err = q.Where(q.Filepath.Eq(path)).Delete()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = q.Create(&model.Config{
|
||||
Name: name,
|
||||
Filepath: path,
|
||||
SyncNodeIds: json.SyncNodeIds,
|
||||
SyncOverwrite: json.Overwrite,
|
||||
})
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, config.Config{
|
||||
Name: name,
|
||||
Content: content,
|
||||
ChatGPTMessages: make([]openai.ChatCompletionMessage, 0),
|
||||
FilePath: path,
|
||||
ModifiedAt: time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
export function syncCertificateSuccess(text: string) {
|
||||
const data = JSON.parse(text)
|
||||
|
||||
return $gettext('Sync Certificate %{cert_name} to %{env_name} successfully',
|
||||
{ cert_name: data.cert_name, env_name: data.env_name })
|
||||
}
|
||||
|
||||
export function syncCertificateError(text: string) {
|
||||
const data = JSON.parse(text)
|
||||
|
||||
if (data.status_code === 404) {
|
||||
return $gettext('Sync Certificate %{cert_name} to %{env_name} failed, please upgrade the remote Nginx UI to the latest version',
|
||||
{ cert_name: data.cert_name, env_name: data.env_name }, true)
|
||||
}
|
||||
|
||||
return $gettext('Sync Certificate %{cert_name} to %{env_name} failed, response: %{resp}',
|
||||
{ cert_name: data.cert_name, env_name: data.env_name, resp: data.resp_body }, true)
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
export function syncConfigSuccess(text: string) {
|
||||
const data = JSON.parse(text)
|
||||
|
||||
return $gettext('Sync Config %{config_name} to %{env_name} successfully',
|
||||
{ config_name: data.config_name, env_name: data.env_name })
|
||||
}
|
||||
|
||||
export function syncConfigError(text: string) {
|
||||
const data = JSON.parse(text)
|
||||
|
||||
if (data.status_code === 404) {
|
||||
return $gettext('Sync config %{cert_name} to %{env_name} failed, please upgrade the remote Nginx UI to the latest version',
|
||||
{ config_name: data.config_name, env_name: data.env_name }, true)
|
||||
}
|
||||
|
||||
return $gettext('Sync config %{config_name} to %{env_name} failed, response: %{resp}',
|
||||
{ cert_name: data.cert_name, env_name: data.env_name, resp: data.resp_body }, true)
|
||||
}
|
||||
|
||||
export function syncRenameConfigSuccess(text: string) {
|
||||
const data = JSON.parse(text)
|
||||
|
||||
return $gettext('Rename %{orig_path} to %{new_path} on %{env_name} successfully',
|
||||
{ orig_path: data.orig_path, new_path: data.orig_path, env_name: data.env_name })
|
||||
}
|
||||
|
||||
export function syncRenameConfigError(text: string) {
|
||||
const data = JSON.parse(text)
|
||||
|
||||
if (data.status_code === 404) {
|
||||
return $gettext('Rename %{orig_path} to %{new_path} on %{env_name} failed, please upgrade the remote Nginx UI to the latest version',
|
||||
{ orig_path: data.orig_path, new_path: data.orig_path, env_name: data.env_name }, true)
|
||||
}
|
||||
|
||||
return $gettext('Rename %{orig_path} to %{new_path} on %{env_name} failed, response: %{resp}',
|
||||
{ orig_path: data.orig_path, new_path: data.orig_path, resp: data.resp_body, env_name: data.env_name }, true)
|
||||
}
|
||||
Binary file not shown.
@ -1 +1 @@
|
||||
{"version":"2.0.0-beta.28","build_id":147,"total_build":351}
|
||||
{"version":"2.0.0-beta.28","build_id":149,"total_build":353}
|
||||
@ -1 +1 @@
|
||||
{"version":"2.0.0-beta.28","build_id":147,"total_build":351}
|
||||
{"version":"2.0.0-beta.28","build_id":149,"total_build":353}
|
||||
@ -0,0 +1,292 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/internal/notification"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SyncConfigPayload struct {
|
||||
Name string `json:"name"`
|
||||
Filepath string `json:"filepath"`
|
||||
NewFilepath string `json:"new_filepath"`
|
||||
Content string `json:"content"`
|
||||
Overwrite bool `json:"overwrite"`
|
||||
}
|
||||
|
||||
func SyncToRemoteServer(c *model.Config, newFilepath string) (err error) {
|
||||
if c.Filepath == "" || len(c.SyncNodeIds) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
nginxConfPath := nginx.GetConfPath()
|
||||
if !helper.IsUnderDirectory(c.Filepath, nginxConfPath) {
|
||||
return fmt.Errorf("config: %s is not under the nginx conf path: %s",
|
||||
c.Filepath, nginxConfPath)
|
||||
}
|
||||
|
||||
if newFilepath != "" && !helper.IsUnderDirectory(newFilepath, nginxConfPath) {
|
||||
return fmt.Errorf("config: %s is not under the nginx conf path: %s",
|
||||
c.Filepath, nginxConfPath)
|
||||
}
|
||||
|
||||
currentPath := c.Filepath
|
||||
if newFilepath != "" {
|
||||
currentPath = newFilepath
|
||||
}
|
||||
configBytes, err := os.ReadFile(currentPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
payload := &SyncConfigPayload{
|
||||
Name: c.Name,
|
||||
Filepath: c.Filepath,
|
||||
NewFilepath: newFilepath,
|
||||
Content: string(configBytes),
|
||||
Overwrite: c.SyncOverwrite,
|
||||
}
|
||||
payloadBytes, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
q := query.Environment
|
||||
envs, _ := q.Where(q.ID.In(c.SyncNodeIds...)).Find()
|
||||
for _, env := range envs {
|
||||
go func() {
|
||||
err := payload.deploy(env, c, payloadBytes)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func SyncRenameOnRemoteServer(origPath, newPath string, syncNodeIds []int) (err error) {
|
||||
if origPath == "" || newPath == "" || len(syncNodeIds) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
nginxConfPath := nginx.GetConfPath()
|
||||
if !helper.IsUnderDirectory(origPath, nginxConfPath) {
|
||||
return fmt.Errorf("config: %s is not under the nginx conf path: %s",
|
||||
origPath, nginxConfPath)
|
||||
}
|
||||
|
||||
if !helper.IsUnderDirectory(newPath, nginxConfPath) {
|
||||
return fmt.Errorf("config: %s is not under the nginx conf path: %s",
|
||||
newPath, nginxConfPath)
|
||||
}
|
||||
|
||||
payload := &SyncConfigPayload{
|
||||
Filepath: origPath,
|
||||
NewFilepath: newPath,
|
||||
}
|
||||
|
||||
q := query.Environment
|
||||
envs, _ := q.Where(q.ID.In(syncNodeIds...)).Find()
|
||||
for _, env := range envs {
|
||||
go func() {
|
||||
err := payload.rename(env)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type SyncNotificationPayload struct {
|
||||
StatusCode int `json:"status_code"`
|
||||
ConfigName string `json:"config_name"`
|
||||
EnvName string `json:"env_name"`
|
||||
RespBody string `json:"resp_body"`
|
||||
}
|
||||
|
||||
func (p *SyncConfigPayload) deploy(env *model.Environment, c *model.Config, payloadBytes []byte) (err error) {
|
||||
client := http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
}
|
||||
url, err := env.GetUrl("/api/config")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(payloadBytes))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Set("X-Node-Secret", env.Token)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
notificationPayload := &SyncNotificationPayload{
|
||||
StatusCode: resp.StatusCode,
|
||||
ConfigName: c.Name,
|
||||
EnvName: env.Name,
|
||||
RespBody: string(respBody),
|
||||
}
|
||||
|
||||
notificationPayloadBytes, err := json.Marshal(notificationPayload)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
notification.Error("Sync Configuration Error", string(notificationPayloadBytes))
|
||||
return
|
||||
}
|
||||
|
||||
notification.Success("Sync Configuration Success", string(notificationPayloadBytes))
|
||||
|
||||
// handle rename
|
||||
if p.NewFilepath == "" || p.Filepath == p.NewFilepath {
|
||||
return
|
||||
}
|
||||
|
||||
payloadBytes, err = json.Marshal(gin.H{
|
||||
"base_path": filepath.Dir(p.Filepath),
|
||||
"old_filepath": filepath.Base(p.Filepath),
|
||||
"new_filepath": filepath.Base(p.NewFilepath),
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
url, err = env.GetUrl("/api/config_rename")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
req, err = http.NewRequest(http.MethodPost, url, bytes.NewBuffer(payloadBytes))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Set("X-Node-Secret", env.Token)
|
||||
resp, err = client.Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBody, err = io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
notificationPayload = &SyncNotificationPayload{
|
||||
StatusCode: resp.StatusCode,
|
||||
ConfigName: c.Name,
|
||||
EnvName: env.Name,
|
||||
RespBody: string(respBody),
|
||||
}
|
||||
|
||||
notificationPayloadBytes, err = json.Marshal(notificationPayload)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
notification.Error("Sync Rename Configuration Error", string(notificationPayloadBytes))
|
||||
return
|
||||
}
|
||||
|
||||
notification.Success("Sync Rename Configuration Success", string(notificationPayloadBytes))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type SyncRenameNotificationPayload struct {
|
||||
StatusCode int `json:"status_code"`
|
||||
OrigPath string `json:"orig_path"`
|
||||
NewPath string `json:"new_path"`
|
||||
EnvName string `json:"env_name"`
|
||||
RespBody string `json:"resp_body"`
|
||||
}
|
||||
|
||||
func (p *SyncConfigPayload) rename(env *model.Environment) (err error) {
|
||||
// handle rename
|
||||
if p.NewFilepath == "" || p.Filepath == p.NewFilepath {
|
||||
return
|
||||
}
|
||||
|
||||
client := http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
}
|
||||
|
||||
payloadBytes, err := json.Marshal(gin.H{
|
||||
"base_path": strings.ReplaceAll(filepath.Dir(p.Filepath), nginx.GetConfPath(), ""),
|
||||
"orig_name": filepath.Base(p.Filepath),
|
||||
"new_name": filepath.Base(p.NewFilepath),
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
url, err := env.GetUrl("/api/config_rename")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(payloadBytes))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Set("X-Node-Secret", env.Token)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
notificationPayload := &SyncRenameNotificationPayload{
|
||||
StatusCode: resp.StatusCode,
|
||||
OrigPath: p.Filepath,
|
||||
NewPath: p.NewFilepath,
|
||||
EnvName: env.Name,
|
||||
RespBody: string(respBody),
|
||||
}
|
||||
|
||||
notificationPayloadBytes, err := json.Marshal(notificationPayload)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
notification.Error("Sync Rename Configuration Error", string(notificationPayloadBytes))
|
||||
return
|
||||
}
|
||||
|
||||
notification.Success("Sync Rename Configuration Success", string(notificationPayloadBytes))
|
||||
|
||||
return
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/user"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func RequireSecureSession() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
u, ok := c.Get("user")
|
||||
if !ok {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
cUser := u.(*model.Auth)
|
||||
if !cUser.EnabledOTP() {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
ssid := c.GetHeader("X-Secure-Session-ID")
|
||||
if ssid == "" {
|
||||
ssid = c.Query("X-Secure-Session-ID")
|
||||
}
|
||||
if ssid == "" {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "Secure Session ID is empty",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if user.VerifySecureSessionID(ssid, cUser.ID) {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "Secure Session ID is invalid",
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package model
|
||||
|
||||
type Config struct {
|
||||
Model
|
||||
Name string `json:"name"`
|
||||
Filepath string `json:"filepath"`
|
||||
SyncNodeIds []int `json:"sync_node_ids" gorm:"serializer:json"`
|
||||
SyncOverwrite bool `json:"sync_overwrite"`
|
||||
}
|
||||
@ -0,0 +1,370 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
)
|
||||
|
||||
func newConfig(db *gorm.DB, opts ...gen.DOOption) config {
|
||||
_config := config{}
|
||||
|
||||
_config.configDo.UseDB(db, opts...)
|
||||
_config.configDo.UseModel(&model.Config{})
|
||||
|
||||
tableName := _config.configDo.TableName()
|
||||
_config.ALL = field.NewAsterisk(tableName)
|
||||
_config.ID = field.NewInt(tableName, "id")
|
||||
_config.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_config.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_config.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_config.Filepath = field.NewString(tableName, "filepath")
|
||||
_config.SyncNodeIds = field.NewField(tableName, "sync_node_ids")
|
||||
|
||||
_config.fillFieldMap()
|
||||
|
||||
return _config
|
||||
}
|
||||
|
||||
type config struct {
|
||||
configDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Filepath field.String
|
||||
SyncNodeIds field.Field
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (c config) Table(newTableName string) *config {
|
||||
c.configDo.UseTable(newTableName)
|
||||
return c.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (c config) As(alias string) *config {
|
||||
c.configDo.DO = *(c.configDo.As(alias).(*gen.DO))
|
||||
return c.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (c *config) updateTableName(table string) *config {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.ID = field.NewInt(table, "id")
|
||||
c.CreatedAt = field.NewTime(table, "created_at")
|
||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
c.DeletedAt = field.NewField(table, "deleted_at")
|
||||
c.Filepath = field.NewString(table, "filepath")
|
||||
c.SyncNodeIds = field.NewField(table, "sync_node_ids")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *config) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := c.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (c *config) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 6)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["created_at"] = c.CreatedAt
|
||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||||
c.fieldMap["deleted_at"] = c.DeletedAt
|
||||
c.fieldMap["filepath"] = c.Filepath
|
||||
c.fieldMap["sync_node_ids"] = c.SyncNodeIds
|
||||
}
|
||||
|
||||
func (c config) clone(db *gorm.DB) config {
|
||||
c.configDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c config) replaceDB(db *gorm.DB) config {
|
||||
c.configDo.ReplaceDB(db)
|
||||
return c
|
||||
}
|
||||
|
||||
type configDo struct{ gen.DO }
|
||||
|
||||
// FirstByID Where("id=@id")
|
||||
func (c configDo) FirstByID(id int) (result *model.Config, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("id=? ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = c.UnderlyingDB().Where(generateSQL.String(), params...).Take(&result) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteByID update @@table set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=@id
|
||||
func (c configDo) DeleteByID(id int) (err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("update configs set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=? ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = c.UnderlyingDB().Exec(generateSQL.String(), params...) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c configDo) Debug() *configDo {
|
||||
return c.withDO(c.DO.Debug())
|
||||
}
|
||||
|
||||
func (c configDo) WithContext(ctx context.Context) *configDo {
|
||||
return c.withDO(c.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (c configDo) ReadDB() *configDo {
|
||||
return c.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (c configDo) WriteDB() *configDo {
|
||||
return c.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (c configDo) Session(config *gorm.Session) *configDo {
|
||||
return c.withDO(c.DO.Session(config))
|
||||
}
|
||||
|
||||
func (c configDo) Clauses(conds ...clause.Expression) *configDo {
|
||||
return c.withDO(c.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Returning(value interface{}, columns ...string) *configDo {
|
||||
return c.withDO(c.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (c configDo) Not(conds ...gen.Condition) *configDo {
|
||||
return c.withDO(c.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Or(conds ...gen.Condition) *configDo {
|
||||
return c.withDO(c.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Select(conds ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Where(conds ...gen.Condition) *configDo {
|
||||
return c.withDO(c.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Order(conds ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Distinct(cols ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (c configDo) Omit(cols ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (c configDo) Join(table schema.Tabler, on ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (c configDo) LeftJoin(table schema.Tabler, on ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c configDo) RightJoin(table schema.Tabler, on ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c configDo) Group(cols ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (c configDo) Having(conds ...gen.Condition) *configDo {
|
||||
return c.withDO(c.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Limit(limit int) *configDo {
|
||||
return c.withDO(c.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (c configDo) Offset(offset int) *configDo {
|
||||
return c.withDO(c.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (c configDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *configDo {
|
||||
return c.withDO(c.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (c configDo) Unscoped() *configDo {
|
||||
return c.withDO(c.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (c configDo) Create(values ...*model.Config) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Create(values)
|
||||
}
|
||||
|
||||
func (c configDo) CreateInBatches(values []*model.Config, batchSize int) error {
|
||||
return c.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (c configDo) Save(values ...*model.Config) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Save(values)
|
||||
}
|
||||
|
||||
func (c configDo) First() (*model.Config, error) {
|
||||
if result, err := c.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Config), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configDo) Take() (*model.Config, error) {
|
||||
if result, err := c.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Config), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configDo) Last() (*model.Config, error) {
|
||||
if result, err := c.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Config), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configDo) Find() ([]*model.Config, error) {
|
||||
result, err := c.DO.Find()
|
||||
return result.([]*model.Config), err
|
||||
}
|
||||
|
||||
func (c configDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Config, err error) {
|
||||
buf := make([]*model.Config, 0, batchSize)
|
||||
err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (c configDo) FindInBatches(result *[]*model.Config, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return c.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (c configDo) Attrs(attrs ...field.AssignExpr) *configDo {
|
||||
return c.withDO(c.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (c configDo) Assign(attrs ...field.AssignExpr) *configDo {
|
||||
return c.withDO(c.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (c configDo) Joins(fields ...field.RelationField) *configDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Joins(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c configDo) Preload(fields ...field.RelationField) *configDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Preload(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c configDo) FirstOrInit() (*model.Config, error) {
|
||||
if result, err := c.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Config), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configDo) FirstOrCreate() (*model.Config, error) {
|
||||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Config), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configDo) FindByPage(offset int, limit int) (result []*model.Config, count int64, err error) {
|
||||
result, err = c.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = c.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (c configDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = c.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = c.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (c configDo) Scan(result interface{}) (err error) {
|
||||
return c.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (c configDo) Delete(models ...*model.Config) (result gen.ResultInfo, err error) {
|
||||
return c.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (c *configDo) withDO(do gen.Dao) *configDo {
|
||||
c.DO = *do.(*gen.DO)
|
||||
return c
|
||||
}
|
||||
@ -1,154 +0,0 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/internal/analytic"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type ErrorRes struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type toolBodyWriter struct {
|
||||
gin.ResponseWriter
|
||||
body *bytes.Buffer
|
||||
}
|
||||
|
||||
func (r toolBodyWriter) Write(b []byte) (int, error) {
|
||||
return r.body.Write(b)
|
||||
}
|
||||
|
||||
// OperationSync 针对配置了vip的环境操作进行同步
|
||||
func OperationSync() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
bodyBytes, _ := PeekRequest(c.Request)
|
||||
wb := &toolBodyWriter{
|
||||
body: &bytes.Buffer{},
|
||||
ResponseWriter: c.Writer,
|
||||
}
|
||||
c.Writer = wb
|
||||
|
||||
c.Next()
|
||||
if c.Request.Method == "GET" || !statusValid(c.Writer.Status()) { // 请求有问题,无需执行同步操作
|
||||
return
|
||||
}
|
||||
|
||||
totalCount := 0
|
||||
successCount := 0
|
||||
detailMsg := ""
|
||||
// 后置处理操作同步
|
||||
wg := sync.WaitGroup{}
|
||||
for _, node := range analytic.NodeMap {
|
||||
wg.Add(1)
|
||||
node := node
|
||||
go func(data analytic.Node) {
|
||||
defer wg.Done()
|
||||
if node.OperationSync && node.Status && requestUrlMatch(c.Request.URL.Path, data) { // 开启操作同步且当前状态正常
|
||||
totalCount++
|
||||
if err := syncNodeOperation(c, data, bodyBytes); err != nil {
|
||||
detailMsg += fmt.Sprintf("node_name: %s, err_msg: %s; ", data.Name, err)
|
||||
return
|
||||
}
|
||||
successCount++
|
||||
}
|
||||
}(*node)
|
||||
}
|
||||
wg.Wait()
|
||||
if successCount < totalCount { // 如果有错误,替换原来的消息内容
|
||||
originBytes := wb.body
|
||||
logger.Infof("origin response body: %s", originBytes)
|
||||
// clear Origin Buffer
|
||||
wb.body = &bytes.Buffer{}
|
||||
wb.ResponseWriter.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
errorRes := ErrorRes{
|
||||
Message: fmt.Sprintf("operation sync failed, total: %d, success: %d, fail: %d, detail: %s", totalCount, successCount, totalCount-successCount, detailMsg),
|
||||
}
|
||||
byts, _ := json.Marshal(errorRes)
|
||||
_, err := wb.Write(byts)
|
||||
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
}
|
||||
_, err := wb.ResponseWriter.Write(wb.body.Bytes())
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func PeekRequest(request *http.Request) ([]byte, error) {
|
||||
if request.Body != nil {
|
||||
byts, err := io.ReadAll(request.Body) // io.ReadAll as Go 1.16, below please use ioutil.ReadAll
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
request.Body = io.NopCloser(bytes.NewReader(byts))
|
||||
return byts, nil
|
||||
}
|
||||
return make([]byte, 0), nil
|
||||
}
|
||||
|
||||
func requestUrlMatch(url string, node analytic.Node) bool {
|
||||
p, _ := regexp.Compile(node.SyncApiRegex)
|
||||
result := p.FindAllString(url, -1)
|
||||
if len(result) > 0 && result[0] == url {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func statusValid(code int) bool {
|
||||
return code < http.StatusMultipleChoices
|
||||
}
|
||||
|
||||
func syncNodeOperation(c *gin.Context, node analytic.Node, bodyBytes []byte) error {
|
||||
u, err := url.JoinPath(node.URL, c.Request.RequestURI)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
decodedUri, err := url.QueryUnescape(u)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Debugf("syncNodeOperation request: %s, node_id: %d, node_name: %s", decodedUri, node.ID, node.Name)
|
||||
client := http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(c.Request.Method, decodedUri, bytes.NewReader(bodyBytes))
|
||||
req.Header.Set("X-Node-Secret", node.Token)
|
||||
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
byts, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !statusValid(res.StatusCode) {
|
||||
errRes := ErrorRes{}
|
||||
if err = json.Unmarshal(byts, &errRes); err != nil {
|
||||
return err
|
||||
}
|
||||
return errors.New(errRes.Message)
|
||||
}
|
||||
logger.Debug("syncNodeOperation result: ", string(byts))
|
||||
return nil
|
||||
}
|
||||
@ -1,83 +1,83 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api/analytic"
|
||||
"github.com/0xJacky/Nginx-UI/api/certificate"
|
||||
"github.com/0xJacky/Nginx-UI/api/cluster"
|
||||
"github.com/0xJacky/Nginx-UI/api/config"
|
||||
"github.com/0xJacky/Nginx-UI/api/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/api/notification"
|
||||
"github.com/0xJacky/Nginx-UI/api/openai"
|
||||
"github.com/0xJacky/Nginx-UI/api/settings"
|
||||
"github.com/0xJacky/Nginx-UI/api/sites"
|
||||
"github.com/0xJacky/Nginx-UI/api/streams"
|
||||
"github.com/0xJacky/Nginx-UI/api/system"
|
||||
"github.com/0xJacky/Nginx-UI/api/template"
|
||||
"github.com/0xJacky/Nginx-UI/api/terminal"
|
||||
"github.com/0xJacky/Nginx-UI/api/upstream"
|
||||
"github.com/0xJacky/Nginx-UI/api/user"
|
||||
"github.com/gin-contrib/static"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"github.com/0xJacky/Nginx-UI/api/analytic"
|
||||
"github.com/0xJacky/Nginx-UI/api/certificate"
|
||||
"github.com/0xJacky/Nginx-UI/api/cluster"
|
||||
"github.com/0xJacky/Nginx-UI/api/config"
|
||||
"github.com/0xJacky/Nginx-UI/api/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/api/notification"
|
||||
"github.com/0xJacky/Nginx-UI/api/openai"
|
||||
"github.com/0xJacky/Nginx-UI/api/settings"
|
||||
"github.com/0xJacky/Nginx-UI/api/sites"
|
||||
"github.com/0xJacky/Nginx-UI/api/streams"
|
||||
"github.com/0xJacky/Nginx-UI/api/system"
|
||||
"github.com/0xJacky/Nginx-UI/api/template"
|
||||
"github.com/0xJacky/Nginx-UI/api/terminal"
|
||||
"github.com/0xJacky/Nginx-UI/api/upstream"
|
||||
"github.com/0xJacky/Nginx-UI/api/user"
|
||||
"github.com/0xJacky/Nginx-UI/internal/middleware"
|
||||
"github.com/gin-contrib/static"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func InitRouter() *gin.Engine {
|
||||
r := gin.New()
|
||||
r.Use(gin.Logger())
|
||||
r.Use(recovery())
|
||||
r.Use(cacheJs())
|
||||
r.Use(ipWhiteList())
|
||||
r := gin.New()
|
||||
r.Use(
|
||||
gin.Logger(),
|
||||
middleware.Recovery(),
|
||||
middleware.CacheJs(),
|
||||
middleware.IPWhiteList(),
|
||||
static.Serve("/", middleware.MustFs("")),
|
||||
)
|
||||
|
||||
//r.Use(OperationSync())
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"message": "not found",
|
||||
})
|
||||
})
|
||||
|
||||
r.Use(static.Serve("/", mustFS("")))
|
||||
root := r.Group("/api")
|
||||
{
|
||||
system.InitPublicRouter(root)
|
||||
user.InitAuthRouter(root)
|
||||
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"message": "not found",
|
||||
})
|
||||
})
|
||||
// Authorization required not websocket request
|
||||
g := root.Group("/", middleware.AuthRequired(), middleware.Proxy())
|
||||
{
|
||||
user.InitUserRouter(g)
|
||||
analytic.InitRouter(g)
|
||||
user.InitManageUserRouter(g)
|
||||
nginx.InitRouter(g)
|
||||
sites.InitRouter(g)
|
||||
streams.InitRouter(g)
|
||||
config.InitRouter(g)
|
||||
template.InitRouter(g)
|
||||
certificate.InitCertificateRouter(g)
|
||||
certificate.InitDNSCredentialRouter(g)
|
||||
certificate.InitAcmeUserRouter(g)
|
||||
system.InitPrivateRouter(g)
|
||||
settings.InitRouter(g)
|
||||
openai.InitRouter(g)
|
||||
cluster.InitRouter(g)
|
||||
notification.InitRouter(g)
|
||||
}
|
||||
|
||||
root := r.Group("/api")
|
||||
{
|
||||
system.InitPublicRouter(root)
|
||||
user.InitAuthRouter(root)
|
||||
// Authorization required and websocket request
|
||||
w := root.Group("/", middleware.AuthRequired(), middleware.ProxyWs())
|
||||
{
|
||||
analytic.InitWebSocketRouter(w)
|
||||
certificate.InitCertificateWebSocketRouter(w)
|
||||
o := w.Group("", middleware.RequireSecureSession())
|
||||
{
|
||||
terminal.InitRouter(o)
|
||||
}
|
||||
nginx.InitNginxLogRouter(w)
|
||||
upstream.InitRouter(w)
|
||||
system.InitWebSocketRouter(w)
|
||||
}
|
||||
}
|
||||
|
||||
// Authorization required not websocket request
|
||||
g := root.Group("/", authRequired(), proxy())
|
||||
{
|
||||
user.InitUserRouter(g)
|
||||
analytic.InitRouter(g)
|
||||
user.InitManageUserRouter(g)
|
||||
nginx.InitRouter(g)
|
||||
sites.InitRouter(g)
|
||||
streams.InitRouter(g)
|
||||
config.InitRouter(g)
|
||||
template.InitRouter(g)
|
||||
certificate.InitCertificateRouter(g)
|
||||
certificate.InitDNSCredentialRouter(g)
|
||||
certificate.InitAcmeUserRouter(g)
|
||||
system.InitPrivateRouter(g)
|
||||
settings.InitRouter(g)
|
||||
openai.InitRouter(g)
|
||||
cluster.InitRouter(g)
|
||||
notification.InitRouter(g)
|
||||
}
|
||||
|
||||
// Authorization required and websocket request
|
||||
w := root.Group("/", authRequired(), proxyWs())
|
||||
{
|
||||
analytic.InitWebSocketRouter(w)
|
||||
certificate.InitCertificateWebSocketRouter(w)
|
||||
o := w.Group("", required2FA())
|
||||
{
|
||||
terminal.InitRouter(o)
|
||||
}
|
||||
nginx.InitNginxLogRouter(w)
|
||||
upstream.InitRouter(w)
|
||||
system.InitWebSocketRouter(w)
|
||||
}
|
||||
}
|
||||
|
||||
return r
|
||||
return r
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue