Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
fix #287 #286 #275

Signed-off-by: Jian Chang <[email protected]>
  • Loading branch information
aa65535 committed May 10, 2022
1 parent 1f7b039 commit e549697
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
5 changes: 3 additions & 2 deletions files/luci/model/cbi/shadowsocks/servers-details.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright (C) 2016-2021 Jian Chang <[email protected]>
-- Copyright (C) 2016-2022 Jian Chang <[email protected]>
-- Licensed to the public under the GNU General Public License v3.

local m, s, o
Expand Down Expand Up @@ -64,7 +64,8 @@ local function has_ssr_bins()
end

local function support_fast_open()
return luci.sys.exec("cat /proc/sys/net/ipv4/tcp_fastopen 2>/dev/null"):trim() == "3"
local bit = luci.sys.exec("cat /proc/sys/net/ipv4/tcp_fastopen 2>/dev/null"):trim()
return bit == "1" or bit == "3"
end

m = Map(shadowsocks, "%s - %s" %{translate("ShadowSocks"), translate("Edit Server")})
Expand Down
3 changes: 2 additions & 1 deletion files/root/etc/init.d/shadowsocks
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh /etc/rc.common
#
# Copyright (C) 2014-2021 Jian Chang <[email protected]>
# Copyright (C) 2014-2022 Jian Chang <[email protected]>
#
# This is free software, licensed under the GNU General Public License v3.
# See /LICENSE for more information.
Expand Down Expand Up @@ -241,6 +241,7 @@ boot() {
}

kill_all() {
pidof $@ || return 1
kill -9 $(pidof $@) >/dev/null 2>&1
}

Expand Down
45 changes: 41 additions & 4 deletions files/root/usr/bin/ss-subscribe
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/lua

-- Copyright (C) 2021 Jian Chang <[email protected]>
-- Copyright (C) 2021-2022 Jian Chang <[email protected]>

-- This is free software, licensed under the GNU General Public License v3.
-- See /LICENSE for more information.
Expand All @@ -12,6 +12,8 @@ require "nixio"

local config = "shadowsocks"
local uci = luci.model.uci.cursor()
local bit = luci.sys.exec("cat /proc/sys/net/ipv4/tcp_fastopen 2>/dev/null"):trim()
local tfo = bit == "1" or bit == "3"

function base64_decode(text)
if not text then
Expand Down Expand Up @@ -41,7 +43,7 @@ end
function parse_ss(data)
local pos = 0
local params = {}
local result = {type = "ss", timeout = 300, fast_open = 0, no_delay = 0}
local result = {type = "ss", timeout = 300, fast_open = tfo, no_delay = 0}
if data:find("#") then
pos = data:find("#")
local alias = data:sub(pos + 1, -1)
Expand Down Expand Up @@ -78,7 +80,7 @@ end
function parse_ssr(data)
data = luci.util.split(base64_decode(data), "/?")
local main = luci.util.split(data[1], ":")
local result = {type = "ssr", timeout = 300, fast_open = 0}
local result = {type = "ssr", timeout = 300, fast_open = tfo}
local params = {}
result.host = main[1]
result.server = resolveip(main[1])
Expand Down Expand Up @@ -146,7 +148,39 @@ function exec_subscribe(section)
return true
end

function table_equal(t1, t2)
for k, v in pairs(t1) do
if "table" == type(v) then
return table_equal(v, t2[k])
else
if v ~= t2[k] then
return false
end
end
end
return true
end

function get_current_servers()
local name = ""
local servers = {}
local sections = {
{"transparent_proxy", "main_server"},
{"transparent_proxy", "udp_relay_server"},
{"socks5_proxy", "server"},
{"port_forward", "server"}
}
for _, v in pairs(sections) do
name = uci:get_first(config, v[1], v[2])
if name and name ~= "nil" and name ~= "same" then
servers[name] = uci:get_all(config, name)
end
end
return servers
end

if #arg > 0 then
local servers = get_current_servers()
if arg[1]:lower() == "all" then
uci:foreach(config, "subscription", function(s)
exec_subscribe(s[".name"])
Expand All @@ -164,7 +198,10 @@ if #arg > 0 then
end
end
if uci:commit(config) then
os.execute("/etc/init.d/%s restart" %{config})
local current = get_current_servers()
if not table_equal(servers, current) then
os.execute("/etc/init.d/%s restart" %{config})
end
end
os.exit(0)
else
Expand Down

0 comments on commit e549697

Please sign in to comment.