From 37ffb6e4ba874d6cc1001d0076ce100db6ebd083 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 28 Mar 2021 15:50:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E5=85=A8=E9=85=8D=E7=BD=AE=E4=B8=AD?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=8D=95=E7=8B=AC=E6=B7=BB=E5=8A=A0=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E8=AE=BF=E9=97=AE=E7=9A=84IP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/systemconfigs/security_config.go | 30 ++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/pkg/systemconfigs/security_config.go b/pkg/systemconfigs/security_config.go index 5a448ef..d8ad08f 100644 --- a/pkg/systemconfigs/security_config.go +++ b/pkg/systemconfigs/security_config.go @@ -1,9 +1,31 @@ package systemconfigs +import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" + // 安全相关配置 type SecurityConfig struct { - Frame string `json:"frame"` - AllowCountryIds []int64 `json:"allowCountryIds"` - AllowProvinceIds []int64 `json:"allowProvinceIds"` - AllowLocal bool `json:"allowLocal"` + Frame string `json:"frame"` // Frame嵌套 + AllowCountryIds []int64 `json:"allowCountryIds"` // 允许的国家/地区 + AllowProvinceIds []int64 `json:"allowProvinceIds"` // 允许的省份 + AllowLocal bool `json:"allowLocal"` // 允许本地+局域网IP访问 + AllowIPs []string `json:"allowIPs"` // 允许访问的IP + + allowIPRanges []*shared.IPRangeConfig +} + +// 初始化 +func (this *SecurityConfig) Init() error { + this.allowIPRanges = []*shared.IPRangeConfig{} + for _, allowIP := range this.AllowIPs { + r, err := shared.ParseIPRange(allowIP) + if err != nil { + return err + } + this.allowIPRanges = append(this.allowIPRanges, r) + } + return nil +} + +func (this *SecurityConfig) AllowIPRanges() []*shared.IPRangeConfig { + return this.allowIPRanges }