From a73a32360e2cdf06d854cf8c9218f0aa72a88877 Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Fri, 8 Apr 2022 04:17:19 +0800 Subject: [PATCH] luci-app-ssr-plus: add Packet Encoding option Signed-off-by: Tianling Shen --- luci-app-ssr-plus/Makefile | 4 ++-- .../model/cbi/shadowsocksr/advanced.lua | 6 ++++++ .../model/cbi/shadowsocksr/client-config.lua | 20 ++++++++++++++++++- luci-app-ssr-plus/po/zh-cn/ssr-plus.po | 6 ++++++ .../root/etc/init.d/shadowsocksr | 1 + .../usr/share/shadowsocksr/gen_config.lua | 13 +++++++++--- .../root/usr/share/shadowsocksr/subscribe.lua | 4 ++++ 7 files changed, 48 insertions(+), 6 deletions(-) diff --git a/luci-app-ssr-plus/Makefile b/luci-app-ssr-plus/Makefile index 86b4057ef..891d5883c 100644 --- a/luci-app-ssr-plus/Makefile +++ b/luci-app-ssr-plus/Makefile @@ -26,8 +26,8 @@ LUCI_PKGARCH:=all LUCI_DEPENDS:= \ @(PACKAGE_libustream-mbedtls||PACKAGE_libustream-openssl||PACKAGE_libustream-wolfssl) \ +coreutils +coreutils-base64 +dns2socks +dns2tcp +dnsmasq-full +ipset +kmod-ipt-nat \ - +ip-full +iptables +iptables-mod-tproxy +lua +libuci-lua +microsocks +tcping \ - +resolveip +shadowsocksr-libev-ssr-check +uclient-fetch \ + +ip-full +iptables +iptables-mod-tproxy +lua +libuci-lua ++luci-lib-ipkg +microsocks \ + +tcping +resolveip +shadowsocksr-libev-ssr-check +uclient-fetch \ +PACKAGE_$(PKG_NAME)_INCLUDE_Kcptun:kcptun-client \ +PACKAGE_$(PKG_NAME)_INCLUDE_IPT2Socks:ipt2socks \ +PACKAGE_$(PKG_NAME)_INCLUDE_NaiveProxy:naiveproxy \ diff --git a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua index 26e1db6e2..6de68df80 100644 --- a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua +++ b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua @@ -56,6 +56,12 @@ o:value("https://ispip.clang.cn/all_cn.txt", translate("Clang.CN")) o:value("https://ispip.clang.cn/all_cn_cidr.txt", translate("Clang.CN.CIDR")) o.default = "https://ispip.clang.cn/all_cn.txt" +o = s:option(ListValue, "default_packet_encoding", translate("Default Packet Encoding")) +o:value("none", translate("none")) +o:value("packet", translate("packet (v2ray-core v5+)")) +o:value("xudp", translate("xudp (Xray-core)")) +o.default = "xudp" + o = s:option(Flag, "netflix_enable", translate("Enable Netflix Mode")) o.rmempty = false diff --git a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua index 79ed9431b..7422b5a2f 100644 --- a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua +++ b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua @@ -1,16 +1,23 @@ -- Copyright (C) 2017 yushi studio github.com/ywb94 -- Licensed to the public under the GNU General Public License v3. + require "nixio.fs" require "luci.sys" require "luci.http" +require "luci.model.ipkg" + local m, s, o, kcp_enable local sid = arg[1] local uuid = luci.sys.exec("cat /proc/sys/kernel/random/uuid") -function is_finded(e) +local function is_finded(e) return luci.sys.exec('type -t -p "%s"' % e) ~= "" and true or false end +local function is_installed(e) + return luci.model.ipkg.installed(e) +end + local server_table = {} local encrypt_methods = { -- ssr @@ -622,6 +629,17 @@ o:depends("type", "ssr") o:depends("type", "ss") o:depends("type", "trojan") +if is_installed("sagernet-core") then + o = s:option(ListValue, "packet_encoding", translate("Packet Encoding")) + o:value("none", translate("none")) + o:value("packet", translate("packet (v2ray-core v5+)")) + o:value("xudp", translate("xudp (Xray-core)")) + o.default = "xudp" + o.rmempty = true + o:depends({type = "v2ray", v2ray_protocol = "vless"}) + o:depends({type = "v2ray", v2ray_protocol = "vmess"}) +end + o = s:option(Flag, "switch_enable", translate("Enable Auto Switch")) o.rmempty = false o.default = "1" diff --git a/luci-app-ssr-plus/po/zh-cn/ssr-plus.po b/luci-app-ssr-plus/po/zh-cn/ssr-plus.po index e1ee40dd5..621c05b5d 100644 --- a/luci-app-ssr-plus/po/zh-cn/ssr-plus.po +++ b/luci-app-ssr-plus/po/zh-cn/ssr-plus.po @@ -730,6 +730,9 @@ msgstr "写入缓冲区大小" msgid "Congestion" msgstr "拥塞控制" +msgid "Packet Encoding" +msgstr "数据包编码" + msgid "Network interface to use" msgstr "使用的网络接口" @@ -757,5 +760,8 @@ msgstr "重新应用" msgid "Apply" msgstr "应用" +msgid "Default Packet Encoding" +msgstr "默认数据包编码" + msgid "Enable Netflix Mode" msgstr "启用 Netflix 分流模式" diff --git a/luci-app-ssr-plus/root/etc/init.d/shadowsocksr b/luci-app-ssr-plus/root/etc/init.d/shadowsocksr index dff53b6fe..a14160e06 100755 --- a/luci-app-ssr-plus/root/etc/init.d/shadowsocksr +++ b/luci-app-ssr-plus/root/etc/init.d/shadowsocksr @@ -908,6 +908,7 @@ reset() { set shadowsocksr.@global[0].switch_time='667' set shadowsocksr.@global[0].switch_timeout='5' set shadowsocksr.@global[0].switch_try_count='3' + set shadowsocksr.@global[0].default_packet_encoding='xudp' set shadowsocksr.@global[0].gfwlist_url='https://fastly.jsdelivr.net/gh/YW5vbnltb3Vz/domain-list-community@release/gfwlist.txt' set shadowsocksr.@global[0].chnroute_url='https://ispip.clang.cn/all_cn.txt' set shadowsocksr.@global[0].nfip_url='https://fastly.jsdelivr.net/gh/QiuSimons/Netflix_IP/NF_only.txt' diff --git a/luci-app-ssr-plus/root/usr/share/shadowsocksr/gen_config.lua b/luci-app-ssr-plus/root/usr/share/shadowsocksr/gen_config.lua index e7f1a0cdd..d210a0e4d 100755 --- a/luci-app-ssr-plus/root/usr/share/shadowsocksr/gen_config.lua +++ b/luci-app-ssr-plus/root/usr/share/shadowsocksr/gen_config.lua @@ -1,11 +1,16 @@ -local ucursor = require"luci.model.uci".cursor() +#!/usr/bin/lua + +local ucursor = require "luci.model.uci".cursor() local json = require "luci.jsonc" + local server_section = arg[1] local proto = arg[2] local local_port = arg[3] or "0" local socks_port = arg[4] or "0" + local server = ucursor:get_all("shadowsocksr", server_section) local outbound_settings = nil + function vmess_vless() outbound_settings = { vnext = { @@ -21,7 +26,8 @@ function vmess_vless() } } } - } + }, + packetEncoding = server.packet_encoding or nil } end function trojan_shadowsocks() @@ -185,7 +191,8 @@ local Xray = { mux = (server.mux == "1" and server.xtls ~= "1" and server.transport ~= "grpc") and { -- mux enabled = true, - concurrency = tonumber(server.concurrency) + concurrency = tonumber(server.concurrency), + packetEncoding = (server.v2ray_protocol == "vmess" or server.v2ray_protocol == "vless") and server.packet_encoding or nil } or nil } or nil } diff --git a/luci-app-ssr-plus/root/usr/share/shadowsocksr/subscribe.lua b/luci-app-ssr-plus/root/usr/share/shadowsocksr/subscribe.lua index 7847b2164..f158e4b17 100755 --- a/luci-app-ssr-plus/root/usr/share/shadowsocksr/subscribe.lua +++ b/luci-app-ssr-plus/root/usr/share/shadowsocksr/subscribe.lua @@ -9,6 +9,7 @@ require "nixio" require "luci.util" require "luci.sys" require "luci.jsonc" +require "luci.model.ipkg" -- these global functions are accessed all the time by the event handler -- so caching them is worth the effort local tinsert = table.insert @@ -25,6 +26,7 @@ local switch = ucic:get_first(name, 'server_subscribe', 'switch', '1') local subscribe_url = ucic:get_first(name, 'server_subscribe', 'subscribe_url', {}) local filter_words = ucic:get_first(name, 'server_subscribe', 'filter_words', '过期时间/剩余流量') local save_words = ucic:get_first(name, 'server_subscribe', 'save_words', '') +local packet_encoding = luci.model.ipkg.installed("sagernet-core") and ucic:get_first(name, 'global', 'default_packet_encoding', 'xudp') or nil local v2_ss = luci.sys.exec('type -t -p ss-redir sslocal') ~= "" and "ss" or "v2ray" local v2_tj = luci.sys.exec('type -t -p trojan') ~= "" and "trojan" or "v2ray" local log = function(...) @@ -168,6 +170,7 @@ local function processData(szType, content) result.transport = info.net result.vmess_id = info.id result.alias = info.ps + result.packet_encoding = packet_encoding -- result.mux = 1 -- result.concurrency = 8 if info.net == 'ws' then @@ -373,6 +376,7 @@ local function processData(szType, content) result.vmess_id = uuid result.vless_encryption = params.encryption or "none" result.transport = params.type and (params.type == 'http' and 'h2' or params.type) or "tcp" + result.packet_encoding = packet_encoding if not params.type or params.type == "tcp" then if params.security == "xtls" then result.xtls = "1"