-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
90 lines (81 loc) · 2.83 KB
/
app.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var express = require('express')
, http = require('http')
, path = require('path')
, mime = require('mime')
, sys = require('sys')
, redis = require('redis')
, io = require('socket.io');
//, terminal = require('web-terminal');
var sanitizer = require('sanitizer');
var app = express();var sanitizer = require('sanitizer');
var client_redis = redis.createClient();
app.configure(function(){
app.set('port', process.env.PORT || 3002);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.multipart())
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.cookieSession({store: '/',
secret: 'BBQ12345AHHH////',
cookie: {httpOnly: false},
key: 'cookie.sid' }));
app.use(express.static(path.join(__dirname, 'public')));
});
//
// add routes
//
require('./routes/fileTpl')(app,client_redis,__dirname)
require('./routes/cms')(app,client_redis,__dirname)
require('./routes/script')(app,client_redis,__dirname)
require('./routes/compilateur')(app,client_redis,__dirname)
require('./routes/loginHome')(app,client_redis,__dirname)
//---------------------------------------------------------------------
var op= http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
//--------------------------------------------------------------------
//*************************************************************
//* socket IO *
//*************************************************************
app.get('/halt',function(req,res){
io.sockets.emit('halt',{});
res.send('OK');
});
io = io.listen(op,{log : false});
//--------------- Terminal --------------------
//
//------------------------------------------------
//terminal(op);
//console.log('Terminal lunched !!')
var slave_id;
slave_id =0;
io.sockets.on('connection', function (socket) {
//socket.emit('faitUneAlerte');
console.log('client connecté');
slave_id = slave_id+1;
if(slave_id>800000)
slave_id = 1;
socket.emit('register',{'id' : slave_id});
console.log('regiser id '+slave_id);
socket.on('finish',function(data){
socket.broadcast.emit('finish',data);
console.log('finish receive to father: '+data.father_id);
});
socket.on('console-emit', function (data) {
var out = sanitizer.escape(data)
socket.broadcast.emit('console-emit',out.replace(/ /g," "));
});
socket.on('console-emit-cmd', function (data) {
socket.broadcast.emit('console-emit',data);
});
socket.on('halt-error', function (data) {
socket.broadcast.emit('halt',{});
});
socket.on('disconnect',function()
{
console.log("disconnect user from ");
});
});