2020-06-19 20:43:08 +03:00
|
|
|
'use strict';
|
|
|
|
|
'require fs';
|
2021-12-05 19:18:32 +03:00
|
|
|
'require poll';
|
2020-06-19 20:43:08 +03:00
|
|
|
'require ui';
|
2021-12-05 19:18:32 +03:00
|
|
|
'require view';
|
2020-06-19 20:43:08 +03:00
|
|
|
'require view.ruantiblock.tools as tools';
|
|
|
|
|
|
2021-12-05 19:18:32 +03:00
|
|
|
return view.extend({
|
2021-11-04 18:57:08 +03:00
|
|
|
infoPoll: function() {
|
|
|
|
|
return fs.exec_direct(tools.execPath, [ 'html-info' ], 'json').catch(e => {
|
|
|
|
|
ui.addNotification(null, E('p', _('Unable to execute or read contents')
|
|
|
|
|
+ ': %s [ %s ]'.format(e.message, tools.execPath)
|
|
|
|
|
));
|
2021-12-05 19:18:32 +03:00
|
|
|
poll.stop();
|
2021-11-04 18:57:08 +03:00
|
|
|
}).then(data => {
|
|
|
|
|
if(!data) {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
data = JSON.parse(data);
|
|
|
|
|
} catch(err) {};
|
|
|
|
|
|
|
|
|
|
if(data.status === 'enabled') {
|
|
|
|
|
let date = document.getElementById('last_blacklist_update.date');
|
|
|
|
|
|
|
|
|
|
if(data.last_blacklist_update.status) {
|
|
|
|
|
if(date) {
|
|
|
|
|
date.textContent = data.last_blacklist_update.date;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let ip = document.getElementById('last_blacklist_update.ip');
|
|
|
|
|
if(ip) {
|
|
|
|
|
ip.textContent = data.last_blacklist_update.ip;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let cidr = document.getElementById('last_blacklist_update.cidr');
|
|
|
|
|
if(cidr) {
|
|
|
|
|
cidr.textContent = data.last_blacklist_update.cidr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let fqdn = document.getElementById('last_blacklist_update.fqdn');
|
|
|
|
|
if(fqdn) {
|
|
|
|
|
fqdn.textContent = data.last_blacklist_update.fqdn;
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
if(date) {
|
|
|
|
|
date.textContent = _('No data');
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if(data.iptables) {
|
|
|
|
|
for(let [k, v] of Object.entries(data.iptables)) {
|
|
|
|
|
if(k === '_dummy') continue;
|
|
|
|
|
|
|
|
|
|
let elem = document.getElementById('iptables.' + k);
|
|
|
|
|
if(elem) {
|
|
|
|
|
elem.textContent = v;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if(data.ipset) {
|
|
|
|
|
for(let [k, v] of Object.entries(data.ipset)) {
|
|
|
|
|
if(k === '_dummy') continue;
|
|
|
|
|
|
|
|
|
|
let elem0 = document.getElementById('ipset.' + k + '.' + '0');
|
|
|
|
|
let elem1 = document.getElementById('ipset.' + k + '.' + '1');
|
|
|
|
|
if(elem0 && elem1) {
|
|
|
|
|
elem0.textContent = v[0];
|
|
|
|
|
elem1.textContent = v[1];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
} else {
|
2021-12-05 19:18:32 +03:00
|
|
|
if(poll.active()) {
|
|
|
|
|
poll.stop();
|
2021-11-04 18:57:08 +03:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
load: function() {
|
|
|
|
|
return fs.exec_direct(tools.execPath, [ 'html-info' ], 'json').catch(e => {
|
|
|
|
|
ui.addNotification(null, E('p', _('Unable to execute or read contents')
|
|
|
|
|
+ ': %s [ %s ]'.format(e.message, tools.execPath)
|
|
|
|
|
));
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
render: function(data) {
|
|
|
|
|
if(!data) {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
data = JSON.parse(data);
|
|
|
|
|
} catch(err) {};
|
|
|
|
|
|
|
|
|
|
let update_status = null,
|
|
|
|
|
iptables = null,
|
|
|
|
|
ipset = null;
|
|
|
|
|
if(data) {
|
|
|
|
|
if(data.status === 'enabled') {
|
2021-12-08 21:13:09 +03:00
|
|
|
update_status = E('table', { 'class': 'table' });
|
2021-11-04 18:57:08 +03:00
|
|
|
|
|
|
|
|
if(data.last_blacklist_update.status) {
|
|
|
|
|
update_status.append(
|
2021-12-08 21:13:09 +03:00
|
|
|
E('tr', { 'class': 'tr' }, [
|
|
|
|
|
E('td', { 'class': 'td left', 'style': 'min-width:33%' },
|
2021-11-04 18:57:08 +03:00
|
|
|
_('Last blacklist update') + ':'),
|
2021-12-08 21:13:09 +03:00
|
|
|
E('td', { 'class': 'td left',
|
2021-11-04 18:57:08 +03:00
|
|
|
'id': 'last_blacklist_update.date' },
|
|
|
|
|
data.last_blacklist_update.date),
|
|
|
|
|
]),
|
2021-12-08 21:13:09 +03:00
|
|
|
E('tr', { 'class': 'tr' }, [
|
|
|
|
|
E('td', { 'class': 'td left' }, 'CIDR:'),
|
|
|
|
|
E('td', { 'class': 'td left',
|
2021-11-04 18:57:08 +03:00
|
|
|
'id': 'last_blacklist_update.cidr' },
|
|
|
|
|
data.last_blacklist_update.cidr),
|
|
|
|
|
]),
|
2022-05-10 20:37:10 +03:00
|
|
|
E('tr', { 'class': 'tr' }, [
|
|
|
|
|
E('td', { 'class': 'td left' }, 'IP:'),
|
|
|
|
|
E('td', { 'class': 'td left',
|
|
|
|
|
'id': 'last_blacklist_update.ip' },
|
|
|
|
|
data.last_blacklist_update.ip),
|
|
|
|
|
]),
|
2021-12-08 21:13:09 +03:00
|
|
|
E('tr', { 'class': 'tr' }, [
|
|
|
|
|
E('td', { 'class': 'td left' }, 'FQDN:'),
|
|
|
|
|
E('td', { 'class': 'td left',
|
2021-11-04 18:57:08 +03:00
|
|
|
'id': 'last_blacklist_update.fqdn' },
|
|
|
|
|
data.last_blacklist_update.fqdn),
|
|
|
|
|
])
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
update_status.append(
|
2021-12-08 21:13:09 +03:00
|
|
|
E('tr', { 'class': 'tr' }, [
|
|
|
|
|
E('td', { 'class': 'td left' },
|
2021-11-04 18:57:08 +03:00
|
|
|
_('Last blacklist update')),
|
2021-12-08 21:13:09 +03:00
|
|
|
E('td', { 'class': 'td left' }, _('No data')),
|
2021-11-04 18:57:08 +03:00
|
|
|
])
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if(data.iptables) {
|
2021-12-08 21:13:09 +03:00
|
|
|
let table_iptables = E('table', { 'class': 'table' }, [
|
|
|
|
|
E('tr', { 'class': 'tr table-titles' }, [
|
|
|
|
|
E('th', { 'class': 'th left', 'style': 'min-width:33%' },
|
2021-11-04 18:57:08 +03:00
|
|
|
_('Match-set')),
|
2021-12-08 21:13:09 +03:00
|
|
|
E('th', { 'class': 'th left' }, _('Bytes')),
|
2021-11-04 18:57:08 +03:00
|
|
|
]),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
for(let [k, v] of Object.entries(data.iptables)) {
|
|
|
|
|
if(k === '_dummy') continue;
|
|
|
|
|
table_iptables.append(
|
2021-12-08 21:13:09 +03:00
|
|
|
E('tr', { 'class': 'tr' }, [
|
|
|
|
|
E('td', {
|
2021-11-04 18:57:08 +03:00
|
|
|
'class' : 'td left',
|
|
|
|
|
'data-title': _('Match-set'),
|
|
|
|
|
}, k),
|
2021-12-08 21:13:09 +03:00
|
|
|
E('td', {
|
2021-11-04 18:57:08 +03:00
|
|
|
'class' : 'td left',
|
|
|
|
|
'id' : 'iptables.' + k,
|
|
|
|
|
'data-title': _('Bytes'),
|
|
|
|
|
}, v),
|
|
|
|
|
])
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
iptables = E([
|
|
|
|
|
E('h3', {}, _('Iptables rules')),
|
|
|
|
|
table_iptables,
|
|
|
|
|
]);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if(data.ipset) {
|
2021-12-08 21:13:09 +03:00
|
|
|
let table_ipset = E('table', { 'class': 'table' },
|
|
|
|
|
E('tr', { 'class': 'tr table-titles' }, [
|
|
|
|
|
E('th', { 'class': 'th left', 'style': 'min-width:33%' },
|
2021-11-04 18:57:08 +03:00
|
|
|
_('Name')),
|
2021-12-08 21:13:09 +03:00
|
|
|
E('th', { 'class': 'th left' },
|
2021-11-04 18:57:08 +03:00
|
|
|
_('Size in memory')),
|
2021-12-08 21:13:09 +03:00
|
|
|
E('th', { 'class': 'th left' },
|
2021-11-04 18:57:08 +03:00
|
|
|
_('Number of entries')),
|
|
|
|
|
])
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
for(let [k, v] of Object.entries(data.ipset)) {
|
|
|
|
|
if(k === '_dummy') continue;
|
|
|
|
|
|
|
|
|
|
table_ipset.append(
|
2021-12-08 21:13:09 +03:00
|
|
|
E('tr', { 'class': 'tr' }, [
|
|
|
|
|
E('td', {
|
2021-12-05 19:18:32 +03:00
|
|
|
'class': 'td left',
|
2021-11-04 18:57:08 +03:00
|
|
|
'data-title': _('Name'),
|
|
|
|
|
}, k),
|
2021-12-08 21:13:09 +03:00
|
|
|
E('td', {
|
2021-11-04 18:57:08 +03:00
|
|
|
'class' : 'td left',
|
|
|
|
|
'id' : 'ipset.' + k + '.' + '0',
|
|
|
|
|
'data-title': _('Size in memory'),
|
|
|
|
|
}, v[0]),
|
2021-12-08 21:13:09 +03:00
|
|
|
E('td', {
|
2021-11-04 18:57:08 +03:00
|
|
|
'class' : 'td left',
|
|
|
|
|
'id' : 'ipset.' + k + '.' + '1',
|
|
|
|
|
'data-title': _('Number of entries'),
|
|
|
|
|
}, v[1]),
|
|
|
|
|
])
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ipset = E([
|
|
|
|
|
E('h3', {}, _('Ipset')),
|
|
|
|
|
table_ipset,
|
|
|
|
|
]);
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-05 19:18:32 +03:00
|
|
|
poll.add(this.infoPoll);
|
2021-11-04 18:57:08 +03:00
|
|
|
} else {
|
|
|
|
|
update_status = E('em', {}, _('Status') + ' : ' + _('disabled'));
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
return E([
|
|
|
|
|
E('h2', { 'class': 'fade-in' },
|
|
|
|
|
_('Ruantiblock') + ' - ' + _('Statistics')
|
|
|
|
|
),
|
|
|
|
|
E('div', { 'class': 'cbi-section-descr fade-in' }),
|
|
|
|
|
E('div', { 'class': 'cbi-section fade-in' },
|
|
|
|
|
E('div', { 'class': 'cbi-section-node' }, update_status)
|
|
|
|
|
),
|
|
|
|
|
E('div', { 'class': 'cbi-section fade-in' },
|
|
|
|
|
E('div', { 'class': 'cbi-section-node' }, iptables)
|
|
|
|
|
),
|
|
|
|
|
E('div', { 'class': 'cbi-section fade-in' },
|
|
|
|
|
E('div', { 'class': 'cbi-section-node' }, ipset)
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
handleSave : null,
|
|
|
|
|
handleSaveApply: null,
|
|
|
|
|
handleReset : null,
|
2020-06-19 20:43:08 +03:00
|
|
|
});
|