-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (37 loc) · 1.19 KB
/
server.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
var express = require('express')
, app = express()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)
, conf = require('./config.json');
server.listen(conf.port);
console.log("server started - listening on port " + conf.port);
/* serve static content from "htdocs" folder */
app.use(express.static(__dirname + '/htdocs'));
// "GET /" serves index.html
app.get('/', function (req, res) {
res.sendfile(__dirname + '/htdocs/index.html');
});
io.sockets.on('connection', function (socket) {
// client connected
socket.emit('control', {
time: new Date(),
text: 'Gummynet - yeah!'
});
// control message (whatever for...)
socket.on('control', function (data) {
// log control message
console.log(data.text);
});
// execute shell command
socket.on('shell', function (data) {
console.log(data.command);
var exec = require('child_process').exec;
var cmd = data.command;
exec(cmd, function(error, stdout, stderr) {
socket.emit('shell', {
time : new Date(),
stdout : stdout
});
});
});
});