Browse Source

Merge branch 'master' of git.scraperwall.com:scw/munchclient

Tobias Begalke 6 years ago
parent
commit
6cbb7600c3
3 changed files with 34 additions and 5 deletions
  1. 1 1
      Makefile
  2. 8 1
      build-rpm-centos7.sh
  3. 25 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)"

+ 8 - 1
build-rpm-centos7.sh

@@ -1,5 +1,7 @@
 #!/bin/bash
 
+set -x
+
 DESTDIR=./dist
 VERSION=$(git describe --tag | sed 's/^v//')
 ITERATION=1
@@ -26,6 +28,8 @@ install -v -m 644 $BINARY.toml $DESTDIR/usr/share/$BINARY/
 # install -v -m 644 ca-chain.cert.pem $DESTDIR/etc/$BINARY/
 
 
+
+docker run --rm -i -t -v $PWD:/scw -v $PWD/rpmmacros:/home/build/.rpmmacros -w /scw scw-centos7-build:latest \
 fpm -s dir -t $PKG_TYPE -C $DESTDIR --name $BINARY \
   --version $VERSION \
   --iteration $ITERATION \
@@ -37,6 +41,7 @@ fpm -s dir -t $PKG_TYPE -C $DESTDIR --name $BINARY \
   -p $OUTDIR \
   --rpm-sign
 
+
 ok=$?
 
 rm -rf $DESTDIR
@@ -46,7 +51,9 @@ if [ $ok -eq 0 -a -f "$rpm_file" ]; then
 	# rm -f "$RPM_DIR/$BINARY-*.rpm"
   cp "$rpm_file" "$RPM_DIR"
 
+	docker run --rm -i -t -v $RPM_DIR:/rpms -w /rpms scw-centos7-build:latest \
+    createrepo -v . \
+
 	(cd "$RPM_DIR" && \
-   createrepo -v . && \
    rsync -av --progress --delete . fender.spyz.org:/srv/http-vhosts/rpm.scraperwall.com/centos7/)
 fi

+ 25 - 3
main.go

@@ -24,6 +24,7 @@ import (
 	"github.com/google/gopacket/layers"
 	"github.com/google/gopacket/pcap"
 	"github.com/hpcloud/tail"
+	"github.com/kr/pretty"
 	"github.com/nats-io/nats"
 	"github.com/nats-io/nats/encoders/protobuf"
 	"github.com/satyrius/gonx"
@@ -269,6 +270,9 @@ func nginxLogCapture(logfile, format string) {
 	reqRegexp := regexp.MustCompile(`^([A-Z]+)\s+(.+?)\s+(HTTP/\d+\.\d+)$`)
 
 	for line := range t.Lines {
+		var remote string
+		var err error
+
 		l := line.Text
 
 		logEntry, err := p.ParseString(l)
@@ -277,12 +281,30 @@ func nginxLogCapture(logfile, format string) {
 			continue
 		}
 
-		remote, err := logEntry.Field("remote_addr")
+		if config.Trace {
+			pretty.Println(logEntry)
+		}
+
+		remote, err = logEntry.Field("remote_addr")
 		if err != nil {
 			log.Println(err)
 			continue
 		}
 
+		xff, err := logEntry.Field("http_x_forwarded_for")
+		if err != nil && xff != "" {
+			if config.Trace {
+				log.Printf("Using XFF: %s\n", xff)
+			}
+
+			remote = xff
+		}
+
+		if remote == "" {
+			log.Println("remote is empty: ignoring request.")
+			continue
+		}
+
 		// only use the first host in case there are multiple hosts in the log
 		if cidx := strings.Index(remote, ","); cidx >= 0 {
 			remote = remote[0:cidx]
@@ -575,7 +597,7 @@ func apacheLogCapture(logfile string) {
 		}
 
 		remote := logEntry.Host
-		if *useXForwardedAsSource && logEntry.ForwardedFor != "" {
+		if config.UseXForwardedAsSource && logEntry.ForwardedFor != "" {
 			remote = logEntry.ForwardedFor
 		}
 
@@ -1078,7 +1100,7 @@ func loadConfig() {
 	}
 }
 
-// version outputs build information
+// version outputs build information...
 func version() {
 	fmt.Printf("munchclient %s, built on %s\n", Version, BuildDate)
 }