Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

driverab #113

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 75 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"ckeditor": "4.7.3",
"classlist.js": "1.1.20150312",
"core-js": "2.5.1",
"download-file": "^0.1.5",
"echarts": "^4.1.0",
"elasticsearch": "^15.1.1",
"express": "^4.16.3",
Expand Down Expand Up @@ -98,8 +99,11 @@
"simple-oauth2": "^1.6.0",
"socicon": "3.0.5",
"socket.io": "^2.1.1",
"string-similarity": "^2.0.0",
"text-diff": "^1.0.1",
"tinymce": "4.5.7",
"typeface-exo": "0.0.22",
"uniqid": "^5.0.3",
"web-animations-js": "2.2.5",
"zone.js": "^0.8.26"
},
Expand Down
96 changes: 96 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');

var fs = require('fs');
// Uniqid module. Generates random id
var uniqid = require('uniqid');
// Download-file module
var download = require('download-file');
// Request method
var request = require('request');
// Load configuration
Expand Down Expand Up @@ -70,11 +75,102 @@ app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});

//Files Management
var oldFile;
//Download config file from remote to node
app.get('/download', (req, res) => {
var url = req.query.url;
var options = {
directory: "./downloads",
filename: uniqid(req.query.instance + '&')
}
download(url, options, function(err) {
if(err) throw err
})
oldFile = options.filename;
res.send(options.filename);
});

//Download config file from node to the frontend
app.get('/download/:file', (req, res) => {
console.log("?downloads/file");
var path = __dirname + '/downloads/' + req.params.file;
res.download(path);
});

//Download log file from remote to frontend
app.get('/download/log-file', (req, res) => {
request(req.query.url).pipe(res)
res.set('Content-Type', 'text/plain');
});

app.post('/validate', (req, res) => {
var savedFile = fs.readFileSync(__dirname + '/downloads/' + oldFile, 'utf-8');
var newFile = req.body.newFile;
savedFile = JSON.stringify(savedFile);
savedFile = JSON.parse(savedFile);

function convertToHash(file){
var hash = {};
var lines = file.split("\n"); //split file by lines
lines.forEach(function(line) {
line = line.replace(/ /g,''); //removing whitespaces
if(!line.match(/^#/) && !line.match(/^\[/) && line != ''){ //Avoid lines that begin with # , [ and empty lines
if(line.match("#")){
line = line.split("#"); //splitting lines that contain #
line = line[0]; //getting the left string of the split
}
if(line.match(/.*=.*/)){ //pushing into the list the lines that are not empty
var split = line.split("=");
hash[split[0]] = split[1];
} else {
hash[line] = 'on';
}
}
});
return hash;
}

var old_config = convertToHash(savedFile);
var new_config = convertToHash(newFile);

function compareHash(parameters, old_config, new_config){
var list = [];
Object.keys(new_config).forEach(function(key){
var properties = {
name: '',
value: ''
};
console.log("comparing property: " + key + " new value: " + new_config[key] + " old value: " + old_config[key]);
var line = key + '=' + new_config[key];
if(parameters[key] && (new_config[key] != old_config[key])){
properties.name = line;
properties.value = false;
list.push(properties);
} else {
properties.name = line;
properties.value = true;
list.push(properties);
}
});
console.log(list);
return list;
}
/*function compareHash(parameters, old_config, new_config){
var list = {};
Object.keys(new_config).forEach(function(key){
console.log("comparing property: " + key + " new value: " + new_config[key] + " old value: " + old_config[key]);
var line = key + '=' + new_config[key];
if(parameters[key] && (new_config[key] != old_config[key])){
list[line] = false;
} else list[line] = true;
});
return list;
}*/
var comp = compareHash(config.parameters, old_config, new_config);
res.send(comp);
});

app.get('/logout', (req, res) => {
console.log('Destroying session SID: ' + req.session.id);
req.session.destroy((error) => {
Expand Down
Loading