luci-app-vssr: bump to v1.16

This commit is contained in:
CN_SZTL 2020-08-26 15:31:34 +08:00
parent 42b5144652
commit 5dfc9cc357
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
32 changed files with 1544 additions and 1702 deletions

View File

@ -1,8 +1,8 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-vssr
PKG_VERSION:=1.15
PKG_RELEASE:=20200825
PKG_VERSION:=1.16
PKG_RELEASE:=20200826
include $(INCLUDE_DIR)/package.mk

View File

@ -97,19 +97,26 @@ end
-- 切换节点
function change_node()
local sockets = require "socket"
local e = {}
local uci = luci.model.uci.cursor()
local sid = luci.http.formvalue("set")
local server = luci.http.formvalue("server")
local flow_table = {"youtube","tw_video","netflix","disney","prime","tvb","custom"}
e.status = false
e.sid = sid
if sid ~= "" and server ~= "" then
uci:set("vssr", '@global[0]', server..'_server', sid)
if( server ~= "global" ) then
uci:set("vssr", '@global[0]', server..'_server', sid)
if( server ~= "global" and server ~= "udp_relay" ) then
uci:set("vssr", '@global[0]', 'v2ray_flow', "1")
for i, v in pairs(flow_table) do
if( v ~= server) then
uci:set("vssr", '@global[0]', v..'_server', 'nil')
end
end
end
uci:commit("vssr")
luci.sys.exec("/etc/init.d/vssr restart")
luci.sys.call("/etc/init.d/vssr restart >/www/restartlog.htm 2>&1")
e.status = true
end
luci.http.prepare_content("application/json")
@ -178,12 +185,18 @@ function check_ip()
local d = {}
local mm = require 'maxminddb'
local vssr = require "vssrutil"
local port = 80
local db = mm.open('/usr/share/vssr/GeoLite2-Country.mmdb')
local ip = vssr.wget("http://api.ipify.org/")
local res = db:lookup(ip)
local port = 80
d.flag = string.lower(res:get("country", "iso_code"))
d.country = res:get("country", "names", "zh-CN")
if (ip ~= "") then
local res = db:lookup(ip)
d.flag = string.lower(res:get("country", "iso_code"))
d.country = res:get("country", "names", "zh-CN")
else
d.flag = "un"
d.country = "Unknown"
ip = "Unknown"
end
e.outboard = ip
e.outboardip = d
e.baidu = vssr.check_site("www.baidu.com",port)

View File

@ -6,6 +6,7 @@ local gfwmode = 0
local gfw_count = 0
local ip_count = 0
local ad_count = 0
local server_count = 0
if nixio.fs.access("/etc/dnsmasq.ssr/gfw_list.conf") then gfwmode = 1 end
@ -23,24 +24,11 @@ if nixio.fs.access("/etc/china_ssr.txt") then
ip_count = sys.exec("cat /etc/china_ssr.txt | wc -l")
end
uci:foreach(vssr, "servers", function(s)
if s["type"] == "v2ray" then
if s.alias then
server_table[s[".name"]] = "[%s]:%s" %
{string.upper(s.type), s.alias}
elseif s.server and s.server_port then
server_table[s[".name"]] = "[%s]:%s:%s" %
{
string.upper(s.type), s.server, s.server_port
}
end
end
uci:foreach("vssr", "servers", function(s)
server_count = server_count + 1
end)
local key_table = {}
for key, _ in pairs(server_table) do table.insert(key_table, key) end
table.sort(key_table)
m = Map(vssr)
-- [[ 服务器节点故障自动切换设置 ]]--
@ -98,14 +86,22 @@ o = s:option(DummyValue, "", "")
o.rawhtml = true
o.template = "vssr/update_subscribe"
o = s:option(Button, "delete", translate("Delete all severs"))
o = s:option(Button,"delete",translate("Delete All Subscribe Severs"))
o.inputstyle = "reset"
o.description = string.format(translate("Server Count") .. ": %d", server_count)
o.write = function()
uci:delete_all("vssr", "servers", function(s) return true end)
uci:commit("vssr")
luci.sys.exec("/etc/init.d/vssr stop")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "vssr",
"advanced"))
uci:delete_all("vssr", "servers", function(s)
if s.hashkey or s.isSubscribe then
return true
else
return false
end
end)
uci:save("vssr")
uci:commit("vssr")
luci.sys.exec("/etc/init.d/vssr restart")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "vssr", "servers"))
return
end
-- [[ adblock ]]--

View File

@ -18,85 +18,33 @@ end
local server_table = {}
local encrypt_methods = {
"none",
"table",
"rc4",
"rc4-md5-6",
"rc4-md5",
"aes-128-cfb",
"aes-192-cfb",
"aes-256-cfb",
"aes-128-ctr",
"aes-192-ctr",
"aes-256-ctr",
"bf-cfb",
"camellia-128-cfb",
"camellia-192-cfb",
"camellia-256-cfb",
"cast5-cfb",
"des-cfb",
"idea-cfb",
"rc2-cfb",
"seed-cfb",
"salsa20",
"chacha20",
"chacha20-ietf",
"none", "table", "rc4", "rc4-md5-6", "rc4-md5", "aes-128-cfb",
"aes-192-cfb", "aes-256-cfb", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr",
"bf-cfb", "camellia-128-cfb", "camellia-192-cfb", "camellia-256-cfb",
"cast5-cfb", "des-cfb", "idea-cfb", "rc2-cfb", "seed-cfb", "salsa20",
"chacha20", "chacha20-ietf"
}
local encrypt_methods_ss = {
-- aead
"aes-128-gcm",
"aes-192-gcm",
"aes-256-gcm",
"chacha20-ietf-poly1305",
"xchacha20-ietf-poly1305",
-- stream
"table",
"rc4",
"rc4-md5",
"aes-128-cfb",
"aes-192-cfb",
"aes-256-cfb",
"aes-128-ctr",
"aes-192-ctr",
"aes-256-ctr",
"bf-cfb",
"camellia-128-cfb",
"camellia-192-cfb",
"camellia-256-cfb",
"salsa20",
"chacha20",
"chacha20-ietf",
-- aead
"aes-128-gcm", "aes-192-gcm", "aes-256-gcm", "chacha20-ietf-poly1305",
"xchacha20-ietf-poly1305", -- stream
"table", "rc4", "rc4-md5", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb",
"aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "bf-cfb", "camellia-128-cfb",
"camellia-192-cfb", "camellia-256-cfb", "salsa20", "chacha20",
"chacha20-ietf"
}
local protocol = {
"origin",
"verify_deflate",
"auth_sha1_v4",
"auth_aes128_sha1",
"auth_aes128_md5",
"auth_chain_a",
"auth_chain_b",
"auth_chain_c",
"auth_chain_d",
"auth_chain_e",
"auth_chain_f",
"origin", "verify_deflate", "auth_sha1_v4", "auth_aes128_sha1",
"auth_aes128_md5", "auth_chain_a", "auth_chain_b", "auth_chain_c",
"auth_chain_d", "auth_chain_e", "auth_chain_f"
}
obfs = {
"plain",
"http_simple",
"http_post",
"random_head",
"tls1.2_ticket_auth",
"plain", "http_simple", "http_post", "random_head", "tls1.2_ticket_auth"
}
local securitys = {
"auto",
"none",
"aes-128-gcm",
"chacha20-poly1305"
}
local securitys = {"auto", "none", "aes-128-gcm", "chacha20-poly1305"}
m = Map(vssr, translate("Edit vssr Server"))
m.redirect = luci.dispatcher.build_url("admin/services/vssr/servers")
@ -180,7 +128,6 @@ o = s:option(Value, "plugin_opts", translate("Plugin Opts"))
o.rmempty = true
o:depends("type", "ss")
o = s:option(ListValue, "protocol", translate("Protocol"))
for _, v in ipairs(protocol) do o:value(v) end
o.rmempty = true
@ -194,8 +141,6 @@ for _, v in ipairs(obfs) do o:value(v) end
o.rmempty = true
o:depends("type", "ssr")
o = s:option(Value, "obfs_param", translate("Obfs param(optional)"))
o:depends("type", "ssr")

View File

@ -1,104 +1,111 @@
-- Copyright (C) 2017 yushi studio <ywb94@qq.com> github.com/ywb94
-- Copyright (C) 2018 lean <coolsnowwolf@gmail.com> github.com/coolsnowwolf
-- Licensed to the public under the GNU General Public License v3.
local m, s, sec, o, kcp_enable
local vssr = "vssr"
local gfwmode=0
local gfwmode = 0
if nixio.fs.access("/etc/dnsmasq.ssr/gfw_list.conf") then
gfwmode=1
end
if nixio.fs.access("/etc/dnsmasq.ssr/gfw_list.conf") then gfwmode = 1 end
local uci = luci.model.uci.cursor()
m = Map(vssr)
m:section(SimpleSection).template = "vssr/status_top"
m:section(SimpleSection).template = "vssr/status_top"
local server_table = {}
local tw_table = {}
local tvb_table = {}
uci:foreach(vssr, "servers", function(s)
if s.alias then
server_table[s[".name"]] = "[%s]:%s" %{string.upper(s.type), s.alias}
elseif s.server and s.server_port then
server_table[s[".name"]] = "[%s]:%s:%s" %{string.upper(s.type), s.server, s.server_port}
end
if s.flag == "tw" then
if s.alias then
tw_table[s[".name"]] = "[%s]:%s" %{string.upper(s.type), s.alias}
elseif s.server and s.server_port then
tw_table[s[".name"]] = "[%s]:%s:%s" %{string.upper(s.type), s.server, s.server_port}
end
end
if s.flag == "hk" then
if s.alias then
tvb_table[s[".name"]] = "[%s]:%s" %{string.upper(s.type), s.alias}
elseif s.server and s.server_port then
tvb_table[s[".name"]] = "[%s]:%s:%s" %{string.upper(s.type), s.server, s.server_port}
end
end
if s.alias then
server_table[s[".name"]] = "[%s]:%s" % {string.upper(s.type), s.alias}
elseif s.server and s.server_port then
server_table[s[".name"]] = "[%s]:%s:%s" %
{
string.upper(s.type), s.server, s.server_port
}
end
if s.flag == "tw" then
if s.alias then
tw_table[s[".name"]] = "[%s]:%s" % {string.upper(s.type), s.alias}
elseif s.server and s.server_port then
tw_table[s[".name"]] = "[%s]:%s:%s" %
{
string.upper(s.type), s.server, s.server_port
}
end
end
if s.flag == "hk" then
if s.alias then
tvb_table[s[".name"]] = "[%s]:%s" % {string.upper(s.type), s.alias}
elseif s.server and s.server_port then
tvb_table[s[".name"]] = "[%s]:%s:%s" %
{
string.upper(s.type), s.server, s.server_port
}
end
end
end)
local key_table = {}
for key,_ in pairs(server_table) do
table.insert(key_table,key)
end
local key_table = {}
for key, _ in pairs(server_table) do table.insert(key_table, key) end
local key_table_tw = {}
for key,_ in pairs(tw_table) do
table.insert(key_table_tw,key)
end
local key_table_tw = {}
for key, _ in pairs(tw_table) do table.insert(key_table_tw, key) end
local key_table_tvb = {}
for key,_ in pairs(tvb_table) do
table.insert(key_table_tvb,key)
end
local key_table_tvb = {}
for key, _ in pairs(tvb_table) do table.insert(key_table_tvb, key) end
table.sort(key_table)
table.sort(key_table)
table.sort(key_table_tw)
table.sort(key_table_tvb)
local route_name = {"youtube_server","tw_video_server","netflix_server","disney_server","prime_server","tvb_server","custom_server"}
local route_label = {"Youtube Proxy","TaiWan Video Proxy","Netflix Proxy","Diseny+ Proxy","Prime Video Proxy","TVB Video Proxy","Custom Proxy"}
local route_name = {
"youtube_server", "tw_video_server", "netflix_server", "disney_server",
"prime_server", "tvb_server", "custom_server"
}
local route_label = {
"Youtube Proxy", "TaiWan Video Proxy", "Netflix Proxy", "Diseny+ Proxy",
"Prime Video Proxy", "TVB Video Proxy", "Custom Proxy"
}
-- [[ Global Setting ]]--
s = m:section(TypedSection, "global",translate("Basic Settings [SS|SSR|V2ray|Trojan]"))
s = m:section(TypedSection, "global",
translate("Basic Settings [SS|SSR|V2ray|Trojan]"))
s.anonymous = true
o = s:option(ListValue, "global_server", translate("Main Server"))
o:value("nil", translate("Disable"))
for _,key in pairs(key_table) do o:value(key,server_table[key]) end
for _, key in pairs(key_table) do o:value(key, server_table[key]) end
o.default = "nil"
o.rmempty = false
o = s:option(ListValue, "udp_relay_server", translate("Game Mode UDP Server"))
o:value("", translate("Disable"))
o:value("same", translate("Same as Main Server"))
for _,key in pairs(key_table) do o:value(key,server_table[key]) end
for _, key in pairs(key_table) do o:value(key, server_table[key]) end
o = s:option(Flag, "v2ray_flow", translate("Open v2ray route"))
o.rmempty = false
o.description = translate("When open v2ray routed,Apply may take more time.")
for i,v in pairs(route_name) do
o = s:option(ListValue, v, translate(route_label[i]))
o:value("nil", translate("Same as Main Server"))
if(v == "tw_video_server") then
for _,key in pairs(key_table_tw) do o:value(key,tw_table[key]) end
elseif(v == "tvb_server") then
for _,key in pairs(key_table_tvb) do o:value(key,tvb_table[key]) end
for i, v in pairs(route_name) do
o = s:option(ListValue, v, translate(route_label[i]))
o:value("nil", translate("Same as Main Server"))
if (v == "tw_video_server") then
for _, key in pairs(key_table_tw) do o:value(key, tw_table[key]) end
elseif (v == "tvb_server") then
for _, key in pairs(key_table_tvb) do
o:value(key, tvb_table[key])
end
else
for _,key in pairs(key_table) do o:value(key,server_table[key]) end
for _, key in pairs(key_table) do o:value(key, server_table[key]) end
end
o:depends("v2ray_flow", "1")
o.default = "nil"
end
o:depends("v2ray_flow", "1")
o.default = "nil"
end
o = s:option(ListValue, "threads", translate("Multi Threads Option"))
o:value("0", translate("Auto Threads"))
@ -118,7 +125,7 @@ o.default = "router"
o = s:option(ListValue, "dports", translate("Proxy Ports"))
o:value("1", translate("All Ports"))
o:value("2", translate("Only Common Ports"))
o.default = 1
o.default = 1
o = s:option(ListValue, "pdnsd_enable", translate("Resolve Dns Mode"))
o:value("1", translate("Use Pdnsd tcp query and cache"))
@ -141,5 +148,5 @@ o:value("114.114.114.114:53", translate("Oversea Mode DNS-1 (114.114.114.114)"))
o:value("114.114.115.115:53", translate("Oversea Mode DNS-2 (114.114.115.115)"))
o:depends("pdnsd_enable", "1")
m:section(SimpleSection).template = "vssr/status_bottom"
m:section(SimpleSection).template = "vssr/status_bottom"
return m

View File

