mirror of
https://github.com/kenzok8/small-package
synced 2025-01-08 13:27:36 +08:00
update 2024-03-04 21:26:03
This commit is contained in:
parent
7efe1d8f35
commit
e3fcfc0f18
@ -11,8 +11,8 @@ PKG_NAME:=luci-app-netspeedtest
|
||||
LUCI_TITLE:=LuCI Support for netspeedtest
|
||||
LUCI_DEPENDS:=+python3 +iperf3-ssl +homebox
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_VERSION:=2.1.5
|
||||
PKG_RELEASE:=2024027
|
||||
PKG_VERSION:=2.1.6
|
||||
PKG_RELEASE:=20240301
|
||||
PKG_MAINTAINER:=<https://github.com/sirpdboy/netspeedtest>
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
module("luci.controller.netspeedtest", package.seeall)
|
||||
local fs=require"nixio.fs"
|
||||
local sys = require "luci.sys"
|
||||
local sys=require "luci.sys"
|
||||
function index()
|
||||
|
||||
if not nixio.fs.access("/etc/config/netspeedtest") then return end
|
||||
@ -12,20 +12,37 @@ function index()
|
||||
entry({"admin","network","netspeedtest","homebox"},cbi("netspeedtest/homebox"),_("Lan homebox Web"),20).leaf = true
|
||||
entry({"admin","network","netspeedtest","speedtestiperf3"},cbi("netspeedtest/speedtestiperf3", {hideapplybtn=true, hidesavebtn=true, hideresetbtn=true}),_("Lan Speedtest Iperf3"),30).leaf = true
|
||||
entry({"admin","network","netspeedtest","speedtestwan"},cbi("netspeedtest/speedtestwan", {hideapplybtn=true, hidesavebtn=true, hideresetbtn=true}),_("Wan Speedtest"), 40).leaf = true
|
||||
|
||||
entry({"admin","network","netspeedtest","speedtestport"},cbi("netspeedtest/speedtestport", {hideapplybtn=true, hidesavebtn=true, hideresetbtn=true}),_("Server Port Latency Test"), 50).leaf = true
|
||||
entry({"admin", "network", "netspeedtest", "test_port"}, call("test_port"))
|
||||
entry({"admin", "network", "netspeedtest", "checknet"}, call("check_net"))
|
||||
entry({"admin", "network", "iperf3_status"}, call("iperf3_status"))
|
||||
|
||||
entry({"admin", "network","test_iperf0"}, post("test_iperf0"), nil).leaf = true
|
||||
entry({"admin", "network","test_iperf1"}, post("test_iperf1"), nil).leaf = true
|
||||
|
||||
entry({"admin", "network","test_iperf0"}, post("test_iperf0"), nil)
|
||||
entry({"admin", "network","test_iperf1"}, post("test_iperf1"), nil)
|
||||
entry({"admin","network","netspeedtest", "speedtestrun"}, call("speedtestrun"))
|
||||
entry({"admin","network","netspeedtest", "netperfrun"}, call("netperfrun"))
|
||||
|
||||
entry({"admin", "network", "netspeedtest", "realtime_log"}, call("get_log"))
|
||||
entry({"admin", "network", "netspeedtest", "dellog"},call("dellog"))
|
||||
end
|
||||
|
||||
function test_port()
|
||||
local e = {}
|
||||
local domain = luci.http.formvalue('domain')
|
||||
local port = luci.http.formvalue('port')
|
||||
local ip=sys.exec("echo "..domain.." | grep -E ^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$ || nslookup "..domain.." 2>/dev/null | grep Address | awk -F' ' '{print$NF}' | grep -E ^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$ | sed -n 1p")
|
||||
ip=sys.exec("echo -n "..ip)
|
||||
e.ping = luci.sys.exec(string.format("echo -n $(tcping -q -c 1 -i 1 -t 2 -p %s %s 2>&1 | grep -o 'time=[0-9]*.[0-9]*' | awk -F '=' '{print $2}') 2>/dev/null", port, ip))
|
||||
|
||||
e.type = "tcping"
|
||||
if r=="" then
|
||||
e.ping=sys.call("echo -n $(ping -c 1 -W 1 %q 2>&1 | grep -o 'time=[0-9]*.[0-9]*' | awk -F '=' '{print $2}') 2>/dev/null" % ip)
|
||||
e.type = "ping"
|
||||
end
|
||||
if e.ping=="" then e.ping="0" end
|
||||
sys.call(string.format("echo -ne '\n$(date +%Y-%m-%d' '%H:%M:%S) server:%s -- port:%s -- TCP:%s Ms' >> /var/log/netspeedtest.log",domain,port,e.ping))
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
|
||||
|
||||
function iperf3_status()
|
||||
local e={}
|
||||
@ -63,9 +80,9 @@ function test_iperf1(addr)
|
||||
end
|
||||
|
||||
function get_log()
|
||||
local e = {}
|
||||
e.running = sys.call("busybox ps -w | grep netspeedtest | grep -v grep >/dev/null") == 0
|
||||
e.log = fs.readfile("/var/log/netspeedtest.log") or ""
|
||||
local e={}
|
||||
e.running=sys.call("busybox ps -w | grep netspeedtest | grep -v grep >/dev/null") == 0
|
||||
e.log=fs.readfile("/var/log/netspeedtest.log") or ""
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
|
@ -0,0 +1,27 @@
|
||||
-- Copyright (C) 2020-2022 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/netspeedtest
|
||||
require("luci.util")
|
||||
local o,t,e
|
||||
|
||||
o = Map("netspeedtest", "<font color='green'>" .. translate("Net Speedtest") .."</font>",translate( "Network speed diagnosis test (including intranet and extranet)<br/>For specific usage, see:") ..translate("<a href=\'https://github.com/sirpdboy/netspeedtest.git' target=\'_blank\'>GitHub @sirpdboy/netspeedtest</a>") )
|
||||
|
||||
t = o:section(TypedSection, "speedtestport", translate('Server Port Latency Test'))
|
||||
t.addremove=false
|
||||
t.anonymous=true
|
||||
|
||||
e = t:option(Value, 'domain', translate('Test server address'))
|
||||
e.default = "www.baidu.com"
|
||||
|
||||
e.description = translate('Enter the domain name or IP address of the server that needs to be tested')
|
||||
|
||||
e = t:option(Value, 'port', translate('Test server port'))
|
||||
e.default = "443"
|
||||
|
||||
e = t:option(DummyValue, '', '')
|
||||
e.rawhtml = true
|
||||
e.template ='netspeedtest/speedtestport'
|
||||
|
||||
e =t:option(DummyValue, '', '')
|
||||
e.rawhtml = true
|
||||
e.template = 'netspeedtest/log'
|
||||
|
||||
return o
|
@ -1,79 +1,91 @@
|
||||
<%#
|
||||
Copyright 2020-2022 sirpdboy Wich <sirpdboy@qq.com>
|
||||
Copyright 2020-2024 sirpdboy Wich <sirpdboy@qq.com>
|
||||
https://github.com/sirpdboy/netspeedtest
|
||||
Licensed to the public under the Apache License 2.0.
|
||||
-%>
|
||||
|
||||
<script type="text/javascript" src="<%=resource%>/cbi.js?v=1.1"></script>
|
||||
<%+cbi/valueheader%>
|
||||
<div class="cbi-value" ><label class="cbi-value-title"><%= translate("Test server port delay") %></label>
|
||||
<div class="cbi-value-field">
|
||||
<input type="button" class="btn cbi-button cbi-button-apply" value='<%:Perform port test%>' onclick="return speedtestportrun(this, 'speedtestport')" />
|
||||
<span id="speedtestport-status"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
|
||||
var stxhr = new XHR();
|
||||
function update_status(field, proto)
|
||||
{
|
||||
var tool = field.name;
|
||||
var addr = field.value;
|
||||
var protocol = proto ;
|
||||
|
||||
var legend = document.getElementById('test-iperf-legend');
|
||||
var output = document.getElementById('test-iperf-output');
|
||||
if (legend && output)
|
||||
{
|
||||
output.innerHTML =
|
||||
'<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' +
|
||||
'<%:Waiting for command to complete...%>'
|
||||
;
|
||||
|
||||
legend.parentNode.style.display = 'block';
|
||||
legend.style.display = 'inline';
|
||||
function speedtestportrun(btn,sid) {
|
||||
var opt={
|
||||
base:"cbid.netspeedtest."+sid,
|
||||
get:function(opt){
|
||||
var id=this.base+'.'+opt;
|
||||
var obj=document.getElementsByName(id)[0] || document.getElementsByClassName(id)[0] || document.getElementById(id)
|
||||
if (obj){
|
||||
return obj;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
},
|
||||
getlist:function(opt){
|
||||
var id=this.base+'.'+opt;
|
||||
var objs=document.getElementsByName(id) || document.getElementsByClassName(id);
|
||||
var ret=[];
|
||||
if (objs){
|
||||
for (var i=0;i < objs.length;i++){
|
||||
ret[i]=objs[i].value;
|
||||
}
|
||||
}else{
|
||||
alert("<%:Fatal on get option,please help in debug%>:"+opt);
|
||||
}
|
||||
return ret;
|
||||
},
|
||||
query:function(param,src,tval="1",fval="0"){
|
||||
var ret="&"+param+"=";
|
||||
var obj=this.get(src);
|
||||
if (obj){
|
||||
if (obj.type=="checkbox"){
|
||||
return ret+(obj.checked==true ? tval:fval);
|
||||
}else{
|
||||
return ret+encodeURIComponent(obj.value);
|
||||
}
|
||||
}
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
stxhr.post('<%=url('admin/network')%>/test_' + tool + protocol + '/' + addr, { token: '<%=token%>' },
|
||||
function(x)
|
||||
{
|
||||
if (x.responseText)
|
||||
{
|
||||
legend.style.display = 'none';
|
||||
output.innerHTML = String.format('<pre>%h</pre>', x.responseText);
|
||||
const RUN_URL = '<%=luci.dispatcher.build_url("admin", "network", "netspeedtest","test_port")%>';
|
||||
const S_URL = '<%=luci.dispatcher.build_url("admin", "network", "netspeedtest","speedtestport")%>';
|
||||
|
||||
var output=document.getElementById("speedtestport-status");
|
||||
|
||||
btn.value='<%:Check...%>';
|
||||
btn.disabled=true;
|
||||
var xdomain=opt.get("domain").value;
|
||||
var xport=opt.get("port").value;
|
||||
console.log(xdomain);
|
||||
XHR.get(RUN_URL, {
|
||||
domain:xdomain,
|
||||
port:xport
|
||||
},
|
||||
function(x,rv) {
|
||||
|
||||
if (output)
|
||||
{
|
||||
console.log(x);
|
||||
if (rv.ping=="0")
|
||||
output.outerHTML = "<font style='color:red'><%:Test failed%></font>";
|
||||
else
|
||||
output.outerHTML = "<font style='color:green'><%:Test server port delay%> :" + rv.ping + " ms" + "</font>";
|
||||
}
|
||||
else
|
||||
{
|
||||
legend.style.display = 'none';
|
||||
output.innerHTML ='</p> <%:Operation execution complete%></p>';
|
||||
|
||||
}
|
||||
|
||||
btn.disabled=false;
|
||||
btn.value='<%:Perform port test%>';
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//]]></script>
|
||||
|
||||
<form method="post" action="<%=url('admin/network/netspeedtest')%>">
|
||||
<table>
|
||||
<tr><td class="cbi-value-title" ><input style="margin: 5px 0" type="hidden" value="" name="iperf" />
|
||||
<select name="iperf_to" style="width:auto">
|
||||
<option value="0" selected="selected"><%:iperfstart%></option>
|
||||
<option value="1"><%:iperfstop%></option>
|
||||
</select></td>
|
||||
<td class="cbi-value-field" style="width:100%;" >
|
||||
<input type="button" value="<%:Perform operation%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.iperf,this.form.iperf_to.selectedIndex)" /></td>
|
||||
</tr>
|
||||
<tr><td class="cbi-value-title" ><%:iperf3 instructions%></td>
|
||||
<td class="cbi-value-field" ><%:The speed measurement terminal must be in the same LAN as the router that starts the speed measurement%><br /><%:Operation steps: start router speed measurement service download test client run speed measurement client input IP address of router speed measurement service%></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="cbi-value-title"><%:Iperf3 speed measurement software download%></td>
|
||||
<td class="cbi-value-field" >
|
||||
<input type="button" class="cbi-button cbi-input-reload" value="<%:Domestic download password:%>cpd6" onclick="javascript:window.open('https://sipdboy.lanzoui.com/b01c3esih','target');" />
|
||||
<input type="button" class="cbi-button cbi-input-reload" value="<%:Download from foreign official websites%>" onclick="javascript:window.open('https://iperf.fr/iperf-download.php','target');" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
<fieldset class="cbi-section" style="display:none">
|
||||
<legend id="test-iperf-legend">
|
||||
<%:Collecting data...%>
|
||||
</legend>
|
||||
<span id="test-iperf-output"></span>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<%+cbi/valuefooter%>
|
||||
|
@ -4,9 +4,11 @@
|
||||
Licensed to the public under the Apache License 2.0.
|
||||
-%>
|
||||
<%+cbi/valueheader%>
|
||||
|
||||
<label class="cbi-value-title"><%= translate("Net Speedtest") %></label>
|
||||
<div class="cbi-value-field">
|
||||
<input class="cbi-button cbi-button-apply" id="update_service" type="button" onclick="run()" value="<%= translate('Perform Wan Speedtest') %>" />
|
||||
|
||||
</div>
|
||||
|
||||
<fieldset class="cbi-section" style="display:none">
|
||||
<legend id="wanspeedtest-legend">
|
||||
<%:Collecting data...%>
|
||||
|
@ -23,7 +23,7 @@ msgid "Lan Speedtest Iperf3"
|
||||
msgstr "内网iperf3吞吐测速"
|
||||
|
||||
msgid "Lan homebox Web"
|
||||
msgstr "内网测速网页版"
|
||||
msgstr "Homebox内网测速网页版"
|
||||
|
||||
msgid "Running state"
|
||||
msgstr "运行状态"
|
||||
@ -104,6 +104,24 @@ msgstr "网速测试中,请稍侯..."
|
||||
msgid "Download from foreign official websites"
|
||||
msgstr "国外官网"
|
||||
|
||||
msgid "Server Port Speedtest"
|
||||
msgstr "端口延迟测试"
|
||||
msgid "Server Port Latency Test"
|
||||
msgstr "服务器端口延迟测试"
|
||||
|
||||
msgid "Test server address"
|
||||
msgstr "测试服务器地址"
|
||||
|
||||
msgid "Test server port"
|
||||
msgstr "测试服务器端口"
|
||||
|
||||
msgid "Enter the domain name or IP address of the server that needs to be tested"
|
||||
msgstr "输入需要测试的服务器域名或者IP地址"
|
||||
|
||||
msgid "Test server port delay"
|
||||
msgstr "测试端口延时"
|
||||
|
||||
msgid "Perform port test"
|
||||
msgstr "执行测试"
|
||||
|
||||
msgid "Test failed"
|
||||
msgstr "测试失败"
|
||||
|
||||
|
@ -23,7 +23,7 @@ msgid "Lan Speedtest Iperf3"
|
||||
msgstr "内网iperf3吞吐测速"
|
||||
|
||||
msgid "Lan homebox Web"
|
||||
msgstr "内网测速网页版"
|
||||
msgstr "Homebox内网测速网页版"
|
||||
|
||||
msgid "Running state"
|
||||
msgstr "运行状态"
|
||||
@ -104,6 +104,24 @@ msgstr "网速测试中,请稍侯..."
|
||||
msgid "Download from foreign official websites"
|
||||
msgstr "国外官网"
|
||||
|
||||
msgid "Server Port Speedtest"
|
||||
msgstr "端口延迟测试"
|
||||
msgid "Server Port Latency Test"
|
||||
msgstr "服务器端口延迟测试"
|
||||
|
||||
msgid "Test server address"
|
||||
msgstr "测试服务器地址"
|
||||
|
||||
msgid "Test server port"
|
||||
msgstr "测试服务器端口"
|
||||
|
||||
msgid "Enter the domain name or IP address of the server that needs to be tested"
|
||||
msgstr "输入需要测试的服务器域名或者IP地址"
|
||||
|
||||
msgid "Test server port delay"
|
||||
msgstr "测试端口延时"
|
||||
|
||||
msgid "Perform port test"
|
||||
msgstr "执行测试"
|
||||
|
||||
msgid "Test failed"
|
||||
msgstr "测试失败"
|
||||
|
||||
|
@ -8,3 +8,7 @@ config speedtestiperf3 'speedtestiperf3'
|
||||
|
||||
config wanspeedtest 'wanspeedtest'
|
||||
option surl ' '
|
||||
|
||||
config speedtestport 'speedtestport'
|
||||
option domain ' '
|
||||
option port ' '
|
||||
|
Loading…
Reference in New Issue
Block a user