Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
3287 rexy 1
var langxml = [], langarr = [], current_language = "", plugins = [], blocks = [], plugin_liste = [],
2
     showCPUListExpanded, showCPUInfoExpanded, showNetworkInfosExpanded, showNetworkActiveSpeed, showCPULoadCompact, oldnetwork = [], refrTimer;
3
 
4
/**
5
 * Fix potential XSS vulnerability in jQuery
6
 */
7
jQuery.htmlPrefilter = function( html ) {
8
	return html;
9
};
10
 
11
/**
12
 * generate a cookie, if not exist, and add an entry to it<br><br>
13
 * inspired by <a href="http://www.quirksmode.org/js/cookies.html">http://www.quirksmode.org/js/cookies.html</a>
14
 * @param {String} name name that holds the value
15
 * @param {String} value value that needs to be stored
16
 * @param {Number} days how many days the entry should be valid in the cookie
17
 */
18
function createCookie(name, value, days) {
19
    var date = new Date(), expires = "";
20
    if (days) {
21
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
22
        if (typeof(date.toUTCString)==="function") {
23
            expires = "; expires=" + date.toUTCString();
24
        } else {
25
            //deprecated
26
            expires = "; expires=" + date.toGMTString();
27
        }
28
    } else {
29
        expires = "";
30
    }
31
    document.cookie = name + "=" + value + expires + "; path=/; samesite=strict";
32
}
33
 
34
/**
35
 * read a value out of a cookie and return the value<br><br>
36
 * inspired by <a href="http://www.quirksmode.org/js/cookies.html">http://www.quirksmode.org/js/cookies.html</a>
37
 * @param {String} name name of the value that should be retrieved
38
 * @return {String}
39
 */
40
function readCookie(name) {
41
    var nameEQ = "", ca = [], c = '';
42
    nameEQ = name + "=";
43
    ca = document.cookie.split(';');
44
    for (var i = 0; i < ca.length; i++) {
45
        c = ca[i];
46
        while (c.charAt(0) === ' ') {
47
            c = c.substring(1, c.length);
48
        }
49
        if (!c.indexOf(nameEQ)) {
50
            return c.substring(nameEQ.length, c.length);
51
        }
52
    }
53
    return null;
54
}
55
 
56
/**
57
 * activates a given style and disables the old one in the document
58
 * @param {String} template template that should be activated
59
 */
60
function switchStyle(template) {
61
    $("#PSI_Template")[0].setAttribute('href', 'templates/bootstrap/' + template + ".css");
62
}
63
 
64
/**
65
 * load the given translation an translate the entire page<br><br>retrieving the translation is done through a
66
 * ajax call
67
 * @private
68
 * @param {String} plugin if plugin is given, the plugin translation file will be read instead of the main translation file
69
 * @param {String} langarrId internal plugin name
70
 * @return {jQuery} translation jQuery-Object
71
 */
