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

v2ray plugin support

This commit is contained in:
Ycarus 2019-01-26 13:51:53 +01:00
parent df7a7ffd2b
commit 58b4ff3198
8 changed files with 186 additions and 40 deletions

View file

@ -510,10 +510,13 @@ function settings_add()
-- Enable/disable obfs -- Enable/disable obfs
local obfs = luci.http.formvalue("obfs") or 0 local obfs = luci.http.formvalue("obfs") or 0
local obfs_plugin = luci.http.formvalue("obfs_plugin") or "v2ray"
ucic:foreach("shadowsocks-libev", "ss_redir", function (section) ucic:foreach("shadowsocks-libev", "ss_redir", function (section)
ucic:set("shadowsocks-libev",section[".name"],"obfs",obfs) ucic:set("shadowsocks-libev",section[".name"],"obfs",obfs)
ucic:set("shadowsocks-libev",section[".name"],"obfs_plugin",obfs_plugin)
end) end)
ucic:set("shadowsocks-libev","tracker","obfs",obfs) ucic:set("shadowsocks-libev","tracker","obfs",obfs)
ucic:set("shadowsocks-libev","tracker","obfs_plugin",obfs_plugin)
ucic:save("shadowsocks-libev") ucic:save("shadowsocks-libev")
ucic:commit("shadowsocks-libev") ucic:commit("shadowsocks-libev")

View file

@ -58,12 +58,19 @@
end) end)
%> %>
<div class="cbi-value"> <div class="cbi-value">
<label class="cbi-value-title"><%:Enable ShadowSocks OBFS%></label> <label class="cbi-value-title"><%:Enable ShadowSocks Obfuscating%></label>
<div class="cbi-value-field"> <div class="cbi-value-field">
<input type="checkbox" name="obfs" class="cbi-input-checkbox" value="1" <% if luci.model.uci.cursor():get("shadowsocks-libev","tracker","obfs") == "1" then %>checked<% end %>> <input type="checkbox" name="obfs" class="cbi-input-checkbox" value="1" <% if luci.model.uci.cursor():get("shadowsocks-libev","tracker","obfs") == "1" then %>checked<% end %>>
<br /> <br />
<div class="cbi-value-description"> <div class="cbi-value-description">
<%:OBFS will be enabled on both side%> <%:Obfuscating will be enabled on both side%>
</div>
</div>
<div class="cbi-value-field">
<select class="cbi-input-select" name="obfs_plugin">
<option value="v2ray" <% if luci.model.uci.cursor():get("shadowsocks-libev","tracker","obfs_plugin") == "v2ray" then %>selected="selected"<% end %>>v2ray</option>
<option value="obfs" <% if luci.model.uci.cursor():get("shadowsocks-libev","tracker","obfs_plugin") == "obfs" then %>selected="selected"<% end %>>simple-obfs</option>
</select>
</div> </div>
</div> </div>
</div> </div>

View file

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI Support for shadowsocks-libev LUCI_TITLE:=LuCI Support for shadowsocks-libev
LUCI_DEPENDS:=+shadowsocks-libev-config +shadowsocks-libev-ss-local +shadowsocks-libev-ss-redir +shadowsocks-libev-ss-rules +shadowsocks-libev-ss-server +shadowsocks-libev-ss-tunnel +simple-obfs LUCI_DEPENDS:=+shadowsocks-libev-config +shadowsocks-libev-ss-local +shadowsocks-libev-ss-redir +shadowsocks-libev-ss-rules +shadowsocks-libev-ss-server +shadowsocks-libev-ss-tunnel +simple-obfs +v2ray-plugin
PKG_LICENSE:=Apache-2.0 PKG_LICENSE:=Apache-2.0

View file

