172714c2736f23f0fc4d3b64d0d99c3c7de95de3
[openwrt-luci.git] /
1 'use strict';
2 'require view';
3 'require uci';
4 'require fs';
5 'require form';
6 'require tools.widgets as widgets';
7 'require shadowsocks-libev as ss';
8
9 var conf = 'shadowsocks-libev';
10
11 function src_dst_option(s /*, ... */) {
12         var o = s.taboption.apply(s, L.varargs(arguments, 1));
13         o.datatype = 'or(ipaddr,cidr)';
14 }
15
16 return view.extend({
17         load: function() {
18                 return Promise.all([
19                         L.resolveDefault(fs.stat('/usr/share/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');
23                                 }
24                         })
25                 ]);
26         },
27         render: function(stats) {
28                 var m, s, o;
29
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.'));
39
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'));
44
45                 s.taboption('general', form.Flag, 'disabled', _('Disable'));
46                 if (!stats[0]) {
47                         ss.option_install_package(s, 'general');
48                 }
49
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');
56
57                 o = s.taboption('general', form.ListValue, 'local_default',
58                         _('Local-out default'),
59                         _('Default action for locally generated TCP packets'));
60                 ss.values_actions(o);
61                 o = s.taboption('general', widgets.DeviceSelect, 'ifnames',
62                         _('Ingress interfaces'),
63                         _('Only apply rules on packets from these network interfaces'));
64                 o.multiple = true;
65                 o.noaliases = true;
66                 o.noinactive = true;
67
68                 src_dst_option(s, 'src', form.DynamicList, 'src_ips_bypass',
69                         _('Src ip/net bypass'),
70                         _('Bypass ss-redir for packets with src address in this list'));
71                 src_dst_option(s, 'src', form.DynamicList, 'src_ips_forward',
72                         _('Src ip/net forward'),
73                         _('Forward through ss-redir for packets with src address in this list'));
74                 src_dst_option(s, 'src', form.DynamicList, 'src_ips_checkdst',
75                         _('Src ip/net checkdst'),
76                         _('Continue to have dst address checked for packets with src address in this list'));
77                 o = s.taboption('src', form.ListValue, 'src_default',
78                         _('Src default'),
79                         _('Default action for packets whose src address do not match any of the src ip/net list'));
80                 ss.values_actions(o);
81
82                 src_dst_option(s, 'dst', form.DynamicList, 'dst_ips_bypass',
83                         _('Dst ip/net bypass'),
84                         _('Bypass ss-redir for packets with dst address in this list'));
85                 src_dst_option(s, 'dst', form.DynamicList, 'dst_ips_forward',
86                         _('Dst ip/net forward'),
87                         _('Forward through ss-redir for packets with dst address in this list'));
88
89                 var dir = '/etc/shadowsocks-libev';
90                 o = s.taboption('dst', form.FileUpload, 'dst_ips_bypass_file',
91                         _('Dst ip/net bypass file'),
92                         _('File containing ip/net for the purposes as with <em>Dst ip/net bypass</em>'));
93                 o.root_directory = dir;
94                 o = s.taboption('dst', form.FileUpload, 'dst_ips_forward_file',
95                         _('Dst ip/net forward file'),
96                         _('File containing ip/net for the purposes as with <em>Dst ip/net forward</em>'));
97                 o.root_directory = dir;
98                 o = s.taboption('dst', form.ListValue, 'dst_default',
99                         _('Dst default'),
100                         _('Default action for packets whose dst address do not match any of the dst ip list'));
101                 ss.values_actions(o);
102
103                 return m.render();
104         },
105 });
git clone https://git.99rst.org/PROJECT