8 return fs
.trimmed('/proc/sys/kernel/hostname');
11 handleArchiveUpload: function(ev
) {
12 return ui
.uploadFile('/tmp/nlbw-restore.tar.gz').then(function() {
13 return fs
.exec('/usr/libexec/nlbwmon-action', [ 'restore' ]).then(function(res
) {
15 throw new Error(res
.stderr
|| res
.stdout
);
17 var json
= JSON
.parse(res
.stdout
|| '{}'),
18 list
= (L
.isObject(json
) && Array
.isArray(json
.restored
)) ? json
.restored
: [];
20 ui
.showModal(_('Restore complete'), [
21 E('p', [ _('The following database files have been restored:') ]),
22 E('ul', list
.map(function(file
) { return E('li', [ file
]) })),
23 E('div', { 'class': 'right' }, [
24 E('button', { 'click': ui
.hideModal
}, [ _('Dismiss') ])
27 }).catch(function(err
) {
28 ui
.addNotification(null, E('p', [ _('Failed to restore backup archive: %s').format(err
.message
) ]));
33 handleArchiveDownload: function(hostname
, ev
) {
34 return fs
.exec_direct('/usr/libexec/nlbwmon-action', [ 'backup' ], 'blob').then(function(blob
) {
35 var url
= window
.URL
.createObjectURL(blob
),
37 name
= 'nlbwmon-backup-%s-%04d-%02d-%02d.tar.gz'.format(hostname
, date
.getFullYear(), date
.getMonth() + 1, date
.getDate()),
38 link
= E('a', { 'style': 'display:none', 'href': url
, 'download': name
});
40 document
.body
.appendChild(link
);
42 document
.body
.removeChild(link
);
43 window
.URL
.revokeObjectURL(url
);
44 }).catch(function(err
) {
45 ui
.addNotification(null, E('p', [ _('Failed to download backup archive: %s').format(err
.message
) ]));
49 render: function(hostname
) {
51 E('h2', [ _('Netlink Bandwidth Monitor - Backup / Restore') ]),
52 E('h5', [ _('Restore Database Backup') ]),
55 'click': ui
.createHandlerFn(this, 'handleArchiveUpload')
58 E('h5', [ _('Download Database Backup') ]),
61 'click': ui
.createHandlerFn(this, 'handleArchiveDownload', hostname
)
62 }, [ _('Generate Backup') ])
68 handleSaveApply
: null,