mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
“系统设置 -- 安全管理”里可以单独添加允许访问的IP
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user