72
function getLanguage(plugin, langarrId) {
73
    var getLangUrl = "";
74
    if (current_language) {
75
        getLangUrl = 'language/language.php?lang=' + current_language;
76
        if (plugin) {
77
            getLangUrl += "&plugin=" + plugin;
78
        }
79
    } else {
80
        getLangUrl = 'language/language.php';
81
        if (plugin) {
82
            getLangUrl += "?plugin=" + plugin;
83
        }
84
    }
85
    $.ajax({
86
        url: getLangUrl,
87
        type: 'GET',
88
        dataType: 'xml',
89
        timeout: 100000,
90
        error: function error() {
91
            $("#errors").append("<li><b>Error loading language</b> - " + getLangUrl + "</li><br>");
92
            $("#errorbutton").attr('data-toggle', 'modal');
93
            $("#errorbutton").css('cursor', 'pointer');
94
            $("#errorbutton").css("visibility", "visible");
95
        },
96
        success: function buildblocks(xml) {
97
            var idexp;
98
            langxml[langarrId] = xml;
99
            if (langarr[langarrId] === undefined) {
100
                langarr.push(langarrId);
101
                langarr[langarrId] = [];
102
            }
103
            $("expression", langxml[langarrId]).each(function langstore(id) {
104
                idexp = $("expression", xml).get(id);
105
                langarr[langarrId][this.getAttribute('id')] = $("exp", idexp).text().toString().replace(/\//g, "/<wbr>");
106
            });
107
            changeSpanLanguage(plugin);
108
        }
109
    });
110
}
111
 
112
/**
113
 * generate a span tag
114
 * @param {Number} id translation id in the xml file
115
 * @param {String} [plugin] name of the plugin for which the tag should be generated
116
 * @param {String} [defaultvalue] default value
117
 * @return {String} string which contains generated span tag for translation string
118
 */
119
function genlang(id, plugin, defaultvalue) {
120
    var html = "", idString = "", plugname = "",
121
        langarrId = current_language + "_";
122
 
123
    if (plugin === undefined) {
124
        plugname = "";
125
        langarrId += "phpSysInfo";
126
    } else {
127
        plugname = plugin.toLowerCase();
128
        langarrId += plugname;
129
    }
130
 
131
    if (id < 100) {
132
        if (id < 10) {
133
            idString = "00" + id.toString();
134
        } else {
135
            idString = "0" + id.toString();
136
        }
137
    } else {
138
        idString = id.toString();
139
    }
140
    if (plugin) {
141
        idString = "plugin_" + plugname + "_" + idString;
142
    }
143
 
144
    html += "<span class=\"lang_" + idString + "\">";
145
 
146
    if ((langxml[langarrId] !== undefined) && (langarr[langarrId] !== undefined)) {
147
        html += langarr[langarrId][idString];
148
    } else if (defaultvalue !== undefined) {
149
        html += defaultvalue;
150
    }
151
 
152
    html += "</span>";
153
 
154
    return html;
155
}
156
 
157
/**
158
 * translates all expressions based on the translation xml file<br>
159
 * translation expressions must be in the format &lt;span class="lang_???"&gt;&lt;/span&gt;, where ??? is
160
 * the number of the translated expression in the xml file<br><br>if a translated expression is not found in the xml
161
 * file nothing would be translated, so the initial value which is inside the span tag is displayed
162
 * @param {String} [plugin] name of the plugin
163
 */
164
function changeLanguage(plugin) {
165
    var langarrId = current_language + "_";
166
 
167
    if (plugin === undefined) {
168
        langarrId += "phpSysInfo";
169
    } else {
170
        langarrId += plugin;
171
    }
172
 
173
    if (langxml[langarrId] !== undefined) {
174
        changeSpanLanguage(plugin);
175
    } else {
176
        langxml.push(langarrId);
177
        getLanguage(plugin, langarrId);
178
    }
179
}
180
 
181
function changeSpanLanguage(plugin) {
182
    var langId = "", langStr = "", langarrId = current_language + "_";
183
 
184
    if (plugin === undefined) {
185
        langarrId += "phpSysInfo";
186
        $('span[class*=lang_]').each(function translate(i) {
187
            langId = this.className.substring(5);
188
            if (langId.indexOf('plugin_') !== 0) { //does not begin with plugin_
189
                langStr = langarr[langarrId][langId];
190
                if (langStr !== undefined) {
191
                    if (langStr.length > 0) {
192
                        this.innerHTML = langStr;
193
                    }
194
                }
195
            }
196
        });
197
        $("#select").css( "display", "table-cell" ); //show if any language loaded
198
        $("#output").show();
199
    } else {
200
        langarrId += plugin;
201
        $('span[class*=lang_plugin_'+plugin.toLowerCase()+'_]').each(function translate(i) {
202
            langId = this.className.substring(5);
203
            langStr = langarr[langarrId][langId];
204
            if (langStr !== undefined) {
205
                if (langStr.length > 0) {
206
                    this.innerHTML = langStr;
207
                }
208
            }
209
        });
210
        $('#panel_'+plugin.toLowerCase()).show(); //show plugin if any language loaded
211
    }
212
}
213
 
214
function reload(initiate) {
215
    $("#errorbutton").css("visibility", "hidden");
216
    $("#errorbutton").css('cursor', 'default');
217
    $("#errorbutton").attr('data-toggle', '');
218
    $("#errors").empty();
219
    $.ajax({
220
        dataType: "json",
221
        url: "xml.php?json",
222
        error: function(jqXHR, status, thrownError) {
223
            if ((status === "parsererror") && (typeof(xmlDoc = $.parseXML(jqXHR.responseText)) === "object")) {
224
                var errs = 0;
225
                try {
226
                    $(xmlDoc).find("Error").each(function() {
227
                        $("#errors").append("<li><b>"+$(this)[0].attributes.Function.nodeValue+"</b> - "+$(this)[0].attributes.Message.nodeValue.replace(/\n/g, "<br>")+"</li><br>");
228
                        errs++;
229
                    });
230
                }
231
                catch (err) {
232
                }
233
                if (errs > 0) {
234
                    $("#errorbutton").attr('data-toggle', 'modal');
235
                    $("#errorbutton").css('cursor', 'pointer');
236
                    $("#errorbutton").css("visibility", "visible");
237
                }
238
            }
239
        },
240
        success: function (data) {
241
            var refrtime;
242
//            console.log(data);
243
//            data_dbg = data;
244
            if ((typeof(initiate) === 'boolean') && (data.Options !== undefined) && (data.Options["@attributes"] !== undefined) && ((refrtime = data.Options["@attributes"].refresh) !== undefined) && (refrtime !== "0")) {
245
                    if ((initiate === false) && (typeof(refrTimer) === 'number')) {
246
                        clearInterval(refrTimer);
247
                    }
248
                    refrTimer = setInterval(reload, refrtime);
249
            }
250
            renderErrors(data);
251
            renderVitals(data);
252
            renderHardware(data);
253
            renderMemory(data);
254
            renderFilesystem(data);
255
            renderNetwork(data);
256
            renderVoltage(data);
257
            renderTemperature(data);
258
            renderFans(data);
259
            renderPower(data);
260
            renderCurrent(data);
261
            renderOther(data);
262
            renderUPS(data);
263
            changeLanguage();
264
        }
265
    });
266
 
267
    for (var i = 0; i < plugins.length; i++) {
268
        plugin_request(plugins[i]);
269
        if ($("#reload_"+plugins[i]).length > 0) {
270
            $("#reload_"+plugins[i]).attr("title", "reload");
271
        }
272
 
273
    }
274
 
275
    if ((typeof(initiate) === 'boolean') && (initiate === true)) {
276
        for (var j = 0; j < plugins.length; j++) {
277
            if ($("#reload_"+plugins[j]).length > 0) {
278
                $("#reload_"+plugins[j]).click(clickfunction());
279
            }
280
        }
281
    }
282
}
283
 
284
function clickfunction(){
285
    return function(){
286
        plugin_request(this.id.substring(7)); //cut "reload_" from name
287
        $(this).attr("title", datetime());
288
    };
289
}
290
 
291
/**
292
 * load the plugin json via ajax
293
 */
294
function plugin_request(pluginname) {
295
 
296
    $.ajax({
297
         dataType: "json",
298
         url: "xml.php?plugin=" + pluginname + "&json",
299
         pluginname: pluginname,
300
         success: function (data) {
301
            try {
302
                for (var propertyName in data.Plugins) {
303
                    if ((data.Plugins[propertyName]["@attributes"] !== undefined) &&
304
                       ((hostname = data.Plugins[propertyName]["@attributes"].Hostname) !== undefined)) {
305
                        $('span[class=hostname_' + pluginname + ']').html(hostname);
306
                    }
307
                    break;
308
                }
309
                // dynamic call
310
                window['renderPlugin_' + this.pluginname](data);
311
                changeLanguage(this.pluginname);
312
                plugin_liste.pushIfNotExist(this.pluginname);
313
            }
314
            catch (err) {
315
            }
316
            renderErrors(data);
317
        }
318
    });
319
}
320
 
321
 
322
$(document).ready(function () {
323
    var old_template = null, cookie_template = null, cookie_language = null, plugtmp = "", blocktmp = "", ua = null, useragent = navigator.userAgent;
324
    var scrollDiv, scrollbarWidth = 0; 
325
 
326
    scrollDiv = document.createElement('div');
327
    scrollDiv.style.cssText = 'position:absolute;top:-9999px;width:50px;height:50px;overflow:scroll';
328
    document.body.appendChild(scrollDiv);
329
    scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
330
    document.body.removeChild(scrollDiv);
331
 
332
    // When the user clicks on the button, open the modal
333
    $('#errorbutton').click(function() {
334
      $('#errors-dialog').css("display","block");;
335
      $('body').css('overflow','hidden');
336
      $('body').css('padding-right',scrollbarWidth+'px');
337
      $('.navbar').css('padding-right',parseFloat($('.navbar').css('padding-right'))+scrollbarWidth+'px')
338
    });
339
 
340
    // When the user clicks on <span> (x), close the modal
341
    $('.close').click(function() {
342
      $('#errors-dialog').css("display","none");
343
      $('body').css('overflow','visible');
344
      $('body').css('padding-right','0');
345
      $('.navbar').css('padding-right',parseFloat($('.navbar').css('padding-right'))-scrollbarWidth+'px')
346
    });
347
 
348
    // When the user clicks anywhere outside of the modal, close it
349
    $('.modal').click(function(event) {
350
      if ($(event.target).hasClass('modal')) {
351
        $('#errors-dialog').css("display","none");
352
        $('body').css('overflow','visible');
353
        $('body').css('padding-right','0');
354
        $('.navbar').css('padding-right',parseFloat($('.navbar').css('padding-right'))-scrollbarWidth+'px')
355
      }
356
    });
357
 
358
    if ($("#hideBootstrapLoader").val().toString()!=="true") {
359
        $(document).ajaxStart(function () {
360
            $("#loader").css("visibility", "visible");
361
        });
362
        $(document).ajaxStop(function () {
363
            $("#loader").css("visibility", "hidden");
364
        });
365
    }
366
 
367
    if ((ua=useragent.match(/Midori\/(\d+)\.?(\d+)?/)) !== null) {
368
        if ((ua[1]==0) && (ua.length==3) && (ua[2]<=4)) {
369
            $("#PSI_CSS_Fix")[0].setAttribute('href', 'templates/bootstrap/vendor/midori04.css');
370
        } else if ((ua[1]==0) && (ua.length==3) && (ua[2]==5)) {
371
            $("#PSI_CSS_Fix")[0].setAttribute('href', 'templates/bootstrap/vendor/midori05.css');
372
        }
373
    } else if ((ua=useragent.match(/\(KHTML, like Gecko\) Version\/(\d+)\.[\d\.]+ (Mobile\/\S+ )?Safari\//)) !== null) {
374
        if (ua[1]<=5) {
375
            $("#PSI_CSS_Fix")[0].setAttribute('href', 'templates/bootstrap/vendor/safari5.css');
376
        } else if (ua[1]<=8) {
377
            $("#PSI_CSS_Fix")[0].setAttribute('href', 'templates/bootstrap/vendor/safari8.css');
378
        }
379
    } else if ((ua=useragent.match(/Firefox\/(\d+)\.[\d\.]+/)) !== null) {
380
        if (ua[1]<=15) {
381
            $("#PSI_CSS_Fix")[0].setAttribute('href', 'templates/bootstrap/vendor/firefox15.css');
382
        } else if (ua[1]<=20) {
383
            $("#PSI_CSS_Fix")[0].setAttribute('href', 'templates/bootstrap/vendor/firefox20.css');
384
        } else if (ua[1]<=27) {
385
            $("#PSI_CSS_Fix")[0].setAttribute('href', 'templates/bootstrap/vendor/firefox27.css');
386
        } else if (ua[1]==28) {
387
            $("#PSI_CSS_Fix")[0].setAttribute('href', 'templates/bootstrap/vendor/firefox28.css');
388
        }
389
    } else if ((ua=useragent.match(/Chrome\/(\d+)\.[\d\.]+/)) !== null) {
390
        if (ua[1]<=25) {
391
            $("#PSI_CSS_Fix")[0].setAttribute('href', 'templates/bootstrap/vendor/chrome25.css');
392
        } else if (ua[1]<=28) {
393
            $("#PSI_CSS_Fix")[0].setAttribute('href', 'templates/bootstrap/vendor/chrome28.css');
394
        }
395
    } else if ((ua=useragent.match(/^Opera\/.*Version\/(\d+)\.[\d\.]+$/)) !== null) {
396
        if (ua[1]<=11) {
397
            $("#PSI_CSS_Fix")[0].setAttribute('href', 'templates/bootstrap/vendor/opera11.css');
398
        }
399
    }
400
 
401
    $(window).resize();
402
 
403
    sorttable.init();
404
 
405
    showCPUListExpanded = $("#showCPUListExpanded").val().toString()==="true";
406
    showCPUInfoExpanded = $("#showCPUInfoExpanded").val().toString()==="true";
407
    showNetworkInfosExpanded = $("#showNetworkInfosExpanded").val().toString()==="true";
408
    showCPULoadCompact = $("#showCPULoadCompact").val().toString()==="true";
409
    switch ($("#showNetworkActiveSpeed").val().toString()) {
410
        case "bps":  showNetworkActiveSpeed = 2;
411
                      break;
412
        case "true": showNetworkActiveSpeed = 1;
413
                      break;
414
        default:     showNetworkActiveSpeed = 0;
415
    }
416
 
417
    blocktmp = $("#blocks").val().toString();
418
    if (blocktmp.length >0 ){
419
        if (blocktmp === "true") {
420
            blocks[0] = "true";
421
        } else {
422
            blocks = blocktmp.split(',');
423
            var j = 0;
424
            for (var i = 0; i < blocks.length; i++) {
425
                if ($("#block_"+blocks[i]).length > 0) {
426
                    $("#output").children().eq(j).before($("#block_"+blocks[i]));
427
                    j++;
428
                }
429
            }
430
        }
431
    }
432
 
433
    plugtmp = $("#plugins").val().toString();
434
    if (plugtmp.length >0 ){
435
        plugins = plugtmp.split(',');
436
    }
437
 
438
 
439
    if ($("#language option").length < 2) {
440
        current_language = $("#language").val().toString();
441
/* not visible any objects
442
        changeLanguage();
443
*/
444
/* plugin_liste not initialized yet
445
        for (var i = 0; i < plugin_liste.length; i++) {
446
            changeLanguage(plugin_liste[i]);
447
        }
448
*/
449
    } else {
450
        cookie_language = readCookie("psi_language");
451
        if (cookie_language !== null) {
452
            current_language = cookie_language;
453
            $("#language").val(current_language);
454
        } else {
455
            current_language = $("#language").val().toString();
456
        }
457
/* not visible any objects
458
        changeLanguage();
459
*/
460
/* plugin_liste not initialized yet
461
        for (var i = 0; i < plugin_liste.length; i++) {
462
            changeLanguage(plugin_liste[i]);
463
        }
464
*/
465
        $("#langblock").css( "display", "inline-block" );
466
 
467
        $("#language").change(function changeLang() {
468
            current_language = $("#language").val().toString();
469
            createCookie('psi_language', current_language, 365);
470
            changeLanguage();
471
            for (var i = 0; i < plugin_liste.length; i++) {
472
                changeLanguage(plugin_liste[i]);
473
            }
474
            return false;
475
        });
476
    }
477
    if ($("#template option").length < 2) {
478
        switchStyle($("#template").val().toString());
479
    } else {
480
        cookie_template = readCookie("psi_bootstrap_template");
481
        if (cookie_template !== null) {
482
            old_template = $("#template").val();
483
            $("#template").val(cookie_template);
484
            if ($("#template").val() === null) {
485
                $("#template").val(old_template);
486
            }
487
        }
488
        switchStyle($("#template").val().toString());
489
 
490
        $("#tempblock").css( "display", "inline-block" );
491
 
492
        $("#template").change(function changeTemplate() {
493
            switchStyle($("#template").val().toString());
494
            createCookie('psi_bootstrap_template', $("#template").val().toString(), 365);
495
            return false;
496
        });
497
    }
498
 
499
    reload(true);
500
 
501
    $(".logo").click(function () {
502
        reload(false);
503
    });
504
});
505
 
506
Array.prototype.push_attrs=function(element) {
507
    for (var i = 0; i < element.length ; i++) {
508
        this.push(element[i]["@attributes"]);
509
    }
510
    return i;
511
};
512
 
513
function full_addr(ip_string) {
514
    var wrongvalue = false;
515
    ip_string = $.trim(ip_string).toLowerCase();
516
    // ipv4 notation
517
    if (ip_string.match(/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$)/)) {
518
        ip_string ='::ffff:' + ip_string;
519
    }
520
    // replace ipv4 address if any
521
    var ipv4 = ip_string.match(/(.*:)([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$)/);
522
    if (ipv4) {
523
        ip_string = ipv4[1];
524
        ipv4 = ipv4[2].match(/[0-9]+/g);
525
        for (var i = 0;i < 4;i ++) {
526
            var byte = parseInt(ipv4[i], 10);
527
            if (byte<256) {
528
                ipv4[i] = ("0" + byte.toString(16)).substr(-2);
529
            } else {
530
                wrongvalue = true;
531
                break;
532
            }
533
        }
534
        if (wrongvalue) {
535
            ip_string = '';
536
        } else {
537
            ip_string += ipv4[0] + ipv4[1] + ':' + ipv4[2] + ipv4[3];
538
        }
539
    }
540
 
541
    if (ip_string === '') {
542
        return '';
543
    }
544
    // take care of leading and trailing ::
545
    ip_string = ip_string.replace(/^:|:$/g, '');
546
 
547
    var ipv6 = ip_string.split(':');
548
 
549
    for (var li = 0; li < ipv6.length; li ++) {
550
        var hex = ipv6[li];
551
        if (hex !== "") {
552
            if (!hex.match(/^[0-9a-f]{1,4}$/)) {
553
                wrongvalue = true;
554
                break;
555
            }
556
            // normalize leading zeros
557
            ipv6[li] = ("0000" + hex).substr(-4);
558
        }
559
        else {
560
            // normalize grouped zeros ::
561
            hex = [];
562
            for (var j = ipv6.length; j <= 8; j ++) {
563
                hex.push('0000');
564
            }
565
            ipv6[li] = hex.join(':');
566
        }
567
    }
568
    if (!wrongvalue) {
569
        var out = ipv6.join(':');
570
        if (out.length == 39) {
571
            return out;
572
        } else {
573
            return '';
574
        }
575
    } else {
576
        return '';
577
    }
578
}
579
 
580
sorttable.sort_ip=function(a,b) {
581
    var x = full_addr(a[0]);
582
    var y = full_addr(b[0]);
583
    if ((x === '') || (y === '')) {
584
        x = a[0];
585
        y = b[0];
586
    }
587
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
588
};
589
 
590
function items(data) {
591
    if (data !== undefined) {
592
        if ((data.length > 0) &&  (data[0] !== undefined) && (data[0]["@attributes"] !== undefined)) {
593
            return data;
594
        } else if (data["@attributes"] !== undefined ) {
595
            return [data];
596
        } else {
597
            return [];
598
        }
599
    } else {
600
        return [];
601
    }
602
}
603
 
604
function renderVitals(data) {
605
    var hostname = "", ip = "";
606
 
607
    if ((blocks.length <= 0) || ((blocks[0] !== "true") && ($.inArray('vitals', blocks) < 0))) {
608
        $("#block_vitals").remove();
609
        if ((data.Vitals !== undefined) && (data.Vitals["@attributes"] !== undefined) && ((hostname = data.Vitals["@attributes"].Hostname) !== undefined) && ((ip = data.Vitals["@attributes"].IPAddr) !== undefined)) {
610
            document.title = "System information: " + hostname + " (" + ip + ")";
611
        }
612
        return;
613
    }
614
 
615
    var directives = {
616
        Uptime: {
617
            html: function () {
618
                return formatUptime(this.Uptime);
619
            }
620
        },
621
        LastBoot: {
622
            text: function () {
623
                var lastboot;
624
                var timestamp = 0;
625
                var datetimeFormat;
626
                if ((data.Generation !== undefined) && (data.Generation["@attributes"] !== undefined) && (data.Generation["@attributes"].timestamp !== undefined) ) {
627
                    timestamp = parseInt(data.Generation["@attributes"].timestamp, 10) * 1000; //server time
628
                    if (isNaN(timestamp)) timestamp = Number(new Date()); //client time
629
                } else {
630
                    timestamp = Number(new Date()); //client time
631
                }
632
                lastboot = new Date(timestamp - (parseInt(this.Uptime, 10) * 1000));
633
                if (((datetimeFormat = data.Options["@attributes"].datetimeFormat) !== undefined) && (datetimeFormat.toLowerCase() === "locale")) {
634
                    return lastboot.toLocaleString();
635
                } else {
636
                    if (typeof(lastboot.toUTCString) === "function") {
637
                        return lastboot.toUTCString();
638
                    } else {
639
                    //deprecated
640
                        return lastboot.toGMTString();
641
                    }
642
                }
643
            }
644
        },
645
        Distro: {
646
            html: function () {
647
                return '<table class="borderless table-hover table-nopadding" style="width:100%;"><tr><td style="padding-right:4px!important;width:32px;"><img src="gfx/images/' + this.Distroicon + '" alt="" title="' + this.Distroicon + '" style="width:32px;height:32px;" /></td><td style="vertical-align:middle;">' + this.Distro + '</td></tr></table>';
648
            }
649
        },
650
        OS: {
651
            html: function () {
652
                return '<table class="borderless table-hover table-nopadding" style="width:100%;"><tr><td style="padding-right:4px!important;width:32px;"><img src="gfx/images/' + this.OS + '.png" alt="" title="' + this.OS + '.png" style="width:32px;height:32px;" /></td><td style="vertical-align:middle;">' + this.OS + '</td></tr></table>';
653
            }
654
        },
655
        LoadAvg: {
656
            html: function () {
657
                if (this.CPULoad !== undefined) {
658
                    return '<table class="borderless table-hover table-nopadding" style="width:100%;"><tr><td style="padding-right:4px!important;width:50%;">'+this.LoadAvg + '</td><td><div class="progress">' +
659
                        '<div class="progress-bar progress-bar-info" style="width:' + round(this.CPULoad,0) + '%;"></div>' +
660
                        '</div><div class="percent">' + round(this.CPULoad,0) + '%</div></td></tr></table>';
661
                } else {
662
                    return this.LoadAvg;
663
                }
664
            }
665
        },
666
        Processes: {
667
            html: function () {
668
                var processes = 0, psarray = [0,0,0,0,0,0];
669
                var not_first = false;
670
                processes = parseInt(this.Processes, 10);
671
                if (processes > 0) {
672
                    if (this.ProcessesRunning !== undefined) {
673
                        psarray[0] = parseInt(this.ProcessesRunning, 10);
674
                    }
675
                    if (this.ProcessesSleeping !== undefined) {
676
                        psarray[1] = parseInt(this.ProcessesSleeping, 10);
677
                    }
678
                    if (this.ProcessesStopped !== undefined) {
679
                        psarray[2] = parseInt(this.ProcessesStopped, 10);
680
                    }
681
                    if (this.ProcessesZombie !== undefined) {
682
                        psarray[3] = parseInt(this.ProcessesZombie, 10);
683
                    }
684
                    if (this.ProcessesWaiting !== undefined) {
685
                        psarray[4] = parseInt(this.ProcessesWaiting, 10);
686
                    }
687
                    if (this.ProcessesOther !== undefined) {
688
                        psarray[5] = parseInt(this.ProcessesOther, 10);
689
                    }
690
                    if (psarray[0] || psarray[1] || psarray[2] || psarray[3] || psarray[4] || psarray[5]) {
691
                        processes += " (";
692
                        var idlist = {0:111,1:112,2:113,3:114,4:115,5:116};
693
                        for (var proc_type in idlist) {
694
                            if (psarray[proc_type]) {
695
                                if (not_first) {
696
                                    processes += ", ";
697
                                }
698
                                processes += psarray[proc_type] + String.fromCharCode(160) + genlang(idlist[proc_type]);
699
                                not_first = true;
700
                            }
701
                        }
702
                        processes += ")";
703
                    }
704
                }
705
                return processes;
706
            }
707
        }
708
    };
709
 
710
    if ((data.Vitals["@attributes"].LoadAvg === '') && (data.Vitals["@attributes"].CPULoad === undefined)) {
711
        $("#tr_LoadAvg").hide();
712
    }
713
    if (data.Vitals["@attributes"].SysLang === undefined) {
714
        $("#tr_SysLang").hide();
715
    }
716
    if (data.Vitals["@attributes"].CodePage === undefined) {
717
        $("#tr_CodePage").hide();
718
    }
719
    if (data.Vitals["@attributes"].Processes === undefined) {
720
        $("#tr_Processes").hide();
721
    }
722
    $('#vitals').render(data.Vitals["@attributes"], directives);
723
 
724
    if ((data.Vitals !== undefined) && (data.Vitals["@attributes"] !== undefined) && ((hostname = data.Vitals["@attributes"].Hostname) !== undefined) && ((ip = data.Vitals["@attributes"].IPAddr) !== undefined)) {
725
        document.title = "System information: " + hostname + " (" + ip + ")";
726
    }
727
 
728
    $("#block_vitals").show();
729
}
730
 
731
function renderHardware(data) {
732
    var hw_type, datas, proc_param, i;
733
 
734
    if ((blocks.length <= 0) || ((blocks[0] !== "true") && ($.inArray('hardware', blocks) < 0))) {
735
        $("#block_hardware").remove();
736
        return;
737
    }
738
 
739
    var directives = {
740
        Model: {
741
            text: function () {
742
                return this.Model;
743
            }
744
        },
745
        CpuSpeed: {
746
            html: function () {
747
                return formatHertz(this.CpuSpeed);
748
            }
749
        },
750
        CpuSpeedMax: {
751
            html: function () {
752
                return formatHertz(this.CpuSpeedMax);
753
            }
754
        },
755
        CpuSpeedMin: {
756
            html: function () {
757
                return formatHertz(this.CpuSpeedMin);
758
            }
759
        },
760
        Cache: {
761
            html: function () {
762
                return formatBytes(this.Cache, data.Options["@attributes"].byteFormat);
763
            }
764
        },
765
        BusSpeed: {
766
            html: function () {
767
                return formatHertz(this.BusSpeed);
768
            }
769
        },
770
        Cputemp: {
771
            html: function () {
772
                return formatTemp(this.Cputemp, data.Options["@attributes"].tempFormat);
773
            }
774
        },
775
        Voltage: {
776
            html: function() {
777
                return round(this.Voltage, 2) + String.fromCharCode(160) + genlang(62); //V
778
            }
779
        },
780
        Bogomips: {
781
            text: function () {
782
                return parseInt(this.Bogomips, 10);
783
            }
784
        },
785
        Load: {
786
            html: function () {
787
                return '<div class="progress">' +
788
                        '<div class="progress-bar progress-bar-info" style="width:' + round(this.Load,0) + '%;"></div>' +
789
                        '</div><div class="percent">' + round(this.Load,0) + '%</div>';
790
            }
791
        }
792
    };
793
 
794
    var hw_directives = {
795
        hwName: {
796
            html: function() {
797
                return this.Name;
798
            }
799
        },
800
        hwCount: {
801
            text: function() {
802
                if ((this.Count !== undefined) && !isNaN(this.Count) && (parseInt(this.Count, 10)>1)) {
803
                    return parseInt(this.Count, 10);
804
                } else {
805
                    return "";
806
                }
807
            }
808
        }
809
    };
810
 
811
    var mem_directives = {
812
        Speed: {
813
            html: function() {
814
                return formatMTps(this.Speed);
815
            }
816
        },
817
        Voltage: {
818
            html: function() {
819
                return round(this.Voltage, 2) + String.fromCharCode(160) + genlang(62); //V
820
            }
821
        },
822
        Capacity: {
823
            html: function () {
824
                return formatBytes(this.Capacity, data.Options["@attributes"].byteFormat);
825
            }
826
        }
827
    };
828
 
829
    var dev_directives = {
830
        Speed: {
831
            html: function() {
832
                return formatBPS(1000000*this.Speed);
833
            }
834
        },
835
        Capacity: {
836
            html: function () {
837
                return formatBytes(this.Capacity, data.Options["@attributes"].byteFormat);
838
            }
839
        }
840
    };
841
 
842
    var html="";
843
 
844
    if (data.Hardware["@attributes"] !== undefined) {
845
        if (data.Hardware["@attributes"].Name !== undefined) {
846
            html+="<tr id=\"hardware-Machine\">";
847
            html+="<th style=\"width:8%;\">"+genlang(107)+"</th>"; //Machine
848
            html+="<td colspan=\"2\"><span data-bind=\"Name\"></span></td>";
849
            html+="</tr>";
850
        }
851
        if (data.Hardware["@attributes"].Virtualizer !== undefined) {
852
            html+="<tr id=\"hardware-Virtualizer\">";
853
            html+="<th style=\"width:8%;\">"+genlang(134)+"</th>"; //Virtualizer
854
            html+="<td colspan=\"2\"><span data-bind=\"Virtualizer\"></span></td>";
855
            html+="</tr>";
856
        }
857
    }
858
 
859
    var paramlist = {CpuSpeed:13,CpuSpeedMax:100,CpuSpeedMin:101,Cache:15,Virt:94,BusSpeed:14,Voltage:52,Bogomips:16,Cputemp:51,Manufacturer:122,Load:9};
860
    try {
861
        datas = items(data.Hardware.CPU.CpuCore);
862
        for (i = 0; i < datas.length; i++) {
863
             if (i === 0) {
864
                html+="<tr id=\"hardware-CPU\" class=\"treegrid-CPU\">";
865
                html+="<th>CPU</th>";
866
                html+="<td><span class=\"treegrid-span\">" + genlang(119) + ":</span></td>"; //Number of processors
867
                html+="<td class=\"rightCell\"><span id=\"CPUCount\"></span></td>";
868
                html+="</tr>";
869
            }
870
            html+="<tr id=\"hardware-CPU-" + i +"\" class=\"treegrid-CPU-" + i +" treegrid-parent-CPU\">";
871
            html+="<th></th>";
872
            if (showCPULoadCompact && (datas[i]["@attributes"].Load !== undefined)) {
873
                html+="<td><span class=\"treegrid-span\" data-bind=\"Model\"></span></td>";
874
                html+="<td style=\"width:15%;\" class=\"rightCell\"><span data-bind=\"Load\"></span></td>";
875
            } else {
876
                html+="<td colspan=\"2\"><span class=\"treegrid-span\" data-bind=\"Model\"></span></td>";
877
            }
878
            html+="</tr>";
879
            for (proc_param in paramlist) {
880
                if (((proc_param !== 'Load') || !showCPULoadCompact) && (datas[i]["@attributes"][proc_param] !== undefined)) {
881
                    html+="<tr id=\"hardware-CPU-" + i + "-" + proc_param + "\" class=\"treegrid-parent-CPU-" + i +"\">";
882
                    html+="<th></th>";
883
                    html+="<td><span class=\"treegrid-span\">" + genlang(paramlist[proc_param]) + "<span></td>";
884
                    html+="<td class=\"rightCell\"><span data-bind=\"" + proc_param + "\"></span></td>";
885
                    html+="</tr>";
886
                }
887
            }
888
 
889
        }
890
    }
891
    catch (err) {
892
        $("#hardware-CPU").hide();
893
    }
894
 
895
    var devparamlist = {Capacity:43,Manufacturer:122,Product:123,Speed:129,Voltage:52,Serial:124};
896
    for (hw_type in {MEM:0,PCI:1,IDE:2,SCSI:3,NVMe:4,USB:5,TB:6,I2C:7}) {
897
        try {
898
            if (hw_type == 'MEM') {
899
                datas = items(data.Hardware[hw_type].Chip);
900
            } else {
901
                datas = items(data.Hardware[hw_type].Device);
902
            }
903
            for (i = 0; i < datas.length; i++) {
904
                if (i === 0) {
905
                    html+="<tr id=\"hardware-" + hw_type + "\" class=\"treegrid-" + hw_type + "\">";
906
                    html+="<th>" + hw_type + "</th>";
907
                    if (hw_type == 'MEM') {
908
                        html+="<td><span class=\"treegrid-span\">" + genlang('128') + ":</span></td>"; //Number of memories
909
                    } else {
910
                        html+="<td><span class=\"treegrid-span\">" + genlang('120') + ":</span></td>"; //Number of devices
911
                    }
912
                    html+="<td class=\"rightCell\"><span id=\"" + hw_type + "Count\"></span></td>";
913
                    html+="</tr>";
914
                }
915
                html+="<tr id=\"hardware-" + hw_type + "-" + i +"\" class=\"treegrid-" + hw_type + "-" + i +" treegrid-parent-" + hw_type + "\">";
916
                html+="<th></th>";
917
                html+="<td><span class=\"treegrid-span\" data-bind=\"hwName\"></span></td>";
918
                html+="<td class=\"rightCell\"><span data-bind=\"hwCount\"></span></td>";
919
                html+="</tr>";
920
                for (proc_param in devparamlist) {
921
                    if (datas[i]["@attributes"][proc_param] !== undefined) {
922
                        html+="<tr id=\"hardware-" + hw_type +"-" + i + "-" + proc_param + "\" class=\"treegrid-parent-" + hw_type +"-" + i +"\">";
923
                        html+="<th></th>";
924
                        html+="<td><span class=\"treegrid-span\">" + genlang(devparamlist[proc_param]) + "<span></td>";
925
                        html+="<td class=\"rightCell\"><span data-bind=\"" + proc_param + "\"></span></td>";
926
                        html+="</tr>";
927
                    }
928
                }
929
            }
930
        }
931
        catch (err) {
932
            $("#hardware-data"+hw_type).hide();
933
        }
934
    }
935
    $("#hardware-data").empty().append(html);
936
 
937
 
938
    if (data.Hardware["@attributes"] !== undefined) {
939
        if (data.Hardware["@attributes"].Name !== undefined) {
940
            $('#hardware-Machine').render(data.Hardware["@attributes"]);
941
        }
942
        if (data.Hardware["@attributes"].Virtualizer !== undefined) {
943
            $('#hardware-Virtualizer').render(data.Hardware["@attributes"]);
944
        }
945
    }
946
 
947
    try {
948
        datas = items(data.Hardware.CPU.CpuCore);
949
        for (i = 0; i < datas.length; i++) {
950
            $('#hardware-CPU-'+ i).render(datas[i]["@attributes"], directives);
951
            for (proc_param in paramlist) {
952
                if (((proc_param !== 'Load') || !showCPULoadCompact) && (datas[i]["@attributes"][proc_param] !== undefined)) {
953
                    $('#hardware-CPU-'+ i +'-'+proc_param).render(datas[i]["@attributes"], directives);
954
                }
955
            }
956
        }
957
        if (i > 0) {
958
            $("#CPUCount").html(i);
959
        }
960
    }
961
    catch (err) {
962
        $("#hardware-CPU").hide();
963
    }
964
 
965
    var licz;
966
    for (hw_type in {MEM:0,PCI:1,IDE:2,SCSI:3,NVMe:4,USB:5,TB:6,I2C:7}) {
967
        try {
968
            licz = 0;
969
            if (hw_type == 'MEM') {
970
                datas = items(data.Hardware[hw_type].Chip);
971
            } else {
972
                datas = items(data.Hardware[hw_type].Device);
973
            }
974
            for (i = 0; i < datas.length; i++) {
975
                $('#hardware-'+hw_type+'-'+ i).render(datas[i]["@attributes"], hw_directives);
976
                if ((datas[i]["@attributes"].Count !== undefined) && !isNaN(datas[i]["@attributes"].Count) && (parseInt(datas[i]["@attributes"].Count, 10)>1)) {
977
                    licz += parseInt(datas[i]["@attributes"].Count, 10);
978
                } else {
979
                    licz++;
980
                }
981
                if (hw_type == 'MEM') {
982
                    for (proc_param in devparamlist) {
983
                        if ((datas[i]["@attributes"][proc_param] !== undefined)) {
984
                            $('#hardware-'+hw_type+'-'+ i +'-'+proc_param).render(datas[i]["@attributes"], mem_directives);
985
                        }
986
                    }
987
                } else {
988
                    for (proc_param in devparamlist) {
989
                        if ((datas[i]["@attributes"][proc_param] !== undefined)) {
990
                            $('#hardware-'+hw_type+'-'+ i +'-'+proc_param).render(datas[i]["@attributes"], dev_directives);
991
                        }
992
                    }
993
                }
994
            }
995
            if (i > 0) {
996
                $("#" + hw_type + "Count").html(licz);
997
            }
998
        }
999
        catch (err) {
1000
            $("#hardware-"+hw_type).hide();
1001
        }
1002
    }
1003
    $('#hardware').treegrid({
1004
        initialState: 'collapsed',
1005
        expanderExpandedClass: 'normalicon normalicon-down',
1006
        expanderCollapsedClass: 'normalicon normalicon-right'
1007
    });
1008
    if (showCPUListExpanded) {
1009
        try {
1010
            $('#hardware-CPU').treegrid('expand');
1011
        }
1012
        catch (err) {
1013
        }
1014
    }
1015
    if (showCPUInfoExpanded && showCPUListExpanded) {
1016
        try {
1017
            datas = items(data.Hardware.CPU.CpuCore);
1018
            for (i = 0; i < datas.length; i++) {
1019
                $('#hardware-CPU-'+i).treegrid('expand');
1020
            }
1021
        }
1022
        catch (err) {
1023
        }
1024
    }
1025
    $("#block_hardware").show();
1026
}
1027
 
1028
function renderMemory(data) {
1029
    if ((blocks.length <= 0) || ((blocks[0] !== "true") && ($.inArray('memory', blocks) < 0))) {
1030
        $("#block_memory").remove();
1031
        return;
1032
    }
1033
 
1034
    var directives = {
1035
        Total: {
1036
            html: function () {
1037
                return formatBytes(this["@attributes"].Total, data.Options["@attributes"].byteFormat);
1038
            }
1039
        },
1040
        Free: {
1041
            html: function () {
1042
                return formatBytes(this["@attributes"].Free, data.Options["@attributes"].byteFormat);
1043
            }
1044
        },
1045
        Used: {
1046
            html: function () {
1047
                return formatBytes(this["@attributes"].Used, data.Options["@attributes"].byteFormat);
1048
            }
1049
        },
1050
        Usage: {
1051
            html: function () {
1052
                if ((this.Details === undefined) || (this.Details["@attributes"] === undefined)) {
1053
                    return '<div class="progress">' +
1054
                        '<div class="progress-bar progress-bar-info" style="width:' + this["@attributes"].Percent + '%;"></div>' +
1055
                        '</div><div class="percent">' + this["@attributes"].Percent + '%</div>';
1056
                } else {
1057
                    var rest = parseInt(this["@attributes"].Percent, 10);
1058
                    var html = '<div class="progress">';
1059
                    if ((this.Details["@attributes"].AppPercent !== undefined) && (this.Details["@attributes"].AppPercent > 0)) {
1060
                        html += '<div class="progress-bar progress-bar-info" style="width:' + this.Details["@attributes"].AppPercent + '%;"></div>';
1061
                        rest -= parseInt(this.Details["@attributes"].AppPercent, 10);
1062
                    }
1063
                    if ((this.Details["@attributes"].CachedPercent !== undefined) && (this.Details["@attributes"].CachedPercent > 0)) {
1064
                        html += '<div class="progress-bar progress-bar-warning" style="width:' + this.Details["@attributes"].CachedPercent + '%;"></div>';
1065
                        rest -= parseInt(this.Details["@attributes"].CachedPercent, 10);
1066
                    }
1067
                    if ((this.Details["@attributes"].BuffersPercent !== undefined) && (this.Details["@attributes"].BuffersPercent > 0)) {
1068
                        html += '<div class="progress-bar progress-bar-danger" style="width:' + this.Details["@attributes"].BuffersPercent + '%;"></div>';
1069
                        rest -= parseInt(this.Details["@attributes"].BuffersPercent, 10);
1070
                    }
1071
                    if (rest > 0) {
1072
                        html += '<div class="progress-bar progress-bar-success" style="width:' + rest + '%;"></div>';
1073
                    }
1074
                    html += '</div>';
1075
                    html += '<div class="percent">' + 'Total: ' + this["@attributes"].Percent + '% ' + '<i>(';
1076
                    var not_first = false;
1077
                    if (this.Details["@attributes"].AppPercent !== undefined) {
1078
                        html += '<span class="progress-bar-info">&emsp;</span>&nbsp;' + genlang(64) + ': '+ this.Details["@attributes"].AppPercent + '%'; //Kernel + apps
1079
                        not_first = true;
1080
                    }
1081
                    if (this.Details["@attributes"].CachedPercent !== undefined) {
1082
                        if (not_first) html += ' - ';
1083
                        html += '<span class="progress-bar-warning">&emsp;</span>&nbsp;' + genlang(66) + ': ' + this.Details["@attributes"].CachedPercent + '%'; //Cache
1084
                        not_first = true;
1085
                    }
1086
                    if (this.Details["@attributes"].BuffersPercent !== undefined) {
1087
                        if (not_first) html += ' - ';
1088
                        html += '<span class="progress-bar-danger">&emsp;</span>&nbsp;' + genlang(65) + ': ' + this.Details["@attributes"].BuffersPercent + '%'; //Buffers
1089
                    }
1090
                    html += ')</i></div>';
1091
                    return html;
1092
                }
1093
            }
1094
        },
1095
        Type: {
1096
            html: function () {
1097
                return genlang(28); //Physical Memory
1098
            }
1099
        }
1100
    };
1101
 
1102
    var directive_swap = {
1103
        Total: {
1104
            html: function () {
1105
                return formatBytes(this.Total, data.Options["@attributes"].byteFormat);
1106
            }
1107
        },
1108
        Free: {
1109
            html: function () {
1110
                return formatBytes(this.Free, data.Options["@attributes"].byteFormat);
1111
            }
1112
        },
1113
        Used: {
1114
            html: function () {
1115
                return formatBytes(this.Used, data.Options["@attributes"].byteFormat);
1116
            }
1117
        },
1118
        Usage: {
1119
            html: function () {
1120
                return '<div class="progress">' +
1121
                    '<div class="progress-bar progress-bar-info" style="width:' + this.Percent + '%;"></div>' +
1122
                    '</div><div class="percent">' + this.Percent + '%</div>';
1123
            }
1124
        },
1125
        Name: {
1126
            html: function () {
1127
                return this.Name + '<br>' + ((this.MountPoint !== undefined) ? this.MountPoint : this.MountPointID);
1128
            }
1129
        }
1130
    };
1131
 
1132
    var data_memory = [];
1133
    if (data.Memory.Swap !== undefined) {
1134
        var datas = items(data.Memory.Swap.Mount);
1135
        data_memory.push_attrs(datas);
1136
        $('#swap-data').render(data_memory, directive_swap);
1137
        $('#swap-data').show();
1138
    } else {
1139
        $('#swap-data').hide();
1140
    }
1141
    $('#memory-data').render(data.Memory, directives);
1142
    $("#block_memory").show();
1143
}
1144
 
1145
function renderFilesystem(data) {
1146
    if ((blocks.length <= 0) || ((blocks[0] !== "true") && ($.inArray('filesystem', blocks) < 0))) {
1147
        $("#block_filesystem").remove();
1148
        return;
1149
    }
1150
 
1151
    var directives = {
1152
        Total: {
1153
            html: function () {
1154
                return formatBytes(this.Total, data.Options["@attributes"].byteFormat, (this.Ignore !== undefined) && (this.Ignore > 0) && showtotals);
1155
            }
1156
        },
1157
        Free: {
1158
            html: function () {
1159
                return formatBytes(this.Free, data.Options["@attributes"].byteFormat, (this.Ignore !== undefined) && (this.Ignore > 0) && showtotals);
1160
            }
1161
        },
1162
        Used: {
1163
            html: function () {
1164
                return formatBytes(this.Used, data.Options["@attributes"].byteFormat, (this.Ignore !== undefined) && (this.Ignore >= 3) && showtotals);
1165
            }
1166
        },
1167
        MountPoint: {
1168
            text: function () {
1169
                return ((this.MountPoint !== undefined) ? this.MountPoint : this.MountPointID);
1170
            }
1171
        },
1172
        Name: {
1173
            html: function () {
1174
                return this.Name.replace(/;/g, ";<wbr>") + ((this.MountOptions !== undefined) ? '<br><i>(' + this.MountOptions + ')</i>' : '');
1175
            }
1176
        },
1177
        Percent: {
1178
            html: function () {
1179
                var used1 = Math.max(Math.min((this.Total != 0) ? Math.ceil((this.Used / this.Total) * 100) : 0, 100), 0);
1180
                var used2 = Math.max(Math.min(Math.ceil(this.Percent), 100), 0);
1181
                var used21= used2 - used1;
1182
                if (used21 > 0) {
1183
                    return '
' + '
1184
1185
= parseInt(data.Options["@attributes"].threshold, 10))) ) ? 'progress-bar progress-bar-danger' : 'progress-bar progress-bar-info' ) +
1186
div>' +
1187
'<div class="progress-bar progress-bar-warning" style="width:' + used21 + '% ;"></div>' +
1188
'div><div class="percent">' + this.Percent + '% ' + ((this.Inodes !== undefined) ? '<i>(' + this.Inodes + '%)</i>' : '') + 'div>';
1189
} else {
1190
return '<div class="progress">' + '<div class="' +
1191
( ( ((this.Ignore == undefined) || (this.Ignore < 4)) && ((data.Options["@attributes"].threshold !== undefined) &&
1192
(parseInt(this.Percent, 10) >= parseInt(data.Options["@attributes"].threshold, 10))) ) ? 'progress-bar progress-bar-danger' : 'progress-bar progress-bar-info' ) +
1193
'" style="width:' + used2 + '% ;"></div>' +
1194
'div>' + '<div class="percent">' + this.Percent + '% ' + ((this.Inodes !== undefined) ? '<i>(' + this.Inodes + '%)</i>' : '') + 'div>';
1195
}
1196
}
1197
}
1198
};
1199
 
