forked from Chinachu/Chinachu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-wui.js
879 lines (726 loc) · 20.3 KB
/
app-wui.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
/*!
* Chinachu WebUI Server Service (chinachu-wui)
*
* Copyright (c) 2012 Yuki KAN and Chinachu Project Contributors
* http://chinachu.akkar.in/
**/
/*jslint node:true, nomen:true, plusplus:true, regexp:true, vars:true, continue:true */
/*global gc */
'use strict';
var CONFIG_FILE = __dirname + '/config.json';
var RULES_FILE = __dirname + '/rules.json';
var RESERVES_DATA_FILE = __dirname + '/data/reserves.json';
var SCHEDULE_DATA_FILE = __dirname + '/data/schedule.json';
var RECORDING_DATA_FILE = __dirname + '/data/recording.json';
var RECORDED_DATA_FILE = __dirname + '/data/recorded.json';
var OPERATOR_LOG_FILE = __dirname + '/log/operator';
var WUI_LOG_FILE = __dirname + '/log/wui';
var SCHEDULER_LOG_FILE = __dirname + '/log/scheduler';
// 標準モジュールのロード
var path = require('path');
var fs = require('fs');
var util = require('util');
var child_process = require('child_process');
var url = require('url');
var querystring = require('querystring');
var vm = require('vm');
var os = require('os');
var zlib = require('zlib');
// ディレクトリチェック
if (!fs.existsSync('./data/') || !fs.existsSync('./log/') || !fs.existsSync('./web/')) {
util.error('必要なディレクトリが存在しないか、カレントワーキングディレクトリが不正です。');
process.exit(1);
}
// 終了処理
process.on('SIGQUIT', function () {
setTimeout(function () {
process.exit(0);
}, 0);
});
// 例外処理
process.on('uncaughtException', function (err) {
util.error('uncaughtException: ' + err);
});
// 追加モジュールのロード
var auth = require('http-auth');
var socketio = require('socket.io');
var chinachu = require('chinachu-common');
var S = require('string');
// etc.
var timer = {};
var emptyFunction = function () {};
// 設定の読み込み
var config = require(CONFIG_FILE);
// https or http
if (config.wuiTlsKeyPath && config.wuiTlsCertPath) {
var spdy = require('spdy');
var tlsOption = {
key : fs.readFileSync(config.wuiTlsKeyPath),
cert: fs.readFileSync(config.wuiTlsCertPath)
};
// 秘密鍵または pfx のパスフレーズを表す文字列
if (config.wuiTlsPassphrase) { tlsOption.passphrase = config.wuiTlsPassphrase; }
if (config.wuiTlsRequestCert) { tlsOption.requestCert = config.wuiTlsRequestCert; }
if (config.wuiTlsRejectUnauthorized) { tlsOption.rejectUnauthorized = config.wuiTlsRejectUnauthorized; }
if (config.wuiTlsCaPath) { tlsOption.ca = [ fs.readFileSync(config.wuiTlsCaPath) ]; }
} else {
var http = require('http');
}
// BASIC認証
if (config.wuiUsers && (config.wuiUsers.length > 0)) {
var basic = auth({
authRealm: 'Authentication.',
authList : config.wuiUsers
});
}
// ステータス
var status = {
connectedCount: 0,
feature: {
previewer : !!config.wuiPreviewer,
streamer : !!config.wuiStreamer,
filer : !!config.wuiFiler,
configurator: !!config.wuiConfigurator
},
system: {
core: os.cpus().length
},
operator: {
alive: false,
pid : null
},
wui: {
alive: false,
pid : null
}
};
var rules = [];
var schedule = [];
var reserves = [];
var recording = [];
var recorded = [];
//
// http server
//
var httpServer, httpServerMain;
if (http) { var app = http.createServer(httpServer); }
if (spdy) { var app = spdy.createServer(tlsOption, httpServer); }
app.listen(config.wuiPort, (typeof config.wuiHost === 'undefined') ? '::' : config.wuiHost);
function httpServer(req, res) {
var q = '';
switch (req.method) {
case 'GET':
case 'HEAD':
q = url.parse(req.url, false).query || '';
if (q.match(/^\{.*\}$/) === null) {
q = querystring.parse(q);
} else {
try {
q = JSON.parse(q);
} catch (e) {
q = {};
}
}
httpServerMain(req, res, q);
q = void 0;
break;
case 'POST':
case 'PUT':
case 'DELETE':
req.on('data', function (chunk) {
q += chunk.toString();
});
req.once('end', function () {
if (q.trim().match(/^\{(\n|.)*\}$/) === null) {
q = querystring.parse(q);
} else {
try {
q = JSON.parse(q.trim());
} catch (e) {
q = {};
}
}
httpServerMain(req, res, q);
q = void 0;
});
break;
default:
res.writeHead(400, {'content-type': 'text/plain'});
res.end('400 Bad Request\n');
util.log('400');
}
}
function httpServerMain(req, res, query) {
// http request logging
var log = function (statusCode) {
util.log([
statusCode,
req.method + ':' + req.url,
req.headers['x-forwarded-for'] || req.client.remoteAddress,
(req.headers['user-agent'] || '').split(' ').pop() || '-'
].join(' '));
};
// serve static file
var location = req.url;
if (location.match(/(\?.*)$/) !== null) { location = location.match(/^(.+)\?.*$/)[1]; }
if (location.match(/\/$/) !== null) { location += 'index.html'; }
// HTTPメソッド指定を上書き
if (query.method) {
req.method = query.method.toUpperCase();
delete query.method;
}
if (query._method) {
req.method = query._method.toUpperCase();
delete query._method;
}
var filename = path.join('./web/', location);
var ext = null;
if (filename.match(/[^\/]+\..+$/) !== null) {
ext = filename.split('.').pop();
}
// エラーレスポンス用
var resErr = function (code) {
res.writeHead(code, {'content-type': 'text/plain'});
if (req.method !== 'HEAD') {
switch (code) {
case 400:
res.write('400 Bad Request\n');
break;
case 402:
res.write('402 Payment Required\n');
break;
case 401:
res.write('401 Unauthorized\n');
break;
case 403:
res.write('403 Forbidden\n');
break;
case 404:
res.write('404 Not Found\n');
break;
case 405:
res.write('405 Method Not Allowed\n');
break;
case 406:
res.write('406 Not Acceptable\n');
break;
case 407:
res.write('407 Proxy Authentication Required\n');
break;
case 408:
res.write('408 Request Timeout\n');
break;
case 409:
res.write('409 Conflict\n');
break;
case 410:
res.write('410 Gone\n');
break;
case 411:
res.write('411 Length Required\n');
break;
case 412:
res.write('412 Precondition Failed\n');
break;
case 413:
res.write('413 Request Entity Too Large\n');
break;
case 414:
res.write('414 Request-URI Too Long\n');
break;
case 415:
res.write('415 Unsupported Media Type\n');
break;
case 416:
res.write('416 Requested Range Not Satisfiable\n');
break;
case 417:
res.write('417 Expectation Failed\n');
break;
case 429:
res.write('429 Too Many Requests\n');
break;
case 451:
res.write('451 Unavailable For Legal Reasons\n');
break;
case 500:
res.write('500 Internal Server Error\n');
break;
case 501:
res.write('501 Not Implemented\n');
break;
case 502:
res.write('502 Bad Gateway\n');
break;
case 503:
res.write('503 Service Unavailable\n');
break;
}
}
res.end();
log(code);
};
var writeHead = function (code) {
var type = 'text/plain';
if (ext === 'html') { type = 'text/html'; }
if (ext === 'js') { type = 'text/javascript'; }
if (ext === 'css') { type = 'text/css'; }
if (ext === 'ico') { type = 'image/vnd.microsoft.icon'; }
if (ext === 'cur') { type = 'image/vnd.microsoft.icon'; }
if (ext === 'png') { type = 'image/png'; }
if (ext === 'gif') { type = 'image/gif'; }
if (ext === 'jpg') { type = 'image/jpeg'; }
if (ext === 'f4v') { type = 'video/mp4'; }
if (ext === 'm4v') { type = 'video/mp4'; }
if (ext === 'mp4') { type = 'video/mp4'; }
if (ext === 'flv') { type = 'video/x-flv'; }
if (ext === 'webm') { type = 'video/webm'; }
if (ext === 'm2ts') { type = 'video/MP2T'; }
if (ext === 'm3u8') { type = 'application/x-mpegURL'; }
if (ext === 'asf') { type = 'video/x-ms-asf'; }
if (ext === 'json') { type = 'application/json; charset=utf-8'; }
if (ext === 'xspf') { type = 'application/xspf+xml'; }
var head = {
'content-type' : type,
'date' : new Date().toUTCString(),
'server' : 'chinachu-wui',
'cache-control' : 'no-cache',
'x-content-type-options' : 'nosniff',
'x-frame-options' : 'DENY',
'x-ua-compatible' : 'IE=Edge,chrome=1',
'x-xss-protection' : '1; mode=block'
};
res.writeHead(code, head);
};
// ヘッダの確認
if (!req.headers.host) { return resErr(400); }
var responseStatic = function () {
if (fs.existsSync(filename) === false) { return resErr(404); }
if (req.method !== 'HEAD' && req.method !== 'GET') {
res.setHeader('allow', 'HEAD, GET');
return resErr(405);
}
if (['ico', 'png'].indexOf(ext) !== -1) {
res.setHeader('cache-control', 'private, max-age=86400');
}
var fstat = fs.statSync(filename);
res.setHeader('accept-ranges', 'bytes');
res.setHeader('last-modified', new Date(fstat.mtime).toUTCString());
if (req.headers['if-modified-since'] && req.headers['if-modified-since'] === new Date(fstat.mtime).toUTCString()) {
writeHead(304);
log(304);
return res.end();
}
var range = {};
if (req.headers.range) {
var bytes = req.headers.range.replace(/bytes=/, '').split('-');
range.start = parseInt(bytes[0], 10);
range.end = parseInt(bytes[1], 10) || fstat.size;
if (range.start > fstat.size || range.end > fstat.size) {
return resErr(416);
}
res.setHeader('content-range', 'bytes ' + range.start + '-' + range.end + '/' + fstat.size);
res.setHeader('content-length', range.end - range.start + 1);
writeHead(206);
log(206);
} else {
res.setHeader('content-length', fstat.size);
writeHead(200);
log(200);
}
if (req.method === 'GET') {
fs.createReadStream(filename, range || {}).pipe(res);
} else {
res.end();
}
};
var responseApi = function () {
var dir = location.replace('/api/', '').replace(/\.[a-z0-9]+$/, '');
var dirs = dir.split('/');
var addr = dir.replace(/^[^\/]+\/?/, '/');
if (dirs[0] === 'index.html') { return resErr(400); }
var resourceFile = './api/resource-' + dirs[0] + '.json';
if (fs.existsSync(resourceFile) === false) { return resErr(404); }
fs.readFile(resourceFile, function (err, json) {
if (err) { return resErr(500); }
var r;
try {
r = JSON.parse(json);
} catch (e) {
util.error(e);
return resErr(500);
}
var pattern;
var param;
var target = null;
var k, i, l;
for (k in r) {
if (r.hasOwnProperty(k)) {
pattern = new RegExp(k.replace(/:[^\/]+/g, '([^/]+)'));
if (addr.match(pattern) !== null) {
target = r[k];
param = {};
if (k.match(pattern).length > 1) {
for (i = 1, l = k.match(pattern).length; i < l; i++) {
param[k.match(pattern)[i].replace(':', '')] = addr.match(pattern)[i];
}
}
}
}
}
if (target === null) { return resErr(400); }
if (target.methods.indexOf(req.method.toLowerCase()) === -1) {
res.setHeader('allow', target.methods.join(', ').toUpperCase());
return resErr(405);
}
if (target.types.indexOf(ext) === -1) { return resErr(415); }
var scriptFile = './api/script-' + target.script + '.vm.js';
if (fs.existsSync(scriptFile) === false) { return resErr(501); }
res._end = res.end;
res.end = function () {
res.end = res._end;
res.end.apply(res, arguments);
res.emit('end');
};
var acceptEncoding = req.headers['accept-encoding'];
if (!acceptEncoding) { acceptEncoding = ''; }
var encoding = '';
if (acceptEncoding.match(/deflate/)) {
encoding = 'deflate';
}/* else if (acceptEncoding.match(/gzip/)) {
encoding = 'gzip';
}*/
if (req.headers['user-agent'] && req.headers['user-agent'].match(/Trident/)) {
encoding = '';
}
var sandbox = {
request : req,
response : res,
path : path,
fs : fs,
url : url,
util : util,
child_process: child_process,
Buffer : Buffer,
zlib : zlib,
chinachu : chinachu,
config : config,
define: {
CONFIG_FILE : CONFIG_FILE,
RULES_FILE : RULES_FILE,
RESERVES_DATA_FILE : RESERVES_DATA_FILE,
SCHEDULE_DATA_FILE : SCHEDULE_DATA_FILE,
RECORDING_DATA_FILE: RECORDING_DATA_FILE,
RECORDED_DATA_FILE : RECORDED_DATA_FILE,
OPERATOR_LOG_FILE : OPERATOR_LOG_FILE,
WUI_LOG_FILE : WUI_LOG_FILE,
SCHEDULER_LOG_FILE : SCHEDULER_LOG_FILE
},
data: {
rules : rules,
schedule : schedule,
reserves : reserves,
recording: recording,
recorded : recorded,
status : status
},
setInterval: setInterval,
setTimeout : setTimeout,
clearInterval: clearInterval,
clearTimeout : clearTimeout,
children: []
};
var isClosed = false;
var cleanup;
sandbox.request.query = query;
sandbox.request.param = param;
sandbox.request.type = ext;
sandbox.request.encoding = encoding;
sandbox.response.head = writeHead;
sandbox.response.error = function (code) {
isClosed = true;
resErr(code);
cleanup();
};
// DEPRECATED
sandbox.response.exit = function (data, encoding) {
util.log('response.exit is DEPRECATED: ' + scriptFile);
try {
res.end(data, encoding);
} catch (e) {
util.log(e);
}
};
var onEnd = function () {
if (!isClosed) {
isClosed = true;
log(res.statusCode);
}
cleanup();
};
var onError = function () {
if (!isClosed) {
isClosed = true;
req.emit('close');
resErr(500);
}
cleanup();
};
cleanup = function () {
setTimeout(function () {
sandbox.children.forEach(function (child) {
child.kill('SIGKILL');
});
sandbox = null;
}, 3000);
if (typeof gc !== 'undefined') {
if (timer.gcByApi) { clearTimeout(timer.gcByApi); }
timer.gcByApi = setTimeout(function () {
process.nextTick(gc);
}, 3500);
}
req.connection.removeListener('close', onEnd);
req.connection.removeListener('error', onError);
req.removeListener('end', onEnd);
cleanup = emptyFunction;
};
req.connection.on('close', onEnd);
req.connection.on('error', onError);
res.on('end', onEnd);
try {
vm.runInNewContext(fs.readFileSync(scriptFile), sandbox, scriptFile);
} catch (ee) {
if (!isClosed) {
resErr(500);
isClosed = true;
}
util.error(ee);
}
return;
});
return;
};
// 静的ファイルまたはAPIレスポンスの分岐
if (req.url.match(/^\/api\/.*$/) === null) {
if (fs.existsSync(filename) === false) { return resErr(404); }
if (req.url.match(/^\/apple-.+\.png$/) !== null) {
process.nextTick(responseStatic);
} else if (!basic) {
process.nextTick(responseStatic);
} else {
basic.apply(req, res, function () {
process.nextTick(responseStatic);
});
}
} else {
if (basic) {
if (!!query._auth) {
// Base64文字列を取り出す
var auths = query._auth.split(':');
// バリデーション
if (auths[0] !== 'basic' || auths.length !== 2) {
return resErr(400);
}
var auth = decodeURIComponent(auths[1]);
// Base64デコード
try {
auth = new Buffer(auth, 'base64').toString('ascii');
} catch (e) {
return resErr(401);
}
// 認証
if (config.wuiUsers && config.wuiUsers.indexOf(auth) === -1) {
return resErr(401);
}
// 通ってよし
process.nextTick(responseApi);
} else {
basic.apply(req, res, function () {
process.nextTick(responseApi);
});
}
} else {
process.nextTick(responseApi);
}
}
}
//
// socket.io server
//
var ioServer, ioServerMain, ioServerSocketOnDisconnect;
var io = socketio.listen(app);
io.enable('browser client minification');
io.set('log level', 1);
io.set('transports', ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']);
io.sockets.on('connection', ioServer);
function ioServer(socket) {
if (basic) {
// ヘッダを確認
if (!socket.handshake.headers.authorization || (socket.handshake.headers.authorization.match(/^Basic .+$/) === null)) {
socket.disconnect();
return;
}
// Base64文字列を取り出す
var auth = socket.handshake.headers.authorization.split(' ')[1];
// Base64デコード
try {
auth = new Buffer(auth, 'base64').toString('ascii');
} catch (e) {
socket.disconnect();
return;
}
// 認証
if (config.wuiUsers && config.wuiUsers.indexOf(auth) === -1) {
socket.disconnect();
return;
}
}
// 通ってよし
ioServerMain(socket);
}
function ioServerMain(socket) {
++status.connectedCount;
socket.on('disconnect', ioServerSocketOnDisconnect);
// broadcast
io.sockets.emit('status', status);
/*
socket.emit('rules', rules);
socket.emit('reserves', reserves);
socket.emit('recording', recording);
socket.emit('recorded', recorded);
socket.emit('schedule', schedule);
*/
socket.emit('notify-rules');
socket.emit('notify-reserves');
socket.emit('notify-recording');
socket.emit('notify-recorded');
socket.emit('notify-schedule');
}
function ioServerSocketOnDisconnect() {
--status.connectedCount;
io.sockets.emit('status', status);
}
// ファイル更新監視: ./data/rules.json
chinachu.jsonWatcher(
RULES_FILE,
function _onUpdated(err, data, mes) {
if (err) {
util.error(err);
return;
}
rules = data;
io.sockets.emit('notify-rules');
util.log(mes);
},
{ create: [], now: true }
);
// ファイル更新監視: ./data/schedule.json
chinachu.jsonWatcher(
SCHEDULE_DATA_FILE,
function _onUpdated(err, data, mes) {
if (err) {
util.error(err);
return;
}
schedule = data;
io.sockets.emit('notify-schedule');
util.log(mes);
},
{ create: [], now: true }
);
// ファイル更新監視: ./data/reserves.json
chinachu.jsonWatcher(
RESERVES_DATA_FILE,
function _onUpdated(err, data, mes) {
if (err) {
util.error(err);
return;
}
reserves = data;
io.sockets.emit('notify-reserves');
util.log(mes);
},
{ create: [], now: true }
);
// ファイル更新監視: ./data/recording.json
chinachu.jsonWatcher(
RECORDING_DATA_FILE,
function _onUpdated(err, data, mes) {
if (err) {
util.error(err);
return;
}
recording = data;
io.sockets.emit('notify-recording');
util.log(mes);
},
{ create: [], now: true }
);
// ファイル更新監視: ./data/recorded.json
chinachu.jsonWatcher(
RECORDED_DATA_FILE,
function _onUpdated(err, data, mes) {
if (err) {
util.error(err);
return;
}
recorded = data;
io.sockets.emit('notify-recorded');
util.log(mes);
},
{ create: [], now: true }
);
// プロセス監視
function processChecker() {
io.sockets.emit('status', status);
var c = chinachu.createCountdown(2, chinachu.createTimeout(processChecker, 5000));
if (fs.existsSync('/var/run/chinachu-operator.pid') === true) {
fs.readFile('/var/run/chinachu-operator.pid', function (err, pid) {
if (err) { return c.tick(); }
pid = pid.toString().trim();
child_process.exec('ps h -p ' + pid + ' -o %cpu,rss', function (err, stdout) {
if (stdout === '') {
status.operator.alive = false;
status.operator.pid = null;
} else {
//stdout = S(stdout.trim()).collapseWhitespace().s;
status.operator.alive = true;
status.operator.pid = parseInt(pid, 10);
}
c.tick();
});
});
} else {
status.operator.alive = false;
status.operator.pid = null;
c.tick();
}
if (fs.existsSync('/var/run/chinachu-wui.pid') === true) {
fs.readFile('/var/run/chinachu-wui.pid', function (err, pid) {
if (err) { return c.tick(); }
pid = pid.toString().trim();
child_process.exec('ps h -p ' + pid + ' -o %cpu,rss', function (err, stdout) {
if (stdout === '') {
status.wui.alive = false;
status.wui.pid = null;
} else {
//stdout = S(stdout.trim()).collapseWhitespace().s;
status.wui.alive = true;
status.wui.pid = parseInt(pid, 10);
}
c.tick();
});
});
} else {
status.wui.alive = false;
status.wui.pid = null;
c.tick();
}
}
processChecker();
//
// gc
//
if (typeof gc !== 'undefined') {
setInterval(gc, 1000 * 60 * 2);
}