summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status
diff options
context:
space:
mode:
authorFlorian Eckert <fe@dev.tdt.de>2021-07-02 15:23:39 +0200
committerFlorian Eckert <fe@dev.tdt.de>2021-07-09 08:38:11 +0200
commitf5f6b3e4f8e3faed4e9c9926e283c9cf226d4bd8 (patch)
treee2718f194ede046a90274443f6b61198f35a0961 /applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status
parent12067c8308936abb567001650105b33bec9a56a9 (diff)
luci-app-mwan3: convert to JS
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
Diffstat (limited to 'applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status')
-rw-r--r--applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/detail.js22
-rw-r--r--applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/diagnostics.js116
-rw-r--r--applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/overview.js104
-rw-r--r--applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/troubleshooting.js22
4 files changed, 264 insertions, 0 deletions
diff --git a/applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/detail.js b/applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/detail.js
new file mode 100644
index 0000000000..552b1321fb
--- /dev/null
+++ b/applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/detail.js
@@ -0,0 +1,22 @@
+'use strict';
+'require fs';
+'require view';
+
+return view.extend({
+ load: function() {
+ return L.resolveDefault(fs.exec_direct('/usr/sbin/mwan3', [ 'status' ]),'');
+ },
+
+ render: function (report) {
+ return E('div', { 'class': 'cbi-map', 'id': 'map' }, [
+ E('h2', _('MultiWAN Manager - Status')),
+ E('div', { 'class': 'cbi-section' }, [
+ E('pre', [ report ])
+ ]),
+ ])
+ },
+
+ handleSaveApply: null,
+ handleSave: null,
+ handleReset: null
+})
diff --git a/applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/diagnostics.js b/applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/diagnostics.js
new file mode 100644
index 0000000000..71bee68f88
--- /dev/null
+++ b/applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/diagnostics.js
@@ -0,0 +1,116 @@
+'use strict';
+'require fs';
+'require uci';
+'require dom';
+'require ui';
+'require view';
+
+return view.extend({
+ handleCommand: function(exec, args) {
+ var buttons = document.querySelectorAll('.cbi-button');
+
+ for (var i = 0; i < buttons.length; i++)
+ buttons[i].setAttribute('disabled', 'true');
+
+ return fs.exec(exec, args).then(function(res) {
+ var out = document.querySelector('.command-output');
+ out.style.display = '';
+
+ dom.content(out, [ res.stdout || '', res.stderr || '' ]);
+ }).catch(function(err) {
+ ui.addNotification(null, E('p', [ err ]))
+ }).finally(function() {
+ for (var i = 0; i < buttons.length; i++)
+ buttons[i].removeAttribute('disabled');
+ });
+ },
+
+ handleAction: function(ev) {
+ var iface = document.getElementById('iface');
+ var task = document.getElementById('task');
+
+ switch (task.value) {
+ case 'gateway':
+ return this.handleCommand('/usr/libexec/luci-mwan3',
+ [ 'diag', 'gateway', iface.value ]);
+ case 'tracking':
+ return this.handleCommand('/usr/libexec/luci-mwan3',
+ [ 'diag', 'tracking', iface.value ]);
+ case 'rules':
+ return this.handleCommand('/usr/libexec/luci-mwan3',
+ [ 'diag', 'rules', iface.value ]);
+ case 'routes':
+ return this.handleCommand('/usr/libexec/luci-mwan3',
+ [ 'diag', 'routes', iface.value ]);
+ case 'ifup':
+ return this.handleCommand('/usr/sbin/mwan3',
+ [ 'ifup', iface.value]);
+ case 'ifdown':
+ return this.handleCommand('/usr/sbin/mwan3',
+ [ 'ifdown', iface.value]);
+ }
+ },
+
+ load: function() {
+ return Promise.all([
+ uci.load('mwan3')
+ ]);
+ },
+
+ render: function () {
+
+ var taskSel = [
+ E('option', { 'value': 'gateway' }, [ _('Ping default gateway') ]),
+ E('option', { 'value': 'tracking' }, [ _('Ping tracking IP') ]),
+ E('option', { 'value': 'rules' }, [ _('Check IP rules') ]),
+ E('option', { 'value': 'routes' }, [ _('Check routing table') ]),
+ E('option', { 'value': 'ifup' }, [ _('Hotplug ifup') ]),
+ E('option', { 'value': 'ifdown' }, [ _('Hotplug ifdown') ])
+ ];
+
+ var ifaceSel = [E('option', { value: '' }, [_('-- Interface Selection --')])];
+
+ var options = uci.sections('mwan3', 'interface')
+ for (var i = 0; i < options.length; i++) {
+ ifaceSel.push(E('option', { 'value': options[i]['.name'] }, options[i]['.name']));
+ }
+
+ return E('div', { 'class': 'cbi-map', 'id': 'map' }, [
+ E('h2', {}, [ _('MultiWAN Manager - Diagnostics') ]),
+ E('div', { 'class': 'cbi-section' }, [
+ E('div', { 'class': 'cbi-section-node' }, [
+ E('div', { 'class': 'cbi-value' }, [
+ E('label', { 'class': 'cbi-value-title' }, [ _('Interface') ]),
+ E('div', { 'class': 'cbi-value-field' }, [
+ E('select', {'class': 'cbi-input-select', 'id': 'iface'},
+ ifaceSel
+ )
+ ])
+ ]),
+ E('div', { 'class': 'cbi-value' }, [
+ E('label', { 'class': 'cbi-value-title' }, [ _('Task') ]),
+ E('div', { 'class': 'cbi-value-field' }, [
+ E('select', { 'class': 'cbi-input-select', 'id': 'task' },
+ taskSel
+ )
+ ])
+ ])
+ ])
+ ]),
+ '\xa0',
+ E('pre', { 'class': 'command-output', 'style': 'display:none' }),
+ '\xa0',
+ E('div', { 'class': 'right' }, [
+ E('button', {
+ 'class': 'cbi-button cbi-button-apply',
+ 'id': 'execute',
+ 'click': ui.createHandlerFn(this, 'handleAction')
+ }, [ _('Execute') ]),
+ ]),
+ ]);
+ },
+
+ handleSaveApply: null,
+ handleSave: null,
+ handleReset: null
+})
diff --git a/applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/overview.js b/applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/overview.js
new file mode 100644
index 0000000000..14e0b0252b
--- /dev/null
+++ b/applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/overview.js
@@ -0,0 +1,104 @@
+'use strict';
+'require poll';
+'require view';
+'require rpc';
+
+var callMwan3Status = rpc.declare({
+ object: 'mwan3',
+ method: 'status',
+ expect: { },
+});
+
+document.querySelector('head').appendChild(E('link', {
+ 'rel': 'stylesheet',
+ 'type': 'text/css',
+ 'href': L.resource('view/mwan3/mwan3.css')
+}));
+
+function renderMwan3Status(status) {
+ if (!status.interfaces)
+ return '<strong>%h</strong>'.format(_('No MWAN interfaces found'));
+
+ var statusview = '';
+ for ( var iface in status.interfaces) {
+ var state = '';
+ var css = '';
+ var time = '';
+ var tname = '';
+ switch (status.interfaces[iface].status) {
+ case 'online':
+ state = _('Online');
+ css = 'success';
+ time = '%t'.format(status.interfaces[iface].online);
+ tname = _('Uptime');
+ css = 'success';
+ break;
+ case 'offline':
+ state = _('Offline');
+ css = 'danger';
+ time = '%t'.format(status.interfaces[iface].offline);
+ tname = _('Downtime');
+ break;
+ case 'notracking':
+ state = _('No Tracking');
+ if ((status.interfaces[iface].uptime) > 0) {
+ css = 'success';
+ time = '%t'.format(status.interfaces[iface].uptime);
+ tname = _('Uptime');
+ }
+ else {
+ css = 'warning';
+ time = '';
+ tname = '';
+ }
+ break;
+ default:
+ state = _('Disabled');
+ css = 'warning';
+ time = '';
+ tname = '';
+ break;
+ }
+
+ statusview += '<div class="alert-message %h">'.format(css);
+ statusview += '<div><strong>%h:&nbsp;</strong>%h</div>'.format(_('Interface'), iface);
+ statusview += '<div><strong>%h:&nbsp;</strong>%h</div>'.format(_('Status'), state);
+
+ if (time)
+ statusview += '<div><strong>%h:&nbsp;</strong>%h</div>'.format(tname, time);
+
+ statusview += '</div>';
+ }
+
+ return statusview;
+}
+
+return view.extend({
+ load: function() {
+ return Promise.all([
+ callMwan3Status(),
+ ]);
+ },
+
+ render: function (data) {
+ poll.add(function() {
+ return callMwan3Status().then(function(result) {
+ var view = document.getElementById('mwan3-service-status');
+ view.innerHTML = renderMwan3Status(result);
+ });
+ });
+
+ return E('div', { class: 'cbi-map' }, [
+ E('h2', [ _('MultiWAN Manager - Overview') ]),
+ E('div', { class: 'cbi-section' }, [
+ E('div', { 'id': 'mwan3-service-status' }, [
+ E('em', { 'class': 'spinning' }, [ _('Collecting data ...') ])
+ ])
+ ])
+ ]);
+ },
+
+ handleSaveApply: null,
+ handleSave: null,
+ handleReset: null
+})
diff --git a/applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/troubleshooting.js b/applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/troubleshooting.js
new file mode 100644
index 0000000000..6446125175
--- /dev/null
+++ b/applications/luci-app-mwan3/htdocs/luci-static/resources/view/mwan3/status/troubleshooting.js
@@ -0,0 +1,22 @@
+'use strict';
+'require fs';
+'require view';
+
+return view.extend({
+ load: function() {
+ return L.resolveDefault(fs.exec_direct('/usr/sbin/mwan3', [ 'internal', 'ipv4' ]),'');
+ },
+
+ render: function (report) {
+ return E('div', { 'class': 'cbi-map', 'id': 'map' }, [
+ E('h2', _('MultiWAN Manager - Troubleshooting')),
+ E('div', { 'class': 'cbi-section' }, [
+ E('pre', [ report ])
+ ]),
+ ])
+ },
+
+ handleSaveApply: null,
+ handleSave: null,
+ handleReset: null
+})