Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d2ecf6822 | ||
|
|
1a6d160a33 | ||
|
|
b69132e1ca | ||
|
|
19890c209f | ||
|
|
1534436435 | ||
|
|
c087d1cba2 | ||
|
|
cfc2ec5e4b | ||
|
|
af9c8523e9 | ||
|
|
00977cf33e | ||
|
|
fc2d018207 | ||
|
|
8569eebfee | ||
|
|
73d72f0d33 | ||
|
|
c4b8540171 | ||
|
|
85219ac2ef | ||
|
|
6976454bde | ||
|
|
813ce44ceb | ||
|
|
294b57ca60 | ||
|
|
22010190b2 | ||
|
|
cc4cd9c620 | ||
|
|
5df9c0f1fd | ||
|
|
dc3594a08d | ||
|
|
49ba1336cd | ||
|
|
96db5af237 |
@@ -12,4 +12,5 @@ dbs:
|
|||||||
|
|
||||||
|
|
||||||
fields:
|
fields:
|
||||||
bool: [ "uamIsOn", "followPort", "requestHostExcludingPort", "autoRemoteStart", "autoInstallNftables" ]
|
bool: [ "uamIsOn", "followPort", "requestHostExcludingPort", "autoRemoteStart", "autoInstallNftables", "enableIPLists", "detectAgents", "checkingPorts", "enableRecordHealthCheck", "offlineIsNotified" ]
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package teaconst
|
package teaconst
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "1.0.4"
|
Version = "1.1.0"
|
||||||
|
|
||||||
ProductName = "Edge API"
|
ProductName = "Edge API"
|
||||||
ProcessName = "edge-api"
|
ProcessName = "edge-api"
|
||||||
@@ -18,7 +18,7 @@ const (
|
|||||||
|
|
||||||
// 其他节点版本号,用来检测是否有需要升级的节点
|
// 其他节点版本号,用来检测是否有需要升级的节点
|
||||||
|
|
||||||
NodeVersion = "1.0.4"
|
NodeVersion = "1.1.0"
|
||||||
|
|
||||||
// SQLVersion SQL版本号
|
// SQLVersion SQL版本号
|
||||||
SQLVersion = "11"
|
SQLVersion = "11"
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ import (
|
|||||||
type DNSTaskType = string
|
type DNSTaskType = string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DNSTaskTypeClusterChange DNSTaskType = "clusterChange"
|
DNSTaskTypeClusterChange DNSTaskType = "clusterChange" // 集群节点、服务发生变化
|
||||||
|
DNSTaskTypeClusterNodesChange DNSTaskType = "clusterNodesChange" // 集群中节点发生变化
|
||||||
DNSTaskTypeClusterRemoveDomain DNSTaskType = "clusterRemoveDomain" // 从集群中移除域名
|
DNSTaskTypeClusterRemoveDomain DNSTaskType = "clusterRemoveDomain" // 从集群中移除域名
|
||||||
DNSTaskTypeNodeChange DNSTaskType = "nodeChange"
|
DNSTaskTypeNodeChange DNSTaskType = "nodeChange"
|
||||||
DNSTaskTypeServerChange DNSTaskType = "serverChange"
|
DNSTaskTypeServerChange DNSTaskType = "serverChange"
|
||||||
|
|||||||
@@ -162,17 +162,36 @@ func CheckClusterDNS(tx *dbs.Tx, cluster *models.NodeCluster, checkNodeIssues bo
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(ipAddr) == 0 {
|
if len(ipAddr) == 0 {
|
||||||
issues = append(issues, &pb.DNSIssue{
|
// 检查是否有离线
|
||||||
Target: node.Name,
|
anyIPAddr, _, err := models.SharedNodeIPAddressDAO.FindFirstNodeAccessIPAddress(tx, nodeId, false, nodeconfigs.NodeRoleNode)
|
||||||
TargetId: nodeId,
|
if err != nil {
|
||||||
Type: "node",
|
return nil, err
|
||||||
Description: "没有设置IP地址",
|
}
|
||||||
Params: map[string]string{
|
if len(anyIPAddr) > 0 {
|
||||||
"clusterName": cluster.Name,
|
issues = append(issues, &pb.DNSIssue{
|
||||||
"clusterId": numberutils.FormatInt64(clusterId),
|
Target: node.Name,
|
||||||
},
|
TargetId: nodeId,
|
||||||
MustFix: true,
|
Type: "node",
|
||||||
})
|
Description: "节点所有IP地址处于离线状态",
|
||||||
|
Params: map[string]string{
|
||||||
|
"clusterName": cluster.Name,
|
||||||
|
"clusterId": numberutils.FormatInt64(clusterId),
|
||||||
|
},
|
||||||
|
MustFix: true,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
issues = append(issues, &pb.DNSIssue{
|
||||||
|
Target: node.Name,
|
||||||
|
TargetId: nodeId,
|
||||||
|
Type: "node",
|
||||||
|
Description: "没有设置可用的IP地址",
|
||||||
|
Params: map[string]string{
|
||||||
|
"clusterName": cluster.Name,
|
||||||
|
"clusterId": numberutils.FormatInt64(clusterId),
|
||||||
|
},
|
||||||
|
MustFix: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,6 +157,9 @@ func (this *HTTPHeaderPolicyDAO) UpdateDeletingHeaders(tx *dbs.Tx, policyId int6
|
|||||||
return errors.New("invalid policyId")
|
return errors.New("invalid policyId")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if headerNames == nil {
|
||||||
|
headerNames = []string{}
|
||||||
|
}
|
||||||
namesJSON, err := json.Marshal(headerNames)
|
namesJSON, err := json.Marshal(headerNames)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -164,7 +167,31 @@ func (this *HTTPHeaderPolicyDAO) UpdateDeletingHeaders(tx *dbs.Tx, policyId int6
|
|||||||
|
|
||||||
var op = NewHTTPHeaderPolicyOperator()
|
var op = NewHTTPHeaderPolicyOperator()
|
||||||
op.Id = policyId
|
op.Id = policyId
|
||||||
op.DeleteHeaders = string(namesJSON)
|
op.DeleteHeaders = namesJSON
|
||||||
|
err = this.Save(tx, op)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return this.NotifyUpdate(tx, policyId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNonStandardHeaders 修改非标Headers
|
||||||
|
func (this *HTTPHeaderPolicyDAO) UpdateNonStandardHeaders(tx *dbs.Tx, policyId int64, headerNames []string) error {
|
||||||
|
if policyId <= 0 {
|
||||||
|
return errors.New("invalid policyId")
|
||||||
|
}
|
||||||
|
|
||||||
|
if headerNames == nil {
|
||||||
|
headerNames = []string{}
|
||||||
|
}
|
||||||
|
namesJSON, err := json.Marshal(headerNames)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var op = NewHTTPHeaderPolicyOperator()
|
||||||
|
op.Id = policyId
|
||||||
|
op.NonStandardHeaders = namesJSON
|
||||||
err = this.Save(tx, op)
|
err = this.Save(tx, op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -220,9 +247,19 @@ func (this *HTTPHeaderPolicyDAO) ComposeHeaderPolicyConfig(tx *dbs.Tx, headerPol
|
|||||||
config.DeleteHeaders = headers
|
config.DeleteHeaders = headers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Non-Standard Headers
|
||||||
|
if IsNotNull(policy.NonStandardHeaders) {
|
||||||
|
var headers = []string{}
|
||||||
|
err = json.Unmarshal(policy.NonStandardHeaders, &headers)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.NonStandardHeaders = headers
|
||||||
|
}
|
||||||
|
|
||||||
// CORS
|
// CORS
|
||||||
if IsNotNull(policy.Cors) {
|
if IsNotNull(policy.Cors) {
|
||||||
var corsConfig = &shared.HTTPCORSHeaderConfig{}
|
var corsConfig = shared.NewHTTPCORSHeaderConfig()
|
||||||
err = json.Unmarshal(policy.Cors, corsConfig)
|
err = json.Unmarshal(policy.Cors, corsConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -4,35 +4,37 @@ import "github.com/iwind/TeaGo/dbs"
|
|||||||
|
|
||||||
// HTTPHeaderPolicy Header定义
|
// HTTPHeaderPolicy Header定义
|
||||||
type HTTPHeaderPolicy struct {
|
type HTTPHeaderPolicy struct {
|
||||||
Id uint32 `field:"id"` // ID
|
Id uint32 `field:"id"` // ID
|
||||||
IsOn bool `field:"isOn"` // 是否启用
|
IsOn bool `field:"isOn"` // 是否启用
|
||||||
State uint8 `field:"state"` // 状态
|
State uint8 `field:"state"` // 状态
|
||||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||||
UserId uint32 `field:"userId"` // 用户ID
|
UserId uint32 `field:"userId"` // 用户ID
|
||||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||||
AddHeaders dbs.JSON `field:"addHeaders"` // 添加的Header
|
AddHeaders dbs.JSON `field:"addHeaders"` // 添加的Header
|
||||||
AddTrailers dbs.JSON `field:"addTrailers"` // 添加的Trailers
|
AddTrailers dbs.JSON `field:"addTrailers"` // 添加的Trailers
|
||||||
SetHeaders dbs.JSON `field:"setHeaders"` // 设置Header
|
SetHeaders dbs.JSON `field:"setHeaders"` // 设置Header
|
||||||
ReplaceHeaders dbs.JSON `field:"replaceHeaders"` // 替换Header内容
|
ReplaceHeaders dbs.JSON `field:"replaceHeaders"` // 替换Header内容
|
||||||
Expires dbs.JSON `field:"expires"` // Expires单独设置
|
Expires dbs.JSON `field:"expires"` // Expires单独设置
|
||||||
DeleteHeaders dbs.JSON `field:"deleteHeaders"` // 删除的Headers
|
DeleteHeaders dbs.JSON `field:"deleteHeaders"` // 删除的Headers
|
||||||
Cors dbs.JSON `field:"cors"` // CORS配置
|
NonStandardHeaders dbs.JSON `field:"nonStandardHeaders"` // 非标Headers
|
||||||
|
Cors dbs.JSON `field:"cors"` // CORS配置
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTTPHeaderPolicyOperator struct {
|
type HTTPHeaderPolicyOperator struct {
|
||||||
Id any // ID
|
Id any // ID
|
||||||
IsOn any // 是否启用
|
IsOn any // 是否启用
|
||||||
State any // 状态
|
State any // 状态
|
||||||
AdminId any // 管理员ID
|
AdminId any // 管理员ID
|
||||||
UserId any // 用户ID
|
UserId any // 用户ID
|
||||||
CreatedAt any // 创建时间
|
CreatedAt any // 创建时间
|
||||||
AddHeaders any // 添加的Header
|
AddHeaders any // 添加的Header
|
||||||
AddTrailers any // 添加的Trailers
|
AddTrailers any // 添加的Trailers
|
||||||
SetHeaders any // 设置Header
|
SetHeaders any // 设置Header
|
||||||
ReplaceHeaders any // 替换Header内容
|
ReplaceHeaders any // 替换Header内容
|
||||||
Expires any // Expires单独设置
|
Expires any // Expires单独设置
|
||||||
DeleteHeaders any // 删除的Headers
|
DeleteHeaders any // 删除的Headers
|
||||||
Cors any // CORS配置
|
NonStandardHeaders any // 非标Headers
|
||||||
|
Cors any // CORS配置
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHTTPHeaderPolicyOperator() *HTTPHeaderPolicyOperator {
|
func NewHTTPHeaderPolicyOperator() *HTTPHeaderPolicyOperator {
|
||||||
|
|||||||
@@ -512,7 +512,7 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, isLocationOrGr
|
|||||||
|
|
||||||
// Referers
|
// Referers
|
||||||
if IsNotNull(web.Referers) {
|
if IsNotNull(web.Referers) {
|
||||||
var referersConfig = &serverconfigs.ReferersConfig{}
|
var referersConfig = serverconfigs.NewReferersConfig()
|
||||||
err = json.Unmarshal(web.Referers, referersConfig)
|
err = json.Unmarshal(web.Referers, referersConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -82,8 +82,11 @@ func (this *IPItemDAO) DisableIPItem(tx *dbs.Tx, id int64, sourceUserId int64) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
var query = this.Query(tx)
|
var query = this.Query(tx)
|
||||||
|
|
||||||
|
// 检查权限
|
||||||
if sourceUserId > 0 {
|
if sourceUserId > 0 {
|
||||||
query.Attr("sourceUserId", sourceUserId)
|
query.Where("(sourceUserId=:sourceUserId OR listId IN (SELECT id FROM " + SharedIPListDAO.Table + " WHERE userId=:sourceUserId AND state=1))")
|
||||||
|
query.Param("sourceUserId", sourceUserId)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = query.
|
_, err = query.
|
||||||
@@ -365,7 +368,9 @@ func (this *IPItemDAO) CountIPItemsWithListId(tx *dbs.Tx, listId int64, sourceUs
|
|||||||
State(IPItemStateEnabled).
|
State(IPItemStateEnabled).
|
||||||
Attr("listId", listId)
|
Attr("listId", listId)
|
||||||
if sourceUserId > 0 {
|
if sourceUserId > 0 {
|
||||||
query.Attr("sourceUserId", sourceUserId)
|
if listId <= 0 || listId == firewallconfigs.GlobalListId {
|
||||||
|
query.Attr("sourceUserId", sourceUserId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(keyword) > 0 {
|
if len(keyword) > 0 {
|
||||||
query.Where("(ipFrom LIKE :keyword OR ipTo LIKE :keyword)").
|
query.Where("(ipFrom LIKE :keyword OR ipTo LIKE :keyword)").
|
||||||
@@ -389,7 +394,9 @@ func (this *IPItemDAO) ListIPItemsWithListId(tx *dbs.Tx, listId int64, sourceUse
|
|||||||
State(IPItemStateEnabled).
|
State(IPItemStateEnabled).
|
||||||
Attr("listId", listId)
|
Attr("listId", listId)
|
||||||
if sourceUserId > 0 {
|
if sourceUserId > 0 {
|
||||||
query.Attr("sourceUserId", sourceUserId)
|
if listId <= 0 || listId == firewallconfigs.GlobalListId {
|
||||||
|
query.Attr("sourceUserId", sourceUserId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(keyword) > 0 {
|
if len(keyword) > 0 {
|
||||||
query.Where("(ipFrom LIKE :keyword OR ipTo LIKE :keyword)").
|
query.Where("(ipFrom LIKE :keyword OR ipTo LIKE :keyword)").
|
||||||
@@ -482,8 +489,13 @@ func (this *IPItemDAO) ExistsEnabledItem(tx *dbs.Tx, itemId int64) (bool, error)
|
|||||||
func (this *IPItemDAO) CountAllEnabledIPItems(tx *dbs.Tx, sourceUserId int64, keyword string, ip string, listId int64, unread bool, eventLevel string, listType string) (int64, error) {
|
func (this *IPItemDAO) CountAllEnabledIPItems(tx *dbs.Tx, sourceUserId int64, keyword string, ip string, listId int64, unread bool, eventLevel string, listType string) (int64, error) {
|
||||||
var query = this.Query(tx)
|
var query = this.Query(tx)
|
||||||
if sourceUserId > 0 {
|
if sourceUserId > 0 {
|
||||||
query.Attr("sourceUserId", sourceUserId)
|
if listId <= 0 {
|
||||||
query.UseIndex("sourceUserId")
|
query.Where("((listId=" + types.String(firewallconfigs.GlobalListId) + " AND sourceUserId=:sourceUserId) OR listId IN (SELECT id FROM " + SharedIPListDAO.Table + " WHERE userId=:sourceUserId AND state=1))")
|
||||||
|
query.Param("sourceUserId", sourceUserId)
|
||||||
|
} else if listId == firewallconfigs.GlobalListId {
|
||||||
|
query.Attr("sourceUserId", sourceUserId)
|
||||||
|
query.UseIndex("sourceUserId")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(keyword) > 0 {
|
if len(keyword) > 0 {
|
||||||
query.Like("ipFrom", dbutils.QuoteLike(keyword))
|
query.Like("ipFrom", dbutils.QuoteLike(keyword))
|
||||||
@@ -519,8 +531,13 @@ func (this *IPItemDAO) CountAllEnabledIPItems(tx *dbs.Tx, sourceUserId int64, ke
|
|||||||
func (this *IPItemDAO) ListAllEnabledIPItems(tx *dbs.Tx, sourceUserId int64, keyword string, ip string, listId int64, unread bool, eventLevel string, listType string, offset int64, size int64) (result []*IPItem, err error) {
|
func (this *IPItemDAO) ListAllEnabledIPItems(tx *dbs.Tx, sourceUserId int64, keyword string, ip string, listId int64, unread bool, eventLevel string, listType string, offset int64, size int64) (result []*IPItem, err error) {
|
||||||
var query = this.Query(tx)
|
var query = this.Query(tx)
|
||||||
if sourceUserId > 0 {
|
if sourceUserId > 0 {
|
||||||
query.Attr("sourceUserId", sourceUserId)
|
if listId <= 0 {
|
||||||
query.UseIndex("sourceUserId")
|
query.Where("((listId=" + types.String(firewallconfigs.GlobalListId) + " AND sourceUserId=:sourceUserId) OR listId IN (SELECT id FROM " + SharedIPListDAO.Table + " WHERE userId=:sourceUserId AND state=1))")
|
||||||
|
query.Param("sourceUserId", sourceUserId)
|
||||||
|
} else if listId == firewallconfigs.GlobalListId {
|
||||||
|
query.Attr("sourceUserId", sourceUserId)
|
||||||
|
query.UseIndex("sourceUserId")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(keyword) > 0 {
|
if len(keyword) > 0 {
|
||||||
query.Like("ipFrom", dbutils.QuoteLike(keyword))
|
query.Like("ipFrom", dbutils.QuoteLike(keyword))
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ const (
|
|||||||
|
|
||||||
MessageTypeReportNodeInactive MessageType = "ReportNodeInactive" // 区域监控节点节点不活跃
|
MessageTypeReportNodeInactive MessageType = "ReportNodeInactive" // 区域监控节点节点不活跃
|
||||||
MessageTypeReportNodeActive MessageType = "ReportNodeActive" // 区域监控节点活跃
|
MessageTypeReportNodeActive MessageType = "ReportNodeActive" // 区域监控节点活跃
|
||||||
MessageTypeConnectivity MessageType = "Connectivity"
|
MessageTypeConnectivity MessageType = "Connectivity" // 连通性
|
||||||
|
MessageTypeNodeSchedule MessageType = "NodeSchedule" // 节点调度信息
|
||||||
|
MessageTypeNodeOfflineDay MessageType = "NodeOfflineDay" // 节点到下线日期
|
||||||
)
|
)
|
||||||
|
|
||||||
type MessageDAO dbs.DAO
|
type MessageDAO dbs.DAO
|
||||||
|
|||||||
33
internal/db/models/nameservers/ns_domain_dao.go
Normal file
33
internal/db/models/nameservers/ns_domain_dao.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
NSDomainStateEnabled = 1 // 已启用
|
||||||
|
NSDomainStateDisabled = 0 // 已禁用
|
||||||
|
)
|
||||||
|
|
||||||
|
type NSDomainDAO dbs.DAO
|
||||||
|
|
||||||
|
func NewNSDomainDAO() *NSDomainDAO {
|
||||||
|
return dbs.NewDAO(&NSDomainDAO{
|
||||||
|
DAOObject: dbs.DAOObject{
|
||||||
|
DB: Tea.Env,
|
||||||
|
Table: "edgeNSDomains",
|
||||||
|
Model: new(NSDomain),
|
||||||
|
PkName: "id",
|
||||||
|
},
|
||||||
|
}).(*NSDomainDAO)
|
||||||
|
}
|
||||||
|
|
||||||
|
var SharedNSDomainDAO *NSDomainDAO
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
dbs.OnReady(func() {
|
||||||
|
SharedNSDomainDAO = NewNSDomainDAO()
|
||||||
|
})
|
||||||
|
}
|
||||||
6
internal/db/models/nameservers/ns_domain_dao_test.go
Normal file
6
internal/db/models/nameservers/ns_domain_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package nameservers_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
)
|
||||||
@@ -4,35 +4,37 @@ import "github.com/iwind/TeaGo/dbs"
|
|||||||
|
|
||||||
// NSDomain DNS域名
|
// NSDomain DNS域名
|
||||||
type NSDomain struct {
|
type NSDomain struct {
|
||||||
Id uint64 `field:"id"` // ID
|
Id uint64 `field:"id"` // ID
|
||||||
ClusterId uint32 `field:"clusterId"` // 集群ID
|
ClusterId uint32 `field:"clusterId"` // 集群ID
|
||||||
UserId uint32 `field:"userId"` // 用户ID
|
UserId uint32 `field:"userId"` // 用户ID
|
||||||
IsOn bool `field:"isOn"` // 是否启用
|
IsOn bool `field:"isOn"` // 是否启用
|
||||||
Name string `field:"name"` // 域名
|
Name string `field:"name"` // 域名
|
||||||
GroupIds dbs.JSON `field:"groupIds"` // 分组ID
|
GroupIds dbs.JSON `field:"groupIds"` // 分组ID
|
||||||
Tsig dbs.JSON `field:"tsig"` // TSIG配置
|
Tsig dbs.JSON `field:"tsig"` // TSIG配置
|
||||||
VerifyTXT string `field:"verifyTXT"` // 验证用的TXT
|
VerifyTXT string `field:"verifyTXT"` // 验证用的TXT
|
||||||
VerifyExpiresAt uint64 `field:"verifyExpiresAt"` // 验证TXT过期时间
|
VerifyExpiresAt uint64 `field:"verifyExpiresAt"` // 验证TXT过期时间
|
||||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
RecordsHealthCheck dbs.JSON `field:"recordsHealthCheck"` // 记录健康检查设置
|
||||||
Version uint64 `field:"version"` // 版本号
|
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||||
Status string `field:"status"` // 状态:none|verified
|
Version uint64 `field:"version"` // 版本号
|
||||||
State uint8 `field:"state"` // 状态
|
Status string `field:"status"` // 状态:none|verified
|
||||||
|
State uint8 `field:"state"` // 状态
|
||||||
}
|
}
|
||||||
|
|
||||||
type NSDomainOperator struct {
|
type NSDomainOperator struct {
|
||||||
Id any // ID
|
Id any // ID
|
||||||
ClusterId any // 集群ID
|
ClusterId any // 集群ID
|
||||||
UserId any // 用户ID
|
UserId any // 用户ID
|
||||||
IsOn any // 是否启用
|
IsOn any // 是否启用
|
||||||
Name any // 域名
|
Name any // 域名
|
||||||
GroupIds any // 分组ID
|
GroupIds any // 分组ID
|
||||||
Tsig any // TSIG配置
|
Tsig any // TSIG配置
|
||||||
VerifyTXT any // 验证用的TXT
|
VerifyTXT any // 验证用的TXT
|
||||||
VerifyExpiresAt any // 验证TXT过期时间
|
VerifyExpiresAt any // 验证TXT过期时间
|
||||||
CreatedAt any // 创建时间
|
RecordsHealthCheck any // 记录健康检查设置
|
||||||
Version any // 版本号
|
CreatedAt any // 创建时间
|
||||||
Status any // 状态:none|verified
|
Version any // 版本号
|
||||||
State any // 状态
|
Status any // 状态:none|verified
|
||||||
|
State any // 状态
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNSDomainOperator() *NSDomainOperator {
|
func NewNSDomainOperator() *NSDomainOperator {
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ type NSRecord struct {
|
|||||||
Ttl uint32 `field:"ttl"` // TTL(秒)
|
Ttl uint32 `field:"ttl"` // TTL(秒)
|
||||||
Weight uint32 `field:"weight"` // 权重
|
Weight uint32 `field:"weight"` // 权重
|
||||||
RouteIds dbs.JSON `field:"routeIds"` // 线路
|
RouteIds dbs.JSON `field:"routeIds"` // 线路
|
||||||
|
HealthCheck dbs.JSON `field:"healthCheck"` // 健康检查配置
|
||||||
|
CountUp uint32 `field:"countUp"` // 连续上线次数
|
||||||
|
CountDown uint32 `field:"countDown"` // 连续离线次数
|
||||||
|
IsUp bool `field:"isUp"` // 是否在线
|
||||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||||
Version uint64 `field:"version"` // 版本号
|
Version uint64 `field:"version"` // 版本号
|
||||||
State uint8 `field:"state"` // 状态
|
State uint8 `field:"state"` // 状态
|
||||||
@@ -42,6 +46,10 @@ type NSRecordOperator struct {
|
|||||||
Ttl any // TTL(秒)
|
Ttl any // TTL(秒)
|
||||||
Weight any // 权重
|
Weight any // 权重
|
||||||
RouteIds any // 线路
|
RouteIds any // 线路
|
||||||
|
HealthCheck any // 健康检查配置
|
||||||
|
CountUp any // 连续上线次数
|
||||||
|
CountDown any // 连续离线次数
|
||||||
|
IsUp any // 是否在线
|
||||||
CreatedAt any // 创建时间
|
CreatedAt any // 创建时间
|
||||||
Version any // 版本号
|
Version any // 版本号
|
||||||
State any // 状态
|
State any // 状态
|
||||||
|
|||||||
63
internal/db/models/node_action_dao.go
Normal file
63
internal/db/models/node_action_dao.go
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
NodeActionStateEnabled = 1 // 已启用
|
||||||
|
NodeActionStateDisabled = 0 // 已禁用
|
||||||
|
)
|
||||||
|
|
||||||
|
type NodeActionDAO dbs.DAO
|
||||||
|
|
||||||
|
func NewNodeActionDAO() *NodeActionDAO {
|
||||||
|
return dbs.NewDAO(&NodeActionDAO{
|
||||||
|
DAOObject: dbs.DAOObject{
|
||||||
|
DB: Tea.Env,
|
||||||
|
Table: "edgeNodeActions",
|
||||||
|
Model: new(NodeAction),
|
||||||
|
PkName: "id",
|
||||||
|
},
|
||||||
|
}).(*NodeActionDAO)
|
||||||
|
}
|
||||||
|
|
||||||
|
var SharedNodeActionDAO *NodeActionDAO
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
dbs.OnReady(func() {
|
||||||
|
SharedNodeActionDAO = NewNodeActionDAO()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnableNodeAction 启用条目
|
||||||
|
func (this *NodeActionDAO) EnableNodeAction(tx *dbs.Tx, id uint64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", NodeActionStateEnabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisableNodeAction 禁用条目
|
||||||
|
func (this *NodeActionDAO) DisableNodeAction(tx *dbs.Tx, id int64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", NodeActionStateDisabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindEnabledNodeAction 查找启用中的条目
|
||||||
|
func (this *NodeActionDAO) FindEnabledNodeAction(tx *dbs.Tx, id int64) (*NodeAction, error) {
|
||||||
|
result, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
State(NodeActionStateEnabled).
|
||||||
|
Find()
|
||||||
|
if result == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result.(*NodeAction), err
|
||||||
|
}
|
||||||
6
internal/db/models/node_action_dao_test.go
Normal file
6
internal/db/models/node_action_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package models_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
)
|
||||||
32
internal/db/models/node_action_model.go
Normal file
32
internal/db/models/node_action_model.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import "github.com/iwind/TeaGo/dbs"
|
||||||
|
|
||||||
|
// NodeAction 节点智能调度设置
|
||||||
|
type NodeAction struct {
|
||||||
|
Id uint64 `field:"id"` // ID
|
||||||
|
NodeId uint64 `field:"nodeId"` // 节点ID
|
||||||
|
Role string `field:"role"` // 角色
|
||||||
|
IsOn bool `field:"isOn"` // 是否启用
|
||||||
|
Conds dbs.JSON `field:"conds"` // 条件
|
||||||
|
Action dbs.JSON `field:"action"` // 动作
|
||||||
|
Duration dbs.JSON `field:"duration"` // 持续时间
|
||||||
|
Order uint32 `field:"order"` // 排序
|
||||||
|
State uint8 `field:"state"` // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
type NodeActionOperator struct {
|
||||||
|
Id any // ID
|
||||||
|
NodeId any // 节点ID
|
||||||
|
Role any // 角色
|
||||||
|
IsOn any // 是否启用
|
||||||
|
Conds any // 条件
|
||||||
|
Action any // 动作
|
||||||
|
Duration any // 持续时间
|
||||||
|
Order any // 排序
|
||||||
|
State any // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNodeActionOperator() *NodeActionOperator {
|
||||||
|
return &NodeActionOperator{}
|
||||||
|
}
|
||||||
1
internal/db/models/node_action_model_ext.go
Normal file
1
internal/db/models/node_action_model_ext.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package models
|
||||||
@@ -996,7 +996,7 @@ func (this *NodeClusterDAO) FindClusterBasicInfo(tx *dbs.Tx, clusterId int64, ca
|
|||||||
cluster, err := this.Query(tx).
|
cluster, err := this.Query(tx).
|
||||||
Pk(clusterId).
|
Pk(clusterId).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
Result("id", "name", "timeZone", "nodeMaxThreads", "cachePolicyId", "httpFirewallPolicyId", "autoOpenPorts", "webp", "uam", "isOn", "ddosProtection", "clock", "globalServerConfig", "autoInstallNftables").
|
Result("id", "name", "timeZone", "nodeMaxThreads", "cachePolicyId", "httpFirewallPolicyId", "autoOpenPorts", "webp", "uam", "cc", "httpPages", "isOn", "ddosProtection", "clock", "globalServerConfig", "autoInstallNftables").
|
||||||
Find()
|
Find()
|
||||||
if err != nil || cluster == nil {
|
if err != nil || cluster == nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1095,7 +1095,7 @@ func (this *NodeClusterDAO) UpdateClusterUAMPolicy(tx *dbs.Tx, clusterId int64,
|
|||||||
return this.NotifyUAMUpdate(tx, clusterId)
|
return this.NotifyUAMUpdate(tx, clusterId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindClusterUAMPolicy 查询设置
|
// FindClusterUAMPolicy 查询UAM设置
|
||||||
func (this *NodeClusterDAO) FindClusterUAMPolicy(tx *dbs.Tx, clusterId int64, cacheMap *utils.CacheMap) (*nodeconfigs.UAMPolicy, error) {
|
func (this *NodeClusterDAO) FindClusterUAMPolicy(tx *dbs.Tx, clusterId int64, cacheMap *utils.CacheMap) (*nodeconfigs.UAMPolicy, error) {
|
||||||
var cacheKey = this.Table + ":FindClusterUAMPolicy:" + types.String(clusterId)
|
var cacheKey = this.Table + ":FindClusterUAMPolicy:" + types.String(clusterId)
|
||||||
if cacheMap != nil {
|
if cacheMap != nil {
|
||||||
@@ -1125,6 +1125,146 @@ func (this *NodeClusterDAO) FindClusterUAMPolicy(tx *dbs.Tx, clusterId int64, ca
|
|||||||
return policy, nil
|
return policy, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateClusterHTTPCCPolicy 修改CC策略设置
|
||||||
|
func (this *NodeClusterDAO) UpdateClusterHTTPCCPolicy(tx *dbs.Tx, clusterId int64, httpCCPolicy *nodeconfigs.HTTPCCPolicy) error {
|
||||||
|
if httpCCPolicy == nil {
|
||||||
|
err := this.Query(tx).
|
||||||
|
Pk(clusterId).
|
||||||
|
Set("cc", dbs.SQL("null")).
|
||||||
|
UpdateQuickly()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.NotifyHTTPCCUpdate(tx, clusterId)
|
||||||
|
}
|
||||||
|
|
||||||
|
httpCCPolicyJSON, err := json.Marshal(httpCCPolicy)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = this.Query(tx).
|
||||||
|
Pk(clusterId).
|
||||||
|
Set("cc", httpCCPolicyJSON).
|
||||||
|
UpdateQuickly()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.NotifyHTTPCCUpdate(tx, clusterId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindClusterHTTPCCPolicy 查询CC策略设置
|
||||||
|
func (this *NodeClusterDAO) FindClusterHTTPCCPolicy(tx *dbs.Tx, clusterId int64, cacheMap *utils.CacheMap) (*nodeconfigs.HTTPCCPolicy, error) {
|
||||||
|
var cacheKey = this.Table + ":FindClusterHTTPCCPolicy:" + types.String(clusterId)
|
||||||
|
if cacheMap != nil {
|
||||||
|
cache, ok := cacheMap.Get(cacheKey)
|
||||||
|
if ok {
|
||||||
|
return cache.(*nodeconfigs.HTTPCCPolicy), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
httpCCJSON, err := this.Query(tx).
|
||||||
|
Pk(clusterId).
|
||||||
|
Result("cc").
|
||||||
|
FindJSONCol()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if IsNull(httpCCJSON) {
|
||||||
|
return nodeconfigs.NewHTTPCCPolicy(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var policy = nodeconfigs.NewHTTPCCPolicy()
|
||||||
|
err = json.Unmarshal(httpCCJSON, policy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return policy, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateClusterHTTPPagesPolicy 修改自定义页面设置
|
||||||
|
func (this *NodeClusterDAO) UpdateClusterHTTPPagesPolicy(tx *dbs.Tx, clusterId int64, httpPagesPolicy *nodeconfigs.HTTPPagesPolicy) error {
|
||||||
|
if httpPagesPolicy == nil {
|
||||||
|
err := this.Query(tx).
|
||||||
|
Pk(clusterId).
|
||||||
|
Set("httpPages", dbs.SQL("null")).
|
||||||
|
UpdateQuickly()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.NotifyHTTPPagesPolicyUpdate(tx, clusterId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除不需要保存的内容
|
||||||
|
var newPages = []*serverconfigs.HTTPPageConfig{}
|
||||||
|
for _, page := range httpPagesPolicy.Pages {
|
||||||
|
newPages = append(newPages, &serverconfigs.HTTPPageConfig{Id: page.Id})
|
||||||
|
}
|
||||||
|
httpPagesPolicy.Pages = newPages
|
||||||
|
|
||||||
|
httpPagesPolicyJSON, err := json.Marshal(httpPagesPolicy)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = this.Query(tx).
|
||||||
|
Pk(clusterId).
|
||||||
|
Set("httpPages", httpPagesPolicyJSON).
|
||||||
|
UpdateQuickly()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.NotifyHTTPPagesPolicyUpdate(tx, clusterId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindClusterHTTPPagesPolicy 查询自定义页面设置
|
||||||
|
func (this *NodeClusterDAO) FindClusterHTTPPagesPolicy(tx *dbs.Tx, clusterId int64, cacheMap *utils.CacheMap) (*nodeconfigs.HTTPPagesPolicy, error) {
|
||||||
|
var cacheKey = this.Table + ":FindClusterHTTPPagesPolicy:" + types.String(clusterId)
|
||||||
|
if cacheMap != nil {
|
||||||
|
cache, ok := cacheMap.Get(cacheKey)
|
||||||
|
if ok {
|
||||||
|
return cache.(*nodeconfigs.HTTPPagesPolicy), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pagesJSON, err := this.Query(tx).
|
||||||
|
Pk(clusterId).
|
||||||
|
Result("httpPages").
|
||||||
|
FindJSONCol()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if IsNull(pagesJSON) {
|
||||||
|
return nodeconfigs.NewHTTPPagesPolicy(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var policy = nodeconfigs.NewHTTPPagesPolicy()
|
||||||
|
err = json.Unmarshal(pagesJSON, policy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取Page信息
|
||||||
|
var newPages = []*serverconfigs.HTTPPageConfig{}
|
||||||
|
for _, page := range policy.Pages {
|
||||||
|
pageConfig, err := SharedHTTPPageDAO.ComposePageConfig(tx, page.Id, cacheMap)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if pageConfig == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newPages = append(newPages, pageConfig)
|
||||||
|
}
|
||||||
|
policy.Pages = newPages
|
||||||
|
|
||||||
|
return policy, nil
|
||||||
|
}
|
||||||
|
|
||||||
// FindClusterDDoSProtection 获取集群的DDoS设置
|
// FindClusterDDoSProtection 获取集群的DDoS设置
|
||||||
func (this *NodeClusterDAO) FindClusterDDoSProtection(tx *dbs.Tx, clusterId int64) (*ddosconfigs.ProtectionConfig, error) {
|
func (this *NodeClusterDAO) FindClusterDDoSProtection(tx *dbs.Tx, clusterId int64) (*ddosconfigs.ProtectionConfig, error) {
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
@@ -1217,6 +1357,16 @@ func (this *NodeClusterDAO) NotifyUAMUpdate(tx *dbs.Tx, clusterId int64) error {
|
|||||||
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, 0, 0, NodeTaskTypeUAMPolicyChanged)
|
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, 0, 0, NodeTaskTypeUAMPolicyChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotifyHTTPCCUpdate 通知HTTP CC更新
|
||||||
|
func (this *NodeClusterDAO) NotifyHTTPCCUpdate(tx *dbs.Tx, clusterId int64) error {
|
||||||
|
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, 0, 0, NodeTaskTypeHTTPCCPolicyChanged)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyHTTPPagesPolicyUpdate 通知HTTP Pages更新
|
||||||
|
func (this *NodeClusterDAO) NotifyHTTPPagesPolicyUpdate(tx *dbs.Tx, clusterId int64) error {
|
||||||
|
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, 0, 0, NodeTaskTypeHTTPPagesPolicyChanged)
|
||||||
|
}
|
||||||
|
|
||||||
// NotifyDNSUpdate 通知DNS更新
|
// NotifyDNSUpdate 通知DNS更新
|
||||||
// TODO 更新新的DNS解析记录的同时,需要删除老的DNS解析记录
|
// TODO 更新新的DNS解析记录的同时,需要删除老的DNS解析记录
|
||||||
func (this *NodeClusterDAO) NotifyDNSUpdate(tx *dbs.Tx, clusterId int64) error {
|
func (this *NodeClusterDAO) NotifyDNSUpdate(tx *dbs.Tx, clusterId int64) error {
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ type NodeCluster struct {
|
|||||||
AutoRemoteStart bool `field:"autoRemoteStart"` // 自动远程启动
|
AutoRemoteStart bool `field:"autoRemoteStart"` // 自动远程启动
|
||||||
AutoInstallNftables bool `field:"autoInstallNftables"` // 自动安装nftables
|
AutoInstallNftables bool `field:"autoInstallNftables"` // 自动安装nftables
|
||||||
IsAD bool `field:"isAD"` // 是否为高防集群
|
IsAD bool `field:"isAD"` // 是否为高防集群
|
||||||
|
HttpPages dbs.JSON `field:"httpPages"` // 自定义页面设置
|
||||||
|
Cc dbs.JSON `field:"cc"` // CC设置
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeClusterOperator struct {
|
type NodeClusterOperator struct {
|
||||||
@@ -81,6 +83,8 @@ type NodeClusterOperator struct {
|
|||||||
AutoRemoteStart any // 自动远程启动
|
AutoRemoteStart any // 自动远程启动
|
||||||
AutoInstallNftables any // 自动安装nftables
|
AutoInstallNftables any // 自动安装nftables
|
||||||
IsAD any // 是否为高防集群
|
IsAD any // 是否为高防集群
|
||||||
|
HttpPages any // 自定义页面设置
|
||||||
|
Cc any // CC设置
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNodeClusterOperator() *NodeClusterOperator {
|
func NewNodeClusterOperator() *NodeClusterOperator {
|
||||||
|
|||||||
@@ -1085,6 +1085,8 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, dataMap *shared
|
|||||||
var clusterIndex = 0
|
var clusterIndex = 0
|
||||||
config.WebPImagePolicies = map[int64]*nodeconfigs.WebPImagePolicy{}
|
config.WebPImagePolicies = map[int64]*nodeconfigs.WebPImagePolicy{}
|
||||||
config.UAMPolicies = map[int64]*nodeconfigs.UAMPolicy{}
|
config.UAMPolicies = map[int64]*nodeconfigs.UAMPolicy{}
|
||||||
|
config.HTTPCCPolicies = map[int64]*nodeconfigs.HTTPCCPolicy{}
|
||||||
|
config.HTTPPagesPolicies = map[int64]*nodeconfigs.HTTPPagesPolicy{}
|
||||||
var allowIPMaps = map[string]bool{}
|
var allowIPMaps = map[string]bool{}
|
||||||
for _, clusterId := range clusterIds {
|
for _, clusterId := range clusterIds {
|
||||||
nodeCluster, err := SharedNodeClusterDAO.FindClusterBasicInfo(tx, clusterId, cacheMap)
|
nodeCluster, err := SharedNodeClusterDAO.FindClusterBasicInfo(tx, clusterId, cacheMap)
|
||||||
@@ -1178,6 +1180,49 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, dataMap *shared
|
|||||||
config.UAMPolicies[clusterId] = uamPolicy
|
config.UAMPolicies[clusterId] = uamPolicy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTTP CC Policy
|
||||||
|
if IsNotNull(nodeCluster.Cc) {
|
||||||
|
var ccPolicy = nodeconfigs.NewHTTPCCPolicy()
|
||||||
|
err = json.Unmarshal(nodeCluster.Cc, ccPolicy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 集成默认设置
|
||||||
|
for i := 0; i < len(serverconfigs.DefaultHTTPCCThresholds); i ++ {
|
||||||
|
if i < len(ccPolicy.Thresholds) {
|
||||||
|
ccPolicy.Thresholds[i].MergeIfEmpty(serverconfigs.DefaultHTTPCCThresholds[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config.HTTPCCPolicies[clusterId] = ccPolicy
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTP Pages Policy
|
||||||
|
if IsNotNull(nodeCluster.HttpPages) {
|
||||||
|
var httpPagesPolicy = nodeconfigs.NewHTTPPagesPolicy()
|
||||||
|
err = json.Unmarshal(nodeCluster.HttpPages, httpPagesPolicy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if httpPagesPolicy.IsOn {
|
||||||
|
var newPages = []*serverconfigs.HTTPPageConfig{}
|
||||||
|
for _, page := range httpPagesPolicy.Pages {
|
||||||
|
pageConfig, err := SharedHTTPPageDAO.ComposePageConfig(tx, page.Id, cacheMap)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if pageConfig != nil && pageConfig.IsOn {
|
||||||
|
newPages = append(newPages, pageConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
httpPagesPolicy.Pages = newPages
|
||||||
|
if len(newPages) > 0 {
|
||||||
|
config.HTTPPagesPolicies[clusterId] = httpPagesPolicy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 自动安装nftables
|
// 自动安装nftables
|
||||||
if clusterIndex == 0 {
|
if clusterIndex == 0 {
|
||||||
config.AutoInstallNftables = nodeCluster.AutoInstallNftables
|
config.AutoInstallNftables = nodeCluster.AutoInstallNftables
|
||||||
@@ -1394,7 +1439,7 @@ func (this *NodeDAO) CountAllEnabledNodesWithGrantId(tx *dbs.Tx, grantId int64)
|
|||||||
func (this *NodeDAO) FindAllEnabledNodesWithGrantId(tx *dbs.Tx, grantId int64) (result []*Node, err error) {
|
func (this *NodeDAO) FindAllEnabledNodesWithGrantId(tx *dbs.Tx, grantId int64) (result []*Node, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(NodeStateEnabled).
|
State(NodeStateEnabled).
|
||||||
Where("id IN (SELECT nodeId FROM edgeNodeLogins WHERE type='ssh' AND JSON_CONTAINS(params, :grantParam))").
|
Where("id IN (SELECT nodeId FROM edgeNodeLogins WHERE type='ssh' AND JSON_CONTAINS(params, :grantParam) AND state=1)").
|
||||||
Param("grantParam", string(maps.Map{"grantId": grantId}.AsJSON())).
|
Param("grantParam", string(maps.Map{"grantId": grantId}.AsJSON())).
|
||||||
Where("clusterId IN (SELECT id FROM edgeNodeClusters WHERE state=1)").
|
Where("clusterId IN (SELECT id FROM edgeNodeClusters WHERE state=1)").
|
||||||
Slice(&result).
|
Slice(&result).
|
||||||
@@ -1550,7 +1595,7 @@ func (this *NodeDAO) FindAllEnabledNodesDNSWithClusterId(tx *dbs.Tx, clusterId i
|
|||||||
Attr("isOn", true).
|
Attr("isOn", true).
|
||||||
Attr("isUp", true).
|
Attr("isUp", true).
|
||||||
Attr("isInstalled", isInstalled).
|
Attr("isInstalled", isInstalled).
|
||||||
Result("id", "name", "dnsRoutes", "isOn").
|
Result("id", "name", "dnsRoutes", "isOn", "offlineDay", "actionStatus", "isBackupForCluster", "isBackupForGroup", "backupIPs", "clusterId", "groupId").
|
||||||
DescPk().
|
DescPk().
|
||||||
Slice(&result).
|
Slice(&result).
|
||||||
FindAll()
|
FindAll()
|
||||||
@@ -1575,7 +1620,7 @@ func (this *NodeDAO) FindEnabledNodeDNS(tx *dbs.Tx, nodeId int64) (*Node, error)
|
|||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
State(NodeStateEnabled).
|
State(NodeStateEnabled).
|
||||||
Pk(nodeId).
|
Pk(nodeId).
|
||||||
Result("id", "name", "dnsRoutes", "clusterId", "isOn").
|
Result("id", "name", "dnsRoutes", "clusterId", "isOn", "offlineDay", "isBackupForCluster", "isBackupForGroup", "actionStatus").
|
||||||
Find()
|
Find()
|
||||||
if one == nil {
|
if one == nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -18,3 +18,8 @@ func (this *NodeDAO) loadServersFromCluster(tx *dbs.Tx, clusterId int64, serverI
|
|||||||
func (this *NodeDAO) composeExtConfig(tx *dbs.Tx, config *nodeconfigs.NodeConfig, clusterIds []int64, cacheMap *utils.CacheMap) error {
|
func (this *NodeDAO) composeExtConfig(tx *dbs.Tx, config *nodeconfigs.NodeConfig, clusterIds []int64, cacheMap *utils.CacheMap) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckNodeIPAddresses 检查节点IP地址
|
||||||
|
func (this *NodeDAO) CheckNodeIPAddresses(tx *dbs.Tx, node *Node) (shouldSkip bool, shouldOverwrite bool, ipAddressStrings []string, err error) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ func (this *NodeIPAddressDAO) FindFirstNodeAccessIPAddressId(tx *dbs.Tx, nodeId
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindNodeAccessAndUpIPAddresses 查找节点所有的可访问的IP地址
|
// FindNodeAccessAndUpIPAddresses 查找节点所有的可访问且在线的IP地址
|
||||||
func (this *NodeIPAddressDAO) FindNodeAccessAndUpIPAddresses(tx *dbs.Tx, nodeId int64, role nodeconfigs.NodeRole) (result []*NodeIPAddress, err error) {
|
func (this *NodeIPAddressDAO) FindNodeAccessAndUpIPAddresses(tx *dbs.Tx, nodeId int64, role nodeconfigs.NodeRole) (result []*NodeIPAddress, err error) {
|
||||||
if len(role) == 0 {
|
if len(role) == 0 {
|
||||||
role = nodeconfigs.NodeRoleNode
|
role = nodeconfigs.NodeRoleNode
|
||||||
@@ -326,6 +326,24 @@ func (this *NodeIPAddressDAO) FindNodeAccessAndUpIPAddresses(tx *dbs.Tx, nodeId
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindNodeAccessIPAddresses 查找节点所有的可访问的IP地址,包括在线和离线
|
||||||
|
func (this *NodeIPAddressDAO) FindNodeAccessIPAddresses(tx *dbs.Tx, nodeId int64, role nodeconfigs.NodeRole) (result []*NodeIPAddress, err error) {
|
||||||
|
if len(role) == 0 {
|
||||||
|
role = nodeconfigs.NodeRoleNode
|
||||||
|
}
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Attr("role", role).
|
||||||
|
Attr("nodeId", nodeId).
|
||||||
|
State(NodeIPAddressStateEnabled).
|
||||||
|
Attr("canAccess", true).
|
||||||
|
Attr("isOn", true).
|
||||||
|
Desc("order").
|
||||||
|
AscPk().
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// CountAllEnabledIPAddresses 计算IP地址数量
|
// CountAllEnabledIPAddresses 计算IP地址数量
|
||||||
// TODO 目前支持边缘节点,将来支持NS节点
|
// TODO 目前支持边缘节点,将来支持NS节点
|
||||||
func (this *NodeIPAddressDAO) CountAllEnabledIPAddresses(tx *dbs.Tx, role string, nodeClusterId int64, upState configutils.BoolState, keyword string) (int64, error) {
|
func (this *NodeIPAddressDAO) CountAllEnabledIPAddresses(tx *dbs.Tx, role string, nodeClusterId int64, upState configutils.BoolState, keyword string) (int64, error) {
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ type Node struct {
|
|||||||
DnsResolver dbs.JSON `field:"dnsResolver"` // DNS解析器
|
DnsResolver dbs.JSON `field:"dnsResolver"` // DNS解析器
|
||||||
EnableIPLists bool `field:"enableIPLists"` // 启用IP名单
|
EnableIPLists bool `field:"enableIPLists"` // 启用IP名单
|
||||||
ApiNodeAddrs dbs.JSON `field:"apiNodeAddrs"` // API节点地址
|
ApiNodeAddrs dbs.JSON `field:"apiNodeAddrs"` // API节点地址
|
||||||
|
OfflineDay string `field:"offlineDay"` // 下线日期YYYYMMDD
|
||||||
|
OfflineIsNotified bool `field:"offlineIsNotified"` // 下线是否已通知
|
||||||
|
IsBackupForCluster bool `field:"isBackupForCluster"` // 是否为集群备用节点
|
||||||
|
IsBackupForGroup bool `field:"isBackupForGroup"` // 是否为分组备用节点
|
||||||
|
BackupIPs dbs.JSON `field:"backupIPs"` // 备用IP
|
||||||
|
ActionStatus dbs.JSON `field:"actionStatus"` // 当前动作配置
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeOperator struct {
|
type NodeOperator struct {
|
||||||
@@ -85,6 +91,12 @@ type NodeOperator struct {
|
|||||||
DnsResolver any // DNS解析器
|
DnsResolver any // DNS解析器
|
||||||
EnableIPLists any // 启用IP名单
|
EnableIPLists any // 启用IP名单
|
||||||
ApiNodeAddrs any // API节点地址
|
ApiNodeAddrs any // API节点地址
|
||||||
|
OfflineDay any // 下线日期YYYYMMDD
|
||||||
|
OfflineIsNotified any // 下线是否已通知
|
||||||
|
IsBackupForCluster any // 是否为集群备用节点
|
||||||
|
IsBackupForGroup any // 是否为分组备用节点
|
||||||
|
BackupIPs any // 备用IP
|
||||||
|
ActionStatus any // 当前动作配置
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNodeOperator() *NodeOperator {
|
func NewNodeOperator() *NodeOperator {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -16,7 +17,7 @@ func (this *Node) DecodeInstallStatus() (*NodeInstallStatus, error) {
|
|||||||
if len(this.InstallStatus) == 0 {
|
if len(this.InstallStatus) == 0 {
|
||||||
return NewNodeInstallStatus(), nil
|
return NewNodeInstallStatus(), nil
|
||||||
}
|
}
|
||||||
status := &NodeInstallStatus{}
|
var status = &NodeInstallStatus{}
|
||||||
err := json.Unmarshal(this.InstallStatus, status)
|
err := json.Unmarshal(this.InstallStatus, status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NewNodeInstallStatus(), err
|
return NewNodeInstallStatus(), err
|
||||||
@@ -37,7 +38,7 @@ func (this *Node) DecodeStatus() (*nodeconfigs.NodeStatus, error) {
|
|||||||
if len(this.Status) == 0 {
|
if len(this.Status) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
status := &nodeconfigs.NodeStatus{}
|
var status = &nodeconfigs.NodeStatus{}
|
||||||
err := json.Unmarshal(this.Status, status)
|
err := json.Unmarshal(this.Status, status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -47,7 +48,7 @@ func (this *Node) DecodeStatus() (*nodeconfigs.NodeStatus, error) {
|
|||||||
|
|
||||||
// DNSRouteCodes 所有的DNS线路
|
// DNSRouteCodes 所有的DNS线路
|
||||||
func (this *Node) DNSRouteCodes() map[int64][]string {
|
func (this *Node) DNSRouteCodes() map[int64][]string {
|
||||||
routes := map[int64][]string{} // domainId => routes
|
var routes = map[int64][]string{} // domainId => routes
|
||||||
if len(this.DnsRoutes) == 0 {
|
if len(this.DnsRoutes) == 0 {
|
||||||
return routes
|
return routes
|
||||||
}
|
}
|
||||||
@@ -61,7 +62,7 @@ func (this *Node) DNSRouteCodes() map[int64][]string {
|
|||||||
|
|
||||||
// DNSRouteCodesForDomainId DNS线路
|
// DNSRouteCodesForDomainId DNS线路
|
||||||
func (this *Node) DNSRouteCodesForDomainId(dnsDomainId int64) ([]string, error) {
|
func (this *Node) DNSRouteCodesForDomainId(dnsDomainId int64) ([]string, error) {
|
||||||
routes := map[int64][]string{} // domainId => routes
|
var routes = map[int64][]string{} // domainId => routes
|
||||||
if len(this.DnsRoutes) == 0 {
|
if len(this.DnsRoutes) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -80,7 +81,7 @@ func (this *Node) DNSRouteCodesForDomainId(dnsDomainId int64) ([]string, error)
|
|||||||
|
|
||||||
// DecodeConnectedAPINodeIds 连接的API
|
// DecodeConnectedAPINodeIds 连接的API
|
||||||
func (this *Node) DecodeConnectedAPINodeIds() ([]int64, error) {
|
func (this *Node) DecodeConnectedAPINodeIds() ([]int64, error) {
|
||||||
apiNodeIds := []int64{}
|
var apiNodeIds = []int64{}
|
||||||
if IsNotNull(this.ConnectedAPINodes) {
|
if IsNotNull(this.ConnectedAPINodes) {
|
||||||
err := json.Unmarshal(this.ConnectedAPINodes, &apiNodeIds)
|
err := json.Unmarshal(this.ConnectedAPINodes, &apiNodeIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -214,3 +215,8 @@ func (this *Node) DecodeAPINodeAddrs() []*serverconfigs.NetworkAddressConfig {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckIsOffline 检查是否已经离线
|
||||||
|
func (this *Node) CheckIsOffline() bool {
|
||||||
|
return len(this.OfflineDay) > 0 && this.OfflineDay < timeutil.Format("Ymd")
|
||||||
|
}
|
||||||
|
|||||||
9
internal/db/models/node_model_ext_schdule.go
Normal file
9
internal/db/models/node_model_ext_schdule.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
//go:build !plus
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
// HasScheduleSettings 检查是否设置了调度
|
||||||
|
func (this *Node) HasScheduleSettings() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
@@ -25,6 +25,8 @@ const (
|
|||||||
NodeTaskTypeNodeLevelChanged NodeTaskType = "nodeLevelChanged" // 节点级别变化
|
NodeTaskTypeNodeLevelChanged NodeTaskType = "nodeLevelChanged" // 节点级别变化
|
||||||
NodeTaskTypeUserServersStateChanged NodeTaskType = "userServersStateChanged" // 用户服务状态变化
|
NodeTaskTypeUserServersStateChanged NodeTaskType = "userServersStateChanged" // 用户服务状态变化
|
||||||
NodeTaskTypeUAMPolicyChanged NodeTaskType = "uamPolicyChanged" // UAM策略变化
|
NodeTaskTypeUAMPolicyChanged NodeTaskType = "uamPolicyChanged" // UAM策略变化
|
||||||
|
NodeTaskTypeHTTPPagesPolicyChanged NodeTaskType = "httpPagesPolicyChanged" // 自定义页面变化
|
||||||
|
NodeTaskTypeHTTPCCPolicyChanged NodeTaskType = "httpCCPolicyChanged" // CC策略变化
|
||||||
NodeTaskTypeUpdatingServers NodeTaskType = "updatingServers" // 更新一组服务
|
NodeTaskTypeUpdatingServers NodeTaskType = "updatingServers" // 更新一组服务
|
||||||
|
|
||||||
// NS相关
|
// NS相关
|
||||||
@@ -297,8 +299,8 @@ func (this *NodeTaskDAO) FindAllDoingNodeTasksWithClusterId(tx *dbs.Tx, role str
|
|||||||
Gt("nodeId", 0).
|
Gt("nodeId", 0).
|
||||||
Where("(isDone=0 OR (isDone=1 AND isOk=0))").
|
Where("(isDone=0 OR (isDone=1 AND isOk=0))").
|
||||||
Desc("isDone").
|
Desc("isDone").
|
||||||
Asc().
|
|
||||||
Asc("nodeId").
|
Asc("nodeId").
|
||||||
|
AscPk().
|
||||||
Slice(&result).
|
Slice(&result).
|
||||||
FindAll()
|
FindAll()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package stats
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
@@ -84,7 +84,9 @@ func (this *NodeTrafficDailyStatDAO) IncreaseDailyStat(tx *dbs.Tx, clusterId int
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
|
// 触发钩子
|
||||||
|
return this.increaseDailyStatHook(tx, role, nodeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindDailyStats 获取日期之间统计
|
// FindDailyStats 获取日期之间统计
|
||||||
14
internal/db/models/node_traffic_daily_stat_dao_ext.go
Normal file
14
internal/db/models/node_traffic_daily_stat_dao_ext.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
//go:build !plus
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 增加日统计Hook
|
||||||
|
func (this *NodeTrafficDailyStatDAO) increaseDailyStatHook(tx *dbs.Tx, role nodeconfigs.NodeRole, nodeId int64) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package stats
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package stats
|
package models
|
||||||
|
|
||||||
// NodeTrafficDailyStat 总的流量统计(按天)
|
// NodeTrafficDailyStat 总的流量统计(按天)
|
||||||
type NodeTrafficDailyStat struct {
|
type NodeTrafficDailyStat struct {
|
||||||
1
internal/db/models/node_traffic_daily_stat_model_ext.go
Normal file
1
internal/db/models/node_traffic_daily_stat_model_ext.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package models
|
||||||
@@ -37,11 +37,15 @@ func init() {
|
|||||||
|
|
||||||
// CreateValue 创建值
|
// CreateValue 创建值
|
||||||
func (this *NodeValueDAO) CreateValue(tx *dbs.Tx, clusterId int64, role nodeconfigs.NodeRole, nodeId int64, item string, valueJSON []byte, createdAt int64) error {
|
func (this *NodeValueDAO) CreateValue(tx *dbs.Tx, clusterId int64, role nodeconfigs.NodeRole, nodeId int64, item string, valueJSON []byte, createdAt int64) error {
|
||||||
|
if len(valueJSON) == 0 {
|
||||||
|
return errors.New("'valueJSON' should not be nil")
|
||||||
|
}
|
||||||
|
|
||||||
var day = timeutil.FormatTime("Ymd", createdAt)
|
var day = timeutil.FormatTime("Ymd", createdAt)
|
||||||
var hour = timeutil.FormatTime("YmdH", createdAt)
|
var hour = timeutil.FormatTime("YmdH", createdAt)
|
||||||
var minute = timeutil.FormatTime("YmdHi", createdAt)
|
var minute = timeutil.FormatTime("YmdHi", createdAt)
|
||||||
|
|
||||||
return this.Query(tx).
|
err := this.Query(tx).
|
||||||
InsertOrUpdateQuickly(maps.Map{
|
InsertOrUpdateQuickly(maps.Map{
|
||||||
"clusterId": clusterId,
|
"clusterId": clusterId,
|
||||||
"role": role,
|
"role": role,
|
||||||
@@ -55,6 +59,17 @@ func (this *NodeValueDAO) CreateValue(tx *dbs.Tx, clusterId int64, role nodeconf
|
|||||||
}, maps.Map{
|
}, maps.Map{
|
||||||
"value": valueJSON,
|
"value": valueJSON,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 触发钩子
|
||||||
|
err = this.nodeValueHook(tx, role, nodeId, item, valueJSON)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean 清除数据
|
// Clean 清除数据
|
||||||
@@ -324,7 +339,7 @@ func (this *NodeValueDAO) SumNodeClusterValues(tx *dbs.Tx, role string, clusterI
|
|||||||
|
|
||||||
// FindLatestNodeValue 获取最近一条数据
|
// FindLatestNodeValue 获取最近一条数据
|
||||||
func (this *NodeValueDAO) FindLatestNodeValue(tx *dbs.Tx, role string, nodeId int64, item string) (*NodeValue, error) {
|
func (this *NodeValueDAO) FindLatestNodeValue(tx *dbs.Tx, role string, nodeId int64, item string) (*NodeValue, error) {
|
||||||
fromMinute := timeutil.FormatTime("YmdHi", time.Now().Unix()-int64(60))
|
var fromMinute = timeutil.FormatTime("YmdHi", time.Now().Unix()-int64(60))
|
||||||
|
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
Attr("role", role).
|
Attr("role", role).
|
||||||
|
|||||||
14
internal/db/models/node_value_dao_ext.go
Normal file
14
internal/db/models/node_value_dao_ext.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
//go:build !plus
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 节点值变更Hook
|
||||||
|
func (this *NodeValueDAO) nodeValueHook(tx *dbs.Tx, role nodeconfigs.NodeRole, nodeId int64, item nodeconfigs.NodeValueItem, valueJSON []byte) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -122,7 +122,7 @@ func (this *RegionProvinceDAO) FindAllEnabledProvincesWithCountryId(tx *dbs.Tx,
|
|||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(RegionProvinceStateEnabled).
|
State(RegionProvinceStateEnabled).
|
||||||
Attr("countryId", countryId).
|
Attr("countryId", countryId).
|
||||||
Asc().
|
AscPk().
|
||||||
Slice(&result).
|
Slice(&result).
|
||||||
FindAll()
|
FindAll()
|
||||||
return
|
return
|
||||||
@@ -132,7 +132,7 @@ func (this *RegionProvinceDAO) FindAllEnabledProvincesWithCountryId(tx *dbs.Tx,
|
|||||||
func (this *RegionProvinceDAO) FindAllEnabledProvinces(tx *dbs.Tx) (result []*RegionProvince, err error) {
|
func (this *RegionProvinceDAO) FindAllEnabledProvinces(tx *dbs.Tx) (result []*RegionProvince, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(RegionProvinceStateEnabled).
|
State(RegionProvinceStateEnabled).
|
||||||
Asc().
|
AscPk().
|
||||||
Slice(&result).
|
Slice(&result).
|
||||||
FindAll()
|
FindAll()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1594,12 +1594,16 @@ func (this *ServerDAO) FindAllEnabledServersWithDomain(tx *dbs.Tx, domain string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FindEnabledServerWithDomain 根据域名查找服务集群ID
|
// FindEnabledServerWithDomain 根据域名查找服务集群ID
|
||||||
func (this *ServerDAO) FindEnabledServerWithDomain(tx *dbs.Tx, domain string) (server *Server, err error) {
|
func (this *ServerDAO) FindEnabledServerWithDomain(tx *dbs.Tx, userId int64, domain string) (server *Server, err error) {
|
||||||
if len(domain) == 0 {
|
if len(domain) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
one, err := this.Query(tx).
|
var query = this.Query(tx)
|
||||||
|
if userId > 0 {
|
||||||
|
query.Attr("userId", userId)
|
||||||
|
}
|
||||||
|
one, err := query.
|
||||||
State(ServerStateEnabled).
|
State(ServerStateEnabled).
|
||||||
Where("JSON_CONTAINS(plainServerNames, :domain)").
|
Where("JSON_CONTAINS(plainServerNames, :domain)").
|
||||||
Param("domain", strconv.Quote(domain)).
|
Param("domain", strconv.Quote(domain)).
|
||||||
@@ -1618,7 +1622,11 @@ func (this *ServerDAO) FindEnabledServerWithDomain(tx *dbs.Tx, domain string) (s
|
|||||||
var dotIndex = strings.Index(domain, ".")
|
var dotIndex = strings.Index(domain, ".")
|
||||||
if dotIndex > 0 {
|
if dotIndex > 0 {
|
||||||
var wildcardDomain = "*." + domain[dotIndex+1:]
|
var wildcardDomain = "*." + domain[dotIndex+1:]
|
||||||
one, err = this.Query(tx).
|
var wildcardQuery = this.Query(tx)
|
||||||
|
if userId > 0 {
|
||||||
|
wildcardQuery.Attr("userId", userId)
|
||||||
|
}
|
||||||
|
one, err = wildcardQuery.
|
||||||
State(ServerStateEnabled).
|
State(ServerStateEnabled).
|
||||||
Where("JSON_CONTAINS(plainServerNames, :domain)").
|
Where("JSON_CONTAINS(plainServerNames, :domain)").
|
||||||
Param("domain", strconv.Quote(wildcardDomain)).
|
Param("domain", strconv.Quote(wildcardDomain)).
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
package stats
|
|
||||||
@@ -51,7 +51,7 @@ func (this *SysEventDAO) CreateEvent(tx *dbs.Tx, event EventInterface) error {
|
|||||||
// 查找事件
|
// 查找事件
|
||||||
func (this *SysEventDAO) FindEvents(tx *dbs.Tx, size int64) (result []*SysEvent, err error) {
|
func (this *SysEventDAO) FindEvents(tx *dbs.Tx, size int64) (result []*SysEvent, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Asc().
|
AscPk().
|
||||||
Limit(size).
|
Limit(size).
|
||||||
Slice(&result).
|
Slice(&result).
|
||||||
FindAll()
|
FindAll()
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func (this *UpdatingServerListDAO) FindLists(tx *dbs.Tx, clusterIds []int64, las
|
|||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Attr("clusterId", clusterIds). // 即使clusterIds数量是变化的,这里也不需要使用Reuse(false),因为clusterIds通常数量有限
|
Attr("clusterId", clusterIds). // 即使clusterIds数量是变化的,这里也不需要使用Reuse(false),因为clusterIds通常数量有限
|
||||||
Gt("id", lastId).
|
Gt("id", lastId).
|
||||||
Asc(). // 非常重要
|
AscPk(). // 非常重要
|
||||||
Slice(&result).
|
Slice(&result).
|
||||||
FindAll()
|
FindAll()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
//go:build !plus
|
//go:build !plus
|
||||||
// +build !plus
|
|
||||||
|
|
||||||
package dnsclients
|
package dnsclients
|
||||||
|
|
||||||
import "github.com/iwind/TeaGo/maps"
|
import (
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
// FindProvider 查找服务商实例
|
// FindProvider 查找服务商实例
|
||||||
func FindProvider(providerType ProviderType, providerId int64) ProviderInterface {
|
func FindProvider(providerType ProviderType, providerId int64) ProviderInterface {
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ func (this *APINode) checkDB() error {
|
|||||||
// 决定是否尝试启动本地的MySQL
|
// 决定是否尝试启动本地的MySQL
|
||||||
if strings.Contains(err.Error(), "connection refused") {
|
if strings.Contains(err.Error(), "connection refused") {
|
||||||
config, _ := db.Config()
|
config, _ := db.Config()
|
||||||
if config != nil && (strings.Contains(config.Dsn, "tcp(127.0.0.1:") || strings.Contains(config.Dsn, "tcp(localhost:)")) && os.Getgid() == 0 /** ROOT 用户 **/ {
|
if config != nil && (strings.Contains(config.Dsn, "tcp(127.0.0.1:") || strings.Contains(config.Dsn, "tcp(localhost:")) && os.Getgid() == 0 /** ROOT 用户 **/ {
|
||||||
var mysqldSafeFile = "/usr/local/mysql/bin/mysqld_safe"
|
var mysqldSafeFile = "/usr/local/mysql/bin/mysqld_safe"
|
||||||
_, err = os.Stat(mysqldSafeFile)
|
_, err = os.Stat(mysqldSafeFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -420,6 +420,12 @@ func (this *ACMETaskService) FindEnabledACMETask(ctx context.Context, req *pb.Fi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 证书
|
||||||
|
var pbCert *pb.SSLCert
|
||||||
|
if task.CertId > 0 {
|
||||||
|
pbCert = &pb.SSLCert{Id: int64(task.CertId)}
|
||||||
|
}
|
||||||
|
|
||||||
return &pb.FindEnabledACMETaskResponse{AcmeTask: &pb.ACMETask{
|
return &pb.FindEnabledACMETaskResponse{AcmeTask: &pb.ACMETask{
|
||||||
Id: int64(task.Id),
|
Id: int64(task.Id),
|
||||||
IsOn: task.IsOn,
|
IsOn: task.IsOn,
|
||||||
@@ -431,5 +437,6 @@ func (this *ACMETaskService) FindEnabledACMETask(ctx context.Context, req *pb.Fi
|
|||||||
AcmeUser: pbACMEUser,
|
AcmeUser: pbACMEUser,
|
||||||
AuthType: task.AuthType,
|
AuthType: task.AuthType,
|
||||||
AuthURL: task.AuthURL,
|
AuthURL: task.AuthURL,
|
||||||
|
SslCert: pbCert,
|
||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -369,7 +369,11 @@ func (this *AdminService) CountAllEnabledAdmins(ctx context.Context, req *pb.Cou
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := models.SharedAdminDAO.CountAllEnabledAdmins(tx, req.Keyword, isSuperAdmin && req.HasWeakPassword)
|
if !isSuperAdmin && req.HasWeakPassword {
|
||||||
|
return this.SuccessCount(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
count, err := models.SharedAdminDAO.CountAllEnabledAdmins(tx, req.Keyword, req.HasWeakPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -393,7 +397,11 @@ func (this *AdminService) ListEnabledAdmins(ctx context.Context, req *pb.ListEna
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
admins, err := models.SharedAdminDAO.ListEnabledAdmins(tx, req.Keyword, isSuperAdmin && req.HasWeakPassword, req.Offset, req.Size)
|
if !isSuperAdmin && req.HasWeakPassword {
|
||||||
|
return &pb.ListEnabledAdminsResponse{Admins: nil}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
admins, err := models.SharedAdminDAO.ListEnabledAdmins(tx, req.Keyword, req.HasWeakPassword, req.Offset, req.Size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -472,13 +472,14 @@ func (this *DNSDomainService) findClusterDNSChanges(cluster *models.NodeCluster,
|
|||||||
var nodeKeys = []string{}
|
var nodeKeys = []string{}
|
||||||
var addingNodeRecordKeysMap = map[string]bool{} // clusterDnsName_type_ip_route
|
var addingNodeRecordKeysMap = map[string]bool{} // clusterDnsName_type_ip_route
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
ipAddresses, err := models.SharedNodeIPAddressDAO.FindNodeAccessAndUpIPAddresses(tx, int64(node.Id), nodeconfigs.NodeRoleNode)
|
shouldSkip, shouldOverwrite, ipAddressesStrings, err := models.SharedNodeDAO.CheckNodeIPAddresses(tx, node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, 0, 0, false, false, err
|
return nil, nil, nil, 0, 0, false, false, err
|
||||||
}
|
}
|
||||||
if len(ipAddresses) == 0 {
|
if shouldSkip {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
routeCodes, err := node.DNSRouteCodesForDomainId(int64(cluster.DnsDomainId))
|
routeCodes, err := node.DNSRouteCodesForDomainId(int64(cluster.DnsDomainId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, 0, 0, false, false, err
|
return nil, nil, nil, 0, 0, false, false, err
|
||||||
@@ -491,7 +492,16 @@ func (this *DNSDomainService) findClusterDNSChanges(cluster *models.NodeCluster,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, route := range routeCodes {
|
|
||||||
|
if !shouldOverwrite {
|
||||||
|
ipAddresses, err := models.SharedNodeIPAddressDAO.FindNodeAccessAndUpIPAddresses(tx, int64(node.Id), nodeconfigs.NodeRoleNode)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, 0, 0, false, false, err
|
||||||
|
}
|
||||||
|
if len(ipAddresses) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
for _, ipAddress := range ipAddresses {
|
for _, ipAddress := range ipAddresses {
|
||||||
// 检查专属节点
|
// 检查专属节点
|
||||||
if !ipAddress.IsValidInCluster(clusterId) {
|
if !ipAddress.IsValidInCluster(clusterId) {
|
||||||
@@ -505,6 +515,16 @@ func (this *DNSDomainService) findClusterDNSChanges(cluster *models.NodeCluster,
|
|||||||
if net.ParseIP(ip) == nil {
|
if net.ParseIP(ip) == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ipAddressesStrings = append(ipAddressesStrings, ip)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(ipAddressesStrings) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, route := range routeCodes {
|
||||||
|
for _, ip := range ipAddressesStrings {
|
||||||
var key = ip + "_" + route
|
var key = ip + "_" + route
|
||||||
nodeKeys = append(nodeKeys, key)
|
nodeKeys = append(nodeKeys, key)
|
||||||
record, ok := nodeRecordMapping[key]
|
record, ok := nodeRecordMapping[key]
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ func (this *DNSTaskService) FindAllDoingDNSTasks(ctx context.Context, req *pb.Fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch task.Type {
|
switch task.Type {
|
||||||
case dns.DNSTaskTypeClusterChange, dns.DNSTaskTypeClusterRemoveDomain:
|
case dns.DNSTaskTypeClusterChange, dns.DNSTaskTypeClusterNodesChange, dns.DNSTaskTypeClusterRemoveDomain:
|
||||||
clusterName, err := models.SharedNodeClusterDAO.FindNodeClusterName(tx, int64(task.ClusterId))
|
clusterName, err := models.SharedNodeClusterDAO.FindNodeClusterName(tx, int64(task.ClusterId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ func (this *HTTPCacheTaskService) CreateHTTPCacheTask(ctx context.Context, req *
|
|||||||
// 查询所在集群
|
// 查询所在集群
|
||||||
server, ok := domainMap[domain]
|
server, ok := domainMap[domain]
|
||||||
if !ok {
|
if !ok {
|
||||||
server, err = models.SharedServerDAO.FindEnabledServerWithDomain(tx, domain)
|
server, err = models.SharedServerDAO.FindEnabledServerWithDomain(tx, userId, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ package services
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/utils/regexputils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
)
|
)
|
||||||
@@ -35,7 +37,8 @@ func (this *HTTPCacheTaskKeyService) ValidateHTTPCacheTaskKeys(ctx context.Conte
|
|||||||
}
|
}
|
||||||
|
|
||||||
var pbFailResults = []*pb.ValidateHTTPCacheTaskKeysResponse_FailKey{}
|
var pbFailResults = []*pb.ValidateHTTPCacheTaskKeysResponse_FailKey{}
|
||||||
var domainMap = map[string]*models.Server{} // domain name => *Server
|
var foundDomainMap = map[string]*models.Server{} // domain name => *Server
|
||||||
|
var missingDomainMap = map[string]bool{} // domain name => true
|
||||||
for _, key := range req.Keys {
|
for _, key := range req.Keys {
|
||||||
if len(key) == 0 {
|
if len(key) == 0 {
|
||||||
pbFailResults = append(pbFailResults, &pb.ValidateHTTPCacheTaskKeysResponse_FailKey{
|
pbFailResults = append(pbFailResults, &pb.ValidateHTTPCacheTaskKeysResponse_FailKey{
|
||||||
@@ -55,21 +58,31 @@ func (this *HTTPCacheTaskKeyService) ValidateHTTPCacheTaskKeys(ctx context.Conte
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否不存在
|
||||||
|
if missingDomainMap[domain] {
|
||||||
|
pbFailResults = append(pbFailResults, &pb.ValidateHTTPCacheTaskKeysResponse_FailKey{
|
||||||
|
Key: key,
|
||||||
|
ReasonCode: "requireServer",
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// 查询所在集群
|
// 查询所在集群
|
||||||
server, ok := domainMap[domain]
|
server, ok := foundDomainMap[domain]
|
||||||
if !ok {
|
if !ok {
|
||||||
server, err = models.SharedServerDAO.FindEnabledServerWithDomain(tx, domain)
|
server, err = models.SharedServerDAO.FindEnabledServerWithDomain(tx, userId, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if server == nil {
|
if server == nil {
|
||||||
|
missingDomainMap[domain] = true
|
||||||
pbFailResults = append(pbFailResults, &pb.ValidateHTTPCacheTaskKeysResponse_FailKey{
|
pbFailResults = append(pbFailResults, &pb.ValidateHTTPCacheTaskKeysResponse_FailKey{
|
||||||
Key: key,
|
Key: key,
|
||||||
ReasonCode: "requireServer",
|
ReasonCode: "requireServer",
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
domainMap[domain] = server
|
foundDomainMap[domain] = server
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查用户
|
// 检查用户
|
||||||
@@ -171,3 +184,22 @@ func (this *HTTPCacheTaskKeyService) UpdateHTTPCacheTaskKeysStatus(ctx context.C
|
|||||||
|
|
||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountHTTPCacheTaskKeysWithDay 计算当天已经清理的Key数量
|
||||||
|
func (this *HTTPCacheTaskKeyService) CountHTTPCacheTaskKeysWithDay(ctx context.Context, req *pb.CountHTTPCacheTaskKeysWithDayRequest) (*pb.RPCCountResponse, error) {
|
||||||
|
userId, err := this.ValidateUserNode(ctx, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !regexputils.YYYYMMDD.MatchString(req.Day) {
|
||||||
|
return nil, errors.New("invalid format 'day'")
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
countKeys, err := models.SharedHTTPCacheTaskKeyDAO.CountUserTasksInDay(tx, userId, req.Day, req.KeyType)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return this.SuccessCount(countKeys)
|
||||||
|
}
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyCORS(ctx context.Cont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var corsConfig = &shared.HTTPCORSHeaderConfig{}
|
var corsConfig = shared.NewHTTPCORSHeaderConfig()
|
||||||
err = json.Unmarshal(req.CorsJSON, corsConfig)
|
err = json.Unmarshal(req.CorsJSON, corsConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -219,3 +219,28 @@ func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyCORS(ctx context.Cont
|
|||||||
|
|
||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateHTTPHeaderPolicyNonStandardHeaders 修改非标的Headers
|
||||||
|
func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyNonStandardHeaders(ctx context.Context, req *pb.UpdateHTTPHeaderPolicyNonStandardHeadersRequest) (*pb.RPCSuccess, error) {
|
||||||
|
_, userId, err := this.ValidateAdminAndUser(ctx, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
|
||||||
|
// 检查权限
|
||||||
|
if userId > 0 {
|
||||||
|
err = models.SharedHTTPHeaderPolicyDAO.CheckUserHeaderPolicy(tx, userId, req.HttpHeaderPolicyId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = models.SharedHTTPHeaderPolicyDAO.UpdateNonStandardHeaders(tx, req.HttpHeaderPolicyId, req.HeaderNames)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.Success()
|
||||||
|
}
|
||||||
|
|||||||
@@ -318,7 +318,22 @@ func (this *HTTPWebService) UpdateHTTPWebPages(ctx context.Context, req *pb.Upda
|
|||||||
|
|
||||||
var tx = this.NullTx()
|
var tx = this.NullTx()
|
||||||
|
|
||||||
err = models.SharedHTTPWebDAO.UpdateWebPages(tx, req.HttpWebId, req.PagesJSON)
|
// 检查配置
|
||||||
|
var pages = []*serverconfigs.HTTPPageConfig{}
|
||||||
|
err = json.Unmarshal(req.PagesJSON, &pages)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("decode 'pages' failed: " + err.Error())
|
||||||
|
}
|
||||||
|
var newPages = []*serverconfigs.HTTPPageConfig{}
|
||||||
|
for _, page := range pages {
|
||||||
|
newPages = append(newPages, &serverconfigs.HTTPPageConfig{Id: page.Id})
|
||||||
|
}
|
||||||
|
newPagesJSON, err := json.Marshal(newPages)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = models.SharedHTTPWebDAO.UpdateWebPages(tx, req.HttpWebId, newPagesJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -384,6 +384,9 @@ func (this *NodeService) ListEnabledNodesMatch(ctx context.Context, req *pb.List
|
|||||||
NodeRegion: pbRegion,
|
NodeRegion: pbRegion,
|
||||||
DnsRoutes: pbRoutes,
|
DnsRoutes: pbRoutes,
|
||||||
Level: int32(node.Level),
|
Level: int32(node.Level),
|
||||||
|
OfflineDay: node.OfflineDay,
|
||||||
|
IsBackupForCluster: node.IsBackupForCluster,
|
||||||
|
IsBackupForGroup: node.IsBackupForGroup,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,6 +686,9 @@ func (this *NodeService) FindEnabledNode(ctx context.Context, req *pb.FindEnable
|
|||||||
DnsRoutes: pbRoutes,
|
DnsRoutes: pbRoutes,
|
||||||
EnableIPLists: node.EnableIPLists,
|
EnableIPLists: node.EnableIPLists,
|
||||||
ApiNodeAddrsJSON: node.ApiNodeAddrs,
|
ApiNodeAddrsJSON: node.ApiNodeAddrs,
|
||||||
|
OfflineDay: node.OfflineDay,
|
||||||
|
IsBackupForCluster: node.IsBackupForCluster,
|
||||||
|
IsBackupForGroup: node.IsBackupForGroup,
|
||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1397,12 +1403,15 @@ func (this *NodeService) FindAllEnabledNodesDNSWithNodeClusterId(ctx context.Con
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result = append(result, &pb.NodeDNSInfo{
|
result = append(result, &pb.NodeDNSInfo{
|
||||||
Id: int64(node.Id),
|
Id: int64(node.Id),
|
||||||
Name: node.Name,
|
Name: node.Name,
|
||||||
IpAddr: ip,
|
IpAddr: ip,
|
||||||
NodeIPAddressId: int64(ipAddress.Id),
|
NodeIPAddressId: int64(ipAddress.Id),
|
||||||
Routes: pbRoutes,
|
Routes: pbRoutes,
|
||||||
NodeClusterId: req.NodeClusterId,
|
NodeClusterId: req.NodeClusterId,
|
||||||
|
IsBackupForCluster: node.IsBackupForCluster,
|
||||||
|
IsBackupForGroup: node.IsBackupForGroup,
|
||||||
|
IsOffline: node.CheckIsOffline(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1497,6 +1506,9 @@ func (this *NodeService) FindEnabledNodeDNS(ctx context.Context, req *pb.FindEna
|
|||||||
NodeClusterDNSName: clusterDNS.DnsName,
|
NodeClusterDNSName: clusterDNS.DnsName,
|
||||||
DnsDomainId: dnsDomainId,
|
DnsDomainId: dnsDomainId,
|
||||||
DnsDomainName: dnsDomainName,
|
DnsDomainName: dnsDomainName,
|
||||||
|
IsBackupForCluster: node.IsBackupForCluster,
|
||||||
|
IsBackupForGroup: node.IsBackupForGroup,
|
||||||
|
IsOffline: node.CheckIsOffline(),
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -2097,6 +2109,11 @@ func (this *NodeService) FindEnabledNodeConfigInfo(ctx context.Context, req *pb.
|
|||||||
// ddos protection
|
// ddos protection
|
||||||
result.HasDDoSProtection = node.HasDDoSProtection()
|
result.HasDDoSProtection = node.HasDDoSProtection()
|
||||||
|
|
||||||
|
// schedule
|
||||||
|
result.HasScheduleSettings = node.HasScheduleSettings()
|
||||||
|
|
||||||
|
// pages
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2240,39 +2257,3 @@ func (this *NodeService) UpdateNodeAPIConfig(ctx context.Context, req *pb.Update
|
|||||||
|
|
||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindNodeUAMPolicies 查找节点的UAM策略
|
|
||||||
func (this *NodeService) FindNodeUAMPolicies(ctx context.Context, req *pb.FindNodeUAMPoliciesRequest) (*pb.FindNodeUAMPoliciesResponse, error) {
|
|
||||||
nodeId, err := this.ValidateNode(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var tx = this.NullTx()
|
|
||||||
clusterIds, err := models.SharedNodeDAO.FindEnabledAndOnNodeClusterIds(tx, nodeId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var pbPolicies = []*pb.FindNodeUAMPoliciesResponse_UAMPolicy{}
|
|
||||||
for _, clusterId := range clusterIds {
|
|
||||||
policy, err := models.SharedNodeClusterDAO.FindClusterUAMPolicy(tx, clusterId, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if policy == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
policyJSON, err := json.Marshal(policy)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
pbPolicies = append(pbPolicies, &pb.FindNodeUAMPoliciesResponse_UAMPolicy{
|
|
||||||
NodeClusterId: clusterId,
|
|
||||||
UamPolicyJSON: policyJSON,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return &pb.FindNodeUAMPoliciesResponse{
|
|
||||||
UamPolicies: pbPolicies,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package services
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns/dnsutils"
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns/dnsutils"
|
||||||
@@ -1140,6 +1141,18 @@ func (this *NodeClusterService) FindEnabledNodeClusterConfigInfo(ctx context.Con
|
|||||||
result.UamIsOn = nodeconfigs.DefaultUAMPolicy.IsOn
|
result.UamIsOn = nodeconfigs.DefaultUAMPolicy.IsOn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTTP CC
|
||||||
|
if models.IsNotNull(cluster.Cc) {
|
||||||
|
var httpCCPolicy = nodeconfigs.NewHTTPCCPolicy()
|
||||||
|
err = json.Unmarshal(cluster.Cc, httpCCPolicy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result.HttpCCIsOn = httpCCPolicy.IsOn
|
||||||
|
} else {
|
||||||
|
result.HttpCCIsOn = nodeconfigs.NewHTTPCCPolicy().IsOn
|
||||||
|
}
|
||||||
|
|
||||||
// system service
|
// system service
|
||||||
if models.IsNotNull(cluster.SystemServices) {
|
if models.IsNotNull(cluster.SystemServices) {
|
||||||
var servicesMap = map[string]maps.Map{}
|
var servicesMap = map[string]maps.Map{}
|
||||||
@@ -1157,6 +1170,16 @@ func (this *NodeClusterService) FindEnabledNodeClusterConfigInfo(ctx context.Con
|
|||||||
// ddos
|
// ddos
|
||||||
result.HasDDoSProtection = cluster.HasDDoSProtection()
|
result.HasDDoSProtection = cluster.HasDDoSProtection()
|
||||||
|
|
||||||
|
// HTTP Pages
|
||||||
|
if models.IsNotNull(cluster.HttpPages) {
|
||||||
|
var pagesPolicy = nodeconfigs.NewHTTPPagesPolicy()
|
||||||
|
err = json.Unmarshal(cluster.HttpPages, pagesPolicy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result.HasHTTPPagesPolicy = pagesPolicy.IsOn && len(pagesPolicy.Pages) > 0
|
||||||
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1225,6 +1248,10 @@ func (this *NodeClusterService) UpdateNodeClusterWebPPolicy(ctx context.Context,
|
|||||||
|
|
||||||
// FindEnabledNodeClusterUAMPolicy 读取集群UAM策略
|
// FindEnabledNodeClusterUAMPolicy 读取集群UAM策略
|
||||||
func (this *NodeClusterService) FindEnabledNodeClusterUAMPolicy(ctx context.Context, req *pb.FindEnabledNodeClusterUAMPolicyRequest) (*pb.FindEnabledNodeClusterUAMPolicyResponse, error) {
|
func (this *NodeClusterService) FindEnabledNodeClusterUAMPolicy(ctx context.Context, req *pb.FindEnabledNodeClusterUAMPolicyRequest) (*pb.FindEnabledNodeClusterUAMPolicyResponse, error) {
|
||||||
|
if !teaconst.IsPlus {
|
||||||
|
return nil, this.NotImplementedYet()
|
||||||
|
}
|
||||||
|
|
||||||
_, _, err := this.ValidateAdminAndUser(ctx, false)
|
_, _, err := this.ValidateAdminAndUser(ctx, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1246,6 +1273,10 @@ func (this *NodeClusterService) FindEnabledNodeClusterUAMPolicy(ctx context.Cont
|
|||||||
|
|
||||||
// UpdateNodeClusterUAMPolicy 设置集群的UAM策略
|
// UpdateNodeClusterUAMPolicy 设置集群的UAM策略
|
||||||
func (this *NodeClusterService) UpdateNodeClusterUAMPolicy(ctx context.Context, req *pb.UpdateNodeClusterUAMPolicyRequest) (*pb.RPCSuccess, error) {
|
func (this *NodeClusterService) UpdateNodeClusterUAMPolicy(ctx context.Context, req *pb.UpdateNodeClusterUAMPolicyRequest) (*pb.RPCSuccess, error) {
|
||||||
|
if !teaconst.IsPlus {
|
||||||
|
return nil, this.NotImplementedYet()
|
||||||
|
}
|
||||||
|
|
||||||
_, err := this.ValidateAdmin(ctx)
|
_, err := this.ValidateAdmin(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1270,6 +1301,62 @@ func (this *NodeClusterService) UpdateNodeClusterUAMPolicy(ctx context.Context,
|
|||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// FindEnabledNodeClusterHTTPCCPolicy 读取集群HTTP CC策略
|
||||||
|
func (this *NodeClusterService) FindEnabledNodeClusterHTTPCCPolicy(ctx context.Context, req *pb.FindEnabledNodeClusterHTTPCCPolicyRequest) (*pb.FindEnabledNodeClusterHTTPCCPolicyResponse, error) {
|
||||||
|
if !teaconst.IsPlus {
|
||||||
|
return nil, this.NotImplementedYet()
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, err := this.ValidateAdminAndUser(ctx, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
httpCCPolicy, err := models.SharedNodeClusterDAO.FindClusterHTTPCCPolicy(tx, req.NodeClusterId, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
httpCCPolicyJSON, err := json.Marshal(httpCCPolicy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &pb.FindEnabledNodeClusterHTTPCCPolicyResponse{
|
||||||
|
HttpCCPolicyJSON: httpCCPolicyJSON,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNodeClusterHTTPCCPolicy 设置集群的HTTP CC策略
|
||||||
|
func (this *NodeClusterService) UpdateNodeClusterHTTPCCPolicy(ctx context.Context, req *pb.UpdateNodeClusterHTTPCCPolicyRequest) (*pb.RPCSuccess, error) {
|
||||||
|
if !teaconst.IsPlus {
|
||||||
|
return nil, this.NotImplementedYet()
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := this.ValidateAdmin(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var httpCCPolicy = nodeconfigs.NewHTTPCCPolicy()
|
||||||
|
err = json.Unmarshal(req.HttpCCPolicyJSON, httpCCPolicy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = httpCCPolicy.Init()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("validate http cc policy failed: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
err = models.SharedNodeClusterDAO.UpdateClusterHTTPCCPolicy(tx, req.NodeClusterId, httpCCPolicy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return this.Success()
|
||||||
|
}
|
||||||
|
|
||||||
// FindNodeClusterDDoSProtection 获取集群的DDoS设置
|
// FindNodeClusterDDoSProtection 获取集群的DDoS设置
|
||||||
func (this *NodeClusterService) FindNodeClusterDDoSProtection(ctx context.Context, req *pb.FindNodeClusterDDoSProtectionRequest) (*pb.FindNodeClusterDDoSProtectionResponse, error) {
|
func (this *NodeClusterService) FindNodeClusterDDoSProtection(ctx context.Context, req *pb.FindNodeClusterDDoSProtectionRequest) (*pb.FindNodeClusterDDoSProtectionResponse, error) {
|
||||||
_, err := this.ValidateAdmin(ctx)
|
_, err := this.ValidateAdmin(ctx)
|
||||||
@@ -1367,3 +1454,51 @@ func (this *NodeClusterService) UpdateNodeClusterGlobalServerConfig(ctx context.
|
|||||||
|
|
||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindNodeClusterHTTPPagesPolicy 获取集群的自定义页面设置
|
||||||
|
func (this *NodeClusterService) FindNodeClusterHTTPPagesPolicy(ctx context.Context, req *pb.FindNodeClusterHTTPPagesPolicyRequest) (*pb.FindNodeClusterHTTPPagesPolicyResponse, error) {
|
||||||
|
_, err := this.ValidateAdmin(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
httpPagesPolicy, err := models.SharedNodeClusterDAO.FindClusterHTTPPagesPolicy(tx, req.NodeClusterId, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
httpPagesPolicyJSON, err := json.Marshal(httpPagesPolicy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &pb.FindNodeClusterHTTPPagesPolicyResponse{
|
||||||
|
HttpPagesPolicyJSON: httpPagesPolicyJSON,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNodeClusterHTTPPagesPolicy 修改集群的自定义页面设置
|
||||||
|
func (this *NodeClusterService) UpdateNodeClusterHTTPPagesPolicy(ctx context.Context, req *pb.UpdateNodeClusterHTTPPagesPolicyRequest) (*pb.RPCSuccess, error) {
|
||||||
|
_, err := this.ValidateAdmin(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
var policy = nodeconfigs.NewHTTPPagesPolicy()
|
||||||
|
err = json.Unmarshal(req.HttpPagesPolicyJSON, policy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = policy.Init()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("validate policy failed: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
err = models.SharedNodeClusterDAO.UpdateClusterHTTPPagesPolicy(tx, req.NodeClusterId, policy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.Success()
|
||||||
|
}
|
||||||
|
|||||||
45
internal/rpc/services/service_node_ext.go
Normal file
45
internal/rpc/services/service_node_ext.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
//go:build !plus
|
||||||
|
|
||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (this *NodeService) FindNodeUAMPolicies(ctx context.Context, req *pb.FindNodeUAMPoliciesRequest) (*pb.FindNodeUAMPoliciesResponse, error) {
|
||||||
|
return nil, this.NotImplementedYet()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *NodeService) FindNodeHTTPCCPolicies(ctx context.Context, req *pb.FindNodeHTTPCCPoliciesRequest) (*pb.FindNodeHTTPCCPoliciesResponse, error) {
|
||||||
|
return nil, this.NotImplementedYet()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *NodeService) FindNodeHTTPPagesPolicies(ctx context.Context, req *pb.FindNodeHTTPPagesPoliciesRequest) (*pb.FindNodeHTTPPagesPoliciesResponse, error) {
|
||||||
|
return nil, this.NotImplementedYet()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *NodeService) FindNodeScheduleInfo(ctx context.Context, req *pb.FindNodeScheduleInfoRequest) (*pb.FindNodeScheduleInfoResponse, error) {
|
||||||
|
return nil, this.NotImplementedYet()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *NodeService) UpdateNodeScheduleInfo(ctx context.Context, req *pb.UpdateNodeScheduleInfoRequest) (*pb.RPCSuccess, error) {
|
||||||
|
return nil, this.NotImplementedYet()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *NodeService) ResetNodeActionStatus(ctx context.Context, req *pb.ResetNodeActionStatusRequest) (*pb.RPCSuccess, error) {
|
||||||
|
return nil, this.NotImplementedYet()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *NodeService) FindAllNodeScheduleInfoWithNodeClusterId(ctx context.Context, req *pb.FindAllNodeScheduleInfoWithNodeClusterIdRequest) (*pb.FindAllNodeScheduleInfoWithNodeClusterIdResponse, error) {
|
||||||
|
return nil, this.NotImplementedYet()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *NodeService) CopyNodeActionsToNodeGroup(ctx context.Context, req *pb.CopyNodeActionsToNodeGroupRequest) (*pb.RPCSuccess, error) {
|
||||||
|
return nil, this.NotImplementedYet()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *NodeService) CopyNodeActionsToNodeCluster(ctx context.Context, req *pb.CopyNodeActionsToNodeClusterRequest) (*pb.RPCSuccess, error) {
|
||||||
|
return nil, this.NotImplementedYet()
|
||||||
|
}
|
||||||
@@ -2010,7 +2010,7 @@ func (this *ServerService) PurgeServerCache(ctx context.Context, req *pb.PurgeSe
|
|||||||
// 查询所在集群
|
// 查询所在集群
|
||||||
server, ok := domainMap[domain]
|
server, ok := domainMap[domain]
|
||||||
if !ok {
|
if !ok {
|
||||||
server, err = models.SharedServerDAO.FindEnabledServerWithDomain(tx, domain)
|
server, err = models.SharedServerDAO.FindEnabledServerWithDomain(tx, 0, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func (this *ServerDailyStatService) UploadServerDailyStats(ctx context.Context,
|
|||||||
|
|
||||||
// 节点流量
|
// 节点流量
|
||||||
if nodeId > 0 {
|
if nodeId > 0 {
|
||||||
err = stats.SharedNodeTrafficDailyStatDAO.IncreaseDailyStat(tx, clusterId, role, nodeId, timeutil.FormatTime("Ymd", stat.CreatedAt), stat.Bytes, stat.CachedBytes, stat.CountRequests, stat.CountCachedRequests, stat.CountAttackRequests, stat.AttackBytes)
|
err = models.SharedNodeTrafficDailyStatDAO.IncreaseDailyStat(tx, clusterId, role, nodeId, timeutil.FormatTime("Ymd", stat.CreatedAt), stat.Bytes, stat.CachedBytes, stat.CountRequests, stat.CountCachedRequests, stat.CountAttackRequests, stat.AttackBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -325,7 +325,7 @@ func (this *ServerStatBoardService) ComposeServerStatNodeBoard(ctx context.Conte
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 当月总流量
|
// 当月总流量
|
||||||
monthlyTrafficStat, err := stats.SharedNodeTrafficDailyStatDAO.SumDailyStat(tx, nodeconfigs.NodeRoleNode, req.NodeId, timeutil.Format("Ym01"), timeutil.Format("Ym31"))
|
monthlyTrafficStat, err := models.SharedNodeTrafficDailyStatDAO.SumDailyStat(tx, nodeconfigs.NodeRoleNode, req.NodeId, timeutil.Format("Ym01"), timeutil.Format("Ym31"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -335,7 +335,7 @@ func (this *ServerStatBoardService) ComposeServerStatNodeBoard(ctx context.Conte
|
|||||||
|
|
||||||
// 按日流量统计
|
// 按日流量统计
|
||||||
var dayFrom = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -14))
|
var dayFrom = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -14))
|
||||||
dailyTrafficStats, err := stats.SharedNodeTrafficDailyStatDAO.FindDailyStats(tx, "node", req.NodeId, dayFrom, timeutil.Format("Ymd"))
|
dailyTrafficStats, err := models.SharedNodeTrafficDailyStatDAO.FindDailyStats(tx, "node", req.NodeId, dayFrom, timeutil.Format("Ymd"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61579,7 +61579,7 @@
|
|||||||
"name": "edgeHTTPHeaderPolicies",
|
"name": "edgeHTTPHeaderPolicies",
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"charset": "utf8mb4_general_ci",
|
"charset": "utf8mb4_general_ci",
|
||||||
"definition": "CREATE TABLE `edgeHTTPHeaderPolicies` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `isOn` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '是否启用',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `addHeaders` json DEFAULT NULL COMMENT '添加的Header',\n `addTrailers` json DEFAULT NULL COMMENT '添加的Trailers',\n `setHeaders` json DEFAULT NULL COMMENT '设置Header',\n `replaceHeaders` json DEFAULT NULL COMMENT '替换Header内容',\n `expires` json DEFAULT NULL COMMENT 'Expires单独设置',\n `deleteHeaders` json DEFAULT NULL COMMENT '删除的Headers',\n `cors` json DEFAULT NULL COMMENT 'CORS配置',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Header定义'",
|
"definition": "CREATE TABLE `edgeHTTPHeaderPolicies` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `isOn` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '是否启用',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `addHeaders` json DEFAULT NULL COMMENT '添加的Header',\n `addTrailers` json DEFAULT NULL COMMENT '添加的Trailers',\n `setHeaders` json DEFAULT NULL COMMENT '设置Header',\n `replaceHeaders` json DEFAULT NULL COMMENT '替换Header内容',\n `expires` json DEFAULT NULL COMMENT 'Expires单独设置',\n `deleteHeaders` json DEFAULT NULL COMMENT '删除的Headers',\n `nonStandardHeaders` json DEFAULT NULL COMMENT '非标Headers',\n `cors` json DEFAULT NULL COMMENT 'CORS配置',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Header定义'",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"name": "id",
|
"name": "id",
|
||||||
@@ -61629,6 +61629,10 @@
|
|||||||
"name": "deleteHeaders",
|
"name": "deleteHeaders",
|
||||||
"definition": "json COMMENT '删除的Headers'"
|
"definition": "json COMMENT '删除的Headers'"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "nonStandardHeaders",
|
||||||
|
"definition": "json COMMENT '非标Headers'"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "cors",
|
"name": "cors",
|
||||||
"definition": "json COMMENT 'CORS配置'"
|
"definition": "json COMMENT 'CORS配置'"
|
||||||
@@ -67267,7 +67271,7 @@
|
|||||||
"name": "edgeNSDomains",
|
"name": "edgeNSDomains",
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"charset": "utf8mb4_general_ci",
|
"charset": "utf8mb4_general_ci",
|
||||||
"definition": "CREATE TABLE `edgeNSDomains` (\n `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `clusterId` int(11) unsigned DEFAULT '0' COMMENT '集群ID',\n `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `name` varchar(255) DEFAULT NULL COMMENT '域名',\n `groupIds` json DEFAULT NULL COMMENT '分组ID',\n `tsig` json DEFAULT NULL COMMENT 'TSIG配置',\n `verifyTXT` varchar(64) DEFAULT NULL COMMENT '验证用的TXT',\n `verifyExpiresAt` bigint(11) unsigned DEFAULT '0' COMMENT '验证TXT过期时间',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `version` bigint(20) unsigned DEFAULT '0' COMMENT '版本号',\n `status` varchar(64) DEFAULT 'none' COMMENT '状态:none|verified',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n PRIMARY KEY (`id`),\n KEY `userId` (`userId`),\n KEY `name` (`name`),\n KEY `version` (`version`) USING BTREE,\n KEY `status` (`status`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='DNS域名'",
|
"definition": "CREATE TABLE `edgeNSDomains` (\n `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `clusterId` int(11) unsigned DEFAULT '0' COMMENT '集群ID',\n `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `name` varchar(255) DEFAULT NULL COMMENT '域名',\n `groupIds` json DEFAULT NULL COMMENT '分组ID',\n `tsig` json DEFAULT NULL COMMENT 'TSIG配置',\n `verifyTXT` varchar(64) DEFAULT NULL COMMENT '验证用的TXT',\n `verifyExpiresAt` bigint(11) unsigned DEFAULT '0' COMMENT '验证TXT过期时间',\n `recordsHealthCheck` json DEFAULT NULL COMMENT '记录健康检查设置',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `version` bigint(20) unsigned DEFAULT '0' COMMENT '版本号',\n `status` varchar(64) DEFAULT 'none' COMMENT '状态:none|verified',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n PRIMARY KEY (`id`),\n KEY `userId` (`userId`),\n KEY `name` (`name`),\n KEY `version` (`version`) USING BTREE,\n KEY `status` (`status`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='DNS域名'",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"name": "id",
|
"name": "id",
|
||||||
@@ -67305,6 +67309,10 @@
|
|||||||
"name": "verifyExpiresAt",
|
"name": "verifyExpiresAt",
|
||||||
"definition": "bigint(11) unsigned DEFAULT '0' COMMENT '验证TXT过期时间'"
|
"definition": "bigint(11) unsigned DEFAULT '0' COMMENT '验证TXT过期时间'"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "recordsHealthCheck",
|
||||||
|
"definition": "json COMMENT '记录健康检查设置'"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "createdAt",
|
"name": "createdAt",
|
||||||
"definition": "bigint(11) unsigned DEFAULT '0' COMMENT '创建时间'"
|
"definition": "bigint(11) unsigned DEFAULT '0' COMMENT '创建时间'"
|
||||||
@@ -67653,7 +67661,7 @@
|
|||||||
"name": "edgeNSRecords",
|
"name": "edgeNSRecords",
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"charset": "utf8mb4_general_ci",
|
"charset": "utf8mb4_general_ci",
|
||||||
"definition": "CREATE TABLE `edgeNSRecords` (\n `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `domainId` int(11) unsigned DEFAULT '0' COMMENT '域名ID',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `description` varchar(512) DEFAULT NULL COMMENT '备注',\n `name` varchar(255) DEFAULT NULL COMMENT '记录名',\n `type` varchar(32) DEFAULT NULL COMMENT '类型',\n `value` varchar(4096) DEFAULT NULL COMMENT '值',\n `mxPriority` int(11) unsigned DEFAULT '0' COMMENT 'MX优先级',\n `srvPriority` int(11) unsigned DEFAULT '0' COMMENT 'SRV优先级',\n `srvWeight` int(11) unsigned DEFAULT '0' COMMENT 'SRV权重',\n `srvPort` int(11) unsigned DEFAULT '0' COMMENT 'SRV端口',\n `caaFlag` tinyint(1) unsigned DEFAULT '0' COMMENT 'CAA Flag',\n `caaTag` varchar(32) DEFAULT NULL COMMENT 'CAA TAG',\n `ttl` int(11) unsigned DEFAULT '0' COMMENT 'TTL(秒)',\n `weight` int(11) unsigned DEFAULT '0' COMMENT '权重',\n `routeIds` json DEFAULT NULL COMMENT '线路',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `version` bigint(20) unsigned DEFAULT '0' COMMENT '版本号',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n PRIMARY KEY (`id`),\n KEY `domainId` (`domainId`),\n KEY `version` (`version`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='DNS记录'",
|
"definition": "CREATE TABLE `edgeNSRecords` (\n `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `domainId` int(11) unsigned DEFAULT '0' COMMENT '域名ID',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `description` varchar(512) DEFAULT NULL COMMENT '备注',\n `name` varchar(255) DEFAULT NULL COMMENT '记录名',\n `type` varchar(32) DEFAULT NULL COMMENT '类型',\n `value` varchar(4096) DEFAULT NULL COMMENT '值',\n `mxPriority` int(11) unsigned DEFAULT '0' COMMENT 'MX优先级',\n `srvPriority` int(11) unsigned DEFAULT '0' COMMENT 'SRV优先级',\n `srvWeight` int(11) unsigned DEFAULT '0' COMMENT 'SRV权重',\n `srvPort` int(11) unsigned DEFAULT '0' COMMENT 'SRV端口',\n `caaFlag` tinyint(1) unsigned DEFAULT '0' COMMENT 'CAA Flag',\n `caaTag` varchar(32) DEFAULT NULL COMMENT 'CAA TAG',\n `ttl` int(11) unsigned DEFAULT '0' COMMENT 'TTL(秒)',\n `weight` int(11) unsigned DEFAULT '0' COMMENT '权重',\n `routeIds` json DEFAULT NULL COMMENT '线路',\n `healthCheck` json DEFAULT NULL COMMENT '健康检查配置',\n `countUp` int(11) unsigned DEFAULT '0' COMMENT '连续上线次数',\n `countDown` int(11) unsigned DEFAULT '0' COMMENT '连续离线次数',\n `isUp` tinyint(1) unsigned DEFAULT '1' COMMENT '是否在线',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `version` bigint(20) unsigned DEFAULT '0' COMMENT '版本号',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n PRIMARY KEY (`id`),\n KEY `domainId` (`domainId`),\n KEY `version` (`version`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='DNS记录'",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"name": "id",
|
"name": "id",
|
||||||
@@ -67719,6 +67727,22 @@
|
|||||||
"name": "routeIds",
|
"name": "routeIds",
|
||||||
"definition": "json COMMENT '线路'"
|
"definition": "json COMMENT '线路'"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "healthCheck",
|
||||||
|
"definition": "json COMMENT '健康检查配置'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "countUp",
|
||||||
|
"definition": "int(11) unsigned DEFAULT '0' COMMENT '连续上线次数'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "countDown",
|
||||||
|
"definition": "int(11) unsigned DEFAULT '0' COMMENT '连续离线次数'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "isUp",
|
||||||
|
"definition": "tinyint(1) unsigned DEFAULT '1' COMMENT '是否在线'"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "createdAt",
|
"name": "createdAt",
|
||||||
"definition": "bigint(11) unsigned DEFAULT '0' COMMENT '创建时间'"
|
"definition": "bigint(11) unsigned DEFAULT '0' COMMENT '创建时间'"
|
||||||
@@ -67992,6 +68016,61 @@
|
|||||||
],
|
],
|
||||||
"records": []
|
"records": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "edgeNodeActions",
|
||||||
|
"engine": "InnoDB",
|
||||||
|
"charset": "utf8mb4_general_ci",
|
||||||
|
"definition": "CREATE TABLE `edgeNodeActions` (\n `id` bigint(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `nodeId` bigint(11) unsigned DEFAULT '0' COMMENT '节点ID',\n `role` varchar(16) DEFAULT NULL COMMENT '角色',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `conds` json DEFAULT NULL COMMENT '条件',\n `action` json DEFAULT NULL COMMENT '动作',\n `duration` json DEFAULT NULL COMMENT '持续时间',\n `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n PRIMARY KEY (`id`),\n KEY `nodeId` (`nodeId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点智能调度设置'",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"definition": "bigint(11) unsigned auto_increment COMMENT 'ID'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nodeId",
|
||||||
|
"definition": "bigint(11) unsigned DEFAULT '0' COMMENT '节点ID'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "role",
|
||||||
|
"definition": "varchar(16) COMMENT '角色'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "isOn",
|
||||||
|
"definition": "tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "conds",
|
||||||
|
"definition": "json COMMENT '条件'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "action",
|
||||||
|
"definition": "json COMMENT '动作'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "duration",
|
||||||
|
"definition": "json COMMENT '持续时间'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "order",
|
||||||
|
"definition": "int(11) unsigned DEFAULT '0' COMMENT '排序'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "state",
|
||||||
|
"definition": "tinyint(1) unsigned DEFAULT '1' COMMENT '状态'"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"indexes": [
|
||||||
|
{
|
||||||
|
"name": "PRIMARY",
|
||||||
|
"definition": "UNIQUE KEY `PRIMARY` (`id`) USING BTREE"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nodeId",
|
||||||
|
"definition": "KEY `nodeId` (`nodeId`) USING BTREE"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"records": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "edgeNodeClusterFirewallActions",
|
"name": "edgeNodeClusterFirewallActions",
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
@@ -68145,7 +68224,7 @@
|
|||||||
"name": "edgeNodeClusters",
|
"name": "edgeNodeClusters",
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"charset": "utf8mb4_general_ci",
|
"charset": "utf8mb4_general_ci",
|
||||||
"definition": "CREATE TABLE `edgeNodeClusters` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `name` varchar(255) DEFAULT NULL COMMENT '名称',\n `useAllAPINodes` tinyint(1) unsigned DEFAULT '1' COMMENT '是否使用所有API节点',\n `apiNodes` json DEFAULT NULL COMMENT '使用的API节点',\n `installDir` varchar(512) DEFAULT NULL COMMENT '安装目录',\n `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `grantId` int(11) unsigned DEFAULT '0' COMMENT '默认认证方式',\n `sshParams` json DEFAULT NULL COMMENT 'SSH默认参数',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n `autoRegister` tinyint(1) unsigned DEFAULT '1' COMMENT '是否开启自动注册',\n `uniqueId` varchar(32) DEFAULT NULL COMMENT '唯一ID',\n `secret` varchar(32) DEFAULT NULL COMMENT '密钥',\n `healthCheck` json DEFAULT NULL COMMENT '健康检查',\n `dnsName` varchar(255) DEFAULT NULL COMMENT 'DNS名称',\n `dnsDomainId` int(11) unsigned DEFAULT '0' COMMENT '域名ID',\n `dns` json DEFAULT NULL COMMENT 'DNS配置',\n `toa` json DEFAULT NULL COMMENT 'TOA配置',\n `cachePolicyId` int(11) unsigned DEFAULT '0' COMMENT '缓存策略ID',\n `httpFirewallPolicyId` int(11) unsigned DEFAULT '0' COMMENT 'WAF策略ID',\n `accessLog` json DEFAULT NULL COMMENT '访问日志设置',\n `systemServices` json DEFAULT NULL COMMENT '系统服务设置',\n `timeZone` varchar(64) DEFAULT NULL COMMENT '时区',\n `nodeMaxThreads` int(11) unsigned DEFAULT '0' COMMENT '节点最大线程数',\n `ddosProtection` json DEFAULT NULL COMMENT 'DDoS防护设置',\n `autoOpenPorts` tinyint(1) unsigned DEFAULT '1' COMMENT '是否自动尝试开放端口',\n `isPinned` tinyint(1) unsigned DEFAULT '0' COMMENT '是否置顶',\n `webp` json DEFAULT NULL COMMENT 'WebP设置',\n `uam` json DEFAULT NULL COMMENT 'UAM设置',\n `clock` json DEFAULT NULL COMMENT '时钟配置',\n `globalServerConfig` json DEFAULT NULL COMMENT '全局服务配置',\n `autoRemoteStart` tinyint(1) unsigned DEFAULT '1' COMMENT '自动远程启动',\n `autoInstallNftables` tinyint(1) unsigned DEFAULT '0' COMMENT '自动安装nftables',\n `isAD` tinyint(1) unsigned DEFAULT '0' COMMENT '是否为高防集群',\n PRIMARY KEY (`id`),\n KEY `uniqueId` (`uniqueId`),\n KEY `grantId` (`grantId`),\n KEY `dnsDomainId` (`dnsDomainId`),\n KEY `cachePolicyId` (`cachePolicyId`),\n KEY `httpFirewallPolicyId` (`httpFirewallPolicyId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点集群'",
|
"definition": "CREATE TABLE `edgeNodeClusters` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `name` varchar(255) DEFAULT NULL COMMENT '名称',\n `useAllAPINodes` tinyint(1) unsigned DEFAULT '1' COMMENT '是否使用所有API节点',\n `apiNodes` json DEFAULT NULL COMMENT '使用的API节点',\n `installDir` varchar(512) DEFAULT NULL COMMENT '安装目录',\n `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `grantId` int(11) unsigned DEFAULT '0' COMMENT '默认认证方式',\n `sshParams` json DEFAULT NULL COMMENT 'SSH默认参数',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n `autoRegister` tinyint(1) unsigned DEFAULT '1' COMMENT '是否开启自动注册',\n `uniqueId` varchar(32) DEFAULT NULL COMMENT '唯一ID',\n `secret` varchar(32) DEFAULT NULL COMMENT '密钥',\n `healthCheck` json DEFAULT NULL COMMENT '健康检查',\n `dnsName` varchar(255) DEFAULT NULL COMMENT 'DNS名称',\n `dnsDomainId` int(11) unsigned DEFAULT '0' COMMENT '域名ID',\n `dns` json DEFAULT NULL COMMENT 'DNS配置',\n `toa` json DEFAULT NULL COMMENT 'TOA配置',\n `cachePolicyId` int(11) unsigned DEFAULT '0' COMMENT '缓存策略ID',\n `httpFirewallPolicyId` int(11) unsigned DEFAULT '0' COMMENT 'WAF策略ID',\n `accessLog` json DEFAULT NULL COMMENT '访问日志设置',\n `systemServices` json DEFAULT NULL COMMENT '系统服务设置',\n `timeZone` varchar(64) DEFAULT NULL COMMENT '时区',\n `nodeMaxThreads` int(11) unsigned DEFAULT '0' COMMENT '节点最大线程数',\n `ddosProtection` json DEFAULT NULL COMMENT 'DDoS防护设置',\n `autoOpenPorts` tinyint(1) unsigned DEFAULT '1' COMMENT '是否自动尝试开放端口',\n `isPinned` tinyint(1) unsigned DEFAULT '0' COMMENT '是否置顶',\n `webp` json DEFAULT NULL COMMENT 'WebP设置',\n `uam` json DEFAULT NULL COMMENT 'UAM设置',\n `clock` json DEFAULT NULL COMMENT '时钟配置',\n `globalServerConfig` json DEFAULT NULL COMMENT '全局服务配置',\n `autoRemoteStart` tinyint(1) unsigned DEFAULT '1' COMMENT '自动远程启动',\n `autoInstallNftables` tinyint(1) unsigned DEFAULT '0' COMMENT '自动安装nftables',\n `isAD` tinyint(1) unsigned DEFAULT '0' COMMENT '是否为高防集群',\n `httpPages` json DEFAULT NULL COMMENT '自定义页面设置',\n `cc` json DEFAULT NULL COMMENT 'CC设置',\n PRIMARY KEY (`id`),\n KEY `uniqueId` (`uniqueId`),\n KEY `grantId` (`grantId`),\n KEY `dnsDomainId` (`dnsDomainId`),\n KEY `cachePolicyId` (`cachePolicyId`),\n KEY `httpFirewallPolicyId` (`httpFirewallPolicyId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点集群'",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"name": "id",
|
"name": "id",
|
||||||
@@ -68294,6 +68373,14 @@
|
|||||||
{
|
{
|
||||||
"name": "isAD",
|
"name": "isAD",
|
||||||
"definition": "tinyint(1) unsigned DEFAULT '0' COMMENT '是否为高防集群'"
|
"definition": "tinyint(1) unsigned DEFAULT '0' COMMENT '是否为高防集群'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "httpPages",
|
||||||
|
"definition": "json COMMENT '自定义页面设置'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cc",
|
||||||
|
"definition": "json COMMENT 'CC设置'"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"indexes": [
|
"indexes": [
|
||||||
@@ -69041,7 +69128,7 @@
|
|||||||
"name": "edgeNodeThresholds",
|
"name": "edgeNodeThresholds",
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"charset": "utf8mb4_general_ci",
|
"charset": "utf8mb4_general_ci",
|
||||||
"definition": "CREATE TABLE `edgeNodeThresholds` (\n `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `role` varchar(32) DEFAULT NULL COMMENT '节点角色',\n `clusterId` int(11) unsigned DEFAULT '0' COMMENT '集群ID',\n `nodeId` int(11) unsigned DEFAULT '0' COMMENT '节点ID',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `item` varchar(255) DEFAULT NULL COMMENT '监控项',\n `param` varchar(255) DEFAULT NULL COMMENT '参数',\n `operator` varchar(255) DEFAULT NULL COMMENT '操作符',\n `value` json DEFAULT NULL COMMENT '对比值',\n `message` varchar(512) DEFAULT NULL COMMENT '消息内容',\n `notifyDuration` int(11) unsigned DEFAULT '0' COMMENT '通知间隔(单位分钟)',\n `notifiedAt` int(11) unsigned DEFAULT '0' COMMENT '上次通知时间',\n `duration` int(11) unsigned DEFAULT '0' COMMENT '时间段',\n `durationUnit` varchar(16) DEFAULT NULL COMMENT '时间段单位',\n `sumMethod` varchar(32) DEFAULT NULL COMMENT '聚合方法',\n `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n PRIMARY KEY (`id`),\n KEY `nodeId` (`nodeId`),\n KEY `clusterId` (`clusterId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='集群阈值设置'",
|
"definition": "CREATE TABLE `edgeNodeThresholds` (\n `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `role` varchar(32) DEFAULT NULL COMMENT '节点角色',\n `clusterId` int(11) unsigned DEFAULT '0' COMMENT '集群ID',\n `nodeId` int(11) unsigned DEFAULT '0' COMMENT '节点ID',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `item` varchar(255) DEFAULT NULL COMMENT '监控项',\n `param` varchar(255) DEFAULT NULL COMMENT '参数',\n `operator` varchar(255) DEFAULT NULL COMMENT '操作符',\n `value` json DEFAULT NULL COMMENT '对比值',\n `message` varchar(512) DEFAULT NULL COMMENT '消息内容',\n `notifyDuration` int(11) unsigned DEFAULT '0' COMMENT '通知间隔(单位分钟)',\n `notifiedAt` int(11) unsigned DEFAULT '0' COMMENT '上次通知时间',\n `duration` int(11) unsigned DEFAULT '0' COMMENT '时间段',\n `durationUnit` varchar(16) DEFAULT NULL COMMENT '时间段单位',\n `sumMethod` varchar(32) DEFAULT NULL COMMENT '聚合方法',\n `order` int(11) unsigned DEFAULT '0' COMMENT '排序',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n PRIMARY KEY (`id`),\n KEY `nodeId` (`nodeId`),\n KEY `clusterId` (`clusterId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点监控阈值设置'",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"name": "id",
|
"name": "id",
|
||||||
@@ -69345,7 +69432,7 @@
|
|||||||
"name": "edgeNodes",
|
"name": "edgeNodes",
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"charset": "utf8mb4_general_ci",
|
"charset": "utf8mb4_general_ci",
|
||||||
"definition": "CREATE TABLE `edgeNodes` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n `level` tinyint(1) unsigned DEFAULT '1' COMMENT '级别',\n `lnAddrs` json DEFAULT NULL COMMENT 'Ln级别访问地址',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `isUp` tinyint(1) unsigned DEFAULT '1' COMMENT '是否在线',\n `countUp` int(11) unsigned DEFAULT '0' COMMENT '连续在线次数',\n `countDown` int(11) unsigned DEFAULT '0' COMMENT '连续下线次数',\n `isActive` tinyint(1) unsigned DEFAULT '1' COMMENT '是否活跃',\n `inactiveNotifiedAt` bigint(11) unsigned DEFAULT '0' COMMENT '离线通知时间',\n `uniqueId` varchar(32) DEFAULT NULL COMMENT '节点ID',\n `secret` varchar(32) DEFAULT NULL COMMENT '密钥',\n `name` varchar(255) DEFAULT NULL COMMENT '节点名',\n `code` varchar(255) DEFAULT NULL COMMENT '代号',\n `clusterId` int(11) unsigned DEFAULT '0' COMMENT '主集群ID',\n `secondaryClusterIds` json DEFAULT NULL COMMENT '从集群ID',\n `regionId` int(11) unsigned DEFAULT '0' COMMENT '区域ID',\n `groupId` int(11) unsigned DEFAULT '0' COMMENT '分组ID',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `status` json DEFAULT NULL COMMENT '最新的状态',\n `version` int(11) unsigned DEFAULT '0' COMMENT '当前版本号',\n `latestVersion` int(11) unsigned DEFAULT '0' COMMENT '最后版本号',\n `installDir` varchar(512) DEFAULT NULL COMMENT '安装目录',\n `isInstalled` tinyint(1) unsigned DEFAULT '0' COMMENT '是否已安装',\n `installStatus` json DEFAULT NULL COMMENT '安装状态',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n `connectedAPINodes` json DEFAULT NULL COMMENT '当前连接的API节点',\n `maxCPU` int(4) unsigned DEFAULT '0' COMMENT '可以使用的最多CPU',\n `maxThreads` int(11) unsigned DEFAULT '0' COMMENT '最大线程数',\n `ddosProtection` json DEFAULT NULL COMMENT 'DDOS配置',\n `dnsRoutes` json DEFAULT NULL COMMENT 'DNS线路设置',\n `maxCacheDiskCapacity` json DEFAULT NULL COMMENT '硬盘缓存容量',\n `maxCacheMemoryCapacity` json DEFAULT NULL COMMENT '内存缓存容量',\n `cacheDiskDir` varchar(255) DEFAULT NULL COMMENT '主缓存目录',\n `cacheDiskSubDirs` json DEFAULT NULL COMMENT '其他缓存目录',\n `dnsResolver` json DEFAULT NULL COMMENT 'DNS解析器',\n `enableIPLists` tinyint(1) unsigned DEFAULT '1' COMMENT '启用IP名单',\n `apiNodeAddrs` json DEFAULT NULL COMMENT 'API节点地址',\n PRIMARY KEY (`id`),\n KEY `uniqueId` (`uniqueId`),\n KEY `clusterId` (`clusterId`),\n KEY `groupId` (`groupId`),\n KEY `regionId` (`regionId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点'",
|
"definition": "CREATE TABLE `edgeNodes` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n `level` tinyint(1) unsigned DEFAULT '1' COMMENT '级别',\n `lnAddrs` json DEFAULT NULL COMMENT 'Ln级别访问地址',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `isUp` tinyint(1) unsigned DEFAULT '1' COMMENT '是否在线',\n `countUp` int(11) unsigned DEFAULT '0' COMMENT '连续在线次数',\n `countDown` int(11) unsigned DEFAULT '0' COMMENT '连续下线次数',\n `isActive` tinyint(1) unsigned DEFAULT '1' COMMENT '是否活跃',\n `inactiveNotifiedAt` bigint(11) unsigned DEFAULT '0' COMMENT '离线通知时间',\n `uniqueId` varchar(32) DEFAULT NULL COMMENT '节点ID',\n `secret` varchar(32) DEFAULT NULL COMMENT '密钥',\n `name` varchar(255) DEFAULT NULL COMMENT '节点名',\n `code` varchar(255) DEFAULT NULL COMMENT '代号',\n `clusterId` int(11) unsigned DEFAULT '0' COMMENT '主集群ID',\n `secondaryClusterIds` json DEFAULT NULL COMMENT '从集群ID',\n `regionId` int(11) unsigned DEFAULT '0' COMMENT '区域ID',\n `groupId` int(11) unsigned DEFAULT '0' COMMENT '分组ID',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `status` json DEFAULT NULL COMMENT '最新的状态',\n `version` int(11) unsigned DEFAULT '0' COMMENT '当前版本号',\n `latestVersion` int(11) unsigned DEFAULT '0' COMMENT '最后版本号',\n `installDir` varchar(512) DEFAULT NULL COMMENT '安装目录',\n `isInstalled` tinyint(1) unsigned DEFAULT '0' COMMENT '是否已安装',\n `installStatus` json DEFAULT NULL COMMENT '安装状态',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n `connectedAPINodes` json DEFAULT NULL COMMENT '当前连接的API节点',\n `maxCPU` int(4) unsigned DEFAULT '0' COMMENT '可以使用的最多CPU',\n `maxThreads` int(11) unsigned DEFAULT '0' COMMENT '最大线程数',\n `ddosProtection` json DEFAULT NULL COMMENT 'DDOS配置',\n `dnsRoutes` json DEFAULT NULL COMMENT 'DNS线路设置',\n `maxCacheDiskCapacity` json DEFAULT NULL COMMENT '硬盘缓存容量',\n `maxCacheMemoryCapacity` json DEFAULT NULL COMMENT '内存缓存容量',\n `cacheDiskDir` varchar(255) DEFAULT NULL COMMENT '主缓存目录',\n `cacheDiskSubDirs` json DEFAULT NULL COMMENT '其他缓存目录',\n `dnsResolver` json DEFAULT NULL COMMENT 'DNS解析器',\n `enableIPLists` tinyint(1) unsigned DEFAULT '1' COMMENT '启用IP名单',\n `apiNodeAddrs` json DEFAULT NULL COMMENT 'API节点地址',\n `offlineDay` varchar(8) DEFAULT NULL COMMENT '下线日期YYYYMMDD',\n `offlineIsNotified` tinyint(1) unsigned DEFAULT '0' COMMENT '下线是否已通知',\n `isBackupForCluster` tinyint(1) unsigned DEFAULT '0' COMMENT '是否为集群备用节点',\n `isBackupForGroup` tinyint(1) unsigned DEFAULT '0' COMMENT '是否为分组备用节点',\n `backupIPs` json DEFAULT NULL COMMENT '备用IP',\n `actionStatus` json DEFAULT NULL COMMENT '当前动作配置',\n PRIMARY KEY (`id`),\n KEY `uniqueId` (`uniqueId`),\n KEY `clusterId` (`clusterId`),\n KEY `groupId` (`groupId`),\n KEY `regionId` (`regionId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点'",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"name": "id",
|
"name": "id",
|
||||||
@@ -69502,6 +69589,30 @@
|
|||||||
{
|
{
|
||||||
"name": "apiNodeAddrs",
|
"name": "apiNodeAddrs",
|
||||||
"definition": "json COMMENT 'API节点地址'"
|
"definition": "json COMMENT 'API节点地址'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "offlineDay",
|
||||||
|
"definition": "varchar(8) COMMENT '下线日期YYYYMMDD'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "offlineIsNotified",
|
||||||
|
"definition": "tinyint(1) unsigned DEFAULT '0' COMMENT '下线是否已通知'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "isBackupForCluster",
|
||||||
|
"definition": "tinyint(1) unsigned DEFAULT '0' COMMENT '是否为集群备用节点'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "isBackupForGroup",
|
||||||
|
"definition": "tinyint(1) unsigned DEFAULT '0' COMMENT '是否为分组备用节点'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "backupIPs",
|
||||||
|
"definition": "json COMMENT '备用IP'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "actionStatus",
|
||||||
|
"definition": "json COMMENT '当前动作配置'"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"indexes": [
|
"indexes": [
|
||||||
|
|||||||
@@ -87,8 +87,8 @@ func (this *DNSTaskExecutor) loop() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case dnsmodels.DNSTaskTypeClusterChange:
|
case dnsmodels.DNSTaskTypeClusterChange, dnsmodels.DNSTaskTypeClusterNodesChange:
|
||||||
err = this.doCluster(taskId, taskVersion, int64(task.ClusterId))
|
err = this.doCluster(taskId, taskVersion, int64(task.ClusterId), task.Type == dnsmodels.DNSTaskTypeClusterNodesChange)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = dnsmodels.SharedDNSTaskDAO.UpdateDNSTaskError(nil, taskId, err.Error())
|
err = dnsmodels.SharedDNSTaskDAO.UpdateDNSTaskError(nil, taskId, err.Error())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -300,7 +300,7 @@ func (this *DNSTaskExecutor) doNode(taskId int64, taskVersion int64, nodeCluster
|
|||||||
|
|
||||||
// 转交给cluster统一处理
|
// 转交给cluster统一处理
|
||||||
if nodeClusterId > 0 {
|
if nodeClusterId > 0 {
|
||||||
err = dnsmodels.SharedDNSTaskDAO.CreateClusterTask(tx, nodeClusterId, dnsmodels.DNSTaskTypeClusterChange)
|
err = dnsmodels.SharedDNSTaskDAO.CreateClusterTask(tx, nodeClusterId, dnsmodels.DNSTaskTypeClusterNodesChange)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -310,7 +310,7 @@ func (this *DNSTaskExecutor) doNode(taskId int64, taskVersion int64, nodeCluster
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, clusterId := range clusterIds {
|
for _, clusterId := range clusterIds {
|
||||||
err = dnsmodels.SharedDNSTaskDAO.CreateClusterTask(tx, clusterId, dnsmodels.DNSTaskTypeClusterChange)
|
err = dnsmodels.SharedDNSTaskDAO.CreateClusterTask(tx, clusterId, dnsmodels.DNSTaskTypeClusterNodesChange)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -323,8 +323,8 @@ func (this *DNSTaskExecutor) doNode(taskId int64, taskVersion int64, nodeCluster
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 修改集群相关记录
|
// 修改集群相关记录
|
||||||
func (this *DNSTaskExecutor) doCluster(taskId int64, taskVersion int64, clusterId int64) error {
|
func (this *DNSTaskExecutor) doCluster(taskId int64, taskVersion int64, clusterId int64, nodesOnly bool) error {
|
||||||
isOk := false
|
var isOk = false
|
||||||
defer func() {
|
defer func() {
|
||||||
if isOk {
|
if isOk {
|
||||||
err := dnsmodels.SharedDNSTaskDAO.UpdateDNSTaskDone(nil, taskId, taskVersion)
|
err := dnsmodels.SharedDNSTaskDAO.UpdateDNSTaskDone(nil, taskId, taskVersion)
|
||||||
@@ -378,6 +378,14 @@ func (this *DNSTaskExecutor) doCluster(taskId int64, taskVersion int64, clusterI
|
|||||||
var isChanged = false
|
var isChanged = false
|
||||||
var addingNodeRecordKeysMap = map[string]bool{} // clusterDnsName_type_ip_route
|
var addingNodeRecordKeysMap = map[string]bool{} // clusterDnsName_type_ip_route
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
|
shouldSkip, shouldOverwrite, ipAddressesStrings, err := models.SharedNodeDAO.CheckNodeIPAddresses(tx, node)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if shouldSkip {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
routes, err := node.DNSRouteCodesForDomainId(domainId)
|
routes, err := node.DNSRouteCodesForDomainId(domainId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -387,26 +395,36 @@ func (this *DNSTaskExecutor) doCluster(taskId int64, taskVersion int64, clusterI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 所有的IP记录
|
// 所有的IP记录
|
||||||
ipAddresses, err := models.SharedNodeIPAddressDAO.FindAllEnabledAddressesWithNode(tx, int64(node.Id), nodeconfigs.NodeRoleNode)
|
if !shouldOverwrite {
|
||||||
if err != nil {
|
ipAddresses, err := models.SharedNodeIPAddressDAO.FindAllEnabledAddressesWithNode(tx, int64(node.Id), nodeconfigs.NodeRoleNode)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(ipAddresses) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, ipAddress := range ipAddresses {
|
||||||
|
// 检查专属节点
|
||||||
|
if !ipAddress.IsValidInCluster(clusterId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
var ip = ipAddress.DNSIP()
|
||||||
|
if len(ip) == 0 || !ipAddress.CanAccess || !ipAddress.IsUp || !ipAddress.IsOn {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if net.ParseIP(ip) == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ipAddressesStrings = append(ipAddressesStrings, ip)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(ipAddresses) == 0 {
|
|
||||||
|
if len(ipAddressesStrings) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, ipAddress := range ipAddresses {
|
|
||||||
// 检查专属节点
|
|
||||||
if !ipAddress.IsValidInCluster(clusterId) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
var ip = ipAddress.DNSIP()
|
for _, ip := range ipAddressesStrings {
|
||||||
if len(ip) == 0 || !ipAddress.CanAccess || !ipAddress.IsUp || !ipAddress.IsOn {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if net.ParseIP(ip) == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
var key = route + "@" + ip
|
var key = route + "@" + ip
|
||||||
_, ok := oldRecordsMap[key]
|
_, ok := oldRecordsMap[key]
|
||||||
@@ -456,80 +474,82 @@ func (this *DNSTaskExecutor) doCluster(taskId int64, taskVersion int64, clusterI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 服务域名
|
// 服务域名
|
||||||
servers, err := models.SharedServerDAO.FindAllServersDNSWithClusterId(tx, clusterId)
|
if !nodesOnly {
|
||||||
if err != nil {
|
servers, err := models.SharedServerDAO.FindAllServersDNSWithClusterId(tx, clusterId)
|
||||||
return err
|
if err != nil {
|
||||||
}
|
return err
|
||||||
serverRecords := []*dnstypes.Record{} // 之所以用数组再存一遍,是因为dnsName可能会重复
|
|
||||||
serverRecordsMap := map[string]*dnstypes.Record{} // dnsName => *Record
|
|
||||||
for _, record := range records {
|
|
||||||
if record.Type == dnstypes.RecordTypeCNAME && record.Value == clusterDomain+"." {
|
|
||||||
serverRecords = append(serverRecords, record)
|
|
||||||
serverRecordsMap[record.Name] = record
|
|
||||||
}
|
}
|
||||||
}
|
serverRecords := []*dnstypes.Record{} // 之所以用数组再存一遍,是因为dnsName可能会重复
|
||||||
|
serverRecordsMap := map[string]*dnstypes.Record{} // dnsName => *Record
|
||||||
// 新增的域名
|
for _, record := range records {
|
||||||
var serverDNSNames = []string{}
|
if record.Type == dnstypes.RecordTypeCNAME && record.Value == clusterDomain+"." {
|
||||||
for _, server := range servers {
|
serverRecords = append(serverRecords, record)
|
||||||
var dnsName = server.DnsName
|
serverRecordsMap[record.Name] = record
|
||||||
if len(dnsName) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
serverDNSNames = append(serverDNSNames, dnsName)
|
|
||||||
_, ok := serverRecordsMap[dnsName]
|
|
||||||
if !ok {
|
|
||||||
isChanged = true
|
|
||||||
err = manager.AddRecord(domain, &dnstypes.Record{
|
|
||||||
Id: "",
|
|
||||||
Name: dnsName,
|
|
||||||
Type: dnstypes.RecordTypeCNAME,
|
|
||||||
Value: clusterDomain + ".",
|
|
||||||
Route: "", // 注意这里为空,需要在执行过程中获取默认值
|
|
||||||
TTL: ttl,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 自动设置的CNAME
|
// 新增的域名
|
||||||
var cnameRecords = []string{}
|
var serverDNSNames = []string{}
|
||||||
if dnsConfig != nil {
|
for _, server := range servers {
|
||||||
cnameRecords = dnsConfig.CNAMERecords
|
var dnsName = server.DnsName
|
||||||
}
|
if len(dnsName) == 0 {
|
||||||
for _, cnameRecord := range cnameRecords {
|
continue
|
||||||
// 如果记录已存在,则跳过
|
}
|
||||||
if lists.ContainsString(serverDNSNames, cnameRecord) {
|
serverDNSNames = append(serverDNSNames, dnsName)
|
||||||
continue
|
_, ok := serverRecordsMap[dnsName]
|
||||||
}
|
if !ok {
|
||||||
|
isChanged = true
|
||||||
serverDNSNames = append(serverDNSNames, cnameRecord)
|
err = manager.AddRecord(domain, &dnstypes.Record{
|
||||||
_, ok := serverRecordsMap[cnameRecord]
|
Id: "",
|
||||||
if !ok {
|
Name: dnsName,
|
||||||
isChanged = true
|
Type: dnstypes.RecordTypeCNAME,
|
||||||
err = manager.AddRecord(domain, &dnstypes.Record{
|
Value: clusterDomain + ".",
|
||||||
Id: "",
|
Route: "", // 注意这里为空,需要在执行过程中获取默认值
|
||||||
Name: cnameRecord,
|
TTL: ttl,
|
||||||
Type: dnstypes.RecordTypeCNAME,
|
})
|
||||||
Value: clusterDomain + ".",
|
if err != nil {
|
||||||
Route: "", // 注意这里为空,需要在执行过程中获取默认值
|
return err
|
||||||
TTL: ttl,
|
}
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 多余的域名
|
// 自动设置的CNAME
|
||||||
for _, record := range serverRecords {
|
var cnameRecords = []string{}
|
||||||
if !lists.ContainsString(serverDNSNames, record.Name) {
|
if dnsConfig != nil {
|
||||||
isChanged = true
|
cnameRecords = dnsConfig.CNAMERecords
|
||||||
err = manager.DeleteRecord(domain, record)
|
}
|
||||||
if err != nil {
|
for _, cnameRecord := range cnameRecords {
|
||||||
return err
|
// 如果记录已存在,则跳过
|
||||||
|
if lists.ContainsString(serverDNSNames, cnameRecord) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
serverDNSNames = append(serverDNSNames, cnameRecord)
|
||||||
|
_, ok := serverRecordsMap[cnameRecord]
|
||||||
|
if !ok {
|
||||||
|
isChanged = true
|
||||||
|
err = manager.AddRecord(domain, &dnstypes.Record{
|
||||||
|
Id: "",
|
||||||
|
Name: cnameRecord,
|
||||||
|
Type: dnstypes.RecordTypeCNAME,
|
||||||
|
Value: clusterDomain + ".",
|
||||||
|
Route: "", // 注意这里为空,需要在执行过程中获取默认值
|
||||||
|
TTL: ttl,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 多余的域名
|
||||||
|
for _, record := range serverRecords {
|
||||||
|
if !lists.ContainsString(serverDNSNames, record.Name) {
|
||||||
|
isChanged = true
|
||||||
|
err = manager.DeleteRecord(domain, record)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
//go:build !plus
|
||||||
|
|
||||||
package tasks_test
|
package tasks_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ func (this *HealthCheckClusterTask) Loop() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var message = "有" + numberutils.FormatInt(len(failedResults)) + "个节点在健康检查中出现问题"
|
var message = "有" + numberutils.FormatInt(len(failedResults)) + "个节点IP在健康检查中出现问题"
|
||||||
err = models.NewMessageDAO().CreateClusterMessage(nil, nodeconfigs.NodeRoleNode, this.clusterId, models.MessageTypeHealthCheckFailed, models.MessageLevelError, message, message, failedResultsJSON)
|
err = models.NewMessageDAO().CreateClusterMessage(nil, nodeconfigs.NodeRoleNode, this.clusterId, models.MessageTypeHealthCheckFailed, models.MessageLevelError, message, message, failedResultsJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -12,9 +12,11 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeutils"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -63,26 +65,31 @@ func (this *HealthCheckExecutor) Run() ([]*HealthCheckResult, error) {
|
|||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tx *dbs.Tx
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
if !node.IsOn {
|
if !node.IsOn || node.IsBackupForCluster || node.IsBackupForGroup || (len(node.OfflineDay) > 0 && node.OfflineDay < timeutil.Format("Ymd")) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result := &HealthCheckResult{
|
|
||||||
Node: node,
|
|
||||||
}
|
|
||||||
|
|
||||||
ipAddr, ipAddrId, err := models.NewNodeIPAddressDAO().FindFirstNodeAccessIPAddress(nil, int64(node.Id), false, nodeconfigs.NodeRoleNode)
|
ipAddrs, err := models.SharedNodeIPAddressDAO.FindNodeAccessIPAddresses(tx, int64(node.Id), nodeconfigs.NodeRoleNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(ipAddr) == 0 {
|
for _, ipAddr := range ipAddrs {
|
||||||
result.Error = "no ip address can be used"
|
var ipClusterIds = ipAddr.DecodeClusterIds()
|
||||||
} else {
|
if len(ipClusterIds) > 0 && !lists.ContainsInt64(ipClusterIds, this.clusterId) {
|
||||||
result.NodeAddr = ipAddr
|
continue
|
||||||
result.NodeAddrId = ipAddrId
|
}
|
||||||
}
|
|
||||||
|
|
||||||
results = append(results, result)
|
// TODO 支持备用IP
|
||||||
|
var result = &HealthCheckResult{
|
||||||
|
Node: node,
|
||||||
|
NodeAddrId: int64(ipAddr.Id),
|
||||||
|
NodeAddr: ipAddr.Ip,
|
||||||
|
}
|
||||||
|
|
||||||
|
results = append(results, result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 并行检查
|
// 并行检查
|
||||||
@@ -188,6 +195,15 @@ func (this *HealthCheckExecutor) runNode(healthCheckConfig *serverconfigs.Health
|
|||||||
this.logErr("HealthCheckExecutor", err.Error())
|
this.logErr("HealthCheckExecutor", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 触发节点动作
|
||||||
|
if !result.IsOk {
|
||||||
|
err := this.fireNodeActions(int64(result.Node.Id))
|
||||||
|
if err != nil {
|
||||||
|
this.logErr("HealthCheckExecutor", err.Error())
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 触发阈值
|
// 触发阈值
|
||||||
|
|||||||
9
internal/tasks/health_check_executor_ext.go
Normal file
9
internal/tasks/health_check_executor_ext.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
//go:build !plus
|
||||||
|
|
||||||
|
package tasks
|
||||||
|
|
||||||
|
// 触发节点动作
|
||||||
|
func (this *HealthCheckExecutor) fireNodeActions(nodeId int64) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ func TestHealthCheckExecutor_Run(t *testing.T) {
|
|||||||
teaconst.IsPlus = true
|
teaconst.IsPlus = true
|
||||||
dbs.NotifyReady()
|
dbs.NotifyReady()
|
||||||
|
|
||||||
executor := tasks.NewHealthCheckExecutor(35)
|
var executor = tasks.NewHealthCheckExecutor(42)
|
||||||
results, err := executor.Run()
|
results, err := executor.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package tasks
|
|||||||
|
|
||||||
import "github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
import "github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
|
|
||||||
|
// HealthCheckResult 健康检查结果
|
||||||
type HealthCheckResult struct {
|
type HealthCheckResult struct {
|
||||||
Node *models.Node
|
Node *models.Node
|
||||||
NodeAddr string
|
NodeAddr string // 节点IP地址
|
||||||
NodeAddrId int64
|
NodeAddrId int64 // 节点IP地址ID
|
||||||
IsOk bool
|
IsOk bool
|
||||||
Error string
|
Error string
|
||||||
CostMs float64
|
CostMs float64
|
||||||
|
|||||||
@@ -72,12 +72,18 @@ func (this *HealthCheckTask) Loop() error {
|
|||||||
for _, cluster := range clusters {
|
for _, cluster := range clusters {
|
||||||
var clusterId = int64(cluster.Id)
|
var clusterId = int64(cluster.Id)
|
||||||
|
|
||||||
|
if !cluster.IsOn {
|
||||||
|
this.stopClusterTask(clusterId)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// 检查当前集群上是否有服务,如果尚没有部署服务,则直接跳过
|
// 检查当前集群上是否有服务,如果尚没有部署服务,则直接跳过
|
||||||
countServers, err := models.SharedServerDAO.CountAllEnabledServersWithNodeClusterId(nil, clusterId)
|
countServers, err := models.SharedServerDAO.CountAllEnabledServersWithNodeClusterId(nil, clusterId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if countServers == 0 {
|
if countServers == 0 {
|
||||||
|
this.stopClusterTask(clusterId)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,8 +92,16 @@ func (this *HealthCheckTask) Loop() error {
|
|||||||
err = json.Unmarshal(cluster.HealthCheck, config)
|
err = json.Unmarshal(cluster.HealthCheck, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.logErr("HealthCheckTask", err.Error())
|
this.logErr("HealthCheckTask", err.Error())
|
||||||
|
this.stopClusterTask(clusterId)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if !config.IsOn {
|
||||||
|
this.stopClusterTask(clusterId)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.stopClusterTask(clusterId)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
task, ok := this.tasksMap[clusterId]
|
task, ok := this.tasksMap[clusterId]
|
||||||
@@ -112,3 +126,11 @@ func (this *HealthCheckTask) Loop() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *HealthCheckTask) stopClusterTask(clusterId int64) {
|
||||||
|
var task = this.tasksMap[clusterId]
|
||||||
|
if task != nil {
|
||||||
|
task.Stop()
|
||||||
|
delete(this.tasksMap, clusterId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
17
internal/tasks/health_check_task_test.go
Normal file
17
internal/tasks/health_check_task_test.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package tasks_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/tasks"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewHealthCheckTask(t *testing.T) {
|
||||||
|
var task = tasks.NewHealthCheckTask(1 * time.Minute)
|
||||||
|
err := task.Loop()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user