diff --git a/package/ctcgfw/luci-app-serverchan/Makefile b/package/ctcgfw/luci-app-serverchan/Makefile
index f772ad7c38..7a7f97ff99 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.78
+PKG_VERSION:=1.79
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 9858e374b7..5c9e0276ce 100644
--- a/package/ctcgfw/luci-app-serverchan/luasrc/controller/serverchan.lua
+++ b/package/ctcgfw/luci-app-serverchan/luasrc/controller/serverchan.lua
@@ -7,18 +7,18 @@ function index()
end
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"),_("高级设置"), 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", "status"}, call("act_status")).leaf=true
end
function act_status()
local e={}
- e.running=luci.sys.call("pgrep -f serverchan/serverchan >/dev/null")==0
+ e.running=luci.sys.call("ps|grep -v grep|grep -c serverchan >/dev/null")==0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
@@ -30,4 +30,4 @@ end
function clear_log()
luci.sys.call("echo '' > /tmp/serverchan/serverchan.log")
-end
+end
\ No newline at end of file
diff --git a/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan/setting.lua b/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan/setting.lua
index 495325422a..1968620eb4 100644
--- a/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan/setting.lua
+++ b/package/ctcgfw/luci-app-serverchan/luasrc/model/cbi/serverchan/setting.lua
@@ -32,16 +32,20 @@ a=s:taboption("basic", ListValue,"send_tg",translate("推送模式"))
a.default=""
a.rmempty = true
a:value("",translate("微信"))
+a:value("2",translate("微信测试号版"))
a:value("1",translate("Telegram"))
a=s:taboption("basic", Value,"sckey",translate('SCKEY'), translate("Serverchan Sckey").."
调用代码获取点击这里
")
a.rmempty = true
a:depends("send_tg","")
-a=s:taboption("basic", Value, "tgtoken", translate("tg推送链接"),translate("").."
获取机器人点击这里
")
+a=s:taboption("basic", Value,"sctkey",translate('SCKEY'), translate("Serverchan Sckey").."
调用代码获取点击这里
")
+a.rmempty = true
+a:depends("send_tg","2")
+
+a=s:taboption("basic", Value, "tgtoken", translate("tg推送链接"),translate("").."
目前公众号已停用,需要自建服务器
获取机器人点击这里
此处填入推送链接,如https://tgbot.lbyczf.com/sendMessage/:Token
")
a.rmempty = true
a:depends("send_tg","1")
-a.placeholder="https://tgbot.lbyczf.com/sendMessage/:Token"
a=s:taboption("basic", Value,"device_name",translate('本设备名称'))
a.rmempty = true
@@ -53,6 +57,20 @@ a.optional = false
a.default = "60"
a.description = translate("越短的时间时间响应越及时,但会占用更多的系统资源")
+a=s:taboption("basic", ListValue,"oui_data",translate("MAC设备信息数据库"))
+a.rmempty = true
+a.default=""
+a:value("",translate("关闭"))
+a:value("1",translate("简化版"))
+a:value("2",translate("完整版"))
+a:value("3",translate("网络查询"))
+a.description = translate("原始数据大小为 4.36m,处理后的完整版约 1.2M,简化版约 250kb
若无梯子,请勿使用网络查询")
+
+a=s:taboption("basic", Flag,"oui_dir",translate("下载到内存"))
+a.rmempty = true
+a:depends("oui_data","1")
+a:depends("oui_data","2")
+
a=s:taboption("basic", Flag,"debuglevel",translate("开启日志"))
a.rmempty = true
@@ -88,7 +106,7 @@ a= s:taboption("content", Value, "ipv4_URL", "URL 地址")
a.rmempty = true
a.default = "members.3322.org/dyndns/getip"
a:depends({serverchan_ipv4="2"})
-a.description = translate("
会因服务器稳定性/连接频繁等原因导致获取失败")
+a.description = translate("
会因服务器稳定性、连接频繁等原因导致获取失败
如接口可以正常获取 IP,不推荐使用")
a=s:taboption("content", ListValue,"serverchan_ipv6",translate("ipv6 变动通知"))
a.rmempty = true
@@ -117,7 +135,7 @@ a= s:taboption("content", Value, "ipv6_URL", "URL 地址")
a.rmempty = true
a.default = "v6.ip.zxinc.org/getip"
a:depends({serverchan_ipv6="2"})
-a.description = translate("
会因服务器稳定性/连接频繁等原因导致获取失败")
+a.description = translate("
会因服务器稳定性、连接频繁等原因导致获取失败
如接口可以正常获取 IP,不推荐使用")
a=s:taboption("content", Flag,"serverchan_up",translate("设备上线通知"))
a.default=1
@@ -134,11 +152,12 @@ a.rmempty = true
a= s:taboption("content", Value, "cpuload", "负载报警阈值")
a.default = 2
a.rmempty = true
-
a:depends({cpuload_enable="1"})
+
a=s:taboption("content", Flag,"temperature_enable",translate("CPU 温度报警"))
-a.default=70
+a.default=1
a.rmempty = true
+a.description = translate("请确认设备可以获取温度,如需修改命令,请移步高级设置")
a= s:taboption("content", Value, "temperature", "温度报警阈值")
a.rmempty = true
@@ -147,6 +166,27 @@ a.datatype="uinteger"
a:depends({temperature_enable="1"})
a.description = translate("
设备报警只会在连续五分钟超过设定值时才会推送
而且一个小时内不会再提醒第二次")
+a=s:taboption("content", Flag,"client_usage",translate("设备异常流量"))
+a.default=0
+a.rmempty = true
+
+a= s:taboption("content", Value, "client_usage_max", "每分钟流量限制")
+a.default = "10M"
+a.rmempty = true
+a:depends({client_usage="1"})
+a.description = translate("设备异常流量警报(byte),你可以追加 K 或者 M")
+
+a=s:taboption("content", Flag,"client_usage_disturb",translate("异常流量免打扰"))
+a.default=1
+a.rmempty = true
+a:depends({client_usage="1"})
+
+a = s:taboption("content", DynamicList, "client_usage_whitelist", translate("异常流量关注列表"))
+nt.mac_hints(function(mac, name) a:value(mac, "%s (%s)" %{ mac, name }) end)
+a.rmempty = true
+a:depends({client_usage_disturb="1"})
+a.description = translate("请输入设备 MAC")
+
--定时推送
a=s:taboption("crontab", ListValue,"send_mode",translate("定时任务设定"))
a.rmempty = true
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 6a38464d73..69e71d55a0 100755
--- a/package/ctcgfw/luci-app-serverchan/root/usr/bin/serverchan/serverchan
+++ b/package/ctcgfw/luci-app-serverchan/root/usr/bin/serverchan/serverchan
@@ -10,14 +10,16 @@ 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" "err_device_aliases"
+ 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" "sctkey" "oui_dir" "oui_data" "client_usage" "client_usage_max" "client_usage_disturb" "client_usage_whitelist"
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
dir="/tmp/serverchan/" && mkdir -p ${dir}
+ [ ! -z "$oui_dir" ] && [ "$oui_dir" -eq "1" ] && oui_base="${dir}oui_base.txt" || oui_base="/usr/bin/serverchan/oui_base.txt"
debuglevel=`echo "$debuglevel"` && [ -z "$debuglevel" ] && logfile="/dev/null" || logfile="${dir}serverchan.log"
- device_aliases=`echo "$device_aliases"|sed 's/ /\n/g'|sed 's/-/ /g'` 2>/dev/null
+ device_aliases=`echo "$device_aliases"|sed 's/ /\n/g'|sed 's/-/ /'` 2>/dev/null
err_device_aliases=`echo "$err_device_aliases"|sed 's/ /\n/g'` 2>/dev/null
+ client_usage_whitelist=`echo "$client_usage_whitelist"|sed 's/ /\n/g'` 2>/dev/null
[ "$iw_version" ] && wlan_interface=`iw dev|grep Interface|awk '{print $2}'` >/dev/null 2>&1
[ -z "$up_timeout" ] || [ "$up_timeout" -eq "0" ] && up_timeout="2"
[ -z "$down_timeout" ] || [ "$down_timeout" -eq "0" ] && down_timeout="20";down_timeout=`expr ${down_timeout} / 2 + 1`
@@ -28,21 +30,43 @@ function read_config(){
# 初始化
function serverchan_init(){
+ enable_detection
if [ -f "/usr/bin/serverchan/errlog" ]; then
cat /usr/bin/serverchan/errlog > ${logfile}
echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】载入上次重启前日志" >> ${logfile}
echo "--------------------------------------------------------" >> ${logfile}
fi
+ down_oui &
deltemp
- rm -f ${dir}fd1 ${dir}sheep_usage ${dir}old_sheep_usage /usr/bin/serverchan/errlog >/dev/null 2>&1
+ rm -f ${dir}fd1 ${dir}sheep_usage ${dir}old_sheep_usage ${dir}client_usage_aliases ${dir}old_client_usage_aliases /usr/bin/serverchan/errlog >/dev/null 2>&1
[ ! -f "/usr/sbin/wrtbwmon" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】未安装 wrtbwmon ,流量统计不可用" >> ${logfile}
for read_str in "ip_version" "cu_version"; do
- [ -z `eval echo '$'$read_str` ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】依赖项未安装" >> ${logfile} && return 1
+ [ -z `eval echo '$'$read_str` ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】依赖项 iputils-arping、curl 未安装,请确认插件是否正常运行" >> ${logfile}
done
- [ -z "$sckey" ] && [ -z "$tgtoken" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】请填写正确的 sckey " >> ${logfile} && return 1
+ [ -z "$sckey" ] && [ -z "$sctkey" ] && [ -z "$tgtoken" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】请填写正确的 sckey " >> ${logfile} && return 1
return 0
}
+# 下载设备MAC厂商信息
+function down_oui(){
+ [ -f ${oui_base} ] && local logrow=$(grep -c "" ${oui_base}) || local logrow="0"
+ [ $logrow -lt "10" ] && rm -f ${oui_base} >/dev/null 2>&1
+ if [ ! -z "$oui_data" ] && [ "$oui_data" -ne "3" ] && [ ! -f ${oui_base} ]; then
+ echo "`date "+%Y-%m-%d %H:%M:%S"` 【初始化】设备MAC厂商信息不存在,重新下载" >> ${logfile}
+ wget --no-check-certificate -t 3 -T 15 -O ${dir}oui.txt https://linuxnet.ca/ieee/oui.txt >/dev/null 2>&1
+ if [ -f ${dir}oui.txt ] && [ "$oui_data" -eq "1" ]; then
+ cat ${dir}oui.txt|grep "base 16"|grep -i "apple\|aruba\|asus\|autelan\|belkin\|bhu\|buffalo\|cctf\|cisco\|comba\|datang\|dell\|dlink\|dowell\|ericsson\|fast\|feixun\|\
+fiberhome\|fujitsu\|grentech\|h3c\|hisense\|hiwifi\|honghai\|honghao\|hp\|htc\|huawei\|intel\|jinli\|jse\|lenovo\|lg\|liteon\|malata\|meizu\|mercury\|meru\|moto\|netcore\|\
+netgear\|nokia\|omron\|oneplus\|oppo\|philips\|router_unkown\|samsung\|shanzhai\|sony\|start_net\|sunyuanda\|tcl\|tenda\|texas\|tianyu\|tp-link\|ubq\|undefine\|VMware\|\
+utstarcom\|volans\|xerox\|xiaomi\|zdc\|zhongxing\|smartisan" > ${oui_base} && echo "`date "+%Y-%m-%d %H:%M:%S"` 【初始化】设备MAC厂商信息下载成功" >> ${logfile} || echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】设备MAC厂商信息下载失败" >> ${logfile}
+ fi
+ if [ -f ${dir}oui.txt ] && [ "$oui_data" -eq "2" ]; then
+ cat ${dir}oui.txt|grep "base 16" > ${oui_base} && echo "`date "+%Y-%m-%d %H:%M:%S"` 【初始化】设备MAC厂商信息下载成功" >> ${logfile} || echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】设备MAC厂商信息下载失败" >> ${logfile}
+ fi
+ rm -f ${dir}oui.txt >/dev/null 2>&1
+ fi
+}
+
# 清理临时文件
function deltemp(){
unset title content
@@ -82,7 +106,7 @@ function getip(){
# 查询 mac 地址
function getmac(){
- #( echo "$tmp_mac"|grep -q "unknown" ) && unset tmp_mac # 为unknown时重新读取
+ ( echo "$tmp_mac"|grep -q "unknown" ) && unset tmp_mac # 为unknown时重新读取
[ -f "${dir}ipAddress" ] && [ -z "$tmp_mac" ] && local tmp_mac=`cat ${dir}ipAddress|grep -w ${1}|awk '{print $2}'|grep -v "^$"|sort -u`
[ -f "${dir}tmp_downlist" ] && [ -z "$tmp_mac" ] && local tmp_mac=`cat ${dir}tmp_downlist|grep -w ${1}|awk '{print $2}'|grep -v "^$"|sort -u`
[ -f "/var/dhcp.leases" ] && [ -z "$tmp_mac" ] && local tmp_mac=`cat /var/dhcp.leases|grep -w ${1}|awk '{print $2}'|grep -v "^$"|sort -u`
@@ -93,11 +117,12 @@ function getmac(){
# 查询主机名
function getname(){
- #( echo "$tmp_name"|grep -q "unknown" ) && unset tmp_name # 为unknown时重新读取
+ [ -z "$tmp_name" ] && local tmp_name=`echo "$device_aliases"|grep -i $2|awk '{print $2}'|grep -v "^$"|sort -u`
[ -f "${dir}ipAddress" ] && [ -z "$tmp_name" ] && local tmp_name=`cat ${dir}ipAddress|grep -w ${1}|awk '{print $3}'|grep -v "^$"|sort -u`
[ -f "${dir}tmp_downlist" ] && [ -z "$tmp_name" ] && local tmp_name=`cat ${dir}tmp_downlist|grep -w ${1}|awk '{print $3}'|grep -v "^$"|sort -u`
- [ -z "$tmp_name" ] && local tmp_name=`echo "$device_aliases"|grep -i $2|awk '{print $2}'|grep -v "^$"|sort -u`
- [ ! -z "$tmp_name" ] && echo "$tmp_name" && return
+ ( ! echo "$tmp_name"|grep -q -w "unknown\|*" ) && [ ! -z "$tmp_name" ] && echo "$tmp_name" && return || unset tmp_name # 为unknown时重新读取
+ [ -f "/var/dhcp.leases" ] && [ -z "$tmp_name" ] && local tmp_name=`cat /var/dhcp.leases|grep -w ${1}|awk '{print $4}'|grep -v "^$"|sort -u`
+ ( ! echo "$tmp_name"|grep -q -w "unknown\|*" ) && [ ! -z "$tmp_name" ] && echo "$tmp_name" && return || unset tmp_name # 为unknown时重新读取
[ -z "$dhcp_config" ] && dhcp_config=`uci show dhcp|grep "ip\|mac\|name"`
for dhcp_config_str in "host" "domain"; do
local dhcp_ip_n=`echo "$dhcp_config"|grep -w ^dhcp.@${dhcp_config_str}.*ip=.${1}|sed -nr 's#^dhcp.(.*).ip.*#\1#gp'` 2>/dev/null
@@ -106,7 +131,9 @@ function getname(){
[ ! -z "$dhcp_mac_n" ] && [ -z "$tmp_name" ] && local tmp_name=`uci get dhcp.${dhcp_ip_n}.name` 2>/dev/null
[ ! -z "$tmp_name" ] && break
done
- [ -f "/var/dhcp.leases" ] && [ -z "$tmp_name" ] && local tmp_name=`cat /var/dhcp.leases|grep -w ${1}|awk '{print $4}'|grep -v "^$"|sort -u`
+ ( ! echo "$tmp_name"|grep -q -w "unknown\|*" ) && [ ! -z "$tmp_name" ] && echo "$tmp_name" && return || unset tmp_name # 为unknown时重新读取
+ [ -f "$oui_base" ] && local tmp_name=$(cat $oui_base|grep -i $(echo "$2"|cut -c 1,2,4,5,7,8)|sed -nr 's#^.*16)..(.*)#\1#gp'|sed 's/ /_/g')
+ [ "$oui_data" -eq "4" ] && local tmp_name=$(curl -sS "http://standards-oui.ieee.org/oui.txt"|grep -i $(echo "$2"|cut -c 1,2,4,5,7,8)|sed -nr 's#^.*16)..(.*)#\1#gp'|sed 's/ /_/g')
[ -z "$tmp_name" ] && local tmp_name="unknown"
echo "$tmp_name"
}
@@ -166,7 +193,7 @@ function usage(){
[ -z "$total_n" ] && total_n="6"
[ "$2" ] && local tmptotal=`cat ${dir}usage.db|sed 's/,,,/,0,0,/g'|sed 's/,,/,0,/g'|sed 's/,/ /g'|grep -i -w ${2}|awk "{print "'$'$total_n"}"|grep -v "^$"|sort -u` 2>/dev/null
[ -z "$tmptotal" ] && local tmptotal="0"
- [ ! "$3" ] && echo `bytes_for_humans ${tmptotal}` || echo $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
@@ -176,9 +203,55 @@ function usage(){
function bytes_for_humans {
[ ! "$1" ] && return
[ "$1" -gt 1073741824 ] && echo "`awk 'BEGIN{printf "%.2f\n",'$1'/'1073741824'}'` GB" && return
- [ "$1" -lt 1073741824 ] && echo "`awk 'BEGIN{printf "%.2f\n",'$1'/'1048576'}'` MB" && return
- [ "$1" -lt 1048576 ] && echo "`awk 'BEGIN{printf "%.2f\n",'$1'/'1024'}'` KB" && return
- [ "$1" -lt 1024 ] && echo "${1} bytes"
+ [ "$1" -gt 1048576 ] && echo "`awk 'BEGIN{printf "%.2f\n",'$1'/'1048576'}'` MB" && return
+ [ "$1" -gt 1024 ] && echo "`awk 'BEGIN{printf "%.2f\n",'$1'/'1024'}'` KB" && return
+ echo "${1} bytes"
+}
+
+# 设备异常流量检测
+function get_client_usage(){
+ [ -z "$client_usage" ] && return
+ [ "$client_usage" -ne "1" ] && return
+ [ -z "$client_usage_max" ] && return
+ [ -z "$get_client_usage_time" ] && get_client_usage_time=`date +%s`
+ ( echo ${client_usage_max: -1}|grep -q "K\|k" ) && client_usage_max=`expr ${client_usage_max%?} \* 1024`
+ ( echo ${client_usage_max: -1}|grep -q "M\|m" ) && client_usage_max=`expr ${client_usage_max%?} \* 1048576`
+ ( echo ${client_usage_max: -1}|grep -q "G\|g" ) && client_usage_max=`expr ${client_usage_max%?} \* 1073741824`
+
+ [ "$client_usage_disturb" -eq "0" ] || [ -z "$client_usage_disturb" ] && [ -f "${dir}ipAddress" ] && local MACLIST=`cat ${dir}ipAddress|awk '{print $2}'|grep -v "^$"|sort -u`
+ [ ! -z "$client_usage_disturb" ] && [ "$client_usage_disturb" -eq "1" ] && [ ! -z "$client_usage_whitelist" ] && local MACLIST=`echo "$client_usage_whitelist"`
+ [ -z "$MACLIST" ] && return
+
+ if [ "$((`date +%s`-$get_client_usage_time))" -ge "60" ]; then
+ > ${dir}client_usage_aliases
+ for mac in $MACLIST; do
+ ( ! cat ${dir}ipAddress|grep -q -i -w $mac|grep -v "^$"|sort -u ) && continue
+ echo "$mac" `usage get ${mac} bytes` >> ${dir}client_usage_aliases
+ [ -f "${dir}old_client_usage_aliases" ] && get_client_usage_bytes=`cat ${dir}old_client_usage_aliases|grep -i -w $mac|awk '{print $2}'|grep -v "^$"|sort -u` || continue
+ [ -z "$get_client_usage_bytes" ] && get_client_usage_bytes="0"
+ if [ "$((`usage get ${mac} bytes`-$get_client_usage_bytes))" -ge "$client_usage_max" ]; then
+ local ip=`cat ${dir}ipAddress|grep -i -w $mac|awk '{print $1}'|grep -v "^$"|sort -u`
+ local ip_name=`getname ${ip} ${mac}`
+ local tmp_usage=$(bytes_for_humans $(expr `usage get ${mac} bytes` - ${get_client_usage_bytes}))
+ local time_up=`cat ${dir}ipAddress|grep -w ${ip}|awk '{print $4}'|grep -v "^$"|sort -u`
+ local ip_total=`usage get $mac` && [ ! -z "$ip_total" ] && local ip_total="${markdown_linefeed}${markdown_tab}总计流量: ${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip_total}"
+ local time1=`date +%s`
+ local time1=$(time_for_humans `expr ${time1} - ${time_up}`)
+ if [ -z "$title" ]; then
+ title="${ip_name} 流量异常"
+ content="${content}${markdown_splitline}#### 设备流量异常${markdown_linefeed}${markdown_tab}客户端名:${markdown_space}${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip_name}${markdown_linefeed}${markdown_tab}客户端IP: ${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip}${markdown_linefeed}${markdown_tab}客户端MAC:${markdown_space}${markdown_space}${markdown_space}${markdown_space}${mac}$ip_total${markdown_linefeed}${markdown_tab}一分钟内流量: ${markdown_space}${markdown_space}${tmp_usage}${markdown_linefeed}${markdown_tab}在线时间: ${markdown_space}${markdown_space}${markdown_space}${markdown_space}${time1}"
+ elif ( echo "$title"|grep -q "流量异常" ); then
+ title="${ip_name} ${title}"
+ content="${content}${markdown_splitline}${markdown_tab}客户端名:${markdown_space}${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip_name}${markdown_linefeed}${markdown_tab}客户端IP: ${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip}${markdown_linefeed}${markdown_tab}客户端MAC:${markdown_space}${markdown_space}${markdown_space}${markdown_space}${mac}$ip_total${markdown_linefeed}${markdown_tab}一分钟内流量: ${markdown_space}${markdown_space}${markdown_space}${tmp_usage}${markdown_linefeed}${markdown_tab}在线时间: ${markdown_space}${markdown_space}${markdown_space}${markdown_space}${time1}"
+ else
+ title="设备状态变化"
+ content="${content}${markdown_splitline}#### 设备流量异常${markdown_linefeed}${markdown_tab}客户端名:${markdown_space}${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip_name}${markdown_linefeed}${markdown_tab}客户端IP: ${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip}${markdown_linefeed}${markdown_tab}客户端MAC:${markdown_space}${markdown_space}${markdown_space}${markdown_space}${mac}$ip_total${markdown_linefeed}${markdown_tab}一分钟内流量: ${markdown_space}${markdown_space}${markdown_space}${tmp_usage}${markdown_linefeed}${markdown_tab}在线时间: ${markdown_space}${markdown_space}${markdown_space}${markdown_space}${time1}"
+ fi
+ fi
+ done
+ cat ${dir}client_usage_aliases > ${dir}old_client_usage_aliases
+ get_client_usage_time=`date +%s`
+ fi
}
# 时间单位换算
@@ -214,6 +287,18 @@ function length_str {
echo `expr $length_zh / 3 \* 2 + $length_en`
}
+# 截取字符,避免中文乱码
+function cut_str {
+ [ ! "$1" ] && return
+ [ ! "$2" ] && return
+ local temp_length=$2
+ while [ $(printf "%d" \'`echo "$1"|cut -c $temp_length`) -ge "128" ] && [ $(printf "%d" \'`echo "$1"|cut -c $temp_length`) -lt "224" ] ; do
+ temp_length=`expr $temp_length + 1`
+ done
+ temp_length=`expr $temp_length - 1`
+ echo "$1"|cut -c -$temp_length
+}
+
# 在线设备列表
function serverchan_first(){
[ -f "${dir}ipAddress" ] && local IPLIST=`cat ${dir}ipAddress|awk '{print $1}'|grep -v "^$"|sort -u`
@@ -306,8 +391,8 @@ function LockFile(){
function blackwhitelist(){
[ ! "$1" ] && return 1
[ -z "$serverchan_whitelist" ] && [ -z "$serverchan_blacklist" ] && [ -z "$serverchan_interface" ] && return
- [ ! -z "$serverchan_whitelist" ] && ( ! echo $serverchan_whitelist|grep -q -i -w $1) && return
- [ ! -z "$serverchan_blacklist" ] && ( echo $serverchan_blacklist|grep -q -i -w $1) && return
+ [ ! -z "$serverchan_whitelist" ] && ( ! echo "$serverchan_whitelist"|grep -q -i -w $1) && return
+ [ ! -z "$serverchan_blacklist" ] && ( echo "$serverchan_blacklist"|grep -q -i -w $1) && return
[ ! -z "$serverchan_interface" ] && ( echo `getinterface ${1}`|grep -q -i -w $serverchan_interface ) && return
}
@@ -315,13 +400,13 @@ function get_client(){
if [ -f "${dir}ipAddress" ]; then
while read line; do
local js_str="${js_str}