2
0

rules.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. 'use strict';
  2. 'require uci';
  3. 'require fs';
  4. 'require form';
  5. 'require tools.widgets as widgets';
  6. 'require shadowsocks-libev as ss';
  7. var conf = 'shadowsocks-libev';
  8. function src_dst_option(s /*, ... */) {
  9. var o = s.taboption.apply(s, L.varargs(arguments, 1));
  10. o.datatype = 'or(ipaddr,cidr)';
  11. }
  12. return L.view.extend({
  13. load: function() {
  14. return Promise.all([
  15. L.resolveDefault(fs.stat('/usr/lib/iptables/libxt_recent.so'), {}),
  16. L.resolveDefault(fs.stat('/usr/bin/ss-rules'), null),
  17. uci.load(conf).then(function() {
  18. if (!uci.get_first(conf, 'ss_rules')) {
  19. uci.set(conf, uci.add(conf, 'ss_rules', 'ss_rules'), 'disabled', '1');
  20. }
  21. })
  22. ]);
  23. },
  24. render: function(stats) {
  25. var m, s, o;
  26. m = new form.Map(conf, _('Redir Rules'),
  27. _('On this page you can configure how traffics are to be \
  28. forwarded to ss-redir instances. \
  29. If enabled, packets will first have their src ip addresses checked \
  30. against <em>Src ip/net bypass</em>, <em>Src ip/net forward</em>, \
  31. <em>Src ip/net checkdst</em> and if none matches <em>Src default</em> \
  32. will give the default action to be taken. \
  33. If the prior check results in action <em>checkdst</em>, packets will continue \
  34. to have their dst addresses checked.'));
  35. s = m.section(form.NamedSection, 'ss_rules', 'ss_rules');
  36. s.tab('general', _('General Settings'));
  37. s.tab('src', _('Source Settings'));
  38. s.tab('dst', _('Destination Settings'));
  39. s.taboption('general', form.Flag, 'disabled', _('Disable'));
  40. if (!stats[1]) {
  41. ss.option_install_package(s, 'general');
  42. }
  43. o = s.taboption('general', form.ListValue, 'redir_tcp',
  44. _('ss-redir for TCP'));
  45. ss.values_redir(o, 'tcp');
  46. o = s.taboption('general', form.ListValue, 'redir_udp',
  47. _('ss-redir for UDP'));
  48. ss.values_redir(o, 'udp');
  49. o = s.taboption('general', form.ListValue, 'local_default',
  50. _('Local-out default'),
  51. _('Default action for locally generated TCP packets'));
  52. ss.values_actions(o);
  53. o = s.taboption('general', widgets.DeviceSelect, 'ifnames',
  54. _('Ingress interfaces'),
  55. _('Only apply rules on packets from these network interfaces'));
  56. o.multiple = true;
  57. o.noaliases = true;
  58. o.noinactive = true;
  59. s.taboption('general', form.Value, 'ipt_args',
  60. _('Extra arguments'),
  61. _('Passes additional arguments to iptables. Use with care!'));
  62. src_dst_option(s, 'src', form.DynamicList, 'src_ips_bypass',
  63. _('Src ip/net bypass'),
  64. _('Bypass ss-redir for packets with src address in this list'));
  65. src_dst_option(s, 'src', form.DynamicList, 'src_ips_forward',
  66. _('Src ip/net forward'),
  67. _('Forward through ss-redir for packets with src address in this list'));
  68. src_dst_option(s, 'src', form.DynamicList, 'src_ips_checkdst',
  69. _('Src ip/net checkdst'),
  70. _('Continue to have dst address checked for packets with src address in this list'));
  71. o = s.taboption('src', form.ListValue, 'src_default',
  72. _('Src default'),
  73. _('Default action for packets whose src address do not match any of the src ip/net list'));
  74. ss.values_actions(o);
  75. src_dst_option(s, 'dst', form.DynamicList, 'dst_ips_bypass',
  76. _('Dst ip/net bypass'),
  77. _('Bypass ss-redir for packets with dst address in this list'));
  78. src_dst_option(s, 'dst', form.DynamicList, 'dst_ips_forward',
  79. _('Dst ip/net forward'),
  80. _('Forward through ss-redir for packets with dst address in this list'));
  81. var dir = '/etc/shadowsocks-libev';
  82. o = s.taboption('dst', form.FileUpload, 'dst_ips_bypass_file',
  83. _('Dst ip/net bypass file'),
  84. _('File containing ip/net for the purposes as with <em>Dst ip/net bypass</em>'));
  85. o.root_directory = dir;
  86. o = s.taboption('dst', form.FileUpload, 'dst_ips_forward_file',
  87. _('Dst ip/net forward file'),
  88. _('File containing ip/net for the purposes as with <em>Dst ip/net forward</em>'));
  89. o.root_directory = dir;
  90. o = s.taboption('dst', form.ListValue, 'dst_default',
  91. _('Dst default'),
  92. _('Default action for packets whose dst address do not match any of the dst ip list'));
  93. ss.values_actions(o);
  94. if (stats[0].type === 'file') {
  95. o = s.taboption('dst', form.Flag, 'dst_forward_recentrst');
  96. } else {
  97. uci.set(conf, 'ss_rules', 'dst_forward_recentrst', '0');
  98. o = s.taboption('dst', form.Button, '_install');
  99. o.inputtitle = _('Install package iptables-mod-conntrack-extra');
  100. o.inputstyle = 'apply';
  101. o.onclick = function() {
  102. window.open(L.url('admin/system/opkg') +
  103. '?query=iptables-mod-conntrack-extra', '_blank', 'noopener');
  104. }
  105. }
  106. o.title = _('Forward recentrst');
  107. o.description = _('Forward those packets whose dst have recently sent to us multiple tcp-rst');
  108. return m.render();
  109. },
  110. });