luci-app-serverchan: bump to v1.78

This commit is contained in:
CN_SZTL 2020-04-23 03:08:32 +08:00
parent 15aae46668
commit 39d4c7314d
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
7 changed files with 55 additions and 33 deletions

View File

@ -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

View File

@ -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

View File

@ -63,7 +63,7 @@ a:depends({err_enable="1"})
a= s:option(DynamicList, "err_device_aliases", translate("关注列表"))
a.rmempty = true
a.description = translate("只会在列表中设备都不在线时才会执行<br/>免打扰时段一小时后关注设备五分钟低流量约10kb/m将视为离线")
a.description = translate("只会在列表中设备都不在线时才会执行<br/>免打扰时段一小时后关注设备五分钟低流量约100kb/m将视为离线")
nt.mac_hints(function(mac, name) a :value(mac, "%s (%s)" %{ mac, name }) end)
a:depends({err_enable="1"})

View File

@ -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

View File

@ -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'

View File

@ -20,7 +20,7 @@ stop() {
restart(){
stop
sleep 2
sleep 1
start
echo "restarted."
}

View File

@ -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}<div class='tr placeholder'>"
local js_str="${js_str}<div class='th'><%:`echo $line|awk '{print $3}'`%></div>"
local tmp_mac=`echo $line|awk '{print $2}'`
local js_str="${js_str}<div class='th'><%:${tmp_mac}%></div>"
local js_str="${js_str}<div class='th'><%:`echo $line|awk '{print $1}'`%></div>"
local tmp_usage=`usage get ${tmp_mac}`
local js_str="${js_str}<div class='th'><%:${tmp_usage}%></div>"
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}<div class='th'><%:${tmp_uptime}%></div></div>"
done < ${dir}ipAddress
fi
cat>/usr/lib/lua/luci/view/serverchan/client.htm<<EOF
<h2><%:在线设备列表%></h2><div class="table" id="traffic"><div class="tr table-titles"><div class="th" id="thClient" style="width:17%"><%:客户端名%></div><div class="th" id="thMAC" style="width:10%"><%:MAC%></div><div class="th" id="thIP" style="width:17%"><%:IP%></div><div class="th" id="thTotal" style="width:9%"><%:总计流量%></div><div class="th" id="thFirstSeen" style="width:15%"><%:在线时间%></div></div>
$js_str
</div>
EOF
}
# 重启网络服务
function network_restart(){
cat>${dir}network_restart<<EOF
@ -338,8 +359,8 @@ function geterrdevicealiases(){
> ${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