|
@ -4,7 +4,27 @@ var pathmodule = require('path'); |
|
|
var app = require('express')(); |
|
|
var app = require('express')(); |
|
|
var http = require('http').Server(app); |
|
|
var http = require('http').Server(app); |
|
|
var https = require('https'); |
|
|
var https = require('https'); |
|
|
var io = require('socket.io')(http); |
|
|
const io = require("socket.io")(http, { |
|
|
|
|
|
// pingTimeout: 30000,
|
|
|
|
|
|
// allowUpgrades: false,
|
|
|
|
|
|
// serveClient: false,
|
|
|
|
|
|
// pingInterval: 10000,
|
|
|
|
|
|
// //transports: [ 'websocket', 'polling' ],
|
|
|
|
|
|
// transports: [ 'polling', 'websocket' ],
|
|
|
|
|
|
cors: { |
|
|
|
|
|
origin: "http://localhost:8080", |
|
|
|
|
|
methods: ["GET", "POST"], |
|
|
|
|
|
allowedHeaders: ["my-custom-header"], |
|
|
|
|
|
credentials: true |
|
|
|
|
|
}, |
|
|
|
|
|
cookie: { |
|
|
|
|
|
name: "test", |
|
|
|
|
|
httpOnly: false, |
|
|
|
|
|
path: "/custom" |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//import { createAdapter } from 'socket.io-redis';
|
|
|
//import { createAdapter } from 'socket.io-redis';
|
|
|
const createAdapter = require('socket.io-redis'); |
|
|
const createAdapter = require('socket.io-redis'); |
|
@ -20,6 +40,7 @@ const subClient = pubClient.duplicate(); |
|
|
|
|
|
|
|
|
io.adapter(createAdapter({ pubClient, subClient })); |
|
|
io.adapter(createAdapter({ pubClient, subClient })); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pubClient.on("connect", function() { |
|
|
pubClient.on("connect", function() { |
|
|
console.log("You are now connected"); |
|
|
console.log("You are now connected"); |
|
|
}); |
|
|
}); |
|
@ -393,7 +414,6 @@ cors(corsOptions), (req, res, next) => { |
|
|
// socket
|
|
|
// socket
|
|
|
// ***************************************************
|
|
|
// ***************************************************
|
|
|
|
|
|
|
|
|
io.origins('*:*') // for latest version
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function onCollection(err, collection) { |
|
|
function onCollection(err, collection) { |
|
@ -408,78 +428,87 @@ function onCollection(err, collection) { |
|
|
var reslog = new Object(); |
|
|
var reslog = new Object(); |
|
|
var now = new Date(); |
|
|
var now = new Date(); |
|
|
cursor.on('data', function (data) { |
|
|
cursor.on('data', function (data) { |
|
|
console.log('+++++++++ondata<<<<<<<<<<<<<<<<<<<<<<' + data); |
|
|
//io.in('anagnostopoulos@uniwa.gr').emit("logdata", data);
|
|
|
io.in('anagnostopoulos@uniwa.gr').emit("logdata", data); |
|
|
|
|
|
|
|
|
|
|
|
var pathfileval = pathmodule.basename(data.tailed_path); |
|
|
console.log('++++++++' + JSON.stringify(data)); |
|
|
var arrfile = pathfileval.toString().split("-"); |
|
|
|
|
|
var pathfile = arrfile[0]; |
|
|
|
|
|
|
|
|
|
|
|
var indexupdate = true |
|
|
var pathfileval = pathmodule.basename(data.tailed_path); |
|
|
var resob = {} |
|
|
var arrfile = pathfileval.toString().split("-"); |
|
|
//var indexfind1 = global.pipelines.findIndex(x => x.pathlogfile==pathfileval);
|
|
|
var pathfile = arrfile[0]; |
|
|
|
|
|
|
|
|
|
|
|
var indexupdate = "yes" |
|
|
|
|
|
var resob = {} |
|
|
|
|
|
//var indexfind1 = global.pipelines.findIndex(x => x.pathlogfile==pathfileval);
|
|
|
pubClient.get(pathfileval, function(err, object) { |
|
|
pubClient.get(pathfileval, function(err, object) { |
|
|
if(object){ |
|
|
console.log('----------------' + err + '<<<<<<<<<<<<<<<<<<<<<<' + object); |
|
|
indexupdate = false |
|
|
if(object){ |
|
|
}else{ |
|
|
indexupdate = "no" |
|
|
console.log('redis '+JSON.stringify(object)); |
|
|
}else{ |
|
|
} |
|
|
console.log('redis '+JSON.stringify(object)); |
|
|
}); |
|
|
} |
|
|
if (indexupdate ){ |
|
|
console.log('update '+JSON.stringify(indexupdate)); |
|
|
(async() => { |
|
|
if (indexupdate == "yes" ){ |
|
|
var token = "d2539e5a7ae1f9f1b0eb2b8f22ca467a86d28407"; // desto
|
|
|
(async() => { |
|
|
var resdata = await getpipelines(token,pathfile) |
|
|
var token = "d2539e5a7ae1f9f1b0eb2b8f22ca467a86d28407"; // desto
|
|
|
resob.pathlogfile = pathfileval |
|
|
var resdata = await getpipelines(token,pathfile) |
|
|
var resobarray = [] |
|
|
resob.pathlogfile = pathfileval |
|
|
var resob1 = {} |
|
|
var resobarray = [] |
|
|
var i = 0 |
|
|
var resob1 = {} |
|
|
resob1.data = resdata.data[i].res25swarmlabname |
|
|
var i = 0 |
|
|
resob1.user25user = resdata.data[i].res25user |
|
|
resob1.data = resdata.data[i].res25swarmlabname |
|
|
resob1.res25creator = resdata.data[i].res25creator |
|
|
resob1.user25user = resdata.data[i].res25user |
|
|
resob1.res25fileforce = resdata.data[i].res25fileforce |
|
|
resob1.res25creator = resdata.data[i].res25creator |
|
|
resob1.tailed_path = pathfileval |
|
|
resob1.res25fileforce = resdata.data[i].res25fileforce |
|
|
//resobarray.push(resob1)
|
|
|
resob1.tailed_path = pathfileval |
|
|
var resob1string = JSON.stringify(resob1); |
|
|
var resob1string = JSON.stringify(resob1); |
|
|
console.log('+++++++++++++++++' + resob1string + '<<<<<<<<<<<<<<<<<<<<<<' + pathfileval); |
|
|
pubClient.set(pathfileval, resob1string, function(err, res) { |
|
|
pubClient.set(pathfileval, resob1string, function(err, res) { |
|
|
}); |
|
|
}); |
|
|
reslog.data = resob1 |
|
|
reslog.data = resob1 |
|
|
reslog.log = data |
|
|
reslog.log = data |
|
|
reslog.date = convertDateToUTC(now) |
|
|
reslog.date = convertDateToUTC(now) |
|
|
var user = resob1.res25creator |
|
|
var user = resob1.res25creator |
|
|
console.log('datauser ' + JSON.stringify(user)); |
|
|
console.log('datauser ' + JSON.stringify(user)); |
|
|
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>> '+JSON.stringify(reslog)); |
|
|
//io.in(user).emit("logdata", reslog);
|
|
|
io.in(user).emit("logdata", reslog); |
|
|
var user = 'anagnostopoulos@uniwa.gr' |
|
|
itemsProcessed++; |
|
|
io.in(user).emit("logdata", reslog); |
|
|
})() |
|
|
itemsProcessed++; |
|
|
}else{ |
|
|
})() |
|
|
|
|
|
}else{ |
|
|
pubClient.get(pathfileval, function(err, object) { |
|
|
|
|
|
var objecttmp = JSON.parse(object); |
|
|
|
|
|
var resob1 = {} |
|
|
|
|
|
resob1.data = objecttmp.res25swarmlabname |
|
|
|
|
|
resob1.user25user = objecttmp.res25user |
|
|
|
|
|
resob1.res25creator = objecttmp.res25creator |
|
|
|
|
|
resob1.res25fileforce = objecttmp.res25fileforce |
|
|
|
|
|
resob1.tailed_path = objecttmp.tailed_path |
|
|
|
|
|
|
|
|
|
|
|
reslog.data = resob1 |
|
|
|
|
|
reslog.log = data |
|
|
|
|
|
reslog.date = convertDateToUTC(now) |
|
|
|
|
|
|
|
|
|
|
|
console.log('<<<<<<<<<<<---------------------<<<<<<<<<<<<<<<---------------------------<<<<<<<<<<<< '+JSON.stringify(object)); |
|
|
|
|
|
console.log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< '+JSON.stringify(reslog)); |
|
|
|
|
|
var user = objecttmp.user25user |
|
|
|
|
|
//io.join(user);
|
|
|
|
|
|
//io.to(user).emit(reslog);
|
|
|
|
|
|
|
|
|
|
|
|
//console.log("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRr", JSON.stringify(io.sockets.adapter.rooms)); // Set { <socket.id> }
|
|
|
|
|
|
|
|
|
|
|
|
io.in(user).emit("logdata", reslog); |
|
|
|
|
|
itemsProcessed++; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
pubClient.get(pathfileval, function(err, object) { |
|
|
|
|
|
var resob1 = {} |
|
|
|
|
|
var i = 0 |
|
|
|
|
|
resob1.data = object.res25swarmlabname |
|
|
|
|
|
resob1.user25user = object.res25user |
|
|
|
|
|
resob1.res25creator = object.res25creator |
|
|
|
|
|
resob1.res25fileforce = object.res25fileforce |
|
|
|
|
|
resob1.tailed_path = object.tailed_path |
|
|
|
|
|
|
|
|
|
|
|
reslog.data = resob1 |
|
|
|
|
|
reslog.log = data |
|
|
|
|
|
reslog.date = convertDateToUTC(now) |
|
|
|
|
|
|
|
|
|
|
|
console.log('>>>>>>>>>>2222222222222>>>>>>>>>>>>>>>>>>>>>>>>>>>>> '+JSON.stringify(object)); |
|
|
|
|
|
var user = object.user25user |
|
|
|
|
|
io.in(user).emit("logdata", reslog); |
|
|
|
|
|
itemsProcessed++; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setInterval(function () { |
|
|
setInterval(function () { |
|
|
console.log('itemsProcessed', itemsProcessed); |
|
|
console.log('itemsProcessed', itemsProcessed); |
|
|
}, 1000); |
|
|
// this method is also exposed by the Server instance
|
|
|
|
|
|
//console.log(adapter.rooms);
|
|
|
|
|
|
}, 8000); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -506,6 +535,11 @@ function onCollection(err, collection) { |
|
|
io.on('connection', s => { |
|
|
io.on('connection', s => { |
|
|
console.error('socket connection'); |
|
|
console.error('socket connection'); |
|
|
|
|
|
|
|
|
|
|
|
//s.set('transports', ['websocket']);
|
|
|
|
|
|
//s.set('pingTimeout', 30000);
|
|
|
|
|
|
//s.set('allowUpgrades', false);
|
|
|
|
|
|
//s.set('serveClient', false);
|
|
|
|
|
|
//s.set('pingInterval', 10000);
|
|
|
// ------------------------------
|
|
|
// ------------------------------
|
|
|
// --- set
|
|
|
// --- set
|
|
|
// ------------------------------
|
|
|
// ------------------------------
|
|
@ -515,6 +549,8 @@ io.on('connection', s => { |
|
|
console.error('socket ...'); |
|
|
console.error('socket ...'); |
|
|
s.auth = false; |
|
|
s.auth = false; |
|
|
|
|
|
|
|
|
|
|
|
s.join('test'); |
|
|
|
|
|
console.log('test' + ' created ') |
|
|
// ------------------------------
|
|
|
// ------------------------------
|
|
|
// --- authenticate
|
|
|
// --- authenticate
|
|
|
// ------------------------------
|
|
|
// ------------------------------
|
|
@ -525,6 +561,8 @@ io.on('connection', s => { |
|
|
var isvalid = await checkToken(token); |
|
|
var isvalid = await checkToken(token); |
|
|
if(isvalid.action == 'ok'){ |
|
|
if(isvalid.action == 'ok'){ |
|
|
console.log("Authserver ok ", s.id + ' - ' + token); |
|
|
console.log("Authserver ok ", s.id + ' - ' + token); |
|
|
|
|
|
// pubClient.set(session, resob1string, function(err, res) {
|
|
|
|
|
|
// });
|
|
|
usersession.SOCKET.user = isvalid.user |
|
|
usersession.SOCKET.user = isvalid.user |
|
|
usersession.SOCKET.scope = isvalid.scope // space delimeter
|
|
|
usersession.SOCKET.scope = isvalid.scope // space delimeter
|
|
|
usersession.SOCKET.token = isvalid.token |
|
|
usersession.SOCKET.token = isvalid.token |
|
@ -539,12 +577,13 @@ io.on('connection', s => { |
|
|
setTimeout(function(){ |
|
|
setTimeout(function(){ |
|
|
if (!s.auth) { |
|
|
if (!s.auth) { |
|
|
console.log("Disconnecting timeout socket ", s.id); |
|
|
console.log("Disconnecting timeout socket ", s.id); |
|
|
s.disconnect('unauthorized'); |
|
|
//s.disconnect('unauthorized');
|
|
|
}else{ |
|
|
}else{ |
|
|
var room = usersession.SOCKET.user |
|
|
var room = usersession.SOCKET.user |
|
|
//s.on("subscribe", function (room) {
|
|
|
//s.on("subscribe", function (room) {
|
|
|
// console.log("joining room", room);
|
|
|
|
|
|
s.join(room); |
|
|
s.join(room); |
|
|
|
|
|
console.log("joining rooom", s.rooms); |
|
|
|
|
|
console.log(room + ' created ') |
|
|
// });
|
|
|
// });
|
|
|
} |
|
|
} |
|
|
}, 30000); |
|
|
}, 30000); |
|
|