From 39d4c7314d3d63cd23f0983a0d37ce7e5f546d29 Mon Sep 17 00:00:00 2001 From: CN_SZTL Date: Thu, 23 Apr 2020 03:08:32 +0800 Subject: [PATCH] luci-app-serverchan: bump to v1.78 --- package/ctcgfw/luci-app-serverchan/Makefile | 2 +- .../luasrc/controller/serverchan.lua | 12 ++--- .../luasrc/model/cbi/serverchan/advanced.lua | 2 +- .../luasrc/model/cbi/serverchan/client.lua | 6 +++ .../root/etc/config/serverchan | 11 ++-- .../root/etc/init.d/serverchan | 2 +- .../root/usr/bin/serverchan/serverchan | 53 +++++++++++++------ 7 files changed, 55 insertions(+), 33 deletions(-) create mode 100644 package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan/client.lua diff --git a/package/ctcgfw/luci-app-serverchan/Makefile b/package/ctcgfw/luci-app-serverchan/Makefile index 1af9b9d8d7..f772ad7c38 100644 --- a/package/ctcgfw/luci-app-serverchan/Makefile +++ b/package/ctcgfw/luci-app-serverchan/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-serverchan -PKG_VERSION:=1.77 +PKG_VERSION:=1.78 PKG_RELEASE:=8 include $(INCLUDE_DIR)/package.mk diff --git a/package/ctcgfw/luci-app-serverchan/luasrc/controller/serverchan.lua b/package/ctcgfw/luci-app-serverchan/luasrc/controller/serverchan.lua index 77dc85bc90..9858e374b7 100644 --- a/package/ctcgfw/luci-app-serverchan/luasrc/controller/serverchan.lua +++ b/package/ctcgfw/luci-app-serverchan/luasrc/controller/serverchan.lua @@ -9,22 +9,22 @@ function index() entry({"admin", "services", "serverchan"}, alias("admin", "services", "serverchan", "setting"),_("微信推送"), 30).dependent = true entry({"admin","services","serverchan","status"},call("act_status")).leaf=true entry({"admin", "services", "serverchan", "setting"}, cbi("serverchan/setting"),_("配置"), 40).leaf = true - entry({"admin", "services", "serverchan", "advanced"}, cbi("serverchan/advanced"),_("高级设置"), 90).leaf = true + entry({"admin", "services", "serverchan", "advanced"}, cbi("serverchan/advanced"),_("高级设置"), 50).leaf = true + entry({"admin", "services", "serverchan", "client"}, form("serverchan/client"), "在线设备", 80) entry({"admin", "services", "serverchan", "log"}, form("serverchan/log"),_("日志"), 99).leaf = true - entry({"admin", "services", "serverchan", "get_log"}, call("get_log")).leaf = true - entry({"admin", "services", "serverchan", "clear_log"}, call("clear_log")).leaf = true + entry({"admin", "services", "serverchan", "clear_log"}, call("clear_log")).leaf = true end function act_status() local e={} - e.running=luci.sys.call("pgrep -f serverchan/serverchan >/dev/null")==0 - luci.http.prepare_content("application/json") + e.running=luci.sys.call("pgrep -f serverchan/serverchan >/dev/null")==0 + luci.http.prepare_content("application/json") luci.http.write_json(e) end function get_log() - luci.http.write(luci.sys.exec( + luci.http.write(luci.sys.exec( "[ -f '/tmp/serverchan/serverchan.log' ] && cat /tmp/serverchan/serverchan.log")) end diff --git a/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan/advanced.lua b/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan/advanced.lua index 89bc28e784..e3111b76ca 100644 --- a/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan/advanced.lua +++ b/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan/advanced.lua @@ -63,7 +63,7 @@ a:depends({err_enable="1"}) a= s:option(DynamicList, "err_device_aliases", translate("关注列表")) a.rmempty = true -a.description = translate("只会在列表中设备都不在线时才会执行
免打扰时段一小时后,关注设备五分钟低流量(约10kb/m)将视为离线") +a.description = translate("只会在列表中设备都不在线时才会执行
免打扰时段一小时后,关注设备五分钟低流量(约100kb/m)将视为离线") nt.mac_hints(function(mac, name) a :value(mac, "%s (%s)" %{ mac, name }) end) a:depends({err_enable="1"}) diff --git a/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan/client.lua b/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan/client.lua new file mode 100644 index 0000000000..9c2dafd4fa --- /dev/null +++ b/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan/client.lua @@ -0,0 +1,6 @@ +f = SimpleForm("serverchan") +luci.sys.call("/usr/bin/serverchan/serverchan client") +f.reset = false +f.submit = false +f:append(Template("serverchan/client")) +return f diff --git a/package/ctcgfw/luci-app-serverchan/root/etc/config/serverchan b/package/ctcgfw/luci-app-serverchan/root/etc/config/serverchan index 836aff6460..a9a53d9be5 100644 --- a/package/ctcgfw/luci-app-serverchan/root/etc/config/serverchan +++ b/package/ctcgfw/luci-app-serverchan/root/etc/config/serverchan @@ -2,13 +2,10 @@ config serverchan 'serverchan' option serverchan_enable '0' option sleeptime '60' - option serverchan_ipv4 '0' option serverchan_ipv6 '0' - option serverchan_up '0' - option serverchan_down '0' - option cpuload_enable '0' + option serverchan_up '1' + option serverchan_down '1' + option cpuload_enable '1' + option cpuload '2' option temperature_enable '0' - option up_timeout '2' - option down_timeout '10' - option serverchan_sheep '0' diff --git a/package/ctcgfw/luci-app-serverchan/root/etc/init.d/serverchan b/package/ctcgfw/luci-app-serverchan/root/etc/init.d/serverchan index 1cbd0a9d86..90189e251e 100755 --- a/package/ctcgfw/luci-app-serverchan/root/etc/init.d/serverchan +++ b/package/ctcgfw/luci-app-serverchan/root/etc/init.d/serverchan @@ -20,7 +20,7 @@ stop() { restart(){ stop - sleep 2 + sleep 1 start echo "restarted." } \ No newline at end of file diff --git a/package/ctcgfw/luci-app-serverchan/root/usr/bin/serverchan/serverchan b/package/ctcgfw/luci-app-serverchan/root/usr/bin/serverchan/serverchan index bfaa8a7e98..135643cf62 100755 --- a/package/ctcgfw/luci-app-serverchan/root/usr/bin/serverchan/serverchan +++ b/package/ctcgfw/luci-app-serverchan/root/usr/bin/serverchan/serverchan @@ -1,8 +1,5 @@ #!/bin/sh -# 等待 3s,确保 luci 设置已保存 -[ ! "$1" ] && sleep 3 - # 读取设置文件 function get_config(){ while [[ "$*" != "" ]]; do @@ -13,7 +10,7 @@ function get_config(){ # 初始化设置信息 function read_config(){ - get_config "serverchan_enable" "sckey" "serverchan_ipv4" "ipv4_interface" "ipv4_URL" "serverchan_ipv6" "ipv6_interface" "ipv6_URL" "serverchan_up" "serverchan_down" "serverchan_sheep" "serverchan_whitelist" "serverchan_blacklist" "serverchan_interface" "starttime" "endtime" "cpuload_enable" "cpuload" "temperature_enable" "temperature" "device_name" "err_enable" "network_err_event" "err_sheep_enable" "system_time_event" "autoreboot_time" "network_restart_time" "public_ip_event" "public_ip_retry_count" "soc_code" "sleeptime" "up_timeout" "down_timeout" "device_aliases" "debuglevel" "cpuload" "temperature" "send_mode" "regular_time" "regular_time_2" "regular_time_3" "interval_time" "thread_num" "timeout_retry_count" "send_tg" "tgtoken" + get_config "serverchan_enable" "sckey" "serverchan_ipv4" "ipv4_interface" "ipv4_URL" "serverchan_ipv6" "ipv6_interface" "ipv6_URL" "serverchan_up" "serverchan_down" "serverchan_sheep" "serverchan_whitelist" "serverchan_blacklist" "serverchan_interface" "starttime" "endtime" "cpuload_enable" "cpuload" "temperature_enable" "temperature" "device_name" "err_enable" "network_err_event" "err_sheep_enable" "system_time_event" "autoreboot_time" "network_restart_time" "public_ip_event" "public_ip_retry_count" "soc_code" "sleeptime" "up_timeout" "down_timeout" "device_aliases" "debuglevel" "cpuload" "temperature" "send_mode" "regular_time" "regular_time_2" "regular_time_3" "interval_time" "thread_num" "timeout_retry_count" "send_tg" "tgtoken" "err_device_aliases" for str_version in "wrtbwmon" "iputils-arping" "curl" "iw"; do eval `echo ${str_version:0:2}"_version"`=`opkg list-installed|grep -w ^${str_version}|awk '{print $3}'` 2>/dev/null done @@ -27,7 +24,6 @@ function read_config(){ [ -z "$timeout_retry_count" ] && timeout_retry_count="2";[ "$timeout_retry_count" -eq "0" ] && timeout_retry_count="1" markdown_splitline="%0D%0A%0D%0A---%0D%0A%0D%0A";markdown_linefeed="%0D%0A%0D%0A";markdown_tab=" ";markdown_space=" " [ ! -z "$send_tg" ] && [ "$send_tg" -eq "1" ] && markdown_splitline="%0D%0A%0D%0A%0D%0A%0D%0A" && markdown_tab="" - enable_detection } # 初始化 @@ -131,6 +127,8 @@ function getinterface(){ # ping function getping(){ + [ "$iw_version" ] && local wlan_online=`iw dev ${ip_interface} station dump|grep -i -w ${ip_mac}|grep Station` >/dev/null 2>&1 + [ "$wlan_online" ] && return 0 for i in `seq 1 ${3}`; do ( ! echo "$ip_ms"|grep -q "ms" ) && local ip_ms=$( arping -I `cat /proc/net/arp|grep -w ${1}|awk '{print $6}'|grep -v "^$"|sort -u` -c 20 -f -w ${2} $1 ) 2>/dev/null ( ! echo "$ip_ms"|grep -q "ms" ) && local ip_ms=`ping -c 5 -w ${2} ${1}|grep -v '100% packet loss'` 2>/dev/null @@ -168,7 +166,7 @@ function usage(){ [ -z "$total_n" ] && total_n="6" [ "$2" ] && local tmptotal=`cat ${dir}usage.db|sed 's/,/ /g'|grep -i -w ${2}|awk "{print "'$'$total_n"}"|grep -v "^$"|sort -u` 2>/dev/null [ -z "$tmptotal" ] && local tmptotal="0" - echo `bytes_for_humans ${tmptotal}` + [ ! "$3" ] && echo `bytes_for_humans ${tmptotal}` || echo $tmptotal elif [ $1 == "down" ] ;then [ "$2" ] && sed -i "/${2}/d" ${dir}usage.db 2>/dev/null fi @@ -313,6 +311,29 @@ function blackwhitelist(){ [ ! -z "$serverchan_interface" ] && ( echo `getinterface ${1}`|grep -q -i -w $serverchan_interface ) && return } +function get_client(){ + if [ -f "${dir}ipAddress" ]; then + while read line; do + local js_str="${js_str}
" + local js_str="${js_str}
<%:`echo $line|awk '{print $3}'`%>
" + local tmp_mac=`echo $line|awk '{print $2}'` + local js_str="${js_str}
<%:${tmp_mac}%>
" + local js_str="${js_str}
<%:`echo $line|awk '{print $1}'`%>
" + local tmp_usage=`usage get ${tmp_mac}` + local js_str="${js_str}
<%:${tmp_usage}%>
" + local tmp_uptime=`echo $line|awk '{print $4}'` + local tmp_timenow=`date +%s` + local tmp_uptime=$(time_for_humans `expr ${tmp_timenow} - ${tmp_uptime}`) + local js_str="${js_str}
<%:${tmp_uptime}%>
" + done < ${dir}ipAddress + fi +cat>/usr/lib/lua/luci/view/serverchan/client.htm<<%:在线设备列表%>
<%:客户端名%>
<%:MAC%>
<%:IP%>
<%:总计流量%>
<%:在线时间%>
+$js_str +
+EOF +} + # 重启网络服务 function network_restart(){ cat>${dir}network_restart< ${dir}sheep_usage local MACLIST=`echo "$err_device_aliases"|grep -v "^$"|sort -u` for mac in $MACLIST; do - [ ! -z "$mac" ] && local tmptotal=`usage get ${mac}` - [ ! -z "$tmptotal" ] && awk 'BEGIN{printf "%.0f\n",'$tmptotal'/'20480'}' 2>/dev/null >> ${dir}sheep_usage + [ ! -z "$mac" ] && local tmptotal=`usage get ${mac} bytes` + [ ! -z "$tmptotal" ] && awk 'BEGIN{printf "%.0f\n",'$tmptotal'/'204800'}' 2>/dev/null >> ${dir}sheep_usage done old_sheep_usage=`cat ${dir}old_sheep_usage` 2>/dev/null sheep_usage=`cat ${dir}sheep_usage` 2>/dev/null @@ -354,8 +375,7 @@ function geterrdevicealiases(){ function unattended(){ [ -z "$err_enable" ] || [ "$err_enable" -ne "1" ] && return [ ! -z "$err_sheep_enable" ] && [ "$err_sheep_enable" -eq "1" ] && [ -z "$sheep_starttime" ] && return - geterrdevicealiases;[ $? -eq "1" ] && local err_mac="1" - [ -z "$err_mac" ] && return + geterrdevicealiases;[ $? -eq "1" ] && return if [ ! -z "$system_time_event" ]; then if [ ! -z "$autoreboot_time" ] && [ `cat /proc/uptime|awk -F. '{run_hour=$1/3600;printf("%d",run_hour)}'` -ge "$autoreboot_time" ] && [ "$system_time_event" -eq "1" ]; then @@ -409,8 +429,8 @@ function rand_geturl(){ [ -z "$network_err_time" ] && network_err_time=`date +%s` if [ ! -z "$network_err_event" ] && [ "$((`date +%s`-$network_err_time))" -ge "600" ]; then > ${dir}send_enable.lock && serverchan_first && deltemp - geterrdevicealiases;[ $? -eq "1" ] && local err_mac="1" - if [ -z "$err_mac" ]; then + geterrdevicealiases + if [ "$?" -eq "0" ]; then [ -f /usr/bin/serverchan/autoreboot_count ] && retry_count=`cat /usr/bin/serverchan/autoreboot_count` && rm -f /usr/bin/serverchan/autoreboot_count >/dev/null 2>&1 [ ! -z ${retry_count} ] && retry_count=0;retry_count=`expr $retry_count + 1` if [ "$network_err_event" -eq "1" ] ;then @@ -541,9 +561,8 @@ function up(){ [ -f ${dir}ipAddress ] && ( cat ${dir}ipAddress|grep -q -w $1 ) && return local ip_mac=`getmac $1` local ip_interface=`getinterface ${ip_mac}` - [ "$iw_version" ] && local wlan_online=`iw dev ${ip_interface} station dump|grep -i -w ${ip_mac}|grep Station` >/dev/null 2>&1 getping ${1} ${up_timeout} "1";local ping_online=$? - if [ ! -z "$wlan_online" ] || [ "$ping_online" -eq "0" ]; then + if [ "$ping_online" -eq "0" ]; then LockFile lock [ -f "${dir}tmp_downlist" ] && local tmp_downip=`cat ${dir}tmp_downlist|grep -w ${1}|awk '{print $2}'|grep -v "^$"|sort -u` if [ ! -z "$tmp_downip" ]; then @@ -580,9 +599,8 @@ function up(){ function down(){ local ip_mac=`getmac $1` local ip_interface=`getinterface ${ip_mac}` - [ "$iw_version" ] && local wlan_down=`iw dev ${ip_interface} station dump|grep -i -w ${ip_mac}|grep Station` >/dev/null 2>&1 getping ${1} ${down_timeout} ${timeout_retry_count};local ping_online=$? - if [ -z "$wlan_down" ] && [ "$ping_online" -eq "1" ]; then + if [ "$ping_online" -eq "1" ]; then LockFile lock [ ! -f "${dir}send_enable.lock" ] && cat ${dir}ipAddress|grep -w ${1}|grep -v "^$"|sort -u >> ${dir}tmp_downlist sed -i "/$1/d" ${dir}ipAddress @@ -799,7 +817,8 @@ unset i # 启动参数 if [ "$1" ] ;then [ $1 == "send" ] && send - [ $1 == "soc" ] && echo `soc_temp` > /tmp/serverchan/soc_tmp + [ $1 == "soc" ] && echo `soc_temp` > ${dir}soc_tmp + [ $1 == "client" ] && get_client exit fi