@ -9,37 +9,36 @@ s.anonymous = true
-- Part of WAN
s:tab("wan_ac", translate("WAN IP AC"))
o = s:taboption("wan_ac", DynamicList, "wan_bp_ips", translate("WAN White List IP"))
o = s:taboption("wan_ac", DynamicList, "wan_bp_ips",
translate("WAN White List IP"))
o.datatype = "ip4addr"
o = s:taboption("wan_ac", DynamicList, "wan_fw_ips", translate("WAN Force Proxy IP"))
o = s:taboption("wan_ac", DynamicList, "wan_fw_ips",
translate("WAN Force Proxy IP"))
o.datatype = "ip4addr"
-- Part of LAN
s:tab("lan_ac", translate("LAN IP AC"))
o = s:taboption("lan_ac", DynamicList, "lan_ac_ips", translate("LAN Bypassed Host List"))
o = s:taboption("lan_ac", DynamicList, "lan_ac_ips",
translate("LAN Bypassed Host List"))
o.datatype = "ipaddr"
luci.ip.neighbors({ family = 4 }, function(entry)
if entry.reachable then
o:value(entry.dest:string())
end
luci.ip.neighbors({family = 4}, function(entry)
if entry.reachable then o:value(entry.dest:string()) end
end)
o = s:taboption("lan_ac", DynamicList, "lan_fp_ips", translate("LAN Force Proxy Host List"))
o = s:taboption("lan_ac", DynamicList, "lan_fp_ips",
translate("LAN Force Proxy Host List"))
o.datatype = "ipaddr"
luci.ip.neighbors({ family = 4 }, function(entry)
if entry.reachable then
o:value(entry.dest:string())
end
luci.ip.neighbors({family = 4}, function(entry)
if entry.reachable then o:value(entry.dest:string()) end
end)
o = s:taboption("lan_ac", DynamicList, "lan_gm_ips", translate("Game Mode Host List"))
o = s:taboption("lan_ac", DynamicList, "lan_gm_ips",
translate("Game Mode Host List"))
o.datatype = "ipaddr"
luci.ip.neighbors({ family = 4 }, function(entry)
if entry.reachable then
o:value(entry.dest:string())
end
luci.ip.neighbors({family = 4}, function(entry)
if entry.reachable then o:value(entry.dest:string()) end
end)
-- Part of Self
@ -50,44 +49,36 @@ end)
-- o:value("2", translatef("Forwarded Proxy"))
-- o.rmempty = false
s:tab("esc", translate("Bypass Domain List"))
s:tab("esc", translate("Bypass Domain List"))
local escconf = "/etc/config/white.list"
o = s:taboption("esc", TextValue, "escconf")
o.rows = 13
o.wrap = "off"
o.rmempty = true
o.cfgvalue = function(self, section)
return NXFS.readfile(escconf) or ""
end
o.cfgvalue = function(self, section) return NXFS.readfile(escconf) or "" end
o.write = function(self, section, value)
NXFS.writefile(escconf, value:gsub("\r\n", "\n"))
end
o.remove = function(self, section, value)
NXFS.writefile(escconf, "")
NXFS.writefile(escconf, value:gsub("\r\n", "\n"))
end
o.remove = function(self, section, value) NXFS.writefile(escconf, "") end
s:tab("block", translate("Black Domain List"))
s:tab("block", translate("Black Domain List"))
local blockconf = "/etc/config/black.list"
o = s:taboption("block", TextValue, "blockconf")
o.rows = 13
o.wrap = "off"
o.rmempty = true
o.cfgvalue = function(self, section)
return NXFS.readfile(blockconf) or " "
end
o.cfgvalue = function(self, section) return NXFS.readfile(blockconf) or " " end
o.write = function(self, section, value)
NXFS.writefile(blockconf, value:gsub("\r\n", "\n"))
end
o.remove = function(self, section, value)
NXFS.writefile(blockconf, "")
NXFS.writefile(blockconf, value:gsub("\r\n", "\n"))
end
o.remove = function(self, section, value) NXFS.writefile(blockconf, "") end
s:tab("proxy", translate("Custom Proxy Domain Name"))
s:tab("proxy", translate("Custom Proxy Domain Name"))
o = s:taboption("proxy", DynamicList, "proxy_domain_name", translate("Proxy Domain Name"))
o = s:taboption("proxy", DynamicList, "proxy_domain_name",
translate("Proxy Domain Name"))
o.datatype = "hostname"
return m
return m

View File

@ -7,9 +7,10 @@ t = f:field(TextValue, "conf")
t.rmempty = true
t.rows = 20
function t.cfgvalue()
luci.sys.exec("[ -f /tmp/vssr.log ] && sed '1!G;h;$!d' /tmp/vssr.log > /tmp/ssrpro.log")
return fs.readfile(conffile) or ""
luci.sys.exec(
"[ -f /tmp/vssr.log ] && sed '1!G;h;$!d' /tmp/vssr.log > /tmp/ssrpro.log")
return fs.readfile(conffile) or ""
end
t.readonly="readonly"
t.readonly = "readonly"
return f
return f

View File

@ -1,60 +1,33 @@
-- Copyright (C) 2017 yushi studio <ywb94@qq.com>
-- Licensed to the public under the GNU General Public License v3.
local m, s, o
local vssr = "vssr"
local sid = arg[1]
local encrypt_methods = {
"rc4-md5",
"rc4-md5-6",
"rc4",
"table",
"aes-128-cfb",
"aes-192-cfb",
"aes-256-cfb",
"aes-128-ctr",
"aes-192-ctr",
"aes-256-ctr",
"bf-cfb",
"camellia-128-cfb",
"camellia-192-cfb",
"camellia-256-cfb",
"cast5-cfb",
"des-cfb",
"idea-cfb",
"rc2-cfb",
"seed-cfb",
"salsa20",
"chacha20",
"chacha20-ietf",
"rc4-md5", "rc4-md5-6", "rc4", "table", "aes-128-cfb", "aes-192-cfb",
"aes-256-cfb", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "bf-cfb",
"camellia-128-cfb", "camellia-192-cfb", "camellia-256-cfb", "cast5-cfb",
"des-cfb", "idea-cfb", "rc2-cfb", "seed-cfb", "salsa20", "chacha20",
"chacha20-ietf"
}
local protocol = {
"origin",
}
local protocol = {"origin"}
obfs = {
"plain",
"http_simple",
"http_post",
}
obfs = {"plain", "http_simple", "http_post"}
m = Map(vssr, translate("Edit vssr Server"))
m.redirect = luci.dispatcher.build_url("admin/services/vssr/server")
if m.uci:get(vssr, sid) ~= "server_config" then
luci.http.redirect(m.redirect)
return
luci.http.redirect(m.redirect)
return
end
-- [[ Server Setting ]]--
s = m:section(NamedSection, sid, "server_config")
s.anonymous = true
s.addremove = false
s.addremove = false
o = s:option(Flag, "enable", translate("Enable"))
o.default = 1
@ -82,7 +55,6 @@ o = s:option(ListValue, "protocol", translate("Protocol"))
for _, v in ipairs(protocol) do o:value(v) end
o.rmempty = false
o = s:option(ListValue, "obfs", translate("Obfs"))
for _, v in ipairs(obfs) do o:value(v) end
o.rmempty = false

View File

@ -1,67 +1,34 @@
-- Copyright (C) 2017 yushi studio <ywb94@qq.com>
-- Licensed to the public under the GNU General Public License v3.
local m, sec, o
local vssr = "vssr"
local uci = luci.model.uci.cursor()
local ipkg = require("luci.model.ipkg")
m = Map(vssr, translate("vssr Server"))
local encrypt_methods = {
"table",
"rc4",
"rc4-md5",
"rc4-md5-6",
"aes-128-cfb",
"aes-192-cfb",
"aes-256-cfb",
"aes-128-ctr",
"aes-192-ctr",
"aes-256-ctr",
"bf-cfb",
"camellia-128-cfb",
"camellia-192-cfb",
"camellia-256-cfb",
"cast5-cfb",
"des-cfb",
"idea-cfb",
"rc2-cfb",
"seed-cfb",
"salsa20",
"chacha20",
"chacha20-ietf",
"table", "rc4", "rc4-md5", "rc4-md5-6", "aes-128-cfb", "aes-192-cfb",
"aes-256-cfb", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "bf-cfb",
"camellia-128-cfb", "camellia-192-cfb", "camellia-256-cfb", "cast5-cfb",
"des-cfb", "idea-cfb", "rc2-cfb", "seed-cfb", "salsa20", "chacha20",
"chacha20-ietf"
}
local protocol = {
"origin",
"verify_deflate",
"auth_sha1_v4",
"auth_aes128_sha1",
"auth_aes128_md5",
"auth_chain_a",
"origin", "verify_deflate", "auth_sha1_v4", "auth_aes128_sha1",
"auth_aes128_md5", "auth_chain_a"
}
obfs = {
"plain",
"http_simple",
"http_post",
"random_head",
"tls1.2_ticket_auth",
"tls1.2_ticket_fastauth",
"plain", "http_simple", "http_post", "random_head", "tls1.2_ticket_auth",
"tls1.2_ticket_fastauth"
}
-- [[ Global Setting ]]--
sec = m:section(TypedSection, "server_global", translate("Global Setting"))
sec.anonymous = true
o = sec:option(Flag, "enable_server", translate("Enable Server"))
o.rmempty = false
@ -72,43 +39,30 @@ sec.addremove = true
sec.template = "cbi/tblsection"
sec.extedit = luci.dispatcher.build_url("admin/services/vssr/server/%s")
function sec.create(...)
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(sec.extedit % sid)
return
end
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(sec.extedit % sid)
return
end
end
o = sec:option(Flag, "enable", translate("Enable"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("0")
end
function o.cfgvalue(...) return Value.cfgvalue(...) or translate("0") end
o.rmempty = false
o = sec:option(DummyValue, "server_port", translate("Server Port"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
function o.cfgvalue(...) return Value.cfgvalue(...) or "?" end
o = sec:option(DummyValue, "encrypt_method", translate("Encrypt Method"))
function o.cfgvalue(...)
local v = Value.cfgvalue(...)
return v and v:upper() or "?"
local v = Value.cfgvalue(...)
return v and v:upper() or "?"
end
o = sec:option(DummyValue, "protocol", translate("Protocol"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
function o.cfgvalue(...) return Value.cfgvalue(...) or "?" end
o = sec:option(DummyValue, "obfs", translate("Obfs"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
function o.cfgvalue(...) return Value.cfgvalue(...) or "?" end
return m

View File

@ -2,39 +2,36 @@ local vssr = "vssr"
local uci = luci.model.uci.cursor()
local server_table = {}
local sys = require "luci.sys"
m = Map(vssr)
-- [[ SOCKS5 Proxy ]]--
if nixio.fs.access("/usr/bin/v2ray/v2ray") then
s = m:section(TypedSection, "socks5_proxy", translate("V2ray SOCKS5 Proxy"))
s.anonymous = true
s = m:section(TypedSection, "socks5_proxy", translate("V2ray SOCKS5 Proxy"))
s.anonymous = true
o = s:option(Flag, "enable_server", translate("Enable Servers"))
o.rmempty = false
o = s:option(Flag, "enable_server", translate("Enable Servers"))
o.rmempty = false
o = s:option(Flag, "enable_auth", translate("Enable Auth"))
o.rmempty = false
o = s:option(Flag, "enable_auth", translate("Enable Auth"))
o.rmempty = false
o = s:option(Value, "Socks_user", translate("Socks user"))
o.default="user"
o.rmempty = true
o:depends("enable_auth", "1")
o = s:option(Value, "Socks_pass", translate("Socks pass"))
o.default="password"
o.password = true
o.rmempty = true
o:depends("enable_auth", "1")
o = s:option(Value, "local_port", translate("Local Port"))
o.datatype = "port"
o.default = 1080
o.rmempty = false
o = s:option(Value, "Socks_user", translate("Socks user"))
o.default = "user"
o.rmempty = true
o:depends("enable_auth", "1")
o = s:option(Value, "Socks_pass", translate("Socks pass"))
o.default = "password"
o.password = true
o.rmempty = true
o:depends("enable_auth", "1")
o = s:option(Value, "local_port", translate("Local Port"))
o.datatype = "port"
o.default = 1080
o.rmempty = false
end

View File

@ -11,11 +11,12 @@
<a href="https://www.maxmind.com">https://www.maxmind.com</a>.</p>
<h4 id="vssr_status"><span class="green" style="color: #404040;">Flag-icon-css</span></h4>
<p style="margin: 1rem; line-height: 1.8em;">A collection of all country flags in SVG — plus the CSS for easier integration <a href="https://flagicons.lipis.dev">https://flagicons.lipis.dev</a></p>
<p style="margin: 1rem; line-height: 1.8em;">A collection of all country flags in SVG — plus the CSS for
easier integration <a href="https://flagicons.lipis.dev">https://flagicons.lipis.dev</a></p>
</div>
</div>
</div>
</div>
<%+footer%>
<%+footer%>

View File

@ -2,34 +2,34 @@
<script type="text/javascript">//<![CDATA[
function refresh_data(btn, dataname) {
btn.disabled = true;
btn.value = '<%:Refresh...%> ';
murl = dataname;
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "vssr","refresh")%>',
{ set: murl },
function (x, rv) {
var s = document.getElementById(dataname + '-status');
if (s) {
if (rv.ret == "0")
s.innerHTML = "<font color='green'>" + "<%:No new data!%> " + "</font>";
else if (rv.ret == "-1") {
s.innerHTML = "<font color='red'>" + "<%:Refresh Error!%> " + "</font>";
}
else {
s.innerHTML = "<font color='green'>" + "<%:Refresh OK!%> " + "<%:Total Records:%>" + rv.ret + "</font>";
}
}
btn.disabled = false;
btn.value = '<%:Refresh Data %>';
}
);
return false;
}
function refresh_data(btn, dataname) {
btn.disabled = true;
btn.value = '<%:Refresh...%> ';
murl = dataname;
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "vssr","refresh")%>',
{ set: murl },
function (x, rv) {
var s = document.getElementById(dataname + '-status');
if (s) {
if (rv.ret == "0")
s.innerHTML = "<font color='green'>" + "<%:No new data!%> " + "</font>";
else if (rv.ret == "-1") {
s.innerHTML = "<font color='red'>" + "<%:Refresh Error!%> " + "</font>";
}
else {
s.innerHTML = "<font color='green'>" + "<%:Refresh OK!%> " + "<%:Total Records:%>" + rv.ret + "</font>";
}
}
btn.disabled = false;
btn.value = '<%:Refresh Data %>';
}
);
return false;
}
//]]></script>
<input type="button" class="cbi-button cbi-input-reload" value="<%:Refresh Data%> "
onclick="return refresh_data(this,'<%=self.option%>')" />
onclick="return refresh_data(this,'<%=self.option%>')" />
<span id="<%=self.option%>-status"><em><%=self.value%></em></span>
<%+cbi/valuefooter%>
<%+cbi/valuefooter%>

View File

@ -52,7 +52,7 @@
str = padright(str, l, "=");
try {
return atob(str);
}catch(err) {
} catch (err) {
return str;
}
}
@ -131,59 +131,59 @@
return false;
} else if (ssu[0] == "ss") {
var url0, param = "";
var sipIndex = ssu[1].indexOf("@");
var ploc = ssu[1].indexOf("#");
if (ploc > 0) {
url0 = ssu[1].substr(0, ploc);
param = ssu[1].substr(ploc + 1);
} else {
url0 = ssu[1];
}
var sipIndex = ssu[1].indexOf("@");
var ploc = ssu[1].indexOf("#");
if (ploc > 0) {
url0 = ssu[1].substr(0, ploc);
param = ssu[1].substr(ploc + 1);
} else {
url0 = ssu[1];
}
if (sipIndex != -1) {
// SIP002
var userInfo = b64decsafe(url0.substr(0, sipIndex));
var temp = url0.substr(sipIndex + 1).split("/?");
var serverInfo = temp[0].split(":");
var server = serverInfo[0];
var port = serverInfo[1];
var method, password, plugin, pluginOpts;
if (temp[1]) {
var pluginInfo = decodeURIComponent(temp[1]);
var pluginIndex = pluginInfo.indexOf(";");
var pluginNameInfo = pluginInfo.substr(0, pluginIndex);
plugin = pluginNameInfo.substr(pluginNameInfo.indexOf("=") + 1)
pluginOpts = pluginInfo.substr(pluginIndex + 1);
}
if (sipIndex != -1) {
// SIP002
var userInfo = b64decsafe(url0.substr(0, sipIndex));
var temp = url0.substr(sipIndex + 1).split("/?");
var serverInfo = temp[0].split(":");
var server = serverInfo[0];
var port = serverInfo[1];
var method, password, plugin, pluginOpts;
if (temp[1]) {
var pluginInfo = decodeURIComponent(temp[1]);
var pluginIndex = pluginInfo.indexOf(";");
var pluginNameInfo = pluginInfo.substr(0, pluginIndex);
plugin = pluginNameInfo.substr(pluginNameInfo.indexOf("=") + 1)
pluginOpts = pluginInfo.substr(pluginIndex + 1);
}
var userInfoSplitIndex = userInfo.indexOf(":");
if (userInfoSplitIndex != -1) {
method = userInfo.substr(0, userInfoSplitIndex);
password = userInfo.substr(userInfoSplitIndex + 1);
}
el('.type').value = "ss";
el('.type').dispatchEvent(event);
el('.server').value = server;
el('.server_port').value = port;
el('.password').value = password || "";
el('.encrypt_method_ss').value = method || "";
el('.plugin').value = plugin || "";
el('.plugin_opts').value = pluginOpts || "";
} else {
var sstr = b64decsafe(url0);
el('.type').value = "ss";
el('.type').dispatchEvent(event);
var team = sstr.split('@');
console.log(param);
var part1 = team[0].split(':');
var part2 = team[1].split(':');
el('.server').value = part2[0];
el('.server_port').value = part2[1];
el('.password').value = part1[1];
el('.encrypt_method_ss').value = part1[0];
el('.plugin').value = "";
el('.plugin_opts').value = "";
}
var userInfoSplitIndex = userInfo.indexOf(":");
if (userInfoSplitIndex != -1) {
method = userInfo.substr(0, userInfoSplitIndex);
password = userInfo.substr(userInfoSplitIndex + 1);
}
el('.type').value = "ss";
el('.type').dispatchEvent(event);
el('.server').value = server;
el('.server_port').value = port;
el('.password').value = password || "";
el('.encrypt_method_ss').value = method || "";
el('.plugin').value = plugin || "";
el('.plugin_opts').value = pluginOpts || "";
} else {
var sstr = b64decsafe(url0);
el('.type').value = "ss";
el('.type').dispatchEvent(event);
var team = sstr.split('@');
console.log(param);
var part1 = team[0].split(':');
var part2 = team[1].split(':');
el('.server').value = part2[0];
el('.server_port').value = part2[1];
el('.password').value = part1[1];
el('.encrypt_method_ss').value = part1[0];
el('.plugin').value = "";
el('.plugin_opts').value = "";
}
if (param != undefined) {
rema = decodeURI(param)
@ -209,22 +209,22 @@
var part2 = team[1].split(':');
var others = part2[1].split('?');
var queryParam = {}
if(others.length > 1) {
var queryParams = others[1]
var queryArray = queryParams.split('&')
for (i = 0; i < queryArray.length; i++) {
var params = queryArray[i].split('=');
queryParam[decodeURIComponent(params[0])] = decodeURIComponent(params[1] || '');
}
}
if (others.length > 1) {
var queryParams = others[1]
var queryArray = queryParams.split('&')
for (i = 0; i < queryArray.length; i++) {
var params = queryArray[i].split('=');
queryParam[decodeURIComponent(params[0])] = decodeURIComponent(params[1] || '');
}
}
el('.server').value = part2[0];
el('.server_port').value = others[0];
el('.password').value = part1[1];
if(queryParam.peer || queryParam.sni){
if (queryParam.peer || queryParam.sni) {
el('.tls').checked = true;
el('.peer').value = queryParam.peer || queryParam.sni;
}
if (param != undefined) {
rema = decodeURI(param)
el('.alias').value = decodeURI(param);
@ -305,4 +305,4 @@
onclick="return import_ssr_url(this, '<%=self.option%>', '<%=self.value%>')" />
<span id="<%=self.option%>-status"></span>
<%+cbi/valuefooter%>
<%+cbi/valuefooter%>

View File

@ -20,7 +20,7 @@
<script>
var wW = $(window).width();
function resize() {
@ -40,7 +40,6 @@
}
function wirte_status(data) {
if (data.outboard) {
json = data.outboardip;
country = (json.flag == "tw") ? "中国 台湾" : json.country;
@ -51,8 +50,7 @@
data.taobao ? $(".i2").attr("src", VSSR_ASSETS + "img/site_icon_02.png") : $(".i2").attr("src", VSSR_ASSETS + "img/site_icon1_02.png");
data.google ? $(".i3").attr("src", VSSR_ASSETS + "img/site_icon_03.png") : $(".i3").attr("src", VSSR_ASSETS + "img/site_icon1_03.png");
data.youtube ? $(".i4").attr("src", VSSR_ASSETS + "img/site_icon_04.png") : $(".i4").attr("src", VSSR_ASSETS + "img/site_icon1_04.png");
setTimeout(function () { $( "body").trigger( "iploaded", [ true ] ); }, 200);
setTimeout(function () { $("body").trigger("iploaded", [true]); }, 200);
}
XHR.poll(10, CHECK_IP_URL, null,
function (x, data) {
@ -67,4 +65,4 @@
$(window).resize(resize);
</script>
</script>

View File

@ -1,4 +1,4 @@
<link rel="stylesheet" href="/luci-static/vssr/css/vssr.css?v=202000825-1">
<link rel="stylesheet" href="/luci-static/vssr/css/vssr.css?v=<%=math.random(1,100000)%>">
<script src="<%=media%>/js/jquery.min.js"></script>
@ -90,4 +90,4 @@
);
//]]>
</script>
</script>

View File

@ -1,6 +1,6 @@
<script type="text/javascript" src="/luci-static/vssr/emoji.js"></script>
<script type="text/javascript" src="/luci-static/vssr/sweetalert.js"></script>
<script type="text/javascript" src="/luci-static/vssr/polyfill.js"></script>
<script type="text/javascript" src="/luci-static/vssr/emoji.js?v=1.16"></script>
<script type="text/javascript" src="/luci-static/vssr/sweetalert.js?v=1.16"></script>
<script type="text/javascript" src="/luci-static/vssr/polyfill.js?v=1.16"></script>
<!-- tblsection -->
<fieldset class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
@ -97,7 +97,7 @@
var iploaded = false;
var ajaxArray = new Array();
var currentCheckCount = 0;
//渲染节点列表
$.each(servers, function (i, val) {
@ -106,7 +106,7 @@
$(id).addClass("fast");
}
val.flag = (val.flag == undefined) ? "un" : val.flag;
$(id).attr("data-flag",val.flag);
$(id).attr("data-flag", val.flag);
$(id).find(".type .tp").text(val.type);
$(id).find(".type").addClass("flag-icon-" + val.flag);
$(id).find(".alias").text(val.alias);
@ -122,98 +122,83 @@
//转换节点名称的Emoji显示
$(".alias").emoji();
//适配方框的大小
$(".flag-icon").each(function (index, el) {
if ($(el).height < 60) {
$(el).parent.height(60);
$(el).width(60)
} else {
$(el).width($(el).height());
}
});
if ($(el).height < 60) {
$(el).parent.height(60);
$(el).width(60)
} else {
$(el).width($(el).height());
}
});
//切换节点
function apply_node(node) {
//$("#cbi-apply-vssr1").show(); //显示应用中
var $html = "";
$html +='<div class="pure-g choose_node">';
$html +='<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="global" data-node="'+node+'"> 主服务器 </button></div></div>';
$html +='<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="youtube" data-node="'+node+'"> Youtube </button></div></div>';
if($('#cbi-' + CONFIG + '-' +node).attr("data-flag") == "tw"){
$html +='<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="tw_video" data-node="'+node+'"> TW Video </button></div></div>';
$html += '<div class="pure-g choose_node">';
$html += '<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="global" data-node="' + node + '"> 主服务器 </button></div></div>';
$html += '<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="udp_relay" data-node="' + node + '"> UDP游戏模式 </button></div></div>';
$html += '<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="youtube" data-node="' + node + '"> Youtube </button></div></div>';
if ($('#cbi-' + CONFIG + '-' + node).attr("data-flag") == "tw") {
$html += '<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="tw_video" data-node="' + node + '"> TW Video </button></div></div>';
}
$html +='<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="netflix" data-node="'+node+'"> Netflix </button></div></div>';
$html +='<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="disney" data-node="'+node+'"> Diseny+ </button></div></div>';
$html +='<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="prime" data-node="'+node+'"> Prime Video </button></div></div>';
if($('#cbi-' + CONFIG + '-' +node).attr("data-flag") =="hk"){
$html +='<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="tvb" data-node="'+node+'"> TVB Video </button></div></div>';
$html += '<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="netflix" data-node="' + node + '"> Netflix </button></div></div>';
$html += '<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="disney" data-node="' + node + '"> Diseny+ </button></div></div>';
$html += '<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="prime" data-node="' + node + '"> Prime Video </button></div></div>';
if ($('#cbi-' + CONFIG + '-' + node).attr("data-flag") == "hk") {
$html += '<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="tvb" data-node="' + node + '"> TVB Video </button></div></div>';
}
$html +='<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="custom" data-node="'+node+'"> 自定义 </button></div></div>';
$html +='</div>';
$html += '<div class="pure-u-1-2"><div class="gap"><button class="cbi-button cbi-button-apply change-node" data-server="custom" data-node="' + node + '"> 自定义 </button></div></div>';
$html += '</div>';
Swal.fire({
title: '请选择应用于',
html:$html,
focusConfirm: false,
confirmButtonText:'关闭',
onRender: (toast) => {
$(".change-node").click(function(){
var dataServer = $(this).attr("data-server");
XHR.halt();
$.each(ajaxArray, function (n, value) { value.abort(); }) //中断所有的ajax请求
Swal.fire({
title: '正在应用中',
allowOutsideClick:false,
onBeforeOpen: () => {
Swal.showLoading()
}
})
$.get(CHANGE_NODE_URL, { set: node,server:dataServer },
function (data, status) {
$("#cbi-apply-vssr1").hide(); //隐藏应用中
if (data.status) {
var id = '#cbi-<%=self.config%>-' + node;
if(dataServer == "global"){
$(".cbi-section-table-row").removeClass("fast");
$(id).addClass("fast");
title: '请选择应用于',
html: $html,
focusConfirm: false,
confirmButtonText: '关闭',
onRender: (toast) => {
$(".change-node").click(function () {
var dataServer = $(this).attr("data-server");
XHR.halt();
$.each(ajaxArray, function (n, value) { value.abort(); }) //中断所有的ajax请求
Swal.fire({
title: '正在应用中',
allowOutsideClick: false,
onBeforeOpen: () => {
Swal.showLoading()
}
Swal.close();
XHR.run();
}
});
})
}
})
$.get(CHANGE_NODE_URL, { set: node, server: dataServer },
function (data, status) {
$("#cbi-apply-vssr1").hide(); //隐藏应用中
if (data.status) {
var id = '#cbi-<%=self.config%>-' + node;
if (dataServer == "global") {
$(".cbi-section-table-row").removeClass("fast");
$(id).addClass("fast");
}
Swal.close();
XHR.run();
}
});
})
}
})
/*$.get(CHANGE_NODE_URL, { set: node },
function (data, status) {
$("#cbi-apply-vssr1").hide(); //隐藏应用中
if (data.status) {
var id = '#cbi-<%=self.config%>-' + node;
$(".cbi-section-table-row").removeClass("fast");
$(id).addClass("fast");
}
});*/
}
//设定自动切换
//设定自动切换
$(".incon").click(function () {
$.each(ajaxArray, function (n, value) { value.abort(); }) //中断所有的ajax请求
$node_switch_icon = $(this).find(".pure-imgw");
$node_target = $(this).attr("data-setction");
$.post(SWITCH_NODE_URL, { node: $node_target }, function (data) {
if(data.status){
if(data.switch){
if (data.status) {
if (data.switch) {
$node_switch_icon.removeClass("hidden");
}else{
} else {
$node_switch_icon.addClass("hidden");
}
}else{
} else {
alert("请求出错!")
}
}, "json");
@ -230,10 +215,9 @@
host = $(this).find(".cbi-section-table-row ").attr("server");
port = $(this).find(".cbi-section-table-row ").attr("server_port");
$(".host_con").text("");
if(host != undefined){
if (host != undefined) {
check_port(host, port, this);
}
});
}
@ -242,7 +226,7 @@
$.ajaxSettings.async = true;
var axhr = $.get(CHECK_PING_URL, { host: hosts, port: ports },
function (data, status) {
currentCheckCount ++
currentCheckCount++
var host_con = $(target).find(".host_con");
host_con.removeClass("fast");
host_con.removeClass("middle");
@ -266,8 +250,8 @@
host_con.addClass("nopass");
host_con.text("Error");
}
if(currentCheckCount == ajaxArray.length){
if (currentCheckCount == ajaxArray.length) {
XHR.run();
}
});
@ -275,15 +259,13 @@
}
$(document).ready(function () {
//setTimeout(function () { check(); }, 500); //延迟500MS开始检测
$( "body" ).on( "iploaded", function( event, param1 ) {
if(!iploaded){
$("body").on("iploaded", function (event, param1) {
if (!iploaded) {
iploaded = true;
check();
}
});
$(".cbi-page-actions").hide(); //隐藏底部保存提交按钮
$(".cbi-button-check").click(function () {
check();
@ -291,4 +273,4 @@
});
});
</script>
</script>

View File

@ -1,108 +1,108 @@
<%+cbi/valueheader%>
<link rel="stylesheet" href="/luci-static/vssr/css/vssr.css?v=72883">
<link rel="stylesheet" href="/luci-static/vssr/css/vssr.css?v=<%=math.random(1,100000)%>">
<label class="cbi-value-title"><%= translate("Update") %></label>
<div class="cbi-value-field">
<input class="cbi-button cbi-button-reload" id="update_subscribe" type="button"
size="0" value="<%= translate("Save And Start Subscribe") %>">
<input class="cbi-button cbi-button-reload" id="update_subscribe" type="button" size="0"
value="<%= translate("Save And Start Subscribe") %>">
</div>
<script type="text/javascript">
const SAVE_SUBSCRIBE_URL = '<%=luci.dispatcher.build_url("admin", "services", "vssr","subscribe")%>';
const SERVERS_URL = '<%=luci.dispatcher.build_url("admin", "services", "vssr","servers")%>';
const SAVE_SUBSCRIBE_URL = '<%=luci.dispatcher.build_url("admin", "services", "vssr","subscribe")%>';
const SERVERS_URL = '<%=luci.dispatcher.build_url("admin", "services", "vssr","servers")%>';
var _responseLen;
var noChange = 0;
var modal = '<div class="modals-bg">' +
'<div class="modals">' +
'<h2><%:Subscription%></h2>' +
'<h3 style="margin-left:0;"><%:Subscribing,Please do not refresh!%></h3>' +
'<textarea cols="63" rows="28" wrap="on" readonly="readonly" id="log_content3" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>' +
'</div>' +
'</div>';
var _responseLen;
var noChange = 0;
var modal = '<div class="modals-bg">' +
'<div class="modals">' +
'<h2><%:Subscription%></h2>' +
'<h3 style="margin-left:0;"><%:Subscribing,Please do not refresh!%></h3>' +
'<textarea cols="63" rows="28" wrap="on" readonly="readonly" id="log_content3" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>' +
'</div>' +
'</div>';
//显示并开始刷新订阅
function update_subscribe() {
$("body").append(modal);
$(".modals-bg").show();
setTimeout("get_realtime_log();", 500);
}
//保存订阅按钮
$("#update_subscribe").click(function () {
prefix_array = $("#cbi-vssr-server_subscribe .cbi-section-node").attr("id").split("-");
prefix_array[0] = "cbid";
prefix = prefix_array.join(".");
if ($("[name='" + prefix + ".auto_update']").is(":checked")) {
var auto_update = "1";
} else {
var auto_update = "0";
}
var auto_update_time = $("[name='" + prefix + ".auto_update_time']").val();
var subscribe_url = [];
$("[name='" + prefix + ".subscribe_url']").each(function () {
if ($(this).val() != "") {
subscribe_url.push($(this).val());
}
});
if ($("[name='" + prefix + ".proxy']").is(":checked")) {
var proxy = "1";
} else {
var proxy = "0";
}
//显示并开始刷新订阅
function update_subscribe() {
$("body").append(modal);
$(".modals-bg").show();
setTimeout("get_realtime_log();", 500);
}
//保存订阅按钮
$("#update_subscribe").click(function () {
prefix_array = $("#cbi-vssr-server_subscribe .cbi-section-node").attr("id").split("-");
prefix_array[0] = "cbid";
prefix = prefix_array.join(".");
if ($("[name='" + prefix + ".auto_update']").is(":checked")) {
var auto_update = "1";
} else {
var auto_update = "0";
}
var auto_update_time = $("[name='" + prefix + ".auto_update_time']").val();
var subscribe_url = [];
$("[name='" + prefix + ".subscribe_url']").each(function () {
if ($(this).val() != "") {
subscribe_url.push($(this).val());
}
});
if ($("[name='" + prefix + ".proxy']").is(":checked")) {
var proxy = "1";
} else {
var proxy = "0";
}
var data = {
auto_update: auto_update,
auto_update_time: auto_update_time,
subscribe_url: JSON.stringify(subscribe_url),
proxy: proxy
}
//console.log(data);
$.ajax({
type: "post",
url: SAVE_SUBSCRIBE_URL,
dataType: "json",
data: data,
success: function (d) {
if (d.error == 0) {
update_subscribe();
} else {
alert("请至少填写一个订阅链接");
}
}
});
return false;
});
var data = {
auto_update: auto_update,
auto_update_time: auto_update_time,
subscribe_url: JSON.stringify(subscribe_url),
proxy: proxy
}
//console.log(data);
$.ajax({
type: "post",
url: SAVE_SUBSCRIBE_URL,
dataType: "json",
data: data,
success: function (d) {
if (d.error == 0) {
update_subscribe();
} else {
alert("请至少填写一个订阅链接");
}
}
});
return false;
});
function get_realtime_log() {
$.ajax({
url: '/check_update.htm?v=' + parseInt(Math.random() * 100000000),
dataType: 'html',
error: function (xhr) {
setTimeout("get_realtime_log();", 1000);
},
success: function (response) {
var retArea = document.getElementById("log_content3");
if (response.search("END SUBSCRIBE") != -1) {
noChange++;
}
console.log(noChange);
if (noChange > 10) {
window.location.href = SERVERS_URL;
return false;
} else {
setTimeout("get_realtime_log();", 250);
}
retArea.value = response;
retArea.scrollTop = retArea.scrollHeight;
_responseLen = response.length;
},
error: function () {
setTimeout("get_realtime_log();", 500);
}
});
}
function get_realtime_log() {
$.ajax({
url: '/check_update.htm?v=' + parseInt(Math.random() * 100000000),
dataType: 'html',
error: function (xhr) {
setTimeout("get_realtime_log();", 1000);
},
success: function (response) {
var retArea = document.getElementById("log_content3");
if (response.search("END SUBSCRIBE") != -1) {
noChange++;
}
console.log(noChange);
if (noChange > 10) {
window.location.href = SERVERS_URL;
return false;
} else {
setTimeout("get_realtime_log();", 250);
}
retArea.value = response;
retArea.scrollTop = retArea.scrollHeight;
_responseLen = response.length;
},
error: function () {
setTimeout("get_realtime_log();", 500);
}
});
}
</script>
<%+cbi/valuefooter%>
<%+cbi/valuefooter%>

View File

@ -479,8 +479,8 @@ msgstr "游戏模式UDP中继"
msgid "Server failsafe auto swith settings"
msgstr "服务器节点故障自动切换设置"
msgid "Delete all severs"
msgstr "删除所有服务器"
msgid "Delete All Subscribe Severs"
msgstr "删除所有订阅服务器"
msgid "Severs Nodes"
msgstr "节点列表"

View File

@ -39,192 +39,192 @@ shunt_port=(2080 2081 2082 2083 2084 2085 2086 2087)
shunt_array=("youtube" "tw_video" "netflix" "disney" "prime" "tvb" "custom")
scount=0
uci_get_by_name() {
local ret=$(uci get $NAME.$1.$2 2>/dev/null)
echo ${ret:=$3}
local ret=$(uci get $NAME.$1.$2 2>/dev/null)
echo ${ret:=$3}
}
uci_get_by_type() {
local ret=$(uci get $NAME.@$1[0].$2 2>/dev/null)
echo ${ret:=$3}
local ret=$(uci get $NAME.@$1[0].$2 2>/dev/null)
echo ${ret:=$3}
}
add_cron() {
sed -i '/vssr.log/d' $CRON_FILE && echo '0 1 * * * echo "" > /tmp/vssr.log' >>$CRON_FILE
[ $(uci_get_by_type server_subscribe auto_update 0) -eq 1 ] && echo "0 $(uci_get_by_type server_subscribe auto_update_time) * * * /usr/bin/lua /usr/share/vssr/subscribe.lua" >>$CRON_FILE
[ $(uci_get_by_type server_subscribe auto_update 0) -eq 1 ] && echo "0 $(uci_get_by_type server_subscribe auto_update_time) * * * /usr/bin/lua /usr/share/vssr/update.lua" >>$CRON_FILE
crontab $CRON_FILE
sed -i '/vssr.log/d' $CRON_FILE && echo '0 1 * * * echo "" > /tmp/vssr.log' >>$CRON_FILE
[ $(uci_get_by_type server_subscribe auto_update 0) -eq 1 ] && echo "0 $(uci_get_by_type server_subscribe auto_update_time) * * * /usr/bin/lua /usr/share/vssr/subscribe.lua" >>$CRON_FILE
[ $(uci_get_by_type server_subscribe auto_update 0) -eq 1 ] && echo "0 $(uci_get_by_type server_subscribe auto_update_time) * * * /usr/bin/lua /usr/share/vssr/update.lua" >>$CRON_FILE
crontab $CRON_FILE
}
del_cron() {
sed -i '/vssr/d' $CRON_FILE
sed -i '/vssr.log/d' $CRON_FILE
/etc/init.d/cron restart
sed -i '/vssr/d' $CRON_FILE
sed -i '/vssr.log/d' $CRON_FILE
/etc/init.d/cron restart
}
count_shunt() {
scount=0
for ((i = 0; i < ${#shunt_array[@]}; i++)); do
local server_index=$(uci_get_by_type global ${shunt_array[i]}_server)
local server_type=$(uci_get_by_name $server_index type)
if [ "$server_type" != "" ]; then
scount=$(($scount + 1))
fi
done
scount=0
for ((i = 0; i < ${#shunt_array[@]}; i++)); do
local server_index=$(uci_get_by_type global ${shunt_array[i]}_server)
local server_type=$(uci_get_by_name $server_index type)
if [ "$server_type" != "" ]; then
scount=$(($scount + 1))
fi
done
}
count_shunt
run_mode=$(uci_get_by_type global run_mode)
gen_config_file() {
local hostip=$(uci_get_by_name $1 server)
local hostip=$(uci_get_by_name $1 server)
[ $2 = "0" -a $kcp_flag = "1" ] && hostip="127.0.0.1"
[ $2 = "0" -a $kcp_flag = "1" ] && hostip="127.0.0.1"
if [ $2 = "0" ]; then
re_type="tcp"
config_file=$CONFIG_FILE
server_obj=$GLOBAL_SERVER
elif [ $2 = "1" ]; then
re_type="udp"
config_file=$CONFIG_UDP_FILE
server_obj=$UDP_RELAY_SERVER
fi
if [ $(uci_get_by_name $1 fast_open 0) = "1" ]; then
fastopen="true"
else
fastopen="false"
fi
if [ $2 = "0" ]; then
re_type="tcp"
config_file=$CONFIG_FILE
server_obj=$GLOBAL_SERVER
elif [ $2 = "1" ]; then
re_type="udp"
config_file=$CONFIG_UDP_FILE
server_obj=$UDP_RELAY_SERVER
fi
if [ $(uci_get_by_name $1 fast_open 0) = "1" ]; then
fastopen="true"
else
fastopen="false"
fi
local stype=$(uci_get_by_name $1 type)
local port=$(uci_get_by_name $1 local_port)
if [ "$stype" == "trojan" ]; then
if [ "$re_type" == "udp" ]; then
re_type="client"
port="10801"
else
re_type="nat"
fi
fi
local mport=0
if [ $3 = "1" ]; then
stype="v2ray"
mport=1090
re_type="tcp"
fi
lua /usr/share/vssr/genconfig_${stype}.lua ${server_obj} ${re_type} ${port} ${hostip} ${mport} >${config_file}
sed -i 's/\\//g' $config_file
local stype=$(uci_get_by_name $1 type)
local port=$(uci_get_by_name $1 local_port)
if [ "$stype" == "trojan" ]; then
if [ "$re_type" == "udp" ]; then
re_type="client"
port="10801"
else
re_type="nat"
fi
fi
local mport=0
if [ $3 = "1" ]; then
stype="v2ray"
mport=1090
re_type="tcp"
fi
lua /usr/share/vssr/genconfig_${stype}.lua ${server_obj} ${re_type} ${port} ${hostip} ${mport} >${config_file}
sed -i 's/\\//g' $config_file
}
get_arg_out() {
case "$(uci_get_by_type access_control router_proxy 1)" in
1) echo "-o" ;;
2) echo "-O" ;;
esac
case "$(uci_get_by_type access_control router_proxy 1)" in
1) echo "-o" ;;
2) echo "-O" ;;
esac
}
start_rules() {
local server=$(uci_get_by_name $GLOBAL_SERVER server)
#resolve name
if echo $server | grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
server=${server}
elif [ "$server" != "${server#*:[0-9a-fA-F]}" ]; then
server=${server}
else
server=$(ping ${server} -s 1 -c 1 | grep PING | cut -d'(' -f 2 | cut -d')' -f1)
if echo $server | grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
echo $server >/etc/ssr_ip
else
server=$(cat /etc/ssr_ip)
fi
fi
local server=$(uci_get_by_name $GLOBAL_SERVER server)
#resolve name
if echo $server | grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
server=${server}
elif [ "$server" != "${server#*:[0-9a-fA-F]}" ]; then
server=${server}
else
server=$(ping ${server} -s 1 -c 1 | grep PING | cut -d'(' -f 2 | cut -d')' -f1)
if echo $server | grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
echo $server >/etc/ssr_ip
else
server=$(cat /etc/ssr_ip)
fi
fi
kcp_server=$server
kcp_server=$server
local kcp_enable=$(uci_get_by_name $GLOBAL_SERVER kcp_enable 0)
if [ $kcp_enable = "1" ]; then
kcp_flag=1
fi
local kcp_enable=$(uci_get_by_name $GLOBAL_SERVER kcp_enable 0)
if [ $kcp_enable = "1" ]; then
kcp_flag=1
fi
local local_port=$(uci_get_by_name $GLOBAL_SERVER local_port)
local lan_ac_ips=$(uci_get_by_type access_control lan_ac_ips)
local lan_ac_mode="b"
local router_proxy=$(uci_get_by_type access_control router_proxy)
if [ "$GLOBAL_SERVER" == "$UDP_RELAY_SERVER" -a $kcp_flag == 0 ]; then
ARG_UDP="-u"
elif [ -n "$UDP_RELAY_SERVER" ]; then
ARG_UDP="-U"
local udp_server=$(uci_get_by_name $UDP_RELAY_SERVER server)
if echo $udp_server | grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
udp_server=${udp_server}
elif [ "$udp_server" != "${udp_server#*:[0-9a-fA-F]}" ]; then
udp_server=${udp_server}
else
udp_server=$(ping ${udp_server} -s 1 -c 1 | grep PING | cut -d'(' -f 2 | cut -d')' -f1)
if echo $udp_server | grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
echo $udp_server >/etc/ssr_ip
else
udp_server=$(cat /etc/ssr_ip)
fi
fi
local udp_local_port=$(uci_get_by_name $UDP_RELAY_SERVER local_port)
fi
local local_port=$(uci_get_by_name $GLOBAL_SERVER local_port)
local lan_ac_ips=$(uci_get_by_type access_control lan_ac_ips)
local lan_ac_mode="b"
local router_proxy=$(uci_get_by_type access_control router_proxy)
if [ "$GLOBAL_SERVER" == "$UDP_RELAY_SERVER" -a $kcp_flag == 0 ]; then
ARG_UDP="-u"
elif [ -n "$UDP_RELAY_SERVER" ]; then
ARG_UDP="-U"
local udp_server=$(uci_get_by_name $UDP_RELAY_SERVER server)
if echo $udp_server | grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
udp_server=${udp_server}
elif [ "$udp_server" != "${udp_server#*:[0-9a-fA-F]}" ]; then
udp_server=${udp_server}
else
udp_server=$(ping ${udp_server} -s 1 -c 1 | grep PING | cut -d'(' -f 2 | cut -d')' -f1)
if echo $udp_server | grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
echo $udp_server >/etc/ssr_ip
else
udp_server=$(cat /etc/ssr_ip)
fi
fi
local udp_local_port=$(uci_get_by_name $UDP_RELAY_SERVER local_port)
fi
if [ -n "$lan_ac_ips" ]; then
case "$lan_ac_mode" in
w | W | b | B) local ac_ips="$lan_ac_mode$lan_ac_ips" ;;
esac
fi
if [ -n "$lan_ac_ips" ]; then
case "$lan_ac_mode" in
w | W | b | B) local ac_ips="$lan_ac_mode$lan_ac_ips" ;;
esac
fi
#deal gfw firewall rule
local gfwmode=""
if [ "$run_mode" = "gfw" ]; then
gfwmode="-g"
elif [ "$run_mode" = "router" ]; then
gfwmode="-r"
elif [ "$run_mode" = "oversea" ]; then
gfwmode="-c"
elif [ "$run_mode" = "all" ]; then
gfwmode="-z"
fi
#deal gfw firewall rule
local gfwmode=""
if [ "$run_mode" = "gfw" ]; then
gfwmode="-g"
elif [ "$run_mode" = "router" ]; then
gfwmode="-r"
elif [ "$run_mode" = "oversea" ]; then
gfwmode="-c"
elif [ "$run_mode" = "all" ]; then
gfwmode="-z"
fi
local dports=$(uci_get_by_type global dports 1)
if [ $dports = "1" ]; then
proxyport=" "
else
proxyport="-m multiport --dports 22,53,587,465,995,993,143,80,443 "
fi
local dports=$(uci_get_by_type global dports 1)
if [ $dports = "1" ]; then
proxyport=" "
else
proxyport="-m multiport --dports 22,53,587,465,995,993,143,80,443 "
fi
/usr/bin/vssr-rules \
-s "$server" \
-l "$local_port" \
-S "$udp_server" \
-L "$udp_local_port" \
-a "$ac_ips" \
-i "$(uci_get_by_type access_control wan_bp_list)" \
-b "$(uci_get_by_type access_control wan_bp_ips)" \
-w "$(uci_get_by_type access_control wan_fw_ips)" \
-p "$(uci_get_by_type access_control lan_fp_ips)" \
-G "$(uci_get_by_type access_control lan_gm_ips)" \
-D "$proxyport" \
$(get_arg_out) $gfwmode $ARG_UDP
return $?
/usr/bin/vssr-rules \
-s "$server" \
-l "$local_port" \
-S "$udp_server" \
-L "$udp_local_port" \
-a "$ac_ips" \
-i "$(uci_get_by_type access_control wan_bp_list)" \
-b "$(uci_get_by_type access_control wan_bp_ips)" \
-w "$(uci_get_by_type access_control wan_fw_ips)" \
-p "$(uci_get_by_type access_control lan_fp_ips)" \
-G "$(uci_get_by_type access_control lan_gm_ips)" \
-D "$proxyport" \
$(get_arg_out) $gfwmode $ARG_UDP
return $?
}
start_pdnsd() {
local usr_dns="$1"
local usr_port="$2"
local usr_dns="$1"
local usr_port="$2"
local tcp_dns_list="208.67.222.222, 208.67.220.220"
[ -z "$usr_dns" ] && usr_dns="8.8.8.8"
[ -z "$usr_port" ] && usr_port="53"
local tcp_dns_list="208.67.222.222, 208.67.220.220"
[ -z "$usr_dns" ] && usr_dns="8.8.8.8"
[ -z "$usr_port" ] && usr_port="53"
[ -d /var/etc ] || mkdir -p /var/etc
[ -d /var/etc ] || mkdir -p /var/etc
if [ ! -d /var/pdnsd ]; then
mkdir -p /var/pdnsd
echo -ne "pd13\000\000\000\000" >/var/pdnsd/pdnsd.cache
chown -R nobody:nogroup /var/pdnsd
fi
if [ ! -d /var/pdnsd ]; then
mkdir -p /var/pdnsd
echo -ne "pd13\000\000\000\000" >/var/pdnsd/pdnsd.cache
chown -R nobody:nogroup /var/pdnsd
fi
cat >/var/etc/pdnsd.conf <<EOF
cat >/var/etc/pdnsd.conf <<EOF
global {
perm_cache=1024;
cache_dir="/var/pdnsd";
@ -261,193 +261,193 @@ server {
}
EOF
/usr/sbin/pdnsd -c /var/etc/pdnsd.conf -d
/usr/sbin/pdnsd -c /var/etc/pdnsd.conf -d
}
find_bin() {
case "$1" in
ss) ret="/usr/bin/ss-redir" ;;
ss-local) ret="/usr/bin/ss-local" ;;
ssr) ret="/usr/bin/ssr-redir" ;;
ssr-local) ret="/usr/bin/ssr-local" ;;
ssr-server) ret="/usr/bin/ssr-server" ;;
v2ray) ret="/usr/bin/v2ray/v2ray" && [ ! -f "$ret" ] && ret="/usr/bin/v2ray" ;;
trojan) ret="/usr/sbin/trojan" ;;
socks5 | tun) ret="/usr/sbin/redsocks2" ;;
esac
echo $ret
case "$1" in
ss) ret="/usr/bin/ss-redir" ;;
ss-local) ret="/usr/bin/ss-local" ;;
ssr) ret="/usr/bin/ssr-redir" ;;
ssr-local) ret="/usr/bin/ssr-local" ;;
ssr-server) ret="/usr/bin/ssr-server" ;;
v2ray) ret="/usr/bin/v2ray/v2ray" && [ ! -f "$ret" ] && ret="/usr/bin/v2ray" ;;
trojan) ret="/usr/sbin/trojan" ;;
socks5 | tun) ret="/usr/sbin/redsocks2" ;;
esac
echo $ret
}
#分流节点
start_shunt() {
for ((i = 0; i < ${#shunt_type[@]}; i++)); do
local server_index=$(uci_get_by_type global ${shunt_type[i]}_server)
local server_port=${shunt_port[i]}
local server_type=$(uci_get_by_name $server_index type)
local server_ip=$(uci_get_by_name $server_index server)
[ "$server_type" == "trojan" ] && re_type="client" || re_type="tcp"
if [ "$server_type" != "v2ray" -a "$server_type" != "" ]; then
local config_file=/var/etc/${NAME}_${shunt_type[i]}.json
local bin=$(find_bin $server_type)
lua /usr/share/vssr/genconfig_${server_type}.lua ${server_index} ${re_type} ${server_port} ${server_ip} >${config_file}
sed -i 's/\\//g' $config_file
case "$server_type" in
ss | ssr)
bin=$(find_bin "ss-local")
[ "$server_type" == "ssr" ] && bin=$(find_bin "ssr-local")
$bin -c $config_file $ARG_OTA -f /var/run/vssr-${shunt_type[i]}.pid1 >/dev/null 2>&1
;;
trojan)
$bin --config $config_file >/dev/null 2>&1 &
;;
esac
echo "$(date "+%Y-%m-%d %H:%M:%S") ${shunt_type[i]}: $server_type 分流服务已启动!" >>/tmp/vssr.log
fi
done
return $?
for ((i = 0; i < ${#shunt_type[@]}; i++)); do
local server_index=$(uci_get_by_type global ${shunt_type[i]}_server)
local server_port=${shunt_port[i]}
local server_type=$(uci_get_by_name $server_index type)
local server_ip=$(uci_get_by_name $server_index server)
[ "$server_type" == "trojan" ] && re_type="client" || re_type="tcp"
if [ "$server_type" != "v2ray" -a "$server_type" != "" ]; then
local config_file=/var/etc/${NAME}_${shunt_type[i]}.json
local bin=$(find_bin $server_type)
lua /usr/share/vssr/genconfig_${server_type}.lua ${server_index} ${re_type} ${server_port} ${server_ip} >${config_file}
sed -i 's/\\//g' $config_file
case "$server_type" in
ss | ssr)
bin=$(find_bin "ss-local")
[ "$server_type" == "ssr" ] && bin=$(find_bin "ssr-local")
$bin -c $config_file $ARG_OTA -f /var/run/vssr-${shunt_type[i]}.pid1 >/dev/null 2>&1
;;
trojan)
$bin --config $config_file >/dev/null 2>&1 &
;;
esac
echo "$(date "+%Y-%m-%d %H:%M:%S") ${shunt_type[i]}: $server_type 分流服务已启动!" >>/tmp/vssr.log
fi
done
return $?
}
start_redir() {
case "$(uci_get_by_name $GLOBAL_SERVER auth_enable)" in
1 | on | true | yes | enabled) ARG_OTA="-A" ;;
*) ARG_OTA="" ;;
esac
case "$(uci_get_by_name $GLOBAL_SERVER auth_enable)" in
1 | on | true | yes | enabled) ARG_OTA="-A" ;;
*) ARG_OTA="" ;;
esac
#deal kcp
local kcp_enable=$(uci_get_by_name $GLOBAL_SERVER kcp_enable 0)
if [ $kcp_enable = "1" ]; then
[ ! -f "/usr/bin/kcptun-client" ] && return 1
#deal kcp
local kcp_enable=$(uci_get_by_name $GLOBAL_SERVER kcp_enable 0)
if [ $kcp_enable = "1" ]; then
[ ! -f "/usr/bin/kcptun-client" ] && return 1
local kcp_str=$(/usr/bin/kcptun-client -v | grep kcptun | wc -l)
[ "0" = $kcp_str ] && return 1
local kcp_port=$(uci_get_by_name $GLOBAL_SERVER kcp_port)
local server_port=$(uci_get_by_name $GLOBAL_SERVER server_port)
local password=$(uci_get_by_name $GLOBAL_SERVER kcp_password)
local kcp_param=$(uci_get_by_name $GLOBAL_SERVER kcp_param)
[ "$password" != "" ] && password="--key "${password}
service_start /usr/bin/kcptun-client \
-r $kcp_server:$kcp_port \
-l :$server_port $password $kcp_param
kcp_enable_flag=1
fi
local kcp_str=$(/usr/bin/kcptun-client -v | grep kcptun | wc -l)
[ "0" = $kcp_str ] && return 1
local kcp_port=$(uci_get_by_name $GLOBAL_SERVER kcp_port)
local server_port=$(uci_get_by_name $GLOBAL_SERVER server_port)
local password=$(uci_get_by_name $GLOBAL_SERVER kcp_password)
local kcp_param=$(uci_get_by_name $GLOBAL_SERVER kcp_param)
[ "$password" != "" ] && password="--key "${password}
service_start /usr/bin/kcptun-client \
-r $kcp_server:$kcp_port \
-l :$server_port $password $kcp_param
kcp_enable_flag=1
fi
gen_config_file $GLOBAL_SERVER 0 0
local stype=$(uci_get_by_name $GLOBAL_SERVER type)
sscmd=$(find_bin $stype)
gen_config_file $GLOBAL_SERVER 0 0
local stype=$(uci_get_by_name $GLOBAL_SERVER type)
sscmd=$(find_bin $stype)
local utype=$(uci_get_by_name $UDP_RELAY_SERVER type)
ucmd=$(find_bin $utype)
local utype=$(uci_get_by_name $UDP_RELAY_SERVER type)
ucmd=$(find_bin $utype)
if [ "$(uci_get_by_type global threads 0)" = "0" ]; then
threads=$(cat /proc/cpuinfo | grep 'processor' | wc -l)
else
threads=$(uci_get_by_type global threads)
fi
#转发TCP
redir_tcp=1
if [ $scount == "0" ]; then
local last_config_file=$CONFIG_FILE
case "$stype" in
ss | ssr)
local pid_file="/var/run/ssr-retcp.pid"
local name="Shadowsocks"
[ "$type" == "ssr" ] && name="ShadowsocksR"
for i in $(seq 1 $threads); do
$sscmd -c $last_config_file $ARG_OTA -f /var/run/ssr-retcp_$i.pid >/dev/null 2>&1
done
echo "$(date "+%Y-%m-%d %H:%M:%S") $name $threads 线程 已启动!" >>/tmp/vssr.log
;;
v2ray)
$sscmd -config $last_config_file >/dev/null 2>&1 &
echo $sscmd
echo "$(date "+%Y-%m-%d %H:%M:%S") $($sscmd -version | head -1) 已启动!" >>/tmp/vssr.log
;;
trojan)
for i in $(seq 1 $threads); do
$sscmd -c $last_config_file >/dev/null 2>&1 &
done
echo "$(date "+%Y-%m-%d %H:%M:%S") $($sscmd -V 2>&1 | head -1) $threads 线程 已启动!" >>/tmp/vssr.log
;;
esac
else
if [ $stype != "vray" ]; then
#开启 v2ray 路由服务
gen_config_file $GLOBAL_SERVER 0 1
sscmd=$(find_bin "v2ray")
local last_config_file=$CONFIG_FILE
$sscmd -config $last_config_file >/dev/null 2>&1 &
echo "$(date "+%Y-%m-%d %H:%M:%S") $($sscmd -version | head -1) 已启动!" >>/tmp/vssr.log
fi
if [ "$(uci_get_by_type global threads 0)" = "0" ]; then
threads=$(cat /proc/cpuinfo | grep 'processor' | wc -l)
else
threads=$(uci_get_by_type global threads)
fi
#转发TCP
redir_tcp=1
if [ $scount == "0" ]; then
local last_config_file=$CONFIG_FILE
case "$stype" in
ss | ssr)
local pid_file="/var/run/ssr-retcp.pid"
local name="Shadowsocks"
[ "$type" == "ssr" ] && name="ShadowsocksR"
for i in $(seq 1 $threads); do
$sscmd -c $last_config_file $ARG_OTA -f /var/run/ssr-retcp_$i.pid >/dev/null 2>&1
done
echo "$(date "+%Y-%m-%d %H:%M:%S") $name $threads 线程 已启动!" >>/tmp/vssr.log
;;
v2ray)
$sscmd -config $last_config_file >/dev/null 2>&1 &
echo $sscmd
echo "$(date "+%Y-%m-%d %H:%M:%S") $($sscmd -version | head -1) 已启动!" >>/tmp/vssr.log
;;
trojan)
for i in $(seq 1 $threads); do
$sscmd -c $last_config_file >/dev/null 2>&1 &
done
echo "$(date "+%Y-%m-%d %H:%M:%S") $($sscmd -V 2>&1 | head -1) $threads 线程 已启动!" >>/tmp/vssr.log
;;
esac
else
if [ $stype != "vray" ]; then
#开启 v2ray 路由服务
gen_config_file $GLOBAL_SERVER 0 1
sscmd=$(find_bin "v2ray")
local last_config_file=$CONFIG_FILE
$sscmd -config $last_config_file >/dev/null 2>&1 &
echo "$(date "+%Y-%m-%d %H:%M:%S") $($sscmd -version | head -1) 已启动!" >>/tmp/vssr.log
fi
fi
fi
#转发UDP
if [ -n "$UDP_RELAY_SERVER" ]; then
redir_udp=1
gen_config_file $UDP_RELAY_SERVER 1 0
last_config_file=$CONFIG_UDP_FILE
case "$stype" in
ss | ssr)
case "$(uci_get_by_name $UDP_RELAY_SERVER auth_enable)" in
1 | on | true | yes | enabled) ARG_OTA="-A" ;;
*) ARG_OTA="" ;;
esac
local name="Shadowsocks"
[ "$type" == "ssr" ] && name="ShadowsocksR"
pid_file="/var/run/ssr-reudp.pid"
$ucmd -c $last_config_file $ARG_OTA -U -f /var/run/ssr-reudp.pid >/dev/null 2>&1
echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay: $name 已启动!" >>/tmp/vssr.log
;;
v2ray)
$ucmd -config $last_config_file >/dev/null 2>&1 &
echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay: V2ray 已启动!" >>/tmp/vssr.log
;;
trojan)
$ucmd --config $last_config_file >/dev/null 2>&1 &
ipt2socks -U -4 -b 0.0.0.0 -s 127.0.0.1 -p 10801 -l $(uci_get_by_name $UDP_RELAY_SERVER local_port) >/dev/null 2>&1 &
echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay: Trojan 已启动!" >>/tmp/vssr.log
;;
esac
fi
#转发UDP
if [ -n "$UDP_RELAY_SERVER" ]; then
redir_udp=1
gen_config_file $UDP_RELAY_SERVER 1 0
last_config_file=$CONFIG_UDP_FILE
case "$stype" in
ss | ssr)
case "$(uci_get_by_name $UDP_RELAY_SERVER auth_enable)" in
1 | on | true | yes | enabled) ARG_OTA="-A" ;;
*) ARG_OTA="" ;;
esac
local name="Shadowsocks"
[ "$type" == "ssr" ] && name="ShadowsocksR"
pid_file="/var/run/ssr-reudp.pid"
$ucmd -c $last_config_file $ARG_OTA -U -f /var/run/ssr-reudp.pid >/dev/null 2>&1
echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay: $name 已启动!" >>/tmp/vssr.log
;;
v2ray)
$ucmd -config $last_config_file >/dev/null 2>&1 &
echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay: V2ray 已启动!" >>/tmp/vssr.log
;;
trojan)
$ucmd --config $last_config_file >/dev/null 2>&1 &
ipt2socks -U -4 -b 0.0.0.0 -s 127.0.0.1 -p 10801 -l $(uci_get_by_name $UDP_RELAY_SERVER local_port) >/dev/null 2>&1 &
echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay: Trojan 已启动!" >>/tmp/vssr.log
;;
esac
fi
#deal with dns
#deal with dns
if [ "$(uci_get_by_type global pdnsd_enable)" = "1" ]; then
local dnsstr="$(uci_get_by_type global tunnel_forward 8.8.4.4:53)"
local dnsserver=$(echo "$dnsstr" | awk -F ':' '{print $1}')
local dnsport=$(echo "$dnsstr" | awk -F ':' '{print $2}')
if [ "$run_mode" = "gfw" ]; then
ipset add gfwlist $dnsserver 2>/dev/null
elif [ "$run_mode" = "oversea" ]; then
ipset add oversea $dnsserver 2>/dev/null
else
ipset add ss_spec_wan_ac $dnsserver nomatch 2>/dev/null
fi
start_pdnsd $dnsserver $dnsport
pdnsd_enable_flag=1
fi
if [ "$(uci_get_by_type global pdnsd_enable)" = "1" ]; then
local dnsstr="$(uci_get_by_type global tunnel_forward 8.8.4.4:53)"
local dnsserver=$(echo "$dnsstr" | awk -F ':' '{print $1}')
local dnsport=$(echo "$dnsstr" | awk -F ':' '{print $2}')
if [ "$run_mode" = "gfw" ]; then
ipset add gfwlist $dnsserver 2>/dev/null
elif [ "$run_mode" = "oversea" ]; then
ipset add oversea $dnsserver 2>/dev/null
else
ipset add ss_spec_wan_ac $dnsserver nomatch 2>/dev/null
fi
start_pdnsd $dnsserver $dnsport
pdnsd_enable_flag=1
fi
if [ "$(uci_get_by_type global enable_switch)" = "1" ]; then
if [ "$(uci_get_by_name $GLOBAL_SERVER switch_enable)" = "1" ]; then
if [ -z "$switch_server" ]; then
local switch_time=$(uci_get_by_type global switch_time)
local switch_timeout=$(uci_get_by_type global switch_timeout)
service_start /usr/bin/vssr-switch start $switch_time $switch_timeout
switch_enable=1
fi
fi
fi
add_cron
if [ "$(uci_get_by_type global enable_switch)" = "1" ]; then
if [ "$(uci_get_by_name $GLOBAL_SERVER switch_enable)" = "1" ]; then
if [ -z "$switch_server" ]; then
local switch_time=$(uci_get_by_type global switch_time)
local switch_timeout=$(uci_get_by_type global switch_timeout)
service_start /usr/bin/vssr-switch start $switch_time $switch_timeout
switch_enable=1
fi
fi
fi
add_cron
return $?
return $?
}
gen_service_file() {
if [ $(uci_get_by_name $1 fast_open) = "1" ]; then
fastopen="true"
else
fastopen="false"
fi
cat <<-EOF >$2
if [ $(uci_get_by_name $1 fast_open) = "1" ]; then
fastopen="true"
else
fastopen="false"
fi
cat <<-EOF >$2
{
"server": "0.0.0.0",
"server_port": $(uci_get_by_name $1 server_port),
@ -464,31 +464,31 @@ gen_service_file() {
}
start_service() {
[ $(uci_get_by_name $1 enable) = "0" ] && return 1
let server_count=server_count+1
if [ $server_count = 1 ]; then
iptables -N SSR-SERVER-RULE &&
iptables -t filter -I INPUT -j SSR-SERVER-RULE
fi
[ $(uci_get_by_name $1 enable) = "0" ] && return 1
let server_count=server_count+1
if [ $server_count = 1 ]; then
iptables -N SSR-SERVER-RULE &&
iptables -t filter -I INPUT -j SSR-SERVER-RULE
fi
gen_service_file $1 /var/etc/${NAME}_${server_count}.json
/usr/bin/ssr-server -c /var/etc/${NAME}_${server_count}.json -u -f /var/run/ssr-server${server_count}.pid >/dev/null 2>&1
iptables -t filter -A SSR-SERVER-RULE -p tcp --dport $(uci_get_by_name $1 server_port) -j ACCEPT
iptables -t filter -A SSR-SERVER-RULE -p udp --dport $(uci_get_by_name $1 server_port) -j ACCEPT
return 0
gen_service_file $1 /var/etc/${NAME}_${server_count}.json
/usr/bin/ssr-server -c /var/etc/${NAME}_${server_count}.json -u -f /var/run/ssr-server${server_count}.pid >/dev/null 2>&1
iptables -t filter -A SSR-SERVER-RULE -p tcp --dport $(uci_get_by_name $1 server_port) -j ACCEPT
iptables -t filter -A SSR-SERVER-RULE -p udp --dport $(uci_get_by_name $1 server_port) -j ACCEPT
return 0
}
gen_serv_include() {
FWI=$(uci get firewall.vssr.path 2>/dev/null)
[ -n "$FWI" ] || return 0
if [ ! -f $FWI ]; then
echo '#!/bin/sh' >$FWI
fi
extract_rules() {
echo "*filter"
iptables-save -t filter | grep SSR-SERVER-RULE | sed -e "s/^-A INPUT/-I INPUT/"
echo 'COMMIT'
}
cat <<-EOF >>$FWI
FWI=$(uci get firewall.vssr.path 2>/dev/null)
[ -n "$FWI" ] || return 0
if [ ! -f $FWI ]; then
echo '#!/bin/sh' >$FWI
fi
extract_rules() {
echo "*filter"
iptables-save -t filter | grep SSR-SERVER-RULE | sed -e "s/^-A INPUT/-I INPUT/"
echo 'COMMIT'
}
cat <<-EOF >>$FWI
iptables-save -c | grep -v "SSR-SERVER" | iptables-restore -c
iptables-restore -n <<-EOT
$(extract_rules)
@ -497,112 +497,112 @@ gen_serv_include() {
}
start_server() {
SERVER_ENABLE=$(uci_get_by_type server_global enable_server)
[ "$SERVER_ENABLE" = 0 ] && return 0
mkdir -p /var/run /var/etc
SERVER_ENABLE=$(uci_get_by_type server_global enable_server)
[ "$SERVER_ENABLE" = 0 ] && return 0
mkdir -p /var/run /var/etc
config_load $NAME
config_foreach start_service server_config
gen_serv_include
return 0
config_load $NAME
config_foreach start_service server_config
gen_serv_include
return 0
}
start_local() {
local local_server=$(uci_get_by_type socks5_proxy enable_server)
local local_server=$(uci_get_by_type socks5_proxy enable_server)
[ "$local_server" = "0" ] && return 1
mkdir -p /var/run /var/etc
[ "$local_server" = "0" ] && return 1
mkdir -p /var/run /var/etc
lua /usr/share/vssr/genconfig_v2ray_s.lua >$CONFIG_SOCK5_FILE
sed -i 's/\\//g' $config_file
lua /usr/share/vssr/genconfig_v2ray_s.lua >$CONFIG_SOCK5_FILE
sed -i 's/\\//g' $config_file
/usr/bin/v2ray/v2ray -config $CONFIG_SOCK5_FILE >/dev/null 2>&1 &
local_enable=1
/usr/bin/v2ray/v2ray -config $CONFIG_SOCK5_FILE >/dev/null 2>&1 &
local_enable=1
}
rules() {
[ "$GLOBAL_SERVER" = "nil" ] && return 1
mkdir -p /var/run /var/etc
UDP_RELAY_SERVER=$(uci_get_by_type global udp_relay_server)
[ "$UDP_RELAY_SERVER" = "same" ] && UDP_RELAY_SERVER=$GLOBAL_SERVER
if start_rules; then
return 0
else
return 1
fi
[ "$GLOBAL_SERVER" = "nil" ] && return 1
mkdir -p /var/run /var/etc
UDP_RELAY_SERVER=$(uci_get_by_type global udp_relay_server)
[ "$UDP_RELAY_SERVER" = "same" ] && UDP_RELAY_SERVER=$GLOBAL_SERVER
if start_rules; then
return 0
else
return 1
fi
}
start() {
if [ -z "$switch_server" ]; then
GLOBAL_SERVER=$(uci_get_by_type global global_server)
else
GLOBAL_SERVER=$switch_server
switch_enable=1
fi
if [ -z "$switch_server" ]; then
GLOBAL_SERVER=$(uci_get_by_type global global_server)
else
GLOBAL_SERVER=$switch_server
switch_enable=1
fi
if rules; then
start_redir
if rules; then
start_redir
mkdir -p /tmp/dnsmasq.d && cp -a /etc/dnsmasq.ssr /tmp/ && cp -a /etc/dnsmasq.oversea /tmp/
if ! [ "$run_mode" = "oversea" ]; then
cat >/tmp/dnsmasq.d/dnsmasq-ssr.conf <<EOF
mkdir -p /tmp/dnsmasq.d && cp -a /etc/dnsmasq.ssr /tmp/ && cp -a /etc/dnsmasq.oversea /tmp/
if ! [ "$run_mode" = "oversea" ]; then
cat >/tmp/dnsmasq.d/dnsmasq-ssr.conf <<EOF
conf-dir=/tmp/dnsmasq.ssr
EOF
else
cat >/tmp/dnsmasq.d/dnsmasq-ssr.conf <<EOF
else
cat >/tmp/dnsmasq.d/dnsmasq-ssr.conf <<EOF
conf-dir=/tmp/dnsmasq.oversea
EOF
fi
fi
if [ $(uci_get_by_type global adblock) = 0 ]; then
rm -f /tmp/dnsmasq.ssr/ad.conf
fi
if [ $(uci_get_by_type global adblock) = 0 ]; then
rm -f /tmp/dnsmasq.ssr/ad.conf
fi
/usr/share/vssr/gfw2ipset.sh
/etc/init.d/dnsmasq restart >/dev/null 2>&1
/usr/share/vssr/gfw2ipset.sh
/etc/init.d/dnsmasq restart >/dev/null 2>&1
fi
start_server
start_local
if [ $scount != "0" ]; then
start_shunt
fi
if [ $(uci_get_by_type global monitor_enable) = 1 ]; then
let total_count=server_count+redir_tcp+redir_udp+tunnel_enable+kcp_enable_flag+local_enable+pdnsd_enable_flag+switch_enable
if [ $total_count -gt 0 ]; then
#param:server(count) redir_tcp(0:no,1:yes) redir_udp tunnel kcp local gfw
service_start /usr/bin/vssr-monitor $server_count $redir_tcp $redir_udp $tunnel_enable $kcp_enable_flag $local_enable $pdnsd_enable_flag $switch_enable
fi
fi
fi
start_server
start_local
if [ $scount != "0" ]; then
start_shunt
fi
if [ $(uci_get_by_type global monitor_enable) = 1 ]; then
let total_count=server_count+redir_tcp+redir_udp+tunnel_enable+kcp_enable_flag+local_enable+pdnsd_enable_flag+switch_enable
if [ $total_count -gt 0 ]; then
#param:server(count) redir_tcp(0:no,1:yes) redir_udp tunnel kcp local gfw
service_start /usr/bin/vssr-monitor $server_count $redir_tcp $redir_udp $tunnel_enable $kcp_enable_flag $local_enable $pdnsd_enable_flag $switch_enable
fi
fi
ENABLE_SERVER=$(uci_get_by_type global global_server)
[ "$ENABLE_SERVER" = "nil" ] && return 1
ENABLE_SERVER=$(uci_get_by_type global global_server)
[ "$ENABLE_SERVER" = "nil" ] && return 1
}
boot() {
(/usr/share/vssr/chinaipset.sh && sleep 5 && start >/dev/null 2>&1) &
(/usr/share/vssr/chinaipset.sh && sleep 5 && start >/dev/null 2>&1) &
}
stop() {
echo "stop"
/usr/bin/vssr-rules -f
srulecount=$(iptables -L | grep SSR-SERVER-RULE | wc -l)
if [ $srulecount -gt 0 ]; then
iptables -F SSR-SERVER-RULE
iptables -t filter -D INPUT -j SSR-SERVER-RULE
iptables -X SSR-SERVER-RULE 2>/dev/null
fi
if [ -z "$switch_server" ]; then
kill -9 $(busybox ps -w | grep vssr-switch | grep -v grep | awk '{print $1}') >/dev/null 2>&1
fi
if [ $(uci_get_by_type global monitor_enable) = 1 ]; then
kill -9 $(busybox ps -w | grep vssr-monitor | grep -v grep | awk '{print $1}') >/dev/null 2>&1
fi
killall -q -9 ss-redir ss-local obfs-local ssr-redir ssr-local ssr-server v2ray v2ray-plugin trojan microsocks ipt2socks dns2socks redsocks2 pdnsd
echo "stop"
/usr/bin/vssr-rules -f
srulecount=$(iptables -L | grep SSR-SERVER-RULE | wc -l)
if [ $srulecount -gt 0 ]; then
iptables -F SSR-SERVER-RULE
iptables -t filter -D INPUT -j SSR-SERVER-RULE
iptables -X SSR-SERVER-RULE 2>/dev/null
fi
if [ -z "$switch_server" ]; then
kill -9 $(busybox ps -w | grep vssr-switch | grep -v grep | awk '{print $1}') >/dev/null 2>&1
fi
if [ $(uci_get_by_type global monitor_enable) = 1 ]; then
kill -9 $(busybox ps -w | grep vssr-monitor | grep -v grep | awk '{print $1}') >/dev/null 2>&1
fi
killall -q -9 ss-redir ss-local obfs-local ssr-redir ssr-local ssr-server v2ray v2ray-plugin trojan microsocks ipt2socks dns2socks redsocks2 pdnsd
if [ -f "/tmp/dnsmasq.d/dnsmasq-ssr.conf" ]; then
rm -f /tmp/dnsmasq.d/dnsmasq-ssr.conf
/etc/init.d/dnsmasq restart >/dev/null 2>&1
fi
del_cron
if [ -f "/tmp/dnsmasq.d/dnsmasq-ssr.conf" ]; then
rm -f /tmp/dnsmasq.d/dnsmasq-ssr.conf
/etc/init.d/dnsmasq restart >/dev/null 2>&1
fi
del_cron
}

View File

@ -7,12 +7,12 @@
# See /LICENSE for more information.
#
TAG="_SS_SPEC_RULE_" # comment tag
IPT="iptables -t nat" # alias of iptables
FWI=$(uci get firewall.vssr.path 2>/dev/null) # firewall include file
TAG="_SS_SPEC_RULE_" # comment tag
IPT="iptables -t nat" # alias of iptables
FWI=$(uci get firewall.vssr.path 2>/dev/null) # firewall include file
usage() {
cat <<-EOF
cat <<-EOF
Usage: vssr-rules [options]
Valid options are:
@ -39,194 +39,194 @@ usage() {
-g gfw list mode
-r return china mode
-h show this help message and exit
EOF
exit $1
EOF
exit $1
}
loger() {
# 1.alert 2.crit 3.err 4.warn 5.notice 6.info 7.debug
logger -st vssr-rules[$$] -p$1 $2
# 1.alert 2.crit 3.err 4.warn 5.notice 6.info 7.debug
logger -st vssr-rules[$$] -p$1 $2
}
flush_r() {
flush_iptables() {
local ipt="iptables -t $1"
local DAT=$(iptables-save -t $1)
eval $(echo "$DAT" | grep "$TAG" | sed -e 's/^-A/$ipt -D/' -e 's/$/;/')
for chain in $(echo "$DAT" | awk '/^:SS_SPEC/{print $1}'); do
$ipt -F ${chain:1} 2>/dev/null && $ipt -X ${chain:1}
done
}
flush_iptables nat
flush_iptables mangle
ip rule del fwmark 0x01/0x01 table 100 2>/dev/null
ip route del local 0.0.0.0/0 dev lo table 100 2>/dev/null
ipset -X ss_spec_lan_ac 2>/dev/null
ipset -X ss_spec_wan_ac 2>/dev/null
ipset -X ssr_gen_router 2>/dev/null
ipset -X fplan 2>/dev/null
ipset -X gmlan 2>/dev/null
ipset -X oversea 2>/dev/null
ipset -X whitelist 2>/dev/null
ipset -X blacklist 2>/dev/null
[ -n "$FWI" ] && echo '#!/bin/sh' >$FWI
return 0
flush_iptables() {
local ipt="iptables -t $1"
local DAT=$(iptables-save -t $1)
eval $(echo "$DAT" | grep "$TAG" | sed -e 's/^-A/$ipt -D/' -e 's/$/;/')
for chain in $(echo "$DAT" | awk '/^:SS_SPEC/{print $1}'); do
$ipt -F ${chain:1} 2>/dev/null && $ipt -X ${chain:1}
done
}
flush_iptables nat
flush_iptables mangle
ip rule del fwmark 0x01/0x01 table 100 2>/dev/null
ip route del local 0.0.0.0/0 dev lo table 100 2>/dev/null
ipset -X ss_spec_lan_ac 2>/dev/null
ipset -X ss_spec_wan_ac 2>/dev/null
ipset -X ssr_gen_router 2>/dev/null
ipset -X fplan 2>/dev/null
ipset -X gmlan 2>/dev/null
ipset -X oversea 2>/dev/null
ipset -X whitelist 2>/dev/null
ipset -X blacklist 2>/dev/null
[ -n "$FWI" ] && echo '#!/bin/sh' >$FWI
return 0
}
ipset_r() {
ipset -N gmlan hash:net 2>/dev/null
for ip in $LAN_GM_IP; do ipset -! add gmlan $ip; done
case "$RUNMODE" in
router)
ipset -! -R <<-EOF || return 1
ipset -N gmlan hash:net 2>/dev/null
for ip in $LAN_GM_IP; do ipset -! add gmlan $ip; done
case "$RUNMODE" in
router)
ipset -! -R <<-EOF || return 1
create ss_spec_wan_ac hash:net
$(gen_iplist | sed -e "s/^/add ss_spec_wan_ac /")
EOF
ipset -N gfwlist hash:net 2>/dev/null
$IPT -N SS_SPEC_WAN_AC
$IPT -I SS_SPEC_WAN_AC -p tcp ! --dport 53 -d $server -j RETURN
$IPT -A SS_SPEC_WAN_AC -m set --match-set ss_spec_wan_ac dst -j RETURN
$IPT -A SS_SPEC_WAN_AC -j SS_SPEC_WAN_FW
;;
gfw)
ipset -N gfwlist hash:net 2>/dev/null
$IPT -N SS_SPEC_WAN_AC
$IPT -A SS_SPEC_WAN_AC -m set --match-set gfwlist dst -j SS_SPEC_WAN_FW
$IPT -A SS_SPEC_WAN_AC -m set --match-set gmlan src -m set ! --match-set china dst -j SS_SPEC_WAN_FW
$IPT -A SS_SPEC_WAN_AC -m set --match-set china dst -j RETURN
$IPT -I SS_SPEC_WAN_AC -p tcp ! --dport 53 -d $server -j RETURN
;;
oversea)
ipset -N oversea hash:net 2>/dev/null
$IPT -N SS_SPEC_WAN_AC
ipset -N gmlan hash:net 2>/dev/null
for ip in $LAN_GM_IP; do ipset -! add gmlan $ip; done
$IPT -A SS_SPEC_WAN_AC -m set --match-set china dst -j SS_SPEC_WAN_FW
$IPT -I SS_SPEC_WAN_AC -p tcp ! --dport 53 -d $server -j RETURN
;;
all)
$IPT -N SS_SPEC_WAN_AC
$IPT -A SS_SPEC_WAN_AC -j SS_SPEC_WAN_FW
$IPT -I SS_SPEC_WAN_AC -p tcp ! --dport 53 -d $server -j RETURN
;;
esac
ipset -N fplan hash:net 2>/dev/null
for ip in $LAN_FP_IP; do ipset -! add fplan $ip ; done
$IPT -I SS_SPEC_WAN_AC -m set --match-set fplan src -j SS_SPEC_WAN_FW
ipset -N whitelist hash:net 2>/dev/null
ipset -N blacklist hash:net 2>/dev/null
$IPT -I SS_SPEC_WAN_AC -m set --match-set blacklist dst -j SS_SPEC_WAN_FW
$IPT -I SS_SPEC_WAN_AC -m set --match-set whitelist dst -j RETURN
ipset -N gfwlist hash:net 2>/dev/null
$IPT -N SS_SPEC_WAN_AC
$IPT -I SS_SPEC_WAN_AC -p tcp ! --dport 53 -d $server -j RETURN
$IPT -A SS_SPEC_WAN_AC -m set --match-set ss_spec_wan_ac dst -j RETURN
$IPT -A SS_SPEC_WAN_AC -j SS_SPEC_WAN_FW
;;
gfw)
ipset -N gfwlist hash:net 2>/dev/null
$IPT -N SS_SPEC_WAN_AC
$IPT -A SS_SPEC_WAN_AC -m set --match-set gfwlist dst -j SS_SPEC_WAN_FW
$IPT -A SS_SPEC_WAN_AC -m set --match-set gmlan src -m set ! --match-set china dst -j SS_SPEC_WAN_FW
$IPT -A SS_SPEC_WAN_AC -m set --match-set china dst -j RETURN
$IPT -I SS_SPEC_WAN_AC -p tcp ! --dport 53 -d $server -j RETURN
;;
oversea)
ipset -N oversea hash:net 2>/dev/null
$IPT -N SS_SPEC_WAN_AC
ipset -N gmlan hash:net 2>/dev/null
for ip in $LAN_GM_IP; do ipset -! add gmlan $ip; done
$IPT -A SS_SPEC_WAN_AC -m set --match-set china dst -j SS_SPEC_WAN_FW
$IPT -I SS_SPEC_WAN_AC -p tcp ! --dport 53 -d $server -j RETURN
;;
all)
$IPT -N SS_SPEC_WAN_AC
$IPT -A SS_SPEC_WAN_AC -j SS_SPEC_WAN_FW
$IPT -I SS_SPEC_WAN_AC -p tcp ! --dport 53 -d $server -j RETURN
;;
esac
for ip in $WAN_BP_IP; do ipset -! add whitelist $ip; done
for ip in $WAN_FW_IP; do ipset -! add blacklist $ip; done
ipset -N fplan hash:net 2>/dev/null
for ip in $LAN_FP_IP; do ipset -! add fplan $ip; done
$IPT -I SS_SPEC_WAN_AC -m set --match-set fplan src -j SS_SPEC_WAN_FW
return $?
ipset -N whitelist hash:net 2>/dev/null
ipset -N blacklist hash:net 2>/dev/null
$IPT -I SS_SPEC_WAN_AC -m set --match-set blacklist dst -j SS_SPEC_WAN_FW
$IPT -I SS_SPEC_WAN_AC -m set --match-set whitelist dst -j RETURN
for ip in $WAN_BP_IP; do ipset -! add whitelist $ip; done
for ip in $WAN_FW_IP; do ipset -! add blacklist $ip; done
return $?
}
fw_rule() {
$IPT -N SS_SPEC_WAN_FW
$IPT -A SS_SPEC_WAN_FW -d 0.0.0.0/8 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 10.0.0.0/8 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 127.0.0.0/8 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 169.254.0.0/16 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 172.16.0.0/12 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 192.168.0.0/16 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 224.0.0.0/4 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 240.0.0.0/4 -j RETURN
$IPT -A SS_SPEC_WAN_FW -p tcp $PROXY_PORTS \
-j REDIRECT --to-ports $local_port 2>/dev/null || {
loger 3 "Can't redirect, please check the iptables."
exit 1
}
return $?
$IPT -N SS_SPEC_WAN_FW
$IPT -A SS_SPEC_WAN_FW -d 0.0.0.0/8 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 10.0.0.0/8 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 127.0.0.0/8 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 169.254.0.0/16 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 172.16.0.0/12 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 192.168.0.0/16 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 224.0.0.0/4 -j RETURN
$IPT -A SS_SPEC_WAN_FW -d 240.0.0.0/4 -j RETURN
$IPT -A SS_SPEC_WAN_FW -p tcp $PROXY_PORTS \
-j REDIRECT --to-ports $local_port 2>/dev/null || {
loger 3 "Can't redirect, please check the iptables."
exit 1
}
return $?
}
ac_rule() {
if [ -n "$LAN_AC_IP" ]; then
case "${LAN_AC_IP:0:1}" in
w | W)
MATCH_SET="-m set --match-set ss_spec_lan_ac src"
;;
b | B)
MATCH_SET="-m set ! --match-set ss_spec_lan_ac src"
;;
*)
loger 3 "Bad argument \`-a $LAN_AC_IP\`."
return 2
;;
esac
fi
IFNAME=$(uci get -P/var/state network.lan.ifname 2>/dev/null)
ipset -! -R <<-EOF || return 1
if [ -n "$LAN_AC_IP" ]; then
case "${LAN_AC_IP:0:1}" in
w | W)
MATCH_SET="-m set --match-set ss_spec_lan_ac src"
;;
b | B)
MATCH_SET="-m set ! --match-set ss_spec_lan_ac src"
;;
*)
loger 3 "Bad argument \`-a $LAN_AC_IP\`."
return 2
;;
esac
fi
IFNAME=$(uci get -P/var/state network.lan.ifname 2>/dev/null)
ipset -! -R <<-EOF || return 1
create ss_spec_lan_ac hash:net
$(for ip in ${LAN_AC_IP:1}; do echo "add ss_spec_lan_ac $ip"; done)
EOF
$IPT -I PREROUTING 1 ${IFNAME:+-i $IFNAME} -p tcp $EXT_ARGS $MATCH_SET \
-m comment --comment "$TAG" -j SS_SPEC_WAN_AC
if [ "$OUTPUT" = 1 ]; then
$IPT -I OUTPUT 1 -p tcp $EXT_ARGS \
-m comment --comment "$TAG" -j SS_SPEC_WAN_AC
elif [ "$OUTPUT" = 2 ]; then
ipset -! -R <<-EOF || return 1
$IPT -I PREROUTING 1 ${IFNAME:+-i $IFNAME} -p tcp $EXT_ARGS $MATCH_SET \
-m comment --comment "$TAG" -j SS_SPEC_WAN_AC
if [ "$OUTPUT" = 1 ]; then
$IPT -I OUTPUT 1 -p tcp $EXT_ARGS \
-m comment --comment "$TAG" -j SS_SPEC_WAN_AC
elif [ "$OUTPUT" = 2 ]; then
ipset -! -R <<-EOF || return 1
create ssr_gen_router hash:net
$(gen_spec_iplist | sed -e "s/^/add ssr_gen_router /")
EOF
$IPT -N SS_SPEC_ROUTER && \
$IPT -A SS_SPEC_ROUTER -m set --match-set ssr_gen_router dst -j RETURN && \
$IPT -A SS_SPEC_ROUTER -j SS_SPEC_WAN_FW
$IPT -I OUTPUT 1 -p tcp -m comment --comment "$TAG" -j SS_SPEC_ROUTER
fi
return $?
$IPT -N SS_SPEC_ROUTER &&
$IPT -A SS_SPEC_ROUTER -m set --match-set ssr_gen_router dst -j RETURN &&
$IPT -A SS_SPEC_ROUTER -j SS_SPEC_WAN_FW
$IPT -I OUTPUT 1 -p tcp -m comment --comment "$TAG" -j SS_SPEC_ROUTER
fi
return $?
}
tp_rule() {
[ -n "$TPROXY" ] || return 0
ip rule add fwmark 0x01/0x01 table 100
ip route add local 0.0.0.0/0 dev lo table 100
local ipt="iptables -t mangle"
$ipt -N SS_SPEC_TPROXY
$ipt -A SS_SPEC_TPROXY -p udp --dport 443 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp --dport 80 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp --dport 53 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 0.0.0.0/8 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 10.0.0.0/8 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 127.0.0.0/8 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 169.254.0.0/16 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 172.16.0.0/12 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 192.168.0.0/16 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 224.0.0.0/4 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 240.0.0.0/4 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp ! --dport 53 -d $server -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp $PROXY_PORTS -m set --match-set fplan src \
-j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
case "$RUNMODE" in
router)
$ipt -A SS_SPEC_TPROXY -p udp -m set --match-set gmlan src -m set ! --match-set china dst \
-j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
$ipt -A SS_SPEC_TPROXY -p udp $PROXY_PORTS -m set ! --match-set ss_spec_wan_ac dst \
-j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
;;
gfw)
$ipt -A SS_SPEC_TPROXY -p udp -m set --match-set china dst -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -m set --match-set gmlan src -m set ! --match-set china dst \
-j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
$ipt -A SS_SPEC_TPROXY -p udp -m set $PROXY_PORTS --match-set gfwlist dst \
-j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
;;
oversea)
$ipt -A SS_SPEC_TPROXY -p udp $PROXY_PORTS -m set --match-set china dst \
-j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
;;
all)
$ipt -A SS_SPEC_TPROXY -p udp $PROXY_PORTS -j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
;;
esac
$ipt -I PREROUTING 1 ${IFNAME:+-i $IFNAME} -p udp $EXT_ARGS $MATCH_SET \
-m comment --comment "$TAG" -j SS_SPEC_TPROXY
return $?
[ -n "$TPROXY" ] || return 0
ip rule add fwmark 0x01/0x01 table 100
ip route add local 0.0.0.0/0 dev lo table 100
local ipt="iptables -t mangle"
$ipt -N SS_SPEC_TPROXY
$ipt -A SS_SPEC_TPROXY -p udp --dport 443 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp --dport 80 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp --dport 53 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 0.0.0.0/8 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 10.0.0.0/8 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 127.0.0.0/8 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 169.254.0.0/16 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 172.16.0.0/12 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 192.168.0.0/16 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 224.0.0.0/4 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -d 240.0.0.0/4 -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp ! --dport 53 -d $server -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp $PROXY_PORTS -m set --match-set fplan src \
-j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
case "$RUNMODE" in
router)
$ipt -A SS_SPEC_TPROXY -p udp -m set --match-set gmlan src -m set ! --match-set china dst \
-j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
$ipt -A SS_SPEC_TPROXY -p udp $PROXY_PORTS -m set ! --match-set ss_spec_wan_ac dst \
-j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
;;
gfw)
$ipt -A SS_SPEC_TPROXY -p udp -m set --match-set china dst -j RETURN
$ipt -A SS_SPEC_TPROXY -p udp -m set --match-set gmlan src -m set ! --match-set china dst \
-j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
$ipt -A SS_SPEC_TPROXY -p udp -m set $PROXY_PORTS --match-set gfwlist dst \
-j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
;;
oversea)
$ipt -A SS_SPEC_TPROXY -p udp $PROXY_PORTS -m set --match-set china dst \
-j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
;;
all)
$ipt -A SS_SPEC_TPROXY -p udp $PROXY_PORTS -j TPROXY --on-port "$LOCAL_PORT" --tproxy-mark 0x01/0x01
;;
esac
$ipt -I PREROUTING 1 ${IFNAME:+-i $IFNAME} -p udp $EXT_ARGS $MATCH_SET \
-m comment --comment "$TAG" -j SS_SPEC_TPROXY
return $?
}
get_wan_ip() {
@ -261,7 +261,7 @@ EOF
}
gen_spec_iplist() {
cat <<-EOF
cat <<-EOF
0.0.0.0/8
10.0.0.0/8
100.64.0.0/10
@ -278,112 +278,112 @@ gen_spec_iplist() {
224.0.0.0/4
240.0.0.0/4
255.255.255.255
$(get_wan_ip)
$(get_wan_ip)
EOF
}
gen_include() {
[ -n "$FWI" ] || return 0
extract_rules() {
echo "*$1"
iptables-save -t $1 | grep SS_SPEC_ |\
sed -e "s/^-A \(OUTPUT\|PREROUTING\)/-I \1 1/"
echo 'COMMIT'
}
cat <<-EOF >>$FWI
iptables-save -c | grep -v "SS_SPEC" | iptables-restore -c
iptables-restore -n <<-EOT
$(extract_rules nat)
$(extract_rules mangle)
EOT
EOF
return 0
[ -n "$FWI" ] || return 0
extract_rules() {
echo "*$1"
iptables-save -t $1 | grep SS_SPEC_ |
sed -e "s/^-A \(OUTPUT\|PREROUTING\)/-I \1 1/"
echo 'COMMIT'
}
cat <<-EOF >>$FWI
iptables-save -c | grep -v "SS_SPEC" | iptables-restore -c
iptables-restore -n <<-EOT
$(extract_rules nat)
$(extract_rules mangle)
EOT
EOF
return 0
}
while getopts ":s:l:S:L:i:e:a:b:w:p:G:D:oOuUfgrczh" arg; do
case "$arg" in
s)
server=$OPTARG
;;
l)
local_port=$OPTARG
;;
S)
SERVER=$OPTARG
;;
L)
LOCAL_PORT=$OPTARG
;;
i)
IGNORE_LIST=$OPTARG
;;
e)
EXT_ARGS=$OPTARG
;;
a)
LAN_AC_IP=$OPTARG
;;
b)
WAN_BP_IP=$(for ip in $OPTARG; do echo $ip; done)
;;
w)
WAN_FW_IP=$OPTARG
;;
p)
LAN_FP_IP=$OPTARG
;;
G)
LAN_GM_IP=$OPTARG
;;
D)
PROXY_PORTS=$OPTARG
;;
o)
OUTPUT=1
;;
O)
OUTPUT=2
;;
u)
TPROXY=1
;;
U)
TPROXY=2
;;
g)
RUNMODE=gfw
;;
r)
RUNMODE=router
;;
c)
RUNMODE=oversea
;;
z)
RUNMODE=all
;;
f)
flush_r
exit 0
;;
h)
usage 0
;;
esac
case "$arg" in
s)
server=$OPTARG
;;
l)
local_port=$OPTARG
;;
S)
SERVER=$OPTARG
;;
L)
LOCAL_PORT=$OPTARG
;;
i)
IGNORE_LIST=$OPTARG
;;
e)
EXT_ARGS=$OPTARG
;;
a)
LAN_AC_IP=$OPTARG
;;
b)
WAN_BP_IP=$(for ip in $OPTARG; do echo $ip; done)
;;
w)
WAN_FW_IP=$OPTARG
;;
p)
LAN_FP_IP=$OPTARG
;;
G)
LAN_GM_IP=$OPTARG
;;
D)
PROXY_PORTS=$OPTARG
;;
o)
OUTPUT=1
;;
O)
OUTPUT=2
;;
u)
TPROXY=1
;;
U)
TPROXY=2
;;
g)
RUNMODE=gfw
;;
r)
RUNMODE=router
;;
c)
RUNMODE=oversea
;;
z)
RUNMODE=all
;;
f)
flush_r
exit 0
;;
h)
usage 0
;;
esac
done
if [ -z "$server" -o -z "$local_port" ]; then
usage 2
usage 2
fi
if [ "$TPROXY" == 1 ]; then
SERVER=$server
LOCAL_PORT=$local_port
SERVER=$server
LOCAL_PORT=$local_port
elif [ "$TPROXY" == 2 ]; then
: ${SERVER:?"You must assign an ip for the udp relay server."}
: ${LOCAL_PORT:?"You must assign a port for the udp relay server."}
: ${SERVER:?"You must assign an ip for the udp relay server."}
: ${LOCAL_PORT:?"You must assign a port for the udp relay server."}
fi
flush_r && fw_rule && ipset_r && ac_rule && tp_rule && gen_include
[ "$?" == 0 ] || loger 3 "Start failed!"
exit $?
exit $?

