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