luci-app-banip: sync with banIP-0.8.4-1
[project/luci.git] / applications / luci-app-banip / htdocs / luci-static / resources / view / banip / blocklist.js
1 'use strict';
2 'require view';
3 'require fs';
4 'require ui';
5
6 return view.extend({
7 load: function () {
8 return Promise.all([
9 L.resolveDefault(fs.stat('/etc/banip/banip.blocklist'), {}),
10 L.resolveDefault(fs.read_direct('/etc/banip/banip.blocklist'), '')
11 ]);
12 },
13 handleSave: function (ev) {
14 let value = ((document.querySelector('textarea').value || '').trim().toLowerCase().replace(/\r\n/g, '\n')) + '\n';
15 return fs.write('/etc/banip/banip.blocklist', value)
16 .then(function () {
17 document.querySelector('textarea').value = value;
18 document.body.scrollTop = document.documentElement.scrollTop = 0;
19 ui.addNotification(null, E('p', _('Blocklist modifications have been saved, start the Domain Lookup or restart banIP that changes take effect.')), 'info');
20 }).catch(function (e) {
21 document.body.scrollTop = document.documentElement.scrollTop = 0;
22 ui.addNotification(null, E('p', _('Unable to save modifications: %s').format(e.message)), 'error');
23 });
24 },
25 render: function (blocklist) {
26 if (blocklist[0].size >= 100000) {
27 document.body.scrollTop = document.documentElement.scrollTop = 0;
28 ui.addNotification(null, E('p', _('The blocklist is too big, unable to save modifications.')), 'error');
29 }
30 return E([
31 E('p', {},
32 _('This is the local banIP blocklist that will prevent certain MAC/IP/CIDR addresses.<br /> \
33 <em><b>Please note:</b></em> add only exactly one MAC/IPv4/IPv6 address or domain name per line.')),
34 E('p', {},
35 E('textarea', {
36 'style': 'width: 100% !important; padding: 5px; font-family: monospace',
37 'spellcheck': 'false',
38 'wrap': 'off',
39 'rows': 25
40 }, [blocklist[1] != null ? blocklist[1] : ''])
41 )
42 ]);
43 },
44 handleSaveApply: null,
45 handleReset: null
46 });