@@ -44,9 +44,9 @@ function read_config(){
[ -z "$up_timeout" ] || [ "$up_timeout" -eq "0" ] && up_timeout="2"
[ -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`
[ -z "$down_timeout" ] || [ "$down_timeout" -eq "0" ] && down_timeout="20";down_timeout=`expr ${down_timeout} / 2 + 1`
[ -z "$timeout_retry_count" ] && timeout_retry_count="2";[ "$timeout_retry_count" -eq "0" ] && timeout_retry_count="1"
[ -z "$timeout_retry_count" ] && timeout_retry_count="2";[ "$timeout_retry_count" -eq "0" ] && timeout_retry_count="1"
[ -z "$bark_srv" ] && bark_srv="https://api.day.app"
[ ! -z "$bark_token" ] && [ -z "$bark_srv" ] && bark_srv="https://api.day.app"
# String Map
# 字符串读取
str_title_start=`/usr/bin/jq -r '.str_title_start' ${jsonpath}`
str_title_start=`/usr/bin/jq -r '.str_title_start' ${jsonpath}`
str_title_end=`/usr/bin/jq -r '.str_title_end' ${jsonpath}`
str_title_end=`/usr/bin/jq -r '.str_title_end' ${jsonpath}`
str_linefeed=`/usr/bin/jq -r '.str_linefeed' ${jsonpath}`
str_linefeed=`/usr/bin/jq -r '.str_linefeed' ${jsonpath}`
@@ -77,6 +77,9 @@ function pushbot_init(){
fi
fi
down_oui &
down_oui &
deltemp
deltemp
get_syslog
add_ip_black
rm -f ${dir}fd1 ${dir}sheep_usage ${dir}old_sheep_usage ${dir}client_usage_aliases ${dir}old_client_usage_aliases /usr/bin/pushbot/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/pushbot/errlog >/dev/null 2>&1
[ ! -f "/usr/sbin/wrtbwmon" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】未安装 wrtbwmon ,流量统计不可用" >> ${logfile}
[ ! -f "/usr/sbin/wrtbwmon" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】未安装 wrtbwmon ,流量统计不可用" >> ${logfile}
[ -z "$ip_version" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法获取依赖项 iputils-arping 版本号,请确认插件是否正常运行" >> ${logfile}
[ -z "$ip_version" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法获取依赖项 iputils-arping 版本号,请确认插件是否正常运行" >> ${logfile}
@@ -99,7 +102,11 @@ function diy_send(){
[ $logrow -eq "0" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【! ! ! 】json 文件生成失败,请检查文件格式" >> ${logfile} && return 1
[ $logrow -eq "0" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【! ! ! 】json 文件生成失败,请检查文件格式" >> ${logfile} && return 1
/usr/bin/jq -r '.[]' ${tempjsonpath}|grep "null" && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】参数变量生成失败,请检查设置项 `/usr/bin/jq -r '.' ${tempjsonpath}|grep "null"`" >> ${logfile}
/usr/bin/jq -r '.[]' ${tempjsonpath}|grep "null" && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】参数变量生成失败,请检查设置项 `/usr/bin/jq -r '.' ${tempjsonpath}|grep "null"`" >> ${logfile}
if [ ! -z "$bark_token" ]; then
local bark_text=`/usr/bin/jq -r '.bark_text' ${tempjsonpath}` && local bark_text=`echo $bark_text|sed 's/ /%20/g'` && curl -s $bark_text
else
curl -X POST -H "$content_type" -d "${data}" "${diyurl}"
curl -X POST -H "$content_type" -d "${data}" "${diyurl}"
fi
}
}
# 下载设备MAC厂商信息
# 下载设备MAC厂商信息
@@ -483,7 +490,7 @@ function LockFile(){
LockFile lock
LockFile lock
fi
fi
[ $1 = "unlock" ] && rm -f ${dir}pushbot.lock >/dev/null 2>&1
[ $1 = "unlock" ] && rm -f ${dir}pushbot.lock >/dev/null 2>&1
return
return 0
}
}
# 检测黑白名单
# 检测黑白名单
@@ -752,6 +759,7 @@ function ip_changes(){
function up(){
function up(){
[ -f ${dir}ipAddress ] && ( cat ${dir}ipAddress|grep -q -w $1 ) && return
[ -f ${dir}ipAddress ] && ( cat ${dir}ipAddress|grep -q -w $1 ) && return
local ip_mac=`getmac $1`
local ip_mac=`getmac $1`
local ip_name=`getname ${1} ${ip_mac}`
local ip_interface=`getinterface ${ip_mac}`
local ip_interface=`getinterface ${ip_mac}`
getping ${1} ${up_timeout} "1";local ping_online=$?
getping ${1} ${up_timeout} "1";local ping_online=$?
if [ "$ping_online" -eq "0" ]; then
if [ "$ping_online" -eq "0" ]; then
@@ -858,6 +866,7 @@ function down_send(){
# 当前设备列表
# 当前设备列表
function current_device(){
function current_device(){
( echo "$lite_enable"|grep -q "content" ) || ( echo "$lite_enable"|grep -q "device" ) && return
[ -f ${dir}ipAddress ] && local logrow=$(grep -c "" ${dir}ipAddress) || local logrow="0";[ $logrow -eq "0" ] && return
[ -f ${dir}ipAddress ] && local logrow=$(grep -c "" ${dir}ipAddress) || local logrow="0";[ $logrow -eq "0" ] && return
[ -f ${dir}usage.db ] && local ip_total_db="总计流量${str_space}${str_space}${str_space}${str_space}"
[ -f ${dir}usage.db ] && local ip_total_db="总计流量${str_space}${str_space}${str_space}${str_space}"
content="${content}${str_splitline}${str_title_start}${font_blue} 现有在线设备 ${logrow} 台,具体如下${font_end}${str_title_end}${str_linefeed}${str_tab}IP 地址${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${ip_total_db}${boldstar}客户端名${boldstar}"
content="${content}${str_splitline}${str_title_start}${font_blue} 现有在线设备 ${logrow} 台,具体如下${font_end}${str_title_end}${str_linefeed}${str_tab}IP 地址${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${ip_total_db}${boldstar}客户端名${boldstar}"
@@ -880,7 +889,7 @@ function current_device(){
local ip_total="${ip_total}${str_space}"
local ip_total="${ip_total}${str_space}"
done
done
fi
fi
content="${content}${str_linefeed}${str_tab}${ip}${ip_total}${boldstar}${font_green}${ip_name}${font_end}${boldstar}"
content="${content}${str_linefeed}${str_tab}${ip}${ip_total}${boldstar}${font_green}${ip_name}${font_end2 }${boldstar}"
unset i n ip_total ip_mac ip_name
unset i n ip_total ip_mac ip_name
done
done
}
}
@@ -965,7 +974,7 @@ EOF
rm -f ${dir}get_syslog >/dev/null 2>&1
rm -f ${dir}get_syslog >/dev/null 2>&1
}
}
# 登陆 提醒通知
# 登录 提醒通知
function login_send(){
function login_send(){
[ -z "$web_logged" ] && [ -z "$ssh_logged" ] && [ -z "$web_login_failed" ] && [ -z "$ssh_login_failed" ] && return
[ -z "$web_logged" ] && [ -z "$ssh_logged" ] && [ -z "$web_login_failed" ] && [ -z "$ssh_login_failed" ] && return
[ ! -f ${dir}login_monitor ] && return
[ ! -f ${dir}login_monitor ] && return
@@ -984,17 +993,17 @@ function login_send(){
local web_login_mode=`cat ${dir}web_login|grep -w ${login_ip}|awk '{print $3}'|grep -v "^$"|sort -u|head -n1`
local web_login_mode=`cat ${dir}web_login|grep -w ${login_ip}|awk '{print $3}'|grep -v "^$"|sort -u|head -n1`
if [ ! -z "$web_logged" ] && [ "$web_logged" -eq "1" ]; then
if [ ! -z "$web_logged" ] && [ "$web_logged" -eq "1" ]; then
if [ -z "$title" ]; then
if [ -z "$title" ]; then
title="${login_ip} 通过 w eb 登陆 了路由器"
title="${login_ip} 通过 W eb 登录 了路由器"
content="${content}${str_splitline}${str_title_start} 登陆 信息${str_title_end}${str_linefeed}${str_tab}时间:${str_space}${str_space}${str_space}${str_space}${str_space}${web_login_time}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}${content_mode}"
content="${content}${str_splitline}${str_title_start}${font_green} 登录 信息${font_end}${ str_title_end}${str_linefeed}${str_tab}时间:${str_space}${str_space}${str_space}${str_space}${str_space}${web_login_time}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}${content_mode}"
elif ( echo "$title"|grep -q "登陆 了路由器" ); then
elif ( echo "$title"|grep -q "登录 了路由器" ); then
title="${login_ip} ${title}"
title="${login_ip} ${title}"
content="${content}${str_splitline}${str_tab}时间:${str_space}${str_space}${str_space}${str_space}${str_space}${web_login_time}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}${content_mode}"
content="${content}${str_splitline}${str_tab}时间:${str_space}${str_space}${str_space}${str_space}${str_space}${web_login_time}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}${content_mode}"
else
else
title="设备状态变化"
title="设备状态变化"
content="${content}${str_splitline}${str_title_start} 登陆 信息${str_title_end}${str_linefeed}${str_tab}时间:${str_space}${str_space}${str_space}${str_space}${str_space}${web_login_time}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}${content_mode}"
content="${content}${str_splitline}${str_title_start}${font_green} 登录 信息${font_end}${ str_title_end}${str_linefeed}${str_tab}时间:${str_space}${str_space}${str_space}${str_space}${str_space}${web_login_time}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}${content_mode}"
fi
fi
fi
fi
echo "`date "+%Y-%m-%d %H:%M:%S"` ${disturb_text}设备 ${login_ip} 通过 web ${web_login_mode} 登陆 了路由器 " >> ${logfile}
echo "`date "+%Y-%m-%d %H:%M:%S"` ${disturb_text}设备 ${login_ip} 通过 web ${web_login_mode} 登录 了路由器 " >> ${logfile}
done
done
echo "" > ${dir}web_login
echo "" > ${dir}web_login
unset login_ip login_ip_list
unset login_ip login_ip_list
@@ -1008,17 +1017,17 @@ function login_send(){
[ ! -z "$ssh_login_mode" ] && local content_mode="${str_linefeed}${str_tab}登录方式: ${str_space}${str_space}${str_space}${str_space}${ssh_login_mode}"
[ ! -z "$ssh_login_mode" ] && local content_mode="${str_linefeed}${str_tab}登录方式: ${str_space}${str_space}${str_space}${str_space}${ssh_login_mode}"
if [ ! -z "$ssh_logged" ] && [ "$ssh_logged" -eq "1" ]; then
if [ ! -z "$ssh_logged" ] && [ "$ssh_logged" -eq "1" ]; then
if [ -z "$title" ]; then
if [ -z "$title" ]; then
title="${login_ip} 通过 ssh 登陆 了路由器"
title="${login_ip} 通过 SSH 登录 了路由器"
content="${content}${str_splitline}${str_title_start} 登陆 信息${str_title_end}${str_linefeed}${str_tab}时间:${str_space}${str_space}${str_space}${str_space}${str_space}${ssh_login_time}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}${content_mode}"
content="${content}${str_splitline}${str_title_start}${font_green} 登录 信息${font_end}${ str_title_end}${str_linefeed}${str_tab}时间:${str_space}${str_space}${str_space}${str_space}${str_space}${ssh_login_time}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}${content_mode}"
elif ( echo "$title"|grep -q "登陆 了路由器" ); then
elif ( echo "$title"|grep -q "登录 了路由器" ); then
title="${login_ip} ${title}"
title="${login_ip} ${title}"
content="${content}${str_splitline}${str_tab}时间:${str_space}${str_space}${str_space}${str_space}${str_space}${ssh_login_time}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}${content_mode}"
content="${content}${str_splitline}${str_tab}时间:${str_space}${str_space}${str_space}${str_space}${str_space}${ssh_login_time}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}${content_mode}"
else
else
title="设备状态变化"
title="设备状态变化"
content="${content}${str_splitline}${str_title_start} 登陆 信息${str_title_end}${str_linefeed}${str_tab}时间:${str_space}${str_space}${str_space}${str_space}${str_space}${ssh_login_time}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}${content_mode}"
content="${content}${str_splitline}${str_title_start}${font_green} 登录 信息${str_title_end}${str_linefeed}${str_tab}时间:${str_space}${str_space}${str_space}${str_space}${str_space}${ssh_login_time}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}${content_mode}"
fi
fi
fi
fi
echo "`date "+%Y-%m-%d %H:%M:%S"` 【info】设备 ${login_ip} 通过 ssh ${ssh_login_mode} 登陆 了路由器 " >> ${logfile}
echo "`date "+%Y-%m-%d %H:%M:%S"` 【info】设备 ${login_ip} 通过 SSH ${ssh_login_mode} 登录 了路由器 " >> ${logfile}
done
done
echo "" > ${dir}ssh_login
echo "" > ${dir}ssh_login
unset login_ip login_ip_list
unset login_ip login_ip_list
@@ -1031,18 +1040,18 @@ function login_send(){
if [ "$web_login_sum" -ge "$login_max_num" ] ;then
if [ "$web_login_sum" -ge "$login_max_num" ] ;then
if [ ! -z "$web_login_failed" ] && [ "$web_login_failed" -eq "1" ]; then
if [ ! -z "$web_login_failed" ] && [ "$web_login_failed" -eq "1" ]; then
if [ -z "$title" ]; then
if [ -z "$title" ]; then
title="${login_ip} 通过 w eb 频繁尝试登陆 "
title="${login_ip} 通过 W eb 频繁尝试登录 "
content="${content}${str_splitline}${str_title_start} 登陆 信息${str_title_end}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}"
content="${content}${str_splitline}${str_title_start}${font_red} 登录 信息${font_end}${ str_title_end}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}"
elif ( echo "$title"|grep -q "频繁尝试登陆 " ); then
elif ( echo "$title"|grep -q "频繁尝试登录 " ); then
title="${login_ip} ${title}"
title="${login_ip} ${title}"
content="${content}${str_splitline}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}"
content="${content}${str_splitline}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}"
else
else
title="设备状态变化"
title="设备状态变化"
content="${content}${str_splitline}${str_title_start} 登陆 信息${str_title_end}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}"
content="${content}${str_splitline}${str_title_start}${font_red} 登录 信息${font_end}${ str_title_end}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}"
fi
fi
fi
fi
sed -i "/^${login_ip}$/d" ${dir}web_failed
sed -i "/^${login_ip}$/d" ${dir}web_failed
echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】设备 ${login_ip} 通过 w eb 频繁尝试登陆 " >> ${logfile}
echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】设备 ${login_ip} 通过 W eb 频繁尝试登录 " >> ${logfile}
add_ip_black $login_ip
add_ip_black $login_ip
fi
fi
done
done
@@ -1056,18 +1065,18 @@ function login_send(){
if [ "$ssh_login_sum" -ge "$login_max_num" ] ;then
if [ "$ssh_login_sum" -ge "$login_max_num" ] ;then
if [ ! -z "$ssh_login_failed" ] && [ "$ssh_login_failed" -eq "1" ]; then
if [ ! -z "$ssh_login_failed" ] && [ "$ssh_login_failed" -eq "1" ]; then
if [ -z "$title" ]; then
if [ -z "$title" ]; then
title="${login_ip} 通过 ssh 频繁尝试登陆 "
title="${login_ip} 通过 SSH 频繁尝试登录 "
content="${content}${str_splitline}${str_title_start} 登陆 信息${str_title_end}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}"
content="${content}${str_splitline}${str_title_start}${font_red} 登录 信息${font_end}${ str_title_end}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}"
elif ( echo "$title"|grep -q "频繁尝试登陆 " ); then
elif ( echo "$title"|grep -q "频繁尝试登录 " ); then
title="${login_ip} ${title}"
title="${login_ip} ${title}"
content="${content}${str_splitline}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}"
content="${content}${str_splitline}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}"
else
else
title="设备状态变化"
title="设备状态变化"
content="${content}${str_splitline}${str_title_start} 登陆 信息${str_title_end}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}"
content="${content}${str_splitline}${str_title_start}${font_red} 登录 信息${font_end}${ str_title_end}${str_linefeed}${str_tab}设备 IP: ${str_space}${str_space}${str_space}${str_space}${login_ip}"
fi
fi
fi
fi
sed -i "/^${login_ip}$/d" ${dir}ssh_failed
sed -i "/^${login_ip}$/d" ${dir}ssh_failed
echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】设备 ${login_ip} 通过 ssh 频繁尝试登陆 " >> ${logfile}
echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】设备 ${login_ip} 通过 SSH 频繁尝试登录 " >> ${logfile}
add_ip_black $login_ip
add_ip_black $login_ip
fi
fi
done
done
@@ -1102,7 +1111,7 @@ function add_ip_black(){
function send(){
function send(){
echo "`date "+%Y-%m-%d %H:%M:%S"` 【定时数据】创建定时任务" >> ${logfile}
echo "`date "+%Y-%m-%d %H:%M:%S"` 【定时数据】创建定时任务" >> ${logfile}
pushbot_disturb;local send_disturb=$?
pushbot_disturb;local send_disturb=$?
get_config "send_title" "router_status" "client_list" " router_temp" "router_wan"
get_config "send_title" "router_status" "router_temp" "router_wan" "client_list"
[ -z "$send_title" ] && local send_title="路由状态:"
[ -z "$send_title" ] && local send_title="路由状态:"
[ ! -z "$1" ] && local send_title="发送测试:" && local send_content="${str_splitline}${str_title_start}内容1${str_title_end}${str_linefeed}${str_tab}设备1${str_linefeed}${str_tab}设备2${str_splitline}${str_title_start}内容2${str_title_end}${str_linefeed}${str_tab}设备3${str_linefeed}${str_tab}设备4"
[ ! -z "$1" ] && local send_title="发送测试:" && local send_content="${str_splitline}${str_title_start}内容1${str_title_end}${str_linefeed}${str_tab}设备1${str_linefeed}${str_tab}设备2${str_splitline}${str_title_start}内容2${str_title_end}${str_linefeed}${str_tab}设备3${str_linefeed}${str_tab}设备4"
@@ -1240,10 +1249,10 @@ while [ "$pushbot_enable" -eq "1" ]; do
# 异常流量检测
# 异常流量检测
[ ! -f "${dir}send_enable.lock" ] && get_client_usage
[ ! -f "${dir}send_enable.lock" ] && get_client_usage
# 登陆 提醒通知
# 登录 提醒通知
[ ! -f "${dir}send_enable.lock" ] && login_send
[ ! -f "${dir}send_enable.lock" ] && login_send
# Noti
# 通知
if [ ! -f "${dir}send_enable.lock" ] && [ ! -z "$title" ] && [ ! -z "$content" ]; then
if [ ! -f "${dir}send_enable.lock" ] && [ ! -z "$title" ] && [ ! -z "$content" ]; then
[ ! -z "$device_name" ] && title="【$device_name】$title"
[ ! -z "$device_name" ] && title="【$device_name】$title"
( echo "$lite_enable"|grep -q "content" ) && content="$title"
( echo "$lite_enable"|grep -q "content" ) && content="$title"