allowlist.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict';
  2. 'require view';
  3. 'require fs';
  4. 'require ui';
  5. let notMsg, errMsg;
  6. return view.extend({
  7. load: function () {
  8. return Promise.all([
  9. L.resolveDefault(fs.stat('/etc/banip/banip.allowlist'), {}),
  10. L.resolveDefault(fs.read_direct('/etc/banip/banip.allowlist'), '')
  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.allowlist', value)
  16. .then(function () {
  17. document.querySelector('textarea').value = value;
  18. document.body.scrollTop = document.documentElement.scrollTop = 0;
  19. if (!notMsg) {
  20. ui.addNotification(null, E('p', _('Allowlist modifications have been saved, reload banIP that changes take effect.')), 'info');
  21. notMsg = true;
  22. }
  23. }).catch(function (e) {
  24. document.body.scrollTop = document.documentElement.scrollTop = 0;
  25. if (!errMsg) {
  26. ui.addNotification(null, E('p', _('Unable to save modifications: %s').format(e.message)), 'error');
  27. errMsg = true;
  28. }
  29. });
  30. },
  31. render: function (allowlist) {
  32. if (allowlist[0].size >= 100000) {
  33. document.body.scrollTop = document.documentElement.scrollTop = 0;
  34. ui.addNotification(null, E('p', _('The allowlist is too big, unable to save modifications.')), 'error');
  35. }
  36. return E([
  37. E('p', {},
  38. _('This is the local banIP allowlist that will permit certain MAC-, IP-addresses or domain names.<br /> \
  39. <em><b>Please note:</b></em> add only exactly one MAC/IPv4/IPv6 address or domain name per line. Ranges in CIDR notation and MAC/IP-bindings are allowed.')),
  40. E('p', {},
  41. E('textarea', {
  42. 'style': 'width: 100% !important; padding: 5px; font-family: monospace',
  43. 'spellcheck': 'false',
  44. 'wrap': 'off',
  45. 'rows': 25
  46. }, [allowlist[1] != null ? allowlist[1] : ''])
  47. )
  48. ]);
  49. },
  50. handleSaveApply: null,
  51. handleReset: null
  52. });