View File

@ -20,13 +20,13 @@ CONFIG_SWTICH_FILE=/var/etc/${NAME}_t.json
[ -n "$2" ] && switch_time=$2
uci_get_by_name() {
local ret=$(uci get $NAME.$1.$2 2>/dev/null)
echo ${ret:=$3}
local ret=$(uci get $NAME.$1.$2 2>/dev/null)
echo ${ret:=$3}
}
uci_get_by_type() {
local ret=$(uci get $NAME.@$1[0].$2 2>/dev/null)
echo ${ret:=$3}
local ret=$(uci get $NAME.@$1[0].$2 2>/dev/null)
echo ${ret:=$3}
}
DEFAULT_SERVER=$(uci_get_by_type global global_server)
@ -34,143 +34,143 @@ CURRENT_SERVER=$DEFAULT_SERVER
#判断代理是否正常
check_proxy() {
local result=0
local try_count=$(uci_get_by_type global switch_try_count 3)
for i in $(seq 1 $try_count); do
/usr/bin/ssr-check www.google.com 80 $switch_time 1
if [ "$?" == "0" ]; then
result=0
break
else
/usr/bin/ssr-check www.baidu.com 80 $switch_time 1
if [ "$?" == "0" ]; then
result=1
else
result=2
fi
fi
sleep 1
done
return $result
local result=0
local try_count=$(uci_get_by_type global switch_try_count 3)
for i in $(seq 1 $try_count); do
/usr/bin/ssr-check www.google.com 80 $switch_time 1
if [ "$?" == "0" ]; then
result=0
break
else
/usr/bin/ssr-check www.baidu.com 80 $switch_time 1
if [ "$?" == "0" ]; then
result=1
else
result=2
fi
fi
sleep 1
done
return $result
}
test_proxy() {
local servername=$(uci_get_by_name $1 server)
local serverport=$(uci_get_by_name $1 server_port)
ret=$(ping -c 3 $servername | grep 'loss' | awk -F ',' '{ print $3 }' | awk -F "%" '{ print $1 }')
[ -z "$ret" ] && return 1
[ "$ret" -gt "50" ] && return 1
ipset add ss_spec_wan_ac $servername 2>/dev/null
ret=$?
/usr/bin/ssr-check $servername $serverport $switch_time
local ret2=$?
if [ "$ret" = "0" ]; then
ipset del ss_spec_wan_ac $servername 2>/dev/null
fi
if [ "$ret2" = "0" ]; then
return 0
else
return 1
fi
local servername=$(uci_get_by_name $1 server)
local serverport=$(uci_get_by_name $1 server_port)
ret=$(ping -c 3 $servername | grep 'loss' | awk -F ',' '{ print $3 }' | awk -F "%" '{ print $1 }')
[ -z "$ret" ] && return 1
[ "$ret" -gt "50" ] && return 1
ipset add ss_spec_wan_ac $servername 2>/dev/null
ret=$?
/usr/bin/ssr-check $servername $serverport $switch_time
local ret2=$?
if [ "$ret" = "0" ]; then
ipset del ss_spec_wan_ac $servername 2>/dev/null
fi
if [ "$ret2" = "0" ]; then
return 0
else
return 1
fi
}
search_proxy() {
let server_count=server_count+1
[ "$normal_flag" = "1" -a "$server_count" -le "$server_locate" ] && return 0
[ "$(uci_get_by_name $1 switch_enable)" != "1" ] && return 1
[ $ENABLE_SERVER != nil ] && return 0
[ "$1" = "$CURRENT_SERVER" ] && return 0
local servername=$(uci_get_by_name $1 server)
local serverport=$(uci_get_by_name $1 server_port)
ipset add ss_spec_wan_ac $servername 2>/dev/null
ret=$?
/usr/bin/ssr-check $servername $serverport $switch_time
local ret2=$?
if [ "$ret" = "0" ]; then
ipset del ss_spec_wan_ac $servername 2>/dev/null
fi
if [ "$ret2" = "0" ]; then
server_locate=$server_count
ENABLE_SERVER=$1
return 0
else
return 1
fi
let server_count=server_count+1
[ "$normal_flag" = "1" -a "$server_count" -le "$server_locate" ] && return 0
[ "$(uci_get_by_name $1 switch_enable)" != "1" ] && return 1
[ $ENABLE_SERVER != nil ] && return 0
[ "$1" = "$CURRENT_SERVER" ] && return 0
local servername=$(uci_get_by_name $1 server)
local serverport=$(uci_get_by_name $1 server_port)
ipset add ss_spec_wan_ac $servername 2>/dev/null
ret=$?
/usr/bin/ssr-check $servername $serverport $switch_time
local ret2=$?
if [ "$ret" = "0" ]; then
ipset del ss_spec_wan_ac $servername 2>/dev/null
fi
if [ "$ret2" = "0" ]; then
server_locate=$server_count
ENABLE_SERVER=$1
return 0
else
return 1
fi
}
#选择可用的代理
select_proxy() {
config_load $NAME
ENABLE_SERVER=nil
mkdir -p /var/run /var/etc
server_count=0
config_foreach search_proxy servers
config_load $NAME
ENABLE_SERVER=nil
mkdir -p /var/run /var/etc
server_count=0
config_foreach search_proxy servers
}
#切换代理
switch_proxy() {
/etc/init.d/vssr restart $1
return 0
/etc/init.d/vssr restart $1
return 0
}
start() {
#不支持kcptun启用时的切换
[ $(uci_get_by_name $DEFAULT_SERVER kcp_enable) = "1" ] && return 1
#不支持kcptun启用时的切换
[ $(uci_get_by_name $DEFAULT_SERVER kcp_enable) = "1" ] && return 1
while [ "1" = "1" ]; do #死循环
sleep $cycle_time
while [ "1" = "1" ]; do #死循环
sleep $cycle_time
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
#判断当前代理是否为缺省服务器
if [ "$CURRENT_SERVER" != "$DEFAULT_SERVER" ]; then
#echo "not default proxy"
echo "$(date "+%Y-%m-%d %H:%M:%S") 当前为备用节点,尝试切换为主节点。" >>/tmp/vssr.log
#判断当前代理是否为缺省服务器
if [ "$CURRENT_SERVER" != "$DEFAULT_SERVER" ]; then
#echo "not default proxy"
echo "$(date "+%Y-%m-%d %H:%M:%S") 当前为备用节点,尝试切换为主节点。" >>/tmp/vssr.log
#检查缺省服务器是否正常
if test_proxy $DEFAULT_SERVER; then
#echo "switch to default proxy"
echo "$(date "+%Y-%m-%d %H:%M:%S") 主节点不可用." >>/tmp/vssr.log
#缺省服务器正常,切换回来
CURRENT_SERVER=$DEFAULT_SERVER
switch_proxy $CURRENT_SERVER
echo "$(date "+%Y-%m-%d %H:%M:%S") 切换为默认节点 ["$(uci_get_by_name $CURRENT_SERVER server)"]" >>/tmp/vssr.log
continue
else
echo "$(date "+%Y-%m-%d %H:%M:%S") 主节点不可用,继续使用当前备用节点。" >>/tmp/vssr.log
fi
fi
#检查缺省服务器是否正常
if test_proxy $DEFAULT_SERVER; then
#echo "switch to default proxy"
echo "$(date "+%Y-%m-%d %H:%M:%S") 主节点不可用." >>/tmp/vssr.log
#缺省服务器正常,切换回来
CURRENT_SERVER=$DEFAULT_SERVER
switch_proxy $CURRENT_SERVER
echo "$(date "+%Y-%m-%d %H:%M:%S") 切换为默认节点 ["$(uci_get_by_name $CURRENT_SERVER server)"]" >>/tmp/vssr.log
continue
else
echo "$(date "+%Y-%m-%d %H:%M:%S") 主节点不可用,继续使用当前备用节点。" >>/tmp/vssr.log
fi
fi
#判断当前代理是否正常
check_proxy
current_ret=$?
#判断当前代理是否正常
check_proxy
current_ret=$?
if [ "$current_ret" = "1" ]; then
#当前代理错误,判断有无可用的服务器
#echo "current error"
echo "$(date "+%Y-%m-%d %H:%M:%S") 当前节点不可用,尝试切换其他节点。" >>/tmp/vssr.log
if [ "$current_ret" = "1" ]; then
#当前代理错误,判断有无可用的服务器
#echo "current error"
echo "$(date "+%Y-%m-%d %H:%M:%S") 当前节点不可用,尝试切换其他节点。" >>/tmp/vssr.log
select_proxy
if [ "$ENABLE_SERVER" != nil ]; then
#有其他服务器可用,进行切换
#echo $(uci_get_by_name $new_proxy server)
echo "$(date "+%Y-%m-%d %H:%M:%S") 另外一个节点可用,即将切换节点。" >>/tmp/vssr.log
CURRENT_SERVER=$ENABLE_SERVER
switch_proxy $CURRENT_SERVER
normal_flag=1
echo "$(date "+%Y-%m-%d %H:%M:%S") 切换节点成功。" >>/tmp/vssr.log
else
switch_proxy $CURRENT_SERVER
normal_flag=1
echo "$(date "+%Y-%m-%d %H:%M:%S") 尝试重启当前节点。" >>/tmp/vssr.log
fi
else
normal_flag=0
#echo "$(date "+%Y-%m-%d %H:%M:%S") vssr No Problem." >> /tmp/vssr.log
fi
select_proxy
if [ "$ENABLE_SERVER" != nil ]; then
#有其他服务器可用,进行切换
#echo $(uci_get_by_name $new_proxy server)
echo "$(date "+%Y-%m-%d %H:%M:%S") 另外一个节点可用,即将切换节点。" >>/tmp/vssr.log
CURRENT_SERVER=$ENABLE_SERVER
switch_proxy $CURRENT_SERVER
normal_flag=1
echo "$(date "+%Y-%m-%d %H:%M:%S") 切换节点成功。" >>/tmp/vssr.log
else
switch_proxy $CURRENT_SERVER
normal_flag=1
echo "$(date "+%Y-%m-%d %H:%M:%S") 尝试重启当前节点。" >>/tmp/vssr.log
fi
else
normal_flag=0
#echo "$(date "+%Y-%m-%d %H:%M:%S") vssr No Problem." >> /tmp/vssr.log
fi
done
done
}

