2019-07-20 22:27:42 +08:00
|
|
|
-- Copyright (C) 2017 yushi studio <ywb94@qq.com>
-- Licensed to the public under the GNU General Public License v3.
module("luci.controller.shadowsocksr", package.seeall)
function index()
if not nixio.fs.access("/etc/config/shadowsocksr") then
return
end
entry({"admin", "services", "shadowsocksr"},alias("admin", "services", "shadowsocksr", "client"),_("ShadowSocksR Plus+"), 10).dependent = true
entry({"admin", "services", "shadowsocksr", "client"},cbi("shadowsocksr/client"),_("SSR Client"), 10).leaf = true
entry({"admin", "services", "shadowsocksr", "servers"}, arcombine(cbi("shadowsocksr/servers"), cbi("shadowsocksr/client-config")),_("Severs Nodes"), 20).leaf = true
entry({"admin", "services", "shadowsocksr", "control"},cbi("shadowsocksr/control"),_("Access Control"), 30).leaf = true
entry({"admin", "services", "shadowsocksr", "list"},form("shadowsocksr/list"),_("GFW List"), 40).leaf = true
entry({"admin", "services", "shadowsocksr", "oversealist"},form("shadowsocksr/oversealist"),_("Oversea List"), 50).leaf = true
entry({"admin", "services", "shadowsocksr", "advanced"},cbi("shadowsocksr/advanced"),_("Advanced Settings"), 60).leaf = true
if nixio.fs.access("/usr/bin/ssr-server") and nixio.fs.access("/usr/bin/ss-server") and nixio.fs.access("/usr/bin/v2ray/v2ray") then
entry({"admin", "services", "shadowsocksr", "server"},arcombine(cbi("shadowsocksr/server"), cbi("shadowsocksr/server-config")),_("SSR Server"), 70).leaf = true
end
entry({"admin", "services", "shadowsocksr", "status"},form("shadowsocksr/status"),_("Status"), 80).leaf = true
entry({"admin", "services", "shadowsocksr", "check"}, call("check_status"))
entry({"admin", "services", "shadowsocksr", "refresh"}, call("refresh_data"))
entry({"admin", "services", "shadowsocksr", "checkport"}, call("check_port"))
entry({"admin", "services", "shadowsocksr", "log"},form("shadowsocksr/log"),_("Log"), 90).leaf = true
entry({"admin", "services", "shadowsocksr", "run"},call("act_status")).leaf=true
entry({"admin", "services", "shadowsocksr", "ping"}, call("act_ping")).leaf=true
end
-- 检测全局服务器状态
function act_status()
local e={}
--全局服务器
e.global=luci.sys.call("ps -w | grep ssr-retcp | grep -v grep >/dev/null") == 0
--检测PDNSD状态
if tonumber(luci.sys.exec("ps -w | grep pdnsd |grep -v grep| wc -l"))>0 then
e.pdnsd= true
elseif tonumber(luci.sys.exec("ps -w | grep dnsparsing |grep -v grep| wc -l"))>0 then
e.pdnsd= true
elseif tonumber(luci.sys.exec("ps -w | grep dnscrypt-proxy |grep -v grep| wc -l"))>0 then
e.pdnsd= true
elseif tonumber(luci.sys.exec("ps -w | grep chinadns |grep -v grep| wc -l"))>0 then
e.pdnsd= true
end
--检测SOCKS5状态
if tonumber(luci.sys.exec("ps -w | grep ssr-local |grep -v grep| wc -l"))>0 then
e.SOCKS5= true
elseif tonumber(luci.sys.exec("ps -w | grep ss-local |grep -v grep| wc -l"))>0 then
e.SOCKS5= true
elseif tonumber(luci.sys.exec("ps -w | grep v2-ssr-local |grep -v grep| wc -l"))>0 then
e.SOCKS5= true
end
-- 检测游戏模式状态
e.game = false
if tonumber(luci.sys.exec("ps -w | grep ssr-reudp |grep -v grep| wc -l"))>0 then
e.game= true
else
if tonumber(luci.sys.exec("ps -w | grep ssr-retcp |grep \"\\-u\"|grep -v grep| wc -l"))>0 then
e.game= true
end
end
-- 检测国内通道
e.baidu = false
sret = luci.sys.call("/usr/bin/ssr-check www.baidu.com 80 3 1")
if sret == 0 then
e.baidu = true
end
-- 检测国外通道
e.google = false
sret = luci.sys.call("/usr/bin/ssr-check www.google.com 80 3 1")
if sret == 0 then
e.google = true
end
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
function check_status()
local set ="/usr/bin/ssr-check www." .. luci.http.formvalue("set") .. ".com 80 3 1"
sret=luci.sys.call(set)
if sret== 0 then
retstring ="0"
else
retstring ="1"
end
luci.http.prepare_content("application/json")
luci.http.write_json({ ret=retst
|