1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
'use strict';
'require form';
'require fs';
'require rpc';
'require ui';
'require view';
var mapdata = { actions: {} };
var mibDownload = rpc.declare({
object: 'file',
method: 'read',
params: [ 'path' ],
expect: { data : '' },
});
return L.view.extend({
handleMIB: function(name) {
const base = '/usr/share/snmp/mibs/';
const fileName = name;
const a = document.createElement('a');
document.body.appendChild(a);
a.style.display = 'none';
return mibDownload(base + fileName).then(function(res) {
const data = res;
const file = new Blob( [data] , { type: 'text/plain'});
const fileUrl = window.URL.createObjectURL(file);
a.href = fileUrl;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(fileUrl);
document.body.removeChild(a);
});
},
load: function() {
return Promise.all([
L.resolveDefault(fs.list('/usr/share/snmp/mibs/'), [])
.then(function(entries) {
const files = [];
entries.forEach((elem) => {
if (elem.type == 'file' &&
elem.name.match(/MIB\.(mib|my|txt)$/i)) {
files.push(elem.name);
}
});
return files;
})
]);
},
render: function(data) {
let m, s, o, ss;
const files = data[0];
m = new form.JSONMap(mapdata, _('SNMP - MIB Download'),
'Here you can download SNMP-MIB files');
s = m.section(form.NamedSection, 'actions', _('Actions'));
o = s.option(form.SectionValue, 'actions',
form.NamedSection, 'actions', 'actions',
_('Download Area'));
ss = o.subsection;
files.forEach((elem) => {
o = ss.option(form.Button, 'dl_mib', _(elem));
o.inputstyle = 'action important';
o.inputtitle = _('Download');
o.onclick = ui.createHandlerFn(this, this.handleMIB, elem);
});
return m.render();
},
handleSaveApply: null,
handleSave: null,
handleReset: null
});
|