View File

@ -98,11 +98,15 @@ function _M.get_flag(remark, host)
end
end
if (iso_code == nil) then
local ret = nixio.getaddrinfo(host, "any")
local hostip = ret[1].address
local res = db:lookup(hostip)
iso_code = string.lower(res:get("country", "iso_code"))
if (iso_code == nil ) then
if( host ~= "") then
local ret = nixio.getaddrinfo(host, "any")
local hostip = ret[1].address
local res = db:lookup(hostip)
iso_code = string.lower(res:get("country", "iso_code"))
else
iso_code = "un"
end
end
return string.gsub(iso_code, '\n', '')
end
@ -119,17 +123,16 @@ function _M.check_site(host, port)
return ret
end
function _M.trim(text)
if not text or text == "" then
return ""
end
return (string.gsub(text, "^%s*(.-)%s*$", "%1"))
if not text or text == "" then return "" end
return (string.gsub(text, "^%s*(.-)%s*$", "%1"))
end
function _M.wget(url)
local stdout = luci.sys.exec('wget-ssl -q --user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36" --no-check-certificate -t 3 -T 10 -O- "' .. url .. '"')
return _M.trim(stdout)
local stdout = luci.sys.exec(
'wget-ssl -q --user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36" --no-check-certificate -t 3 -T 10 -O- "' ..
url .. '"')
return _M.trim(stdout)
end
return _M

