mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 13:10:26 +08:00 
			
		
		
		
	修复 安全设置 -- 允许访问的国家和地区 中不能使用中国特殊区域的问题
This commit is contained in:
		@@ -2,10 +2,10 @@ package helpers
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeAdmin/internal/events"
 | 
						"github.com/TeaOSLab/EdgeAdmin/internal/events"
 | 
				
			||||||
	nodes "github.com/TeaOSLab/EdgeAdmin/internal/rpc"
 | 
					 | 
				
			||||||
	"github.com/TeaOSLab/EdgeAdmin/internal/utils"
 | 
						"github.com/TeaOSLab/EdgeAdmin/internal/utils"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
 | 
				
			||||||
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/regionconfigs"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
 | 
				
			||||||
	"github.com/iwind/TeaGo/lists"
 | 
						"github.com/iwind/TeaGo/lists"
 | 
				
			||||||
	"github.com/iwind/TeaGo/logs"
 | 
						"github.com/iwind/TeaGo/logs"
 | 
				
			||||||
@@ -77,23 +77,25 @@ func checkIPWithoutCache(config *systemconfigs.SecurityConfig, ipAddr string) bo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// 检查位置
 | 
						// 检查位置
 | 
				
			||||||
	if len(config.AllowCountryIds) > 0 || len(config.AllowProvinceIds) > 0 {
 | 
						if len(config.AllowCountryIds) > 0 || len(config.AllowProvinceIds) > 0 {
 | 
				
			||||||
		rpc, err := nodes.SharedRPC()
 | 
							var userRegion = iplibrary.Lookup(ip)
 | 
				
			||||||
		if err != nil {
 | 
							if userRegion == nil || !userRegion.IsOk() {
 | 
				
			||||||
			logs.Println("[USER_MUST_AUTH][ERROR]" + err.Error())
 | 
					 | 
				
			||||||
			return false
 | 
								return false
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		resp, err := rpc.IPLibraryRPC().LookupIPRegion(rpc.Context(0), &pb.LookupIPRegionRequest{Ip: ipAddr})
 | 
							if len(config.AllowCountryIds) > 0 {
 | 
				
			||||||
		if err != nil {
 | 
								// 检查大中华区
 | 
				
			||||||
			logs.Println("[USER_MUST_AUTH][ERROR]" + err.Error())
 | 
								var found = false
 | 
				
			||||||
			return false
 | 
								for _, countryId := range config.AllowCountryIds {
 | 
				
			||||||
 | 
									if regionconfigs.MatchUserRegion(userRegion.CountryId(), userRegion.ProvinceId(), countryId) {
 | 
				
			||||||
 | 
										found = true
 | 
				
			||||||
 | 
										break
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if !found {
 | 
				
			||||||
 | 
									return false
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if resp.IpRegion == nil {
 | 
							if len(config.AllowProvinceIds) > 0 && !lists.ContainsInt64(config.AllowProvinceIds, userRegion.ProvinceId()) {
 | 
				
			||||||
			return true
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if len(config.AllowCountryIds) > 0 && !lists.ContainsInt64(config.AllowCountryIds, resp.IpRegion.CountryId) {
 | 
					 | 
				
			||||||
			return false
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if len(config.AllowProvinceIds) > 0 && !lists.ContainsInt64(config.AllowProvinceIds, resp.IpRegion.ProvinceId) {
 | 
					 | 
				
			||||||
			return false
 | 
								return false
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user