-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkalxen.js
65 lines (62 loc) · 2.46 KB
/
kalxen.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
var execFile = require('child_process').execFile;
var http = require('http');
var server = http.createServer(function (request, response) {
if (request.method == 'POST') {
var body = '';
request.on('data', function (data) {
body += data;
// 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB
if (body.length > 1e6) {
// FLOOD ATTACK OR FAULTY CLIENT, NUKE REQUEST
request.connection.destroy();
}
});
request.on('end', function () {
if(body === 'laere') {
console.log('API Summon started...');
execFile('./laere.sh', function (error, stdout, stderr) {
if (error) {
console.log(error);
response.writeHead(500, {"Content-Type": "text/plain"});
response.end("I'm not feeling very well...\n");
}
else {
console.log(stdout);
console.log(stderr);
console.log('Summon complete...');
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Thanks\n");
}
});
}
else if(body === 'laere-ui') {
console.log('UI Summon started...');
execFile('./laere-ui.sh', function (error, stdout, stderr) {
if (error) {
console.log(error);
response.writeHead(500, {"Content-Type": "text/plain"});
response.end("I'm not feeling very well...\n");
}
else {
console.log(stdout);
console.log(stderr);
console.log('Summon complete...');
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Thanks\n");
}
});
}
else {
response.writeHead(400, {"Content-Type": "text/plain"});
response.end("Bad request\n");
}
});
}
else {
response.writeHead(400, {"Content-Type": "text/plain"});
response.end("Bad request\n");
}
});
server.listen(9001);
// Put a friendly message on the terminal
console.log("Kalxen running at port 9001");