View File

@ -1,5 +1,5 @@
echo "create china hash:net family inet hashsize 1024 maxelem 65536" > /tmp/china.ipset
awk '!/^$/&&!/^#/{printf("add china %s'" "'\n",$0)}' /etc/china_ssr.txt >> /tmp/china.ipset
echo "create china hash:net family inet hashsize 1024 maxelem 65536" >/tmp/china.ipset
awk '!/^$/&&!/^#/{printf("add china %s'" "'\n",$0)}' /etc/china_ssr.txt >>/tmp/china.ipset
ipset -! flush china
ipset -! restore < /tmp/china.ipset 2>/dev/null
ipset -! restore </tmp/china.ipset 2>/dev/null
rm -f /tmp/china.ipset

View File

@ -1,7 +1,7 @@
local ucursor = require "luci.model.uci".cursor()
local ucursor = require"luci.model.uci".cursor()
local json = require "luci.jsonc"
local server_section = arg[1]
local proto = arg[2]
local proto = arg[2]
local local_port = arg[3]
local host = arg[4]
@ -13,11 +13,11 @@ local ss = {
local_address = "0.0.0.0",
local_port = local_port,
password = server.password,
timeout = (server.timeout ~= nil) and server.timeout or 60,
timeout = (server.timeout ~= nil) and server.timeout or 60,
method = server.encrypt_method_ss,
reuse_port = true,
fast_open = (server.fast_open == "1") and true or false,
plugin = (server.plugin ~= nil) and server.plugin or nil,
plugin_opts = (server.plugin ~= nil) and server.plugin_opts or nil,
plugin_opts = (server.plugin ~= nil) and server.plugin_opts or nil
}
print(json.stringify(ss, 1))

