8ac7e7cdae2ce075a3e5e37d13a9272fa2526163
[project/luci.git] / modules / luci-mod-status / htdocs / luci-static / resources / view / status / include / 10_system.js
1 'use strict';
2 'require fs';
3 'require rpc';
4
5 var callSystemBoard = rpc.declare({
6 object: 'system',
7 method: 'board'
8 });
9
10 var callSystemInfo = rpc.declare({
11 object: 'system',
12 method: 'info'
13 });
14
15 return L.Class.extend({
16 title: _('System'),
17
18 load: function() {
19 return Promise.all([
20 L.resolveDefault(callSystemBoard(), {}),
21 L.resolveDefault(callSystemInfo(), {}),
22 fs.lines('/usr/lib/lua/luci/version.lua')
23 ]);
24 },
25
26 render: function(data) {
27 var boardinfo = data[0],
28 systeminfo = data[1],
29 luciversion = data[2];
30
31 luciversion = luciversion.filter(function(l) {
32 return l.match(/^\s*(luciname|luciversion)\s*=/);
33 }).map(function(l) {
34 return l.replace(/^\s*\w+\s*=\s*['"]([^'"]+)['"].*$/, '$1');
35 }).join(' ');
36
37 var fields = [
38 _('Hostname'), boardinfo.hostname,
39 _('Model'), boardinfo.model,
40 _('Architecture'), boardinfo.system,
41 _('Firmware Version'), (L.isObject(boardinfo.release) ? boardinfo.release.description + ' / ' : '') + (luciversion || ''),
42 _('Kernel Version'), boardinfo.kernel,
43 _('Local Time'), systeminfo.localtime ? (new Date(systeminfo.localtime * 1000)).toLocaleString() : null,
44 _('Uptime'), systeminfo.uptime ? '%t'.format(systeminfo.uptime) : null,
45 _('Load Average'), Array.isArray(systeminfo.load) ? '%.2f, %.2f, %.2f'.format(
46 systeminfo.load[0] / 65535.0,
47 systeminfo.load[1] / 65535.0,
48 systeminfo.load[2] / 65535.0
49 ) : null
50 ];
51
52 var table = E('div', { 'class': 'table' });
53
54 for (var i = 0; i < fields.length; i += 2) {
55 table.appendChild(E('div', { 'class': 'tr' }, [
56 E('div', { 'class': 'td left', 'width': '33%' }, [ fields[i] ]),
57 E('div', { 'class': 'td left' }, [ (fields[i + 1] != null) ? fields[i + 1] : '?' ])
58 ]));
59 }
60
61 return table;
62 }
63 });