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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
'use strict';
'require uci';
'require view';
'require poll';
'require network';
'require rpc';
'require ui';
'require olsr.common_js as olsr';
return olsr.olsrview.extend({
action_hna() {
let self = this;
return new Promise(function (resolve, reject) {
self
.fetch_jsoninfo('hna')
.then(function ([data, has_v4, has_v6, error]) {
if (error) {
reject(error);
}
const resolveVal = uci.get('luci_olsr', 'general', 'resolve');
function compare(a, b) {
if (a.proto === b.proto) {
return a.genmask < b.genmask;
} else {
return a.proto < b.proto ? -1 : a.proto > b.proto ? 1 : 0;
}
}
let modifiedData;
self
.callGetHosts()
.then(function (res) {
function matchHostnames(ip) {
const lines = res.hosts.split('\n');
for (let line of lines) {
const ipandhostname = line.trim().split(/\s+/);
if (ipandhostname[0] === ip) {
return ipandhostname[1];
}
}
return null;
}
modifiedData = data.map(function (v) {
if (resolveVal === '1') {
const hostname = matchHostnames(v.gateway);
if (hostname) {
v.hostname = hostname;
}
}
if (v.validityTime) {
v.validityTime = parseInt((v.validityTime / 1000).toFixed(0));
}
return v;
});
modifiedData.sort(compare);
const result = { hna: modifiedData, has_v4: has_v4, has_v6: has_v6 };
resolve(result);
})
.catch(function (err) {
modifiedData = data;
console.error(err);
});
})
.catch(function (err) {
reject(err);
});
});
},
load() {
let self = this;
poll.add(function () {
self.render();
}, 5);
return Promise.all([uci.load('olsrd'), uci.load('luci_olsr')]);
},
render() {
let hna_res;
let has_v4;
let has_v6;
return this.action_hna()
.then(function (result) {
hna_res = result.hna;
has_v4 = result.has_v4;
has_v6 = result.has_v6;
const table = E('div', { 'class': 'table cbi-section-table', 'id': 'olsrd_hna' }, [
E('div', { 'class': 'tr cbi-section-table-titles' }, [
E('div', { 'class': 'th cbi-section-table-cell' }, _('Announced network')),
E('div', { 'class': 'th cbi-section-table-cell' }, _('OLSR gateway')),
E('div', { 'class': 'th cbi-section-table-cell' }, _('Validity Time')),
]),
]);
let i = 1;
const rv = [];
for (let entry of hna_res) {
rv.push({
proto: entry.proto,
destination: entry.destination,
genmask: entry.genmask,
gateway: entry.gateway,
hostname: entry.hostname,
validityTime: entry.validityTime,
});
}
const info = rv;
const hnadiv = document.getElementById('olsrd_hna');
if (hnadiv) {
let s =
'<div class="tr cbi-section-table-titles">' +
'<div class="th cbi-section-table-cell">Announced network</div>' +
'<div class="th cbi-section-table-cell">OLSR gateway</div>' +
'<div class="th cbi-section-table-cell">Validity Time</div>' +
'</div>';
for (let idx = 0; idx < info.length; idx++) {
const hna = info[idx];
let linkgw = '';
s += '<div class="tr cbi-section-table-row cbi-rowstyle-' + (1 + (idx % 2)) + ' proto-' + hna.proto + '">';
if (hna.proto === '6') {
linkgw = '<a href="http://[' + hna.gateway + ']/cgi-bin-status.html">' + hna.gateway + '</a>';
} else {
linkgw = '<a href="http://' + hna.gateway + '/cgi-bin-status.html">' + hna.gateway + '</a>';
}
const validity = hna.validityTime !== undefined ? hna.validityTime + 's' : '-';
const hostname = hna.hostname !== null ? ' / <a href="http://%q/cgi-bin-status.html">%h</a>'.format(hna.hostname, hna.hostname) : '';
s +=
'<div class="td cbi-section-table-cell left">' +
(hna.destination + '/' + hna.genmask) +
'</div>' +
'<div class="td cbi-section-table-cell left">' +
(linkgw + hostname) +
'</div>' +
'<div class="td cbi-section-table-cell left">' +
validity +
'</div>' +
'</div>';
}
hnadiv.innerHTML = s;
}
i = 1;
for (let route of hna_res) {
const tr = E('div', { 'class': 'tr cbi-section-table-row cbi-rowstyle-' + i + ' proto-' + route.proto }, [
E('div', { 'class': 'td cbi-section-table-cell left' }, route.destination + '/' + route.genmask),
E('div', { 'class': 'td cbi-section-table-cell left' }, [
route.proto === '6' ? E('a', { 'href': 'http://[' + route.gateway + ']/cgi-bin-status.html' }, route.gateway) : E('a', { 'href': 'http://' + route.gateway + '/cgi-bin-status.html' }, route.gateway),
route.hostname ? E('span', {}, [' / ', E('a', { 'href': 'http://%q/cgi-bin-status.html'.format(route.hostname) }, '%h'.format(route.hostname))]) : '',
]),
E('div', { 'class': 'td cbi-section-table-cell left' }, route.validityTime ? route.validityTime + 's' : '-'),
]);
table.appendChild(tr);
i = (i % 2) + 1;
}
const fieldset = E('fieldset', { 'class': 'cbi-section' }, [E('legend', {}, _('Overview of currently active OLSR host net announcements')), table]);
const h2 = E('h2', { 'name': 'content' }, _('Active host net announcements'));
const divToggleButtons = E('div', { 'id': 'togglebuttons' });
let statusOlsrCommonJs = null;
if (has_v4 && has_v6) {
statusOlsrCommonJs = E('script', { 'type': 'text/javascript', 'src': L.resource('olsr/common_js.js') });
}
const fresult = E([], {}, [h2, divToggleButtons, fieldset, statusOlsrCommonJs]);
return fresult;
})
.catch(function (error) {
console.error(error);
});
},
handleSaveApply: null,
handleSave: null,
handleReset: null,
});
|