@ -27,7 +27,8 @@ s:taboption("general", Flag, "disabled", translate("Disable"))
ss.option_install_package(s, "general") ss.option_install_package(s, "general")
ss.options_common(s, "advanced") ss.options_common(s, "advanced")
local obfs_installed = nixio.fs.access("/usr/bin/obfs-local") local obfs_installed = nixio.fs.access("/usr/bin/obfs-local")
if obfs_installed then local v2ray_installed = nixio.fs.access("/usr/bin/v2ray-plugin")
if obfs_installed or v2ray_installed then
ss.options_obfs(s, "obfuscate") ss.options_obfs(s, "obfuscate")
end end
@ -47,9 +48,11 @@ else
translate("The address ss-tunnel will forward traffic to")) translate("The address ss-tunnel will forward traffic to"))
o.datatype = "hostport" o.datatype = "hostport"
end end
if obfs_installed then if obfs_installed or v2ray_installed then
o = s:taboption("obfuscate", Value, "obfs_host", translate("Host")) o = s:taboption("obfuscate", Value, "obfs_host", translate("Host"))
o.default = "www.bing.com" o.default = "www.bing.com"
end
if obfs_installed then
s:taboption("obfuscate", Value, "obfs_uri", translate("HTTP path uri")) s:taboption("obfuscate", Value, "obfs_uri", translate("HTTP path uri"))
end end
end end

View file

@ -131,10 +131,22 @@ end
function options_obfs(s, tab) function options_obfs(s, tab)
local o 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")) 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 = s:taboption(tab, ListValue, "obfs_type", translate("Type"))
o:value("http") o:value("http")
o:value("tls") --o:value("tls")
o.default = "http" o.default = "http"
end end

View file