1200
try {
1201
var fs_data = [];
1202
var datas = items(data.FileSystem.Mount);
1203
var total = {Total:0,Free:0,Used:0};
1204
var showtotals = $("#hideTotals").val().toString()!=="true";
1205
for (var i = 0; i < datas.length; i++) {
1206
fs_data.push(datas[i]["@attributes"]);
1207
if (showtotals) {
1208
if ((datas[i]["@attributes"].Ignore !== undefined) && (datas[i]["@attributes"].Ignore > 0)) {
1209
if (datas[i]["@attributes"].Ignore == 2) {
1210
total.Used += parseInt(datas[i]["@attributes"].Used, 10);
1211
} else if (datas[i]["@attributes"].Ignore == 1) {
1212
total.Total += parseInt(datas[i]["@attributes"].Used, 10);
1213
total.Used += parseInt(datas[i]["@attributes"].Used, 10);
1214
}
1215
} else {
1216
total.Total += parseInt(datas[i]["@attributes"].Total, 10);
1217
total.Free += parseInt(datas[i]["@attributes"].Free, 10);
1218
total.Used += parseInt(datas[i]["@attributes"].Used, 10);
1219
}
1220
total.Percent = (total.Total != 0) ? round(100 - (total.Free / total.Total) * 100, 2) : 0;
1221
}
1222
}
1223
if (i > 0) {
1224
$('#filesystem-data').render(fs_data, directives);
1225
if (showtotals) {
1226
$('#filesystem-foot').render(total, directives);
1227
$('#filesystem-foot').show();
1228
}
1229
$('#filesystem_MountPoint').removeClass("sorttable_sorted"); //reset sort order
1230
// sorttable.innerSortFunction.apply(document.getElementById('filesystem_MountPoint'), []);
1231
sorttable.innerSortFunction.apply($('#filesystem_MountPoint')[0], []);
1232
$("#block_filesystem").show();
1233
} else {
1234
$("#block_filesystem").hide();
1235
}
1236
}
1237
catch (err) {
1238
$("#block_filesystem").hide();
1239
}
1240
}
1241
 
