From 3d560ef7702c8a03e98a56d9c07cc469c2e4ee7a Mon Sep 17 00:00:00 2001 From: Seednode Date: Tue, 20 Dec 2022 17:48:05 -0600 Subject: [PATCH] Added initial attempt at reporting proper IPs in logs --- cmd/version.go | 2 +- cmd/web.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/version.go b/cmd/version.go index 4a3afc6..93e3986 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.27.0" +var Version = "0.28.0" func init() { rootCmd.AddCommand(versionCmd) diff --git a/cmd/web.go b/cmd/web.go index f138b77..48b1c6a 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -293,11 +293,22 @@ func serveStaticFile(w http.ResponseWriter, r *http.Request, paths []string) err w.Write(buf) if Verbose { + remoteAddr := "" + cfIP := w.Header().Get("Cf-Connecting-Ip") + xRealIp := w.Header().Get("X-Real-Ip") + if cfIP != "" { + remoteAddr = cfIP + } else if xRealIp != "" { + remoteAddr = xRealIp + } else { + remoteAddr = r.RemoteAddr + } + fmt.Printf("%v | Served %v (%v) to %v in %v\n", startTime.Format(LogDate), filePath, humanReadableSize(len(buf)), - r.RemoteAddr, + remoteAddr, time.Since(startTime).Round(time.Microsecond), ) }