mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-06 18:10:25 +08:00
[网站服务]可以审核域名、查看审核结果,用户端可以启用、停用域名
This commit is contained in:
5
internal/db/models/errors.go
Normal file
5
internal/db/models/errors.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import "github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
|
||||||
|
var ErrNotFound = errors.New("not found")
|
||||||
@@ -35,6 +35,8 @@ const (
|
|||||||
MessageTypeSSLCertACMETaskFailed MessageType = "SSLCertACMETaskFailed" // SSL证书任务执行失败
|
MessageTypeSSLCertACMETaskFailed MessageType = "SSLCertACMETaskFailed" // SSL证书任务执行失败
|
||||||
MessageTypeSSLCertACMETaskSuccess MessageType = "SSLCertACMETaskSuccess" // SSL证书任务执行成功
|
MessageTypeSSLCertACMETaskSuccess MessageType = "SSLCertACMETaskSuccess" // SSL证书任务执行成功
|
||||||
MessageTypeLogCapacityOverflow MessageType = "LogCapacityOverflow" // 日志超出最大限制
|
MessageTypeLogCapacityOverflow MessageType = "LogCapacityOverflow" // 日志超出最大限制
|
||||||
|
MessageTypeServerNamesAuditingSuccess MessageType = "ServerNamesAuditingSuccess" // 服务域名审核成功
|
||||||
|
MessageTypeServerNamesAuditingFailed MessageType = "ServerNamesAuditingFailed" // 服务域名审核失败
|
||||||
)
|
)
|
||||||
|
|
||||||
type MessageDAO dbs.DAO
|
type MessageDAO dbs.DAO
|
||||||
|
|||||||
@@ -5,15 +5,19 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/rpc"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
|
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/rands"
|
"github.com/iwind/TeaGo/rands"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -87,7 +91,26 @@ func (this *ServerDAO) FindEnabledServerType(serverId int64) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 创建服务
|
// 创建服务
|
||||||
func (this *ServerDAO) CreateServer(adminId int64, userId int64, serverType serverconfigs.ServerType, name string, description string, serverNamesJSON string, httpJSON string, httpsJSON string, tcpJSON string, tlsJSON string, unixJSON string, udpJSON string, webId int64, reverseProxyJSON []byte, clusterId int64, includeNodesJSON string, excludeNodesJSON string, groupIds []int64) (serverId int64, err error) {
|
func (this *ServerDAO) CreateServer(adminId int64,
|
||||||
|
userId int64,
|
||||||
|
serverType serverconfigs.ServerType,
|
||||||
|
name string,
|
||||||
|
description string,
|
||||||
|
serverNamesJSON []byte,
|
||||||
|
isAuditing bool,
|
||||||
|
auditingServerNamesJSON []byte,
|
||||||
|
httpJSON string,
|
||||||
|
httpsJSON string,
|
||||||
|
tcpJSON string,
|
||||||
|
tlsJSON string,
|
||||||
|
unixJSON string,
|
||||||
|
udpJSON string,
|
||||||
|
webId int64,
|
||||||
|
reverseProxyJSON []byte,
|
||||||
|
clusterId int64,
|
||||||
|
includeNodesJSON string,
|
||||||
|
excludeNodesJSON string,
|
||||||
|
groupIds []int64) (serverId int64, err error) {
|
||||||
op := NewServerOperator()
|
op := NewServerOperator()
|
||||||
op.UserId = userId
|
op.UserId = userId
|
||||||
op.AdminId = adminId
|
op.AdminId = adminId
|
||||||
@@ -95,9 +118,13 @@ func (this *ServerDAO) CreateServer(adminId int64, userId int64, serverType serv
|
|||||||
op.Type = serverType
|
op.Type = serverType
|
||||||
op.Description = description
|
op.Description = description
|
||||||
|
|
||||||
if IsNotNull(serverNamesJSON) {
|
if len(serverNamesJSON) > 0 {
|
||||||
op.ServerNames = serverNamesJSON
|
op.ServerNames = serverNamesJSON
|
||||||
}
|
}
|
||||||
|
op.IsAuditing = isAuditing
|
||||||
|
if len(auditingServerNamesJSON) > 0 {
|
||||||
|
op.AuditingServerNames = auditingServerNamesJSON
|
||||||
|
}
|
||||||
if IsNotNull(httpJSON) {
|
if IsNotNull(httpJSON) {
|
||||||
op.Http = httpJSON
|
op.Http = httpJSON
|
||||||
}
|
}
|
||||||
@@ -204,6 +231,15 @@ func (this *ServerDAO) UpdateServerBasic(serverId int64, name string, descriptio
|
|||||||
return this.createEvent()
|
return this.createEvent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 修复服务是否启用
|
||||||
|
func (this *ServerDAO) UpdateServerIsOn(serverId int64, isOn bool) error {
|
||||||
|
_, err := this.Query().
|
||||||
|
Pk(serverId).
|
||||||
|
Set("isOn", isOn).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// 修改服务配置
|
// 修改服务配置
|
||||||
func (this *ServerDAO) UpdateServerConfig(serverId int64, configJSON []byte, updateMd5 bool) (isChanged bool, err error) {
|
func (this *ServerDAO) UpdateServerConfig(serverId int64, configJSON []byte, updateMd5 bool) (isChanged bool, err error) {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
@@ -419,37 +455,81 @@ func (this *ServerDAO) InitServerWeb(serverId int64) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 查找ServerNames配置
|
// 查找ServerNames配置
|
||||||
func (this *ServerDAO) FindServerNames(serverId int64) (serverNamesJSON []byte, err error) {
|
func (this *ServerDAO) FindServerNames(serverId int64) (serverNamesJSON []byte, isAuditing bool, auditingServerNamesJSON []byte, auditingResultJSON []byte, err error) {
|
||||||
col, err := this.Query().
|
if serverId <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
one, err := this.Query().
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
Result("serverNames").
|
Result("serverNames", "isAuditing", "auditingServerNames", "auditingResult").
|
||||||
FindStringCol("")
|
Find()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, false, nil, nil, err
|
||||||
}
|
}
|
||||||
if len(col) == 0 || col == "null" {
|
if one == nil {
|
||||||
return []byte("[]"), nil
|
return
|
||||||
}
|
}
|
||||||
return []byte(col), nil
|
server := one.(*Server)
|
||||||
|
return []byte(server.ServerNames), server.IsAuditing == 1, []byte(server.AuditingServerNames), []byte(server.AuditingResult), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改ServerNames配置
|
// 修改ServerNames配置
|
||||||
func (this *ServerDAO) UpdateServerNames(serverId int64, config []byte) error {
|
func (this *ServerDAO) UpdateServerNames(serverId int64, serverNames []byte) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
}
|
}
|
||||||
if len(config) == 0 {
|
|
||||||
config = []byte("null")
|
op := NewServerOperator()
|
||||||
|
op.Id = serverId
|
||||||
|
|
||||||
|
if len(serverNames) == 0 {
|
||||||
|
serverNames = []byte("[]")
|
||||||
}
|
}
|
||||||
_, err := this.Query().
|
op.ServerNames = serverNames
|
||||||
Pk(serverId).
|
return this.createEvent()
|
||||||
Set("serverNames", string(config)).
|
}
|
||||||
Update()
|
|
||||||
|
// 修改域名审核
|
||||||
|
func (this *ServerDAO) UpdateAuditingServerNames(serverId int64, isAuditing bool, auditingServerNamesJSON []byte) error {
|
||||||
|
if serverId <= 0 {
|
||||||
|
return errors.New("serverId should not be smaller than 0")
|
||||||
|
}
|
||||||
|
|
||||||
|
op := NewServerOperator()
|
||||||
|
op.Id = serverId
|
||||||
|
op.IsAuditing = isAuditing
|
||||||
|
if len(auditingServerNamesJSON) == 0 {
|
||||||
|
op.AuditingServerNames = "[]"
|
||||||
|
} else {
|
||||||
|
op.AuditingServerNames = auditingServerNamesJSON
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.createEvent()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改域名审核结果
|
||||||
|
func (this *ServerDAO) UpdateServerAuditing(serverId int64, result *pb.ServerNameAuditingResult) error {
|
||||||
|
if serverId <= 0 {
|
||||||
|
return errors.New("invalid serverId")
|
||||||
|
}
|
||||||
|
|
||||||
|
resultJSON, err := json.Marshal(maps.Map{
|
||||||
|
"isOk": result.IsOk,
|
||||||
|
"reason": result.Reason,
|
||||||
|
"createdAt": time.Now().Unix(),
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.createEvent()
|
op := NewServerOperator()
|
||||||
|
op.Id = serverId
|
||||||
|
op.IsAuditing = false
|
||||||
|
op.AuditingResult = resultJSON
|
||||||
|
if result.IsOk {
|
||||||
|
op.ServerNames = dbs.SQL("auditingServerNames")
|
||||||
|
}
|
||||||
|
return this.Save(op)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改反向代理配置
|
// 修改反向代理配置
|
||||||
@@ -469,7 +549,7 @@ func (this *ServerDAO) UpdateServerReverseProxy(serverId int64, config []byte) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 计算所有可用服务数量
|
// 计算所有可用服务数量
|
||||||
func (this *ServerDAO) CountAllEnabledServersMatch(groupId int64, keyword string, userId int64) (int64, error) {
|
func (this *ServerDAO) CountAllEnabledServersMatch(groupId int64, keyword string, userId int64, clusterId int64, auditingFlag rpc.BoolFlag) (int64, error) {
|
||||||
query := this.Query().
|
query := this.Query().
|
||||||
State(ServerStateEnabled)
|
State(ServerStateEnabled)
|
||||||
if groupId > 0 {
|
if groupId > 0 {
|
||||||
@@ -483,11 +563,17 @@ func (this *ServerDAO) CountAllEnabledServersMatch(groupId int64, keyword string
|
|||||||
if userId > 0 {
|
if userId > 0 {
|
||||||
query.Attr("userId", userId)
|
query.Attr("userId", userId)
|
||||||
}
|
}
|
||||||
|
if clusterId > 0 {
|
||||||
|
query.Attr("clusterId", clusterId)
|
||||||
|
}
|
||||||
|
if auditingFlag == rpc.BoolFlagTrue {
|
||||||
|
query.Attr("isAuditing", true)
|
||||||
|
}
|
||||||
return query.Count()
|
return query.Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页的服务
|
// 列出单页的服务
|
||||||
func (this *ServerDAO) ListEnabledServersMatch(offset int64, size int64, groupId int64, keyword string, userId int64) (result []*Server, err error) {
|
func (this *ServerDAO) ListEnabledServersMatch(offset int64, size int64, groupId int64, keyword string, userId int64, clusterId int64, auditingFlag int32) (result []*Server, err error) {
|
||||||
query := this.Query().
|
query := this.Query().
|
||||||
State(ServerStateEnabled).
|
State(ServerStateEnabled).
|
||||||
Offset(offset).
|
Offset(offset).
|
||||||
@@ -506,6 +592,12 @@ func (this *ServerDAO) ListEnabledServersMatch(offset int64, size int64, groupId
|
|||||||
if userId > 0 {
|
if userId > 0 {
|
||||||
query.Attr("userId", userId)
|
query.Attr("userId", userId)
|
||||||
}
|
}
|
||||||
|
if clusterId > 0 {
|
||||||
|
query.Attr("clusterId", clusterId)
|
||||||
|
}
|
||||||
|
if auditingFlag == 1 {
|
||||||
|
query.Attr("isAuditing", true)
|
||||||
|
}
|
||||||
|
|
||||||
_, err = query.FindAll()
|
_, err = query.FindAll()
|
||||||
return
|
return
|
||||||
@@ -937,6 +1029,24 @@ func (this *ServerDAO) FindServerAdminIdAndUserId(serverId int64) (adminId int64
|
|||||||
return int64(one.(*Server).AdminId), int64(one.(*Server).UserId), nil
|
return int64(one.(*Server).AdminId), int64(one.(*Server).UserId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查用户服务
|
||||||
|
func (this *ServerDAO) CheckUserServer(serverId int64, userId int64) error {
|
||||||
|
if serverId <= 0 || userId <= 0 {
|
||||||
|
return ErrNotFound
|
||||||
|
}
|
||||||
|
ok, err := this.Query().
|
||||||
|
Pk(serverId).
|
||||||
|
Attr("userId", userId).
|
||||||
|
Exist()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return ErrNotFound
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// 生成DNS Name
|
// 生成DNS Name
|
||||||
func (this *ServerDAO) genDNSName() (string, error) {
|
func (this *ServerDAO) genDNSName() (string, error) {
|
||||||
for {
|
for {
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ type Server struct {
|
|||||||
Name string `field:"name"` // 名称
|
Name string `field:"name"` // 名称
|
||||||
Description string `field:"description"` // 描述
|
Description string `field:"description"` // 描述
|
||||||
ServerNames string `field:"serverNames"` // 域名列表
|
ServerNames string `field:"serverNames"` // 域名列表
|
||||||
|
AuditingServerNames string `field:"auditingServerNames"` // 审核中的域名
|
||||||
|
IsAuditing uint8 `field:"isAuditing"` // 是否正在审核
|
||||||
|
AuditingResult string `field:"auditingResult"` // 审核结果
|
||||||
Http string `field:"http"` // HTTP配置
|
Http string `field:"http"` // HTTP配置
|
||||||
Https string `field:"https"` // HTTPS配置
|
Https string `field:"https"` // HTTPS配置
|
||||||
Tcp string `field:"tcp"` // TCP配置
|
Tcp string `field:"tcp"` // TCP配置
|
||||||
@@ -39,6 +42,9 @@ type ServerOperator struct {
|
|||||||
Name interface{} // 名称
|
Name interface{} // 名称
|
||||||
Description interface{} // 描述
|
Description interface{} // 描述
|
||||||
ServerNames interface{} // 域名列表
|
ServerNames interface{} // 域名列表
|
||||||
|
AuditingServerNames interface{} // 审核中的域名
|
||||||
|
IsAuditing interface{} // 是否正在审核
|
||||||
|
AuditingResult interface{} // 审核结果
|
||||||
Http interface{} // HTTP配置
|
Http interface{} // HTTP配置
|
||||||
Https interface{} // HTTPS配置
|
Https interface{} // HTTPS配置
|
||||||
Tcp interface{} // TCP配置
|
Tcp interface{} // TCP配置
|
||||||
|
|||||||
9
internal/rpc/bool_flag.go
Normal file
9
internal/rpc/bool_flag.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package rpc
|
||||||
|
|
||||||
|
type BoolFlag = int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
BoolFlagNone BoolFlag = 0
|
||||||
|
BoolFlagTrue BoolFlag = 1
|
||||||
|
BoolFlagFalse BoolFlag = 2
|
||||||
|
)
|
||||||
@@ -360,7 +360,7 @@ func (this *NodeClusterService) FindAllEnabledNodeClustersWithGrantId(ctx contex
|
|||||||
// 查找集群的DNS配置
|
// 查找集群的DNS配置
|
||||||
func (this *NodeClusterService) FindEnabledNodeClusterDNS(ctx context.Context, req *pb.FindEnabledNodeClusterDNSRequest) (*pb.FindEnabledNodeClusterDNSResponse, error) {
|
func (this *NodeClusterService) FindEnabledNodeClusterDNS(ctx context.Context, req *pb.FindEnabledNodeClusterDNSRequest) (*pb.FindEnabledNodeClusterDNSResponse, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
_, _, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServerService struct {
|
type ServerService struct {
|
||||||
@@ -41,7 +42,23 @@ func (this *ServerService) CreateServer(ctx context.Context, req *pb.CreateServe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serverId, err := models.SharedServerDAO.CreateServer(req.AdminId, req.UserId, req.Type, req.Name, req.Description, string(req.ServerNamesJON), string(req.HttpJSON), string(req.HttpsJSON), string(req.TcpJSON), string(req.TlsJSON), string(req.UnixJSON), string(req.UdpJSON), req.WebId, req.ReverseProxyJSON, req.NodeClusterId, string(req.IncludeNodesJSON), string(req.ExcludeNodesJSON), req.GroupIds)
|
// 是否需要审核
|
||||||
|
isAuditing := false
|
||||||
|
serverNamesJSON := req.ServerNamesJON
|
||||||
|
auditingServerNamesJSON := []byte("[]")
|
||||||
|
if userId > 0 {
|
||||||
|
globalConfig, err := models.SharedSysSettingDAO.ReadGlobalConfig()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if globalConfig != nil && globalConfig.HTTPAll.DomainAuditingIsOn {
|
||||||
|
isAuditing = true
|
||||||
|
serverNamesJSON = []byte("[]")
|
||||||
|
auditingServerNamesJSON = req.ServerNamesJON
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
serverId, err := models.SharedServerDAO.CreateServer(req.AdminId, req.UserId, req.Type, req.Name, req.Description, serverNamesJSON, isAuditing, auditingServerNamesJSON, string(req.HttpJSON), string(req.HttpsJSON), string(req.TcpJSON), string(req.TlsJSON), string(req.UnixJSON), string(req.UdpJSON), req.WebId, req.ReverseProxyJSON, req.NodeClusterId, string(req.IncludeNodesJSON), string(req.ExcludeNodesJSON), req.GroupIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -55,7 +72,7 @@ func (this *ServerService) CreateServer(ctx context.Context, req *pb.CreateServe
|
|||||||
return &pb.CreateServerResponse{ServerId: serverId}, nil
|
return &pb.CreateServerResponse{ServerId: serverId}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改服务
|
// 修改服务基本信息
|
||||||
func (this *ServerService) UpdateServerBasic(ctx context.Context, req *pb.UpdateServerBasicRequest) (*pb.RPCSuccess, error) {
|
func (this *ServerService) UpdateServerBasic(ctx context.Context, req *pb.UpdateServerBasicRequest) (*pb.RPCSuccess, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||||
@@ -109,6 +126,25 @@ func (this *ServerService) UpdateServerBasic(ctx context.Context, req *pb.Update
|
|||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 修改服务是否启用
|
||||||
|
func (this *ServerService) UpdateServerIsOn(ctx context.Context, req *pb.UpdateServerIsOnRequest) (*pb.RPCSuccess, error) {
|
||||||
|
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if userId > 0 {
|
||||||
|
err = models.SharedServerDAO.CheckUserServer(req.ServerId, userId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = models.SharedServerDAO.UpdateServerIsOn(req.ServerId, req.IsOn)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return this.Success()
|
||||||
|
}
|
||||||
|
|
||||||
// 修改HTTP服务
|
// 修改HTTP服务
|
||||||
func (this *ServerService) UpdateServerHTTP(ctx context.Context, req *pb.UpdateServerHTTPRequest) (*pb.RPCSuccess, error) {
|
func (this *ServerService) UpdateServerHTTP(ctx context.Context, req *pb.UpdateServerHTTPRequest) (*pb.RPCSuccess, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
@@ -355,22 +391,46 @@ func (this *ServerService) UpdateServerReverseProxy(ctx context.Context, req *pb
|
|||||||
|
|
||||||
// 查找服务的域名设置
|
// 查找服务的域名设置
|
||||||
func (this *ServerService) FindServerNames(ctx context.Context, req *pb.FindServerNamesRequest) (*pb.FindServerNamesResponse, error) {
|
func (this *ServerService) FindServerNames(ctx context.Context, req *pb.FindServerNamesRequest) (*pb.FindServerNamesResponse, error) {
|
||||||
_, err := this.ValidateAdmin(ctx, 0)
|
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
serverNamesJSON, err := models.SharedServerDAO.FindServerNames(req.ServerId)
|
if userId > 0 {
|
||||||
|
err = models.SharedServerDAO.CheckUserServer(req.ServerId, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &pb.FindServerNamesResponse{ServerNamesJSON: serverNamesJSON}, nil
|
}
|
||||||
|
|
||||||
|
serverNamesJSON, isAuditing, auditingServerNamesJSON, auditingResultJSON, err := models.SharedServerDAO.FindServerNames(req.ServerId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 审核结果
|
||||||
|
auditingResult := &pb.ServerNameAuditingResult{}
|
||||||
|
if len(auditingResultJSON) > 0 {
|
||||||
|
err = json.Unmarshal(auditingResultJSON, auditingResult)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
auditingResult.IsOk = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.FindServerNamesResponse{
|
||||||
|
ServerNamesJSON: serverNamesJSON,
|
||||||
|
IsAuditing: isAuditing,
|
||||||
|
AuditingServerNamesJSON: auditingServerNamesJSON,
|
||||||
|
AuditingResult: auditingResult,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改域名服务
|
// 修改域名服务
|
||||||
func (this *ServerService) UpdateServerNames(ctx context.Context, req *pb.UpdateServerNamesRequest) (*pb.RPCSuccess, error) {
|
func (this *ServerService) UpdateServerNames(ctx context.Context, req *pb.UpdateServerNamesRequest) (*pb.RPCSuccess, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -379,17 +439,23 @@ func (this *ServerService) UpdateServerNames(ctx context.Context, req *pb.Update
|
|||||||
return nil, errors.New("invalid serverId")
|
return nil, errors.New("invalid serverId")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询老的节点信息
|
// 是否需要审核
|
||||||
server, err := models.SharedServerDAO.FindEnabledServer(req.ServerId)
|
if userId > 0 {
|
||||||
|
globalConfig, err := models.SharedSysSettingDAO.ReadGlobalConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if server == nil {
|
if globalConfig != nil && globalConfig.HTTPAll.DomainAuditingIsOn {
|
||||||
return nil, errors.New("can not find server")
|
err = models.SharedServerDAO.UpdateAuditingServerNames(req.ServerId, true, req.ServerNamesJSON)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return this.Success()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改配置
|
// 修改配置
|
||||||
err = models.SharedServerDAO.UpdateServerNames(req.ServerId, req.Config)
|
err = models.SharedServerDAO.UpdateServerNames(req.ServerId, req.ServerNamesJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -397,6 +463,46 @@ func (this *ServerService) UpdateServerNames(ctx context.Context, req *pb.Update
|
|||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 审核服务的域名设置
|
||||||
|
func (this *ServerService) UpdateServerNamesAuditing(ctx context.Context, req *pb.UpdateServerNamesAuditingRequest) (*pb.RPCSuccess, error) {
|
||||||
|
// 校验请求
|
||||||
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.AuditingResult == nil {
|
||||||
|
return nil, errors.New("'result' should not be nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = models.SharedServerDAO.UpdateServerAuditing(req.ServerId, req.AuditingResult)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送消息提醒
|
||||||
|
_, userId, err := models.SharedServerDAO.FindServerAdminIdAndUserId(req.ServerId)
|
||||||
|
if userId > 0 {
|
||||||
|
if req.AuditingResult.IsOk {
|
||||||
|
err = models.SharedMessageDAO.CreateMessage(0, userId, models.MessageTypeServerNamesAuditingSuccess, models.LevelInfo, "服务域名审核通过", maps.Map{
|
||||||
|
"serverId": req.ServerId,
|
||||||
|
}.AsJSON())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = models.SharedMessageDAO.CreateMessage(0, userId, models.MessageTypeServerNamesAuditingFailed, models.LevelError, "服务域名审核失败,原因:"+req.AuditingResult.Reason, maps.Map{
|
||||||
|
"serverId": req.ServerId,
|
||||||
|
}.AsJSON())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.Success()
|
||||||
|
}
|
||||||
|
|
||||||
// 计算服务数量
|
// 计算服务数量
|
||||||
func (this *ServerService) CountAllEnabledServersMatch(ctx context.Context, req *pb.CountAllEnabledServersMatchRequest) (*pb.RPCCountResponse, error) {
|
func (this *ServerService) CountAllEnabledServersMatch(ctx context.Context, req *pb.CountAllEnabledServersMatchRequest) (*pb.RPCCountResponse, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
@@ -404,7 +510,7 @@ func (this *ServerService) CountAllEnabledServersMatch(ctx context.Context, req
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
count, err := models.SharedServerDAO.CountAllEnabledServersMatch(req.GroupId, req.Keyword, req.UserId)
|
count, err := models.SharedServerDAO.CountAllEnabledServersMatch(req.GroupId, req.Keyword, req.UserId, req.ClusterId, req.AuditingFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -419,7 +525,7 @@ func (this *ServerService) ListEnabledServersMatch(ctx context.Context, req *pb.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
servers, err := models.SharedServerDAO.ListEnabledServersMatch(req.Offset, req.Size, req.GroupId, req.Keyword, req.UserId)
|
servers, err := models.SharedServerDAO.ListEnabledServersMatch(req.Offset, req.Size, req.GroupId, req.Keyword, req.UserId, req.ClusterId, req.AuditingFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -466,6 +572,17 @@ func (this *ServerService) ListEnabledServersMatch(ctx context.Context, req *pb.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 审核结果
|
||||||
|
auditingResult := &pb.ServerNameAuditingResult{}
|
||||||
|
if len(server.AuditingResult) > 0 {
|
||||||
|
err = json.Unmarshal([]byte(server.AuditingResult), auditingResult)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
auditingResult.IsOk = true
|
||||||
|
}
|
||||||
|
|
||||||
result = append(result, &pb.Server{
|
result = append(result, &pb.Server{
|
||||||
Id: int64(server.Id),
|
Id: int64(server.Id),
|
||||||
IsOn: server.IsOn == 1,
|
IsOn: server.IsOn == 1,
|
||||||
@@ -482,6 +599,9 @@ func (this *ServerService) ListEnabledServersMatch(ctx context.Context, req *pb.
|
|||||||
IncludeNodes: []byte(server.IncludeNodes),
|
IncludeNodes: []byte(server.IncludeNodes),
|
||||||
ExcludeNodes: []byte(server.ExcludeNodes),
|
ExcludeNodes: []byte(server.ExcludeNodes),
|
||||||
ServerNamesJSON: []byte(server.ServerNames),
|
ServerNamesJSON: []byte(server.ServerNames),
|
||||||
|
IsAuditing: server.IsAuditing == 1,
|
||||||
|
AuditingServerNamesJSON: []byte(server.AuditingServerNames),
|
||||||
|
AuditingResult: auditingResult,
|
||||||
CreatedAt: int64(server.CreatedAt),
|
CreatedAt: int64(server.CreatedAt),
|
||||||
DnsName: server.DnsName,
|
DnsName: server.DnsName,
|
||||||
NodeCluster: &pb.NodeCluster{
|
NodeCluster: &pb.NodeCluster{
|
||||||
@@ -497,13 +617,20 @@ func (this *ServerService) ListEnabledServersMatch(ctx context.Context, req *pb.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 禁用某服务
|
// 禁用某服务
|
||||||
func (this *ServerService) DisableServer(ctx context.Context, req *pb.DisableServerRequest) (*pb.DisableServerResponse, error) {
|
func (this *ServerService) DeleteServer(ctx context.Context, req *pb.DeleteServerRequest) (*pb.RPCSuccess, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if userId > 0 {
|
||||||
|
err = models.SharedServerDAO.CheckUserServer(req.ServerId, userId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 查找服务
|
// 查找服务
|
||||||
server, err := models.SharedServerDAO.FindEnabledServer(req.ServerId)
|
server, err := models.SharedServerDAO.FindEnabledServer(req.ServerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -525,7 +652,7 @@ func (this *ServerService) DisableServer(ctx context.Context, req *pb.DisableSer
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &pb.DisableServerResponse{}, nil
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找单个服务
|
// 查找单个服务
|
||||||
@@ -848,7 +975,7 @@ func (this *ServerService) FindAllEnabledServersDNSWithClusterId(ctx context.Con
|
|||||||
// 查找单个服务的DNS信息
|
// 查找单个服务的DNS信息
|
||||||
func (this *ServerService) FindEnabledServerDNS(ctx context.Context, req *pb.FindEnabledServerDNSRequest) (*pb.FindEnabledServerDNSResponse, error) {
|
func (this *ServerService) FindEnabledServerDNS(ctx context.Context, req *pb.FindEnabledServerDNSRequest) (*pb.FindEnabledServerDNSResponse, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
_, _, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -932,3 +1059,16 @@ func (this *ServerService) notifyServerDNSChanged(serverId int64) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查服务是否属于某个用户
|
||||||
|
func (this *ServerService) CheckUserServer(ctx context.Context, req *pb.CheckUserServerRequest) (*pb.RPCSuccess, error) {
|
||||||
|
userId, err := this.ValidateUser(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = models.SharedServerDAO.CheckUserServer(req.ServerId, userId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return this.Success()
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package services
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/rpc"
|
||||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
@@ -259,7 +260,7 @@ func (this *UserService) ComposeUserDashboard(ctx context.Context, req *pb.Compo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 网站数量
|
// 网站数量
|
||||||
countServers, err := models.SharedServerDAO.CountAllEnabledServersMatch(0, "", req.UserId)
|
countServers, err := models.SharedServerDAO.CountAllEnabledServersMatch(0, "", req.UserId, 0, rpc.BoolFlagNone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user