1242
function renderNetwork(data) {
1243
if ((blocks.length <= 0) || ((blocks[0] !== "true") && ($.inArray('network', blocks) < 0))) {
1244
$("#block_network").remove();
1245
return;
1246
}
1247
 
1248
var directives = {
1249
Name: {
1250
text: function () {
1251
if (this.Bridge !== undefined) {
1252
return this.Name + " (" + this.Bridge + ")";
1253
} else {
1254
return this.Name;
1255
}
1256
}
1257
},
1258
RxBytes: {
1259
html: function () {
1260
var htmladd = '';
1261
if (showNetworkActiveSpeed) {
1262
if ((this.RxBytes == 0) && (this.RxRate !== undefined)) {
1263
if (showNetworkActiveSpeed == 2) {
1264
htmladd ="<br><i>("+formatBPS(round(this.RxRate, 2))+")</i>";
1265
} else {
1266
htmladd ="<br><i>("+formatBytes(round(this.RxRate, 2), data.Options["@attributes"].byteFormat)+"/s)</i>";
1267
}
1268
} else if ($.inArray(this.Name, oldnetwork) >= 0) {
1269
var diff, difftime;
1270
if (((diff = this.RxBytes - oldnetwork[this.Name].RxBytes) > 0) && ((difftime = data.Generation["@attributes"].timestamp - oldnetwork[this.Name].timestamp) > 0)) {
1271
if (showNetworkActiveSpeed == 2) {
1272
htmladd ="<br><i>("+formatBPS(round(8*diff/difftime, 2))+")</i>";
1273
} else {
1274
htmladd ="<br><i>("+formatBytes(round(diff/difftime, 2), data.Options["@attributes"].byteFormat)+"/s)</i>";
1275
}
1276
}
1277
}
1278
}
1279
return formatBytes(this.RxBytes, data.Options["@attributes"].byteFormat) + htmladd;
1280
}
1281
},
1282
TxBytes: {
1283
html: function () {
1284
var htmladd = '';
1285
if (showNetworkActiveSpeed) {
1286
if ((this.TxBytes == 0) && (this.TxRate !== undefined)) {
1287
if (showNetworkActiveSpeed == 2) {
1288
htmladd ="<br><i>("+formatBPS(round(this.TxRate, 2))+")</i>";
1289
} else {
1290
htmladd ="<br><i>("+formatBytes(round(this.TxRate, 2), data.Options["@attributes"].byteFormat)+"/s)</i>";
1291
}
1292
} else if ($.inArray(this.Name, oldnetwork) >= 0) {
1293
var diff, difftime;
1294
if (((diff = this.TxBytes - oldnetwork[this.Name].TxBytes) > 0) && ((difftime = data.Generation["@attributes"].timestamp - oldnetwork[this.Name].timestamp) > 0)) {
1295
if (showNetworkActiveSpeed == 2) {
1296
htmladd ="<br><i>("+formatBPS(round(8*diff/difftime, 2))+")</i>";
1297
} else {
1298
htmladd ="<br><i>("+formatBytes(round(diff/difftime, 2), data.Options["@attributes"].byteFormat)+"/s)</i>";
1299
}
1300
}
1301
}
1302
}
1303
return formatBytes(this.TxBytes, data.Options["@attributes"].byteFormat) + htmladd;
1304
}
1305
},
1306
Drops: {
1307
html: function () {
1308
return this.Err + "/<wbr>" + this.Drops;
1309
}
1310
}
1311
};
1312
 
1313
var html = "";
1314
var preoldnetwork = [];
1315
 
1316
try {
1317
var datas = items(data.Network.NetDevice);
1318
for (var i = 0; i < datas.length; i++) {
1319
html+="<tr id=\"network-" + i +"\" class=\"treegrid-network-" + i + "\">";
1320
html+="<td><span class=\"treegrid-spanbold\" data-bind=\"Name\"></span></td>";
1321
html+="<td class=\"rightCell\"><span data-bind=\"RxBytes\"></span></td>";
1322
html+="<td class=\"rightCell\"><span data-bind=\"TxBytes\"></span></td>";
1323
html+="<td class=\"rightCell\"><span data-bind=\"Drops\"></span></td>";
1324
html+="</tr>";
1325
 
1326
var info = datas[i]["@attributes"].Info;
1327
if ( (info !== undefined) && (info !== "") ) {
1328
var infos = info.replace(/:/g, "<wbr>:").split(";"); /* split long addresses */
1329
for (var j = 0; j < infos.length; j++){
1330
html +="<tr class=\"treegrid-parent-network-" + i + "\"><td colspan=\"4\"><span class=\"treegrid-span\">" + infos[j] + "</span></td></tr>";
1331
}
1332
}
1333
}
1334
$("#network-data").empty().append(html);
1335
if (i > 0) {
1336
for (var k = 0; k < datas.length; k++) {
1337
$('#network-' + k).render(datas[k]["@attributes"], directives);
1338
if (showNetworkActiveSpeed) {
1339
preoldnetwork.pushIfNotExist(datas[k]["@attributes"].Name);
1340
preoldnetwork[datas[k]["@attributes"].Name] = {timestamp:data.Generation["@attributes"].timestamp, RxBytes:datas[k]["@attributes"].RxBytes, TxBytes:datas[k]["@attributes"].TxBytes};
1341
}
1342
}
1343
$('#network').treegrid({
1344
initialState: showNetworkInfosExpanded?'expanded':'collapsed',
1345
expanderExpandedClass: 'normalicon normalicon-down',
1346
expanderCollapsedClass: 'normalicon normalicon-right'
1347
});
1348
$("#block_network").show();
1349
} else {
1350
$("#block_network").hide();
1351
}
1352
}
1353
catch (err) {
1354
$("#block_network").hide();
1355
}
1356
 
1357
if (showNetworkActiveSpeed) {
1358
while (oldnetwork.length > 0) {
1359
delete oldnetwork[oldnetwork.length-1]; //remove last object
1360
oldnetwork.pop(); //remove last object reference from array
1361
}
1362
oldnetwork = preoldnetwork;
1363
}
1364
}
1365
 
