summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-shadowsocks-libev/luasrc/model
diff options
context:
space:
mode:
Diffstat (limited to 'applications/luci-app-shadowsocks-libev/luasrc/model')
-rw-r--r--applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/rules.lua93
-rw-r--r--applications/luci-app-shadowsocks-libev/luasrc/model/shadowsocks-libev.lua27
2 files changed, 79 insertions, 41 deletions
diff --git a/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/rules.lua b/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/rules.lua
index 5df59cb0ad..4a01bed247 100644
--- a/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/rules.lua
+++ b/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/rules.lua
@@ -9,23 +9,28 @@ m = Map("shadowsocks-libev",
translate("Redir Rules"),
translate("On this page you can configure how traffics are to be \
forwarded to ss-redir instances. \
- If enabled, packets will first have their source ip addresses checked \
- against <em>Src ip bypass</em>, <em>Src ip forward</em>, \
- <em>Src ip checkdst</em> and if none matches <em>Src default</em> \
+ If enabled, packets will first have their src ip addresses checked \
+ against <em>Src ip/net bypass</em>, <em>Src ip/net forward</em>, \
+ <em>Src ip/net checkdst</em> and if none matches <em>Src default</em> \
will give the default action to be taken. \
If the prior check results in action <em>checkdst</em>, packets will continue \
- to have their destination addresses checked."))
+ to have their dst addresses checked."))
local sdata = m:get('ss_rules')
if not sdata then
m:set('ss_rules', nil, 'ss_rules')
- m:set('ss_rules', 'ss_rules', 'disabled', true)
+ m:set('ss_rules', 'disabled', "1")
+end
+
+function src_dst_option(s, ...)
+ local o = s:taboption(...)
+ o.datatype = "or(ip4addr,cidr4)"
end
s = m:section(NamedSection, "ss_rules", "ss_rules")
s:tab("general", translate("General Settings"))
-s:tab("srcip", translate("Source Settings"))
-s:tab("dstip", translate("Destination Settings"))
+s:tab("src", translate("Source Settings"))
+s:tab("dst", translate("Destination Settings"))
s:taboption('general', Flag, "disabled", translate("Disable"))
ss.option_install_package(s, 'general')
@@ -39,40 +44,66 @@ ss.values_redir(o, 'udp')
o = s:taboption('general', ListValue, "local_default",
translate("Local-out default"),
- translate("Default action for locally generated packets"))
+ translate("Default action for locally generated TCP packets"))
ss.values_actions(o)
+o = s:taboption('general', DynamicList, "ifnames",
+ translate("Ingress interfaces"),
+ translate("Only apply rules on packets from these network interfaces"))
+ss.values_ifnames(o)
s:taboption('general', Value, "ipt_args",
translate("Extra arguments"),
translate("Passes additional arguments to iptables. Use with care!"))
-s:taboption('srcip', DynamicList, "src_ips_bypass",
- translate("Src ip bypass"),
- translate("Bypass redir action for packets with source addresses in this list"))
-s:taboption('srcip', DynamicList, "src_ips_forward",
- translate("Src ip forward"),
- translate("Go through redir action for packets with source addresses in this list"))
-s:taboption('srcip', DynamicList, "src_ips_checkdst",
- translate("Src ip checkdst"),
- translate("Continue to have dst address checked for packets with source addresses in this list"))
-o = s:taboption('srcip', ListValue, "src_default",
+src_dst_option(s, 'src', DynamicList, "src_ips_bypass",
+ translate("Src ip/net bypass"),
+ translate("Bypass ss-redir for packets with src address in this list"))
+src_dst_option(s, 'src', DynamicList, "src_ips_forward",
+ translate("Src ip/net forward"),
+ translate("Forward through ss-redir for packets with src address in this list"))
+src_dst_option(s, 'src', DynamicList, "src_ips_checkdst",
+ translate("Src ip/net checkdst"),
+ translate("Continue to have dst address checked for packets with src address in this list"))
+o = s:taboption('src', ListValue, "src_default",
translate("Src default"),
- translate("Default action for packets whose source addresses do not match any of the source ip list"))
+ translate("Default action for packets whose src address do not match any of the src ip/net list"))
ss.values_actions(o)
-s:taboption('dstip', DynamicList, "dst_ips_bypass",
- translate("Dst ip bypass"),
- translate("Bypass redir action for packets with destination addresses in this list"))
-s:taboption('dstip', DynamicList, "dst_ips_forward",
- translate("Dst ip forward"),
- translate("Go through redir action for packets with destination addresses in this list"))
+src_dst_option(s, 'dst', DynamicList, "dst_ips_bypass",
+ translate("Dst ip/net bypass"),
+ translate("Bypass ss-redir for packets with dst address in this list"))
+src_dst_option(s, 'dst', DynamicList, "dst_ips_forward",
+ translate("Dst ip/net forward"),
+ translate("Forward through ss-redir for packets with dst address in this list"))
-o = s:taboption('dstip', FileBrowser, "dst_ips_bypass_file",
- translate("Dst ip bypass file"),
- translate("File containing ip addresses for the purposes as with <em>Dst ip bypass</em>"))
+o = s:taboption('dst', FileBrowser, "dst_ips_bypass_file",
+ translate("Dst ip/net bypass file"),
+ translate("File containing ip/net for the purposes as with <em>Dst ip/net bypass</em>"))
o.datatype = "file"
-s:taboption('dstip', FileBrowser, "dst_ips_forward_file",
- translate("Dst ip forward file"),
- translate("File containing ip addresses for the purposes as with <em>Dst ip forward</em>"))
+s:taboption('dst', FileBrowser, "dst_ips_forward_file",
+ translate("Dst ip/net forward file"),
+ translate("File containing ip/net for the purposes as with <em>Dst ip/net forward</em>"))
o.datatype = "file"
+o = s:taboption('dst', ListValue, "dst_default",
+ translate("Dst default"),
+ translate("Default action for packets whose dst address do not match any of the dst ip list"))
+ss.values_actions(o)
+
+local installed = os.execute("iptables -m recent -h &>/dev/null") == 0
+if installed then
+ o = s:taboption('dst', Flag, "dst_forward_recentrst")
+else
+ m:set('ss_rules', 'dst_forward_recentrst', "0")
+ o = s:taboption("dst", Button, "_install")
+ o.inputtitle = translate("Install package iptables-mod-conntrack-extra")
+ o.inputstyle = "apply"
+ o.write = function()
+ return luci.http.redirect(
+ luci.dispatcher.build_url("admin/system/packages") ..
+ "?submit=1&install=iptables-mod-conntrack-extra"
+ )
+ end
+end
+o.title = translate("Forward recentrst")
+o.description = translate("Forward those packets whose dst have recently sent to us multiple tcp-rst")
return m
diff --git a/applications/luci-app-shadowsocks-libev/luasrc/model/shadowsocks-libev.lua b/applications/luci-app-shadowsocks-libev/luasrc/model/shadowsocks-libev.lua
index 6608ee8d35..7ba6b40c53 100644
--- a/applications/luci-app-shadowsocks-libev/luasrc/model/shadowsocks-libev.lua
+++ b/applications/luci-app-shadowsocks-libev/luasrc/model/shadowsocks-libev.lua
@@ -3,6 +3,7 @@
local _up = getfenv(3)
local ut = require("luci.util")
+local sys = require("luci.sys")
local ds = require("luci.dispatcher")
local nw = require("luci.model.network")
nw.init()
@@ -14,20 +15,25 @@ module("luci.model.shadowsocks-libev", function(m)
end)
function values_actions(o)
- for _, a in ipairs(actions) do
- o:value(a)
+ o:value("bypass")
+ o:value("forward")
+ if o.option ~= "dst_default" then
+ o:value("checkdst")
end
end
function values_redir(o, xmode)
o.map.uci.foreach("shadowsocks-libev", "ss_redir", function(sdata)
+ local disabled = ucival_to_bool(sdata["disabled"])
local sname = sdata[".name"]
local mode = sdata["mode"] or "tcp_only"
- if mode and mode:find(xmode) then
+ if not disabled and mode:find(xmode) then
local desc = "%s - %s" % {sname, mode}
o:value(sname, desc)
end
end)
+ o:value("", "<unset>")
+ o.default = ""
end
function values_serverlist(o)
@@ -43,7 +49,6 @@ function values_serverlist(o)
end
function values_ipaddr(o)
- local keys, vals = {}, {}
for _, v in ipairs(nw:get_interfaces()) do
for _, a in ipairs(v:ipaddrs()) do
o:value(a:host():string(), '%s (%s)' %{ a:host(), v:shortname() })
@@ -51,6 +56,12 @@ function values_ipaddr(o)
end
end
+function values_ifnames(o)
+ for _, v in ipairs(sys.net.devices()) do
+ o:value(v)
+ end
+end
+
function options_client(s, tab)
local o
@@ -226,17 +237,13 @@ modes = {
"udp_only",
}
-actions = {
- "bypass",
- "forward",
- "checkdst",
-}
-
methods = {
-- aead
"aes-128-gcm",
"aes-192-gcm",
"aes-256-gcm",
+ "chacha20-ietf-poly1305",
+ "xchacha20-ietf-poly1305",
-- stream
"table",
"rc4",