-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (28 loc) · 930 Bytes
/
index.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
var http = require('http')
var exec = require('child_process').exec;
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var sResponse,
sFullCommand,
aParts,
sCommand,
aArgs = [];
aParts = req.url.split(/\//);
aParts.shift();
if (aParts[0] === '') {
res.end('No command to run');
return;
}
sCommand = aParts.shift();
aArgs = aParts.slice(0);
sFullCommand = sCommand + ' ' + aArgs.toString().replace(',',' ');
// un-escape forward-slash characters
sFullCommand = sFullCommand.replace(/%2F/g,'/');
exec(sFullCommand, function(error, stdout, stderr) {
sResponse = 'command: ' + sFullCommand;
sResponse += '\n\rstderr:\n\r' + stderr;
sResponse += '\n\rstdout:\n\r' + stdout;
res.end(sResponse);
});
}).listen(3123);
console.log('Running on port 3123...');