luci-app-vssr: sync with upstream source

This commit is contained in:
CN_SZTL 2020-08-27 03:23:13 +08:00
parent bd0230f3f0
commit c43902f035
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
4 changed files with 82 additions and 47 deletions

View File

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

View File

@ -2,7 +2,6 @@
-- Licensed to the public under the GNU General Public License v3.
module("luci.controller.vssr", package.seeall)
function index()
if not nixio.fs.access("/etc/config/vssr") then return end
@ -59,20 +58,23 @@ end
function get_subscribe()
local cjson = require "luci.jsonc"
local e = {}
local name = "vssr"
local name = "vssr"
local uci = luci.model.uci.cursor()
local auto_update = luci.http.formvalue("auto_update")
local auto_update_time = luci.http.formvalue("auto_update_time")
local proxy = luci.http.formvalue("proxy")
local subscribe_url = luci.http.formvalue("subscribe_url")
if subscribe_url ~= "[]" then
uci:delete(name,"@server_subscribe[0]",subscribe_url)
uci:set(name,"@server_subscribe[0]","auto_update",auto_update)
uci:set(name,"@server_subscribe[0]","auto_update_time",auto_update_time)
uci:set(name,"@server_subscribe[0]","proxy",proxy)
uci:set_list(name,"@server_subscribe[0]","subscribe_url",cjson.parse(subscribe_url))
uci:delete(name, "@server_subscribe[0]", subscribe_url)
uci:set(name, "@server_subscribe[0]", "auto_update", auto_update)
uci:set(name, "@server_subscribe[0]", "auto_update_time",
auto_update_time)
uci:set(name, "@server_subscribe[0]", "proxy", proxy)
uci:set_list(name, "@server_subscribe[0]", "subscribe_url",
cjson.parse(subscribe_url))
uci:commit(name)
luci.sys.exec("nohup /usr/bin/lua /usr/share/vssr/subscribe.lua >/www/check_update.htm 2>/dev/null &")
luci.sys.exec(
"nohup /usr/bin/lua /usr/share/vssr/subscribe.lua >/www/check_update.htm 2>/dev/null &")
e.error = 0
else
e.error = 1
@ -102,16 +104,18 @@ function change_node()
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"}
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" and server ~= "udp_relay" ) 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')
if (v ~= server) then
uci:set("vssr", '@global[0]', v .. '_server', 'nil')
end
end
end
@ -123,14 +127,14 @@ function change_node()
luci.http.write_json(e)
end
--设置节点为自动切换
-- 设置节点为自动切换
function switch()
local e = {}
local uci = luci.model.uci.cursor()
local sid = luci.http.formvalue("node")
local isSwitch = uci:get("vssr", sid, "switch_enable")
local toSwitch = (isSwitch == "1") and "0" or "1"
uci:set("vssr", sid, "switch_enable",toSwitch)
uci:set("vssr", sid, "switch_enable", toSwitch)
uci:commit("vssr")
if isSwitch == "1" then
e.switch = false
@ -147,20 +151,20 @@ function act_status()
math.randomseed(os.time())
local e = {}
-- 全局服务器
e.global = luci.sys.call("busybox ps -w | grep vssr_t | grep -v grep >/dev/null") == 0
e.global = luci.sys.call(
"busybox ps -w | grep vssr_t | grep -v grep >/dev/null") == 0
-- 检测PDNSD状态
e.pdnsd = luci.sys.call("pidof pdnsd >/dev/null") == 0
-- 检测游戏模式状态
e.game = luci.sys.call("busybox ps -w | grep vssr_u | grep -v grep >/dev/null") == 0
e.game = luci.sys.call(
"busybox ps -w | grep vssr_u | grep -v grep >/dev/null") == 0
-- 检测Socks5
e.socks5 = luci.sys.call("busybox ps -w | grep vssr_s | grep -v grep >/dev/null") == 0
e.socks5 = luci.sys.call(
"busybox ps -w | grep vssr_s | grep -v grep >/dev/null") == 0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
-- 检测单个节点状态并返回连接速度
function check_port()
local sockets = require "socket"
@ -171,38 +175,47 @@ function check_port()
local t0 = sockets.gettime()
ret = vssr.check_site(set, port)
local t1 = sockets.gettime()
retstring = tostring(ret) == "true" and "1" or "0"
retstring = tostring(ret) == "true" and "1" or "0"
local tt = t1 - t0
luci.http.prepare_content("application/json")
luci.http.write_json({ret = retstring , used = math.floor(tt*1000 + 0.5)})
luci.http.write_json({ret = retstring, used = math.floor(tt * 1000 + 0.5)})
end
function get_iso(ip)
local mm = require 'maxminddb'
local db = mm.open('/usr/share/vssr/GeoLite2-Country.mmdb')
local res = db:lookup(ip)
return string.lower(res:get("country", "iso_code"))
end
function get_cname(ip)
local mm = require 'maxminddb'
local db = mm.open('/usr/share/vssr/GeoLite2-Country.mmdb')
local res = db:lookup(ip)
return string.lower(res:get("country", "names", "zh-CN"))
end
-- 获取当前代理状态 与节点ip
function check_ip()
local e = {}
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/")
d.flag = "un"
d.country = "Unknown"
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"
local status, code = pcall(get_iso, ip)
if (status) then d.flag = code end
local status1, country = pcall(get_cname, ip)
if (status1) then d.country = country end
end
e.outboard = ip
e.outboardip = d
e.baidu = vssr.check_site("www.baidu.com",port)
e.taobao = vssr.check_site("www.taobao.com",port)
e.google = vssr.check_site("www.google.com",port)
e.youtube = vssr.check_site("www.youtube.com",port)
e.baidu = vssr.check_site("www.baidu.com", port)
e.taobao = vssr.check_site("www.taobao.com", port)
e.google = vssr.check_site("www.google.com", port)
e.youtube = vssr.check_site("www.youtube.com", port)
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
@ -214,12 +227,11 @@ function get_flag()
local host = luci.http.formvalue("host")
local remark = luci.http.formvalue("remark")
e.host = host
e.flag = vssr.get_flag(remark,host)
e.flag = vssr.get_flag(remark, host)
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
-- 刷新检测文件
function refresh_data()
local set = luci.http.formvalue("set")
@ -311,4 +323,4 @@ function refresh_data()
end
luci.http.prepare_content("application/json")
luci.http.write_json({ret = retstring, retcount = icount})
end
end

