luci-mod-ucentral: add diagnostic download button

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2022-12-07 17:47:33 +01:00
parent 469443da2a
commit 0e264203de
3 changed files with 35 additions and 3 deletions

View File

@@ -20,7 +20,6 @@ var callReboot = rpc.declare({
expect: { result: 0 } expect: { result: 0 }
}); });
var mapdata = { actions: {}, config: {} }; var mapdata = { actions: {}, config: {} };
return view.extend({ return view.extend({
@@ -45,6 +44,26 @@ return view.extend({
ui.awaitReconnect('192.168.1.1', 'openwrt.lan'); ui.awaitReconnect('192.168.1.1', 'openwrt.lan');
}, },
handleDiagnostics: function(ev) {
return fs.exec('/sbin/diagnostic-bundle').then(function(result) {
var form = E('form', {
method: 'post',
action: L.env.cgi_base + '/cgi-download',
enctype: 'application/x-www-form-urlencoded'
}, [
E('input', { 'type': 'hidden', 'name': 'sessionid', 'value': L.env.sessionid }),
E('input', { 'type': 'hidden', 'name': 'path', 'value': '/tmp/bundle.maverick.tar.gz' }),
E('input', { 'type': 'hidden', 'name': 'filename', 'value': 'bundle.maverick.tar.gz' }),
E('input', { 'type': 'hidden', 'name': 'mimetype', 'value': 'application/gzip' })
]);
document.body.appendChild(form);
form.submit();
form.parentNode.removeChild(form);
});
},
handleSysupgrade: function(ev) { handleSysupgrade: function(ev) {
return ui.uploadFile('/tmp/firmware.bin', ev.target.firstChild) return ui.uploadFile('/tmp/firmware.bin', ev.target.firstChild)
.then(L.bind(function(btn, reply) { .then(L.bind(function(btn, reply) {
@@ -171,6 +190,16 @@ return view.extend({
o.inputtitle = _('Flash image…'); o.inputtitle = _('Flash image…');
o.onclick = L.bind(this.handleSysupgrade, this); o.onclick = L.bind(this.handleSysupgrade, this);
o = s.option(form.SectionValue, 'actions', form.NamedSection, 'actions', 'actions', _('Diagnostic bundle'),
_('Download the default diagnostic bundle from the AP.'));
ss = o.subsection;
o = ss.option(form.Button, 'Diagnostic');
o.inputstyle = 'action important';
o.inputtitle = _('Download Diagnostics');
o.onclick = L.bind(this.handleDiagnostics, this);
return m.render(); return m.render();
}, },

View File

@@ -5,4 +5,4 @@ let bundle = require('bundle');
bundle.init('maverick'); bundle.init('maverick');
include('/usr/share/ucentral/diagnostic.uc', { bundle }); include('/usr/share/ucentral/diagnostic.uc', { bundle });
bundle.complete(); bundle.complete();
system('ln -s /tmp/bundle.maverick.tar.gz /www'); system('chmod +r /tmp/bundle.maverick.tar.gz');

View File

@@ -2,10 +2,12 @@
"luci-mod-ucentral": { "luci-mod-ucentral": {
"description": "Grant access to ucentral configuration", "description": "Grant access to ucentral configuration",
"read": { "read": {
"cgi-io": [ "download" ],
"file": { "file": {
"/etc/ucentral/profile.json": [ "read" ], "/etc/ucentral/profile.json": [ "read" ],
"/proc/mounts": [ "read" ], "/proc/mounts": [ "read" ],
"/proc/mtd": [ "read" ] "/proc/mtd": [ "read" ],
"/tmp/bundle.maverick.tar.gz": [ "read" ]
}, },
"ubus": { "ubus": {
"file": [ "read" ], "file": [ "read" ],
@@ -17,6 +19,7 @@
"file": { "file": {
"/etc/ucentral/profile.json": [ "write" ], "/etc/ucentral/profile.json": [ "write" ],
"/sbin/certupdate": [ "exec" ], "/sbin/certupdate": [ "exec" ],
"/sbin/diagnostic-bundle": [ "exec" ],
"/sbin/firstboot -r -y": [ "exec" ], "/sbin/firstboot -r -y": [ "exec" ],
"/sbin/profileupdate": [ "exec" ], "/sbin/profileupdate": [ "exec" ],
"/sbin/sysupgrade -n /tmp/firmware.bin": [ "exec" ], "/sbin/sysupgrade -n /tmp/firmware.bin": [ "exec" ],