-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
72 lines (64 loc) · 1.76 KB
/
server.js
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
'use strict';
const express = require('express');
const {exec} = require('child_process');
const { execSync } = require('child_process');
exec("sudo perf record -e cache-references,cache-misses -a");
const MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017";
// Constants
const PORT = 8081;
const HOST = '0.0.0.0';
// App
const app = express();
app.get('/', (req, res) => {
res.send('Hello world\n');
});
const bodyparser = require('body-parser');
app.use( bodyparser.json());
app.use(bodyparser.urlencoded({
extended:true
}));
app.post("/login",(req,res) => {
MongoClient.connect(url, function(err,client) {
if (err) throw err;
var db = client.db("mydb");
console.log("inserting values");
console.log(req.body.username);
db.collection('Example').find({
username :req.body.username,
passwd: req.body.passwd
}, function(err,res){
if (err) throw err;
console.log("OK");
client.close();
});
});
res.status(200).send("OK");
});
app.post("/formsubmit",(req,res) => {
MongoClient.connect(url, function(err, client) {
if (err) throw err;
var name=req.body.cardname;
var cardno=req.body.cardno;
var cardexpiry=req.body.expiry;
var cardcvv=req.body.cvv;
var db = client.db("mydb");
console.log("verifying");
db.collection('Example').find({name:name,cardno:cardno,cardexpiry:cardexpiry, cardcvv:cardcvv}, function(err,res){
if (err) throw err;
console.log("qeury successful");
client.close();
});
});
var img;
var child = execSync("sudo sh ./closegen.sh",{
cwd: process.cwd(),
env: process.env,
stdio: 'pipe',
encoding: 'utf-8'});
img = child;
exec("sudo sh ./autogen.sh");
res.status(200).send(JSON.stringify({'img': img}));
});
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);