1366
function renderVoltage(data) {
1367
if ((blocks.length <= 0) || ((blocks[0] !== "true") && ($.inArray('voltage', blocks) < 0))) {
1368
$("#block_voltage").remove();
1369
return;
1370
}
1371
 
1372
var directives = {
1373
Value: {
1374
text: function () {
1375
return (isFinite(this.Value)?round(this.Value,2):"---") + String.fromCharCode(160) + "V";
1376
}
1377
},
1378
Min: {
1379
text: function () {
1380
if (this.Min !== undefined)
1381
return round(this.Min,2) + String.fromCharCode(160) + "V";
1382
}
1383
},
1384
Max: {
1385
text: function () {
1386
if (this.Max !== undefined)
1387
return round(this.Max,2) + String.fromCharCode(160) + "V";
1388
}
1389
},
1390
Label: {
1391
html: function () {
1392
if (this.Event === undefined)
1393
return this.Label;
1394
else
1395
return this.Label + " <img style=\"vertical-align:middle;width:20px;\" src=\"./gfx/attention.gif\" alt=\"!\" title=\"" + this.Event + "\"/>";
1396
}
1397
}
1398
};
1399
try {
1400
var voltage_data = [];
1401
var datas = items(data.MBInfo.Voltage.Item);
1402
if (voltage_data.push_attrs(datas) > 0) {
1403
$('#voltage-data').render(voltage_data, directives);
1404
$("#block_voltage").show();
1405
} else {
1406
$("#block_voltage").hide();
1407
}
1408
}
1409
catch (err) {
1410
$("#block_voltage").hide();
1411
}
1412
}
1413
 
