luci-app-vssr-coexist: sync with upstream source

This commit is contained in:
CN_SZTL 2020-02-17 11:03:14 +08:00
parent d2fdf181d6
commit b7d59feba7
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
4 changed files with 120 additions and 2 deletions

View File

@ -22,9 +22,10 @@ end
entry({"admin", "vpn", "vssr", "subscription"},cbi("vssr/subscription"), _("Subscription"),12).leaf = true
entry({"admin", "vpn", "vssr", "control"}, cbi("vssr/control"),
_("Access Control"), 13).leaf = true -- 访问控制
entry({"admin", "vpn", "vssr", "servers-list"}, cbi("vssr/servers-list"),
_("Severs Nodes"), 14).leaf = true
entry({"admin", "vpn", "vssr", "advanced"}, cbi("vssr/advanced"),
_("Advanced Settings"), 14).leaf = true -- 高级设置
_("Advanced Settings"), 15).leaf = true -- 高级设置
elseif nixio.fs.access("/usr/bin/ssr-server") then
entry({"admin", "vpn", "vssr"},
alias("admin", "vpn", "vssr", "server"), _("vssr"), 10).dependent =
@ -45,6 +46,7 @@ entry({"admin", "vpn", "vssr", "status"},form("vssr/status"),_("Status"), 23).le
entry({"admin", "vpn", "vssr", "refresh"}, call("refresh_data")) -- 更新白名单和GFWLIST
entry({"admin", "vpn", "vssr", "checkport"}, call("check_port")) -- 检测单个端口并返回Ping
entry({"admin", "vpn", "vssr", "checkports"}, call("check_ports"))
entry({"admin", "vpn", "vssr", "ping"}, call("act_ping")).leaf=true
entry({"admin", "vpn", "vssr", "run"}, call("act_status")) -- 检测全局服务器状态
entry({"admin", "vpn", "vssr", "change"}, call("change_node")) -- 切换节点
entry({"admin", "vpn", "vssr", "allserver"}, call("get_servers")) -- 获取所有节点Json
@ -196,6 +198,14 @@ function act_status()
luci.http.write_json(e)
end
function act_ping()
local e={}
e.index=luci.http.formvalue("index")
e.ping=luci.sys.exec("ping -c 1 -W 1 %q 2>&1 | grep -o 'time=[0-9]*.[0-9]' | awk -F '=' '{print$2}'"%luci.http.formvalue("domain"))
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)

View File

@ -0,0 +1,77 @@
-- Licensed to the public under the GNU General Public License v3.
local d = require "luci.dispatcher"
local fs = require "nixio.fs"
local sys = require "luci.sys"
local uci = require "luci.model.uci".cursor()
local m, s, o
local vssr = "vssr"
local uci = luci.model.uci.cursor()
local server_count = 0
uci:foreach("vssr", "servers", function(s)
server_count = server_count + 1
end)
m = Map(vssr)
m:section(SimpleSection).template = "vssr/status"
-- [[ Servers Manage ]]--
s = m:section(TypedSection, "servers")
s.anonymous = true
s.addremove = true
s.description = string.format(translate("Server Count") .. ": %d", server_count)
s.sortable = true
s.template = "cbi/tblsection"
s.extedit = luci.dispatcher.build_url("admin/vpn/vssr/servers/%s")
function s.create(...)
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(s.extedit % sid)
return
end
end
o = s:option(DummyValue, "type", translate("Type"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("")
end
o = s:option(DummyValue, "alias", translate("Alias"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = s:option(DummyValue, "server", translate("Server Address"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
o = s:option(DummyValue, "server_port", translate("Server Port"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
o = s:option(DummyValue, "encrypt_method", translate("Encrypt Method"))
o.width="10%"
o = s:option(DummyValue, "protocol", translate("Protocol"))
o.width="10%"
o = s:option(DummyValue, "obfs", translate("Obfs"))
o.width="10%"
o = s:option(Flag, "switch_enable", translate("Enable Auto Switch"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
o = s:option(DummyValue,"server",translate("Ping Latency"))
o.template="vssr/ping1"
o.width="10%"
m:append(Template("vssr/server_list"))
return m

View File

@ -0,0 +1,28 @@
<%+cbi/valueheader%>
<span class="pingtime" hint="<%=self:cfgvalue(section)%>">-- ms</span>
<%+cbi/valuefooter%>
</fieldset>
<!-- /tblsection --><script type="text/javascript">
//<![CDATA[
var pings = document.getElementsByClassName('pingtime');
for(var i = 0; i < pings.length; i++) {
XHR.get('/cgi-bin/luci/admin/vpn/greatwall/ping', {
index: i,
domain: pings[i].getAttribute("hint")
},
function(x, result) {
pings[result.index].innerHTML = (result.ping ? "<b><font color=green>"+result.ping+"</font></b> ms" : "<b><font color=red> 检测失败 </font></b>");
}
);
XHR.poll(10,'/cgi-bin/luci/admin/vpn/greatwall/ping',{
index: i,
domain: pings[i].getAttribute("hint")
},
function(x, result) {
pings[result.index].innerHTML = (result.ping ? "<b><font color=green>"+result.ping+"</font></b> ms" : "<b><font color=red> 检测失败 </font></b>");
}
);
}
//]]>
</script>

View File

@ -48,6 +48,9 @@ msgid "Ping All Servers"
msgstr "PING 所有节点"
msgid "Ping Latency"
msgstr "Ping 延迟"
msgid "vssr Server"
msgstr "vssr 服务端"