-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
73 lines (60 loc) · 1.84 KB
/
client.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
73
//Made By BioShot\\
/*
#UPDATE 1.0.2 CHANGELOG BY BIOSHOT
[BEGIN $CHANGELOG]
[BEGIN $STATUS]
$SECTION1: NO CHANGE, LAST CHANGE: #1.0;
$SECTION2: NO CHANGE, LAST CHANGE: #1.0;
$SECTION3: CHANGE: @"UPDATE START FUNCTION TO CREATE A NEW SESSION!";
$SECTION4: BROKEN;
[END $STATUS]
[END $CHANGELOG]
*/
//SECTION: 1\\
const express = require("express");
const crypto = require('crypto');
const cors = require('cors');
const exec = require("child_process").exec;
const os = require("os");
const axios = require('axios');
var app = express();
app.use(cors({
origin: '*'
}));
//SECTION: 2\\
var ip='http://192.168.190.1:32012';
let sessionID;
app.get('/system', (req,res)=>{
sessionID=req.query.sessionID;
var command = req.query.command;
if(command != undefined){
if(command.includes("sudo")){
res.send(`Error! Unable to run command ${command}, because it includes and invalid keyword: 'sudo'! Line 31 client.js.`);
}else{
exec(command, (err, stdout, stderr)=>{
if(err){
res.send(err);
return;
}
if(stdout){
res.send(stdout);
}else{
}
});
};
}else if(req.query.getMachineName != undefined){
const hostName = os.hostname();
res.send(hostName ?? os.hostName);
}
})
//SECTION: 3\\
app.listen(32012, '0.0.0.0', ()=>{
axios.get(`http://localhost:8080/newSession?sessionInfo={"about":"blank"}`)
.then (response => console.log(`Session ID: ${response.data}`));
});
//SECTION: 4\\
process.on('SIGHUP', function() {
axios.get(`http://localhost:8080/session/${sessionID}/system?close=1`)
.then (response => res.send(response.data));
process.exit();
});