View File

@ -1,7 +1,7 @@
local ucursor = require "luci.model.uci".cursor()
local ucursor = require"luci.model.uci".cursor()
local json = require "luci.jsonc"
local server_section = arg[1]
local proto = arg[2]
local proto = arg[2]
local local_port = arg[3]
local host = arg[4]
@ -13,13 +13,13 @@ local ssr = {
local_address = "0.0.0.0",
local_port = local_port,
password = server.password,
timeout = (server.timeout ~= nil) and server.timeout or 60,
timeout = (server.timeout ~= nil) and server.timeout or 60,
method = server.encrypt_method,
protocol = server.protocol,
protocol_param = server.protocol_param,
obfs = server.obfs,
obfs_param = server.obfs_param,
reuse_port = true,
fast_open = (server.fast_open == "1") and true or false,
fast_open = (server.fast_open == "1") and true or false
}
print(json.stringify(ssr, 1))

View File

@ -1,4 +1,4 @@
local ucursor = require "luci.model.uci".cursor()
local ucursor = require"luci.model.uci".cursor()
local json = require "luci.jsonc"
local server_section = arg[1]
local proto = arg[2]
@ -7,34 +7,34 @@ local local_port = arg[3]
local server = ucursor:get_all("vssr", server_section)
local trojan = {
log_level = 3,
run_type = proto,
local_addr = "0.0.0.0",
local_port = tonumber(local_port),
remote_addr = server.server,
remote_port = tonumber(server.server_port),
udp_timeout = 60,
-- 传入连接
password = {server.password},
-- 传出连接
ssl = {
verify = (server.insecure == "0") and true or false,
verify_hostname = (server.tls == "1") and false or true,
cert = "",
cipher = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:AES128-SHA:AES256-SHA:DES-CBC3-SHA",
cipher_tls13 = "TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384",
sni = server.peer,
alpn = {"h2", "http/1.1"},
curve = "",
reuse_session = true,
session_ticket = false,
},
tcp = {
no_delay = true,
keep_alive = true,
reuse_port = true,
fast_open = (server.fast_open == "1") and true or false,
fast_open_qlen = 20
}
log_level = 3,
run_type = proto,
local_addr = "0.0.0.0",
local_port = tonumber(local_port),
remote_addr = server.server,
remote_port = tonumber(server.server_port),
udp_timeout = 60,
-- 传入连接
password = {server.password},
-- 传出连接
ssl = {
verify = (server.insecure == "0") and true or false,
verify_hostname = (server.tls == "1") and false or true,
cert = "",
cipher = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:AES128-SHA:AES256-SHA:DES-CBC3-SHA",
cipher_tls13 = "TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384",
sni = server.peer,
alpn = {"h2", "http/1.1"},
curve = "",
reuse_session = true,
session_ticket = false
},
tcp = {
no_delay = true,
keep_alive = true,
reuse_port = true,
fast_open = (server.fast_open == "1") and true or false,
fast_open_qlen = 20
}
}
print(json.stringify(trojan, 1))

