Files
EdgeCommon/pkg/nodeconfigs/node_config.go

713 lines
21 KiB
Go
Raw Normal View History

2020-09-26 08:07:24 +08:00
package nodeconfigs
import (
"bytes"
"context"
2022-04-04 16:42:11 +08:00
"crypto/sha256"
"encoding/base64"
2020-09-26 08:07:24 +08:00
"encoding/json"
2022-01-19 22:15:52 +08:00
"errors"
2020-10-10 19:22:22 +08:00
"fmt"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeutils"
2020-09-26 08:07:24 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
2022-05-18 21:02:58 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
2020-10-08 15:06:56 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
2020-09-26 08:07:24 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/Tea"
2021-01-11 18:16:22 +08:00
"github.com/iwind/TeaGo/maps"
2022-08-04 11:52:28 +08:00
"os"
2022-01-19 22:15:52 +08:00
"reflect"
"strconv"
"strings"
"sync"
2020-09-26 08:07:24 +08:00
)
var sharedNodeConfig *NodeConfig = nil
var uamPolicyLocker = &sync.RWMutex{}
2023-05-23 19:16:09 +08:00
var httpCCPolicyLocker = &sync.RWMutex{}
2023-05-22 17:30:08 +08:00
var httpPagesPolicyLocker = &sync.RWMutex{}
2020-09-26 08:07:24 +08:00
type ServerError struct {
Id int64
Message string
}
func NewServerError(serverId int64, message string) *ServerError {
return &ServerError{Id: serverId, Message: message}
}
// NodeConfig 边缘节点配置
2020-09-26 08:07:24 +08:00
type NodeConfig struct {
Id int64 `yaml:"id" json:"id"`
Edition string `yaml:"edition" json:"edition"`
NodeId string `yaml:"nodeId" json:"nodeId"`
Secret string `yaml:"secret" json:"secret"`
IsOn bool `yaml:"isOn" json:"isOn"`
Servers []*serverconfigs.ServerConfig `yaml:"servers" json:"servers"`
SupportCNAME bool `yaml:"supportCNAME" json:"supportCNAME"`
Version int64 `yaml:"version" json:"version"`
Name string `yaml:"name" json:"name"`
GroupId int64 `yaml:"groupId" json:"groupId"`
RegionId int64 `yaml:"regionId" json:"regionId"`
OCSPVersion int64 `yaml:"ocspVersion" json:"ocspVersion"`
DataMap *shared.DataMap `yaml:"dataMap" json:"dataMap"`
UpdatingServerListId int64 `yaml:"updatingServerListId" json:"updatingServerListId"`
2022-03-18 17:04:53 +08:00
// 性能
MaxCPU int32 `yaml:"maxCPU" json:"maxCPU"`
APINodeAddrs []*serverconfigs.NetworkAddressConfig `yaml:"apiNodeAddrs" json:"apiNodeAddrs"`
CacheDiskDir string `yaml:"cacheDiskDir" json:"cacheDiskDir"` // 文件缓存目录
MaxCacheDiskCapacity *shared.SizeCapacity `yaml:"maxCacheDiskCapacity" json:"maxCacheDiskCapacity"` // 文件缓存容量
CacheDiskSubDirs []*serverconfigs.CacheDir `yaml:"cacheDiskSubDirs" json:"cacheDiskSubDirs"` // 其余缓存目录
2022-05-18 21:02:58 +08:00
MaxCacheMemoryCapacity *shared.SizeCapacity `yaml:"maxCacheMemoryCapacity" json:"maxCacheMemoryCapacity"` // 内容缓存容量
MaxThreads int `yaml:"maxThreads" json:"maxThreads"` // 最大线程数
DDoSProtection *ddosconfigs.ProtectionConfig `yaml:"ddosProtection" json:"ddosProtection"` // DDoS防护
EnableIPLists bool `yaml:"enableIPLists" json:"enableIPLists"` // 启用IP名单
2020-09-26 08:07:24 +08:00
2022-04-04 16:42:11 +08:00
// 级别
Level int32 `yaml:"level" json:"level"`
ParentNodes map[int64][]*ParentNodeConfig `yaml:"parentNodes" json:"parentNodes"` // clusterId => []*ParentNodeConfig
2020-09-26 08:07:24 +08:00
// 全局配置
2022-09-16 18:41:10 +08:00
GlobalConfig *serverconfigs.GlobalConfig `yaml:"globalConfig" json:"globalConfig"` // 全局配置
GlobalServerConfig *serverconfigs.GlobalServerConfig `yaml:"globalServerConfig" json:"globalServerConfig"` // 服务全局配置,用来替代 GlobalConfig
ProductConfig *ProductConfig `yaml:"productConfig" json:"productConfig"`
2020-10-05 16:54:21 +08:00
// 集群统一配置
2021-08-01 14:52:10 +08:00
HTTPFirewallPolicies []*firewallconfigs.HTTPFirewallPolicy `yaml:"httpFirewallPolicies" json:"httpFirewallPolicies"`
HTTPCachePolicies []*serverconfigs.HTTPCachePolicy `yaml:"httpCachePolicies" json:"httpCachePolicies"`
TOA *TOAConfig `yaml:"toa" json:"toa"`
2022-09-18 09:26:01 +08:00
SystemServices map[string]maps.Map `yaml:"systemServices" json:"systemServices"` // 系统服务配置 type => params
FirewallActions []*firewallconfigs.FirewallActionConfig `yaml:"firewallActions" json:"firewallActions"` // 防火墙动作
TimeZone string `yaml:"timeZone" json:"timeZone"` // 自动设置时区
AutoOpenPorts bool `yaml:"autoOpenPorts" json:"autoOpenPorts"` // 自动开放所需端口
Clock *ClockConfig `yaml:"clock" json:"clock"` // 时钟配置
AutoInstallNftables bool `yaml:"autoInstallNftables" json:"autoInstallNftables"` // 自动安装nftables
2020-12-02 14:26:17 +08:00
2022-03-18 17:04:53 +08:00
// 指标
2021-06-27 22:00:02 +08:00
MetricItems []*serverconfigs.MetricItemConfig `yaml:"metricItems" json:"metricItems"`
2022-03-18 17:04:53 +08:00
// 自动白名单
AllowedIPs []string `yaml:"allowedIPs" json:"allowedIPs"`
2022-03-25 14:12:12 +08:00
// 脚本
CommonScripts []*serverconfigs.CommonScript `yaml:"commonScripts" json:"commonScripts"`
2022-04-01 16:20:36 +08:00
// WebP
2022-04-04 16:42:11 +08:00
WebPImagePolicies map[int64]*WebPImagePolicy `yaml:"webpImagePolicies" json:"webpImagePolicies"` // clusterId => *WebPImagePolicy
2022-04-01 16:20:36 +08:00
2022-07-03 22:10:18 +08:00
// UAM相关配置
2023-05-22 17:30:08 +08:00
UAMPolicies map[int64]*UAMPolicy `yaml:"uamPolicies" json:"uamPolicies"` // clusterId => *UAMPolicy
2023-05-23 19:16:09 +08:00
// CC相关配置
HTTPCCPolicies map[int64]*HTTPCCPolicy `yaml:"httpCCPolicies" json:"httpCCPolicies"` // clusterId => *HTTPCCPolicy
2023-05-22 17:30:08 +08:00
// 自定义页面
HTTPPagesPolicies map[int64]*HTTPPagesPolicy `yaml:"httpPagesPolicies" json:"httpPagesPolicies"` // clusterId => *HTTPPagesPolicy
2022-07-03 22:10:18 +08:00
2022-05-04 16:40:43 +08:00
// DNS
DNSResolver *DNSResolverConfig `yaml:"dnsResolver" json:"dnsResolver"`
paddedId string
2021-06-30 20:50:17 +08:00
// firewall
firewallPolicies []*firewallconfigs.HTTPFirewallPolicy
2021-06-30 20:50:17 +08:00
// metrics
hasHTTPConnectionMetrics bool
2021-08-01 21:56:15 +08:00
// 源站集合
originMap map[int64]*serverconfigs.OriginConfig
// 自动白名单
allowedIPMap map[string]bool
2022-01-10 19:54:18 +08:00
// syn flood
synFlood *firewallconfigs.SYNFloodConfig
2022-04-04 16:42:11 +08:00
secretHash string
2020-09-26 08:07:24 +08:00
}
// SharedNodeConfig 取得当前节点配置单例
2020-09-26 08:07:24 +08:00
func SharedNodeConfig() (*NodeConfig, error) {
shared.Locker.Lock()
defer shared.Locker.Unlock()
if sharedNodeConfig != nil {
return sharedNodeConfig, nil
}
// 从本地缓存读取
var configFile = Tea.ConfigFile("node.json")
var readCacheOk = false
defer func() {
if !readCacheOk {
_ = os.Remove(configFile)
}
}()
data, err := os.ReadFile(configFile)
if err != nil {
return &NodeConfig{}, err
}
encodedNodeInfo, encodedJSONData, found := bytes.Cut(data, []byte("\n"))
if !found {
// 删除缓存文件
return &NodeConfig{}, errors.New("node.json: invalid data format")
}
encodedNodeInfoData, err := base64.StdEncoding.DecodeString(string(encodedNodeInfo))
if err != nil {
// 删除缓存文件
return &NodeConfig{}, err
}
nodeUniqueId, nodeSecret, found := strings.Cut(string(encodedNodeInfoData), "|")
if !found {
// 删除缓存文件
return &NodeConfig{}, errors.New("node.json: node info: invalid data format")
}
jsonData, err := nodeutils.DecryptData(nodeUniqueId, nodeSecret, string(encodedJSONData))
2020-09-26 08:07:24 +08:00
if err != nil {
return &NodeConfig{}, err
}
2022-09-16 18:41:10 +08:00
var config = &NodeConfig{}
err = json.Unmarshal(jsonData, &config)
2020-09-26 08:07:24 +08:00
if err != nil {
return &NodeConfig{}, err
}
readCacheOk = true
2020-09-26 08:07:24 +08:00
sharedNodeConfig = config
return config, nil
}
// ResetNodeConfig 重置节点配置
2020-09-26 08:07:24 +08:00
func ResetNodeConfig(nodeConfig *NodeConfig) {
shared.Locker.Lock()
sharedNodeConfig = nodeConfig
shared.Locker.Unlock()
}
2022-01-19 22:15:52 +08:00
// CloneNodeConfig 复制节点配置
func CloneNodeConfig(nodeConfig *NodeConfig) (*NodeConfig, error) {
if nodeConfig == nil {
return nil, errors.New("node config should not be nil")
}
uamPolicyLocker.RLock()
defer uamPolicyLocker.RUnlock()
2023-05-23 19:16:09 +08:00
httpCCPolicyLocker.RLock()
defer httpCCPolicyLocker.RUnlock()
2023-05-22 17:30:08 +08:00
httpPagesPolicyLocker.RLock()
defer httpPagesPolicyLocker.RUnlock()
2022-01-19 22:15:52 +08:00
var newConfigValue = reflect.Indirect(reflect.ValueOf(&NodeConfig{}))
var oldValue = reflect.Indirect(reflect.ValueOf(nodeConfig))
var valueType = oldValue.Type()
for i := 0; i < valueType.NumField(); i++ {
var field = valueType.Field(i)
var fieldName = field.Name
if !field.IsExported() {
continue
}
if fieldName == "Servers" {
continue
}
newConfigValue.FieldByName(fieldName).Set(oldValue.FieldByName(fieldName))
}
var newConfig = newConfigValue.Interface().(NodeConfig)
newConfig.Servers = append([]*serverconfigs.ServerConfig{}, nodeConfig.Servers...)
return &newConfig, nil
}
// Init 初始化
func (this *NodeConfig) Init(ctx context.Context) (err error, serverErrors []*ServerError) {
// 设置Context
if ctx == nil {
ctx = context.Background()
}
ctx = context.WithValue(ctx, "DataMap", this.DataMap)
2022-04-04 16:42:11 +08:00
this.secretHash = fmt.Sprintf("%x", sha256.Sum256([]byte(this.NodeId+"@"+this.Secret)))
2020-10-10 19:22:22 +08:00
this.paddedId = fmt.Sprintf("%08d", this.Id)
2020-10-05 16:54:21 +08:00
// servers
for _, server := range this.Servers {
2022-09-22 11:09:11 +08:00
// 避免在运行时重新初始化
if server.IsInitialized() {
continue
}
2022-01-19 22:15:52 +08:00
// 初始化
errs := server.Init(ctx)
if len(errs) > 0 {
// 这里不返回错误,而是继续往下,防止单个服务错误而影响其他服务
for _, serverErr := range errs {
serverErrors = append(serverErrors, NewServerError(server.Id, "server '"+strconv.FormatInt(server.Id, 10)+"' init failed: "+serverErr.Error()))
}
2020-10-05 16:54:21 +08:00
}
2022-01-19 22:15:52 +08:00
// 检查ACME支持
if server.IsOn && server.SupportCNAME {
this.SupportCNAME = true
}
2020-10-05 16:54:21 +08:00
}
// global config
if this.GlobalConfig != nil {
err = this.GlobalConfig.Init()
2020-10-05 16:54:21 +08:00
if err != nil {
return
2020-10-05 16:54:21 +08:00
}
}
// cache policy
2021-08-01 14:52:10 +08:00
if len(this.HTTPCachePolicies) > 0 {
for _, policy := range this.HTTPCachePolicies {
err = policy.Init()
2021-08-01 14:52:10 +08:00
if err != nil {
return
2021-08-01 14:52:10 +08:00
}
2020-10-08 15:06:56 +08:00
}
}
// firewall policy
2021-08-01 14:52:10 +08:00
if len(this.HTTPFirewallPolicies) > 0 {
for _, policy := range this.HTTPFirewallPolicies {
err = policy.Init()
2021-08-01 14:52:10 +08:00
if err != nil {
return
2021-08-01 14:52:10 +08:00
}
2020-10-05 16:54:21 +08:00
}
}
2020-12-02 14:26:17 +08:00
// TOA
if this.TOA != nil {
err = this.TOA.Init()
2020-12-02 14:26:17 +08:00
if err != nil {
return
2020-12-02 14:26:17 +08:00
}
}
2021-08-01 21:56:15 +08:00
// 源站
this.originMap = map[int64]*serverconfigs.OriginConfig{}
// 查找FirewallPolicy
2022-01-19 22:15:52 +08:00
this.synFlood = nil
this.firewallPolicies = []*firewallconfigs.HTTPFirewallPolicy{}
2021-08-01 14:52:10 +08:00
for _, policy := range this.HTTPFirewallPolicies {
if policy.IsOn {
this.firewallPolicies = append(this.firewallPolicies, policy)
2022-01-10 19:54:18 +08:00
if policy.SYNFlood != nil && policy.SYNFlood.IsOn {
this.synFlood = policy.SYNFlood
}
2021-08-01 14:52:10 +08:00
}
}
for _, server := range this.Servers {
if !server.IsOk() || !server.IsOn {
continue
}
2021-08-01 14:52:10 +08:00
// WAF策略
if server.HTTPFirewallPolicyId > 0 {
for _, policy := range this.HTTPFirewallPolicies {
if server.HTTPFirewallPolicyId == policy.Id {
server.HTTPFirewallPolicy = policy
break
}
}
}
// 缓存策略
if server.HTTPCachePolicyId > 0 {
for _, policy := range this.HTTPCachePolicies {
if server.HTTPCachePolicyId == policy.Id {
server.HTTPCachePolicy = policy
}
}
}
2021-08-01 21:56:15 +08:00
// 源站
if server.ReverseProxyRef != nil && server.ReverseProxyRef.IsOn && server.ReverseProxy != nil && server.ReverseProxy.IsOn {
for _, origin := range server.ReverseProxy.PrimaryOrigins {
if origin.IsOn {
this.originMap[origin.Id] = origin
}
}
for _, origin := range server.ReverseProxy.BackupOrigins {
if origin.IsOn {
this.originMap[origin.Id] = origin
}
}
}
if server.Web != nil {
2021-08-01 14:52:10 +08:00
this.lookupWeb(server, server.Web)
}
}
// firewall actions
for _, action := range this.FirewallActions {
err = action.Init()
if err != nil {
return
}
}
2021-06-27 22:00:02 +08:00
// metric items
2021-06-30 20:50:17 +08:00
this.hasHTTPConnectionMetrics = false
2021-06-27 22:00:02 +08:00
for _, item := range this.MetricItems {
err = item.Init()
2021-06-27 22:00:02 +08:00
if err != nil {
return
2021-06-27 22:00:02 +08:00
}
2021-06-30 20:50:17 +08:00
if item.IsOn && item.HasHTTPConnectionValue() {
this.hasHTTPConnectionMetrics = true
}
2021-06-27 22:00:02 +08:00
}
// 自动白名单
this.allowedIPMap = map[string]bool{}
for _, allowIP := range this.AllowedIPs {
this.allowedIPMap[allowIP] = true
}
2022-04-01 16:20:36 +08:00
// webp image policy
if this.WebPImagePolicies != nil {
for _, policy := range this.WebPImagePolicies {
err = policy.Init()
if err != nil {
return
}
}
}
2022-07-03 22:10:18 +08:00
// uam policy
uamPolicyLocker.RLock()
2023-05-22 17:30:08 +08:00
if len(this.UAMPolicies) > 0 {
2022-07-03 22:10:18 +08:00
for _, policy := range this.UAMPolicies {
err = policy.Init()
if err != nil {
uamPolicyLocker.RUnlock()
2022-07-03 22:10:18 +08:00
return
}
}
}
uamPolicyLocker.RUnlock()
2022-07-03 22:10:18 +08:00
2023-05-23 19:16:09 +08:00
// http cc policy
httpCCPolicyLocker.RLock()
if len(this.HTTPCCPolicies) > 0 {
for _, policy := range this.HTTPCCPolicies {
err = policy.Init()
if err != nil {
httpCCPolicyLocker.RUnlock()
return
}
}
}
httpCCPolicyLocker.RUnlock()
// http pages policy
2023-05-22 17:30:08 +08:00
httpPagesPolicyLocker.RLock()
if len(this.HTTPPagesPolicies) > 0 {
for _, policy := range this.HTTPPagesPolicies {
err = policy.Init()
if err != nil {
httpPagesPolicyLocker.RUnlock()
return
}
}
}
httpPagesPolicyLocker.RUnlock()
2022-05-04 16:40:43 +08:00
// dns resolver
if this.DNSResolver != nil {
err = this.DNSResolver.Init()
if err != nil {
return
}
}
2022-09-16 18:41:10 +08:00
// 全局服务设置
if this.GlobalServerConfig != nil {
err = this.GlobalServerConfig.Init()
if err != nil {
return
}
}
// api node addrs
if len(this.APINodeAddrs) > 0 {
for _, addr := range this.APINodeAddrs {
err := addr.Init()
if err != nil {
return err, nil
}
}
}
return
2020-10-05 16:54:21 +08:00
}
2022-01-19 22:15:52 +08:00
// AddServer 添加服务
func (this *NodeConfig) AddServer(server *serverconfigs.ServerConfig) {
if server == nil {
return
}
var found = false
for index, oldServer := range this.Servers {
if oldServer.Id == server.Id {
this.Servers[index] = server
found = true
break
}
}
if !found {
this.Servers = append(this.Servers, server)
}
}
// RemoveServer 删除服务
func (this *NodeConfig) RemoveServer(serverId int64) {
for index, oldServer := range this.Servers {
if oldServer.Id == serverId {
this.Servers = append(this.Servers[:index], this.Servers[index+1:]...)
break
}
}
}
// AvailableGroups 根据网络地址和协议分组
2021-09-22 19:39:55 +08:00
func (this *NodeConfig) AvailableGroups() []*serverconfigs.ServerAddressGroup {
var groupMapping = map[string]*serverconfigs.ServerAddressGroup{} // protocol://addr => Server Group
2020-09-26 08:07:24 +08:00
for _, server := range this.Servers {
if !server.IsOk() || !server.IsOn {
2020-09-26 08:07:24 +08:00
continue
}
for _, addr := range server.FullAddresses() {
group, ok := groupMapping[addr]
if ok {
group.Add(server)
} else {
2021-09-22 19:39:55 +08:00
group = serverconfigs.NewServerAddressGroup(addr)
2020-09-26 08:07:24 +08:00
group.Add(server)
}
groupMapping[addr] = group
}
}
var result = []*serverconfigs.ServerAddressGroup{}
2020-09-26 08:07:24 +08:00
for _, group := range groupMapping {
result = append(result, group)
}
return result
}
// FindAllFirewallPolicies 获取所有的防火墙策略
func (this *NodeConfig) FindAllFirewallPolicies() []*firewallconfigs.HTTPFirewallPolicy {
return this.firewallPolicies
}
// Save 写入到文件
2020-09-26 08:07:24 +08:00
func (this *NodeConfig) Save() error {
shared.Locker.Lock()
defer shared.Locker.Unlock()
data, err := json.Marshal(this)
if err != nil {
return err
}
var headerData = []byte(base64.StdEncoding.EncodeToString([]byte(this.NodeId+"|"+this.Secret)) + "\n")
encodedData, err := nodeutils.EncryptData(this.NodeId, this.Secret, data)
if err != nil {
return err
}
return os.WriteFile(Tea.ConfigFile("node.json"), append(headerData, encodedData...), 0777)
2020-09-26 08:07:24 +08:00
}
2020-10-05 16:54:21 +08:00
// PaddedId 获取填充后的ID
2020-10-10 19:22:22 +08:00
func (this *NodeConfig) PaddedId() string {
return this.paddedId
}
2021-06-30 20:50:17 +08:00
// HasHTTPConnectionMetrics 是否含有HTTP连接数的指标
func (this *NodeConfig) HasHTTPConnectionMetrics() bool {
return this.hasHTTPConnectionMetrics
}
2021-08-01 21:56:15 +08:00
// FindOrigin 读取源站配置
func (this *NodeConfig) FindOrigin(originId int64) *serverconfigs.OriginConfig {
if this.originMap == nil {
return nil
}
config, ok := this.originMap[originId]
if ok {
return config
}
return nil
}
// 搜索WAF策略
2021-08-01 14:52:10 +08:00
func (this *NodeConfig) lookupWeb(server *serverconfigs.ServerConfig, web *serverconfigs.HTTPWebConfig) {
if web == nil || !web.IsOn {
return
}
if web.FirewallPolicy != nil && web.FirewallPolicy.IsOn {
// 复用节点的选项设置
if server.HTTPFirewallPolicy != nil {
2022-05-21 18:57:59 +08:00
if (web.FirewallPolicy.BlockOptions == nil || !web.FirewallPolicy.BlockOptions.IsPrior) && server.HTTPFirewallPolicy.BlockOptions != nil {
web.FirewallPolicy.BlockOptions = server.HTTPFirewallPolicy.BlockOptions
}
2022-05-21 18:57:59 +08:00
if (web.FirewallPolicy.CaptchaOptions == nil || !web.FirewallPolicy.CaptchaOptions.IsPrior) && server.HTTPFirewallPolicy.CaptchaOptions != nil {
web.FirewallPolicy.CaptchaOptions = server.HTTPFirewallPolicy.CaptchaOptions
}
2022-05-21 18:57:59 +08:00
if (web.FirewallPolicy.SYNFlood == nil || !web.FirewallPolicy.SYNFlood.IsPrior) && server.HTTPFirewallPolicy.SYNFlood != nil {
web.FirewallPolicy.SYNFlood = server.HTTPFirewallPolicy.SYNFlood
}
if (web.FirewallPolicy.Log == nil || !web.FirewallPolicy.Log.IsPrior) && server.HTTPFirewallPolicy.Log != nil {
web.FirewallPolicy.Log = server.HTTPFirewallPolicy.Log
}
web.FirewallPolicy.Mode = server.HTTPFirewallPolicy.Mode
web.FirewallPolicy.UseLocalFirewall = server.HTTPFirewallPolicy.UseLocalFirewall
}
this.firewallPolicies = append(this.firewallPolicies, web.FirewallPolicy)
}
if len(web.Locations) > 0 {
for _, location := range web.Locations {
2021-08-01 21:56:15 +08:00
// 源站
if location.IsOn && location.ReverseProxyRef != nil && location.ReverseProxyRef.IsOn && location.ReverseProxy != nil && location.ReverseProxy.IsOn {
for _, origin := range location.ReverseProxy.PrimaryOrigins {
if origin.IsOn {
this.originMap[origin.Id] = origin
}
}
for _, origin := range location.ReverseProxy.BackupOrigins {
if origin.IsOn {
this.originMap[origin.Id] = origin
}
}
}
// Web
if location.Web != nil && location.Web.IsOn {
2021-08-01 14:52:10 +08:00
this.lookupWeb(server, location.Web)
}
}
}
}
// IPIsAutoAllowed 检查是否自动允许某个IP
func (this *NodeConfig) IPIsAutoAllowed(ip string) bool {
_, ok := this.allowedIPMap[ip]
return ok
}
2022-01-10 19:54:18 +08:00
// SYNFloodConfig 获取SYN Flood配置
func (this *NodeConfig) SYNFloodConfig() *firewallconfigs.SYNFloodConfig {
return this.synFlood
}
2022-03-18 17:04:53 +08:00
// UpdateCertOCSP 修改证书OCSP
2022-03-18 20:20:28 +08:00
func (this *NodeConfig) UpdateCertOCSP(certId int64, ocsp []byte, expiresAt int64) {
2022-03-18 17:04:53 +08:00
shared.Locker.Lock()
defer shared.Locker.Unlock()
var servers = this.Servers
for _, server := range servers {
if server.HTTPS != nil &&
server.HTTPS.SSLPolicy != nil &&
server.HTTPS.SSLPolicy.OCSPIsOn &&
server.HTTPS.SSLPolicy.ContainsCert(certId) {
2022-03-18 20:20:28 +08:00
server.HTTPS.SSLPolicy.UpdateCertOCSP(certId, ocsp, expiresAt)
2022-03-18 17:04:53 +08:00
}
if server.TLS != nil &&
server.TLS.SSLPolicy != nil &&
server.TLS.SSLPolicy.OCSPIsOn &&
server.TLS.SSLPolicy.ContainsCert(certId) {
2022-03-18 20:20:28 +08:00
server.TLS.SSLPolicy.UpdateCertOCSP(certId, ocsp, expiresAt)
2022-03-18 17:04:53 +08:00
}
}
}
2022-04-01 16:20:36 +08:00
// FindWebPImagePolicyWithClusterId 使用集群ID查找WebP策略
func (this *NodeConfig) FindWebPImagePolicyWithClusterId(clusterId int64) *WebPImagePolicy {
if this.WebPImagePolicies == nil {
return nil
}
return this.WebPImagePolicies[clusterId]
}
2022-04-04 16:42:11 +08:00
2022-07-03 22:10:18 +08:00
// FindUAMPolicyWithClusterId 使用集群ID查找UAM策略
func (this *NodeConfig) FindUAMPolicyWithClusterId(clusterId int64) *UAMPolicy {
uamPolicyLocker.RLock()
defer uamPolicyLocker.RUnlock()
2022-07-03 22:10:18 +08:00
if this.UAMPolicies == nil {
return nil
}
return this.UAMPolicies[clusterId]
}
// UpdateUAMPolicies 修改集群UAM策略
func (this *NodeConfig) UpdateUAMPolicies(policies map[int64]*UAMPolicy) {
uamPolicyLocker.Lock()
defer uamPolicyLocker.Unlock()
this.UAMPolicies = policies
}
2023-05-23 19:16:09 +08:00
// FindHTTPCCPolicyWithClusterId 使用集群ID查找CC策略
func (this *NodeConfig) FindHTTPCCPolicyWithClusterId(clusterId int64) *HTTPCCPolicy {
httpCCPolicyLocker.RLock()
defer httpCCPolicyLocker.RUnlock()
if this.HTTPCCPolicies == nil {
return nil
}
return this.HTTPCCPolicies[clusterId]
}
// UpdateHTTPCCPolicies 修改集群CC策略
func (this *NodeConfig) UpdateHTTPCCPolicies(policies map[int64]*HTTPCCPolicy) {
httpCCPolicyLocker.Lock()
defer httpCCPolicyLocker.Unlock()
this.HTTPCCPolicies = policies
}
2023-05-22 17:30:08 +08:00
// UpdateHTTPPagesPolicies 修改集群自定义页面策略
func (this *NodeConfig) UpdateHTTPPagesPolicies(policies map[int64]*HTTPPagesPolicy) {
httpPagesPolicyLocker.Lock()
defer httpPagesPolicyLocker.Unlock()
this.HTTPPagesPolicies = policies
}
// FindHTTPPagesPolicyWithClusterId 使用集群ID查找自定义页面策略
func (this *NodeConfig) FindHTTPPagesPolicyWithClusterId(clusterId int64) *HTTPPagesPolicy {
httpPagesPolicyLocker.RLock()
defer httpPagesPolicyLocker.RUnlock()
if this.HTTPPagesPolicies == nil {
return nil
}
return this.HTTPPagesPolicies[clusterId]
}
2022-04-04 16:42:11 +08:00
// SecretHash 对Id和Secret的Hash计算
func (this *NodeConfig) SecretHash() string {
return this.secretHash
}