luci-app-shadowsocks-libev: add a ss_rules section if none exists
[project/luci.git] / applications / luci-app-shadowsocks-libev / luasrc / model / cbi / shadowsocks-libev / rules.lua
1 -- Copyright 2017 Yousong Zhou <yszhou4tech@gmail.com>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local ss = require("luci.model.shadowsocks-libev")
5
6 local m, s, o
7
8 m = Map("shadowsocks-libev",
9         translate("Redir Rules"),
10         translate("On this page you can configure how traffics are to be \
11                 forwarded to ss-redir instances. \
12                 If enabled, packets will first have their source ip addresses checked \
13                 against <em>Src ip bypass</em>, <em>Src ip forward</em>, \
14                 <em>Src ip checkdst</em> and if none matches <em>Src default</em> \
15                 will give the default action to be taken. \
16                 If the prior check results in action <em>checkdst</em>, packets will continue \
17                 to have their destination addresses checked."))
18
19 local sdata = m:get('ss_rules')
20 if not sdata then
21         m:set('ss_rules', nil, 'ss_rules')
22         m:set('ss_rules', 'ss_rules', 'disabled', true)
23 end
24
25 s = m:section(NamedSection, "ss_rules", "ss_rules")
26 s:tab("general", translate("General Settings"))
27 s:tab("srcip", translate("Source Settings"))
28 s:tab("dstip", translate("Destination Settings"))
29
30 s:taboption('general', Flag, "disabled", translate("Disable"))
31 ss.option_install_package(s, 'general')
32
33 o = s:taboption('general', ListValue, "redir_tcp",
34         translate("ss-redir for TCP"))
35 ss.values_redir(o, 'tcp')
36 o = s:taboption('general', ListValue, "redir_udp",
37         translate("ss-redir for UDP"))
38 ss.values_redir(o, 'udp')
39
40 o = s:taboption('general', ListValue, "local_default",
41         translate("Local-out default"),
42         translate("Default action for locally generated packets"))
43 ss.values_actions(o)
44 s:taboption('general', Value, "ipt_args",
45         translate("Extra arguments"),
46         translate("Passes additional arguments to iptables. Use with care!"))
47
48 s:taboption('srcip', DynamicList, "src_ips_bypass",
49         translate("Src ip bypass"),
50         translate("Bypass redir action for packets with source addresses in this list"))
51 s:taboption('srcip', DynamicList, "src_ips_forward",
52         translate("Src ip forward"),
53         translate("Go through redir action for packets with source addresses in this list"))
54 s:taboption('srcip', DynamicList, "src_ips_checkdst",
55         translate("Src ip checkdst"),
56         translate("Continue to have dst address checked for packets with source addresses in this list"))
57 o = s:taboption('srcip', ListValue, "src_default",
58         translate("Src default"),
59         translate("Default action for packets whose source addresses do not match any of the source ip list"))
60 ss.values_actions(o)
61
62 s:taboption('dstip', DynamicList, "dst_ips_bypass",
63         translate("Dst ip bypass"),
64         translate("Bypass redir action for packets with destination addresses in this list"))
65 s:taboption('dstip', DynamicList, "dst_ips_forward",
66         translate("Dst ip forward"),
67         translate("Go through redir action for packets with destination addresses in this list"))
68
69 o = s:taboption('dstip', FileBrowser, "dst_ips_bypass_file",
70         translate("Dst ip bypass file"),
71         translate("File containing ip addresses for the purposes as with <em>Dst ip bypass</em>"))
72 o.datatype = "file"
73 s:taboption('dstip', FileBrowser, "dst_ips_forward_file",
74         translate("Dst ip forward file"),
75         translate("File containing ip addresses for the purposes as with <em>Dst ip forward</em>"))
76 o.datatype = "file"
77
78 return m