mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 16:00:25 +08:00 
			
		
		
		
	允许在集群设置 -- “网站设置” 中设置节点IP访问显示的内容
This commit is contained in:
		@@ -8,6 +8,7 @@ import (
 | 
				
			|||||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeNode/internal/ttlcache"
 | 
						"github.com/TeaOSLab/EdgeNode/internal/ttlcache"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeNode/internal/waf"
 | 
						"github.com/TeaOSLab/EdgeNode/internal/waf"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -32,7 +33,14 @@ func (this *HTTPRequest) doMismatch() {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 根据配置进行相应的处理
 | 
						// 根据配置进行相应的处理
 | 
				
			||||||
	if sharedNodeConfig.GlobalServerConfig != nil && sharedNodeConfig.GlobalServerConfig.HTTPAll.MatchDomainStrictly {
 | 
						var globalServerConfig = sharedNodeConfig.GlobalServerConfig
 | 
				
			||||||
 | 
						if globalServerConfig != nil && globalServerConfig.HTTPAll.MatchDomainStrictly {
 | 
				
			||||||
 | 
							// 是否正在访问IP
 | 
				
			||||||
 | 
							if globalServerConfig.HTTPAll.NodeIPShowPage && net.ParseIP(this.ReqHost) != nil {
 | 
				
			||||||
 | 
								_, _ = this.writer.WriteString(globalServerConfig.HTTPAll.NodeIPPageHTML)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 检查cc
 | 
							// 检查cc
 | 
				
			||||||
		// TODO 可以在管理端配置是否开启以及最多尝试次数
 | 
							// TODO 可以在管理端配置是否开启以及最多尝试次数
 | 
				
			||||||
		// 要考虑到服务在切换集群时,域名未生效状态时,用户访问的仍然是老集群中的节点,就会产生找不到域名的情况
 | 
							// 要考虑到服务在切换集群时,域名未生效状态时,用户访问的仍然是老集群中的节点,就会产生找不到域名的情况
 | 
				
			||||||
@@ -47,7 +55,7 @@ func (this *HTTPRequest) doMismatch() {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 处理当前连接
 | 
							// 处理当前连接
 | 
				
			||||||
		var httpAllConfig = sharedNodeConfig.GlobalServerConfig.HTTPAll
 | 
							var httpAllConfig = globalServerConfig.HTTPAll
 | 
				
			||||||
		var mismatchAction = httpAllConfig.DomainMismatchAction
 | 
							var mismatchAction = httpAllConfig.DomainMismatchAction
 | 
				
			||||||
		if mismatchAction != nil && mismatchAction.Code == "page" {
 | 
							if mismatchAction != nil && mismatchAction.Code == "page" {
 | 
				
			||||||
			if mismatchAction.Options != nil {
 | 
								if mismatchAction.Options != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -116,7 +116,7 @@ func (this *BaseListener) matchSSL(domain string) (*sslconfigs.SSLPolicy, *tls.C
 | 
				
			|||||||
		return nil, nil, errors.New("no tls server name found")
 | 
							return nil, nil, errors.New("no tls server name found")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 通过代理服务域名配置匹配
 | 
						// 通过网站域名配置匹配
 | 
				
			||||||
	server, _ := this.findNamedServer(domain)
 | 
						server, _ := this.findNamedServer(domain)
 | 
				
			||||||
	if server == nil {
 | 
						if server == nil {
 | 
				
			||||||
		// 找不到或者此时的服务没有配置证书,需要搜索所有的Server,通过SSL证书内容中的DNSName匹配
 | 
							// 找不到或者此时的服务没有配置证书,需要搜索所有的Server,通过SSL证书内容中的DNSName匹配
 | 
				
			||||||
@@ -138,7 +138,7 @@ func (this *BaseListener) matchSSL(domain string) (*sslconfigs.SSLPolicy, *tls.C
 | 
				
			|||||||
	if server.SSLPolicy() == nil || !server.SSLPolicy().IsOn {
 | 
						if server.SSLPolicy() == nil || !server.SSLPolicy().IsOn {
 | 
				
			||||||
		// 找不到或者此时的服务没有配置证书,需要搜索所有的Server,通过SSL证书内容中的DNSName匹配
 | 
							// 找不到或者此时的服务没有配置证书,需要搜索所有的Server,通过SSL证书内容中的DNSName匹配
 | 
				
			||||||
		// 此功能仅为了兼容以往版本(v1.0.4),不应该作为常态启用
 | 
							// 此功能仅为了兼容以往版本(v1.0.4),不应该作为常态启用
 | 
				
			||||||
		if  globalServerConfig != nil && globalServerConfig.HTTPAll.MatchCertFromAllServers {
 | 
							if globalServerConfig != nil && globalServerConfig.HTTPAll.MatchCertFromAllServers {
 | 
				
			||||||
			for _, searchingServer := range group.Servers() {
 | 
								for _, searchingServer := range group.Servers() {
 | 
				
			||||||
				if searchingServer.SSLPolicy() == nil || !searchingServer.SSLPolicy().IsOn {
 | 
									if searchingServer.SSLPolicy() == nil || !searchingServer.SSLPolicy().IsOn {
 | 
				
			||||||
					continue
 | 
										continue
 | 
				
			||||||
@@ -174,19 +174,26 @@ func (this *BaseListener) findNamedServer(name string) (serverConfig *serverconf
 | 
				
			|||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var matchDomainStrictly = sharedNodeConfig.GlobalServerConfig != nil && sharedNodeConfig.GlobalServerConfig.HTTPAll.MatchDomainStrictly
 | 
						var globalServerConfig = sharedNodeConfig.GlobalServerConfig
 | 
				
			||||||
 | 
						var matchDomainStrictly = globalServerConfig != nil && globalServerConfig.HTTPAll.MatchDomainStrictly
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if sharedNodeConfig.GlobalServerConfig != nil &&
 | 
						if globalServerConfig != nil &&
 | 
				
			||||||
		len(sharedNodeConfig.GlobalServerConfig.HTTPAll.DefaultDomain) > 0 &&
 | 
							len(globalServerConfig.HTTPAll.DefaultDomain) > 0 &&
 | 
				
			||||||
		(!matchDomainStrictly || configutils.MatchDomains(sharedNodeConfig.GlobalServerConfig.HTTPAll.AllowMismatchDomains, name) || (sharedNodeConfig.GlobalServerConfig.HTTPAll.AllowNodeIP && net.ParseIP(name) != nil)) {
 | 
							(!matchDomainStrictly || configutils.MatchDomains(globalServerConfig.HTTPAll.AllowMismatchDomains, name) || (globalServerConfig.HTTPAll.AllowNodeIP && net.ParseIP(name) != nil)) {
 | 
				
			||||||
		var defaultDomain = sharedNodeConfig.GlobalServerConfig.HTTPAll.DefaultDomain
 | 
							if globalServerConfig.HTTPAll.AllowNodeIP &&
 | 
				
			||||||
		serverConfig, serverName = this.findNamedServerMatched(defaultDomain)
 | 
								globalServerConfig.HTTPAll.NodeIPShowPage &&
 | 
				
			||||||
		if serverConfig != nil {
 | 
								net.ParseIP(name) != nil {
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								var defaultDomain = globalServerConfig.HTTPAll.DefaultDomain
 | 
				
			||||||
 | 
								serverConfig, serverName = this.findNamedServerMatched(defaultDomain)
 | 
				
			||||||
 | 
								if serverConfig != nil {
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if matchDomainStrictly && !configutils.MatchDomains(sharedNodeConfig.GlobalServerConfig.HTTPAll.AllowMismatchDomains, name) && (!sharedNodeConfig.GlobalServerConfig.HTTPAll.AllowNodeIP || net.ParseIP(name) == nil) {
 | 
						if matchDomainStrictly && !configutils.MatchDomains(globalServerConfig.HTTPAll.AllowMismatchDomains, name) && (!globalServerConfig.HTTPAll.AllowNodeIP || net.ParseIP(name) == nil) {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user