diff --git a/luci-app-netspeedtest/Makefile b/luci-app-netspeedtest/Makefile index c95f9396a..d094b15c1 100644 --- a/luci-app-netspeedtest/Makefile +++ b/luci-app-netspeedtest/Makefile @@ -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:= include $(TOPDIR)/feeds/luci/luci.mk diff --git a/luci-app-netspeedtest/luasrc/controller/netspeedtest.lua b/luci-app-netspeedtest/luasrc/controller/netspeedtest.lua index 0855e6797..b4288cedf 100644 --- a/luci-app-netspeedtest/luasrc/controller/netspeedtest.lua +++ b/luci-app-netspeedtest/luasrc/controller/netspeedtest.lua @@ -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 diff --git a/luci-app-netspeedtest/luasrc/model/cbi/netspeedtest/speedtestport.lua b/luci-app-netspeedtest/luasrc/model/cbi/netspeedtest/speedtestport.lua new file mode 100644 index 000000000..cffa91fab --- /dev/null +++ b/luci-app-netspeedtest/luasrc/model/cbi/netspeedtest/speedtestport.lua @@ -0,0 +1,27 @@ +-- Copyright (C) 2020-2022 sirpdboy https://github.com/sirpdboy/netspeedtest +require("luci.util") +local o,t,e + +o = Map("netspeedtest", "" .. translate("Net Speedtest") .."",translate( "Network speed diagnosis test (including intranet and extranet)
For specific usage, see:") ..translate("GitHub @sirpdboy/netspeedtest") ) + +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 diff --git a/luci-app-netspeedtest/luasrc/view/netspeedtest/speedtestport.htm b/luci-app-netspeedtest/luasrc/view/netspeedtest/speedtestport.htm index 7a963249f..a4d8c36c0 100644 --- a/luci-app-netspeedtest/luasrc/view/netspeedtest/speedtestport.htm +++ b/luci-app-netspeedtest/luasrc/view/netspeedtest/speedtestport.htm @@ -1,79 +1,91 @@ <%# - Copyright 2020-2022 sirpdboy Wich + Copyright 2020-2024 sirpdboy Wich https://github.com/sirpdboy/netspeedtest Licensed to the public under the Apache License 2.0. -%> - - <%+cbi/valueheader%> +
+
+ + +
+
+ + -
- - - - - - - - - - - -
- -
<%:iperf3 instructions%><%:The speed measurement terminal must be in the same LAN as the router that starts the speed measurement%>
<%:Operation steps: start router speed measurement service download test client run speed measurement client input IP address of router speed measurement service%>
<%:Iperf3 speed measurement software download%> - -
- -
- <%+cbi/valuefooter%> diff --git a/luci-app-netspeedtest/luasrc/view/netspeedtest/speedtestwan.htm b/luci-app-netspeedtest/luasrc/view/netspeedtest/speedtestwan.htm index 7043756a3..e7f92765d 100644 --- a/luci-app-netspeedtest/luasrc/view/netspeedtest/speedtestwan.htm +++ b/luci-app-netspeedtest/luasrc/view/netspeedtest/speedtestwan.htm @@ -4,9 +4,11 @@ Licensed to the public under the Apache License 2.0. -%> <%+cbi/valueheader%> - + +
- +
+