This repository was archived by the owner on Nov 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathserver.js
More file actions
141 lines (109 loc) · 3.96 KB
/
Copy pathserver.js
File metadata and controls
141 lines (109 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const express = require('express');
const fs = require('fs')
const PyShell = require('python-shell');
const cors = require('cors')
const path = require('path')
const serveStatic = require('serve-static');
const formidable = require('formidable')
let app = express();
app.use(serveStatic(__dirname + "/dist"));
app.use(express.json())
app.use(cors())
const port = process.env.PORT || 5000;
app.post('/dataset-analysis', async (req, res) => {
try{
res.setTimeout(10 * 60 * 1000, function(){
console.log('Request has timed out.');
res.send(408);
});
const tools = req.body.tools
const dataset = req.body.dataset
var options = {
args: ['--tool', tools, '--dataset', dataset]
};
let results = fs.readFileSync(__dirname + '/smartbugs/results.json');
let pyshell = new PyShell.PythonShell(__dirname + '/smartbugs/smartBugs.py', options);
console.log("Received Request: ", options.args);
pyshell.on('message', function(message) {
console.log("Received", message);
});
pyshell.end(async (err, code, signal) => {
if (err) throw err;
let results = await fs.readFileSync(__dirname + '/smartbugs/results.json');
res.send(results)
});
}catch(err){
res.status(400).json({ error: 'Something went wrong!' })
}
})
app.post('/input-file-analysis', async (req, res) => {
try{
res.setTimeout(10 * 60 * 1000, function(){
console.log('Request has timed out.');
res.send(408);
});
const tools = req.body.tools
const contract = req.body.file
await fs.writeFileSync(__dirname + '/smartbugs/toAnalyze/toAnalyze.sol', contract)
const options = {
args: ['--tool', ...tools, '--file', __dirname + '/smartbugs/toAnalyze/toAnalyze.sol']
};
let results = fs.readFileSync(__dirname + '/smartbugs/results.json');
let pyshell = new PyShell.PythonShell(__dirname + '/smartbugs/smartBugs.py', options);
console.log("Received Request: ", options.args);
pyshell.on('message', function(message) {
console.log("Received", message);
});
pyshell.end(async (err, code, signal) => {
if (err) throw err;
let results = await fs.readFileSync(__dirname + '/smartbugs/results.json');
res.send(results)
});
}catch(err){
res.status(400).json({ error: 'Something went wrong!' })
}
})
app.post('/imported-file-analysis', async (req, res) => {
try{
let tools
res.setTimeout(10 * 60 * 1000, function(){
console.log('Request has timed out.');
res.send(408);
});
const form = new formidable.IncomingForm();
form.parse(req);
form.on('fileBegin', function (name, file){
file.path = __dirname + '/smartbugs/toAnalyze/toAnalyze.sol';
});
form.on('field', function(name, value) {
if(name == 'tools') {
tools = value
}
});
form.on('file', async function (name, file){
console.log('Uploaded ' + file.name);
const options = {
args: ['--tool', ...tools.split(','), '--file', __dirname + '/smartbugs/toAnalyze/toAnalyze.sol']
};
let results = fs.readFileSync(__dirname + '/smartbugs/results.json');
let pyshell = new PyShell.PythonShell(__dirname + '/smartbugs/smartBugs.py', options);
console.log("Received Request: ", options.args);
pyshell.on('message', function(message) {
console.log("Received", message);
});
pyshell.end(async (err, code, signal) => {
if (err) throw err;
let results = await fs.readFileSync('smartbugs/results.json');
res.send(results)
});
});
}catch(err){
res.status(400).json({ error: 'Something went wrong!' })
}
})
app.listen(port, () => {
console.log('SmartBugs running at:' + '\n' +
'- Local: http://localhost:'+ port + '/' + '\n'
+ '- Network: http://192.168.1.120:' + port + '/' + '\n'
)
});