This commit is contained in:
aozhiwei 2020-11-03 16:15:40 +08:00
parent 7ee3df2b24
commit 2e2562c7cd
4 changed files with 12 additions and 1 deletions

View File

@ -19,7 +19,7 @@ func (this *App_) Init() {
G.HttpServer = new(f5.HttpServer).Init("httpserver", 1000 * 60)
G.RiskMgr = new(RiskMgr).Init()
G.HttpServer.Start(G.MetaMgr.GetServer(1).GetListenPort());
G.HttpServer.Start(G.MetaMgr.GetCurrServer().GetListenPort());
}
func (this *App_) UnInit() {

View File

@ -82,6 +82,10 @@ func (this *MetaMgr) GetServer(instance_id int32) *MtwServerInfo {
}
}
func (this *MetaMgr) GetCurrServer() *MtwServerInfo {
return this.GetServer(int32(f5.App.GetInstanceId()))
}
func (this *MetaMgr) GetAliKey() *MtwAliKeyConf {
v, ok := this.MetaMgr.GetMetaById(MT_ALI_KEY, 1).(*MtwAliKeyConf)
if ok {

View File

@ -54,6 +54,8 @@ type RiskMgr struct {
launchBlackListBlockTimes int64
totalUnSafeZoneBlockTimes int64
unSafeZoneBlockTimes int64
clusterConf *MtwServerInfo
}
func (this* RiskMgr) Init() *RiskMgr {
@ -94,6 +96,7 @@ func (this* RiskMgr) Init() *RiskMgr {
}
this.accessKeyId = G.MetaMgr.GetAliKey().GetAccessKeyid()
this.accessSecret = G.MetaMgr.GetAliKey().GetAccessSecret()
this.clusterConf = G.MetaMgr.GetCurrServer()
G.HttpServer.RegisterHandle("Analyse", "isOpen", this.__analyseIsOpen)
G.HttpServer.RegisterHandle("Ops", "dump", this.__opsDump)
@ -254,6 +257,9 @@ func (this *RiskMgr) __analyseIsOpen(w* http.ResponseWriter, r *http.Request) {
channel := f5.ExtractChannelFromAccountId(accountId)
remoteAddr := q5.GetRequestRemoteAddr(r)
if this.clusterConf.GetTesting() == 1 && q5.Request(r, "ip").GetString() != "" {
remoteAddr = q5.Request(r, "ip").GetString()
}
if G.RiskMgr.InIpWhiteList(remoteAddr) {
atomic.AddInt64(&this.totalIpWhiteListPassTimes, 1)
atomic.AddInt64(&this.ipWhiteListPassTimes, 1)

View File

@ -18,6 +18,7 @@ message ServerInfo
optional int32 instance_id = 1;
optional string listen_ip = 2;
optional int32 listen_port = 3;
optional int32 testing = 4;
}
message ServerInfoMetas