-
+<%local fs=require"nixio.fs"%>
+
+
+<%:reverse%>
+
-
-
+function poll_check(){
+var tag = document.getElementById('logview');
+tag.style.display="block"
+XHR.poll(3, '<%=url([[admin]], [[network]], [[netspeedtest]], [[netcheck]])%>', null,
+ function(x, data) {
+ var lv = document.getElementById('cbid.logview.test.conf');
+ if (x.responseText && lv) {
+ if (x.responseText=="\u0000"){
+ for(j = 0,len=this.XHR._q.length; j < len; j++) {
+ if (this.XHR._q[j].url == '<%=url([[admin]], [[network]], [[netspeedtest]], [[netcheck]])%>'){
+ this.XHR._q.splice(j,1);
+ checkbtn.disabled = false;
+ checkbtn.value = '<%:Click to execute%>';
+ break;
+ }
+ }
+ return
+ }
+ if (islogreverse){
+ lv.innerHTML = x.responseText.split('\n').reverse().join('\n')+lv.innerHTML;
+ }else{
+ lv.innerHTML += x.responseText;
+ }
+ }
+ }
+);}
+
+//]]>
+
<%+cbi/valuefooter%>
diff --git a/netspeedtest/luci-app-netspeedtest/root/etc/init.d/netspeedtest b/netspeedtest/luci-app-netspeedtest/root/etc/init.d/netspeedtest
index 0fd8a2a..eff8cf2 100644
--- a/netspeedtest/luci-app-netspeedtest/root/etc/init.d/netspeedtest
+++ b/netspeedtest/luci-app-netspeedtest/root/etc/init.d/netspeedtest
@@ -15,7 +15,15 @@ EXTRA_COMMANDS="wantest"
TMP_T=/var/netspeedtest_nstest.tmp
BINSPEEDTEST='/usr/bin/speedtest'
LOCK=/var/lock/netspeedtest_nstest.lock
+LOGD=/etc/netspeedtest
LOG=/var/log/netspeedtest.log
+LOGE=$LOGD/netspeedtest.log
+LOGT=$LOGD/netspeedtestpos
+[ -d "$LOGD" ] || mkdir -p $LOGD
+[ -f "$LOGE" ] || echo "start" > $LOG
+[ -f "$LOGT" ] || echo "start" > $LOGT
+[ -f "$LOG" ] || echo "start" > $LOG
+
MAX_LOG=500
limit_log() {
local logf=$1
@@ -29,10 +37,6 @@ limit_log() {
fi
}
-init_log() {
- local logf=$1
- [ ! -f "$logf" ] && echo "" > $logf
-}
echone() {
echo -ne $* >> $LOG
@@ -42,46 +46,50 @@ echone() {
wantest() {
[ -f $LOCK ] && exit
limit_log $LOG 500
- init_log $LOG
touch $LOCK
TESTMODE=$1
BINTEMP=$(git_bin_handle $TESTMODE)
- # [ -n "$BINTEMP" ] || return
- # echone "\n BINTEMP: $BINTEMP "
case $TESTMODE in
0)
- echo -ne "\n —————ookla-speedtest测速$TESTMODE—————" >> $LOG
- info=$($BINTEMP > $TMP_T 2>&1 )
- RESULT=$(echo "$TMP_T" | grep "URL" | awk '{print $NF}')
+ echo -ne "\n —————ookla-speedtest测速—————\n" | tee -a $LOG
+ $BINTEMP | tee $TMP_T
+ RESULT=$(cat $TMP_T | grep 'URL' | cut -c15-)
if [ -n "$RESULT" ] ;then
echo -ne "\n 测服信息:`cat $TMP_T | grep 'Server'| cut -c10- | awk -F: '{printf $2$3}'` 线路:`cat $TMP_T | grep 'ISP' | awk -F: '{printf $2}' ` 延时:`cat $TMP_T | grep 'Latency' | awk -F: '{printf $2}' | awk -F '(' '{printf $1}'`" >> $LOG
echo -ne "\n 下行速率:`cat $TMP_T | grep 'Download' |awk -F: '{printf $2}' | awk -F '(' '{printf $1}'` --" >> $LOG
echo -ne "-- 上行速率:`cat $TMP_T | grep 'Upload' |awk -F: '{printf $2}' | awk -F '(' '{printf $1}'`" >> $LOG
echo -ne "\n 测速结果图片链接:`cat $TMP_T | grep 'URL' | cut -c15-`" >> $LOG
- echo -ne "$RESULT"
else
- echo -ne "\n 因客户端在LUCI状态下无法执行,测试失败!" >> $LOG
- echo -ne "\n 请SSH登陆后输入 :/etc/init.d/netspeedtest wantest 0 然后等完成后,刷新后查看记录!" >> $LOG
+ echo -ne "\n 因客户端在LUCI下运行错误,测试失败!" | tee -a $LOG
+ echo -ne "\n 请SSH运行:/etc/init.d/netspeedtest wantest 0 测试,完成后,在日志中有测试结果!" | tee -a $LOG
fi
- echo -ne "\n 测试时间: `date +%Y-%m-%d' '%H:%M:%S`" >> $LOG
- echo -ne "\n ————————————————————\n" >> $LOG
+ echo -ne "\n 测试时间: `date +%Y-%m-%d' '%H:%M:%S`" | tee -a $LOG
+ echo -ne "\n ————————————————————\n" | tee -a $LOG
;;
- *)
- echo -ne "\n —————python3-speedtest测速$TESTMODE—————" >> $LOG
- info=$($BINTEMP > $TMP_T 2>&1 )
+ *)
+ echo -ne "\n —————python3-speedtest测速—————\n" | tee -a $LOG
+ $BINTEMP | tee $TMP_T
echo -ne "\n 测服信息:$(cat $TMP_T | grep 'Hosted by'| cut -c10- | awk -F: '{printf $1}') 延时:$(cat $TMP_T | grep 'Hosted by' | awk -F: '{printf $2}')" >> $LOG
- echo -ne "\n 下行速率:$(cat $TMP_T | grep 'Download:' |awk -F: '{printf $2}' )" >> $LOG
- echo -ne " ---- 上行速率:$(cat $TMP_T | grep 'Upload:' |awk -F: '{printf $2}' )" >> $LOG
+ echo -ne "\n 下行速率:$(cat $TMP_T | grep 'Download:' |awk -F: '{printf $2}' ) --" >> $LOG
+ echo -ne "-- 上行速率:$(cat $TMP_T | grep 'Upload:' |awk -F: '{printf $2}' )" >> $LOG
echo -ne "\n 测试结果图片链接:$(cat $TMP_T | grep 'results:' | cut -c16- )" >> $LOG
- echo -ne "\n 测试时间:`date +%Y-%m-%d" "%H:%M:%S`" >> $LOG
- echo -ne "\n ————————————————————\n" >> $LOG
- echo -ne $(cat $TMP_T | grep 'results:' | awk '{print $NF}')
+ echo -ne "\n 测试时间:`date +%Y-%m-%d" "%H:%M:%S`" | tee -a $LOG
+ echo -ne "\n ————————————————————\n" | tee -a $LOG
;;
esac
rm -f $LOCK
}
-
+getcpucore(){
+#i386, x86_64, arm32, arm32hf, and arm64.
+ cputype=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
+ [ -n "$(echo $cputype | grep -E "linux.*armv.*")" ] && cpucore="armel"
+ [ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && [ ! -d /jffs/clash ] && cpucore="armhf"
+ [ -n "$(echo $cputype | grep -E "linux.*aarch64.*|linux.*armv8.*")" ] && cpucore="aarch64"
+ [ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="i386"
+ [ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="x86_64"
+echo $cpucore
+}
git_bin_handle()
{
@@ -95,7 +103,7 @@ case $1 in
chmod 755 $BINSPEEDTEST >/dev/null 2>&1
echo "$BINSPEEDTEST --accept-gdpr --accept-license --progress=no"
else
- ooklaurl=`curl --connect-timeout 5 -m 60 -sSL 'https://www.speedtest.net/apps/cli' | grep 'Download for Linux' | sed 's|<|\n<|g' | sed -n '/Download for Linux/,/<\/div>/p' | sed -En "s|.*
x86_64|\1|p" `
+ ooklaurl=`curl --connect-timeout 5 -m 60 -sSL 'https://www.speedtest.net/apps/cli' | grep 'Download for Linux' | sed 's|<|\n<|g' | sed -n '/Download for Linux/,/<\/div>/p' | sed -En "s|.*$(getcpucore)|\1|p" `
[ -n "$ooklaurl" ] && curl -sSL $ooklaurl | tar -xvz -C /tmp >/dev/null 2>&1 || return
mv /tmp/speedtest $BINSPEEDTEST >/dev/null 2>&1
chmod 755 $BINSPEEDTEST >/dev/null 2>&1
diff --git a/netspeedtest/luci-app-netspeedtest/root/etc/uci-defaults/40_luci-netspeedtest b/netspeedtest/luci-app-netspeedtest/root/etc/uci-defaults/40_luci-netspeedtest
index ef606f4..55efe07 100644
--- a/netspeedtest/luci-app-netspeedtest/root/etc/uci-defaults/40_luci-netspeedtest
+++ b/netspeedtest/luci-app-netspeedtest/root/etc/uci-defaults/40_luci-netspeedtest
@@ -1,9 +1,18 @@
#!/bin/sh
chmod +x /etc/init.d/netspeedtest >/dev/null 2>&1
+[ `uci -q get partexp.global` ] && uci set partexp.global=global
[ `uci -q get netspeedtest.netspeedtest` ] || uci set netspeedtest.netspeedtest=netspeedtest
[ `uci -q get netspeedtest.speedtestiperf3` ] || uci set netspeedtest.speedtestiperf3=speedtestiperf3
[ `uci -q get netspeedtest.speedtestport` ] || uci set netspeedtest.speedtestport=speedtestport
[ `uci -q get netspeedtest.speedtestwan` ] || uci set netspeedtest.speedtestport=speedtestwan
+LOGD=/etc/netspeedtest
+LOG=/var/log/netspeedtest.log
+LOGE=$LOGD/netspeedtest.log
+LOGT=$LOGD/netspeedtestpos
+[ -d "$LOGD" ] || mkdir -p $LOGD
+[ -f "$LOGE" ] || echo "start" > $LOG
+[ -f "$LOGT" ] || echo "start" > $LOGT
+[ -f "$LOG" ] || echo "start" > $LOG
rm -rf /tmp/luci-modulecache /tmp/luci-indexcache*
exit 0