1414
function renderTemperature(data) {
1415
if ((blocks.length <= 0) || ((blocks[0] !== "true") && ($.inArray('temperature', blocks) < 0))) {
1416
$("#block_temperature").remove();
1417
return;
1418
}
1419
 
1420
var directives = {
1421
Value: {
1422
html: function () {
1423
return formatTemp(this.Value, data.Options["@attributes"].tempFormat);
1424
}
1425
},
1426
Max: {
1427
html: function () {
1428
if (this.Max !== undefined)
1429
return formatTemp(this.Max, data.Options["@attributes"].tempFormat);
1430
}
1431
},
1432
Label: {
1433
html: function () {
1434
if (this.Event === undefined)
1435
return this.Label;
1436
else
1437
return this.Label + " <img style=\"vertical-align:middle;width:20px;\" src=\"./gfx/attention.gif\" alt=\"!\" title=\"" + this.Event + "\"/>";
1438
}
1439
}
1440
};
1441
 
1442
try {
1443
var temperature_data = [];
1444
var datas = items(data.MBInfo.Temperature.Item);
1445
if (temperature_data.push_attrs(datas) > 0) {
1446
$('#temperature-data').render(temperature_data, directives);
1447
$("#block_temperature").show();
1448
} else {
1449
$("#block_temperature").hide();
1450
}
1451
}
1452
catch (err) {
1453
$("#block_temperature").hide();
1454
}
1455
}
1456
 
1457
function renderFans(data) {
1458
if ((blocks.length <= 0) || ((blocks[0] !== "true") && ($.inArray('fans', blocks) < 0))) {
1459
$("#block_fans").remove();
1460
return;
1461
}
1462
 
1463
var directives = {
1464
Value: {
1465
html: function () {
1466
if (this.Unit === "%") {
1467
if (isFinite(this.Value))
1468
return '<div class="progress">' +
1469
'<div class="progress-bar progress-bar-info" style="width:' + round(this.Value,0) + '%;"></div>' +
1470
'div><div class="percent">' + round(this.Value,0) + '%</div>';
1471
else
1472
return '---%';
1473
} else {
1474
return (isFinite(this.Value)?round(this.Value,0):"---") + String.fromCharCode(160) + genlang(63); //RPM
1475
}
1476
}
1477
},
1478
Min: {
1479
html: function () {
1480
if (this.Min !== undefined) {
1481
if (this.Unit === "%") {
1482
return round(this.Min,0) + "%";
1483
} else {
1484
return round(this.Min,0) + String.fromCharCode(160) + genlang(63); //RPM
1485
}
1486
}
1487
}
1488
},
1489
Label: {
1490
html: function () {
1491
if (this.Event === undefined)
1492
return this.Label;
1493
else
1494
return this.Label + " gfx/attention.gif\" alt=\"!\" title=\"" + this.Event + "\"/>";
1495
}
1496
}
1497
};
1498
 
1499
try {
1500
var fans_data = [];
1501
var datas = items(data.MBInfo.Fans.Item);
1502
if (fans_data.push_attrs(datas) > 0) {
1503
$('#fans-data').render(fans_data, directives);
1504
$("#block_fans").show();
1505
} else {
1506
$("#block_fans").hide();
1507
}
1508
}
1509
catch (err) {
1510
$("#block_fans").hide();
1511
}
1512
}
1513
 
1514
function renderPower(data) {
1515
if ((blocks.length <= 0) || ((blocks[0] !== "true") && ($.inArray('power', blocks) < 0))) {
1516
$("#block_power").remove();
1517
return;
1518
}
1519
 
1520
var directives = {
1521
Value: {
1522
text: function () {
1523
return (isFinite(this.Value)?round(this.Value,2):"---") + String.fromCharCode(160) + "W";
1524
}
1525
},
1526
Max: {
1527
text: function () {
1528
if (this.Max !== undefined)
1529
return round(this.Max,2) + String.fromCharCode(160) + "W";
1530
}
1531
},
1532
Label: {
1533
html: function () {
1534
if (this.Event === undefined)
1535
return this.Label;
1536
else
1537
return this.Label + " <img style=\"vertical-align:middle;width:20px;\" src=\"./gfx/attention.gif\" alt=\"!\" title=\"" + this.Event + "\"/>";
1538
}
1539
}
1540
};
1541
 
1542
try {
1543
var power_data = [];
1544
var datas = items(data.MBInfo.Power.Item);
1545
if (power_data.push_attrs(datas) > 0) {
1546
$('#power-data').render(power_data, directives);
1547
$("#block_power").show();
1548
} else {
1549
$("#block_power").hide();
1550
}
1551
}
1552
catch (err) {
1553
$("#block_power").hide();
1554
}
1555
}
1556
 
1557
function renderCurrent(data) {
1558
if ((blocks.length <= 0) || ((blocks[0] !== "true") && ($.inArray('current', blocks) < 0))) {
1559
$("#block_current").remove();
1560
return;
1561
}
1562
 
1563
var directives = {
1564
Value: {
1565
text: function () {
1566
return (isFinite(this.Value)?round(this.Value,2):"---") + String.fromCharCode(160) + "A";
1567
}
1568
},
1569
Min: {
1570
text: function () {
1571
if (this.Min !== undefined)
1572
return round(this.Min,2) + String.fromCharCode(160) + "A";
1573
}
1574
},
1575
Max: {
1576
text: function () {
1577
if (this.Max !== undefined)
1578
return round(this.Max,2) + String.fromCharCode(160) + "A";
1579
}
1580
},
1581
Label: {
1582
html: function () {
1583
if (this.Event === undefined)
1584
return this.Label;
1585
else
1586
return this.Label + " <img style=\"vertical-align:middle;width:20px;\" src=\"./gfx/attention.gif\" alt=\"!\" title=\"" + this.Event + "\"/>";
1587
}
1588
}
1589
};
1590
 
1591
try {
1592
var current_data = [];
1593
var datas = items(data.MBInfo.Current.Item);
1594
if (current_data.push_attrs(datas) > 0) {
1595
$('#current-data').render(current_data, directives);
1596
$("#block_current").show();
1597
} else {
1598
$("#block_current").hide();
1599
}
1600
}
1601
catch (err) {
1602
$("#block_current").hide();
1603
}
1604
}
1605
 
1606
function renderOther(data) {
1607
if ((blocks.length <= 0) || ((blocks[0] !== "true") && ($.inArray('other', blocks) < 0))) {
1608
$("#block_other").remove();
1609
return;
1610
}
1611
 
1612
var directives = {
1613
Value: {
1614
html: function () {
1615
if (this.Unit === "%") {
1616
if (isFinite(this.Value))
1617
return '<div class="progress">' +
1618
'<div class="progress-bar progress-bar-info" style="width:' + round(this.Value,0) + '%;"></div>' +
1619
'</div><div class="percent">' + round(this.Value,0) + '%</div>';
1620
else
1621
return '---%';
1622
} else {
1623
return this.Value;
1624
}
1625
}
1626
},
1627
Label: {
1628
html: function () {
1629
if (this.Event === undefined)
1630
return this.Label;
1631
else
1632
return this.Label + " <img style=\"vertical-align:middle;width:20px;\" src=\"./gfx/attention.gif\" alt=\"!\" title=\"" + this.Event + "\"/>";
1633
}
1634
}
1635
};
1636
 
1637
try {
1638
var other_data = [];
1639
var datas = items(data.MBInfo.Other.Item);
1640
if (other_data.push_attrs(datas) > 0) {
1641
$('#other-data').render(other_data, directives);
1642
$("#block_other").show();
1643
} else {
1644
$("#block_other").hide();
1645
}
1646
}
1647
catch (err) {
1648
$("#block_other").hide();
1649
}
1650
}
1651
 