View File

@ -11,8 +11,7 @@ local _M = {}
function _M.get_flag(remark, host)
local nixio = require "nixio"
local ip = require "luci.ip"
local mm = require 'maxminddb'
local db = mm.open('/usr/share/vssr/GeoLite2-Country.mmdb')
local iso_table = {
"AC", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS",
"AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH",
@ -100,10 +99,18 @@ function _M.get_flag(remark, host)
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"))
local ret = nixio.getaddrinfo(_M.trim(host), "any")
if(ret == nil) then
iso_code = "un"
else
local hostip = ret[1].address
local status,code = pcall(_M.get_iso,hostip)
if(status) then
iso_code = code
else
iso_code = "un"
end
end
else
iso_code = "un"
end
@ -111,6 +118,21 @@ function _M.get_flag(remark, host)
return string.gsub(iso_code, '\n', '')
end
function _M.get_iso(ip)
local mm = require 'maxminddb'
local db = mm.open('/usr/share/vssr/GeoLite2-Country.mmdb')
local res = db:lookup(ip)
return string.lower(res:get("country", "iso_code"))
end
function _M.get_cname(ip)
local mm = require 'maxminddb'
local db = mm.open('/usr/share/vssr/GeoLite2-Country.mmdb')
local res = db:lookup(ip)
return string.lower(res:get("country", "names", "zh-CN"))
end
-- Get status of conncet to any site with host and port
-- Return String:true or nil
function _M.check_site(host, port)
@ -129,7 +151,8 @@ function _M.trim(text)
end
function _M.wget(url)
local stdout = luci.sys.exec(
local sys = require "luci.sys"
local stdout = 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)