From c2804868dccb4b62f7df7edc65b16046c50007b7 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sat, 27 May 2023 18:12:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=95=8C=E9=9D=A2=E5=B1=8F?= =?UTF-8?q?=E8=94=BD=E4=B8=AA=E5=88=AB=E6=95=8F=E6=84=9F=E5=8C=BA=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/web/actions/default/index/index.go | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/internal/web/actions/default/index/index.go b/internal/web/actions/default/index/index.go index 100e0534..63a5ad58 100644 --- a/internal/web/actions/default/index/index.go +++ b/internal/web/actions/default/index/index.go @@ -13,15 +13,19 @@ import ( adminserverutils "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/server/admin-server-utils" "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" "github.com/TeaOSLab/EdgeCommon/pkg/configutils" + "github.com/TeaOSLab/EdgeCommon/pkg/iplibrary" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/types" stringutil "github.com/iwind/TeaGo/utils/string" "net" "time" ) +const regionDenyMessage = "当前软件系统暂时不为你所在的区域提供服务。" + type IndexAction struct { actionutils.ParentAction } @@ -36,6 +40,11 @@ func (this *IndexAction) RunGet(params struct { Auth *helpers.UserShouldAuth }) { + if !this.checkRegion() { + this.WriteString(regionDenyMessage) + return + } + // 是否自动从HTTP跳转到HTTPS if this.Request.TLS == nil { httpsPort, _ := adminserverutils.ReadServerHTTPS() @@ -125,6 +134,11 @@ func (this *IndexAction) RunPost(params struct { Auth *helpers.UserShouldAuth CSRF *actionutils.CSRF }) { + if !this.checkRegion() { + this.Fail(regionDenyMessage) + return + } + params.Must. Field("username", params.Username). Require("请输入用户名"). @@ -216,3 +230,13 @@ func (this *IndexAction) RunPost(params struct { this.Success() } + +// 检查登录区域 +func (this *IndexAction) checkRegion() bool { + var ip = this.RequestRemoteIP() + var result = iplibrary.LookupIP(ip) + if result != nil && result.IsOk() && result.CountryId() > 0 && lists.ContainsInt64([]int64{10}, result.CountryId()) { + return false + } + return true +}