@ -103,6 +103,8 @@ _get_ss_redir() {
[ "$cf_no_delay" = "1" ] && no_delay="true" [ "$cf_no_delay" = "1" ] && no_delay="true"
config_get cf_obfs $1 obfs config_get cf_obfs $1 obfs
[ "$cf_obfs" = "1" ] && obfs="true" [ "$cf_obfs" = "1" ] && obfs="true"
config_get cf_obfs_plugin $1 obfs_plugin
config_get cf_obfs_type $1 obfs_type
} }
_set_ss_server_vps() { _set_ss_server_vps() {
@ -123,6 +125,8 @@ _set_ss_server_vps() {
current_method="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.method')" current_method="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.method')"
current_ebpf="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.ebpf')" current_ebpf="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.ebpf')"
current_obfs="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.obfs')" current_obfs="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.obfs')"
current_obfs_plugin="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.obfs_plugin')"
current_obfs_type="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.obfs_type')"
current_fast_open="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.fast_open')" current_fast_open="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.fast_open')"
current_no_delay="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.no_delay')" current_no_delay="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.no_delay')"
@ -130,12 +134,14 @@ _set_ss_server_vps() {
fast_open="false" fast_open="false"
no_delay="false" no_delay="false"
obfs="false" obfs="false"
obfs_plugin="v2ray"
obfs_type="http"
config_load shadowsocks-libev config_load shadowsocks-libev
config_foreach _get_ss_redir ss_redir config_foreach _get_ss_redir ss_redir
if [ "$current_port" != "$port" ] || [ "$current_method" != "$method" ] || [ "$current_key" != "$key" ] || [ "$current_ebpf" != "$ebpf" ] || [ "$current_obfs" != "$obfs" ] || [ "$current_fast_open" != "$fast_open" ] || [ "$current_no_delay" != "$no_delay" ]; then if [ "$current_obfs_plugin" != "$obfs_plugin" ] || [ "$current_obfs_type" != "$obfs_type" ] || [ "$current_port" != "$port" ] || [ "$current_method" != "$method" ] || [ "$current_key" != "$key" ] || [ "$current_ebpf" != "$ebpf" ] || [ "$current_obfs" != "$obfs" ] || [ "$current_fast_open" != "$fast_open" ] || [ "$current_no_delay" != "$no_delay" ]; then
local settings local settings
settings='{"port": '$port',"method":"'$method'","fast_open":'$fast_open',"reuse_port":true,"no_delay":'$no_delay',"mptcp":true,"key":"'$key'","ebpf":'$ebpf',"obfs":'$obfs'}' settings='{"port": '$port',"method":"'$method'","fast_open":'$fast_open',"reuse_port":true,"no_delay":'$no_delay',"mptcp":true,"key":"'$key'","ebpf":'$ebpf',"obfs":'$obfs',"obfs_plugin":"'$obfs_plugin'","obfs_type":"'$obfs_type'"}'
_set_json "shadowsocks" "$settings" _set_json "shadowsocks" "$settings"
fi fi
} }
@ -276,12 +282,14 @@ _set_config_from_vps() {
ss_no_delay="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.no_delay')" ss_no_delay="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.no_delay')"
ss_fast_open="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.fast_open')" ss_fast_open="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.fast_open')"
ss_obfs="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.obfs')" ss_obfs="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.obfs')"
ss_obfs_plugin="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.obfs_plugin')"
#ss_reuse_port="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.reuse_port')" #ss_reuse_port="$(echo "$vps_config" | jsonfilter -q -e '@.shadowsocks.reuse_port')"
config_load shadowsocks-libev config_load shadowsocks-libev
config_foreach _set_ss_redir ss_redir "no_delay" $ss_no_delay config_foreach _set_ss_redir ss_redir "no_delay" $ss_no_delay
config_foreach _set_ss_redir ss_redir "fast_open" $ss_fast_open config_foreach _set_ss_redir ss_redir "fast_open" $ss_fast_open
config_foreach _set_ss_redir ss_redir "ebpf" $ss_ebpf config_foreach _set_ss_redir ss_redir "ebpf" $ss_ebpf
config_foreach _set_ss_redir ss_redir "obfs" $ss_obfs config_foreach _set_ss_redir ss_redir "obfs" $ss_obfs
config_foreach _set_ss_redir ss_redir "obfs_plugin" $ss_obfs_plugin
uci -q batch <<-EOF >/dev/null uci -q batch <<-EOF >/dev/null
set shadowsocks-libev.sss0.key=$ss_key set shadowsocks-libev.sss0.key=$ss_key
set shadowsocks-libev.sss0.server_port=$ss_port set shadowsocks-libev.sss0.server_port=$ss_port

View file

@ -92,6 +92,7 @@ ss_mkjson_ss_local_conf() {
ss_mkjson_server_conf ss_mkjson_server_conf
[ "$obfs" = 0 ] && obfs=false || obfs=true [ "$obfs" = 0 ] && obfs=false || obfs=true
if $obfs; then if $obfs; then
if [ "$obfs_plugin" = "obfs" ]; then
obfs_options="obfs=$obfs_type" obfs_options="obfs=$obfs_type"
[ -z "$obfs_host" ] || obfs_options="$obfs_options;obfs-host=$obfs_host" [ -z "$obfs_host" ] || obfs_options="$obfs_options;obfs-host=$obfs_host"
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;obfs-uri=$obfs_uri" [ -z "$obfs_uri" ] || obfs_options="$obfs_options;obfs-uri=$obfs_uri"
@ -102,6 +103,17 @@ ss_mkjson_ss_local_conf() {
${obfs:+${q}plugin${q}: ${q}/usr/bin/obfs-local${q},${q}plugin_opts${q}: ${q}$obfs_options${q},} ${obfs:+${q}plugin${q}: ${q}/usr/bin/obfs-local${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
EOF EOF
fi fi
if [ "$obfs_plugin" = "v2ray" ]; then
obfs_options="loglevel=default"
[ "$obfs_type" = "tls" ] && obfs_options="tls"
[ -z "$obfs_host" ] || obfs_options="$obfs_options;host=$obfs_host"
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;path=$obfs_uri"
[ "$fast_open" = true ] && obfs_options="$obfs_options;fast-open"
cat <<-EOF
${obfs:+${q}plugin${q}: ${q}/usr/bin/v2ray-plugin${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
EOF
fi
fi
} }
ss_mkjson_ss_redir_conf() { ss_mkjson_ss_redir_conf() {
@ -112,6 +124,7 @@ ss_mkjson_ss_redir_conf() {
EOF EOF
[ "$obfs" = 0 ] && obfs=false || obfs=true [ "$obfs" = 0 ] && obfs=false || obfs=true
if $obfs; then if $obfs; then
if [ "$obfs_plugin" = "obfs" ]; then
obfs_options="obfs=$obfs_type" obfs_options="obfs=$obfs_type"
[ -z "$obfs_host" ] || obfs_options="$obfs_options;obfs-host=$obfs_host" [ -z "$obfs_host" ] || obfs_options="$obfs_options;obfs-host=$obfs_host"
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;obfs-uri=$obfs_uri" [ -z "$obfs_uri" ] || obfs_options="$obfs_options;obfs-uri=$obfs_uri"
@ -122,12 +135,24 @@ ss_mkjson_ss_redir_conf() {
${obfs:+${q}plugin${q}: ${q}/usr/bin/obfs-local${q},${q}plugin_opts${q}: ${q}$obfs_options${q},} ${obfs:+${q}plugin${q}: ${q}/usr/bin/obfs-local${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
EOF EOF
fi fi
if [ "$obfs_plugin" = "v2ray" ]; then
obfs_options="loglevel=default"
[ "$obfs_type" = "tls" ] && obfs_options="tls"
[ -z "$obfs_host" ] || obfs_options="$obfs_options;host=$obfs_host"
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;path=$obfs_uri"
[ "$fast_open" = true ] && obfs_options="$obfs_options;fast-open"
cat <<-EOF
${obfs:+${q}plugin${q}: ${q}/usr/bin/v2ray-plugin${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
EOF
fi
fi
} }
ss_mkjson_ss_server_conf() { ss_mkjson_ss_server_conf() {
ss_mkjson_server_conf_ ss_mkjson_server_conf_
[ "$obfs" = 0 ] && obfs=false || obfs=true [ "$obfs" = 0 ] && obfs=false || obfs=true
if $obfs; then if $obfs; then
if [ "$obfs_plugin" = "obfs" ]; then
obfs_options="obfs=$obfs_type" obfs_options="obfs=$obfs_type"
[ "$fast_open" = true ] && obfs_options="$obfs_options;fast-open" [ "$fast_open" = true ] && obfs_options="$obfs_options;fast-open"
[ "$mptcp" = true ] && obfs_options="$obfs_options;mptcp" [ "$mptcp" = true ] && obfs_options="$obfs_options;mptcp"
@ -136,6 +161,15 @@ ss_mkjson_ss_server_conf() {
${obfs:+${q}plugin${q}: ${q}/usr/bin/obfs-server${q},${q}plugin_opts${q}: ${q}$obfs_options${q},} ${obfs:+${q}plugin${q}: ${q}/usr/bin/obfs-server${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
EOF EOF
fi fi
if [ "$obfs_plugin" = "v2ray" ]; then
obfs_options="server"
[ "$obfs_type" = "tls" ] && obfs_options="tls"
[ "$fast_open" = true ] && obfs_options="$obfs_options;fast-open"
cat <<-EOF
${obfs:+${q}plugin${q}: ${q}/usr/bin/v2ray-plugin${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
EOF
fi
fi
} }
ss_mkjson_ss_tunnel_conf() { ss_mkjson_ss_tunnel_conf() {
@ -146,6 +180,7 @@ ss_mkjson_ss_tunnel_conf() {
EOF EOF
[ "$obfs" = 0 ] && obfs=false || obfs=true [ "$obfs" = 0 ] && obfs=false || obfs=true
if $obfs; then if $obfs; then
if [ "$obfs_plugin" = "obfs" ]; then
obfs_options="obfs=$obfs_type" obfs_options="obfs=$obfs_type"
[ -z "$obfs_host" ] || obfs_options="$obfs_options;obfs-host=$obfs_host" [ -z "$obfs_host" ] || obfs_options="$obfs_options;obfs-host=$obfs_host"
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;obfs-uri=$obfs_uri" [ -z "$obfs_uri" ] || obfs_options="$obfs_options;obfs-uri=$obfs_uri"
@ -154,6 +189,17 @@ ss_mkjson_ss_tunnel_conf() {
${obfs:+${q}plugin${q}: ${q}/usr/bin/obfs-local${q},${q}plugin_opts${q}: ${q}$obfs_options${q},} ${obfs:+${q}plugin${q}: ${q}/usr/bin/obfs-local${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
EOF EOF
fi fi
if [ "$obfs_plugin" = "v2ray" ]; then
obfs_options="loglevel=default"
[ "$obfs_type" = "tls" ] && obfs_options="tls"
[ -z "$obfs_host" ] || obfs_options="$obfs_options;host=$obfs_host"
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;path=$obfs_uri"
[ "$fast_open" = true ] && obfs_options="$obfs_options;fast-open"
cat <<-EOF
${obfs:+${q}plugin${q}: ${q}/usr/bin/v2ray-plugin${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
EOF
fi
fi
} }
ss_xxx() { ss_xxx() {
@ -427,6 +473,7 @@ validate_common_options_() {
'timeout:uinteger' \ 'timeout:uinteger' \
'user:string' \ 'user:string' \
'obfs:bool:0' \ 'obfs:bool:0' \
'obfs_plugin:or("v2ray","obfs-simple"):v2ray' \
'obfs_type:or("http","tls"):http' 'obfs_type:or("http","tls"):http'
} }

View file

@ -0,0 +1,66 @@
#
# Copyright (C) 2018-2019 chenhw2 <https://github.com/chenhw2>
#
# This is free software, licensed under the GNU General Public License v3.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=v2ray-plugin
PKG_VERSION:=1.0
PKG_RELEASE:=8cea1a3
PKG_MAINTAINER:=chenhw2 <https://github.com/chenhw2>
# OpenWrt ARCH: arm, i386, x86_64, mips, mipsel
# Golang ARCH: arm[5-7], 386, amd64, mips, mipsle
PKG_ARCH:=$(ARCH)
BIN_ARCH:=$(ARCH)
ifeq ($(ARCH),mipsel)
PKG_ARCH:=mips
BIN_ARCH:=mipsle
endif
ifeq ($(ARCH),i386)
PKG_ARCH:=386
BIN_ARCH:=386
endif
ifeq ($(ARCH),x86_64)
PKG_ARCH:=amd64
BIN_ARCH:=amd64
endif
ifeq ($(ARCH),arm)
BIN_ARCH:=arm7
endif
PKG_SOURCE:=v2ray-plugin-linux-$(PKG_ARCH)-$(PKG_RELEASE).tar.gz
PKG_SOURCE_URL:=https://github.com/shadowsocks/v2ray-plugin/releases/download/v$(PKG_VERSION)/
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_HASH:=skip
include $(INCLUDE_DIR)/package.mk
define Package/v2ray-plugin
SECTION:=net
CATEGORY:=Network
TITLE:=SIP003 plugin for shadowsocks, based on v2ray
URL:=https://github.com/shadowsocks/v2ray-plugin
endef
define Package/v2ray-plugin/description
Yet another SIP003 plugin for shadowsocks, based on v2ray
endef
define Build/Prepare
gzip -dc "$(DL_DIR)/$(PKG_SOURCE)" | tar -C $(PKG_BUILD_DIR)/ -xf -
endef
define Build/Compile
echo "$(PKG_NAME)Compile Skiped!"
endef
define Package/v2ray-plugin/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/v2ray-plugin_linux_$(BIN_ARCH) $(1)/usr/bin/v2ray-plugin
endef
$(eval $(call BuildPackage,v2ray-plugin))