Added initial attempt at reporting proper IPs in logs

This commit is contained in:
Seednode 2022-12-20 17:48:05 -06:00
parent cfbffb6dab
commit 3d560ef770
2 changed files with 13 additions and 2 deletions

View File

@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var Version = "0.27.0" var Version = "0.28.0"
func init() { func init() {
rootCmd.AddCommand(versionCmd) rootCmd.AddCommand(versionCmd)

View File

@ -293,11 +293,22 @@ func serveStaticFile(w http.ResponseWriter, r *http.Request, paths []string) err
w.Write(buf) w.Write(buf)
if Verbose { 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", fmt.Printf("%v | Served %v (%v) to %v in %v\n",
startTime.Format(LogDate), startTime.Format(LogDate),
filePath, filePath,
humanReadableSize(len(buf)), humanReadableSize(len(buf)),
r.RemoteAddr, remoteAddr,
time.Since(startTime).Round(time.Microsecond), time.Since(startTime).Round(time.Microsecond),
) )
} }