-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
84 lines (64 loc) · 1.94 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
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
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var spawn = require('child_process').spawn;
var fs = require('fs');
var path = require("path");
var baseApps = 'apps/';
app.use('/', express.static(__dirname + '/'));
app.get('/', function(req, res){
res.sendfile('index.html');
});
io.on('connection', function(socket){
// Permite ejecutar las apliaciones
socket.on('ejecutar', function(ejecutar){
console.log("Ejecutando: "+__dirname + "/" + baseApps + ejecutar);
var exec = require('child_process').exec,
child;
child = exec(__dirname + "/" + baseApps + ejecutar,
function (error, stdout, stderr) {
//console.log('stdout: ' + stdout);
//console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
});
});
io.on('connection', function (socket) {
var archivos = [];
//var icono = '';
socket.on('listar_archivos', function(carpeta){
archivos.length=0;
fs.readdir( baseApps+carpeta, function (err, files) {
if (err) {
throw err;
}
files.map(function (file) {
return path.join(baseApps+carpeta, file);
}).filter(function (file) {
return fs.statSync(file).isFile();
}).forEach(function (file) {
if(path.extname(file)=='.lnk' || path.extname(file)=='.exe'){
icono = path.join(baseApps+carpeta, path.basename(file,path.extname(file)))+'.png';
if(!fs.existsSync(icono)){
icono = baseApps+'no-icon.png';
}
console.log('Icono: '+icono);
archivos.push({
'path':path.dirname(file),
'nombreCompleto':path.basename(file),
'icono': icono,
'nombre':path.basename(file,path.extname(file))}
);
console.log("Link: %s (%s)", file, path.extname(file));
}
});
socket.emit('listar_archivos', {'archivos': archivos});
});
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});