aggiunto estrazione whois
This commit is contained in:
parent
d67a1a407d
commit
3b8869dfb4
1 changed files with 43 additions and 37 deletions
80
llmongo.js
80
llmongo.js
|
@ -4,6 +4,7 @@ var Redis = require('redis');
|
|||
var MongoClient = require('mongodb').MongoClient
|
||||
var fs = require('fs')
|
||||
var Console = require('console').Console;
|
||||
var whois = require('whois-json');
|
||||
|
||||
var redis, mongodb, lastlogin, mongoUri, redisUri, logname;
|
||||
|
||||
|
@ -18,7 +19,7 @@ Logger.prototype.log = function(){
|
|||
var args = Array.prototype.slice.call(arguments);
|
||||
var string = args[0];
|
||||
args.shift();
|
||||
// console.log(string + " - " + args );
|
||||
// console.log(string + " - " + args );
|
||||
if (args.length > 0) {
|
||||
this.mylog.log.apply(this, ["%s "+string,(new Date()).toJSON()].concat(args));
|
||||
} else {
|
||||
|
@ -34,20 +35,20 @@ var args = process.argv.slice(2);
|
|||
args.forEach(function(val, index, array){
|
||||
switch(val) {
|
||||
case '-mongo':
|
||||
if(args[index+1].search('mongodb://') >= 0) {
|
||||
mongoUri = args[index+1];
|
||||
} else {
|
||||
mongoUri = 'mongodb://'+args[index+1];
|
||||
}
|
||||
break;
|
||||
if(args[index+1].search('mongodb://') >= 0) {
|
||||
mongoUri = args[index+1];
|
||||
} else {
|
||||
mongoUri = 'mongodb://'+args[index+1];
|
||||
}
|
||||
break;
|
||||
case '-redis':
|
||||
if(args[index+1].match(/\S+:\d+/)) {
|
||||
redisUri = args[index+1];
|
||||
} else {
|
||||
logger.log("Wrong redis URI");
|
||||
process.exit(0);
|
||||
}
|
||||
break;
|
||||
if(args[index+1].match(/\S+:\d+/)) {
|
||||
redisUri = args[index+1];
|
||||
} else {
|
||||
logger.log("Wrong redis URI");
|
||||
process.exit(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -59,8 +60,8 @@ logger.log("Connecting redis: %s", redisUri);
|
|||
redis = Redis.createClient(redisUri.split(':')[1], redisUri.split(':')[0]) //new Redis(redisUri);
|
||||
|
||||
redis.on("error", function (err) {
|
||||
logger.log("Error redis %s", err);
|
||||
process.exit(-99);
|
||||
logger.log("Error redis %s", err);
|
||||
process.exit(-99);
|
||||
});
|
||||
|
||||
logger.log("Connecting mongodb: %s", mongoUri);
|
||||
|
@ -121,30 +122,35 @@ MongoClient.connect(mongoUri, function(err, db){
|
|||
var slog = log.split(':');
|
||||
var data = new Date(parseInt(slog[1]+"000"));
|
||||
// logger.log("Data: %s ", data, slog[1]);
|
||||
lastlogin.insert({
|
||||
user: user,
|
||||
protocol: slog[0],
|
||||
date: data,
|
||||
ip: slog[2],
|
||||
class: slog[2].split(".", 3).join("."),
|
||||
}, function(err, r){
|
||||
if( err ){
|
||||
console.log(err);
|
||||
if ( err.errmsg.indexOf("duplicate key error") >= 0 ) {
|
||||
logger.log("Duplicate key: %s - ", log, user, lindex);
|
||||
readLogs(lindex+1, user, len);
|
||||
}else {
|
||||
logger.log("insert error: %s", err);
|
||||
redis.rpush(user, log, function(err, result){
|
||||
quit();
|
||||
process.exit(-4);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
var classip = slog[2].split(".", 3).join(".")+".0;"
|
||||
whois(classip, function(err, data) {
|
||||
lastlogin.insert({
|
||||
user: user,
|
||||
protocol: slog[0],
|
||||
date: data,
|
||||
ip: slog[2],
|
||||
class: classip,
|
||||
orgname: orgname,
|
||||
netname: netname,
|
||||
}, function(err, r){
|
||||
if( err ){
|
||||
console.log(err);
|
||||
if ( err.errmsg.indexOf("duplicate key error") >= 0 ) {
|
||||
logger.log("Duplicate key: %s - ", log, user, lindex);
|
||||
readLogs(lindex+1, user, len);
|
||||
}else {
|
||||
logger.log("insert error: %s", err);
|
||||
redis.rpush(user, log, function(err, result){
|
||||
quit();
|
||||
process.exit(-4);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Salvato il log su mongo, legge il successivo.
|
||||
logger.log("Saved: %s - ", log, user, lindex);
|
||||
readLogs(lindex+1, user, len);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue