From 2121e97d32bf92b4654d56a92f7c31a2e19fe6b3 Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Sat, 10 Nov 2018 23:16:17 +0800 Subject: [PATCH] add V2Ray and SSR server in luci ssr plus --- package/lean/luci-app-ssr-plus/Makefile | 2 +- .../model/cbi/shadowsocksr/client-config.lua | 14 ++++ .../luci-app-ssr-plus/po/zh-cn/ssr-plus.po | 2 +- .../root/etc/init.d/shadowsocksr | 38 ++++++--- .../usr/share/shadowsocksr/genv2config.lua | 78 +++++++++++++++++++ package/lean/v2ray/Makefile | 2 +- 6 files changed, 122 insertions(+), 14 deletions(-) create mode 100644 package/lean/luci-app-ssr-plus/root/usr/share/shadowsocksr/genv2config.lua diff --git a/package/lean/luci-app-ssr-plus/Makefile b/package/lean/luci-app-ssr-plus/Makefile index 4555ac258..25cbfb8f9 100644 --- a/package/lean/luci-app-ssr-plus/Makefile +++ b/package/lean/luci-app-ssr-plus/Makefile @@ -9,7 +9,7 @@ LUCI_TITLE:=LuCI support for SSR Plus LUCI_DEPENDS:=+shadowsocksr-libev-alt +shadowsocks-libev-ss-redir +ipset +ip-full +iptables-mod-tproxy +dnsmasq-full +coreutils +coreutils-base64 +bash +pdnsd-alt +wget LUCI_PKGARCH:=all PKG_VERSION:=1 -PKG_RELEASE:=36 +PKG_RELEASE:=38 include $(TOPDIR)/feeds/luci/luci.mk diff --git a/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua b/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua index d87a6b82e..57654fd02 100644 --- a/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua +++ b/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua @@ -8,6 +8,7 @@ local ipkg = require("luci.model.ipkg") local fs = require "nixio.fs" local sys = require "luci.sys" local sid = arg[1] +local uuid = luci.sys.exec("cat /proc/sys/kernel/random/uuid") local function isKcptun(file) if not fs.access(file, "rwx", "rx", "rx") then @@ -151,6 +152,8 @@ o.rmempty = false o = s:option(Value, "password", translate("Password")) o.password = true o.rmempty = false +o:depends("type", "ssr") +o:depends("type", "ss") o = s:option(ListValue, "encrypt_method", translate("Encrypt Method")) for _, v in ipairs(encrypt_methods) do o:value(v) end @@ -188,6 +191,7 @@ o:depends("type", "v2ray") -- VmessId o = s:option(Value, "vmess_id", translate("VmessId")) o.rmempty = false +o.default = uuid o:depends("type", "v2ray") -- 加密方式 @@ -308,6 +312,8 @@ o:depends("type", "v2ray") o = s:option(Flag, "fast_open", translate("TCP Fast Open")) o.rmempty = false o.default = "0" +o:depends("type", "ssr") +o:depends("type", "ss") o = s:option(Flag, "switch_enable", translate("Enable Auto Switch")) o.rmempty = false @@ -322,6 +328,8 @@ if nixio.fs.access("/usr/bin/ssr-kcptun") then kcp_enable = s:option(Flag, "kcp_enable", translate("KcpTun Enable"), translate("bin:/usr/bin/ssr-kcptun")) kcp_enable.rmempty = false +kcp_enable:depends("type", "ssr") +kcp_enable:depends("type", "ss") o = s:option(Value, "kcp_port", translate("KcpTun Port")) o.datatype = "port" @@ -339,12 +347,18 @@ function o.validate(self, value, section) return value end +kcp_enable:depends("type", "ssr") +kcp_enable:depends("type", "ss") o = s:option(Value, "kcp_password", translate("KcpTun Password")) o.password = true +kcp_enable:depends("type", "ssr") +kcp_enable:depends("type", "ss") o = s:option(Value, "kcp_param", translate("KcpTun Param")) o.default = "--nocomp" +kcp_enable:depends("type", "ssr") +kcp_enable:depends("type", "ss") end diff --git a/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po b/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po index a2fc72d4f..c74fd43c2 100644 --- a/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po +++ b/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po @@ -369,7 +369,7 @@ msgid "GFW List" msgstr "GFW列表" msgid "ShadowSocksR Plus+ Settings" -msgstr "ShadowSocksR Plus+ 设置" +msgstr "ShadowSocksR Plus+ 设置(支持SS/SSR/V2RAY)" msgid "Main Server" msgstr "主服务器" diff --git a/package/lean/luci-app-ssr-plus/root/etc/init.d/shadowsocksr b/package/lean/luci-app-ssr-plus/root/etc/init.d/shadowsocksr index 2a8da1b92..91f9a545c 100755 --- a/package/lean/luci-app-ssr-plus/root/etc/init.d/shadowsocksr +++ b/package/lean/luci-app-ssr-plus/root/etc/init.d/shadowsocksr @@ -2,6 +2,7 @@ # # Copyright (C) 2017 openwrt-ssr # Copyright (C) 2017 yushi studio +# Copyright (C) 2018 lean # # This is free software, licensed under the GNU General Public License v3. # See /LICENSE for more information. @@ -119,6 +120,8 @@ EOF "fast_open": $fastopen } EOF + elif [ "$stype" == "v2ray" ] ;then + lua /usr/share/shadowsocksr/genv2config.lua $GLOBAL_SERVER tcp > /var/etc/v2-ssr-retcp.json fi } @@ -147,7 +150,7 @@ start_rules() { kcp_server=$server - local kcp_enable=$(uci_get_by_name $GLOBAL_SERVER kcp_enable) + local kcp_enable=$(uci_get_by_name $GLOBAL_SERVER kcp_enable 0) if [ $kcp_enable = "1" ] ;then kcp_flag=1 fi @@ -256,7 +259,7 @@ start_redir() { esac #deal kcp - local kcp_enable=$(uci_get_by_name $GLOBAL_SERVER kcp_enable) + local kcp_enable=$(uci_get_by_name $GLOBAL_SERVER kcp_enable 0) if [ $kcp_enable = "1" ] ;then [ ! -f "/usr/bin/ssr-kcptun" ] && return 1 @@ -280,7 +283,7 @@ start_redir() { elif [ "$stype" == "ssr" ] ;then sscmd="/usr/bin/ssr-redir" elif [ "$stype" == "v2ray" ] ;then - sscmd="/usr/bin/v2ray" + sscmd="/usr/bin/v2ray/v2ray" fi local utype=$(uci_get_by_name $UDP_RELAY_SERVER type) @@ -289,17 +292,23 @@ start_redir() { elif [ "$utype" == "ssr" ] ;then ucmd="/usr/bin/ssr-redir" elif [ "$utype" == "v2ray" ] ;then - ucmd="/usr/bin/v2ray" + ucmd="/usr/bin/v2ray/v2ray" fi redir_tcp=1 - local last_config_file=$CONFIG_FILE - local pid_file="/var/run/ssr-retcp.pid" - $sscmd \ - -c $CONFIG_FILE $ARG_OTA \ - -f /var/run/ssr-retcp.pid + + if [ "$stype" == "ss" -o "$stype" == "ssr" ] ;then + local last_config_file=$CONFIG_FILE + local pid_file="/var/run/ssr-retcp.pid" + $sscmd \ + -c $CONFIG_FILE $ARG_OTA \ + -f /var/run/ssr-retcp.pid + elif [ "$stype" == "v2ray" ] ;then + $sscmd -config /var/etc/v2-ssr-retcp.json >/dev/null 2>&1 & + fi if [ "$ARG_UDP" = "-U" ]; then + if [ "$utype" == "ss" -o "$utype" == "ssr" ] ;then case "$(uci_get_by_name $UDP_RELAY_SERVER auth_enable)" in 1|on|true|yes|enabled) ARG_OTA="-A";; *) ARG_OTA="";; @@ -310,9 +319,15 @@ start_redir() { redir_udp=1 $ucmd \ -c $last_config_file $ARG_OTA $ARG_UDP \ - -f $pid_file + -f $pid_file + fi fi - + + if [ "$utype" == "v2ray" ] ; then + lua /usr/share/shadowsocksr/genv2config.lua $UDP_RELAY_SERVER udp > /var/etc/v2-ssr-reudp.json + $ucmd -config /var/etc/v2-ssr-reudp.json >/dev/null 2>&1 & + fi + #deal with dns if [ "$(uci_get_by_type global pdnsd_enable)" = "1" ] ;then @@ -471,6 +486,7 @@ stop() { fi killall -q -9 ss-redir killall -q -9 ssr-redir + killall -q -9 v2ray killall -q -9 ssr-server killall -q -9 ssr-kcptun killall -q -9 ssr-local diff --git a/package/lean/luci-app-ssr-plus/root/usr/share/shadowsocksr/genv2config.lua b/package/lean/luci-app-ssr-plus/root/usr/share/shadowsocksr/genv2config.lua new file mode 100644 index 000000000..8196ae091 --- /dev/null +++ b/package/lean/luci-app-ssr-plus/root/usr/share/shadowsocksr/genv2config.lua @@ -0,0 +1,78 @@ +local ucursor = require "luci.model.uci" +local json = require "luci.jsonc" +local server_section = arg[1] +local proto = arg[2] + +local server = ucursor:get_all("shadowsocksr", server_section) + +local v2ray = { + -- 传入连接 + inbound = { + port = 1234, + protocol = "dokodemo-door", + settings = { + network = proto, + followRedirect = true + }, + sniffing = { + enabled = true, + destOverride = { "http", "tls" } + } + }, + -- 传出连接 + outbound = { + protocol = "vmess", + settings = { + vnext = { + { + address = server.server, + port = tonumber(server.server_port), + users = { + { + id = server.vmess_id, + alterId = tonumber(server.alter_id), + security = server.security + } + } + } + } + }, + -- 底层传输配置 + streamSettings = { + network = server.transport, + security = (server.tls == '1') and "tls" or "none", + kcpSettings = (server.transport == "kcp") and { + mtu = tonumber(server.mtu), + tti = tonumber(server.tti), + uplinkCapacity = tonumber(server.uplink_capacity), + downlinkCapacity = tonumber(server.downlink_capacity), + congestion = (server.congestion == "1") and true or false, + readBufferSize = tonumber(server.read_buffer_size), + writeBufferSize = tonumber(server.write_buffer_size), + header = { + type = server.kcp_guise + } + } or nil, + wsSettings = (server.transport == "ws") and { + path = server.ws_path, + headers = (server.ws_host ~= nil) and { + Host = server.ws_host + } or nil, + } or nil, + httpSettings = (server.transport == "h2") and { + path = server.h2_path, + host = server.h2_host, + } or nil + } + }, + + -- 额外传出连接 + outboundDetour = { + { + protocol = "freedom", + tag = "direct", + settings = { keep = "" } + } + } +} +print(json.stringify(v2ray)) \ No newline at end of file diff --git a/package/lean/v2ray/Makefile b/package/lean/v2ray/Makefile index 2573646a8..433df2f2a 100644 --- a/package/lean/v2ray/Makefile +++ b/package/lean/v2ray/Makefile @@ -39,7 +39,7 @@ define Package/$(PKG_NAME) SECTION:=net CATEGORY:=Network TITLE:=V2Ray is a cross-platform proxy software - DEPENDS:= + DEPENDS:=+ca-certificates URL:=https://github.com/v2ray/v2ray-core endef