luci-app-vssr: sync with upstream source

This commit is contained in:
CN_SZTL 2020-02-20 02:53:29 +08:00
parent 84438f6031
commit 0639c6e428
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
9 changed files with 103 additions and 28 deletions

View File

@ -132,7 +132,7 @@ function change_node()
if sid ~= "" then
uci:set("vssr", name, "global_server", sid)
uci:commit("vssr")
luci.sys.call("uci commit vssr && /etc/init.d/vssr restart")
luci.sys.call("/etc/init.d/vssr restart")
e.status = true
end
luci.http.prepare_content("application/json")
@ -271,13 +271,27 @@ if luci.sys.call("ps -w | grep trojan-server | grep -v grep >/dev/null") == 0 th
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"))
local e = {}
local domain = luci.http.formvalue("domain")
local port = luci.http.formvalue("port")
e.index = luci.http.formvalue("index")
local iret = luci.sys.call(" ipset add ss_spec_wan_ac " .. domain .. " 2>/dev/null")
local socket = nixio.socket("inet", "stream")
socket:setopt("socket", "rcvtimeo", 3)
socket:setopt("socket", "sndtimeo", 3)
e.socket = socket:connect(domain, port)
socket:close()
e.ping = luci.sys.exec("ping -c 1 -W 1 %q 2>&1 | grep -o 'time=[0-9]*.[0-9]' | awk -F '=' '{print$2}'" % domain)
if (iret == 0) then
luci.sys.call(" ipset del ss_spec_wan_ac " .. domain)
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)

View File

@ -104,6 +104,9 @@ function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
o = sec:option(DummyValue,"vmess_id",translate("ID"))
o.width="10%"
o = sec:option(DummyValue, "encrypt_method", translate("Encrypt Method"))
o.width="10%"

View File

@ -55,18 +55,15 @@ function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
o = s:option(DummyValue, "encrypt_method", translate("Encrypt Method"))
o = s:option(DummyValue,"security",translate("Encrypt Method"))
o.width="10%"
o = s:option(DummyValue, "protocol", translate("Protocol"))
o.width="10%"
o = s:option(DummyValue, "obfs", translate("Obfs"))
o = s:option(DummyValue, "server_port", translate("Socket Connected"))
o.template="vssr/socket"
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"

View File

@ -36,7 +36,8 @@ end
o.default=2
o.rmempty = false
o = s:option(DynamicList, "subscribe_url", translate("Subscribe URL"))
o = s:option(DynamicList, "subscribe_url", translate("Subscribe URL"),
translate("Before subscribing please click below to delete all servers in the subscription"))
o.rmempty = true
o = s:option(Flag, "proxy", translate("Through proxy update"))

View File

@ -2,23 +2,50 @@
Copyright 2018-2019 Lienol <lawlienol@gmail.com>
Licensed to the public under the Apache License 2.0.
-%>
<%
local dsp = require "luci.dispatcher"
-%>
<script type="text/javascript">
//<![CDATA[
var pings = document.getElementsByClassName('pingtime');
for(var i = 0; i < pings.length; i++) {
XHR.get('<%=dsp.build_url("admin/vpn/vssr/ping")%>', {
index: i,
domain: pings[i].getAttribute("hint")
const doms = document.getElementsByClassName('pingtime');
const ports = document.getElementsByClassName("socket-connected")
const xhr = (index) => {
return new Promise((res) => {
const dom = doms[index];
const port = ports[index];
if (!dom) res()
port.innerHTML = '<font color="#0072c3">connecting...</font>';
XHR.get('<%=dsp.build_url("admin/vpn/vssr/ping")%>', {
index,
domain: dom.getAttribute("hint"),
port: port.getAttribute("hint")
},
function(x, result) {
pings[result.index].innerHTML = (result.ping ? result.ping : "--") + " ms";
}
);
(x, result) => {
let col = '#ff0000';
if (result.ping) {
if (result.ping < 300) col = '#ff3300';
if (result.ping < 200) col = '#ff7700';
if (result.ping < 100) col = '#249400';
}
dom.innerHTML = `<font color="${col}">${(result.ping ? result.ping : "--") + " ms"}</font>`
if (result.socket) {
port.innerHTML = '<font color="#249400">ok</font>';
} else {
port.innerHTML = '<font color="#ff0000">fail</font>';
}
res();
});
})
}
let task = -1;
const thread = () => {
task = task + 1
if (doms[task]) {
xhr(task).then(thread);
}
}
for (let i = 0; i < 10; i++) {
thread()
}
//]]>
</script>

View File

@ -0,0 +1,3 @@
<%+cbi/valueheader%>
<span class="socket-connected" hint="<%=self:cfgvalue(section)%>">wait</span>
<%+cbi/valuefooter%>

View File

@ -0,0 +1,18 @@
<%+cbi/valueheader%>
<script type="text/javascript">//<![CDATA[
function subscribe(btn,dataname) {
btn.disabled = true;
btn.value = '<%:Refresh...%> ';
murl=dataname;
XHR.get('<%=luci.dispatcher.build_url("admin", "vpn", "vssr","subscribe")%>', { set:murl }, function(x,rv) {
// 先简单刷新后期如果重构会考虑下如何组织lua shell JavaScript之间的代码逻辑和各自的调用逻辑
window.location.reload()
// btn.disabled = false;
// btn.value = '<%:Refresh Data %>';
});
return false;
}
//]]></script>
<input type="button" class="cbi-button cbi-input-apply" value="<%:Update All Subscribe Severs%> " onclick="return subscribe(this,'<%=self.option%>')" />
<!-- <span id="<%=self.option%>-status"><em><%=self.value%></em></span> -->
<%+cbi/valuefooter%>

View File

@ -764,6 +764,9 @@ msgstr "启用管理控制台"
msgid "Service Port"
msgstr "端口"
msgid "Socket Connected"
msgstr "连接测试"
msgid "Enable HTTP Proxy"
msgstr "启用HTTP代理"
@ -771,5 +774,14 @@ msgstr "启用HTTP代理"
msgid "HTTP Port"
msgstr "HTTP代理端口"
msgid "plugin"
msgstr "插件"
msgid "Plugin Opts"
msgstr "插件参数"
msgid "Before subscribing please click below to delete all servers in the subscription"
msgstr "订阅前请点击下面的删除所有服务器在订阅"

View File

@ -312,7 +312,7 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
position: relative;
background: #CCFFFF;
margin: 10px;
padding: 8px 15px 10px 70px;
padding: 18px 18px 18px 88px;
box-shadow: 0 0 1rem 0 rgba(136,152,170,.75);
border-radius: .5rem;
border: 0;
@ -464,10 +464,10 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
background-color: #336633 !important;
border-color: #2e6da4 !important;
font-size:12px;
padding:0.5rem 0.8rem;
padding:0.6rem 0.8rem;
float:right;
margin-right:10px;
margin-top:0rem;
margin-top:-0.3rem;
}