diff --git a/Docker/Dockerfile b/Docker/Dockerfile index 6750443..bf374df 100644 --- a/Docker/Dockerfile +++ b/Docker/Dockerfile @@ -3,6 +3,6 @@ FROM scratch MAINTAINER Michele Fadda "" -COPY lastlogin_mongodb-v4.2.0 /bin/lastlogin_mongodb +COPY lastlogin_mongodb-v4.3.0 /bin/lastlogin_mongodb ENTRYPOINT [ "/bin/lastlogin_mongodb" ] diff --git a/Docker/build.sh b/Docker/build.sh new file mode 100755 index 0000000..f46bc98 --- /dev/null +++ b/Docker/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build -t mikif70/llmongo:4.3.0 . diff --git a/Docker/run.sh b/Docker/run.sh index 9f96e6d..7131db0 100644 --- a/Docker/run.sh +++ b/Docker/run.sh @@ -6,9 +6,8 @@ docker run \ --name llmongo_tiscali \ --log-opt max-size=2m \ --log-opt max-file=5 \ - mikif70/llmongo:4.2.0 \ + mikif70/llmongo:4.2.1 \ -l /data/llmongo.log \ - -p /data/llmongo.pid \ -r redis-ll.mail.tiscali.sys:6379 \ -m 10.39.80.189:27017 \ -d lastlogin \ diff --git a/consumer.go b/consumer.go index ac33e1b..1128301 100644 --- a/consumer.go +++ b/consumer.go @@ -2,6 +2,8 @@ package main import ( + "crypto/md5" + "crypto/sha1" "crypto/sha256" "encoding/hex" "fmt" @@ -19,7 +21,7 @@ type consumed struct { logins []string } -func hash(val []byte) string { +func hash256(val []byte) string { h := sha256.New() h.Write(val) @@ -27,6 +29,22 @@ func hash(val []byte) string { return hex.EncodeToString(h.Sum(nil)) } +func hash160(val []byte) string { + + h := sha1.New() + h.Write(val) + + return hex.EncodeToString(h.Sum(nil)) +} + +func hash128(val []byte) string { + + h := md5.New() + h.Write(val) + + return hex.EncodeToString(h.Sum(nil)) +} + // protocol:timestamp:ip:country func consumer() { @@ -68,7 +86,7 @@ func consumer() { } // genera l' _ID con user + timestamp + ip - mlID := hash([]byte(fmt.Sprintf("%s%s%s", prod.user, time.Unix(date, 0).Format("20060102T15"), sval[2]))) // Format("20060102T150405") + mlID := hash160([]byte(fmt.Sprintf("%s%s%s", prod.user, time.Unix(date, 0).Format("20060102T15"), sval[2]))) // Format("20060102T150405") ml := MongoLogin{ ID: mlID, User: prod.user, diff --git a/dbs.go b/dbs.go index 2416667..f0bec39 100644 --- a/dbs.go +++ b/dbs.go @@ -90,7 +90,7 @@ func (db *Dbs) poolRedis() { func (db *Dbs) connectMongo() { - mongoList := strings.Split(db.MongoURI, ",") + mongoList := strings.Split(db.MongoURI, "|") for m := range mongoList { nm, err := mgo.Dial(fmt.Sprintf("mongodb://%s", mongoList[m])) diff --git a/main.go b/main.go index 0aca129..c04d029 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( ) const ( - _Version = "v4.2.0" + _Version = "v4.3.0" _Producer = 0 _Consumer = 1 _Remover = 2 @@ -75,8 +75,8 @@ func main() { // defer pid.Remove() start := time.Now() - fmt.Printf("Start: %+v\n", opts) - log.Printf("Start: %+v\n", opts) + fmt.Printf("Start:\t%+v\n\t%+v\n", opts, dbs) + log.Printf("Start:\t%+v\n\t%+v\n", opts, dbs) opts.Month = start.Format("0601")