From c7f37d495802b7b24d72f92630dda9b39a1217f2 Mon Sep 17 00:00:00 2001 From: Jeremy Yen Date: Wed, 27 Sep 2023 16:07:19 +0800 Subject: [PATCH 1/2] Remove unused logs --- Dockerfile | 1 - internal/challenge_response.go | 2 +- internal/session_cookie.go | 8 ++++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 431849b..70e8584 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,6 @@ WORKDIR /opt/banjax # To enable live reload for dev, uncomment the following lines #COPY ./.air.toml /opt/banjax/ -# go mod edit -replace github.com/codahale/hdrhistogram=github.com/HdrHistogram/hdrhistogram-go@v0.9.0 #RUN go mod edit -replace github.com/imdario/mergo=dario.cat/mergo@v1.0.0 #RUN go get -u github.com/cosmtrek/air@v1.40.4 #RUN mkdir -p /opt/banjax/tmp diff --git a/internal/challenge_response.go b/internal/challenge_response.go index f07ce0c..4ee22cb 100644 --- a/internal/challenge_response.go +++ b/internal/challenge_response.go @@ -70,7 +70,7 @@ func ValidateExpirationAndHmac(secretKey string, func ParseCookie(cookieString string, clientIp string) ([]byte, []byte, []byte, error) { cookieBytes := make([]byte, 20+32+8) - log.Printf("ParseCookie[%s]: cookieString: %s", clientIp, cookieString) + // log.Printf("ParseCookie[%s]: cookieString: %s", clientIp, cookieString) cookieBytes, err := base64.StdEncoding.DecodeString(cookieString) if err != nil { diff --git a/internal/session_cookie.go b/internal/session_cookie.go index 26c49e8..ba4cfdd 100644 --- a/internal/session_cookie.go +++ b/internal/session_cookie.go @@ -115,13 +115,13 @@ func sessionCookieEndPoint(c *gin.Context, config *Config) error { // cookie exists, validate it validateErr := validateSessionCookie(dsc, config.SessionCookieHmacSecret, time.Now(), clientIp) if validateErr == nil { - // cookie is valid, do nothing - fmt.Printf("[%s] cookie %s is valid, report dsc_new=false\n", clientIp, dsc) + // cookie is valid, do not attach cookie but only report dsc_new=false + // fmt.Printf("DSC: [%s] cookie %s is valid, report dsc_new=false\n", clientIp, dsc) attachSessionCookie(c, config, dsc, false) } else { // cookie is invalid, create a new one newDsc := newSessionCookie(config.SessionCookieHmacSecret, config.SessionCookieTtlSeconds, clientIp) - fmt.Printf("[%s] cookie %s is not valid, issue new: %s\n", clientIp, dsc, newDsc) + fmt.Printf("DSC: [%s] cookie %s is not valid, issue new: %s\n", clientIp, dsc, newDsc) attachSessionCookie(c, config, newDsc, true) } return nil @@ -129,7 +129,7 @@ func sessionCookieEndPoint(c *gin.Context, config *Config) error { // no cookie, create a new one newDsc := newSessionCookie(config.SessionCookieHmacSecret, config.SessionCookieTtlSeconds, clientIp) - fmt.Printf("[%s] issue new cookie: %s\n", clientIp, newDsc) + // fmt.Printf("DSC: [%s] issue new cookie: %s\n", clientIp, newDsc) attachSessionCookie(c, config, newDsc, true) return nil } From 6ab0bdf5443a68c338b8f1a2a6b7a7f1c0f3e895 Mon Sep 17 00:00:00 2001 From: Jeremy Yen Date: Wed, 27 Sep 2023 16:28:54 +0800 Subject: [PATCH 2/2] Fix log print --- internal/session_cookie.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/session_cookie.go b/internal/session_cookie.go index ba4cfdd..767ed82 100644 --- a/internal/session_cookie.go +++ b/internal/session_cookie.go @@ -15,6 +15,7 @@ import ( "encoding/binary" "errors" "fmt" + "log" "math/rand" "strconv" "strings" @@ -121,7 +122,7 @@ func sessionCookieEndPoint(c *gin.Context, config *Config) error { } else { // cookie is invalid, create a new one newDsc := newSessionCookie(config.SessionCookieHmacSecret, config.SessionCookieTtlSeconds, clientIp) - fmt.Printf("DSC: [%s] cookie %s is not valid, issue new: %s\n", clientIp, dsc, newDsc) + log.Printf("DSC: [%s] cookie %s is not valid, issue new: %s\n", clientIp, dsc, newDsc) attachSessionCookie(c, config, newDsc, true) } return nil