1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Update shadowsocks luci interface

This commit is contained in:
Ycarus (Yannick Chabanois) 2019-06-17 18:30:39 +02:00
parent 69275038c5
commit 95288f3b1d
14 changed files with 982 additions and 676 deletions

View file

@ -22,18 +22,12 @@ m.title = "shadowsocks-libev - %s - %s" % {stype, sname}
s = m:section(NamedSection, sname, stype)
s:tab("general", translate("General Settings"))
s:tab("advanced", translate("Advanced Settings"))
s:tab("obfuscate", translate("Obfuscating"))
s:taboption("general", Flag, "disabled", translate("Disable"))
ss.option_install_package(s, "general")
ss.options_common(s, "advanced")
local obfs_installed = nixio.fs.access("/usr/bin/obfs-local")
local v2ray_installed = nixio.fs.access("/usr/bin/v2ray-plugin")
if obfs_installed or v2ray_installed then
ss.options_obfs(s, "obfuscate")
end
if stype == "ss_server" then
ss.options_server(s, "general")
ss.options_server(s, {tab="general"})
o = s:taboption("general", Value, "bind_address",
translate("Bind address"),
translate("The address ss-server will initiate connection from"))
@ -48,13 +42,6 @@ else
translate("The address ss-tunnel will forward traffic to"))
o.datatype = "hostport"
end
if obfs_installed or v2ray_installed then
o = s:taboption("obfuscate", Value, "obfs_host", translate("Host"))
o.default = "www.bing.com"
end
if obfs_installed then
s:taboption("obfuscate", Value, "obfs_uri", translate("HTTP path uri"))
end
end
return m

View file

@ -24,8 +24,7 @@ end
function src_dst_option(s, ...)
local o = s:taboption(...)
--o.datatype = "or(ip4addr,cidr4)"
o.datatype = "or(ip4addr,ip6addr)"
o.datatype = "or(ipaddr,cidr)"
end
s = m:section(NamedSection, "ss_rules", "ss_rules")
@ -99,8 +98,8 @@ else
o.inputstyle = "apply"
o.write = function()
return luci.http.redirect(
luci.dispatcher.build_url("admin/system/packages") ..
"?submit=1&install=iptables-mod-conntrack-extra"
luci.dispatcher.build_url("admin/system/opkg") ..
"?query=iptables-mod-conntrack-extra"
)
end
end

View file

@ -9,7 +9,7 @@ local m, s
m = Map("shadowsocks-libev",
translate("Remote Servers"),
translate("Definition of remote shadowsocks servers. \
Disable any of them will also disable instances refering to it."))
Disable any of them will also disable instances referring to it."))
local sname = arg[1]
if sname then
@ -19,13 +19,18 @@ if sname then
end
s = m:section(NamedSection, sname, "server")
m.title = m.title .. ' - ' .. sname
opts = {}
else
s = m:section(TypedSection, "server")
s.template = 'cbi/tblsection'
s.addremove = true
s.extedit = function(self, section)
return 'servers/' .. section
end
opts = {row=true}
end
s:option(Flag, "disabled", translate("Disable"))
ss.options_server(s)
ss.options_server(s, opts)
return m

View file

