From ca7370c336715e26c0ff4dc8467442512601c610 Mon Sep 17 00:00:00 2001 From: CN_SZTL Date: Wed, 12 Feb 2020 21:45:48 +0800 Subject: [PATCH] luci-app-serverchan: bump to 1.33 --- package/ctcgfw/luci-app-serverchan/Makefile | 2 +- .../luasrc/model/cbi/serverchan.lua | 29 +- .../root/etc/init.d/serverchan | 4 +- .../root/usr/bin/serverchan/serverchan | 459 +++++++++--------- 4 files changed, 257 insertions(+), 237 deletions(-) diff --git a/package/ctcgfw/luci-app-serverchan/Makefile b/package/ctcgfw/luci-app-serverchan/Makefile index f120e3618d..31addd4b03 100644 --- a/package/ctcgfw/luci-app-serverchan/Makefile +++ b/package/ctcgfw/luci-app-serverchan/Makefile @@ -9,7 +9,7 @@ LUCI_TITLE:=LuCI support for serverchan LUCI_DEPENDS:=+iputils-arping +curl LUCI_PKGARCH:=all PKG_NAME:=luci-app-serverchan -PKG_VERSION:=1.30 +PKG_VERSION:=1.33 PKG_RELEASE:=42 include $(TOPDIR)/feeds/luci/luci.mk diff --git a/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan.lua b/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan.lua index 4dbb12b818..528e96c396 100644 --- a/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan.lua +++ b/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan.lua @@ -36,7 +36,7 @@ device_name.description = translate("在推送信息标题中会标识本设备 sleeptime=s:taboption("tab_basic", Value,"sleeptime",translate('检测时间间隔')) sleeptime.default = "60" -sleeptime.description = translate("越短的时间灵敏度越高,但会占用更多的系统资源") +sleeptime.description = translate("越短的时间时间响应越及时,但会占用更多的系统资源") debuglevel=s:taboption("tab_basic", ListValue,"debuglevel",translate("日志调试等级")) debuglevel:value("",translate("关闭")) @@ -143,7 +143,7 @@ a= s:taboption("tab_basic2", Value, "temperature", "温度报警阈值") a.rmempty = true a.placeholder = "80" a:depends({temperature_enable="1"}) -a.description = translate("
设备报警只会在连续五次超过阈值的时候才会推送
而且一个小时内不会再提醒第二次") +a.description = translate("
设备报警只会在连续五分钟超过设定值时才会推送
而且一个小时内不会再提醒第二次") e=s:taboption("tab_basic3", ListValue,"send_mode",translate("定时任务设定")) e.default="disable" @@ -154,18 +154,28 @@ e:value("2",translate("间隔发送")) e=s:taboption("tab_basic3", ListValue,"regular_time",translate("发送时间")) for t=0,23 do e:value(t,translate("每天"..t.."点")) -end -e.default=12 +end +e.default=8 e.datatype=uinteger e:depends("send_mode","1") -e=s:taboption("tab_basic3", ListValue,"regular_time_2",translate("第一次发送时间")) +e=s:taboption("tab_basic3", ListValue,"regular_time_2",translate("发送时间")) +e:value("",translate("关闭")) for t=0,23 do e:value(t,translate("每天"..t.."点")) -end -e.default=8 +end +e.default="关闭" e.datatype=uinteger -e:depends("send_mode","2") +e:depends("send_mode","1") + +e=s:taboption("tab_basic3", ListValue,"regular_time_3",translate("发送时间")) +e:value("",translate("关闭")) +for t=0,23 do +e:value(t,translate("每天"..t.."点")) +end +e.default="关闭" +e.datatype=uinteger +e:depends("send_mode","1") e=s:taboption("tab_basic3", ListValue,"interval_time",translate("发送间隔")) for t=1,23 do @@ -174,6 +184,7 @@ end e.default=6 e.datatype=uinteger e:depends("send_mode","2") +e.description = translate("
从 00:00 开始,每 * 小时发送一次") title= s:taboption("tab_basic3", Value, "send_title", translate("微信推送标题")) title:depends("send_mode","1") @@ -214,7 +225,7 @@ up_timeout.default = "2" down_timeout=s:taboption("tab_basic4", Value,"down_timeout",translate('设备离线检测超时')) down_timeout.default = "10" -down_timeout.description = translate("如果遇到设备频繁离线,可以把超时时间设置长一些") +down_timeout.description = translate("如果遇到设备频繁离线,可以把超时时间设置长一些
因为会重试两次,所以实际时间会略大于设定值的 2 倍") sheep=s:taboption("tab_basic4", ListValue,"serverchan_sheep",translate("免打扰时段设置"),translate("在指定整点时间段内,暂停推送消息
免打扰时间中,定时推送也会被阻止。")) sheep:value("0",translate("关闭")) 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 f08912e4bd..ed28f9fd34 100755 --- a/package/ctcgfw/luci-app-serverchan/root/etc/init.d/serverchan +++ b/package/ctcgfw/luci-app-serverchan/root/etc/init.d/serverchan @@ -4,7 +4,7 @@ STOP=10 start() { -flag=$(ps | grep "serverchan/serverchan" | grep -v "grep" | wc -l) +flag=$(ps | grep "/usr/bin/serverchan/serverchan" | grep -v "grep" | wc -l) if [ $flag -eq 0 ] ;then /usr/bin/serverchan/serverchan & else @@ -12,5 +12,5 @@ else fi } stop() { -kill -9 `pgrep -f serverchan/serverchan` +kill -9 `pgrep -f /usr/bin/serverchan/serverchan` } 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 254dac1eda..1902ce7d4e 100755 --- a/package/ctcgfw/luci-app-serverchan/root/usr/bin/serverchan/serverchan +++ b/package/ctcgfw/luci-app-serverchan/root/usr/bin/serverchan/serverchan @@ -44,7 +44,7 @@ function read_config(){ if [ -z "$down_timeout" ] ; then down_timeout="10";fi } -#等待 5s,确保 luci 设置已保存 +# 等待 5s,确保 luci 设置已保存 #sleep 5 read_config @@ -54,108 +54,102 @@ function enable_detection(){ for i in `seq 1 $1` do serverchan_enable=`get_config serverchan_enable` - if [ -z "$serverchan_enable" ] || [ "$serverchan_enable" -eq "0" ] ; then kill -9 `pgrep -f serverchan`;fi + if [ -z "$serverchan_enable" ] || [ "$serverchan_enable" -eq "0" ] ; then kill -9 `pgrep -f /usr/bin/serverchan/serverchan`;fi sleep 1 done else serverchan_enable=`get_config serverchan_enable` - if [ -z "$serverchan_enable" ] || [ "$serverchan_enable" -eq "0" ] ; then kill -9 `pgrep -f serverchan`;fi + if [ -z "$serverchan_enable" ] || [ "$serverchan_enable" -eq "0" ] ; then kill -9 `pgrep -f /usr/bin/serverchan/serverchan`;fi fi } # 初始化 function serverchan_init(){ if [ -z "$serverchan_enable" ] || [ "$serverchan_enable" -eq "0" ] ; then exit;fi -if [ -z "$serverchan_enable" ] ; then echo "`date "+%H:%M:%S"` 【!!!】无法读取程序开关 " >> ${logfile};fi -if [ -z "$serverchan_sckey" ] ; then echo "`date "+%H:%M:%S"` 【!!!】无法读取 SCKEY" >> ${logfile};fi -if [ -z "$serverchan_sckey" ] && [ "${#serverchan_sckey}" -lt "50" ] ; then echo "`date "+%H:%M:%S"` 【!!!】请填入正确的 SCKEY " >> ${logfile};fi +if [ -z "$serverchan_enable" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取程序开关 " >> ${logfile};fi +if [ -z "$serverchan_sckey" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取 SCKEY" >> ${logfile};fi +if [ -z "$serverchan_sckey" ] && [ "${#serverchan_sckey}" -lt "50" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】请填入正确的 SCKEY " >> ${logfile};fi if [ -z "$serverchan_sckey" ] && [ "${#serverchan_sckey}" -lt "50" ] ; then exit;fi -if [ -z "$serverchan_ipv4" ] || [ "$serverchan_ipv4" -ne "0" ] && [ "$serverchan_ipv4" -ne "1" ] && [ "$serverchan_ipv4" -ne "2" ] ; then echo "`date "+%H:%M:%S"` 【!!!】无法读取 ipv4 变化通知 开关" >> ${logfile};fi -if [ ! -z "$serverchan_ipv4" ] && [ "$serverchan_ipv4" -eq "1" ] && [ -z "$ipv4_interface" ] ; then echo "`date "+%H:%M:%S"` 【!!!】无法读取 ipv4 IP 接口信息" >> ${logfile};fi -if [ ! -z "$serverchan_ipv4" ] && [ "$serverchan_ipv4" -eq "2" ] && [ -z "$ipv4_URL" ] ; then echo "`date "+%H:%M:%S"` 【!!!】无法读取 ipv4 IP URL信息" >> ${logfile};fi -if [ -z "$serverchan_ipv6" ] || [ "$serverchan_ipv6" -ne "0" ] && [ "$serverchan_ipv6" -ne "1" ] && [ "$serverchan_ipv6" -ne "2" ] ; then echo "`date "+%H:%M:%S"` 【!!!】无法读取 ipv6 变化通知 开关" >> ${logfile};fi -if [ ! -z "$serverchan_ipv6" ] && [ "$serverchan_ipv6" -eq "1" ] && [ -z "$ipv6_interface" ] ; then echo "`date "+%H:%M:%S"` 【!!!】无法读取 ipv6 IP 接口信息" >> ${logfile};fi -if [ ! -z "$serverchan_ipv6" ] && [ "$serverchan_ipv6" -eq "2" ] && [ -z "$ipv6_URL" ] ; then echo "`date "+%H:%M:%S"` 【!!!】无法读取 ipv6 IP URL信息" >> ${logfile};fi -if [ -z "$serverchan_up" ] || [ "$serverchan_up" -ne "0" ] && [ "$serverchan_up" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【!!!】无法读取 设备上线提醒 开关" >> ${logfile};fi -if [ -z "$serverchan_down" ] || [ "$serverchan_down" -ne "0" ] && [ "$serverchan_down" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【!!!】无法读取 设备下线提醒 开关" >> ${logfile};fi +if [ -z "$serverchan_ipv4" ] || [ "$serverchan_ipv4" -ne "0" ] && [ "$serverchan_ipv4" -ne "1" ] && [ "$serverchan_ipv4" -ne "2" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取 ipv4 变化通知 开关" >> ${logfile};fi +if [ ! -z "$serverchan_ipv4" ] && [ "$serverchan_ipv4" -eq "1" ] && [ -z "$ipv4_interface" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取 ipv4 IP 接口信息" >> ${logfile};fi +if [ ! -z "$serverchan_ipv4" ] && [ "$serverchan_ipv4" -eq "2" ] && [ -z "$ipv4_URL" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取 ipv4 IP URL信息" >> ${logfile};fi +if [ -z "$serverchan_ipv6" ] || [ "$serverchan_ipv6" -ne "0" ] && [ "$serverchan_ipv6" -ne "1" ] && [ "$serverchan_ipv6" -ne "2" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取 ipv6 变化通知 开关" >> ${logfile};fi +if [ ! -z "$serverchan_ipv6" ] && [ "$serverchan_ipv6" -eq "1" ] && [ -z "$ipv6_interface" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取 ipv6 IP 接口信息" >> ${logfile};fi +if [ ! -z "$serverchan_ipv6" ] && [ "$serverchan_ipv6" -eq "2" ] && [ -z "$ipv6_URL" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取 ipv6 IP URL信息" >> ${logfile};fi +if [ -z "$serverchan_up" ] || [ "$serverchan_up" -ne "0" ] && [ "$serverchan_up" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取 设备上线提醒 开关" >> ${logfile};fi +if [ -z "$serverchan_down" ] || [ "$serverchan_down" -ne "0" ] && [ "$serverchan_down" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取 设备下线提醒 开关" >> ${logfile};fi mkdir -p ${dir} network_enable="200" rm -f ${dir}title >/dev/null 2>&1 rm -f ${dir}content >/dev/null 2>&1 rm -f ${dir}serverchan.lock >/dev/null 2>&1 send_enable=0 -echo "`date "+%H:%M:%S"` 【初始化】载入配置文件" >> ${logfile} -if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【初始化】工作目录为 $dir " >> ${logfile};fi -if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【初始化】log 目录为 $logfile " >> ${logfile};fi +echo "`date "+%Y-%m-%d %H:%M:%S"` 【初始化】载入配置文件" >> ${logfile} +if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【初始化】工作目录为 $dir " >> ${logfile};fi +if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【初始化】log 目录为 $logfile " >> ${logfile};fi # 如果 “忽略列表 为空” 并且 “关注列表为空” if [ -z "$serverchan_whitelist" ] && [ -z "$serverchan_blacklist" ] && [ -z "$serverchan_interface" ]; then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【初始化】未启用 MAC 过滤" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【初始化】未启用 MAC 过滤" >> ${logfile};fi # 如果 “忽略列表不为空” elif [ ! -z "$serverchan_whitelist" ] ; then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【初始化】忽略列表内设备" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【初始化】忽略列表内设备" >> ${logfile};fi # 如果 “关注列表不为空” elif [ ! -z "$serverchan_blacklist" ] ; then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【初始化】仅关注列表内设备" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【初始化】仅关注列表内设备" >> ${logfile};fi # 如果 “仅关注接口选项打开” elif [ ! -z "$serverchan_interface" ] ; then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【初始化】仅关注接口内设备" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【初始化】仅关注接口内设备" >> ${logfile};fi fi } - -#创建计划任务 +# 创建计划任务 function serverchan_cron(){ -send_mode=`get_config send_mode` -if [ ! -z "$send_mode" ] ; then - if [ "$send_mode" -eq "1" ] ; then + send_mode=`get_config send_mode` + if [ ! -z "$send_mode" ] ; then regular_time=`get_config regular_time` - if [ ! -z "$regular_time" ] ; then - if ( echo `crontab -l` | grep "serverchan" | grep -q " $regular_time " ); then - echo "" >/dev/null - elif ( echo `crontab -l` | grep -q "serverchan" ); then - crontab -l > conf && sed -i "/serverchan/d" conf && crontab conf && rm -f conf >/dev/null 2>&1 - crontab -l > conf && echo -e "0 $regular_time * * * /usr/bin/serverchan/serverchan send &" >> conf && crontab conf && rm -f conf >/dev/null 2>&1 - /etc/init.d/cron stop - /etc/init.d/cron start - else - crontab -l > conf && echo -e "0 $regular_time * * * /usr/bin/serverchan/serverchan send &" >> conf && crontab conf && rm -f conf >/dev/null 2>&1 - /etc/init.d/cron stop - /etc/init.d/cron start - fi - fi - elif [ "$send_mode" -eq "2" ] ; then regular_time_2=`get_config regular_time_2` + regular_time_3=`get_config regular_time_3` + if [ ! -z "$regular_time_2" ] ; then regular_time_2=,${regular_time_2};fi + if [ ! -z "$regular_time_3" ] ; then regular_time_3=,${regular_time_3};fi interval_time=`get_config interval_time` - if [ ! -z "$regular_time_2" ] && [ ! -z "$interval_time" ] ; then - if ( echo `crontab -l` | grep "serverchan" | grep -q "$regular_time_2-24/$interval_time " ); then - echo "" >/dev/null + + # 定时发送 + if [ ! -z "$regular_time" ] || [ ! -z "$regular_time_2" ] || [ ! -z "$regular_time_3" ] ; then + if ( echo `crontab -l` | grep "serverchan" | grep -q " $regular_time$regular_time_2$regular_time_3 " ); then + return elif ( echo `crontab -l` | grep -q "serverchan" ); then crontab -l > conf && sed -i "/serverchan/d" conf && crontab conf && rm -f conf >/dev/null 2>&1 - crontab -l > conf && echo -e "0 $regular_time_2-24/$interval_time * * * /usr/bin/serverchan/serverchan send &" >> conf && crontab conf && rm -f conf >/dev/null 2>&1 - /etc/init.d/cron stop - /etc/init.d/cron start + crontab -l > conf && echo -e "0 $regular_time$regular_time_2$regular_time_3 * * * /usr/bin/serverchan/serverchan send &" >> conf && crontab conf && rm -f conf >/dev/null 2>&1 else - crontab -l > conf && echo -e "0 $regular_time_2-24/$interval_time * * * /usr/bin/serverchan/serverchan send &" >> conf && crontab conf && rm -f conf >/dev/null 2>&1 - /etc/init.d/cron stop - /etc/init.d/cron start + crontab -l > conf && echo -e "0 $regular_time * * * /usr/bin/serverchan/serverchan send &" >> conf && crontab conf && rm -f conf >/dev/null 2>&1 + fi + # 间隔发送 + elif [ ! -z "$interval_time" ] ; then + if ( echo `crontab -l` | grep "serverchan" | grep -q " */$interval_time " ); then + return + elif ( echo `crontab -l` | grep -q "serverchan" ); then + crontab -l > conf && sed -i "/serverchan/d" conf && crontab conf && rm -f conf >/dev/null 2>&1 + crontab -l > conf && echo -e "0 */$interval_time * * * /usr/bin/serverchan/serverchan send &" >> conf && crontab conf && rm -f conf >/dev/null 2>&1 + else + crontab -l > conf && echo -e "0 */$interval_time * * * /usr/bin/serverchan/serverchan send &" >> conf && crontab conf && rm -f conf >/dev/null 2>&1 fi fi elif [ -z "$send_mode" ] ; then if ( echo `crontab -l` | grep -q "serverchan" ); then crontab -l > conf && sed -i "/serverchan/d" conf && crontab conf && rm -f conf >/dev/null 2>&1 - /etc/init.d/cron stop - /etc/init.d/cron start fi - fi -fi + fi + /etc/init.d/cron stop + /etc/init.d/cron start + } -#免打扰检测 +# 免打扰检测 function serverchan_disturb(){ if [ ! -z "$serverchan_sheep" ] && [ "$serverchan_sheep" -eq "1" ] && [ ! -z "$starttime" ] && [ ! -z "$endtime" ] ;then if [ `date +%H` -ge $endtime -a $starttime -lt $endtime ] || [ `date +%H` -lt $starttime -a $starttime -lt $endtime ] || [ `date +%H` -lt $starttime -a `date +%H` -ge $endtime -a $starttime -gt $endtime ] ; then enable=1;else enable=0;fi @@ -165,7 +159,7 @@ function serverchan_disturb(){ while [ $enable -eq "0" ] ; do if [ "$sheep_str" -eq "0" ] ; then - echo "`date "+%H:%M:%S"` 【免打扰】夜深了,该休息了" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 【免打扰】夜深了,该休息了" >> ${logfile} sheep_str=1 fi read_config @@ -186,18 +180,17 @@ function serverchan_disturb(){ } -#清理日志 +# 清理日志 function clean_log(){ logrow=$(grep -c "" ${logfile}) if [ $logrow -gt 500 ] ;then - #cat /dev/null > ${logfile} sed -i '1,100d' ${logfile} - echo "`date "+%H:%M:%S"` 【清理】日志超出上限,删除前 100 条" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 【清理】日志超出上限,删除前 100 条" >> ${logfile} fi } if [ -f ${logfile} ] ; then clean_log;fi -#文件锁 +# 文件锁 function LockFile() { if [ ! -f "${dir}serverchan.lock" ] ; then @@ -217,13 +210,13 @@ function usage(){ if [ -f "/usr/sbin/wrtbwmon" ] && [ -f "/etc/init.d/wrtbwmon" ] ; then wrtbwmon update ${dir}usage.db else - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【!!!】未安装 wrtbwmon ,流量统计不可用" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】未安装 wrtbwmon ,流量统计不可用" >> ${logfile};fi fi } function usage_ip(){ if [ "$1" ] ;then - ip=`cat /tmp/serverchan/usage.db | grep -w $1` + if [ -f "${dir}usage.db" ] ; then ip=`cat /tmp/serverchan/usage.db | grep -w $1`;else return;fi if [ ! -z "$ip" ] ; then ip=`echo $ip | sed 's/,/ /g'`;fi if [ ! -z "$ip" ] ; then ip_total=`echo $ip | awk '{print $6}'`;fi if [ ! -z "$ip_total" ] ; then echo `bytes_for_humans $ip_total`;fi @@ -242,7 +235,6 @@ function usage_down(){ } # 流量数据单位换算 -# bytes_for_humans 1024 function bytes_for_humans { if [ "$1" ] ;then if [[ $1 -lt 1024 ]]; then @@ -260,7 +252,6 @@ function bytes_for_humans { } # 时间单位换算 -# time_for_humans 1024 function time_for_humans { if [ "$1" ] ;then if [[ $1 -lt 60 ]]; then @@ -288,7 +279,7 @@ function time_for_humans { fi } -#检测黑白名单 +# 检测黑白名单 function blackwhitelist(){ if [ "$1" ] ;then # 如果 “忽略列表 为空” 并且 “关注列表为空” @@ -321,7 +312,7 @@ function blackwhitelist(){ fi } -#检测设备上线 +# 检测设备上线 function up(){ if [ ! -f "${dir}ipAddress" ] ; then > ${dir}ipAddress;fi if [ "$1" ] ;then @@ -362,7 +353,7 @@ if [ "$1" ] ;then LockFile usage_down $1 if ( echo "$ip_mac" | grep -q "unknown" ) || ( echo "$ip_name" | grep -q "unknown" ) ; then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 获取 $1 $ip_mac 设备信息失败,重试中" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 获取 $1 $ip_mac 设备信息失败,重试中" >> ${logfile};fi for i in `seq 1 5` do sleep 1 @@ -375,41 +366,41 @@ if [ "$1" ] ;then fi if [ -z "$ip_mac" ] ; then ip_mac="unknown" - echo "`date "+%H:%M:%S"` 获取 $1 mac 超时,跳过" >> ${logfile} + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 获取 $1 mac 超时,跳过" >> ${logfile};fi fi if [ -z "$ip_name" ] ; then ip_name="unknown" - echo "`date "+%H:%M:%S"` 获取 $1 设备名超时,跳过" >> ${logfile} + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 获取 $1 设备名超时,跳过" >> ${logfile};fi fi # 如果定时任务没有运行 if [ ! -z "$send_enable" ] && [ "$send_enable" -ne 3 ] ; then - - # 如果通过黑白名单验证 - if [ ! -z `blackwhitelist $1` ] && [ `blackwhitelist $1` -eq 1 ] ; then - if [ -f "${dir}title" ] ; then title=`cat ${dir}title` ;fi - if [ -f "${dir}content" ] ; then content=`cat ${dir}content` ;fi - if [ -z "$title" ] ; then - title="有人连接了你的路由器" - content="%0D%0A%0D%0A---%0D%0A%0D%0A####新设备连接%0D%0A%0D%0A"">$ip_name%0D%0A%0D%0A"">$1" - elif ( echo ${title} | grep -q "有人连接了你的路由器" ) ; then - title="有人连接了你的路由器" - content="%0D%0A%0D%0A"">$ip_name $1" - else - title="设备状态变化" - content="%0D%0A%0D%0A---%0D%0A%0D%0A####新设备连接%0D%0A%0D%0A"">$ip_name%0D%0A%0D%0A"">$1" - fi - echo "`date "+%H:%M:%S"` 【微信推送】新设备 $ip_name $1 连接了">> ${logfile} - - if [ ! -z "$serverchan_blacklist" ] ; then - if ( echo $serverchan_blacklist | grep -q -i $ip_mac ); then - title="你偷偷关注的设备上线了" + if [ ! -z "$serverchan_up" ] && [ "$serverchan_up" -eq "1" ] ; then + # 如果通过黑白名单验证 + if [ ! -z `blackwhitelist $1` ] && [ `blackwhitelist $1` -eq 1 ] ; then + if [ -f "${dir}title" ] ; then title=`cat ${dir}title` ;fi + if [ -f "${dir}content" ] ; then content=`cat ${dir}content` ;fi + if [ -z "$title" ] ; then + title="有人连接了你的路由器" + content="%0D%0A%0D%0A---%0D%0A%0D%0A####新设备连接%0D%0A%0D%0A"">$ip_name%0D%0A%0D%0A"">$1" + elif ( echo ${title} | grep -q "有人连接了你的路由器" ) ; then + title="有人连接了你的路由器" + content="%0D%0A%0D%0A"">$ip_name%0D%0A%0D%0A"">$1" + else + title="设备状态变化" + content="%0D%0A%0D%0A---%0D%0A%0D%0A####新设备连接%0D%0A%0D%0A"">$ip_name%0D%0A%0D%0A"">$1" fi - fi + echo "`date "+%Y-%m-%d %H:%M:%S"` 【微信推送】新设备 $ip_name $1 连接了">> ${logfile} + + if [ ! -z "$serverchan_blacklist" ] ; then + title="你偷偷关注的设备上线了" + fi - echo $title >${dir}title - echo -n $content >>${dir}content + echo $title >${dir}title + echo -n $content >>${dir}content + fi fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 新设备 $ip_name $1 连接了" >> ${logfile};fi else # 如果定时任务运行 unset title @@ -417,18 +408,18 @@ if [ "$1" ] ;then fi echo "$1 $ip_mac $ip_name `date +%s`" >> ${dir}ipAddress else - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 设备 $ip_name $1 连接失败" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 设备 $ip_name $1 连接失败" >> ${logfile};fi fi rm -f ${dir}serverchan.lock >/dev/null 2>&1 else - #调试日志 - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -eq "5" ] ; then echo "`date "+%H:%M:%S"` $ip_name $1 已存在,跳过" >> ${logfile};fi + # 调试日志 + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -eq "5" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` $ip_name $1 已存在,跳过" >> ${logfile};fi fi unset ip_ms fi } -#检测设备下线 +# 检测设备下线 function down(){ if [ ! -f "${dir}ipAddress" ] ; then return;fi if [ "$1" ] ;then @@ -438,7 +429,7 @@ if [ "$1" ] ;then if [ -z "$ip_mac" ] ; then ip_mac=$( cat /proc/net/arp | grep "0x2" | grep -w $1 | awk '{print $4}' | grep -v "^$" | sort -u );fi ip_name=$( cat ${dir}ipAddress | grep -w $1 |awk '{print $3}' | grep -v "^$" | sort -u ) if ( echo "$ip_mac" | grep -q "unknown" ) || ( echo "$ip_name" | grep -q "unknown" ) ; then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` $1 $ip_mac 无设备名,尝试重新读取" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` $1 $ip_mac 无设备名,尝试重新读取" >> ${logfile};fi time_up=$( cat ${dir}ipAddress | grep -w $ip |awk '{print $4}' | grep -v "^$" | sort -u ) if [ -z "$time_up" ] ; then time_up=`date +%s`;fi sed -i "/$1/d" ${dir}ipAddress @@ -465,39 +456,40 @@ if [ "$1" ] ;then if ( echo ${ip_ms} | grep -q ms ); then # 如果连接成功 - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 设备 $ip_name $1 依然坚挺" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 设备 $ip_name $1 依然坚挺" >> ${logfile};fi # 如果连接失败 else LockFile # 如果定时任务没有运行 if [ ! -z "$send_enable" ] && [ "$send_enable" -ne 3 ] && [ ! -z "$ip_ms" ] ; then - - # 如果通过黑白名单验证 - if [ ! -z `blackwhitelist $1` ] && [ `blackwhitelist $1` -eq 1 ] ; then - if [ -f "${dir}title" ] ; then title=`cat ${dir}title` ;fi - if [ -f "${dir}content" ] ; then content=`cat ${dir}content` ;fi - ip_total=`usage_ip $1` - time_down=`date +%s` - time_up=$( cat ${dir}ipAddress | grep -w $1 |awk '{print $4}' | grep -v "^$" | sort -u ) - time1=$(($time_down-$time_up)) - time1=`time_for_humans $time1` - if [ -z "$title" ] ; then - title="设备离线通知" - content="%0D%0A%0D%0A---%0D%0A%0D%0A####设备断开连接%0D%0A%0D%0A"">$ip_name%0D%0A%0D%0A"">$1%0D%0A%0D%0A"">总计流量:$ip_total%0D%0A%0D%0A"">在线 $time1" - elif ( echo ${title} | grep -q "设备离线通知" ) ; then - title="设备离线通知" - content="%0D%0A%0D%0A"">$ip_name $1 %0D%0A%0D%0A"">总计流量:$ip_total%0D%0A%0D%0A"">在线 $time1" - else - title="设备状态变化" - content="%0D%0A%0D%0A---%0D%0A%0D%0A####设备断开连接%0D%0A%0D%0A"">$ip_name%0D%0A%0D%0A"">$1%0D%0A%0D%0A"">总计流量:$ip_total%0D%0A%0D%0A"">在线 $time1" - fi + if [ ! -z "$serverchan_down" ] && [ "$serverchan_down" -eq "1" ] ; then + # 如果通过黑白名单验证 + if [ ! -z `blackwhitelist $1` ] && [ `blackwhitelist $1` -eq 1 ] ; then + if [ -f "${dir}title" ] ; then title=`cat ${dir}title` ;fi + if [ -f "${dir}content" ] ; then content=`cat ${dir}content` ;fi + ip_total=`usage_ip $1` && if [ ! -z "$ip_total" ] ; then ip_total=">总计流量:$ip_total%0D%0A%0D%0A""";fi + time_down=`date +%s` + time_up=$( cat ${dir}ipAddress | grep -w $1 |awk '{print $4}' | grep -v "^$" | sort -u ) + time1=$(($time_down-$time_up)) + time1=`time_for_humans $time1` + if [ -z "$title" ] ; then + title="设备离线通知" + content="%0D%0A%0D%0A---%0D%0A%0D%0A####设备断开连接%0D%0A%0D%0A"">$ip_name%0D%0A%0D%0A"">$1%0D%0A%0D%0A""$ip_total>在线 $time1" + elif ( echo ${title} | grep -q "设备离线通知" ) ; then + title="设备离线通知" + content="%0D%0A%0D%0A"">$ip_name $1 %0D%0A%0D%0A""$ip_total>在线 $time1" + else + title="设备状态变化" + content="%0D%0A%0D%0A---%0D%0A%0D%0A####设备断开连接%0D%0A%0D%0A"">$ip_name%0D%0A%0D%0A"">$1%0D%0A%0D%0A""$ip_total>在线 $time1" + fi - echo "`date "+%H:%M:%S"` 【微信推送】设备 $ip_name $1 断开连接 " >> ${logfile} - echo $title >${dir}title - echo -n $content >>${dir}content + echo "`date "+%Y-%m-%d %H:%M:%S"` 【微信推送】设备 $ip_name $1 断开连接 " >> ${logfile} + echo $title >${dir}title + echo -n $content >>${dir}content + fi fi - echo "`date "+%H:%M:%S"` 设备 $ip_name $1 断开连接 " >> ${logfile} + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 设备 $ip_name $1 断开连接 " >> ${logfile};fi sed -i "/$1/d" ${dir}ipAddress usage_down $1 unset title @@ -509,17 +501,24 @@ if [ "$1" ] ;then fi } -#发送定时数据 +# 获取SOC温度 +function soc_temp(){ + cat /sys/class/thermal/thermal_zone*/temp | sort | sed '$!d' | cut -c-2 2>/dev/null + # 取所有传感器数值中的最大值 +} + +# 发送定时数据 function send(){ - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【定时数据】创建定时任务" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【定时数据】创建定时任务" >> ${logfile};fi uci set serverchan.serverchan.send_enable=3 uci commit serverchan unset title unset content send_content="" serverchan_cron + serverchan_disturb send_title=`get_config send_title` - if [ -z "$send_title" ] ; then send_title="OpenWrt By tty228 路由状态:";fi + if [ -z "$send_title" ] ; then send_title="路由状态:";fi router_status=`get_config router_status` if [ ! -z "$router_status" ] && [ "$router_status" -eq "1" ] ; then send_content=${send_content}"%0D%0A%0D%0A---%0D%0A%0D%0A#### 系统运行状态%0D%0A%0D%0A";fi #if [ ! -z "$router_status" ] && [ "$router_status" -eq "1" ] ; then send_content=${send_content}"%0D%0A%0D%0A"" CPU占用:`top -n 1 |grep -i Cpu:| awk '{print $3":"$2" "$5":"$4}'`";fi @@ -527,7 +526,7 @@ function send(){ if [ ! -z "$router_status" ] && [ "$router_status" -eq "1" ] ; then send_content=${send_content}"%0D%0A%0D%0A"" 内存占用:`free -m | sed -n '2p' | awk '{print""($3/$2)*100"%"}'`";fi if [ ! -z "$router_status" ] && [ "$router_status" -eq "1" ] ; then send_content=${send_content}"%0D%0A%0D%0A""`cat /proc/uptime| awk -F. '{run_days=$1 / 86400;run_hour=($1 % 86400)/3600;run_minute=($1 % 3600)/60;run_second=$1 % 60;printf(" 运行时间:%d天%d时%d分%d秒",run_days,run_hour,run_minute,run_second)}'`";fi router_temp=`get_config router_temp` - if [ ! -z "$router_temp" ] && [ "$router_temp" -eq "1" ] ; then send_content=${send_content}"%0D%0A%0D%0A""---%0D%0A%0D%0A#### 设备温度%0D%0A%0D%0A CPU:`cut -c1-2 /sys/class/thermal/thermal_zone*/temp`%e2%84%83";fi + if [ ! -z "$router_temp" ] && [ "$router_temp" -eq "1" ] ; then send_content=${send_content}"%0D%0A%0D%0A""---%0D%0A%0D%0A#### 设备温度%0D%0A%0D%0A CPU:`soc_temp`%e2%84%83";fi router_wan=`get_config router_wan` send_wanIP=$(ubus call network.interface.wan status | grep '\"address\"' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') send_wanIPv6=$(ip addr show|grep -v deprecated|grep -A1 'inet6 [^f:]'|sed -nr ':a;N;s#^ +inet6 ([a-f0-9:]+)/.+? scope global .*? valid_lft ([0-9]+sec) .*#\2 \1#p;ta'|sort -nr|head -n1|cut -d' ' -f2) @@ -547,10 +546,10 @@ function send(){ fi client_list=`get_config client_list` if [ ! -z "$client_list" ] && [ "$client_list" -eq "1" ] ; then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【定时数据】检测客户端列表" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【定时数据】检测客户端列表" >> ${logfile};fi if [ ! -f "${dir}ipAddress" ] ; then > ${dir}ipAddress;fi - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【定时数据】开始进行设备下线检测" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【定时数据】开始进行设备下线检测" >> ${logfile};fi IPLIST=$( cat ${dir}ipAddress| awk '{print $1}' | grep -v "^$" | sort -u ) for ip in $IPLIST; do if [ ! -z "$ip" ] ; then @@ -559,7 +558,7 @@ function send(){ done wait - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【定时数据】开始进行设备接入检测" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【定时数据】开始进行设备接入检测" >> ${logfile};fi IPLIST=$( cat /proc/net/arp | grep "0x2" | awk '{print $1}' | grep -v "^$" | sort -u ) for ip in $IPLIST; do if [ ! -z "$ip" ] ; then @@ -572,12 +571,12 @@ function send(){ IPLIST=$( cat ${dir}ipAddress | awk '{print $1}' ) for ip in $IPLIST; do - ip_total=`usage_ip $ip` + ip_total=`usage_ip $ip` && if [ ! -z "$ip_total" ] ; then ip_total="总计流量:$ip_total ";fi time_down=`date +%s` time_up=$( cat ${dir}ipAddress | grep -w $ip |awk '{print $4}' | grep -v "^$" | sort -u ) time1=$(($time_down-$time_up)) time1=`time_for_humans $time1` - send_content=${send_content}"%0D%0A%0D%0A"" `cat ${dir}ipAddress | grep -w $ip | awk '{print $3}' | grep -v "^$" | sort -u` $ip%0D%0A%0D%0A"" 总计流量:$ip_total 在线 $time1" + send_content=${send_content}"%0D%0A%0D%0A"" `cat ${dir}ipAddress | grep -w $ip | awk '{print $3}' | grep -v "^$" | sort -u` $ip%0D%0A%0D%0A"" 在线 $time1" done fi if [ ! -z "$device_name" ] ; then send_title="【$device_name】$send_title" ;fi @@ -585,31 +584,30 @@ function send(){ content=$( echo $content| sed $'s/unknown/%e6%9c%aa%e7%9f%a5%e8%ae%be%e5%a4%87/') #send_content=$( echo $send_content | sed $'s/\ /%20/g'| sed $'s/\"/%22/g'| sed $'s/\#/%23/g'| sed $'s/\&/%26/g'| sed $'s/\,/%2C/g'| sed $'s/\//%2F/g'| sed $'s/\:/%3A/g'| sed $'s/\;/%3B/g'| sed $'s/\=/%3D/g'| sed $'s/\@/%40/g') #未转义 | sed $'s/\(/%28/g' | sed $'s/\)/%29/g' | sed $'s/\+/%2B/g' | sed $'s/\%/%25/g' | sed $'s/\/%3E/g' | sed $'s/\?/%3F/g' | sed $'s/\\/%5C/g' | sed $'s/\|/%7C/g' - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【定时数据】进行 URL 编码,标题=$send_title" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【定时数据】进行 URL 编码,标题=$send_title" >> ${logfile};fi if [ -z "$send_content" ] ; then send_content="%0D%0A%0D%0A---%0D%0A%0D%0A#### 我遇到了一个难题%0D%0A%0D%0A>你没有选择需要发送的项目,该怎么办呢%0D%0A%0D%0A---"; - echo "`date "+%H:%M:%S"` 【!!!】定时发送选项错误,请检查你的设置" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】定时发送选项错误,请检查你的设置" >> ${logfile} fi nowtime=`date "+%Y-%m-%d %H:%M:%S"` if [ ! -z "$serverchan_sheep" ] && [ "$serverchan_sheep" -eq "2" ] && [ ! -z "$starttime" ] && [ ! -z "$endtime" ] ;then if [ `date +%H` -ge $endtime -a $starttime -lt $endtime ] || [ `date +%H` -lt $starttime -a $starttime -lt $endtime ] || [ `date +%H` -lt $starttime -a `date +%H` -ge $endtime -a $starttime -gt $endtime ] ; then curl -s "http://sc.ftqq.com/$serverchan_sckey.send?text=${send_title}" -d "&desp=${nowtime}%0D%0A%0D%0A${send_content}" >/dev/null else - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【定时数据】当前为免打扰时间,消息不发送" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【定时数据】当前为免打扰时间,消息不发送" >> ${logfile};fi fi else curl -s "http://sc.ftqq.com/$serverchan_sckey.send?text=${send_title}" -d "&desp=${nowtime}%0D%0A%0D%0A${send_content}" >/dev/null fi uci set serverchan.serverchan.send_enable=0 uci commit serverchan - echo "`date "+%H:%M:%S"` 【定时数据】微信推送" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 【定时数据】微信推送" >> ${logfile} exit } if [ "$1" ] ;then if [ $1 = "send" ] ;then send;fi if [ $1 = "crontab" ] ;then serverchan_cron;fi - if [ $1 = "del_log" ] ;then clean_log del;fi exit fi @@ -617,18 +615,15 @@ serverchan_cron serverchan_init serverchan_disturb -#初始化在线设备列表 +# 初始化在线设备列表 function serverchan_first(){ if [ ! -z "$serverchan_enable" ] && [ "$serverchan_enable" -eq "1" ] ; then - echo "`date "+%H:%M:%S"` 【初始化】载入在线设备" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 【初始化】载入在线设备" >> ${logfile} uci set serverchan.serverchan.send_enable=3 uci commit serverchan IPLIST=$( cat /proc/net/arp | grep "0x2" | awk '{print $1}' | grep -v "^$" | sort -u ) > ${dir}ipAddress for ip in $IPLIST; do - #忽略列表不检测 - #只检测关注列表 - # 如果 “ip 列表不为空” if [ ! -z "$ip" ] ; then @@ -654,11 +649,10 @@ if [ ! -z "$serverchan_enable" ] && [ "$serverchan_enable" -eq "1" ] ; then wait uci set serverchan.serverchan.send_enable=0 uci commit serverchan - echo "`date "+%H:%M:%S"` 【初始化】初始化完成" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 【初始化】初始化完成" >> ${logfile} fi } serverchan_first -usage while [ "$serverchan_enable" -eq "1" ] ; do @@ -674,32 +668,32 @@ function rand_geturl(){ if [ -z "$check" ] || [ "$check" -ne "200" ] ; then sleep 1 && rand_geturl;fi if [ ! -z "$check" ] && [ "$check" -eq "200" ] ; then usage - if [ ! -z "$network_enable" ] && [ "$network_enable" -eq "404" ] ; then echo "`date "+%H:%M:%S"` 【网络状态】网络恢复正常.." >> ${logfile};fi + if [ ! -z "$network_enable" ] && [ "$network_enable" -eq "404" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【网络状态】网络恢复正常.." >> ${logfile};fi network_enable="200" - #外网IP变化 + # 外网IP变化 if [ ! -z "$serverchan_ipv4" ] && [ ! -z "$serverchan_ipv6" ] && [ "$serverchan_ipv4" -ne "0" ] || [ "$serverchan_ipv6" -ne "0" ] ; then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【外网IP】正在检测外网IP变化" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【外网IP】正在检测外网IP变化" >> ${logfile};fi nowtime=`date "+%Y-%m-%d %H:%M:%S"` - #查询当前 ipv4 + # 查询当前 ipv4 if [ ! -z "$serverchan_ipv4" ] && [ "$serverchan_ipv4" -eq "1" ] ; then IPv4=$(ip -4 address show "$ipv4_interface" | grep inet | grep -v 127.0.0 | awk '{print $2}' | cut -d'/' -f1 | head -n 1 | grep -v "^$" | sort -u);fi if [ ! -z "$serverchan_ipv4" ] && [ "$serverchan_ipv4" -eq "2" ] ; then IPv4=$(curl -k -s -4 "$ipv4_URL");fi - #查询当前 ipv6 + # 查询当前 ipv6 if [ ! -z "$serverchan_ipv6" ] && [ "$serverchan_ipv6" -eq "1" ] ; then IPv6=$(ip -6 address show "$ipv6_interface" | grep inet6 | awk '{print $2}' | cut -d'/' -f1 | head -n 1 | grep -v "^$" | sort -u);fi if [ ! -z "$serverchan_ipv6" ] && [ "$serverchan_ipv6" -eq "2" ] ; then IPv6=$(curl -k -s -6 "$ipv6_URL");fi - #查询ip历史记录 + # 查询ip历史记录 if [ -f ${dir}ip ] ; then last_IPv4=$(cat "${dir}ip" | grep IPv4 | awk '{print $2}' | grep -v "^$" | sort -u) last_IPv6=$(cat "${dir}ip" | grep IPv6 | awk '{print $2}' | grep -v "^$" | sort -u) if [ ! -z "$serverchan_ipv4" ] && [ "$serverchan_ipv4" -ne "0" ] ;then if [ ! -z "$IPv4" ] && ( echo ${IPv4} | grep -w -q ${last_IPv4} );then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` IP 无变化,当前 ip 为 $last_IPv4" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` IP 无变化,当前 ip 为 $last_IPv4" >> ${logfile};fi elif [ ! -z "$IPv4" ] ; then - echo "`date "+%H:%M:%S"` 当前 IP: ${IPv4}" >> ${logfile} - echo "`date "+%H:%M:%S"` 上次 IP: ${last_IPv4}" >> ${logfile} - echo "`date "+%H:%M:%S"` 【微信推送】当前IP:${IPv4}" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 当前 IP: ${IPv4}" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 上次 IP: ${last_IPv4}" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 【微信推送】当前IP:${IPv4}" >> ${logfile} echo IPv4 $IPv4 > ${dir}ip echo -e IPv6 $last_IPv6 >> ${dir}ip @@ -715,17 +709,17 @@ function rand_geturl(){ echo $title >${dir}title echo -n $content >>${dir}content else - echo "`date "+%H:%M:%S"` 【!!!】获取 IPv4 地址失败" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】获取 IPv4 地址失败" >> ${logfile} fi fi if [ ! -z "$serverchan_ipv6" ] && [ "$serverchan_ipv6" -ne "0" ] ;then if [ ! -z "$IPv6" ] && ( echo ${IPv6} | grep -w -q ${last_IPv6} );then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` IPv6 无变化,当前 ipv6 为 $last_IPv6" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` IPv6 无变化,当前 ipv6 为 $last_IPv6" >> ${logfile};fi elif [ ! -z "$IPv6" ] ; then - echo "`date "+%H:%M:%S"` 当前 IPv6: ${IPv6}" >> ${logfile} - echo "`date "+%H:%M:%S"` 上次 IPv6: ${last_IPv6}" >> ${logfile} - echo "`date "+%H:%M:%S"` 【微信推送】当前IPv6:${IPv6}" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 当前 IPv6: ${IPv6}" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 上次 IPv6: ${last_IPv6}" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 【微信推送】当前IPv6:${IPv6}" >> ${logfile} echo IPv4 $IPv4 > ${dir}ip echo -e IPv6 $IPv6 >> ${dir}ip @@ -741,16 +735,16 @@ function rand_geturl(){ echo $title >${dir}title echo -n $content >>${dir}content else - echo "`date "+%H:%M:%S"` 【!!!】获取 IPv6 地址失败" >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】获取 IPv6 地址失败" >> ${logfile} fi fi else unset last_IPv4 unset last_IPv6 - echo "`date "+%H:%M:%S"` 【微信推送】路由器已经重启!" >> ${logfile} - if [ ! -z "$serverchan_ipv4" ] && [ "$serverchan_ipv4" -ne "0" ] ;then echo "`date "+%H:%M:%S"` 当前IP: ${IPv4}" >> ${logfile};fi - if [ ! -z "$serverchan_ipv6" ] && [ "$serverchan_ipv6" -ne "0" ] ;then echo "`date "+%H:%M:%S"` 当前IPv6: ${IPv6}" >> ${logfile};fi + echo "`date "+%Y-%m-%d %H:%M:%S"` 【微信推送】路由器已经重启!" >> ${logfile} + if [ ! -z "$serverchan_ipv4" ] && [ "$serverchan_ipv4" -ne "0" ] ;then echo "`date "+%Y-%m-%d %H:%M:%S"` 当前IP: ${IPv4}" >> ${logfile};fi + if [ ! -z "$serverchan_ipv6" ] && [ "$serverchan_ipv6" -ne "0" ] ;then echo "`date "+%Y-%m-%d %H:%M:%S"` 当前IPv6: ${IPv6}" >> ${logfile};fi echo IPv4 $IPv4 > ${dir}ip echo -e IPv6 $IPv6 >> ${dir}ip @@ -766,22 +760,22 @@ function rand_geturl(){ if [ -f ${logfile} ] ; then clean_log;fi fi - #设备下线提醒 + # 设备下线提醒 if [ ! -z "$serverchan_down" ] && [ "$serverchan_down" -eq "1" ] ; then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【离线】开始进行设备下线检测" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【离线】开始进行设备下线检测" >> ${logfile};fi fi read_config - #从 ipAddress 文件中读取上次检测到的在线列表 - IPLIST=$( cat ${dir}ipAddress | awk '{print $1}' | grep -v "^$" | sort -u ) - IPLISTrow=$(grep -c "" ${dir}ipAddress) - for ip in $IPLIST; do + # 从 ipAddress 文件中读取上次检测到的在线列表 + if [ -f ${dir}ipAddress ] ; then IPLIST=$( cat ${dir}ipAddress | awk '{print $1}' | grep -v "^$" | sort -u ) && IPLISTrow=$(grep -c "" ${dir}ipAddress);fi + + for ip in $IPLIST; do # 如果 ip 列表不为空 send_enable=`get_config send_enable` if [ ! -z "$ip" ] && [ "$send_enable" -ne 3 ] ; then ip_mac=$( cat /var/dhcp.leases | grep -w $ip |awk '{print $2}' | grep -v "^$" | sort -u ) if [ -z "$ip_mac" ] ; then ip_mac=$( cat /proc/net/arp | grep "0x2" | grep -w $ip | awk '{print $4}' | grep -v "^$" | sort -u );fi - #设备名为空时尝试重读 + # 设备名为空时尝试重读 if [ ! -z "$device_aliases" ] && [ ! -z "$ip_mac" ] && ( echo "$device_aliases" | grep -q -i $ip_mac ); then ip_name=$( echo "$device_aliases" | grep -i $ip_mac |awk '{print $2}' | grep -v "^$" | sort -u ) ipAddress_name=$( cat ${dir}ipAddress | grep -w $ip | awk '{print $3}' | grep -v "^$" | sort -u ) @@ -800,21 +794,19 @@ function rand_geturl(){ down $ip & fi - done - wait - if [ "$IPLISTrow" -eq $(grep -c "" ${dir}ipAddress) ] ; then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 没有检测到设备离线" >> ${logfile};fi - fi - #fi + done + wait + if [ "$IPLISTrow" -eq $(grep -c "" ${dir}ipAddress) ] ; then + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 没有检测到设备离线" >> ${logfile};fi + fi - #新设备接入 + # 新设备接入 if [ ! -z "$serverchan_up" ] && [ "$serverchan_up" -eq "1" ] ; then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【连接】开始进行设备接入检测" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【连接】开始进行设备接入检测" >> ${logfile};fi fi read_config - #从 arp 缓存中读取 0x2 在线列表 - IPLIST=$( cat /proc/net/arp | grep "0x2" | awk '{print $1}' | grep -v "^$" | sort -u ) - IPLISTrow=$(grep -c "" ${dir}ipAddress) + # 从 arp 缓存中读取 0x2 在线列表 + if [ -f ${dir}ipAddress ] ; then IPLIST=$( cat /proc/net/arp | grep "0x2" | awk '{print $1}' | grep -v "^$" | sort -u ) && IPLISTrow=$(grep -c "" ${dir}ipAddress);fi for ip in $IPLIST; do # 如果 “ip 列表不为空” send_enable=`get_config send_enable` @@ -841,55 +833,82 @@ function rand_geturl(){ done wait if [ "$IPLISTrow" -eq $(grep -c "" ${dir}ipAddress) ] ; then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 没有新设备连接" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 没有新设备连接" >> ${logfile};fi else usage fi cpu_Alert=0 - #负载状态报警 + # 负载状态报警 if [ ! -z "$cpuload_enable" ] && [ "$cpuload_enable" -eq "1" ] ; then - - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【负载】正在检测 CPU 负载" >> ${logfile};fi - cpu_fuzai=`cat /proc/loadavg | awk '{print $1}'` + if [ -z "$cpuload_time" ] ; then cpuload_time=`date +%s`;fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【负载】正在检测 CPU 负载" >> ${logfile};fi + cpu_fuzai=`cat /proc/loadavg | awk '{print $1}' 2>/dev/null` cpuload=`get_config cpuload` - if [ ! -z "$cpuload" ] && [ `expr $cpu_fuzai \> $cpuload` -eq "1" ] ; then - cpuload_n=$(($cpuload_n+1)) - echo "`date "+%H:%M:%S"` 【!!警报!!】当前 CPU 负载过高: ${cpu_fuzai}" >> ${logfile} - else - cpuload_n=0 - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` CPU 负载正常:$cpu_fuzai" >> ${logfile};fi + if [ ! -z "$cpu_fuzai" ] && [ ! -z "$cpuload" ] && [ `expr $cpu_fuzai \> $cpuload` -eq "1" ] ; then + if [ -f ${logfile} ] && [ $(grep -c "" ${logfile}) -ge "2" ] ; then + log_end=`awk '{print}' ${logfile} | tail -n 2 | awk 'NR==1'` + log_end_2=`awk 'END {print}' ${logfile}` + if ( echo ${log_end} | grep -q "负载" ) && ( echo ${log_end_2} | grep -q "负载" ) ; then + sed -i '$d' -i /tmp/serverchan/serverchan.log + sed -i '$d' -i /tmp/serverchan/serverchan.log + echo "`echo $log_end | awk '{print $1" "$2}'` 【刷屏日志自动过滤】 CPU 负载持续超高: `echo $log_end | awk '{print $6}'`" >> ${logfile} + fi + fi + echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!警报!!】 CPU 负载过高: ${cpu_fuzai}" >> ${logfile} + elif [ -z "$cpu_fuzai" ] ; then + echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取设备负载,请检查命令" >> ${logfile} + # 一小时 CD 中 + elif [ ! -z "$cpucd_time" ] ; then + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` CPU 负载正常:$cpu_fuzai" >> ${logfile};fi + else + cpuload_time=`date +%s` + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` CPU 负载正常:$cpu_fuzai" >> ${logfile};fi fi - if [ "$cpuload_n" -eq "5" ] ;then + if [ "$((`date +%s`-$cpuload_time))" -ge "300" ] && [ -z "$cpucd_time" ] ; then if [ -f "${dir}title" ] ; then title=`cat ${dir}title` ;fi if [ -f "${dir}content" ] ; then content=`cat ${dir}content` ;fi title="CPU 负载过高!" cpu_Alert=1 - cpuload_time=`date +%s` - echo "`date "+%H:%M:%S"` 【微信推送】当前 CPU 负载过高: ${cpu_fuzai}" >> ${logfile} + if [ -z "$cpucd_time" ] ; then cpucd_time=1;fi + echo "`date "+%Y-%m-%d %H:%M:%S"` 【微信推送】 CPU 负 载过高: ${cpu_fuzai}" >> ${logfile} content="%0D%0A%0D%0A---%0D%0A%0D%0A""####CPU 负载过高%0D%0A%0D%0A>CPU 负载已连续五分钟超过预设%0D%0A%0D%0A>接下来一小时不再提示%0D%0A%0D%0A>当前负载:${cpu_fuzai}" echo $title >${dir}title echo -n $content >>${dir}content - elif [ "$cpuload_n" -gt "5" ] && [ "$((`date +%s`-$cpuload_time))" -ge "3600" ] ;then - cpuload_n=4 + elif [ "$((`date +%s`-$cpuload_time))" -ge "3300" ] ;then + unset cpucd_time fi fi - #温度状态报警 + # 温度状态报警 if [ ! -z "$temperature_enable" ] && [ "$temperature_enable" -eq "1" ] ; then - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【温度】正在检测 CPU 温度" >> ${logfile};fi - cpu_wendu=`cut -c1-2 /sys/class/thermal/thermal_zone*/temp` + if [ -z "$temperature_time" ] ; then temperature_time=`date +%s`;fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【温度】正在检测 CPU 温度" >> ${logfile};fi + cpu_wendu=`soc_temp` temperature=`get_config temperature` - if [ ! -z "$temperature" ] && [ "$cpu_wendu" -gt "$temperature" ] ; then - temperature_n=$(($temperature_n+1)) - echo "`date "+%H:%M:%S"` 【!!警报!!】当前 CPU 温度过高: ${cpu_wendu}" >> ${logfile} + if [ ! -z "$cpu_wendu" ] && [ ! -z "$temperature" ] && [ "$cpu_wendu" -gt "$temperature" ] ; then + if [ -f ${logfile} ] && [ $(grep -c "" ${logfile}) -ge "2" ] ; then + log_end=`awk '{print}' ${logfile} | tail -n 2 | awk 'NR==1'` + log_end_2=`awk 'END {print}' ${logfile}` + if ( echo ${log_end} | grep -q "温度" ) && ( echo ${log_end_2} | grep -q "温度" ) ; then + sed -i '$d' -i /tmp/serverchan/serverchan.log + sed -i '$d' -i /tmp/serverchan/serverchan.log + echo "`echo $log_end | awk '{print $1" "$2}'` 【刷屏日志自动过滤】 CPU 温度持续超高: `echo $log_end | awk '{print $6}'`" >> ${logfile} + fi + fi + echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!警报!!】 CPU 温度过高: ${cpu_wendu}" >> ${logfile} + elif [ -z "$cpu_wendu" ] ; then + echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取设备温度,请检查命令" >> ${logfile} + # 一小时 CD 中 + elif [ ! -z "$temperaturecd_time" ] ; then + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` CPU 温度正常:$cpu_wendu" >> ${logfile};fi else - temperature_n=0 - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` CPU 温度正常:$cpu_wendu" >> ${logfile};fi + temperature_time=`date +%s` + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` CPU 温度正常:$cpu_wendu" >> ${logfile};fi fi - if [ "$temperature_n" -eq "5" ] ;then + if [ "$((`date +%s`-$temperature_time))" -ge "300" ] && [ -z "$temperaturecd_time" ] ; then if [ -f "${dir}title" ] ; then title=`cat ${dir}title` ;fi if [ -f "${dir}content" ] ; then content=`cat ${dir}content` ;fi if [ ! -z "$title" ] && ( echo ${title} | grep -q "过高" ) ; then @@ -898,13 +917,13 @@ function rand_geturl(){ title="CPU 温度过高!" fi cpu_Alert=1 - temperature_time=`date +%s` - echo "`date "+%H:%M:%S"` 【微信推送】当前 CPU 温度过高: ${cpu_wendu}" >> ${logfile} + if [ -z "$temperaturecd_time" ] ; then temperaturecd_time=1;fi + echo "`date "+%Y-%m-%d %H:%M:%S"` 【微信推送】 CPU 温 度过高: ${cpu_wendu}" >> ${logfile} content="%0D%0A%0D%0A---%0D%0A%0D%0A""####CPU 温度过高%0D%0A%0D%0A>CPU 温度已连续五分钟超过预设%0D%0A%0D%0A>接下来一小时不再提示%0D%0A%0D%0A>当前温度:${cpu_wendu}" echo $title >${dir}title echo -n $content >>${dir}content - elif [ "$temperature_n" -gt "5" ] && [ "$((`date +%s`-$temperature_time))" -ge "3600" ] ;then - temperature_n=4 + elif [ "$((`date +%s`-$temperature_time))" -ge "3300" ] ;then + unset temperaturecd_time fi fi @@ -928,7 +947,7 @@ function rand_geturl(){ else if [ ! -z "$network_enable" ] && [ "$network_enable" -eq "200" ] ; then - echo "`date "+%H:%M:%S"` 【!!!!】当前网络不通!停止检测! " >> ${logfile} + echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!!】当前网络不通!停止检测! " >> ${logfile} network_enable="404" fi enable_detection $sleeptime @@ -942,7 +961,7 @@ function rand_geturl(){ do if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] && [ "$send_str" -eq "0" ] ; then if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "-----------------------------------------------------" >> ${logfile};fi - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 发送定时数据,程序暂停中" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 发送定时数据,程序暂停中" >> ${logfile};fi if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo ""-----------------------------------------------------"" >> ${logfile};fi send_str=1 fi @@ -963,12 +982,12 @@ function serverchan_send(){ if [ ! -z "$device_name" ] ; then title="【$device_name】$title" ;fi title=$( echo $title | sed $'s/\ /%20/g'| sed $'s/\"/%22/g'| sed $'s/\#/%23/g'| sed $'s/\&/%26/g'| sed $'s/\,/%2C/g'| sed $'s/\//%2F/g'| sed $'s/\:/%3A/g'| sed $'s/\;/%3B/g'| sed $'s/\=/%3D/g'| sed $'s/\@/%40/g') content=$( echo $content| sed $'s/unknown/%e6%9c%aa%e7%9f%a5%e8%ae%be%e5%a4%87/') - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 进行 URL 编码,标题=$title" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 进行 URL 编码,标题=$title" >> ${logfile};fi if [ ! -z "$serverchan_sheep" ] && [ "$serverchan_sheep" -eq "2" ] && [ ! -z "$starttime" ] && [ ! -z "$endtime" ] ;then if [ `date +%H` -ge $endtime -a $starttime -lt $endtime ] || [ `date +%H` -lt $starttime -a $starttime -lt $endtime ] || [ `date +%H` -lt $starttime -a `date +%H` -ge $endtime -a $starttime -gt $endtime ] ; then curl -s "http://sc.ftqq.com/$serverchan_sckey.send?text=${title}" -d "&desp=${nowtime}%0D%0A%0D%0A${content}" >/dev/null else - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 当前为免打扰时间,消息不发送" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 当前为免打扰时间,消息不发送" >> ${logfile};fi fi else curl -s "http://sc.ftqq.com/$serverchan_sckey.send?text=${title}" -d "&desp=${nowtime}%0D%0A%0D%0A${content}" >/dev/null @@ -978,23 +997,13 @@ function serverchan_send(){ rm -f ${dir}title >/dev/null 2>&1 rm -f ${dir}content >/dev/null 2>&1 fi - if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%H:%M:%S"` 【等待】我累了,$sleeptime 秒后再回来" >> ${logfile};fi + if [ ! -z "$debuglevel" ] && [ "$debuglevel" -ne "1" ] ; then echo "`date "+%Y-%m-%d %H:%M:%S"` 【等待】我累了,$sleeptime 秒后再回来" >> ${logfile};fi enable_detection $sleeptime } serverchan_disturb serverchan_send - #if [ ! -z "$serverchan_sheep" ] && [ "$serverchan_sheep" -eq "1" ] && [ ! -z "$starttime" ] && [ ! -z "$endtime" ] ;then - # if [ `date +%H` -ge $endtime -a $starttime -lt $endtime ] || [ `date +%H` -lt $starttime -a $starttime -lt $endtime ] || [ `date +%H` -lt $starttime -a `date +%H` -ge $endtime -a $starttime -gt $endtime ] ; then - # serverchan_send - # else - # serverchan_disturb - # fi - #else - # serverchan_send - #fi - continue done -echo "`date "+%H:%M:%S"` 【!!!】程序未启用,退出脚本!" >> ${logfile} +echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】程序未启用,退出脚本!" >> ${logfile} exit