-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
73 lines (65 loc) · 1.91 KB
/
main.js
File metadata and controls
73 lines (65 loc) · 1.91 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
const express = require("express");
const app = express();
const fs = require("fs");
const { exec } = require("child_process");
const { log } = require("console");
const port = 6969;
app.use(express.json()); // to get the data in json format
app.use(express.urlencoded({ extended: true })); // to get the form data
app.set("view engine", "ejs");
app.use(express.static("public")); // to view static files
let ip = ""
app.get("/", (req, res) => {
res.status(200).render("start");
})
app.post("/ip", (req,res) => {
ip = req.body.ip;
})
app.get("/list", (req, res) => {
console.log(`yo this is the ip bro : ${ip}`);
exec(`./script1.sh ${ip}`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(stdout);
res.status(200).render("index", { layout: false, list: stdout });
})
});
app.post("/upload", (req, res) => {
let file = req.body.filename;
console.log(`Yo this is the fileName : ${file}`);
exec(`./script2.sh ${ip} ${file}`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(stdout);
})
})
app.post("/download", (req, res) => {
let file = req.body.filename;
console.log(`Yo this is the fileName : ${file}`);
exec(`./script3.sh ${ip} ${file}`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(stdout);
})
})
app.listen(port, () => {
console.log(`App listening at port ${port}`);
})