@ -1,4 +1,3 @@
-- Copyright 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
-- Copyright 2017 Yousong Zhou <yszhou4tech@gmail.com>
-- Licensed to the public under the Apache License 2.0.
@ -7,7 +6,6 @@ local ut = require("luci.util")
local sys = require("luci.sys")
local ds = require("luci.dispatcher")
local nw = require("luci.model.network")
local ucic = luci.model.uci.cursor()
nw.init()
module("luci.model.shadowsocks-libev", function(m)
setmetatable(m, {__index=function (self, k)
@ -25,7 +23,7 @@ function values_actions(o)
end
function values_redir(o, xmode)
ucic:foreach("shadowsocks-libev", "ss_redir", function(sdata)
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"
@ -39,7 +37,7 @@ function values_redir(o, xmode)
end
function values_serverlist(o)
ucic:foreach("shadowsocks-libev", "server", function(sdata)
o.map.uci:foreach("shadowsocks-libev", "server", function(sdata)
local sname = sdata[".name"]
local server = sdata["server"]
local server_port = sdata["server_port"]
@ -78,9 +76,13 @@ function options_client(s, tab)
o.datatype = "port"
end
function options_server(s, tab)
function options_server(s, opts)
local o
local optfunc
local tab = opts and opts.tab or nil
local row = opts and opts.row or false
local v2ray_installed = nixio.fs.access("/usr/bin/v2ray-plugin")
local obfs_installed = nixio.fs.access("/usr/bin/obfs-local")
if tab == nil then
optfunc = function(...) return s:option(...) end
@ -98,12 +100,39 @@ function options_server(s, tab)
for _, m in ipairs(methods) do
o:value(m)
end
o = optfunc(Value, "key", translate("Key (base64 encoding)"))
o.datatype = "base64"
o.password = true
o = optfunc(Value, "password", translate("Password"))
o.password = true
o.size = 12
if not row then
o = optfunc(Value, "key", translate("Key (base64)"))
o.datatype = "base64"
o.password = true
o.size = 12
--optfunc(Value, "plugin", translate("Plugin"))
--optfunc(Value, "plugin_opts", translate("Plugin Options"))
optfunc(Flag, "obfs", translate("Enable obfuscation"))
o = optfunc(ListValue, "obfs_plugin", translate("OBFS Plugin"))
if v2ray_installed then
o:value("v2ray")
o.default = "v2ray"
else
o.default = "obfs-simple"
end
if obfs_installed then
o:value("obfs-simple")
end
if v2ray_installed or obfs_installed then
o = optfunc(ListValue, "obfs_type", translate("OBFS Type"))
o:value("http")
o:value("tls")
o.default = "http"
o = optfunc(Value, "obfs_host", translate("OBFS Host"))
o.default = "www.bing.com"
end
if obfs_installed then
o = optfunc(Value, "obfs_uri", translate("OBFS HTTP path uri"))
end
end
end
function options_common(s, tab)
@ -121,33 +150,11 @@ function options_common(s, tab)
s:taboption(tab, Value, "user", translate("Run as"))
s:taboption(tab, Flag, "verbose", translate("Verbose"))
s:taboption(tab, Flag, "mptcp", translate("Enable MPTCP"))
s:taboption(tab, Flag, "ipv6_first", translate("IPv6 First"), translate("Prefer IPv6 addresses when resolving names"))
s:taboption(tab, Flag, "fast_open", translate("Enable TCP Fast Open"))
s:taboption(tab, Flag, "reuse_port", translate("Enable SO_REUSEPORT"))
s:taboption(tab, Flag, "no_delay", translate("Enable TCP_NODELAY"))
s:taboption(tab, Flag, "mptcp", translate("Enable MPTCP"))
--s:taboption(tab, Flag, "ebpf", translate("Enable eBPF"))
end
function options_obfs(s, tab)
local o
local v2ray_installed = nixio.fs.access("/usr/bin/v2ray-plugin")
local obfs_installed = nixio.fs.access("/usr/bin/obfs-local")
s:taboption(tab, Flag, "obfs", translate("Enable"))
o = s:taboption(tab, ListValue, "obfs_plugin", translate("Plugin"))
if v2ray_installed then
o:value("v2ray")
o.default = "v2ray"
else
o.default = "obfs-simple"
end
if obfs_installed then
o:value("obfs-simple")
end
o = s:taboption(tab, ListValue, "obfs_type", translate("Type"))
o:value("http")
o:value("tls")
o.default = "http"
s:taboption(tab, Flag, "reuse_port", translate("Enable SO_REUSEPORT"))
end
function ucival_to_bool(val)
@ -164,20 +171,12 @@ function cfgvalue_overview(sdata)
cfgvalue_overview_(sdata, lines, {
"bind_address",
})
local installed = nixio.fs.access("/usr/bin/obfs-server")
if installed then
cfgvalue_overview_(sdata, lines, names_options_obfs)
end
elseif stype == "ss_local" or stype == "ss_redir" or stype == "ss_tunnel" then
cfgvalue_overview_(sdata, lines, names_options_client)
if stype == "ss_tunnel" then
cfgvalue_overview_(sdata, lines, {"tunnel_address"})
end
cfgvalue_overview_(sdata, lines, names_options_common)
local installed = nixio.fs.access("/usr/bin/obfs-local")
if installed then
cfgvalue_overview_(sdata, lines, names_options_obfs)
end
else
return nil, nil
end
@ -186,7 +185,7 @@ function cfgvalue_overview(sdata)
local value = {
[".name"] = sname,
name = '%s.<var>%s</var>' % {stype, sname},
overview = table.concat(lines, "</br>"),
overview = table.concat(lines, "<br />"),
disabled = ucival_to_bool(sdata["disabled"]),
}
return key, value
@ -231,8 +230,8 @@ function option_install_package(s, tab)
function p_install.write()
return luci.http.redirect(
luci.dispatcher.build_url("admin/system/packages") ..
"?submit=1&install=%s" % opkg_package
luci.dispatcher.build_url("admin/system/opkg") ..
"?query=%s" % opkg_package
)
end
end
@ -243,6 +242,8 @@ names_options_server = {
"method",
"key",
"password",
"plugin",
"plugin_opts",
}
names_options_client = {
@ -261,11 +262,6 @@ names_options_common = {
"mtu",
"timeout",
"user",
"mptcp",
}
names_options_obfs = {
"obfs",
}
modes = {