View File

@ -15,14 +15,15 @@ local disney_server = ucursor:get_first(name, 'global', 'disney_server')
local prime_server = ucursor:get_first(name, 'global', 'prime_server')
local tvb_server = ucursor:get_first(name, 'global', 'tvb_server')
local custom_server = ucursor:get_first(name, 'global', 'custom_server')
local proxy_domain_name = ucursor:get_list(name,"@access_control[0]","proxy_domain_name")
local proxy_domain_name = ucursor:get_list(name, "@access_control[0]",
"proxy_domain_name")
function gen_outbound(server_node, tags, local_ports)
local bound = {}
if server_node == "nil" then
bound = nil
else
local server = ucursor:get_all(name, server_node)
if server.type ~= "v2ray" then
bound = {
@ -30,10 +31,7 @@ function gen_outbound(server_node, tags, local_ports)
protocol = "socks",
settings = {
servers = {
{
address = "127.0.0.1",
port = tonumber(local_ports)
}
{address = "127.0.0.1", port = tonumber(local_ports)}
}
}
}
@ -61,7 +59,8 @@ function gen_outbound(server_node, tags, local_ports)
network = server.transport,
security = (server.tls == '1') and "tls" or "none",
tlsSettings = {
allowInsecure = (server.insecure == "1") and true or false,
allowInsecure = (server.insecure == "1") and true or
false,
serverName = server.ws_host
},
kcpSettings = (server.transport == "kcp") and {
@ -69,7 +68,8 @@ function gen_outbound(server_node, tags, local_ports)
tti = tonumber(server.tti),
uplinkCapacity = tonumber(server.uplink_capacity),
downlinkCapacity = tonumber(server.downlink_capacity),
congestion = (server.congestion == "1") and true or false,
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}
@ -100,18 +100,18 @@ end
local outbounds_table = {}
if v2ray_flow == "1" then
table.insert(outbounds_table, gen_outbound(server_section, "global",2080))
table.insert(outbounds_table, gen_outbound(youtube_server, "youtube",2081))
table.insert(outbounds_table, gen_outbound(tw_video_server, "twvideo",2082))
table.insert(outbounds_table, gen_outbound(netflix_server, "netflix",2083))
table.insert(outbounds_table, gen_outbound(disney_server, "disney",2084))
table.insert(outbounds_table, gen_outbound(prime_server, "prime",2085))
table.insert(outbounds_table, gen_outbound(tvb_server, "tvb",2086))
table.insert(outbounds_table, gen_outbound(custom_server, "custom",2087))
table.insert(outbounds_table, gen_outbound(server_section, "global", 2080))
table.insert(outbounds_table, gen_outbound(youtube_server, "youtube", 2081))
table.insert(outbounds_table, gen_outbound(tw_video_server, "twvideo", 2082))
table.insert(outbounds_table, gen_outbound(netflix_server, "netflix", 2083))
table.insert(outbounds_table, gen_outbound(disney_server, "disney", 2084))
table.insert(outbounds_table, gen_outbound(prime_server, "prime", 2085))
table.insert(outbounds_table, gen_outbound(tvb_server, "tvb", 2086))
table.insert(outbounds_table, gen_outbound(custom_server, "custom", 2087))
else
table.insert(outbounds_table, gen_outbound(server_section, "main",local_port))
table.insert(outbounds_table,
gen_outbound(server_section, "main", local_port))
end
-- rules gen
@ -119,20 +119,10 @@ end
local youtube_rule = {
type = "field",
domain = {
"youtube",
"ggpht.com",
"googlevideo.com",
"withyoutube.com",
"youtu.be",
"youtube-nocookie.com",
"youtube.com",
"youtubeeducation.com",
"youtubegaming.com",
"youtubei.googleapis.com",
"youtubekids.com",
"youtubemobilesupport.com",
"yt.be",
"ytimg.com"
"youtube", "ggpht.com", "googlevideo.com", "withyoutube.com",
"youtu.be", "youtube-nocookie.com", "youtube.com",
"youtubeeducation.com", "youtubegaming.com", "youtubei.googleapis.com",
"youtubekids.com", "youtubemobilesupport.com", "yt.be", "ytimg.com"
},
outboundTag = "youtube"
}
@ -140,15 +130,8 @@ local youtube_rule = {
local tw_video_rule = {
type = "field",
domain = {
"vidol.tv",
"hinet.net",
"books.com",
"litv.tv",
"pstatic.net",
"app-measurement.com",
"kktv.com.tw",
"gamer.com.tw",
"wetv.vip"
"vidol.tv", "hinet.net", "books.com", "litv.tv", "pstatic.net",
"app-measurement.com", "kktv.com.tw", "gamer.com.tw", "wetv.vip"
},
outboundTag = "twvideo"
}
@ -156,20 +139,12 @@ local tw_video_rule = {
local netflix_rule = {
type = "field",
domain = {
"fast.com",
"netflix.ca",
"netflix.com",
"netflix.net",
"netflixinvestor.com",
"netflixtechblog.com",
"nflxext.com",
"nflximg.com",
"nflximg.net",
"nflxsearch.net",
"nflxso.net",
"fast.com", "netflix.ca", "netflix.com", "netflix.net",
"netflixinvestor.com", "netflixtechblog.com", "nflxext.com",
"nflximg.com", "nflximg.net", "nflxsearch.net", "nflxso.net",
"nflxvideo.net"
},
outboundTag = "netflix"
}
@ -185,17 +160,9 @@ local disney_rule = {
local prime_rule = {
type = "field",
domain = {
"aiv-cdn.net",
"amazonaws.com",
"amazonvideo.com",
"llnwd.net",
"amazonprimevideos.com",
"amazonvideo.cc",
"prime-video.com",
"primevideo.cc",
"primevideo.com",
"primevideo.info",
"primevideo.org",
"aiv-cdn.net", "amazonaws.com", "amazonvideo.com", "llnwd.net",
"amazonprimevideos.com", "amazonvideo.cc", "prime-video.com",
"primevideo.cc", "primevideo.com", "primevideo.info", "primevideo.org",
"rimevideo.tv"
},
outboundTag = "prime"
@ -203,10 +170,7 @@ local prime_rule = {
local tvb_rule = {
type = "field",
domain = {
"tvsuper.com",
"tvb.com"
},
domain = {"tvsuper.com", "tvb.com"},
outboundTag = "tvb"
}
@ -259,7 +223,9 @@ local v2ray = {
protocol = "dokodemo-door",
settings = {network = proto, followRedirect = true},
sniffing = {enabled = true, destOverride = {"http", "tls"}},
streamSettings = {sockopt = { tproxy = (proto == "tcp") and "redirect" or "tproxy"}}
streamSettings = {
sockopt = {tproxy = (proto == "tcp") and "redirect" or "tproxy"}
}
}
},

View File

@ -1,4 +1,4 @@
local ucursor = require "luci.model.uci".cursor()
local ucursor = require"luci.model.uci".cursor()
local name = "vssr"
local json = require "luci.jsonc"
local proto = "socks"
@ -7,36 +7,25 @@ local local_port = ucursor:get_first(name, 'socks5_proxy', 'local_port')
local Socks_user = ucursor:get_first(name, 'socks5_proxy', 'Socks_user')
local Socks_pass = ucursor:get_first(name, 'socks5_proxy', 'Socks_pass')
local v2ray = {
log = {
--error = "/var/log/v2ray.log",
loglevel = "warning"
},
-- 传入连接
inbound = {
port = local_port,
protocol = proto,
settings = {
auth = (auth_type == '1') and "password" or "noauth",
accounts =(auth_type == "1") and {
{
user = (auth_type == '1') and Socks_user,
pass = Socks_pass
}
} or nil,
}
},
-- 传出连接
outbound = {
protocol = "freedom"
},
-- 额外传出连接
outboundDetour = {
{
protocol = "blackhole",
tag = "blocked"
}
}
log = {
-- error = "/var/log/v2ray.log",
loglevel = "warning"
},
-- 传入连接
inbound = {
port = local_port,
protocol = proto,
settings = {
auth = (auth_type == '1') and "password" or "noauth",
accounts = (auth_type == "1") and
{{user = (auth_type == '1') and Socks_user, pass = Socks_pass}} or
nil
}
},
-- 传出连接
outbound = {protocol = "freedom"},
-- 额外传出连接
outboundDetour = {{protocol = "blackhole", tag = "blocked"}}
}
print(json.stringify(v2ray,1))
print(json.stringify(v2ray, 1))

View File

@ -3,23 +3,19 @@
mkdir -p /tmp/dnsmasq.ssr
awk '!/^$/&&!/^#/{printf("ipset=/.%s/'"gfwlist"'\n",$0)}' /etc/config/gfw.list > /tmp/dnsmasq.ssr/custom_forward.conf
awk '!/^$/&&!/^#/{printf("server=/.%s/'"127.0.0.1#5335"'\n",$0)}' /etc/config/gfw.list >> /tmp/dnsmasq.ssr/custom_forward.conf
awk '!/^$/&&!/^#/{printf("ipset=/.%s/'"gfwlist"'\n",$0)}' /etc/config/gfw.list >/tmp/dnsmasq.ssr/custom_forward.conf
awk '!/^$/&&!/^#/{printf("server=/.%s/'"127.0.0.1#5335"'\n",$0)}' /etc/config/gfw.list >>/tmp/dnsmasq.ssr/custom_forward.conf
awk '!/^$/&&!/^#/{printf("ipset=/.%s/'"blacklist"'\n",$0)}' /etc/config/black.list > /tmp/dnsmasq.ssr/blacklist_forward.conf
awk '!/^$/&&!/^#/{printf("server=/.%s/'"127.0.0.1#5335"'\n",$0)}' /etc/config/black.list >> /tmp/dnsmasq.ssr/blacklist_forward.conf
awk '!/^$/&&!/^#/{printf("ipset=/.%s/'"blacklist"'\n",$0)}' /etc/config/black.list >/tmp/dnsmasq.ssr/blacklist_forward.conf
awk '!/^$/&&!/^#/{printf("server=/.%s/'"127.0.0.1#5335"'\n",$0)}' /etc/config/black.list >>/tmp/dnsmasq.ssr/blacklist_forward.conf
awk '!/^$/&&!/^#/{printf("ipset=/.%s/'"whitelist"'\n",$0)}' /etc/config/white.list > /tmp/dnsmasq.ssr/whitelist_forward.conf
awk '!/^$/&&!/^#/{printf("ipset=/.%s/'"whitelist"'\n",$0)}' /etc/config/white.list >/tmp/dnsmasq.ssr/whitelist_forward.conf
function valid_ip()
{
function valid_ip() {
ip=$1
read_ip=$(echo $ip|awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}')
if echo $ip|grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' >/dev/null
then
if [ $read_ip == "yes" ]
then
read_ip=$(echo $ip | awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}')
if echo $ip | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' >/dev/null; then
if [ $read_ip == "yes" ]; then
return 0
else
return 1
@ -32,14 +28,14 @@ function valid_ip()
config_load vssr
function addWhiteList() {
local iface="$1"
local host
config_get host "$iface" server
if valid_ip $host; then
ipset -! add whitelist $host
else
[ ! -z "$host" ] && echo "ipset=/.$host/whitelist" >> /tmp/dnsmasq.ssr/whitelist_forward.conf
fi
local iface="$1"
local host
config_get host "$iface" server
if valid_ip $host; then
ipset -! add whitelist $host
else
[ ! -z "$host" ] && echo "ipset=/.$host/whitelist" >>/tmp/dnsmasq.ssr/whitelist_forward.conf
fi
}
config_foreach addWhiteList
config_foreach addWhiteList

View File

@ -9,7 +9,6 @@ require 'luci.util'
require 'luci.jsonc'
require 'luci.sys'
-- these global functions are accessed all the time by the event handler
-- so caching them is worth the effort
local luci = luci
@ -210,7 +209,7 @@ local function processData(szType, content)
end
result.encrypt_method_ss = method
result.password = password
elseif szType == "trojan" then
local idx_sp = 0
local alias = ""
@ -263,14 +262,16 @@ local function processData(szType, content)
result.alias = alias
result.switch_enable = switch_enable
local vssrutil = require "vssrutil"
result.flag = vssrutil.get_flag(result.alias,result.server)
result.flag = vssrutil.get_flag(result.alias, result.server)
return result
end
-- wget
local function wget(url)
local stdout = luci.sys.exec('wget-ssl -q --user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36" --no-check-certificate -t 3 -T 10 -O- "' .. url .. '"')
return trim(stdout)
local stdout = luci.sys.exec(
'wget-ssl -q --user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36" --no-check-certificate -t 3 -T 10 -O- "' ..
url .. '"')
return trim(stdout)
end
local execute = function()

View File

@ -1,4 +1,5 @@
#!/usr/bin/lua
------------------------------------------------
-- This file is part of the luci-app-ssr-plus update.lua
-- By Mattraks
@ -7,101 +8,103 @@ require 'nixio'
require 'luci.util'
require 'luci.jsonc'
require 'luci.sys'
local icount =0
local icount = 0
local ucic = luci.model.uci.cursor()
local log = function(...)
print(os.date("%Y-%m-%d %H:%M:%S ") .. table.concat({ ... }, " "))
print(os.date("%Y-%m-%d %H:%M:%S ") .. table.concat({...}, " "))
end
log('正在更新【GFW列表】数据库')
if nixio.fs.access("/usr/bin/wget-ssl") then
refresh_cmd="wget-ssl --no-check-certificate https://cdn.jsdelivr.net/gh/gfwlist/gfwlist/gfwlist.txt -O /tmp/gfw.b64"
else
refresh_cmd="wget -O /tmp/gfw.b64 http://iytc.net/tools/list.b64"
end
sret=luci.sys.call(refresh_cmd .. " 2>/dev/null")
if sret== 0 then
luci.sys.call("/usr/bin/vssr-gfw")
icount = luci.sys.exec("cat /tmp/gfwnew.txt | wc -l")
if tonumber(icount)>1000 then
oldcount=luci.sys.exec("cat /etc/dnsmasq.ssr/gfw_list.conf | wc -l")
if tonumber(icount) ~= tonumber(oldcount) then
luci.sys.exec("cp -f /tmp/gfwnew.txt /etc/dnsmasq.ssr/gfw_list.conf")
-- retstring=tostring(math.ceil(tonumber(icount)/2))
log('更新成功! 新的总纪录数:'.. icount)
else
log('你已经是最新数据,无需更新!')
end
else
log('更新失败!')
end
luci.sys.exec("rm -f /tmp/gfwnew.txt")
refresh_cmd =
"wget-ssl --no-check-certificate https://cdn.jsdelivr.net/gh/gfwlist/gfwlist/gfwlist.txt -O /tmp/gfw.b64"
else
log('更新失败!')
refresh_cmd = "wget -O /tmp/gfw.b64 http://iytc.net/tools/list.b64"
end
sret = luci.sys.call(refresh_cmd .. " 2>/dev/null")
if sret == 0 then
luci.sys.call("/usr/bin/vssr-gfw")
icount = luci.sys.exec("cat /tmp/gfwnew.txt | wc -l")
if tonumber(icount) > 1000 then
oldcount = luci.sys.exec("cat /etc/dnsmasq.ssr/gfw_list.conf | wc -l")
if tonumber(icount) ~= tonumber(oldcount) then
luci.sys
.exec("cp -f /tmp/gfwnew.txt /etc/dnsmasq.ssr/gfw_list.conf")
-- retstring=tostring(math.ceil(tonumber(icount)/2))
log('更新成功! 新的总纪录数:' .. icount)
else
log('你已经是最新数据,无需更新!')
end
else
log('更新失败!')
end
luci.sys.exec("rm -f /tmp/gfwnew.txt")
else
log('更新失败!')
end
log('正在更新【国内IP段】数据库')
refresh_cmd="wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' 2>/dev/null| awk -F\\| '/CN\\|ipv4/ { printf(\"%s/%d\\n\", $4, 32-log($5)/log(2)) }' > /tmp/china_ssr.txt"
sret=luci.sys.call(refresh_cmd)
refresh_cmd =
"wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' 2>/dev/null| awk -F\\| '/CN\\|ipv4/ { printf(\"%s/%d\\n\", $4, 32-log($5)/log(2)) }' > /tmp/china_ssr.txt"
sret = luci.sys.call(refresh_cmd)
icount = luci.sys.exec("cat /tmp/china_ssr.txt | wc -l")
if sret== 0 then
icount = luci.sys.exec("cat /tmp/china_ssr.txt | wc -l")
if tonumber(icount)>1000 then
oldcount=luci.sys.exec("cat /etc/china_ssr.txt | wc -l")
if tonumber(icount) ~= tonumber(oldcount) then
luci.sys.exec("cp -f /tmp/china_ssr.txt /etc/china_ssr.txt")
-- retstring=tostring(math.ceil(tonumber(icount)/2))
log('更新成功! 新的总纪录数:'.. icount)
else
log('你已经是最新数据,无需更新!')
end
else
log('更新失败!')
end
luci.sys.exec("rm -f /tmp/china_ssr.txt")
if sret == 0 then
icount = luci.sys.exec("cat /tmp/china_ssr.txt | wc -l")
if tonumber(icount) > 1000 then
oldcount = luci.sys.exec("cat /etc/china_ssr.txt | wc -l")
if tonumber(icount) ~= tonumber(oldcount) then
luci.sys.exec("cp -f /tmp/china_ssr.txt /etc/china_ssr.txt")
-- retstring=tostring(math.ceil(tonumber(icount)/2))
log('更新成功! 新的总纪录数:' .. icount)
else
log('你已经是最新数据,无需更新!')
end
else
log('更新失败!')
end
luci.sys.exec("rm -f /tmp/china_ssr.txt")
else
log('更新失败!')
log('更新失败!')
end
-- --[[
if ucic:get_first('vssr', 'global', 'adblock', '') == '1' then
log('正在更新【广告屏蔽】数据库')
local need_process = 0
if nixio.fs.access("/usr/bin/wget-ssl") then
refresh_cmd="wget-ssl --no-check-certificate -O - https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt > /tmp/adnew.conf"
need_process = 1
else
refresh_cmd="wget -O /tmp/ad.conf http://iytc.net/tools/ad.conf"
end
sret=luci.sys.call(refresh_cmd .. " 2>/dev/null")
if sret== 0 then
if need_process == 1 then
luci.sys.call("/usr/bin/vssr-ad")
end
icount = luci.sys.exec("cat /tmp/ad.conf | wc -l")
if tonumber(icount)>1000 then
if nixio.fs.access("/etc/dnsmasq.ssr/ad.conf") then
oldcount=luci.sys.exec("cat /etc/dnsmasq.ssr/ad.conf | wc -l")
else
oldcount=0
end
if tonumber(icount) ~= tonumber(oldcount) then
luci.sys.exec("cp -f /tmp/ad.conf /etc/dnsmasq.ssr/ad.conf")
-- retstring=tostring(math.ceil(tonumber(icount)))
if oldcount==0 then
luci.sys.call("/etc/init.d/dnsmasq restart")
end
log('更新成功! 新的总纪录数:'.. icount)
else
log('你已经是最新数据,无需更新!')
end
else
log('更新失败!')
end
luci.sys.exec("rm -f /tmp/ad.conf")
else
log('更新失败!')
end
log('正在更新【广告屏蔽】数据库')
local need_process = 0
if nixio.fs.access("/usr/bin/wget-ssl") then
refresh_cmd =
"wget-ssl --no-check-certificate -O - https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt > /tmp/adnew.conf"
need_process = 1
else
refresh_cmd = "wget -O /tmp/ad.conf http://iytc.net/tools/ad.conf"
end
sret = luci.sys.call(refresh_cmd .. " 2>/dev/null")
if sret == 0 then
if need_process == 1 then luci.sys.call("/usr/bin/vssr-ad") end
icount = luci.sys.exec("cat /tmp/ad.conf | wc -l")
if tonumber(icount) > 1000 then
if nixio.fs.access("/etc/dnsmasq.ssr/ad.conf") then
oldcount = luci.sys.exec("cat /etc/dnsmasq.ssr/ad.conf | wc -l")
else
oldcount = 0
end
if tonumber(icount) ~= tonumber(oldcount) then
luci.sys.exec("cp -f /tmp/ad.conf /etc/dnsmasq.ssr/ad.conf")
-- retstring=tostring(math.ceil(tonumber(icount)))
if oldcount == 0 then
luci.sys.call("/etc/init.d/dnsmasq restart")
end
log('更新成功! 新的总纪录数:' .. icount)
else
log('你已经是最新数据,无需更新!')
end
else
log('更新失败!')
end
luci.sys.exec("rm -f /tmp/ad.conf")
else
log('更新失败!')
end
end
-- --]]

View File

@ -1,5 +1,5 @@
@import url("flag-icon.min.css");
@import url("sweetalert2.css?v=2");
@import url("flag-icon.min.css?v=1.16");
@import url("sweetalert2.css?v=1.16");
/*!
Pure v1.0.1
Copyright 2013 Yahoo!
@ -225,7 +225,7 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
}
.pure-u-23-24 {
width: 95.8333%
width: 95.8333%
}
.pure-u-1,
@ -251,7 +251,7 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
overflow-y: hidden;
border: 1px solid rgba(0, 0, 0, .05);
border-radius: .375rem;
background-color:#fff;
background-color: #fff;
box-shadow: 0 0 2rem 0 rgba(136, 152, 170, .15);
}
@ -259,14 +259,17 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
margin: 1rem;
}
.pure-img{
.pure-img {
max-height: 100%;
width: auto;
}
.pure-imgw{
.pure-imgw {
max-width: 100%;
height: auto;
}
.green {
font-size: 1.25rem;
color: #2dce89;
@ -308,10 +311,12 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
color: #8898aa !important;
line-height: 1.8em;
}
.p-in5{
.p-in5 {
padding: 8px;
}
.flag-icon:before{
.flag-icon:before {
position: absolute;
}
@ -328,21 +333,23 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
line-height: 1.7em;
overflow: hidden;
letter-spacing: normal;
}
.cbi-section-table-row:hover{
background: #fff;
}
.cbi-section-table-row.fast{
.cbi-section-table-row:hover {
background: #fff;
}
.cbi-section-table-row.fast {
background: #5e72e4;
color: #fff;
}
.cbi-section-table-row.fast .ssr-button{
.cbi-section-table-row.fast .ssr-button {
color: #fff;
}
.cbi-section-table-row.fast .ssr-button:hover,
.cbi-section-table-row.fast .ssr-button:focus,
.cbi-section-table-row.fast .ssr-button:active {
@ -352,7 +359,7 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
box-shadow: none;
}
.cbi-section-table-row.fast .host_con{
.cbi-section-table-row.fast .host_con {
color: #fff !important;
}
@ -386,15 +393,18 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
}
.alias{
margin-bottom:1px;
.alias {
margin-bottom: 1px;
}
.incon{
.incon {
cursor: pointer;
}
.incon .pure-imgw{
.incon .pure-imgw {
transition: all 0.2s;
}
.incon:nth-child(2) {
position: absolute;
left: 0;
@ -404,9 +414,10 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
border: 0;
border-right: #d1dfed 1px solid;
background-position: top;
}
.incon:nth-child(2) .tp{
.incon:nth-child(2) .tp {
position: absolute;
left: 0;
bottom: 0;
@ -492,48 +503,56 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
padding: 0.1rem 0.5rem;
border-radius: 0.2rem;
}
footer.mobile-hide{
footer.mobile-hide {
display: block;
}
.mar-10 {margin-left: 50px; margin-right: 10px;}
.mar-10 {
margin-left: 50px;
margin-right: 10px;
}
.status-bar{
.status-bar {
position: fixed;
bottom: 0;
right: 0;
box-shadow: 0 0 2rem 0 rgba(136,152,170,.3);
box-shadow: 0 0 2rem 0 rgba(136, 152, 170, .3);
color: #525f7f;
background: #fff;
z-index: 5;
box-sizing: border-box;
}
.status-bar .inner{
.status-bar .inner {
margin: 1em;
}
.status-bar .inner .flag{
.status-bar .inner .flag {
height: 3em;
display: block;
float: left;
margin-right: 1em;
}
.status-bar .inner .status-info{
.status-bar .inner .status-info {
font-weight: bold;
}
.status-bar .icon-con{
.status-bar .icon-con {
height: 3em;
text-align: right;
}
.choose_node .gap{
margin:0.5rem 1rem;
position:relative;
.choose_node .gap {
margin: 0.5rem 1rem;
position: relative;
}
.choose_node .gap .cbi-button{
width:100% !important;
.choose_node .gap .cbi-button {
width: 100% !important;
}
@media screen and (max-width: 2000px) {
.pure-u-1-5 {
width: 25%;
@ -589,8 +608,9 @@ footer.mobile-hide{
border-color: #fb6340 !important;
box-shadow: 0 0 1rem 0 rgba(136, 152, 170, .75);
}
.choose_node .pure-u-1-2{
width:50%;
.choose_node .pure-u-1-2 {
width: 50%;
}
}
@ -626,6 +646,8 @@ footer.mobile-hide{
.modals h2 {
padding: 0 !important;
background-color: transparent !important;
color: #fff !important;
}
.modals h3 {
@ -642,6 +664,7 @@ footer.mobile-hide{
height: calc(100% - 4rem);
font-family: 'Lucida Console';
font-size: 11px;
line-height: 1.5em;
background: transparent;
color: #FFFFFF;
outline: none;
@ -678,23 +701,26 @@ footer.mobile-hide{
left: 0;
top: 0;
}
.status-bar .pure-u-1-2{
.status-bar .pure-u-1-2 {
width: 50%;
}
.status-bar .inner .flag{
.status-bar .inner .flag {
height: 3em;
display: block;
float: left;
margin-right: 1em;
}
.status-bar .icon-con{
.status-bar .icon-con {
height: 2.5em;
text-align: right;
}
}
@media (prefers-color-scheme: dark) {
.block {
@media (prefers-color-scheme: dark) {
.block {
background-color: #3c3c3c !important;
box-shadow: 0 0 0.5rem 0 rgba(0, 0, 0, 0.35);
}
@ -704,11 +730,12 @@ footer.mobile-hide{
background-color: #3c3c3c !important;
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.35);
}
.incon:nth-child(2) {
border-right: #1e1e1e 1px solid;
}
.ssr-button {
color: #ccc;
}
}
.incon:nth-child(2) {
border-right: #1e1e1e 1px solid;
}
.ssr-button {
color: #ccc;
}
}