75560fd6e1fb541ef12ddd84bf2cbbbb1eba89c6
[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 var 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 (rc) {
17 document.querySelector('textarea').value = value;
18 ui.addNotification(null, E('p', _('Blocklist modifications have been saved, restart banIP that changes take effect.')), 'info');
19 }).catch(function (e) {
20 ui.addNotification(null, E('p', _('Unable to save modifications: %s').format(e.message)));
21 });
22 },
23 render: function (blocklist) {
24 if (blocklist[0].size >= 100000) {
25 ui.addNotification(null, E('p', _('The blocklist is too big, unable to save modifications.')), 'error');
26 }
27 return E([
28 E('p', {},
29 _('This is the local banIP blocklist that will prevent certain MAC/IP/CIDR addresses.<br /> \
30 <em><b>Please note:</b></em> add only exactly one MAC/IPv4/IPv6 address or domain name per line.')),
31 E('p', {},
32 E('textarea', {
33 'style': 'width: 100% !important; padding: 5px; font-family: monospace',
34 'spellcheck': 'false',
35 'wrap': 'off',
36 'rows': 25
37 }, [blocklist[1] != null ? blocklist[1] : ''])
38 )
39 ]);
40 },
41 handleSaveApply: null,
42 handleReset: null
43 });