1652
function renderUPS(data) {
1653
if ((blocks.length <= 0) || ((blocks[0] !== "true") && ($.inArray('ups', blocks) < 0))) {
1654
$("#block_ups").remove();
1655
return;
1656
}
1657
 
1658
var i, datas, proc_param;
1659
var directives = {
1660
Name: {
1661
text: function () {
1662
return this.Name + ((this.Mode !== undefined) ? " (" + this.Mode + ")" : "");
1663
}
1664
},
1665
LineVoltage: {
1666
html: function () {
1667
return this.LineVoltage + String.fromCharCode(160) + genlang(82); //V
1668
}
1669
},
1670
LineFrequency: {
1671
html: function () {
1672
return this.LineFrequency + String.fromCharCode(160) + genlang(109); //Hz
1673
}
1674
},
1675
BatteryVoltage: {
1676
html: function () {
1677
return this.BatteryVoltage + String.fromCharCode(160) + genlang(82); //V
1678
}
1679
},
1680
TimeLeftMinutes: {
1681
html: function () {
1682
return this.TimeLeftMinutes + String.fromCharCode(160) + genlang(83); //minutes
1683
}
1684
},
1685
LoadPercent: {
1686
html: function () {
1687
return '<div class="progress">' +
1688
'<div class="progress-bar progress-bar-info" style="width:' + round(this.LoadPercent,0) + '%;"></div>' +
1689
'</div><div class="percent">' + round(this.LoadPercent,0) + '%</div>';
1690
}
1691
},
1692
BatteryChargePercent: {
1693
html: function () {
1694
return '<div class="progress">' +
1695
'<div class="progress-bar progress-bar-info" style="width:' + round(this.BatteryChargePercent,0) + '%;"></div>' +
1696
'</div><div class="percent">' + round(this.BatteryChargePercent,0) + '%</div>';
1697
}
1698
}
1699
};
1700
 
1701
if ((data.UPSInfo !== undefined) && (items(data.UPSInfo.UPS).length > 0)) {
1702
var html="";
1703
var paramlist = {Model:70,StartTime:72,Status:73,BeeperStatus:133,Temperature:84,OutagesCount:74,LastOutage:75,LastOutageFinish:76,LineVoltage:77,LineFrequency:108,LoadPercent:78,BatteryDate:104,BatteryVoltage:79,BatteryChargePercent:80,TimeLeftMinutes:81};
1704
 
1705
try {
1706
datas = items(data.UPSInfo.UPS);
1707
for (i = 0; i < datas.length; i++) {
1708
html+="<tr id=\"ups-" + i +"\" class=\"treegrid-UPS-" + i+ "\">";
1709
html+="<td colspan=\"2\"><span class=\"treegrid-spanbold\" data-bind=\"Name\"></span></td>";
1710
html+="</tr>";
1711
for (proc_param in paramlist) {
1712
if (datas[i]["@attributes"][proc_param] !== undefined) {
1713
html+="<tr id=\"ups-" + i + "-" + proc_param + "\" class=\"treegrid-parent-UPS-" + i +"\">";
1714
html+="<td style=\"width:60%;\"><span class=\"treegrid-spanbold\">" + genlang(paramlist[proc_param]) + "</span></td>";
1715
html+="<td class=\"rightCell\"><span data-bind=\"" + proc_param + "\"></span></td>";
1716
html+="</tr>";
1717
}
1718
}
1719
 
1720
}
1721
}
1722
catch (err) {
1723
}
1724
 
1725
if ((data.UPSInfo["@attributes"] !== undefined) && (data.UPSInfo["@attributes"].ApcupsdCgiLinks === "1")) {
1726
html+="<tr>";
1727
html+="<td colspan=\"2\">(<a title='details' href='/cgi-bin/apcupsd/multimon.cgi' target='apcupsdcgi'>"+genlang(99)+"</a>)</td>";
1728
html+="</tr>";
1729
}
1730
 
1731
$("#ups-data").empty().append(html);
1732
 
1733
try {
1734
datas = items(data.UPSInfo.UPS);
1735
for (i = 0; i < datas.length; i++) {
1736
$('#ups-'+ i).render(datas[i]["@attributes"], directives);
1737
for (proc_param in paramlist) {
1738
if (datas[i]["@attributes"][proc_param] !== undefined) {
1739
$('#ups-'+ i +'-'+proc_param).render(datas[i]["@attributes"], directives);
1740
}
1741
}
1742
}
1743
}
1744
catch (err) {
1745
}
1746
 
1747
$('#ups').treegrid({
1748
initialState: 'expanded',
1749
expanderExpandedClass: 'normalicon normalicon-down',
1750
expanderCollapsedClass: 'normalicon normalicon-right'
1751
});
1752
 
1753
$("#block_ups").show();
1754
} else {
1755
$("#block_ups").hide();
1756
}
1757
}
1758
 
1759
function renderErrors(data) {
1760
try {
1761
var datas = items(data.Errors.Error);
1762
for (var i = 0; i < datas.length; i++) {
1763
$("#errors").append("<li><b>"+datas[i]["@attributes"].Function+"</b> - "+datas[i]["@attributes"].Message.replace(/\n/g, "<br>")+"</li><br>");
1764
}
1765
if (i > 0) {
1766
$("#errorbutton").attr('data-toggle', 'modal');
1767
$("#errorbutton").css('cursor', 'pointer');
1768
$("#errorbutton").css("visibility", "visible");
1769
}
1770
}
1771
catch (err) {
1772
$("#errorbutton").css("visibility", "hidden");
1773
$("#errorbutton").css('cursor', 'default');
1774
$("#errorbutton").attr('data-toggle', '');
1775
}
1776
}
1777
 
1778
/**
1779
* format seconds to a better readable statement with days, hours and minutes
1780
* @param {Number} sec seconds that should be formatted
1781
* @return {String} html string with no breaking spaces and translation statemen
1782
*/
1783
function formatUptime(sec) {
1784
var txt = "", intMin = 0, intHours = 0, intDays = 0;
1785
intMin = sec / 60;
1786
intHours = intMin / 60;
1787
intDays = Math.floor(intHours / 24);
1788
intHours = Math.floor(intHours - (intDays * 24));
1789
intMin = Math.floor(intMin - (intDays * 60 * 24) - (intHours * 60));
1790
if (intDays) {
1791
txt += intDays.toString() + String.fromCharCode(160) + genlang(48) + String.fromCharCode(160); //days
1792
}
1793
if (intHours) {
1794
txt += intHours.toString() + String.fromCharCode(160) + genlang(49) + String.fromCharCode(160); //hours
1795
}
1796
return txt + intMin.toString() + String.fromCharCode(160) + genlang(50); //Minutes
1797
}
1798
 
1799
/**
1800
* format a celcius temperature to fahrenheit and also append the right suffix
1801
* @param {String} degreeC temperature in celvius
1802
* @param {String} temperature format
1803
* @return {String} html string with no breaking spaces and translation statements
1804
*/
1805
function formatTemp(degreeC, tempFormat) {
1806
var degree = 0;
1807
if (tempFormat === undefined) {
1808
tempFormat = "c";
1809
}
1810
degree = parseFloat(degreeC);
1811
if (isNaN(degreeC)) {
1812
return "---";
1813
} else {
1814
switch (tempFormat.toLowerCase()) {
1815
case "f":
1816
return round((((9 * degree) / 5) + 32), 1) + String.fromCharCode(160) + genlang(61);
1817
case "c":
1818
return round(degree, 1) + String.fromCharCode(160) + genlang(60);
1819
case "c-f":
1820
return round(degree, 1) + String.fromCharCode(160) + genlang(60) + "<br><i>(" + round((((9 * degree) / 5) + 32), 1) + String.fromCharCode(160) + genlang(61) + ")i>";
1821
case "f-c":
1822
return round((((9 * degree) / 5) + 32), 1) + String.fromCharCode(160) + genlang(61) + "<br><i>(" + round(degree, 1) + String.fromCharCode(160) + genlang(60) + ")</i>";
1823
}
1824
}
1825
}
1826
 
1827
/**
1828
* format a given MHz value to a better readable statement with the right suffix
1829
* @param {Number} mhertz mhertz value that should be formatted
1830
* @return {String} html string with no breaking spaces and translation statements
1831
*/
1832
function formatHertz(mhertz) {
1833
if ((mhertz >= 0) && (mhertz < 1000)) {
1834
< 1000)) { return mhertz.toString() + String.fromCharCode(160) + genlang(92);
1835
< 1000)) { } else {
1836
< 1000)) { if (mhertz >= 1000) {
1837
< 1000)) { return round(mhertz / 1000, 2) + String.fromCharCode(160) + genlang(93);
1838
< 1000)) { } else {
1839
< 1000)) { return "";
1840
< 1000)) { }
1841
< 1000)) { }
1842
< 1000)) {}
1843
 
1844
< 1000)) {/**
1845
< 1000)) { * format a given MT/s value to a better readable statement with the right suffix
1846
< 1000)) { * @param {Number} mtps mtps value that should be formatted
1847
< 1000)) { * @return {String} html string with no breaking spaces and translation statements
1848
< 1000)) { */
1849
< 1000)) {function formatMTps(mtps) {
1850
< 1000)) { if ((mtps >= 0) && (mtps < 1000)) {
1851
< 1000)) { return mtps.toString() + String.fromCharCode(160) + genlang(131);
1852
< 1000)) { } else {
1853
< 1000)) { if (mtps >= 1000) {
1854
< 1000)) { return round(mtps / 1000, 2) + String.fromCharCode(160) + genlang(132);
1855
< 1000)) { } else {
1856
< 1000)) { return "";
1857
< 1000)) { }
1858
< 1000)) { }
1859
< 1000)) {}
1860
 
1861
< 1000)) {/**
1862
< 1000)) { * format the byte values into a user friendly value with the corespondenting unit expression<br>support is included
1863
< 1000)) { * for binary and decimal output<br>user can specify a constant format for all byte outputs or the output is formated
1864
< 1000)) { * automatically so that every value can be read in a user friendly way
1865
< 1000)) { * @param {Number} bytes value that should be converted in the corespondenting format, which is specified in the phpsysinfo.ini
1866
< 1000)) { * @param {String} byte format
1867
< 1000)) { * @param {parenths} if true then add parentheses
1868
< 1000)) { * @return {String} string of the converted bytes with the translated unit expression
1869
< 1000)) { */
1870
< 1000)) {function formatBytes(bytes, byteFormat, parenths) {
1871
< 1000)) { var show = "";
1872
 
1873
< 1000)) { if (byteFormat === undefined) {
1874
< 1000)) { byteFormat = "auto_binary";
1875
< 1000)) { }
1876
 
