访问日志支持中文域名搜索

This commit is contained in:
GoEdgeLab
2022-09-07 17:07:46 +08:00
parent 312d94821a
commit d9b49b55fa

View File

@@ -21,6 +21,7 @@ import (
"github.com/iwind/TeaGo/rands" "github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types" "github.com/iwind/TeaGo/types"
timeutil "github.com/iwind/TeaGo/utils/time" timeutil "github.com/iwind/TeaGo/utils/time"
"golang.org/x/net/idna"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
@@ -509,6 +510,14 @@ func (this *HTTPAccessLogDAO) listAccessLogs(tx *dbs.Tx,
query.Where("domain LIKE :host2"). query.Where("domain LIKE :host2").
Param("host2", domain) Param("host2", domain)
} else { } else {
// 中文域名
if !regexp.MustCompile(`^[a-zA-Z0-9-.]+$`).MatchString(domain) {
unicodeDomain, err := idna.ToASCII(domain)
if err == nil && len(unicodeDomain) > 0 {
domain = unicodeDomain
}
}
query.Attr("domain", domain) query.Attr("domain", domain)
query.UseIndex("domain") query.UseIndex("domain")
} }