overview.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. 'use strict';
  2. 'require dom';
  3. 'require view';
  4. 'require poll';
  5. 'require fs';
  6. 'require ui';
  7. 'require uci';
  8. 'require form';
  9. 'require tools.widgets as widgets';
  10. /*
  11. button handling
  12. */
  13. function handleAction(ev) {
  14. if (ev === 'restart' || ev === 'reload') {
  15. let map = document.querySelector('.cbi-map');
  16. dom.callClassMethod(map, 'save')
  17. .then(L.bind(ui.changes.apply, ui.changes))
  18. .then(function () {
  19. return fs.exec_direct('/etc/init.d/banip', [ev]);
  20. });
  21. } else {
  22. return fs.exec_direct('/etc/init.d/banip', [ev]);
  23. }
  24. }
  25. return view.extend({
  26. load: function () {
  27. return Promise.all([
  28. L.resolveDefault(fs.read_direct('/etc/banip/banip.custom.feeds'), ''),
  29. L.resolveDefault(fs.read_direct('/etc/banip/banip.feeds'), ''),
  30. L.resolveDefault(fs.read_direct('/etc/banip/banip.countries'), ''),
  31. uci.load('banip')
  32. ]);
  33. },
  34. render: function (result) {
  35. let m, s, o;
  36. m = new form.Map('banip', 'banIP', _('Configuration of the banIP package to ban incoming and outgoing IPs via named nftables Sets. \
  37. For further information please check the <a style="color:#37c;font-weight:bold;" href="https://github.com/openwrt/packages/blob/master/net/banip/files/README.md" target="_blank" rel="noreferrer noopener" >online documentation</a>'));
  38. /*
  39. poll runtime information
  40. */
  41. let buttons, rtRes, infStat, infVer, infElements, infFeeds, infDevices, infUplink, infSystem, nftInfos, runInfos, infFlags, last_run
  42. pollData: poll.add(function () {
  43. return L.resolveDefault(fs.stat('/var/run/banip.lock')).then(function (stat) {
  44. buttons = document.querySelectorAll('.cbi-button');
  45. infStat = document.getElementById('status');
  46. if (stat) {
  47. for (let i = 0; i < buttons.length; i++) {
  48. buttons[i].setAttribute('disabled', 'true');
  49. }
  50. if (infStat && !infStat.classList.contains('spinning')) {
  51. infStat.classList.add('spinning');
  52. }
  53. } else {
  54. for (let i = 0; i < buttons.length; i++) {
  55. buttons[i].removeAttribute('disabled');
  56. }
  57. if (infStat && infStat.classList.contains('spinning')) {
  58. infStat.classList.remove('spinning');
  59. }
  60. }
  61. L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['status'])).then(function (result) {
  62. if (result) {
  63. rtRes = result.trim().split('\n');
  64. if (rtRes) {
  65. for (let i = 0; i < rtRes.length; i++) {
  66. if (rtRes[i].match(/^\s+\+\sstatus\s+\:\s+(.*)$/)) {
  67. rtRes.status = rtRes[i].match(/^\s+\+\sstatus\s+\:\s+(.*)$/)[1];
  68. } else if (rtRes[i].match(/^\s+\+\sversion\s+\:\s+(.*)$/)) {
  69. rtRes.version = rtRes[i].match(/^\s+\+\sversion\s+\:\s+(.*)$/)[1];
  70. } else if (rtRes[i].match(/^\s+\+\selement_count\s+\:\s+(.*)$/)) {
  71. rtRes.elementCount = rtRes[i].match(/^\s+\+\selement_count\s+\:\s+(.*)$/)[1];
  72. } else if (rtRes[i].match(/^\s+\+\sactive_feeds\s+\:\s+(.*)$/)) {
  73. rtRes.activeFeeds = rtRes[i].match(/^\s+\+\sactive_feeds\s+\:\s+(.*)$/)[1];
  74. } else if (rtRes[i].match(/^\s+\+\sactive_devices\s+\:\s+(.*)$/)) {
  75. rtRes.activeDevices = rtRes[i].match(/^\s+\+\sactive_devices\s+\:\s+(.*)$/)[1];
  76. } else if (rtRes[i].match(/^\s+\+\sactive_uplink\s+\:\s+(.*)$/)) {
  77. rtRes.activeUplink = rtRes[i].match(/^\s+\+\sactive_uplink\s+\:\s+(.*)$/)[1];
  78. } else if (rtRes[i].match(/^\s+\+\snft_info\s+\:\s+(.*)$/)) {
  79. rtRes.nftInfo = rtRes[i].match(/^\s+\+\snft_info\s+\:\s+(.*)$/)[1];
  80. } else if (rtRes[i].match(/^\s+\+\srun_info\s+\:\s+(.*)$/)) {
  81. rtRes.runInfo = rtRes[i].match(/^\s+\+\srun_info\s+\:\s+(.*)$/)[1];
  82. } else if (rtRes[i].match(/^\s+\+\srun_flags\s+\:\s+(.*)$/)) {
  83. rtRes.runFlags = rtRes[i].match(/^\s+\+\srun_flags\s+\:\s+(.*)$/)[1];
  84. } else if (rtRes[i].match(/^\s+\+\slast_run\s+\:\s+(.*)$/)) {
  85. rtRes.lastRun = rtRes[i].match(/^\s+\+\slast_run\s+\:\s+(.*)$/)[1];
  86. } else if (rtRes[i].match(/^\s+\+\ssystem_info\s+\:\s+(.*)$/)) {
  87. rtRes.systemInfo = rtRes[i].match(/^\s+\+\ssystem_info\s+\:\s+(.*)$/)[1];
  88. }
  89. }
  90. }
  91. if (rtRes) {
  92. infStat = document.getElementById('status');
  93. if (infStat) {
  94. infStat.textContent = rtRes.status || '-';
  95. }
  96. infVer = document.getElementById('version');
  97. if (infVer) {
  98. infVer.textContent = rtRes.version || '-';
  99. }
  100. infElements = document.getElementById('elements');
  101. if (infElements) {
  102. infElements.textContent = rtRes.elementCount || '-';
  103. }
  104. infFeeds = document.getElementById('feeds');
  105. if (infFeeds) {
  106. infFeeds.textContent = rtRes.activeFeeds || '-';
  107. }
  108. infDevices = document.getElementById('devices');
  109. if (infDevices) {
  110. infDevices.textContent = rtRes.activeDevices || '-';
  111. }
  112. infUplink = document.getElementById('uplink');
  113. if (infUplink) {
  114. infUplink.textContent = rtRes.activeUplink || '-';
  115. }
  116. nftInfos = document.getElementById('nft');
  117. if (nftInfos) {
  118. nftInfos.textContent = rtRes.nftInfo || '-';
  119. }
  120. runInfos = document.getElementById('run');
  121. if (runInfos) {
  122. runInfos.textContent = rtRes.runInfo || '-';
  123. }
  124. infFlags = document.getElementById('flags');
  125. if (infFlags) {
  126. infFlags.textContent = rtRes.runFlags || '-';
  127. }
  128. last_run = document.getElementById('last');
  129. if (last_run) {
  130. last_run.textContent = rtRes.lastRun || '-';
  131. }
  132. infSystem = document.getElementById('system');
  133. if (infSystem) {
  134. infSystem.textContent = rtRes.systemInfo || '-';
  135. }
  136. }
  137. } else {
  138. infStat = document.getElementById('status');
  139. if (infStat) {
  140. infStat.textContent = '-';
  141. poll.stop();
  142. if (infStat.classList.contains('spinning')) {
  143. infStat.classList.remove('spinning');
  144. }
  145. }
  146. }
  147. });
  148. });
  149. }, 2);
  150. /*
  151. runtime information and buttons
  152. */
  153. s = m.section(form.NamedSection, 'global');
  154. s.render = L.bind(function (view, section_id) {
  155. return E('div', { 'class': 'cbi-section' }, [
  156. E('h3', _('Information')),
  157. E('div', { 'class': 'cbi-value' }, [
  158. E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Status')),
  159. E('div', { 'class': 'cbi-value-field spinning', 'id': 'status', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '\xa0')
  160. ]),
  161. E('div', { 'class': 'cbi-value' }, [
  162. E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Version')),
  163. E('div', { 'class': 'cbi-value-field', 'id': 'version', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
  164. ]),
  165. E('div', { 'class': 'cbi-value' }, [
  166. E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Element Count')),
  167. E('div', { 'class': 'cbi-value-field', 'id': 'elements', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
  168. ]),
  169. E('div', { 'class': 'cbi-value' }, [
  170. E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Active Feeds')),
  171. E('div', { 'class': 'cbi-value-field', 'id': 'feeds', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
  172. ]),
  173. E('div', { 'class': 'cbi-value' }, [
  174. E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Active Devices')),
  175. E('div', { 'class': 'cbi-value-field', 'id': 'devices', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
  176. ]),
  177. E('div', { 'class': 'cbi-value' }, [
  178. E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Active Uplink')),
  179. E('div', { 'class': 'cbi-value-field', 'id': 'uplink', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
  180. ]),
  181. E('div', { 'class': 'cbi-value' }, [
  182. E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('NFT Information')),
  183. E('div', { 'class': 'cbi-value-field', 'id': 'nft', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
  184. ]),
  185. E('div', { 'class': 'cbi-value' }, [
  186. E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Run Information')),
  187. E('div', { 'class': 'cbi-value-field', 'id': 'run', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
  188. ]),
  189. E('div', { 'class': 'cbi-value' }, [
  190. E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Run Flags')),
  191. E('div', { 'class': 'cbi-value-field', 'id': 'flags', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
  192. ]),
  193. E('div', { 'class': 'cbi-value' }, [
  194. E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Last Run')),
  195. E('div', { 'class': 'cbi-value-field', 'id': 'last', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
  196. ]),
  197. E('div', { 'class': 'cbi-value' }, [
  198. E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('System Information')),
  199. E('div', { 'class': 'cbi-value-field', 'id': 'system', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
  200. ]),
  201. E('div', { class: 'right' }, [
  202. E('button', {
  203. 'class': 'btn cbi-button cbi-button-action',
  204. 'click': ui.createHandlerFn(this, function () {
  205. return handleAction('lookup');
  206. })
  207. }, [_('Domain Lookup')]),
  208. '\xa0',
  209. E('button', {
  210. 'class': 'btn cbi-button cbi-button-negative',
  211. 'click': ui.createHandlerFn(this, function () {
  212. return handleAction('stop');
  213. })
  214. }, [_('Stop')]),
  215. '\xa0',
  216. E('button', {
  217. 'class': 'btn cbi-button cbi-button-positive',
  218. 'click': ui.createHandlerFn(this, function () {
  219. return handleAction('reload');
  220. })
  221. }, [_('Reload')]),
  222. '\xa0',
  223. E('button', {
  224. 'class': 'btn cbi-button cbi-button-positive',
  225. 'click': ui.createHandlerFn(this, function () {
  226. return handleAction('restart');
  227. })
  228. }, [_('Restart')]),
  229. '\xa0'
  230. ])
  231. ]);
  232. }, o, this);
  233. this.pollData;
  234. /*
  235. tabbed config section
  236. */
  237. s = m.section(form.NamedSection, 'global', 'banip', _('Settings'));
  238. s.addremove = false;
  239. s.tab('general', _('General Settings'));
  240. s.tab('advanced', _('Advanced Settings'));
  241. s.tab('adv_chain', _('Table/Chain Settings'));
  242. s.tab('adv_set', _('Feed/Set Settings'));
  243. s.tab('adv_log', _('Log Settings'));
  244. s.tab('adv_email', _('E-Mail Settings'));
  245. s.tab('feeds', _('Feed Selection'));
  246. /*
  247. general settings tab
  248. */
  249. o = s.taboption('general', form.DummyValue, '_sub');
  250. o.rawhtml = true;
  251. o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'
  252. + '<hr style="width: 200px; height: 1px;" />';
  253. o = s.taboption('general', form.Flag, 'ban_enabled', _('Enabled'), _('Enable the banIP service.'));
  254. o.rmempty = false;
  255. o = s.taboption('general', form.Flag, 'ban_debug', _('Verbose Debug Logging'), _('Enable verbose debug logging in case of processing errors.'));
  256. o.rmempty = false;
  257. o = s.taboption('general', form.Flag, 'ban_autodetect', _('Auto Detection'), _('Detect relevant network devices, interfaces, subnets, protocols and utilities automatically.'));
  258. o.rmempty = false;
  259. o = s.taboption('general', form.Flag, 'ban_protov4', _('IPv4 Support'), _('Enables IPv4 support.'));
  260. o.depends('ban_autodetect', '0');
  261. o.optional = true;
  262. o.retain = true;
  263. o = s.taboption('general', form.Flag, 'ban_protov6', _('IPv6 Support'), _('Enables IPv6 support.'));
  264. o.depends('ban_autodetect', '0');
  265. o.optional = true;
  266. o.retain = true;
  267. o = s.taboption('general', widgets.DeviceSelect, 'ban_dev', _('Network Devices'), _('Select the WAN network device(s).'));
  268. o.depends('ban_autodetect', '0');
  269. o.multiple = true;
  270. o.nocreate = true;
  271. o.optional = true;
  272. o.retain = true;
  273. o = s.taboption('general', widgets.NetworkSelect, 'ban_ifv4', _('IPv4 Network Interfaces'), _('Select the logical WAN IPv4 network interface(s).'));
  274. o.depends('ban_autodetect', '0');
  275. o.multiple = true;
  276. o.nocreate = true;
  277. o.optional = true;
  278. o.retain = true;
  279. o = s.taboption('general', widgets.NetworkSelect, 'ban_ifv6', _('IPv6 Network Interfaces'), _('Select the logical WAN IPv6 network interface(s).'));
  280. o.depends('ban_autodetect', '0');
  281. o.multiple = true;
  282. o.nocreate = true;
  283. o.optional = true;
  284. o.retain = true;
  285. o = s.taboption('general', form.ListValue, 'ban_fetchcmd', _('Download Utility'), _('Select one of the pre-configured download utilities.'));
  286. o.depends('ban_autodetect', '0');
  287. o.value('uclient-fetch');
  288. o.value('wget');
  289. o.value('curl');
  290. o.value('aria2c');
  291. o.optional = true;
  292. o.retain = true;
  293. o = s.taboption('general', form.Value, 'ban_fetchparm', _('Download Parameters'), _('Override the pre-configured download options for the selected download utility.'))
  294. o.depends('ban_autodetect', '0');
  295. o.optional = true;
  296. o.retain = true;
  297. o = s.taboption('general', widgets.NetworkSelect, 'ban_trigger', _('Reload Trigger Interface'), _('List of available reload trigger interface(s).'));
  298. o.multiple = true;
  299. o.nocreate = true;
  300. o.rmempty = true;
  301. o = s.taboption('general', form.Value, 'ban_triggerdelay', _('Trigger Delay'), _('Additional trigger delay in seconds during interface reload and boot.'));
  302. o.placeholder = '10';
  303. o.datatype = 'range(1,300)';
  304. o.rmempty = true;
  305. o = s.taboption('general', form.ListValue, 'ban_fetchretry', _('Download Retries'), _('Number of download attempts in case of an error (not supported by uclient-fetch).'));
  306. o.value('1');
  307. o.value('3');
  308. o.value('5');
  309. o.value('10');
  310. o.value('20');
  311. o.default = '5';
  312. o.placeholder = _('-- default --');
  313. o.create = true;
  314. o.optional = true;
  315. o.rmempty = true;
  316. o = s.taboption('general', form.Flag, 'ban_fetchinsecure', _('Download Insecure'), _('Don\'t check SSL server certificates during download.'));
  317. o.rmempty = true;
  318. /*
  319. additional settings tab
  320. */
  321. o = s.taboption('advanced', form.DummyValue, '_sub');
  322. o.rawhtml = true;
  323. o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'
  324. + '<hr style="width: 200px; height: 1px;" />';
  325. o = s.taboption('advanced', form.ListValue, 'ban_nicelimit', _('Nice Level'), _('The selected priority will be used for banIP background processing.'));
  326. o.value('-20', _('Highest Priority'));
  327. o.value('-10', _('High Priority'));
  328. o.value('0', _('Normal Priority'));
  329. o.value('10', _('Less Priority'));
  330. o.value('19', _('Least Priority'));
  331. o.default = '0';
  332. o.placeholder = _('-- default --');
  333. o.create = true;
  334. o.optional = true;
  335. o.rmempty = true;
  336. o = s.taboption('advanced', form.ListValue, 'ban_filelimit', _('Max Open Files'), _('Increase the maximal number of open files, e.g. to handle the amount of temporary split files while loading the Sets.'));
  337. o.value('512');
  338. o.value('1024');
  339. o.value('2048');
  340. o.value('4096');
  341. o.default = '1024';
  342. o.placeholder = _('-- default --');
  343. o.create = true;
  344. o.optional = true;
  345. o.rmempty = true;
  346. o = s.taboption('advanced', form.ListValue, 'ban_cores', _('CPU Cores'), _('Limit the cpu cores used by banIP to save RAM.'));
  347. o.value('1');
  348. o.value('2');
  349. o.value('4');
  350. o.value('8');
  351. o.value('16');
  352. o.optional = true;
  353. o.rmempty = true;
  354. o = s.taboption('advanced', form.ListValue, 'ban_splitsize', _('Set Split Size'), _('Split external Set loading after every n members to save RAM.'));
  355. o.value('512');
  356. o.value('1024');
  357. o.value('2048');
  358. o.value('4096');
  359. o.value('8192');
  360. o.value('16384');
  361. o.optional = true;
  362. o.rmempty = true;
  363. o = s.taboption('advanced', form.Value, 'ban_basedir', _('Base Directory'), _('Base working directory while banIP processing.'));
  364. o.placeholder = '/tmp';
  365. o.rmempty = true;
  366. o = s.taboption('advanced', form.Value, 'ban_backupdir', _('Backup Directory'), _('Target directory for compressed feed backups.'));
  367. o.placeholder = '/tmp/banIP-backup';
  368. o.rmempty = true;
  369. o = s.taboption('advanced', form.Value, 'ban_reportdir', _('Report Directory'), _('Target directory for banIP-related report files.'));
  370. o.placeholder = '/tmp/banIP-report';
  371. o.rmempty = true;
  372. o = s.taboption('advanced', form.Flag, 'ban_deduplicate', _('Deduplicate IPs'), _('Deduplicate IP addresses across all active Sets and tidy up the local blocklist.'));
  373. o.default = 1
  374. o.rmempty = false;
  375. o = s.taboption('advanced', form.Flag, 'ban_reportelements', _('Report Elements'), _('List Set elements in the status and report, disable this to reduce the CPU load.'));
  376. o.default = 1
  377. o.optional = true;
  378. /*
  379. advanced chain settings tab
  380. */
  381. o = s.taboption('adv_chain', form.DummyValue, '_sub');
  382. o.rawhtml = true;
  383. o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'
  384. + '<hr style="width: 200px; height: 1px;" />';
  385. o = s.taboption('adv_chain', form.ListValue, 'ban_nftpriority', _('Chain Priority'), _('Set the nft chain priority within the banIP table, lower values means higher priority.'));
  386. o.value('10');
  387. o.value('0');
  388. o.value('-100');
  389. o.value('-150');
  390. o.value('-200');
  391. o.default = '-100';
  392. o.placeholder = _('-- default --');
  393. o.create = true;
  394. o.optional = true;
  395. o.rmempty = true;
  396. o = s.taboption('adv_chain', form.Value, 'ban_allowflag', _('Allow Protocol/Ports'), _('Always allow a protocol \(tcp/udp\) with certain ports or port ranges in WAN-Input and WAN-Forward chain.'));
  397. o.placeholder = 'tcp 80 443-445';
  398. o.rmempty = true;
  399. o = s.taboption('adv_chain', widgets.DeviceSelect, 'ban_vlanallow', _('Allow VLAN Forwards'), _('Always allow certain VLAN forwards.'));
  400. o.multiple = true;
  401. o.nocreate = true;
  402. o.optional = true;
  403. o.rmempty = true;
  404. o = s.taboption('adv_chain', widgets.DeviceSelect, 'ban_vlanblock', _('Block VLAN Forwards'), _('Always block certain VLAN forwards.'));
  405. o.multiple = true;
  406. o.nocreate = true;
  407. o.optional = true;
  408. o.rmempty = true;
  409. o = s.taboption('adv_chain', form.ListValue, 'ban_icmplimit', _('ICMP-Threshold'), _('ICMP-Threshold in packets per second to prevent WAN-DoS attacks. To disable this safeguard set it to \'0\'.'));
  410. o.value('0');
  411. o.value('10');
  412. o.value('50');
  413. o.value('100');
  414. o.value('250');
  415. o.value('500');
  416. o.value('1000');
  417. o.default = '10';
  418. o.placeholder = _('-- default --');
  419. o.create = true;
  420. o.optional = true;
  421. o.rmempty = true;
  422. o = s.taboption('adv_chain', form.ListValue, 'ban_synlimit', _('SYN-Threshold'), _('SYN-Threshold in packets per second to prevent WAN-DoS attacks. To disable this safeguard set it to \'0\'.'));
  423. o.value('0');
  424. o.value('10');
  425. o.value('50');
  426. o.value('100');
  427. o.value('250');
  428. o.value('500');
  429. o.value('1000');
  430. o.default = '10';
  431. o.placeholder = _('-- default --');
  432. o.create = true;
  433. o.optional = true;
  434. o.rmempty = true;
  435. o = s.taboption('adv_chain', form.ListValue, 'ban_udplimit', _('UDP-Threshold'), _('UDP-Threshold in packets per second to prevent WAN-DoS attacks. To disable this safeguard set it to \'0\'.'));
  436. o.value('0');
  437. o.value('100');
  438. o.value('250');
  439. o.value('500');
  440. o.value('1000');
  441. o.value('2500');
  442. o.value('5000');
  443. o.default = '100';
  444. o.placeholder = _('-- default --');
  445. o.create = true;
  446. o.optional = true;
  447. o.rmempty = true;
  448. /*
  449. advanced Set settings tab
  450. */
  451. o = s.taboption('adv_set', form.DummyValue, '_sub');
  452. o.rawhtml = true;
  453. o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'
  454. + '<hr style="width: 200px; height: 1px;" />';
  455. o = s.taboption('adv_set', form.ListValue, 'ban_nftpolicy', _('Set Policy'), _('Set the nft policy for banIP-related Sets.'));
  456. o.value('memory', _('memory'));
  457. o.value('performance', _('performance'));
  458. o.default = 'memory';
  459. o.placeholder = _('-- default --');
  460. o.create = true;
  461. o.optional = true;
  462. o.rmempty = true;
  463. o = s.taboption('adv_set', form.ListValue, 'ban_blocktype', _('Block Type'), _('Drop packets silently or actively reject the traffic on WAN-Input and WAN-Forward chains.'));
  464. o.value('drop', _('drop'));
  465. o.value('reject', _('reject'));
  466. o.default = 'drop';
  467. o.placeholder = _('-- default --');
  468. o.create = true;
  469. o.optional = true;
  470. o.rmempty = true;
  471. o = s.taboption('adv_set', form.ListValue, 'ban_blockpolicy', _('Default Block Policy'), _('By default each feed is active in all supported chains. Limit the default block policy to a certain chain.'));
  472. o.value('input', _('WAN-Input Chain'));
  473. o.value('forwardwan', _('WAN-Forward Chain'));
  474. o.value('forwardlan', _('LAN-Forward Chain'));
  475. o.optional = true;
  476. o.rmempty = true;
  477. let feed, feeds, descr;
  478. if (result && Object.keys(result).length) {
  479. if (result[0]) {
  480. try {
  481. feeds = JSON.parse(result[0]);
  482. } catch (e) {
  483. ui.addNotification(null, E('p', _('Unable to parse the custom feed file!')), 'error');
  484. }
  485. }
  486. if (result[1] && (!feeds || (feeds && !Object.keys(feeds).length))) {
  487. try {
  488. feeds = JSON.parse(result[1]);
  489. } catch (e) {
  490. ui.addNotification(null, E('p', _('Unable to parse the default feed file!')), 'error');
  491. }
  492. }
  493. }
  494. if (feeds && Object.keys(feeds).length) {
  495. o = s.taboption('adv_set', form.MultiValue, 'ban_blockinput', _('WAN-Input Chain'), _('Limit certain feeds to the WAN-Input chain.'));
  496. o.value('allowlist', _('local allowlist'));
  497. o.value('blocklist', _('local blocklist'));
  498. for (let i = 0; i < Object.keys(feeds).length; i++) {
  499. feed = Object.keys(feeds)[i].trim();
  500. o.value(feed);
  501. }
  502. o.optional = true;
  503. o.rmempty = true;
  504. o = s.taboption('adv_set', form.MultiValue, 'ban_blockforwardwan', _('WAN-Forward Chain'), _('Limit certain feeds to the WAN-Forward chain.'));
  505. o.value('allowlist', _('local allowlist'));
  506. o.value('blocklist', _('local blocklist'));
  507. for (let i = 0; i < Object.keys(feeds).length; i++) {
  508. feed = Object.keys(feeds)[i].trim();
  509. o.value(feed);
  510. }
  511. o.optional = true;
  512. o.rmempty = true;
  513. o = s.taboption('adv_set', form.MultiValue, 'ban_blockforwardlan', _('LAN-Forward Chain'), _('Limit certain feeds to the LAN-Forward chain.'));
  514. o.value('allowlist', _('local allowlist'));
  515. o.value('blocklist', _('local blocklist'));
  516. for (let i = 0; i < Object.keys(feeds).length; i++) {
  517. feed = Object.keys(feeds)[i].trim();
  518. o.value(feed);
  519. }
  520. o.optional = true;
  521. o.rmempty = true;
  522. }
  523. /*
  524. advanced log settings tab
  525. */
  526. o = s.taboption('adv_log', form.DummyValue, '_sub');
  527. o.rawhtml = true;
  528. o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'
  529. + '<hr style="width: 200px; height: 1px;" />';
  530. o = s.taboption('adv_log', form.ListValue, 'ban_nftloglevel', _('NFT Log Level'), _('Set the syslog level for NFT logging.'));
  531. o.value('emerg', _('emerg'));
  532. o.value('alert', _('alert'));
  533. o.value('crit', _('crit'));
  534. o.value('err', _('err'));
  535. o.value('warn', _('warn'));
  536. o.value('notice', _('notice'));
  537. o.value('info', _('info'));
  538. o.value('debug', _('debug'));
  539. o.default = 'warn';
  540. o.placeholder = _('-- default --');
  541. o.create = true;
  542. o.optional = true;
  543. o.rmempty = true;
  544. o = s.taboption('adv_log', form.Flag, 'ban_logprerouting', _('Log Prerouting'), _('Log suspicious Prerouting packets.'));
  545. o.rmempty = false;
  546. o = s.taboption('adv_log', form.Flag, 'ban_loginput', _('Log WAN-Input'), _('Log suspicious incoming WAN packets.'));
  547. o.rmempty = false;
  548. o = s.taboption('adv_log', form.Flag, 'ban_logforwardwan', _('Log WAN-Forward'), _('Log suspicious forwarded WAN packets.'));
  549. o.rmempty = false;
  550. o = s.taboption('adv_log', form.Flag, 'ban_logforwardlan', _('Log LAN-Forward'), _('Log suspicious forwarded LAN packets.'));
  551. o.rmempty = false;
  552. o = s.taboption('adv_log', form.Value, 'ban_logreadfile', _('Logfile Location'), _('Location for parsing the log file, e.g. via syslog-ng, to deactivate the standard parsing via logread.'));
  553. o.placeholder = '/var/log/messages';
  554. o.rmempty = true;
  555. o = s.taboption('adv_log', form.ListValue, 'ban_loglimit', _('Log Limit'), _('Parse only the last stated number of log entries for suspicious events. To disable the log monitor at all set it to \'0\'.'));
  556. o.value('0');
  557. o.value('50');
  558. o.value('100');
  559. o.value('250');
  560. o.value('500');
  561. o.value('1000');
  562. o.default = '100';
  563. o.placeholder = _('-- default --');
  564. o.create = true;
  565. o.optional = true;
  566. o.rmempty = true;
  567. o = s.taboption('adv_log', form.Value, 'ban_logcount', _('Log Count'), _('Number of failed login attempts of the same IP in the log before blocking.'));
  568. o.placeholder = '1';
  569. o.datatype = 'range(1,10)';
  570. o.rmempty = true;
  571. o = s.taboption('adv_log', form.DynamicList, 'ban_logterm', _('Log Terms'), _('The default regular expressions are filtering suspicious ssh, LuCI, nginx and asterisk traffic.'));
  572. o.optional = true;
  573. o.rmempty = true;
  574. o = s.taboption('adv_log', form.Flag, 'ban_remotelog', _('Enable Remote Logging'), _('Enable the cgi interface to receive remote logging events.'));
  575. o.default = 0
  576. o.optional = true;
  577. o.rmempty = true;
  578. o = s.taboption('adv_log', form.Value, 'ban_remotetoken', _('Remote Token'), _('Token to communicate with the cgi interface.'));
  579. o.depends('ban_remotelog', '1');
  580. o.datatype = 'and(minlength(3),maxlength(20))';
  581. o.validate = function (section_id, value) {
  582. if (!value) {
  583. return _('Empty field not allowed');
  584. }
  585. if (!value.match(/^[A-Za-z0-9\.\:]+$/)) {
  586. return _('Invalid characters');
  587. }
  588. return true;
  589. }
  590. o.optional = true;
  591. o.rmempty = true;
  592. /*
  593. advanced email settings tab
  594. */
  595. o = s.taboption('adv_email', form.DummyValue, '_sub');
  596. o.rawhtml = true;
  597. o.default = '<em style="color:#37c;font-weight:bold;">' + _('To enable email notifications, set up the \'msmtp\' package and specify a vaild E-Mail receiver address.') + '</em>'
  598. + '<hr style="width: 200px; height: 1px;" />';
  599. o = s.taboption('adv_email', form.Flag, 'ban_mailnotification', _('E-Mail Notification'), _('Receive E-Mail notifications with every banIP run.'));
  600. o.rmempty = true;
  601. o = s.taboption('adv_email', form.Value, 'ban_mailreceiver', _('E-Mail Receiver Address'), _('Receiver address for banIP notification E-Mails, this information is required to enable E-Mail functionality.'));
  602. o.placeholder = 'name@example.com';
  603. o.rmempty = true;
  604. o = s.taboption('adv_email', form.Value, 'ban_mailsender', _('E-Mail Sender Address'), _('Sender address for banIP notification E-Mails.'));
  605. o.placeholder = 'no-reply@banIP';
  606. o.rmempty = true;
  607. o = s.taboption('adv_email', form.Value, 'ban_mailtopic', _('E-Mail Topic'), _('Topic for banIP notification E-Mails.'));
  608. o.placeholder = 'banIP notification';
  609. o.rmempty = true;
  610. o = s.taboption('adv_email', form.Value, 'ban_mailprofile', _('E-Mail Profile'), _('Profile used by \'msmtp\' for banIP notification E-Mails.'));
  611. o.placeholder = 'ban_notify';
  612. o.datatype = 'uciname';
  613. o.rmempty = true;
  614. /*
  615. feeds tab
  616. */
  617. o = s.taboption('feeds', form.DummyValue, '_sub');
  618. o.rawhtml = true;
  619. o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service reload to take effect.') + '</em>'
  620. + '<hr style="width: 200px; height: 1px;" />'
  621. + '<em style="color:#37c;font-weight:bold;">' + _('External Blocklist Feeds') + '</em>';
  622. if (feeds && Object.keys(feeds).length) {
  623. o = s.taboption('feeds', form.MultiValue, 'ban_feed', _('Blocklist Feed'));
  624. for (let i = 0; i < Object.keys(feeds).length; i++) {
  625. feed = Object.keys(feeds)[i].trim();
  626. descr = feeds[feed].descr.trim() || '-';
  627. o.value(feed, feed + ' (' + descr + ')');
  628. }
  629. o.optional = true;
  630. o.rmempty = true;
  631. }
  632. let err, ccode, rir, country, countries = [];
  633. if (result && Object.keys(result[2]).length) {
  634. countries = result[2].trim().split('\n');
  635. if (countries && countries.length) {
  636. o = s.taboption('feeds', form.MultiValue, 'ban_country', _('Countries') + ' (<abbr title="Regional Internet Registries">RIR</abbr>)');
  637. for (let i = 0; i < countries.length; i++) {
  638. try {
  639. ccode = countries[i].match(/^(\w+)\t/)[1].trim();
  640. rir = countries[i].match(/^\w+\t(\w+)\t/)[1].trim();
  641. country = countries[i].match(/^\w+\t\w+\t(.*$)/)[1].trim();
  642. o.value(ccode, country + ' (' + rir + ')');
  643. } catch (e) {
  644. countries[i] = "";
  645. if (!err) {
  646. ui.addNotification(null, E('p', _('Unable to parse the countries file!')), 'error');
  647. }
  648. err = e;
  649. }
  650. }
  651. o.optional = true;
  652. o.rmempty = true;
  653. }
  654. }
  655. o = s.taboption('feeds', form.MultiValue, 'ban_region', _('Regional Internet Registry'));
  656. o.value('AFRINIC', _('AFRINIC - serving Africa and the Indian Ocean region'));
  657. o.value('APNIC', _('APNIC - serving the Asia Pacific region'));
  658. o.value('ARIN', _('ARIN - serving Canada and the United States'));
  659. o.value('LACNIC', _('LACNIC - serving the Latin American and Caribbean region'));
  660. o.value('RIPE', _('RIPE - serving Europe, Middle East and Central Asia'));
  661. o.optional = true;
  662. o.rmempty = true;
  663. o = s.taboption('feeds', form.DynamicList, 'ban_asn', _('ASNs'));
  664. o.datatype = 'uinteger';
  665. o.optional = true;
  666. o.rmempty = true;
  667. o = s.taboption('feeds', form.DummyValue, '_feeds');
  668. o.rawhtml = true;
  669. o.default = '<hr style="width: 200px; height: 1px;" /><em style="color:#37c;font-weight:bold;">' + _('External Allowlist Feeds') + '</em>';
  670. if (countries && countries.length) {
  671. o = s.taboption('feeds', form.DynamicList, 'ban_allowurl', _('Allowlist Feed URLs'));
  672. for (let i = 0; i < countries.length; i++) {
  673. try {
  674. ccode = countries[i].match(/^(\w+)\t/)[1].trim();
  675. rir = countries[i].match(/^\w+\t(\w+)\t/)[1].trim();
  676. country = countries[i].match(/^\w+\t\w+\t(.*$)/)[1].trim();
  677. o.value('https://www.ipdeny.com/ipblocks/data/aggregated/' + ccode + '-aggregated.zone', country + ' IPv4 (' + rir + ')');
  678. o.value('https://www.ipdeny.com/ipv6/ipaddresses/aggregated/' + ccode + '-aggregated.zone', country + ' IPv6 (' + rir + ')');
  679. } catch (e) {
  680. countries[i] = "";
  681. }
  682. }
  683. o.optional = true;
  684. o.rmempty = true;
  685. o.validate = function (section_id, value) {
  686. if (!value) {
  687. return true;
  688. }
  689. if (!value.match(/^(http:\/\/|https:\/\/)[A-Za-z0-9\/\.\-_\?\&\+=:~#]+$/)) {
  690. return _('Protocol/URL format not supported');
  691. }
  692. return true;
  693. }
  694. }
  695. o = s.taboption('feeds', form.DummyValue, '_feeds');
  696. o.rawhtml = true;
  697. o.default = '<hr style="width: 200px; height: 1px;" /><em style="color:#37c;font-weight:bold;">' + _('Local Feed Settings') + '</em>';
  698. o = s.taboption('feeds', form.Flag, 'ban_autoallowlist', _('Auto Allowlist'), _('Automatically add resolved domains and uplink IPs to the local banIP allowlist.'));
  699. o.default = 1
  700. o.rmempty = false;
  701. o = s.taboption('feeds', form.ListValue, 'ban_autoallowuplink', _('Auto Allow Uplink'), _('Limit the uplink autoallow function.'));
  702. o.depends('ban_autoallowlist', '1');
  703. o.value('disable', _('Disable'));
  704. o.value('subnet', _('Subnet'));
  705. o.value('ip', _('IP'));
  706. o.default = 'subnet';
  707. o.placeholder = _('-- default --');
  708. o.create = true;
  709. o.optional = true;
  710. o.rmempty = true;
  711. o = s.taboption('feeds', form.Flag, 'ban_autoblocklist', _('Auto Blocklist'), _('Automatically add resolved domains and suspicious IPs to the local banIP blocklist.'));
  712. o.default = 1
  713. o.rmempty = false;
  714. o = s.taboption('feeds', form.Flag, 'ban_autoblocksubnet', _('Auto Block Subnet'), _('Automatically add entire subnets to the blocklist Set based on an additional RDAP request with the suspicious IP.'));
  715. o.default = 0
  716. o.optional = true;
  717. o.rmempty = true;
  718. o = s.taboption('feeds', form.ListValue, 'ban_nftexpiry', _('Blocklist Set Expiry'), _('Expiry time for auto added blocklist Set members.'));
  719. o.value('10s');
  720. o.value('1m');
  721. o.value('5m');
  722. o.value('1h');
  723. o.value('2h');
  724. o.value('1d');
  725. o.optional = true;
  726. o.rmempty = true;
  727. o = s.taboption('feeds', form.Flag, 'ban_allowlistonly', _('Allowlist Only'), _('Restrict the internet access from/to a small number of secure IPs.'));
  728. o.rmempty = false;
  729. return m.render();
  730. },
  731. handleSaveApply: null,
  732. handleSave: null,
  733. handleReset: null
  734. });