ソースを参照

config bugfix for X-Forwarded-For header when parsing logfiles

Tobias von Dewitz 6 年 前
コミット
5cc2d01372
2 ファイル変更4 行追加4 行削除
  1. 1 1
      Makefile
  2. 3 3
      main.go

+ 1 - 1
Makefile

@@ -3,4 +3,4 @@ BUILD=$(shell date +%FT%T%z)
 
 
 all:
-	go build -tags netgo -ldflags "-s -X main.Version=$(VERSION) -X main.BuildDate=$(BUILD)"
+	env GOOS=linux GOARCH=amd64 go build -tags netgo -ldflags "-s -X main.Version=$(VERSION) -X main.BuildDate=$(BUILD)"

+ 3 - 3
main.go

@@ -278,9 +278,9 @@ func nginxLogCapture(logfile, format string) {
 			continue
 		}
 
-		if *useXForwardedAsSource {
+		if config.UseXForwardedAsSource {
 			xff, err := logEntry.Field("http_x_forwarded_for")
-			if err != nil {
+			if err != nil && xff != "" {
 				remote = xff
 			}
 		}
@@ -387,7 +387,7 @@ func apacheLogCapture(logfile string) {
 		}
 
 		remote := logEntry.Host
-		if *useXForwardedAsSource && logEntry.ForwardedFor != "" {
+		if config.UseXForwardedAsSource && logEntry.ForwardedFor != "" {
 			remote = logEntry.ForwardedFor
 		}