luci-app-banip: re-launch the banIP LuCI frontend
[project/luci.git] / applications / luci-app-banip / htdocs / luci-static / resources / view / banip / allowlist.js
1 'use strict';
2 'require view';
3 'require fs';
4 'require ui';
5
6 return view.extend({
7 load: function () {
8 return L.resolveDefault(fs.read_direct('/etc/banip/banip.allowlist'), '');
9 },
10 handleSave: function (ev) {
11 var value = ((document.querySelector('textarea').value || '').trim().toLowerCase().replace(/\r\n/g, '\n')) + '\n';
12 return fs.write('/etc/banip/banip.allowlist', value)
13 .then(function (rc) {
14 document.querySelector('textarea').value = value;
15 ui.addNotification(null, E('p', _('Allowlist modifications have been saved, restart banIP that changes take effect.')), 'info');
16 }).catch(function (e) {
17 ui.addNotification(null, E('p', _('Unable to save modifications: %s').format(e.message)));
18 });
19 },
20 render: function (allowlist) {
21 return E([
22 E('p', {},
23 _('This is the local banIP allowlist that will permit certain MAC/IP/CIDR addresses.<br /> \
24 <em><b>Please note:</b></em> add only exactly one MAC/IPv4/IPv6 address or domain name per line.')),
25 E('p', {},
26 E('textarea', {
27 'style': 'width: 100% !important; padding: 5px; font-family: monospace',
28 'spellcheck': 'false',
29 'wrap': 'off',
30 'rows': 25
31 }, [allowlist != null ? allowlist : ''])
32 )
33 ]);
34 },
35 handleSaveApply: null,
36 handleReset: null
37 });