From b5dc25c09ca938be6f9d82f461873eb69728481f Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 1 Feb 2014 18:29:03 +0000 Subject: [PATCH] luci2: move most RPC proxy function declarations into the views using them to reduce the size of the core luci2.js library --- luci2/htdocs/luci2/luci2.js | 262 --------- luci2/htdocs/luci2/view/network.diagnostics.js | 47 +- luci2/htdocs/luci2/view/network.hosts.js | 44 +- luci2/htdocs/luci2/view/network.routes.js | 206 +++---- luci2/htdocs/luci2/view/network.switch.js | 73 ++- luci2/htdocs/luci2/view/status.dmesg.js | 27 +- luci2/htdocs/luci2/view/status.overview.js | 109 ++-- luci2/htdocs/luci2/view/status.processes.js | 133 +++-- luci2/htdocs/luci2/view/status.routes.js | 26 +- luci2/htdocs/luci2/view/status.syslog.js | 27 +- luci2/htdocs/luci2/view/system.admin.js | 722 +++++++++++++------------ luci2/htdocs/luci2/view/system.cron.js | 24 +- luci2/htdocs/luci2/view/system.leds.js | 215 ++++---- luci2/htdocs/luci2/view/system.software.js | 139 ++++- luci2/htdocs/luci2/view/system.startup.js | 179 +++--- luci2/htdocs/luci2/view/system.system.js | 420 +++++++------- luci2/htdocs/luci2/view/system.upgrade.js | 107 +++- luci2/htdocs/luci2/view/system.users.js | 584 ++++++++++---------- 18 files changed, 1725 insertions(+), 1619 deletions(-) diff --git a/luci2/htdocs/luci2/luci2.js b/luci2/htdocs/luci2/luci2.js index 30e3063..34cef8a 100644 --- a/luci2/htdocs/luci2/luci2.js +++ b/luci2/htdocs/luci2/luci2.js @@ -2805,41 +2805,6 @@ function LuCI2() }); }, - getProcessList: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'process_list', - expect: { processes: [ ] }, - filter: function(data) { - data.sort(function(a, b) { return a.pid - b.pid }); - return data; - } - }), - - getSystemLog: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'syslog', - expect: { log: '' } - }), - - getKernelLog: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'dmesg', - expect: { log: '' } - }), - - getZoneInfo: function(cb) - { - return $.getJSON(_luci2.globals.resource + '/zoneinfo.json', cb); - }, - - sendSignal: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'process_signal', - params: [ 'pid', 'signal' ], - filter: function(data) { - return (data == 0); - } - }), initList: _luci2.rpc.declare({ object: 'luci2.system', @@ -2879,239 +2844,12 @@ function LuCI2() initDisable: function(init, cb) { return _luci2.system.initRun(init, 'disable', cb) }, - getRcLocal: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'rclocal_get', - expect: { data: '' } - }), - - setRcLocal: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'rclocal_set', - params: [ 'data' ] - }), - - - getCrontab: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'crontab_get', - expect: { data: '' } - }), - - setCrontab: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'crontab_set', - params: [ 'data' ] - }), - - - getSSHKeys: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'sshkeys_get', - expect: { keys: [ ] } - }), - - setSSHKeys: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'sshkeys_set', - params: [ 'keys' ] - }), - - - setPassword: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'password_set', - params: [ 'user', 'password' ] - }), - - - listLEDs: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'led_list', - expect: { leds: [ ] } - }), - - listUSBDevices: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'usb_list', - expect: { devices: [ ] } - }), - - - testUpgrade: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'upgrade_test', - expect: { '': { } } - }), - - startUpgrade: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'upgrade_start', - params: [ 'keep' ] - }), - - cleanUpgrade: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'upgrade_clean' - }), - - - restoreBackup: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'backup_restore' - }), - - cleanBackup: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'backup_clean' - }), - - - getBackupConfig: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'backup_config_get', - expect: { config: '' } - }), - - setBackupConfig: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'backup_config_set', - params: [ 'data' ] - }), - - - listBackup: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'backup_list', - expect: { files: [ ] } - }), - - - testReset: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'reset_test', - expect: { supported: false } - }), - - startReset: _luci2.rpc.declare({ - object: 'luci2.system', - method: 'reset_start' - }), - - performReboot: _luci2.rpc.declare({ object: 'luci2.system', method: 'reboot' }) }; - this.opkg = { - updateLists: _luci2.rpc.declare({ - object: 'luci2.opkg', - method: 'update', - expect: { '': { } } - }), - - _allPackages: _luci2.rpc.declare({ - object: 'luci2.opkg', - method: 'list', - params: [ 'offset', 'limit', 'pattern' ], - expect: { '': { } } - }), - - _installedPackages: _luci2.rpc.declare({ - object: 'luci2.opkg', - method: 'list_installed', - params: [ 'offset', 'limit', 'pattern' ], - expect: { '': { } } - }), - - _findPackages: _luci2.rpc.declare({ - object: 'luci2.opkg', - method: 'find', - params: [ 'offset', 'limit', 'pattern' ], - expect: { '': { } } - }), - - _fetchPackages: function(action, offset, limit, pattern) - { - var packages = [ ]; - - return action(offset, limit, pattern).then(function(list) { - if (!list.total || !list.packages) - return { length: 0, total: 0 }; - - packages.push.apply(packages, list.packages); - packages.total = list.total; - - if (limit <= 0) - limit = list.total; - - if (packages.length >= limit) - return packages; - - _luci2.rpc.batch(); - - for (var i = offset + packages.length; i < limit; i += 100) - action(i, (Math.min(i + 100, limit) % 100) || 100, pattern); - - return _luci2.rpc.flush(); - }).then(function(lists) { - for (var i = 0; i < lists.length; i++) - { - if (!lists[i].total || !lists[i].packages) - continue; - - packages.push.apply(packages, lists[i].packages); - packages.total = lists[i].total; - } - - return packages; - }); - }, - - listPackages: function(offset, limit, pattern) - { - return _luci2.opkg._fetchPackages(_luci2.opkg._allPackages, offset, limit, pattern); - }, - - installedPackages: function(offset, limit, pattern) - { - return _luci2.opkg._fetchPackages(_luci2.opkg._installedPackages, offset, limit, pattern); - }, - - findPackages: function(offset, limit, pattern) - { - return _luci2.opkg._fetchPackages(_luci2.opkg._findPackages, offset, limit, pattern); - }, - - installPackage: _luci2.rpc.declare({ - object: 'luci2.opkg', - method: 'install', - params: [ 'package' ], - expect: { '': { } } - }), - - removePackage: _luci2.rpc.declare({ - object: 'luci2.opkg', - method: 'remove', - params: [ 'package' ], - expect: { '': { } } - }), - - getConfig: _luci2.rpc.declare({ - object: 'luci2.opkg', - method: 'config_get', - expect: { config: '' } - }), - - setConfig: _luci2.rpc.declare({ - object: 'luci2.opkg', - method: 'config_set', - params: [ 'data' ] - }) - }; - this.session = { login: _luci2.rpc.declare({ diff --git a/luci2/htdocs/luci2/view/network.diagnostics.js b/luci2/htdocs/luci2/view/network.diagnostics.js index 99f185a..1649264 100644 --- a/luci2/htdocs/luci2/view/network.diagnostics.js +++ b/luci2/htdocs/luci2/view/network.diagnostics.js @@ -1,24 +1,59 @@ L.ui.view.extend({ title: L.tr('Diagnostics'), + runPing: L.rpc.declare({ + object: 'luci2.network', + method: 'ping', + params: [ 'data' ], + expect: { '': { code: -1 } } + }), + + runPing6: L.rpc.declare({ + object: 'luci2.network', + method: 'ping6', + params: [ 'data' ], + expect: { '': { code: -1 } } + }), + + runTraceroute: L.rpc.declare({ + object: 'luci2.network', + method: 'traceroute', + params: [ 'data' ], + expect: { '': { code: -1 } } + }), + + runTraceroute6: L.rpc.declare({ + object: 'luci2.network', + method: 'traceroute6', + params: [ 'data' ], + expect: { '': { code: -1 } } + }), + + runNslookup: L.rpc.declare({ + object: 'luci2.network', + method: 'nslookup', + params: [ 'data' ], + expect: { '': { code: -1 } } + }), + execute: function() { var self = this; var tools = [ ]; $.when( - L.network.runPing('?').then(function(rv) { + self.runPing('?').then(function(rv) { if (rv.code != -1) tools.push(['runPing', L.tr('IPv4 Ping')]); }), - L.network.runPing6('?').then(function(rv) { + self.runPing6('?').then(function(rv) { if (rv.code != -1) tools.push(['runPing6', L.tr('IPv6 Ping')]); }), - L.network.runTraceroute('?').then(function(rv) { + self.runTraceroute('?').then(function(rv) { if (rv.code != -1) tools.push(['runTraceroute', L.tr('IPv4 Traceroute')]); }), - L.network.runTraceroute6('?').then(function(rv) { + self.runTraceroute6('?').then(function(rv) { if (rv.code != -1) tools.push(['runTraceroute6', L.tr('IPv6 Tracroute')]); }), - L.network.runNslookup('?').then(function(rv) { + self.runNslookup('?').then(function(rv) { if (rv.code != -1) tools.push(['runNslookup', L.tr('DNS Lookup')]); }) ).then(function() { @@ -38,7 +73,7 @@ L.ui.view.extend({ $('#run').click(function() { L.ui.loading(true); - L.network[$('#tool').val()]($('#host').val()).then(function(rv) { + self[$('#tool').val()]($('#host').val()).then(function(rv) { $('#output').empty().show(); if (rv.stdout) diff --git a/luci2/htdocs/luci2/view/network.hosts.js b/luci2/htdocs/luci2/view/network.hosts.js index 587b181..99fbe47 100644 --- a/luci2/htdocs/luci2/view/network.hosts.js +++ b/luci2/htdocs/luci2/view/network.hosts.js @@ -1,29 +1,29 @@ L.ui.view.extend({ - title: L.tr('Hostnames'), - description: L.tr('Manage static host records to let the local DNS server resolve certain names to specific IP addresses.'), + title: L.tr('Hostnames'), + description: L.tr('Manage static host records to let the local DNS server resolve certain names to specific IP addresses.'), - execute: function() { - var m = new L.cbi.Map('dhcp', { - readonly: !this.options.acls.hostnames - }); + execute: function() { + var m = new L.cbi.Map('dhcp', { + readonly: !this.options.acls.hostnames + }); - var s = m.section(L.cbi.TableSection, 'domain', { - anonymous: true, - addremove: true, - add_caption: L.tr('Add new hostname'), - remove_caption: L.tr('Remove hostname') - }); + var s = m.section(L.cbi.TableSection, 'domain', { + anonymous: true, + addremove: true, + add_caption: L.tr('Add new hostname'), + remove_caption: L.tr('Remove hostname') + }); - s.option(L.cbi.InputValue, 'name', { - caption: L.tr('Hostname'), - datatype: 'hostname' - }); + s.option(L.cbi.InputValue, 'name', { + caption: L.tr('Hostname'), + datatype: 'hostname' + }); - s.option(L.cbi.InputValue, 'ip', { - caption: L.tr('IP address'), - datatype: 'ipaddr' - }); + s.option(L.cbi.InputValue, 'ip', { + caption: L.tr('IP address'), + datatype: 'ipaddr' + }); - return m.insertInto('#map'); - } + return m.insertInto('#map'); + } }); diff --git a/luci2/htdocs/luci2/view/network.routes.js b/luci2/htdocs/luci2/view/network.routes.js index a1ed560..4464706 100644 --- a/luci2/htdocs/luci2/view/network.routes.js +++ b/luci2/htdocs/luci2/view/network.routes.js @@ -1,105 +1,105 @@ L.ui.view.extend({ - title: L.tr('Routes'), - description: L.tr('Routes specify over which interface and gateway a certain host or network can be reached.'), - - execute: function() { - var self = this; - return L.network.listNetworkNames().then(function(list) { - var m = new L.cbi.Map('network', { - readonly: !self.options.acls.network - }); - - var s4 = m.section(L.cbi.TableSection, 'route', { - caption: L.tr('Static IPv4 Routes'), - anonymous: true, - addremove: true, - sortable: true, - add_caption: L.tr('Add new route'), - remove_caption: L.tr('Remove route') - }); - - var ifc = s4.option(L.cbi.ListValue, 'interface', { - caption: L.tr('Interface') - }); - - for (var i = 0; i < list.length; i++) - ifc.value(list[i]); - - s4.option(L.cbi.InputValue, 'target', { - caption: L.tr('Target'), - datatype: 'ip4addr' - }); - - s4.option(L.cbi.InputValue, 'netmask', { - caption: L.tr('IPv4-Netmask'), - datatype: 'ip4addr', - placeholder: '255.255.255.255', - optional: true - }); - - s4.option(L.cbi.InputValue, 'gateway', { - caption: L.tr('IPv4-Gateway'), - datatype: 'ip4addr', - optional: true - }); - - s4.option(L.cbi.InputValue, 'metric', { - caption: L.tr('Metric'), - datatype: 'range(0,255)', - placeholder: 0, - optional: true - }); - - s4.option(L.cbi.InputValue, 'mtu', { - caption: L.tr('MTU'), - datatype: 'range(64,9000)', - placeholder: 1500, - optional: true - }); - - - var s6 = m.section(L.cbi.TableSection, 'route6', { - caption: L.tr('Static IPv6 Routes'), - anonymous: true, - addremove: true, - sortable: true, - add_caption: L.tr('Add new route'), - remove_caption: L.tr('Remove route') - }); - - var ifc = s6.option(L.cbi.ListValue, 'interface', { - caption: L.tr('Interface') - }); - - for (var i = 0; i < list.length; i++) - ifc.value(list[i]); - - s6.option(L.cbi.InputValue, 'target', { - caption: L.tr('Target'), - datatype: 'ip6addr' - }); - - s6.option(L.cbi.InputValue, 'gateway', { - caption: L.tr('IPv6-Gateway'), - datatype: 'ip6addr', - optional: true - }); - - s6.option(L.cbi.InputValue, 'metric', { - caption: L.tr('Metric'), - datatype: 'range(0,255)', - placeholder: 0, - optional: true - }); - - s6.option(L.cbi.InputValue, 'mtu', { - caption: L.tr('MTU'), - datatype: 'range(64,9000)', - placeholder: 1500, - optional: true - }); - - m.insertInto('#map'); - }); - } + title: L.tr('Routes'), + description: L.tr('Routes specify over which interface and gateway a certain host or network can be reached.'), + + execute: function() { + var self = this; + var ifaces = L.NetworkModel.getInterfaces(); + + var m = new L.cbi.Map('network', { + readonly: !self.options.acls.network + }); + + var s4 = m.section(L.cbi.TableSection, 'route', { + caption: L.tr('Static IPv4 Routes'), + anonymous: true, + addremove: true, + sortable: true, + add_caption: L.tr('Add new route'), + remove_caption: L.tr('Remove route') + }); + + var ifc = s4.option(L.cbi.ListValue, 'interface', { + caption: L.tr('Interface') + }); + + for (var i = 0; i < ifaces.length; i++) + ifc.value(ifaces[i].name()); + + s4.option(L.cbi.InputValue, 'target', { + caption: L.tr('Target'), + datatype: 'ip4addr' + }); + + s4.option(L.cbi.InputValue, 'netmask', { + caption: L.tr('IPv4-Netmask'), + datatype: 'ip4addr', + placeholder: '255.255.255.255', + optional: true + }); + + s4.option(L.cbi.InputValue, 'gateway', { + caption: L.tr('IPv4-Gateway'), + datatype: 'ip4addr', + optional: true + }); + + s4.option(L.cbi.InputValue, 'metric', { + caption: L.tr('Metric'), + datatype: 'range(0,255)', + placeholder: 0, + optional: true + }); + + s4.option(L.cbi.InputValue, 'mtu', { + caption: L.tr('MTU'), + datatype: 'range(64,9000)', + placeholder: 1500, + optional: true + }); + + + var s6 = m.section(L.cbi.TableSection, 'route6', { + caption: L.tr('Static IPv6 Routes'), + anonymous: true, + addremove: true, + sortable: true, + add_caption: L.tr('Add new route'), + remove_caption: L.tr('Remove route') + }); + + var ifc = s6.option(L.cbi.ListValue, 'interface', { + caption: L.tr('Interface') + }); + + for (var i = 0; i < ifaces.length; i++) + ifc.value(ifaces[i].name()); + + s6.option(L.cbi.InputValue, 'target', { + caption: L.tr('Target'), + datatype: 'ip6addr' + }); + + s6.option(L.cbi.InputValue, 'gateway', { + caption: L.tr('IPv6-Gateway'), + datatype: 'ip6addr', + optional: true + }); + + s6.option(L.cbi.InputValue, 'metric', { + caption: L.tr('Metric'), + datatype: 'range(0,255)', + placeholder: 0, + optional: true + }); + + s6.option(L.cbi.InputValue, 'mtu', { + caption: L.tr('MTU'), + datatype: 'range(64,9000)', + placeholder: 1500, + optional: true + }); + + m.insertInto('#map'); + } }); diff --git a/luci2/htdocs/luci2/view/network.switch.js b/luci2/htdocs/luci2/view/network.switch.js index bfe27c6..39a5b0b 100644 --- a/luci2/htdocs/luci2/view/network.switch.js +++ b/luci2/htdocs/luci2/view/network.switch.js @@ -2,6 +2,37 @@ L.ui.view.extend({ title: L.tr('Switch'), description: L.tr('The network ports on this device can be combined to several VLANs in which computers can communicate directly with each other. VLANs are often used to separate different network segments. Often there is by default one Uplink port for a connection to the next greater network like the internet and other ports for a local network.'), + listSwitchNames: L.rpc.declare({ + object: 'luci2.network', + method: 'switch_list', + expect: { switches: [ ] } + }), + + getSwitchInfo: L.rpc.declare({ + object: 'luci2.network', + method: 'switch_info', + params: [ 'switch' ], + expect: { info: { } }, + filter: function(data, params) { + data['attrs'] = data['switch']; + data['vlan_attrs'] = data['vlan']; + data['port_attrs'] = data['port']; + data['switch'] = params['switch']; + + delete data.vlan; + delete data.port; + + return data; + } + }), + + getSwitchStatus: L.rpc.declare({ + object: 'luci2.network', + method: 'switch_status', + params: [ 'switch' ], + expect: { ports: [ ] } + }), + switchPortState: L.cbi.ListValue.extend({ choices: [ [ 'n', L.trc('Switch port state', 'off') ], @@ -60,11 +91,11 @@ L.ui.view.extend({ execute: function() { var self = this; - return L.network.listSwitchNames().then(function(switches) { + return self.listSwitchNames().then(function(switches) { L.rpc.batch(); for (var i = 0; i < switches.length; i++) - L.network.getSwitchInfo(switches[i]); + self.getSwitchInfo(switches[i]); return L.rpc.flush(); }).then(function(switches) { @@ -283,25 +314,25 @@ L.ui.view.extend({ } return m.insertInto('#map').then(function() { - self.repeat(function() { - return L.network.getSwitchStatus(swname).then(function(ports) { - for (var j = 0; j < ports.length; j++) - { - var s = L.tr('No link'); - var d = ' '; - - if (ports[j].link) - { - s = '%dbaseT'.format(ports[j].speed); - d = ports[j].full_duplex ? L.tr('Full-duplex') : L.tr('Half-duplex'); - } - - $('#portstatus-%s-%d'.format(swname, j)) - .empty().append(s + '
' + d); - } - }); - }, 5000); - }); + self.repeat(function() { + return self.getSwitchStatus(swname).then(function(ports) { + for (var j = 0; j < ports.length; j++) + { + var s = L.tr('No link'); + var d = ' '; + + if (ports[j].link) + { + s = '%dbaseT'.format(ports[j].speed); + d = ports[j].full_duplex ? L.tr('Full-duplex') : L.tr('Half-duplex'); + } + + $('#portstatus-%s-%d'.format(swname, j)) + .empty().append(s + '
' + d); + } + }); + }, 5000); + }); }); } }); diff --git a/luci2/htdocs/luci2/view/status.dmesg.js b/luci2/htdocs/luci2/view/status.dmesg.js index bcb35d0..de03973 100644 --- a/luci2/htdocs/luci2/view/status.dmesg.js +++ b/luci2/htdocs/luci2/view/status.dmesg.js @@ -1,13 +1,20 @@ L.ui.view.extend({ - title: L.tr('Kernel Log'), - refresh: 5000, - execute: function() { - return L.system.getKernelLog().then(function(log) { - var ta = document.getElementById('syslog'); - var lines = log.replace(/\n+$/, '').split(/\n/); + title: L.tr('Kernel Log'), + refresh: 5000, - ta.rows = lines.length; - ta.value = lines.reverse().join("\n"); - }); - } + getKernelLog: L.rpc.declare({ + object: 'luci2.system', + method: 'dmesg', + expect: { log: '' } + }), + + execute: function() { + return this.getKernelLog().then(function(log) { + var ta = document.getElementById('syslog'); + var lines = log.replace(/\n+$/, '').split(/\n/); + + ta.rows = lines.length; + ta.value = lines.reverse().join("\n"); + }); + } }); diff --git a/luci2/htdocs/luci2/view/status.overview.js b/luci2/htdocs/luci2/view/status.overview.js index 7440f8c..909c4c1 100644 --- a/luci2/htdocs/luci2/view/status.overview.js +++ b/luci2/htdocs/luci2/view/status.overview.js @@ -1,10 +1,30 @@ L.ui.view.extend({ title: L.tr('Status'), - execute: function() { + + getConntrackCount: L.rpc.declare({ + object: 'luci2.network', + method: 'conntrack_count', + expect: { '': { count: 0, limit: 0 } } + }), + + getDHCPLeases: L.rpc.declare({ + object: 'luci2.network', + method: 'dhcp_leases', + expect: { leases: [ ] } + }), + + getDHCPv6Leases: L.rpc.declare({ + object: 'luci2.network', + method: 'dhcp6_leases', + expect: { leases: [ ] } + }), + + renderContents: function() { + var self = this; return $.when( - L.network.findWanInterfaces().then(function(wans) { - var wan = wans[0]; - var wan6 = wans[1]; + L.NetworkModel.refreshStatus().then(function() { + var wan = L.NetworkModel.findWAN(); + var wan6 = L.NetworkModel.findWAN6(); if (!wan && !wan6) { @@ -21,57 +41,36 @@ L.ui.view.extend({ width: '146px', align: 'right', format: function(v) { - return new L.ui.devicebadge(v).render(); + var dev = L.NetworkModel.resolveAlias(v.getDevice()); + if (dev) + return $('') + .addClass('badge') + .attr('title', dev.description()) + .append($('').attr('src', dev.icon())) + .append(' %s'.format(dev.name())); + + return ''; } }, { format: function(v, n) { - var format_addr = function() - { - var rv = [ ]; - if (n > 0) - { - for (var i = 0; i < v['ipv6-address'].length; i++) - rv.push('%s/%d'.format(v['ipv6-address'][i].address, v['ipv6-address'][i].mask)); - - for (var i = 0; i < v['ipv6-prefix-assignment'].length; i++) - rv.push('%s1/%d'.format(v['ipv6-prefix-assignment'][i].address, v['ipv6-prefix-assignment'][i].mask)); - } - else - { - for (var i = 0; i < v['ipv4-address'].length; i++) - rv.push('%s/%d'.format(v['ipv4-address'][i].address, v['ipv4-address'][i].mask)); - } - return rv.join(', '); - }; - - var format_dns = function() - { - var rv = [ ]; - for (var i = 0; i < v['dns-server'].length; i++) - { - if ((n > 0 && v['dns-server'][i].indexOf(':') > -1) || - (n == 0 && v['dns-server'][i].indexOf(':') == -1)) - rv.push(v['dns-server'][i]); - } - return rv.join(', '); - }; - var s = '' + L.tr('Type') + ': %s | ' + - '' + L.tr('Connected') + ': %t
' + - '' + L.tr('Address') + ': %s
'; + '' + L.tr('Connected') + ': %t
'; - s = s.format(v.proto, v.uptime, format_addr()); + s = s.format(v.getProtocol().description, v.getUptime(), + n ? v.getIPv6Addrs(true).join(', ') + : v.getIPv4Addrs(true).join(', ')); - for (var i = 0; i < v.route.length; i++) - if (v.route[i].mask == 0 && v.route[i].nexthop != '::') - { - s += '' + L.tr('Gateway') + ': %s
'.format(v.route[i].nexthop); - break; - } + var addr = n ? v.getIPv6Addrs() : v.getIPv4Addrs(); + if (addr.length) + s += '' + L.tr('Address') + ': %s
'.format(addr.join(', ')); + + var gw = v.getIPv4Gateway(); + if (gw) + s += '' + L.tr('Gateway') + ': %s
'.format(gw); - var dns = format_dns(); - if (dns) - s += '' + L.tr('DNS') + ': %s
'.format(dns); + var dns = n ? v.getIPv6DNS() : v.getIPv4DNS(); + if (dns.length) + s += '' + L.tr('DNS') + ': %s
'.format(dns.join(', ')); return s; } @@ -86,7 +85,7 @@ L.ui.view.extend({ networkTable.insertInto('#network_status_table'); }), - L.network.getConntrackCount().then(function(count) { + self.getConntrackCount().then(function(count) { var conntrackTable = new L.ui.table({ caption: L.tr('Connection Tracking'), columns: [ { @@ -352,7 +351,7 @@ L.ui.view.extend({ assocTable.rows(assoclist); assocTable.insertInto('#wifi_assoc_table'); }), - L.network.getDHCPLeases().then(function(leases) { + self.getDHCPLeases().then(function(leases) { var leaseTable = new L.ui.table({ caption: L.tr('DHCP Leases'), placeholder: L.tr('There are no active leases.'), @@ -378,7 +377,7 @@ L.ui.view.extend({ leaseTable.rows(leases); leaseTable.insertInto('#lease_status_table'); }), - L.network.getDHCPv6Leases().then(function(leases) { + self.getDHCPv6Leases().then(function(leases) { if (!leases.length) return; @@ -407,5 +406,13 @@ L.ui.view.extend({ leaseTable.insertInto('#lease6_status_table'); }) ) + }, + + execute: function() + { + var self = this; + return L.NetworkModel.init().then(function() { + self.repeat(self.renderContents, 5000); + }); } }); diff --git a/luci2/htdocs/luci2/view/status.processes.js b/luci2/htdocs/luci2/view/status.processes.js index 9c80d89..b58df8a 100644 --- a/luci2/htdocs/luci2/view/status.processes.js +++ b/luci2/htdocs/luci2/view/status.processes.js @@ -1,59 +1,80 @@ L.ui.view.extend({ - title: L.tr('Processes'), - description: L.tr('This list gives an overview over currently running system processes and their status.'), - execute: function() { - var allow_signals = this.options.acls.status; - return L.system.getProcessList().then(function(list) { - var procTable = new L.ui.table({ - columns: [ { - caption: L.tr('PID'), - key: 'pid' - }, { - caption: L.tr('Owner'), - key: 'user' - }, { - caption: L.tr('Command'), - key: 'command' - }, { - caption: L.tr('CPU usage (%)'), - key: 'cpu_percent', - format: '%d%%' - }, { - caption: L.tr('Memory usage (%)'), - key: 'vsize_percent', - format: '%d%%' - }, { - key: 'pid', - format: function(v, n) { - return $('
') - .addClass('btn-group') - .append($('