@@ -5,6 +5,11 @@ var path = require('path');
55var glob = require ( "glob" ) ;
66var masterpw = "gulli" ;
77
8+ //Global counter variables
9+ var doneSimulations = 0 ;
10+ var openSimulations = 0 ;
11+
12+
813
914// Required modules for form handling
1015var express = require ( 'express' ) ,
@@ -19,13 +24,52 @@ var DEFAULT_MINIMUM_TIMEOUT = 500;//in sec
1924router . get ( '/' , function ( req , res ) {
2025 var db = req . db ;
2126 var activeclients = db . collection ( 'activeclients' ) ;
22- console . log ( "Delivering index-page." ) ;
27+ var simlist = db . collection ( 'simlist' ) ;
28+
29+
30+ /*console.log("Delivering index-page.");*/
31+ simlist . find ( { simulated : false } , function ( err , result ) {
32+ if ( err ) {
33+ console . log ( "Error finding open simulations in db." ) ;
34+ } else {
35+ //console.log("Will try to count open simulations.");
36+ if ( result != null ) {
37+ result . count ( function ( err , count ) {
38+ if ( err ) {
39+ console . log ( "Error counting open simulations." ) ;
40+ } else {
41+ openSimulations = count ;
42+ //console.log("Number of open Simulations is:"+openSimulations);
43+ }
44+ } ) ;
45+ } //End if
46+ } //End else
47+ } ) ;
48+ simlist . find ( { simulated : true } , function ( err , result ) {
49+ if ( err ) {
50+ console . log ( "Error finding done simulations in db." ) ;
51+ } else {
52+ //console.log("Will try to count open simulations.");
53+ if ( result != null ) {
54+ result . count ( function ( err , count ) {
55+ if ( err ) {
56+ console . log ( "Error counting done simulations." ) ;
57+ } else {
58+ doneSimulations = count ;
59+ //console.log("Number of done Simulations is:"+doneSimulations);
60+ }
61+ } ) ;
62+ } //End if
63+ } //End else
64+ } ) ;
2365
2466 removeOldClientsFromList ( db , function ( error ) {
2567 res . render ( 'index' , {
2668 title : 'TimeNET distribution server' ,
2769 clientcount : Math . round ( global . clientcount ) ,
28- clientsrunning : global . clientsrunning
70+ clientsrunning : global . clientsrunning ,
71+ opensimulations : openSimulations ,
72+ donesimulations : doneSimulations
2973 } ) ;
3074
3175 } ) ;
@@ -326,7 +370,8 @@ router.post('/rest/log/upload', function (req, res) {
326370
327371
328372 form . parse ( req , function ( err , fields , files ) {
329- var old_path = files . attachment . path ,
373+ try {
374+ var old_path = files . attachment . path ,
330375 file_size = files . attachment . size ,
331376 file_name = files . attachment . name ,
332377 simid = fields . simid ,
@@ -370,7 +415,11 @@ router.post('/rest/log/upload', function (req, res) {
370415 } ) ;
371416
372417 } ) ;
373- } ) ;
418+
419+ } catch ( e ) {
420+ console . log ( "Error while uploading logfile. " ) ;
421+ }
422+ } ) ;
374423
375424} ) ;
376425
@@ -679,6 +728,7 @@ function removeOldClientsFromList(db, cb) {
679728
680729 }
681730 }
731+ if ( global . clientsrunning == NaN ) global . clientsrunning = 0 ;
682732 } ) ;
683733
684734 //console.log("Simulating Clients:"+global.clientsrunning);
0 commit comments