|
@ -4,7 +4,11 @@ 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 CONFIG = require(pathmodule.resolve(__dirname, "runconfig.js")); |
|
|
// var CONFIG = require(pathmodule.resolve(__dirname, "runconfig.js"));
|
|
|
|
|
|
const dotenv = require("dotenv"); |
|
|
|
|
|
const check123 = dotenv.config(); |
|
|
|
|
|
const { DATABASE, COLLECTION, URL, REDIS, REDIS_PORT, PORT } = process.env; |
|
|
|
|
|
|
|
|
const io = require("socket.io")(http, { |
|
|
const io = require("socket.io")(http, { |
|
|
// pingTimeout: 30000,
|
|
|
// pingTimeout: 30000,
|
|
|
// allowUpgrades: false,
|
|
|
// allowUpgrades: false,
|
|
@ -29,9 +33,10 @@ const createAdapter = require("socket.io-redis"); |
|
|
|
|
|
|
|
|
const Redis = require("ioredis"); |
|
|
const Redis = require("ioredis"); |
|
|
|
|
|
|
|
|
|
|
|
// console.log(REDIS, REDIS_PORT, DATABASE, COLLECTION, URL);
|
|
|
const pubClient = new Redis({ |
|
|
const pubClient = new Redis({ |
|
|
host: "redisserver", |
|
|
host: REDIS, |
|
|
port: 6379, |
|
|
port: REDIS_PORT, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
//const pubClient = new RedisClient({ host: 'localhost', port: 6379 });
|
|
|
//const pubClient = new RedisClient({ host: 'localhost', port: 6379 });
|
|
@ -98,15 +103,15 @@ const corsOptions = { |
|
|
// Lefos - get length of logs
|
|
|
// Lefos - get length of logs
|
|
|
app.get("/length", cors(corsOptions), (req, res) => { |
|
|
app.get("/length", cors(corsOptions), (req, res) => { |
|
|
console.error("getting length of logs"); |
|
|
console.error("getting length of logs"); |
|
|
var url = "mongodb://mongo:27017/"; |
|
|
var url = URL; |
|
|
MongoClient.connect( |
|
|
MongoClient.connect( |
|
|
url, |
|
|
url, |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
function (err, db) { |
|
|
function (err, db) { |
|
|
if (err) throw err; |
|
|
if (err) throw err; |
|
|
var dbo = db.db("fluentdb"); |
|
|
var dbo = db.db(DATABASE); |
|
|
dbo |
|
|
dbo |
|
|
.collection("test") |
|
|
.collection(COLLECTION) |
|
|
.find({}) |
|
|
.find({}) |
|
|
.toArray(function (err, result) { |
|
|
.toArray(function (err, result) { |
|
|
if (err) throw err; |
|
|
if (err) throw err; |
|
@ -211,16 +216,16 @@ function IsJsonString(str) { |
|
|
app.get("/services", cors(corsOptions), (req, res) => { |
|
|
app.get("/services", cors(corsOptions), (req, res) => { |
|
|
console.error("getting length of logs"); |
|
|
console.error("getting length of logs"); |
|
|
|
|
|
|
|
|
var url = "mongodb://mongo:27017/"; |
|
|
var url = URL; |
|
|
|
|
|
|
|
|
MongoClient.connect( |
|
|
MongoClient.connect( |
|
|
url, |
|
|
url, |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
function (err, db) { |
|
|
function (err, db) { |
|
|
if (err) throw err; |
|
|
if (err) throw err; |
|
|
var dbo = db.db("fluentdb"); |
|
|
var dbo = db.db(DATABASE); |
|
|
dbo |
|
|
dbo |
|
|
.collection("test") |
|
|
.collection(COLLECTION) |
|
|
.find({}) |
|
|
.find({}) |
|
|
.toArray(function (err, result) { |
|
|
.toArray(function (err, result) { |
|
|
if (err) throw err; |
|
|
if (err) throw err; |
|
@ -278,16 +283,16 @@ app.get("/services", cors(corsOptions), (req, res) => { |
|
|
app.get("/test", cors(corsOptions), (req, res) => { |
|
|
app.get("/test", cors(corsOptions), (req, res) => { |
|
|
console.log("reading from db...."); |
|
|
console.log("reading from db...."); |
|
|
|
|
|
|
|
|
var url = "mongodb://mongo:27017/"; |
|
|
var url = URL; |
|
|
|
|
|
|
|
|
MongoClient.connect( |
|
|
MongoClient.connect( |
|
|
url, |
|
|
url, |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
function (err, db) { |
|
|
function (err, db) { |
|
|
if (err) throw err; |
|
|
if (err) throw err; |
|
|
var dbo = db.db("fluentdb"); |
|
|
var dbo = db.db(DATABASE); |
|
|
dbo |
|
|
dbo |
|
|
.collection("test") |
|
|
.collection(COLLECTION) |
|
|
.find({}) |
|
|
.find({}) |
|
|
.toArray(function (err, result) { |
|
|
.toArray(function (err, result) { |
|
|
if (err) throw err; |
|
|
if (err) throw err; |
|
@ -323,16 +328,16 @@ app.get("/test", cors(corsOptions), (req, res) => { |
|
|
app.get("/raw", cors(corsOptions), (req, res) => { |
|
|
app.get("/raw", cors(corsOptions), (req, res) => { |
|
|
console.log("reading from db...."); |
|
|
console.log("reading from db...."); |
|
|
|
|
|
|
|
|
var url = "mongodb://mongo:27017/"; |
|
|
var url = URL; |
|
|
|
|
|
|
|
|
MongoClient.connect( |
|
|
MongoClient.connect( |
|
|
url, |
|
|
url, |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
function (err, db) { |
|
|
function (err, db) { |
|
|
if (err) throw err; |
|
|
if (err) throw err; |
|
|
var dbo = db.db("fluentdb"); |
|
|
var dbo = db.db(DATABASE); |
|
|
dbo |
|
|
dbo |
|
|
.collection("test") |
|
|
.collection(COLLECTION) |
|
|
.find({}) |
|
|
.find({}) |
|
|
.toArray(function (err, result) { |
|
|
.toArray(function (err, result) { |
|
|
if (err) throw err; |
|
|
if (err) throw err; |
|
@ -373,16 +378,16 @@ app.get("/test2", cors(corsOptions), (req, res) => { |
|
|
console.error("EXTRA PARAMS: " + logtext); |
|
|
console.error("EXTRA PARAMS: " + logtext); |
|
|
//console.log("TEST LOG");
|
|
|
//console.log("TEST LOG");
|
|
|
|
|
|
|
|
|
var url = "mongodb://mongo:27017/"; |
|
|
var url = URL; |
|
|
var jsonfinal = []; |
|
|
var jsonfinal = []; |
|
|
MongoClient.connect( |
|
|
MongoClient.connect( |
|
|
url, |
|
|
url, |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
function (err, db) { |
|
|
function (err, db) { |
|
|
if (err) throw err; |
|
|
if (err) throw err; |
|
|
var dbo = db.db("fluentdb"); |
|
|
var dbo = db.db(DATABASE); |
|
|
dbo |
|
|
dbo |
|
|
.collection("test") |
|
|
.collection(COLLECTION) |
|
|
.find({}) |
|
|
.find({}) |
|
|
.toArray(function (err, result) { |
|
|
.toArray(function (err, result) { |
|
|
if (err) throw err; |
|
|
if (err) throw err; |
|
@ -768,194 +773,6 @@ function convertDateToUTC(date) { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// ***************************************************
|
|
|
|
|
|
// get pipelines
|
|
|
|
|
|
// ***************************************************
|
|
|
|
|
|
|
|
|
|
|
|
async function getpipelines(token, pipelinename) { |
|
|
|
|
|
const agent = new https.Agent({ |
|
|
|
|
|
rejectUnauthorized: false, |
|
|
|
|
|
}); |
|
|
|
|
|
const instance = axios.create({ |
|
|
|
|
|
baseURL: "https://api.swarmlab.io", |
|
|
|
|
|
withCredentials: true, |
|
|
|
|
|
rejectUnauthorized: false, |
|
|
|
|
|
crossdomain: true, |
|
|
|
|
|
httpsAgent: agent, |
|
|
|
|
|
headers: { |
|
|
|
|
|
Accept: "application/json", |
|
|
|
|
|
"Content-Type": "multipart/form-data", |
|
|
|
|
|
Authorization: "Bearer " + token, |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
/* |
|
|
|
|
|
var params = { |
|
|
|
|
|
playbook: value |
|
|
|
|
|
} |
|
|
|
|
|
var options = { |
|
|
|
|
|
params: params, |
|
|
|
|
|
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const playbook = await api.GET('playbookCode',options); |
|
|
|
|
|
return playbook |
|
|
|
|
|
*/ |
|
|
|
|
|
try { |
|
|
|
|
|
var pipelines = { |
|
|
|
|
|
querytokenFilter: CONFIG.api.token, |
|
|
|
|
|
filter: pipelinename, |
|
|
|
|
|
}; |
|
|
|
|
|
//var params = {
|
|
|
|
|
|
// pipeline: pipelines
|
|
|
|
|
|
// }
|
|
|
|
|
|
var params = { |
|
|
|
|
|
querytokenFilter: CONFIG.api.token, |
|
|
|
|
|
filter: pipelinename, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var options = { |
|
|
|
|
|
params: params, |
|
|
|
|
|
headers: { |
|
|
|
|
|
"content-type": "application/x-www-form-urlencoded", |
|
|
|
|
|
Authorization: `Bearer ${token}`, |
|
|
|
|
|
}, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
//https://api.swarmlab.io/gettutorlabrooms?sort=pipelinename%7Casc&page=1&per_page=5&filter=&type=scripts&tutor=yes
|
|
|
|
|
|
instance.defaults.timeout = 30000; |
|
|
|
|
|
//const res = await instance.get('/getplaygrounds',params,options);
|
|
|
|
|
|
const res = await instance.get("/getplaygrounds", options); |
|
|
|
|
|
if (res.status == 200) { |
|
|
|
|
|
return res.data; |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log("noerror: " + res); |
|
|
|
|
|
return await res.status; |
|
|
|
|
|
} |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
console.error("error: " + err); |
|
|
|
|
|
var error = new Object(); |
|
|
|
|
|
error.action = "401"; |
|
|
|
|
|
return await error; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************
|
|
|
|
|
|
// get user pipelines
|
|
|
|
|
|
// ***************************************************
|
|
|
|
|
|
|
|
|
|
|
|
async function getuserpipelines(token, user, swarmlabname) { |
|
|
|
|
|
var pipelinename = user; |
|
|
|
|
|
const agent = new https.Agent({ |
|
|
|
|
|
rejectUnauthorized: false, |
|
|
|
|
|
}); |
|
|
|
|
|
const instance = axios.create({ |
|
|
|
|
|
baseURL: "https://api.swarmlab.io", |
|
|
|
|
|
withCredentials: true, |
|
|
|
|
|
rejectUnauthorized: false, |
|
|
|
|
|
crossdomain: true, |
|
|
|
|
|
httpsAgent: agent, |
|
|
|
|
|
headers: { |
|
|
|
|
|
Accept: "application/json", |
|
|
|
|
|
"Content-Type": "multipart/form-data", |
|
|
|
|
|
Authorization: "Bearer " + token, |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
try { |
|
|
|
|
|
var pipelines = { |
|
|
|
|
|
querytokenFilter: CONFIG.api.token, |
|
|
|
|
|
filter: pipelinename, |
|
|
|
|
|
swarmlabname: swarmlabname, |
|
|
|
|
|
}; |
|
|
|
|
|
//var params = {
|
|
|
|
|
|
// pipeline: pipelines
|
|
|
|
|
|
// }
|
|
|
|
|
|
var params = { |
|
|
|
|
|
querytokenFilter: CONFIG.api.token, |
|
|
|
|
|
filter: pipelinename, |
|
|
|
|
|
swarmlabname: swarmlabname, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var options = { |
|
|
|
|
|
params: params, |
|
|
|
|
|
headers: { |
|
|
|
|
|
"content-type": "application/x-www-form-urlencoded", |
|
|
|
|
|
Authorization: `Bearer ${token}`, |
|
|
|
|
|
}, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
instance.defaults.timeout = 30000; |
|
|
|
|
|
const res = await instance.get("/getuserplaygrounds", options); |
|
|
|
|
|
if (res.status == 200) { |
|
|
|
|
|
return res.data; |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log("noerror: " + res); |
|
|
|
|
|
return await res.status; |
|
|
|
|
|
} |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
console.error("error: " + err); |
|
|
|
|
|
var error = new Object(); |
|
|
|
|
|
error.action = "401"; |
|
|
|
|
|
error.error = err; |
|
|
|
|
|
return await error; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
global.online = "ob"; |
|
|
|
|
|
global.pipelines = []; |
|
|
|
|
|
|
|
|
|
|
|
function sendlog(reslog, pathfileval) { |
|
|
|
|
|
var usertmp = global.pipelines.find((x) => x.pathlogfile == pathfileval); |
|
|
|
|
|
//for (var key in usertmp.data){
|
|
|
|
|
|
var user = usertmp.data[0].user25user; |
|
|
|
|
|
// if(usertmp.data){
|
|
|
|
|
|
console.log("-----------------------" + JSON.stringify(usertmp)); |
|
|
|
|
|
io.in(user).emit("logdata", reslog); |
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// function onlogfile(path) {
|
|
|
|
|
|
// console.log("File", path, "has been added");
|
|
|
|
|
|
// var pathfileval = pathmodule.basename(path);
|
|
|
|
|
|
// var arrfile = pathfileval.toString().split("-");
|
|
|
|
|
|
// var pathfile = arrfile[0];
|
|
|
|
|
|
// var indexfind1 = global.pipelines.findIndex(
|
|
|
|
|
|
// (x) => x.pathlogfile == pathfileval
|
|
|
|
|
|
// );
|
|
|
|
|
|
// console.log(
|
|
|
|
|
|
// "file11111111111111111111111111111111 " + JSON.stringify(pathfileval)
|
|
|
|
|
|
// );
|
|
|
|
|
|
// if (indexfind1 === -1) {
|
|
|
|
|
|
// (async () => {
|
|
|
|
|
|
// console.log(
|
|
|
|
|
|
// "file2222222222222222222222222222222222222 " +
|
|
|
|
|
|
// JSON.stringify(pathfileval)
|
|
|
|
|
|
// );
|
|
|
|
|
|
// var token = "d2539e5a7ae1f9f1b0eb2b8f22ca467a86d28407"; // desto
|
|
|
|
|
|
// var resdata = await getpipelines(token, pathfile);
|
|
|
|
|
|
// //resdata.data.pathlogfile = 'test'
|
|
|
|
|
|
// var resob = {};
|
|
|
|
|
|
// resob.pathlogfile = pathfileval;
|
|
|
|
|
|
// var resobarray = [];
|
|
|
|
|
|
// for (let i in resdata.data) {
|
|
|
|
|
|
// var resob1 = {};
|
|
|
|
|
|
// resob1.data = resdata.data[i].res25swarmlabname;
|
|
|
|
|
|
// resob1.user25user = resdata.data[i].res25user;
|
|
|
|
|
|
// resob1.res25creator = resdata.data[i].res25creator;
|
|
|
|
|
|
// resob1.res25fileforce = resdata.data[i].res25fileforce;
|
|
|
|
|
|
// resobarray.push(resob1);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// resob.data = resobarray;
|
|
|
|
|
|
// var indexfind = global.pipelines.findIndex(
|
|
|
|
|
|
// (x) => x.pathlogfile == pathfileval
|
|
|
|
|
|
// );
|
|
|
|
|
|
// indexfind === -1
|
|
|
|
|
|
// ? global.pipelines.push(resob)
|
|
|
|
|
|
// : console.log("object already exists " + pathfileval);
|
|
|
|
|
|
// })();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// Έλεγχος αν υπάρχει ήδη ενεργό stream με τη βάση δεδομένων για κάποιον
|
|
|
// Έλεγχος αν υπάρχει ήδη ενεργό stream με τη βάση δεδομένων για κάποιον
|
|
|
async function checkstream(data) { |
|
|
async function checkstream(data) { |
|
|
var res = await getkey(data.id); |
|
|
var res = await getkey(data.id); |
|
@ -964,55 +781,19 @@ async function checkstream(data) { |
|
|
} else { |
|
|
} else { |
|
|
console.log("Creating Stream...."); |
|
|
console.log("Creating Stream...."); |
|
|
|
|
|
|
|
|
var url = "mongodb://mongo:27017/"; |
|
|
var url = URL; |
|
|
MongoClient.connect( |
|
|
MongoClient.connect( |
|
|
url, |
|
|
url, |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
function (err, db) { |
|
|
function (err, db) { |
|
|
if (err) throw err; |
|
|
if (err) throw err; |
|
|
var dbo = db.db("fluentdb"); |
|
|
var dbo = db.db(DATABASE); |
|
|
dbo.collection("test", onCollectionNew.bind(data)); |
|
|
dbo.collection(COLLECTION, onCollectionNew.bind(data)); |
|
|
} |
|
|
} |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function sleep(ms) { |
|
|
|
|
|
return new Promise((resolve) => setTimeout(resolve, ms)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// δεν την χρησιμοποιώ κάπου
|
|
|
|
|
|
function getSHA256ofJSON(data, inputEncoding, encoding) { |
|
|
|
|
|
if (!data) { |
|
|
|
|
|
return ""; |
|
|
|
|
|
} |
|
|
|
|
|
inputEncoding = inputEncoding || "utf-8"; |
|
|
|
|
|
encoding = encoding || "hex"; |
|
|
|
|
|
const hash = require("crypto").createHash("md5"); |
|
|
|
|
|
return hash.update(JSON.stringify(data), inputEncoding).digest(encoding); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// async function getUser(token) {
|
|
|
|
|
|
// return new Promise((resolve) => {
|
|
|
|
|
|
// pubClient.get(token, function (err, reply) {
|
|
|
|
|
|
// if (err) {
|
|
|
|
|
|
// console.log("----------error------------");
|
|
|
|
|
|
|
|
|
|
|
|
// resolve(null);
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// if (reply) {
|
|
|
|
|
|
// console.log("---------found----------");
|
|
|
|
|
|
// resolve(1);
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// console.log("----------not found------------");
|
|
|
|
|
|
// resolve(2);
|
|
|
|
|
|
// //return 2
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// Διαδικασία ελέγχου στοιχείων στο redis για την εξακρίβωση ύπαρξης stream με τη βάση
|
|
|
// Διαδικασία ελέγχου στοιχείων στο redis για την εξακρίβωση ύπαρξης stream με τη βάση
|
|
|
async function getkey(id) { |
|
|
async function getkey(id) { |
|
|
return new Promise((resolve) => { |
|
|
return new Promise((resolve) => { |
|
|