|
|
@ -2,9 +2,16 @@ var path = require('path'); |
|
|
|
var app = require('express')(); |
|
|
|
var http = require('http').Server(app); |
|
|
|
var io = require('socket.io')(http); |
|
|
|
//var MongoClient = require('mongodb').MongoClient;
|
|
|
|
|
|
|
|
//const socketAuth = require('socketio-auth');
|
|
|
|
var async = require("async"); |
|
|
|
const { check, validationResult } = require('express-validator'); |
|
|
|
const urlExistSync = require("url-exist-sync"); |
|
|
|
|
|
|
|
var express = require('express'); |
|
|
|
app.use(express.json()); |
|
|
|
|
|
|
|
const helmet = require('helmet'); |
|
|
|
app.use(helmet()); |
|
|
|
|
|
|
|
const cors = require('cors') |
|
|
|
const whitelist = [ |
|
|
@ -57,56 +64,34 @@ app.post('/run', [ |
|
|
|
//check('llo').isBase64()
|
|
|
|
], |
|
|
|
cors(corsOptions), (req, res, next) => { |
|
|
|
console.error('socket POST from client'); |
|
|
|
var RES = new Object(); |
|
|
|
RES.error = false |
|
|
|
RES.error_msg = "ok" |
|
|
|
res.json(RES) |
|
|
|
}); |
|
|
|
|
|
|
|
// ------------------------------------------------
|
|
|
|
/* |
|
|
|
var mongouser = "playgrounduser"; |
|
|
|
var mongopass = "efvvnuioervefSDFSGYGHRDFVsdfergvssppiiedifhwincvinviw_dbfjbsifbsdkjfswuunscfudfgbbfvibqefwrvnine"; |
|
|
|
const mongourl = 'mongodb://'+mongouser+':'+mongopass+'@node1:27017/?replicaSet=rs0'; |
|
|
|
const dbNameedit = 'swarmlab_playground_logs'; |
|
|
|
|
|
|
|
var mongooption = { |
|
|
|
server: { |
|
|
|
reconnectTries: Number.MAX_VALUE, |
|
|
|
reconnectInterval: 1000 |
|
|
|
//console.log(JSON.stringify(req.headers));
|
|
|
|
//console.log(JSON.stringify(req.body));
|
|
|
|
console.log("mongo "+JSON.stringify(req.body)); |
|
|
|
console.log("LOG "+JSON.stringify(req.body[0].message)); |
|
|
|
console.log("PATH "+JSON.stringify(req.body[0].tailed_path)); |
|
|
|
for (var i = 0; i < req.body.length; i++){ |
|
|
|
var obj = req.body[i]; |
|
|
|
var reslog = new Object(); |
|
|
|
for (var key in obj){ |
|
|
|
var value = obj[key]; |
|
|
|
//console.log("line " + key + ": " + value);
|
|
|
|
reslog.key = key |
|
|
|
reslog.value = value |
|
|
|
io.emit("logdata", reslog); |
|
|
|
} |
|
|
|
} |
|
|
|
// Create a new MongoClient
|
|
|
|
|
|
|
|
const client = new MongoClient(mongourl, mongooption); |
|
|
|
|
|
|
|
var dbName; |
|
|
|
|
|
|
|
function findDocuments(db, callback) { |
|
|
|
const collection = db.collection( 'devel_log' ); |
|
|
|
collection.find().toArray(function(err, docs) { |
|
|
|
console.log("Found the following records"); |
|
|
|
console.log(docs) |
|
|
|
callback(docs); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
//io.in("iot").emit("message", RES);
|
|
|
|
|
|
|
|
console.error('socket POST from client'); |
|
|
|
var RES = new Object(); |
|
|
|
RES.error = false |
|
|
|
RES.error_msg = "ok" |
|
|
|
RES.msg = req.body[0].messsage |
|
|
|
|
|
|
|
// Use connect method to connect to the Server
|
|
|
|
client.connect(function(err) { |
|
|
|
console.log("Connected correctly to server"); |
|
|
|
dbName = client.db(dbNameedit); |
|
|
|
findDocuments(dbName, function() { |
|
|
|
//client.close();
|
|
|
|
}); |
|
|
|
res.json(RES) |
|
|
|
}); |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
io.origins('*:*') // for latest version
|
|
|
|
|
|
|
|