1877
< 1000)) { switch (byteFormat.toLowerCase()) {
1878
< 1000)) { case "pib":
1879
< 1000)) { show += round(bytes / Math.pow(1024, 5), 2);
1880
< 1000)) { show += String.fromCharCode(160) + genlang(90);
1881
< 1000)) { break;
1882
< 1000)) { case "tib":
1883
< 1000)) { show += round(bytes / Math.pow(1024, 4), 2);
1884
< 1000)) { show += String.fromCharCode(160) + genlang(86);
1885
< 1000)) { break;
1886
< 1000)) { case "gib":
1887
< 1000)) { show += round(bytes / Math.pow(1024, 3), 2);
1888
< 1000)) { show += String.fromCharCode(160) + genlang(87);
1889
< 1000)) { break;
1890
< 1000)) { case "mib":
1891
< 1000)) { show += round(bytes / Math.pow(1024, 2), 2);
1892
< 1000)) { show += String.fromCharCode(160) + genlang(88);
1893
< 1000)) { break;
1894
< 1000)) { case "kib":
1895
< 1000)) { show += round(bytes / Math.pow(1024, 1), 2);
1896
< 1000)) { show += String.fromCharCode(160) + genlang(89);
1897
< 1000)) { break;
1898
< 1000)) { case "pb":
1899
< 1000)) { show += round(bytes / Math.pow(1000, 5), 2);
1900
< 1000)) { show += String.fromCharCode(160) + genlang(91);
1901
< 1000)) { break;
1902
< 1000)) { case "tb":
1903
< 1000)) { show += round(bytes / Math.pow(1000, 4), 2);
1904
< 1000)) { show += String.fromCharCode(160) + genlang(85);
1905
< 1000)) { break;
1906
< 1000)) { case "gb":
1907
< 1000)) { show += round(bytes / Math.pow(1000, 3), 2);
1908
< 1000)) { show += String.fromCharCode(160) + genlang(41);
1909
< 1000)) { break;
1910
< 1000)) { case "mb":
1911
< 1000)) { show += round(bytes / Math.pow(1000, 2), 2);
1912
< 1000)) { show += String.fromCharCode(160) + genlang(40);
1913
< 1000)) { break;
1914
< 1000)) { case "kb":
1915
< 1000)) { show += round(bytes / Math.pow(1000, 1), 2);
1916
< 1000)) { show += String.fromCharCode(160) + genlang(39);
1917
< 1000)) { break;
1918
< 1000)) { case "b":
1919
< 1000)) { show += bytes;
1920
< 1000)) { show += String.fromCharCode(160) + genlang(96);
1921
< 1000)) { break;
1922
< 1000)) { case "auto_decimal":
1923
< 1000)) { if (bytes > Math.pow(1000, 5)) {
1924
< 1000)) { show += round(bytes / Math.pow(1000, 5), 2);
1925
< 1000)) { show += String.fromCharCode(160) + genlang(91);
1926
< 1000)) { } else {
1927
< 1000)) { if (bytes > Math.pow(1000, 4)) {
1928
< 1000)) { show += round(bytes / Math.pow(1000, 4), 2);
1929
< 1000)) { show += String.fromCharCode(160) + genlang(85);
1930
< 1000)) { } else {
1931
< 1000)) { if (bytes > Math.pow(1000, 3)) {
1932
< 1000)) { show += round(bytes / Math.pow(1000, 3), 2);
1933
< 1000)) { show += String.fromCharCode(160) + genlang(41);
1934
< 1000)) { } else {
1935
< 1000)) { if (bytes > Math.pow(1000, 2)) {
1936
< 1000)) { show += round(bytes / Math.pow(1000, 2), 2);
1937
< 1000)) { show += String.fromCharCode(160) + genlang(40);
1938
< 1000)) { } else {
1939
< 1000)) { if (bytes > Math.pow(1000, 1)) {
1940
< 1000)) { show += round(bytes / Math.pow(1000, 1), 2);
1941
< 1000)) { show += String.fromCharCode(160) + genlang(39);
1942
< 1000)) { } else {
1943
< 1000)) { show += bytes;
1944
< 1000)) { show += String.fromCharCode(160) + genlang(96);
1945
< 1000)) { }
1946
< 1000)) { }
1947
< 1000)) { }
1948
< 1000)) { }
1949
< 1000)) { }
1950
< 1000)) { break;
1951
< 1000)) { default:
1952
< 1000)) { if (bytes > Math.pow(1024, 5)) {
1953
< 1000)) { show += round(bytes / Math.pow(1024, 5), 2);
1954
< 1000)) { show += String.fromCharCode(160) + genlang(90);
1955
< 1000)) { } else {
1956
< 1000)) { if (bytes > Math.pow(1024, 4)) {
1957
< 1000)) { show += round(bytes / Math.pow(1024, 4), 2);
1958
< 1000)) { show += String.fromCharCode(160) + genlang(86);
1959
< 1000)) { } else {
1960
< 1000)) { if (bytes > Math.pow(1024, 3)) {
1961
< 1000)) { show += round(bytes / Math.pow(1024, 3), 2);
1962
< 1000)) { show += String.fromCharCode(160) + genlang(87);
1963
< 1000)) { } else {
1964
< 1000)) { if (bytes > Math.pow(1024, 2)) {
1965
< 1000)) { show += round(bytes / Math.pow(1024, 2), 2);
1966
< 1000)) { show += String.fromCharCode(160) + genlang(88);
1967
< 1000)) { } else {
1968
< 1000)) { if (bytes > Math.pow(1024, 1)) {
1969
< 1000)) { show += round(bytes / Math.pow(1024, 1), 2);
1970
< 1000)) { show += String.fromCharCode(160) + genlang(89);
1971
< 1000)) { } else {
1972
< 1000)) { show += bytes;
1973
< 1000)) { show += String.fromCharCode(160) + genlang(96);
1974
< 1000)) { }
1975
< 1000)) { }
1976
< 1000)) { }
1977
< 1000)) { }
1978
< 1000)) { }
1979
< 1000)) { }
1980
< 1000)) { if (parenths === true) {
1981
< 1000)) { show = "(" + show + ")i>";
1982
< 1000)) { }
1983
< 1000)) { return "<span style='display:none'>" + round(bytes,0) + ".</span>" + show; //span for sorting
1984
< 1000)) {}
1985
 
1986
< 1000)) {function formatBPS(bps) {
1987
< 1000)) { var show = "";
1988
 
1989
< 1000)) { if (bps > Math.pow(1000, 5)) {
1990
< 1000)) { show += round(bps / Math.pow(1000, 5), 2);
1991
< 1000)) { show += String.fromCharCode(160) + 'Pb/s';
1992
< 1000)) { } else {
1993
< 1000)) { if (bps > Math.pow(1000, 4)) {
1994
< 1000)) { show += round(bps / Math.pow(1000, 4), 2);
1995
< 1000)) { show += String.fromCharCode(160) + 'Tb/s';
1996
< 1000)) { } else {
1997
< 1000)) { if (bps > Math.pow(1000, 3)) {
1998
< 1000)) { show += round(bps / Math.pow(1000, 3), 2);
1999
< 1000)) { show += String.fromCharCode(160) + 'Gb/s';
2000
< 1000)) { } else {
2001
< 1000)) { if (bps > Math.pow(1000, 2)) {
2002
< 1000)) { show += round(bps / Math.pow(1000, 2), 2);
2003
< 1000)) { show += String.fromCharCode(160) + 'Mb/s';
2004
< 1000)) { } else {
2005
< 1000)) { if (bps > Math.pow(1000, 1)) {
2006
< 1000)) { show += round(bps / Math.pow(1000, 1), 2);
2007
< 1000)) { show += String.fromCharCode(160) + 'Kb/s';
2008
< 1000)) { } else {
2009
< 1000)) { show += bps;
2010
< 1000)) { show += String.fromCharCode(160) + 'b/s';
2011
< 1000)) { }
2012
< 1000)) { }
2013
< 1000)) { }
2014
< 1000)) { }
2015
< 1000)) { }
2016
< 1000)) { return show;
2017
< 1000)) {}
2018
 
2019
< 1000)) {Array.prototype.pushIfNotExist = function(val) {
2020
< 1000)) { if (typeof(val) == 'undefined' || val === '') {
2021
< 1000)) { return;
2022
< 1000)) { }
2023
< 1000)) { val = $.trim(val);
2024
< 1000)) { if ($.inArray(val, this) == -1) {
2025
< 1000)) { this.push(val);
2026
< 1000)) { }
2027
< 1000)) {};
2028
 
2029
< 1000)) {/**
2030
< 1000)) { * generate a formatted datetime string of the current datetime
2031
< 1000)) { * @return {String} formatted datetime string
2032
< 1000)) { */
2033
< 1000)) {function datetime() {
2034
< 1000)) { var date, day = 0, month = 0, year = 0, hour = 0, minute = 0, days = "", months = "", years = "", hours = "", minutes = "";
2035
< 1000)) { date = new Date();
2036
< 1000)) { day = date.getDate();
2037
< 1000)) { month = date.getMonth() + 1;
2038
< 1000)) { year = date.getFullYear();
2039
< 1000)) { hour = date.getHours();
2040
< 1000)) { minute = date.getMinutes();
2041
 
2042
< 1000)) { // format values smaller that 10 with a leading 0
2043
< 1000)) { days = (day < 10) ? "0" + day.toString() : day.toString();
2044
< 1000)) {< 10) ? "0" + day.toString() : day.toString(); months = (month < 10) ? "0" + month.toString() : month.toString();
2045
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString(); years = (year < 1000) ? year.toString() : year.toString();
2046
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString(); minutes = (minute < 10) ? "0" + minute.toString() : minute.toString();
2047
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString(); hours = (hour < 10) ? "0" + hour.toString() : hour.toString();
2048
 
2049
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString(); return days + "." + months + "." + years + " - " + hours + ":" + minutes;
2050
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();}
2051
 
2052
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();/**
2053
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString(); * round a given value to the specified precision, difference to Math.round() is that there
2054
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString(); * will be appended Zeros to the end if the precision is not reached (0.1 gets rounded to 0.100 when precision is set to 3)
2055
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString(); * @param {Number} x value to round
2056
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString(); * @param {Number} n precision
2057
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString(); * @return {String}
2058
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString(); */
2059
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();function round(x, n) {
2060
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString(); var e = 0, k = "";
2061
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString(); if (n < 0 || n > 14) {
2062
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n > return 0;
2063
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n > }
2064
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n > if (n === 0) {
2065
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n > return Math.round(x);
2066
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n > } else {
2067
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n > e = Math.pow(10, n);
2068
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n > k = (Math.round(x * e) / e).toString();
2069
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n > if (k.indexOf('.') === -1) {
2070
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n > k += '.';
2071
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n > }
2072
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n > k += e.toString().substring(1);
2073
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n > return k.substring(0, k.indexOf('.') + n + 1);
2074
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n > }
2075
< 1000)) {< 10) ? "0" + day.toString() : day.toString();< 10) ? "0" + month.toString() : month.toString();< 1000) ? year.toString() : year.toString();< 10) ? "0" + minute.toString() : minute.toString();< 10) ? "0" + hour.toString() : hour.toString();< 0 || n >}