“系统设置 -- 安全管理”里可以单独添加允许访问的IP

This commit is contained in:
GoEdgeLab
2021-03-28 15:50:28 +08:00
parent a2bd1af9f2
commit 55a92b05c4
4 changed files with 43 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
@@ -23,6 +24,9 @@ func (this *IndexAction) RunGet(params struct{}) {
this.ErrorPage(err)
return
}
if config.AllowIPs == nil {
config.AllowIPs = []string{}
}
// 国家和地区
countryMaps := []maps.Map{}
@@ -69,6 +73,7 @@ func (this *IndexAction) RunPost(params struct {
CountryIdsJSON []byte
ProvinceIdsJSON []byte
AllowLocal bool
AllowIPs []string
Must *actions.Must
CSRF *actionutils.CSRF
@@ -106,6 +111,19 @@ func (this *IndexAction) RunPost(params struct {
}
config.AllowProvinceIds = provinceIds
// 允许的IP
if len(params.AllowIPs) > 0 {
for _, ip := range params.AllowIPs {
_, err := shared.ParseIPRange(ip)
if err != nil {
this.Fail("允许访问的IP '" + ip + "' 格式错误:" + err.Error())
}
}
config.AllowIPs = params.AllowIPs
} else {
config.AllowIPs = []string{}
}
// 允许本地
config.AllowLocal = params.AllowLocal