luci-app-pushbot: bump to 3.55-15 (#7845)

Co-authored-by: 然后七年 <69092025+zzsj0928@users.noreply.github.com>
This commit is contained in:
EnnawYang 2021-09-12 14:11:02 +08:00 committed by GitHub
parent 12d4b91c8b
commit f08bdedec6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 794 additions and 209 deletions

View File

@ -1,17 +1,20 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-pushbot
PKG_VERSION:=3.12
PKG_RELEASE:=10
PKG_VERSION:=3.55
PKG_RELEASE:=15
PKG_MAINTAINER:=tty228 zzsj0928
LUCI_TITLE:=LuCI support for Pushbot
LUCI_PKGARCH:=all
LUCI_DEPENDS:=+iputils-arping +curl
LUCI_DEPENDS:=+iputils-arping +curl +jq
define Package/$(PKG_NAME)/conffiles
/etc/config/pushbot
/usr/bin/pushbot/api/diy.json
/usr/bin/pushbot/api/ipv4.list
/usr/bin/pushbot/api/ipv6.list
endef
include $(TOPDIR)/feeds/luci/luci.mk

View File

@ -28,6 +28,9 @@
- 故由 然后七年 @zzsj0928 重新修改为本插件为钉钉机器人API使用。
- 本插件工作在openwrt
- 本插件支持:钉钉推送,企业微信推送,PushPlus推送,微信推送,企业微信应用推送,飞书推送,钉钉机器人推送,企业微信机器人推送,飞书机器人推送,一对多推送,Bark推送(仅iOS)
- 自20210911之后的版本支持Bark群组群组名默认为设备名
- 自20210901之后的版本增加依赖jq请重新编译或在安装前同步安装jq
# 显示效果
## 通知栏:直接显示推送主题,一目了然,按设备不同,分组显示
<img src="https://raw.githubusercontent.com/zzsj0928/ReadmeContents/main/Serverchand/Msg.Notification.jpg" width="500">

View File

@ -31,7 +31,6 @@ a.datatype="uinteger"
a=s:option(Value, "soc_code", "自定义温度读取命令")
a.rmempty = true
a:value("",translate("默认"))
a:value("sensors",translate("sensors命令"))
a.description = translate("请尽量避免使用特殊符号,如双引号、$、!等,执行结果需为数字,用于温度对比")
a=s:option(Button,"soc",translate("测试温度命令"))

View File

@ -29,49 +29,40 @@ a.default=0
a.rmempty = true
--精简模式
a=s:taboption("basic", Flag,"lite_enable",translate("精简模式"))
a.default=0
a.rmempty = true
a = s:taboption("basic", MultiValue, "lite_enable", translate("精简模式"))
a:value("device", translate("精简当前设备列表"))
a:value("nowtime", translate("精简当前时间"))
a:value("content", translate("只推送标题"))
a.widget = "checkbox"
a.default = nil
a.optional = true
a= s:taboption("basic", Flag, "content_current_device", "精简当前设备列表")
a.default = 0
--推送模式
a=s:taboption("basic", ListValue,"jsonpath",translate("推送模式"))
a.default="/usr/bin/pushbot/api/dingding.json"
a.rmempty = true
a:depends({lite_enable="1"})
a= s:taboption("basic", Flag, "content_nowtime", "精简当前时间")
a.default = 0
a.rmempty = true
a:depends({lite_enable="1"})
a= s:taboption("basic", Flag, "content_content", "只推送标题")
a.default = 0
a.rmempty = true
a:depends({lite_enable="1"})
a=s:taboption("basic", ListValue,"send_we",translate("推送模式"))
a.default=""
a.rmempty = true
a:value("",translate("钉钉"))
a:value("1",translate("企业微信"))
a:value("3",translate("飞书"))
a:value("4",translate("Bark"))
a:value("2",translate("PushPlus"))
a:value("/usr/bin/pushbot/api/dingding.json",translate("钉钉"))
a:value("/usr/bin/pushbot/api/ent_wechat.json",translate("企业微信"))
a:value("/usr/bin/pushbot/api/feishu.json",translate("飞书"))
a:value("/usr/bin/pushbot/api/bark.json",translate("Bark"))
a:value("/usr/bin/pushbot/api/pushplus.json",translate("PushPlus"))
a:value("/usr/bin/pushbot/api/diy.json",translate("自定义推送"))
a=s:taboption("basic", Value,"dd_webhook",translate('Webhook'), translate("钉钉机器人 Webhook").."<br>调用代码获取<a href='https://developers.dingtalk.com/document/robots/custom-robot-access' target='_blank'>点击这里</a><br><br>")
a.rmempty = true
a:depends("send_we","")
a:depends("jsonpath","/usr/bin/pushbot/api/dingding.json")
a=s:taboption("basic", Value, "we_webhook", translate("Webhook"),translate("企业微信机器人 Webhook").."<br>调用代码获取<a href='https://work.weixin.qq.com/api/doc/90000/90136/91770' target='_blank'>点击这里</a><br><br>")
a.rmempty = true
a:depends("send_we","1")
a:depends("jsonpath","/usr/bin/pushbot/api/ent_wechat.json")
a=s:taboption("basic", Value,"pp_token",translate('PushPlus Token'), translate("PushPlus Token").."<br>调用代码获取<a href='http://pushplus.plus/doc/' target='_blank'>点击这里</a><br><br>")
a.rmempty = true
a:depends("send_we","2")
a:depends("jsonpath","/usr/bin/pushbot/api/pushplus.json")
a=s:taboption("basic", ListValue,"pp_channel",translate('PushPlus Channel'))
a.rmempty = true
a:depends("send_we","2")
a:depends("jsonpath","/usr/bin/pushbot/api/pushplus.json")
a:value("wechat",translate("wechatPushPlus微信公众号"))
a:value("cp",translate("cp企业微信应用"))
a:value("webhook",translate("webhook第三方webhook"))
@ -95,21 +86,41 @@ a:depends("pp_topic_enable","1")
a=s:taboption("basic", Value,"fs_webhook",translate('WebHook'), translate("飞书 WebHook").."<br>调用代码获取<a href='https://www.feishu.cn/hc/zh-CN/articles/360024984973' target='_blank'>点击这里</a><br><br>")
a.rmempty = true
a:depends("send_we","3")
a:depends("jsonpath","/usr/bin/pushbot/api/feishu.json")
a=s:taboption("basic", Value,"bark_token",translate('Bark Token'), translate("Bark Token").."<br>调用代码获取<a href='https://github.com/Finb/Bark' target='_blank'>点击这里</a><br><br>")
a.rmempty = true
a:depends("send_we","4")
a:depends("jsonpath","/usr/bin/pushbot/api/bark.json")
a=s:taboption("basic", Flag,"bark_srv_enable",translate("自建 Bark 服务器"))
a.default=0
a.rmempty = true
a:depends("send_we","4")
a:depends("jsonpath","/usr/bin/pushbot/api/bark.json")
a=s:taboption("basic", Value,"bark_srv",translate('Bark Server'), translate("Bark 自建服务器地址").."<br>如https://your.domain:port<br>具体自建服务器设定参见:<a href='https://github.com/Finb/Bark' target='_blank'>点击这里</a><br><br>")
a.rmempty = true
a:depends("bark_srv_enable","1")
a=s:taboption("basic", TextValue, "diy_json", translate("自定义推送"))
a.optional = false
a.rows = 28
a.wrap = "soft"
a.cfgvalue = function(self, section)
return fs.readfile("/usr/bin/pushbot/api/diy.json")
end
a.write = function(self, section, value)
fs.writefile("/usr/bin/pushbot/api/diy.json", value:gsub("\r\n", "\n"))
end
a:depends("jsonpath","/usr/bin/pushbot/api/diy.json")
a=s:taboption("basic", Button,"__add",translate("发送测试"))
a.inputtitle=translate("发送")
a.inputstyle = "apply"
function a.write(self, section)
luci.sys.call("cbi.apply")
luci.sys.call("/usr/bin/pushbot/pushbot test &")
end
a=s:taboption("basic", Value,"device_name",translate('本设备名称'))
a.rmempty = true
a.description = translate("在推送信息标题中会标识本设备名称,用于区分推送信息的来源设备")
@ -118,6 +129,7 @@ a=s:taboption("basic", Value,"sleeptime",translate('检测时间间隔'))
a.rmempty = true
a.optional = false
a.default = "60"
a.datatype = "and(uinteger,min(10))"
a.description = translate("越短的时间时间响应越及时,但会占用更多的系统资源")
a=s:taboption("basic", ListValue,"oui_data",translate("MAC设备信息数据库"))
@ -146,7 +158,7 @@ a.rmempty = true
a.description = translate("<br/> 请输入设备 MAC 和设备别名,用“-”隔开,如:<br/> XX:XX:XX:XX:XX:XX-我的手机")
--设备状态
a=s:taboption("content", ListValue,"pushbot_ipv4",translate("ipv4 变动通知"))
a=s:taboption("content", ListValue,"pushbot_ipv4",translate("IPv4 变更通知"))
a.rmempty = true
a.default=""
a:value("",translate("关闭"))
@ -169,13 +181,20 @@ for _, iface in ipairs(ifaces) do
end
a.description = translate("<br/>一般选择 wan 接口,多拨环境请自行选择")
a= s:taboption("content", DynamicList, "ipv4_URL", "URL 地址")
a.rmempty = true
a=s:taboption("content", TextValue, "ipv4_list", translate("IPv4 API列表"))
a.optional = false
a.rows = 8
a.wrap = "soft"
a.cfgvalue = function(self, section)
return fs.readfile("/usr/bin/pushbot/api/ipv4.list")
end
a.write = function(self, section, value)
fs.writefile("/usr/bin/pushbot/api/ipv4.list", value:gsub("\r\n", "\n"))
end
a.description = translate("<br/>会因服务器稳定性、连接频繁等原因导致获取失败<br/>如接口可以正常获取 IP不推荐使用<br/>从以上列表中随机地址访问")
a:depends({pushbot_ipv4="2"})
a.description = translate("<br/>会因服务器稳定性、连接频繁等原因导致获取失败<br/>从以上列表中随机一个地址,留空使用默认地址")
a=s:taboption("content", ListValue,"pushbot_ipv6",translate("ipv6 变动通知"))
a=s:taboption("content", ListValue,"pushbot_ipv6",translate("IPv6 变更通知"))
a.rmempty = true
a.default="disable"
a:value("0",translate("关闭"))
@ -198,11 +217,18 @@ for _, iface in ipairs(ifaces) do
end
a.description = translate("<br/>一般选择 wan 接口,多拨环境请自行选择")
a= s:taboption("content", DynamicList, "ipv6_URL", "URL 地址")
a.rmempty = true
a=s:taboption("content", TextValue, "ipv6_list", translate("IPv6 API列表"))
a.optional = false
a.rows = 8
a.wrap = "soft"
a.cfgvalue = function(self, section)
return fs.readfile("/usr/bin/pushbot/api/ipv6.list")
end
a.write = function(self, section, value)
fs.writefile("/usr/bin/pushbot/api/ipv6.list", value:gsub("\r\n", "\n"))
end
a.description = translate("<br/>会因服务器稳定性、连接频繁等原因导致获取失败<br/>如接口可以正常获取 IP不推荐使用<br/>从以上列表中随机地址访问")
a:depends({pushbot_ipv6="2"})
a.description = translate("<br/>会因服务器稳定性、连接频繁等原因导致获取失败<br/>从以上列表中随机一个地址,留空使用默认地址")
a=s:taboption("content", Flag,"pushbot_up",translate("设备上线通知"))
a.default=1
@ -254,8 +280,71 @@ a.rmempty = true
a:depends({client_usage_disturb="1"})
a.description = translate("请输入设备 MAC")
--LoginNoti
a=s:taboption("content", Flag,"web_logged",translate("Web 登录提醒"))
a.default=0
a.rmempty = true
a=s:taboption("content", Flag,"ssh_logged",translate("SSH 登录提醒"))
a.default=0
a.rmempty = true
a=s:taboption("content", Flag,"web_login_failed",translate("Web 错误尝试提醒"))
a.default=0
a.rmempty = true
a=s:taboption("content", Flag,"ssh_login_failed",translate("SSH 错误尝试提醒"))
a.default=0
a.rmempty = true
a= s:taboption("content", Value, "login_max_num", "错误尝试次数")
a.default = "3"
a.datatype="and(uinteger,min(1))"
a:depends("web_login_failed","1")
a:depends("ssh_login_failed","1")
a.description = translate("超过次数后推送提醒")
a=s:taboption("content", Flag,"web_login_black",translate("自动拉黑"))
a.default=0
a.rmempty = true
a:depends("web_login_failed","1")
a:depends("ssh_login_failed","1")
a.description = translate("直到重启前都不会重置次数,请先添加白名单")
a= s:taboption("content", Value, "ip_black_timeout", "拉黑时间(秒)")
a.default = "86400"
a.datatype="and(uinteger,min(0))"
a:depends("web_login_black","1")
a.description = translate("0 为永久拉黑,慎用<br>如不幸误操作,请更改设备 IP 进入 LUCI 界面清空规则")
a=s:taboption("content", DynamicList, "ip_white_list", translate("白名单 IP 列表"))
a.datatype = "ipaddr"
a.rmempty = true
luci.ip.neighbors({family = 4}, function(entry)
if entry.reachable then
a:value(entry.dest:string())
end
end)
a:depends("web_logged","1")
a:depends("ssh_logged","1")
a:depends("web_login_failed","1")
a:depends("ssh_login_failed","1")
a.description = translate("忽略白名单登陆提醒和拉黑操作,暂不支持掩码位表示")
a=s:taboption("content", TextValue, "ip_black_list", translate("IP 黑名单列表"))
a.optional = false
a.rows = 8
a.wrap = "soft"
a.cfgvalue = function(self, section)
return fs.readfile("/usr/bin/pushbot/api/ip_blacklist")
end
a.write = function(self, section, value)
fs.writefile("/usr/bin/pushbot/api/ip_blacklist", value:gsub("\r\n", "\n"))
end
a:depends("web_login_black","1")
--定时推送
a=s:taboption("crontab", ListValue,"send_mode",translate("定时任务设定"))
a=s:taboption("crontab", ListValue,"crontab",translate("定时任务设定"))
a.rmempty = true
a.default=""
a:value("",translate("关闭"))
@ -269,7 +358,7 @@ a:value(t,translate("每天"..t.."点"))
end
a.default=8
a.datatype=uinteger
a:depends("send_mode","1")
a:depends("crontab","1")
a=s:taboption("crontab", ListValue,"regular_time_2",translate("发送时间"))
a.rmempty = true
@ -279,7 +368,7 @@ a:value(t,translate("每天"..t.."点"))
end
a.default="关闭"
a.datatype=uinteger
a:depends("send_mode","1")
a:depends("crontab","1")
a=s:taboption("crontab", ListValue,"regular_time_3",translate("发送时间"))
a.rmempty = true
@ -290,7 +379,7 @@ a:value(t,translate("每天"..t.."点"))
end
a.default="关闭"
a.datatype=uinteger
a:depends("send_mode","1")
a:depends("crontab","1")
a=s:taboption("crontab", ListValue,"interval_time",translate("发送间隔"))
a.rmempty = true
@ -299,39 +388,39 @@ a:value(t,translate(t.."小时"))
end
a.default=6
a.datatype=uinteger
a:depends("send_mode","2")
a:depends("crontab","2")
a.description = translate("<br/>从 00:00 开始,每 * 小时发送一次")
a= s:taboption("crontab", Value, "send_title", translate("推送标题"))
a:depends("send_mode","1")
a:depends("send_mode","2")
a:depends("crontab","1")
a:depends("crontab","2")
a.placeholder = "OpenWrt By tty228 路由状态:"
a.description = translate("<br/>使用特殊符号可能会造成发送失败")
a=s:taboption("crontab", Flag,"router_status",translate("系统运行情况"))
a.default=1
a:depends("send_mode","1")
a:depends("send_mode","2")
a:depends("crontab","1")
a:depends("crontab","2")
a=s:taboption("crontab", Flag,"router_temp",translate("设备温度"))
a.default=1
a:depends("send_mode","1")
a:depends("send_mode","2")
a:depends("crontab","1")
a:depends("crontab","2")
a=s:taboption("crontab", Flag,"router_wan",translate("WAN信息"))
a.default=1
a:depends("send_mode","1")
a:depends("send_mode","2")
a:depends("crontab","1")
a:depends("crontab","2")
a=s:taboption("crontab", Flag,"client_list",translate("客户端列表"))
a.default=1
a:depends("send_mode","1")
a:depends("send_mode","2")
a:depends("crontab","1")
a:depends("crontab","2")
e=s:taboption("crontab", Button,"_add",translate("手动发送"))
e.inputtitle=translate("发送")
e:depends("send_mode","1")
e:depends("send_mode","2")
e:depends("crontab","1")
e:depends("crontab","2")
e.inputstyle = "apply"
function e.write(self, section)
luci.sys.call("cbi.apply")
@ -379,11 +468,13 @@ a = s:taboption("disturb", DynamicList, "pushbot_whitelist", translate("忽略
nt.mac_hints(function(mac, name) a :value(mac, "%s (%s)" %{ mac, name }) end)
a.rmempty = true
a:depends({macmechanism="allow"})
a.description = translate("AA:AA:AA:AA:AA:AA\\|BB:BB:BB:BB:BB:B 可以将多个 MAC 视为同一用户<br/>任一设备在线后不再推送,设备全部离线时才会推送,避免双 wifi 频繁推送")
a = s:taboption("disturb", DynamicList, "pushbot_blacklist", translate("关注列表"))
nt.mac_hints(function(mac, name) a:value(mac, "%s (%s)" %{ mac, name }) end)
a.rmempty = true
a:depends({macmechanism="block"})
a.description = translate("AA:AA:AA:AA:AA:AA\\|BB:BB:BB:BB:BB:B 可以将多个 MAC 视为同一用户<br/>任一设备在线后不再推送,设备全部离线时才会推送,避免双 wifi 频繁推送")
a = s:taboption("disturb", ListValue, "pushbot_interface", translate("接口名称"))
a:depends({macmechanism="interface"})
@ -401,4 +492,20 @@ for _, iface in ipairs(ifaces) do
end
end
a=s:taboption("disturb", ListValue,"macmechanism2",translate("MAC过滤2"))
a:value("",translate("disable"))
a:value("MAC_online",translate("列表内任意设备在线时免打扰"))
a:value("MAC_offline",translate("列表内设备都离线后免打扰"))
a.rmempty = true
a = s:taboption("disturb", DynamicList, "MAC_online_list", translate("在线免打扰列表"))
nt.mac_hints(function(mac, name) a:value(mac, "%s (%s)" %{ mac, name }) end)
a.rmempty = true
a:depends({macmechanism2="MAC_online"})
a = s:taboption("disturb", DynamicList, "MAC_offline_list", translate("任意离线免打扰列表"))
nt.mac_hints(function(mac, name) a:value(mac, "%s (%s)" %{ mac, name }) end)
a.rmempty = true
a:depends({macmechanism2="MAC_offline"})
return m

View File

@ -0,0 +1,34 @@
{
"_api": "这是Bark推送 post 模板信息 api 文件",
"_api": "【Bark推送】",
"url": "${bark_srv}/push",
"data": "@${tempjsonpath}",
"content_type": "Content-Type: application/json; charset=utf-8",
"str_title_start": "【",
"str_title_end": "】",
"str_linefeed": "\\n",
"str_splitline": "\\n\\n",
"str_space": " ",
"str_tab": " ",
"table_tab": "",
"font_green": "",
"font_green2": "",
"font_red": "",
"font_blue": "",
"font_purple": "",
"font_end": "",
"font_end2": "",
"percentsym": "25",
"boldstar": "",
"type":
{
"device_key": "\"${bark_token}\"",
"title": "\"${1}\"",
"body": "\"${nowtime}${str_linefeed}${2}\"",
"ext_params": {
"group": "\"${device_name}\"",
"isArchive": "1"
}
}
}

View File

@ -0,0 +1,32 @@
{
"_api": "这是 Pushbot:钉钉 api 文件",
"_api": "【钉钉推送】",
"url": "\"https://oapi.dingtalk.com/robot/send?access_token=${dd_webhook}\"",
"data": "@${tempjsonpath}",
"content_type": "Content-Type:application/json",
"str_title_start": "**",
"str_title_end": "**",
"str_linefeed": "\\n\\n",
"str_splitline": "\\n\\n---\\n\\n",
"str_space": " ",
"str_tab": " ",
"table_tab": "<font color=#76CCFF>┋</font>",
"font_green": "<font color=#92D050>",
"font_green2": "<font color=#92D050>",
"font_red": "<font color=#FF6666>",
"font_blue": "<font color=#76CCFF>",
"font_purple": "<font color=#6A65FF>",
"font_end": "</font>",
"font_end2": "</font>",
"percentsym": "",
"boldstar": "**",
"type":
{
"msgtype": "\"markdown\"",
"markdown": {
"title": "\"${1}\"",
"text": "\"${str_title_start}${font_purple}${1}${font_end}${str_title_end}${str_linefeed}${nowtime}${str_linefeed}${2}${str_linefeed}${font_purple}${1}${font_end}\""
}
}
}

View File

@ -0,0 +1,50 @@
{
"_//": "-------------------------------------------------------------------------------",
"_readme": "这是 自定义 api 文件,这里以 telegram 为例",
"_readme": "特殊符号请使用斜杠转义,变量使用 ${var} 表示",
"_//": "-------------------------------------------------------------------------------",
"_api": "【DIY 推送】",
"_url": "api 地址",
"_data": "生成的 json 文件路径,一般不需要改,如 api 不支持 json请参考 serverchan 推送接口",
"_content_type": "post 内容类型,这里为 json",
"_//": "-------------------------------------------------------------------------------",
"_str_title_start": "标题粗体字开始符号",
"_str_title_end": "标题粗体字结束符号",
"_str_linefeed": "换行符号",
"_str_splitline": "换行+分隔符",
"_str_space": "空格",
"_str_tab": "TAB用在行首生成文字区块",
"_//": "-------------------------------------------------------------------------------",
"_type":
{
"_readme": "type 对象因为需要转义变量,前后必须使用 斜杠+双引号 转义",
"_readme": "参照上文说明,填写下文相关参数"
},
"_//": "-------------------------------------------------------------------------------",
"url": "https://api.telegram.org/bot${tg_token}/sendMessage",
"data": "@${tempjsonpath}",
"content_type": "Content-Type: application/json",
"str_title_start": "<b>",
"str_title_end": "</b>",
"str_linefeed": "\\n",
"str_splitline": "\\n----\\n",
"str_space": " ",
"str_tab": " ",
"table_tab": "<font color=#76CCFF>┋</font>",
"font_green": "<font color=#92D050>",
"font_green2": "<font color=#92D050>",
"font_red": "<font color=#FF6666>",
"font_blue": "<font color=#76CCFF>",
"font_purple": "<font color=#6A65FF>",
"font_end": "</font>",
"font_end2": "</font>",
"percentsym": "25",
"boldstar": "**",
"type":
{
"text":"\"${str_title_start}${1}${str_title_end}${str_splitline}${nowtime}${2}\"",
"chat_id":"\"${chat_id}\"",
"parse_mode":"\"HTML\""
}
}

View File

@ -0,0 +1,32 @@
{
"_api": "这是企业微信 markdown 模板信息 api 文件",
"_api": "【企业微信】",
"url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${we_webhook}",
"data": "@${tempjsonpath}",
"content_type": "Content-Type: application/json",
"str_title_start": "#### ",
"str_title_end": "",
"str_linefeed": "\\n",
"str_splitline": "\\n------\\n",
"str_space": " ",
"str_tab": " ",
"table_tab": "<font color=#76CCFF>┋</font>",
"font_green": "<font color=#92D050>",
"font_green2": "<font color=#92D050>",
"font_red": "<font color=#FF6666>",
"font_blue": "<font color=#76CCFF>",
"font_purple": "<font color=#6A65FF>",
"font_end": "</font>",
"font_end2": "</font>",
"percentsym": "",
"boldstar": "**",
"type":
{
"msgtype": "\"markdown\"",
"markdown": {
"title": "\"${1}\"",
"content": "\"${str_title_start}${font_purple}${1}${font_end}${str_title_end}${str_linefeed}${nowtime}${str_linefeed}${2}\""
}
}
}

View File

@ -0,0 +1,61 @@
{
"_api": "这是飞书推送 post 模板信息 api 文件",
"_api": "【飞书推送】",
"url": "https://open.feishu.cn/open-apis/bot/v2/hook/${fs_webhook}",
"data": "@${tempjsonpath}",
"content_type": "Content-Type: application/json",
"str_title_start": "**",
"str_title_end": "**",
"str_linefeed": "\\n",
"str_splitline": "\\n\\n",
"str_space": " ",
"str_tab": " ",
"table_tab": "",
"font_green": "",
"font_green": "",
"font_red": "",
"font_blue": "",
"font_purple": "",
"font_end": "",
"font_end2": "",
"percentsym": "",
"boldstar": "**",
"type":
{
"msg_type": "\"interactive\"",
"card": {
"config": {
"wide_screen_mode": "true"
},
"header": {
"template": "\"purple\"",
"title": {
"content": "\"${1}\"",
"tag": "\"plain_text\""
}
},
"elements": [
{
"tag": "\"div\"",
"text": {
"content": "\"${nowtime}${str_linefeed}${2}\"",
"tag": "\"lark_md\""
}
},
{
"tag": "\"hr\""
},
{
"elements": [
{
"content": "\"来自${device_name}\"",
"tag": "\"lark_md\""
}
],
"tag": "\"note\""
}
]
}
}
}

View File

@ -0,0 +1,6 @@
www.cip.cc
ipv4.ddnspod.com
ifcfg.cn
speed.neu.edu.cn/getIP.php
ddns.oray.com/checkip
www.net.cn/static/customercare/yourip.asp

View File

@ -0,0 +1,5 @@
ip.sb
ipv6.ddnspod.com
api-ipv6.ip.sb/ip
speed.neu6.edu.cn/getIP.php
v6.myip.la/json

View File

@ -0,0 +1,34 @@
{
"_api": "这是 Pushbot:PushPlus api 文件",
"_api": "【PushPlus推送】",
"url": "http://www.pushplus.plus/send",
"data": "@${tempjsonpath}",
"content_type": "Content-Type:application/json",
"str_title_start": "#### ",
"str_title_end": "",
"str_linefeed": "\\n\\n",
"str_splitline": "\\n----\\n",
"str_space": " ",
"str_tab": " ",
"table_tab": "",
"font_green": "<font color=#92D050>",
"font_green2": "",
"font_red": "<font color=#FF6666>",
"font_blue": "<font color=#76CCFF>",
"font_purple": "<font color=#6A65FF>",
"font_end": "</font>",
"font_end2": "",
"percentsym": "",
"boldstar": "",
"type":
{
"token": "\"${pp_token}\"",
"channel": "\"${pp_channel}\"",
"webhook": "\"${pp_webhook}\"",
"topic": "\"${pp_topic}\"",
"title": "\"${1}\"",
"content": "\"${2}\"",
"template": "\"markdown\""
}
}

View File

@ -10,28 +10,63 @@ function get_config(){
# 初始化设置信息
function read_config(){
get_config "pushbot_enable" "dd_webhook" "pushbot_ipv4" "ipv4_interface" "pushbot_ipv6" "ipv6_interface" "pushbot_up" "pushbot_down" "pushbot_sheep" "pushbot_whitelist" "pushbot_blacklist" "pushbot_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_we" "we_webhook" "pp_token" "pp_channel" "pp_webhook" "pp_topic_enable" "pp_topic" "fs_webhook" "bark_srv_enable" "bark_srv" "bark_token" "err_device_aliases" "oui_dir" "oui_data" "client_usage" "client_usage_max" "client_usage_disturb" "client_usage_whitelist" "reset_regularly" "ipv4_urllist" "ipv6_urllist" "lite_enable" "content_current_device" "content_nowtime" "content_content"
get_config "pushbot_enable" "lite_enable" "device_name" "sleeptime" "oui_dir" "oui_data" "reset_regularly" "debuglevel" "device_aliases" \
"pushbot_ipv4" "ipv4_interface" "pushbot_ipv6" "ipv6_interface" "pushbot_up" "pushbot_down" "cpuload_enable" "cpuload" "temperature_enable" "temperature" \
"regular_time" "regular_time_2" "regular_time_3" "interval_time" \
"client_usage" "client_usage_max" "client_usage_disturb" "client_usage_whitelist" \
"web_logged" "ssh_logged" "web_login_failed" "ssh_login_failed" "login_max_num" "web_login_black" "ip_white_list" "ip_black_timeout" \
"pushbot_sheep" "starttime" "endtime" "pushbot_whitelist" "pushbot_blacklist" "pushbot_interface" "MAC_online_list" "MAC_offline_list" \
"up_timeout" "down_timeout" "timeout_retry_count" "thread_num" "soc_code" \
"err_enable" "err_sheep_enable" "err_device_aliases" "network_err_event" "system_time_event" "autoreboot_time" "network_restart_time" "public_ip_event" "public_ip_retry_count" \
"jsonpath" "dd_webhook" "we_webhook" "pp_token" "pp_channel" "pp_webhook" "pp_topic_enable" "pp_topic" "fs_webhook" "bark_srv_enable" "bark_srv" "bark_token"
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/pushbot/" && mkdir -p ${dir}
tempjsonpath="/tmp/pushbot/temp.json"
ip_blacklist_path="/usr/bin/pushbot/api/ip_blacklist"
[ ! -z "$oui_dir" ] && [ "$oui_dir" -eq "1" ] && oui_base="${dir}oui_base.txt" || oui_base="/usr/bin/pushbot/oui_base.txt"
debuglevel=`echo "$debuglevel"` && [ -z "$debuglevel" ] && logfile="/dev/null" || logfile="${dir}pushbot.log"
pushbot_blacklist=`echo "$pushbot_blacklist"|sed 's/ /\n/g'` 2>/dev/null
pushbot_whitelist=`echo "$pushbot_whitelist"|sed 's/ /\n/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
ip_white_list=`echo "$ip_white_list"|sed 's/ /\n/g'` 2>/dev/null
mark_mac_list="${MAC_online_list} ${MAC_offline_list}"
mark_mac_list=`echo "$mark_mac_list"|sed 's/ /\n/g'|sed 's/-/ /'` 2>/dev/null
ipv4_urllist=`cat /usr/bin/pushbot/api/ipv4.list` 2>/dev/null
ipv6_urllist=`cat /usr/bin/pushbot/api/ipv6.list` 2>/dev/null
[ -z "$pushbot_ipv4" ] && pushbot_ipv4=0
[ -z "$pushbot_ipv6" ] && pushbot_ipv6=0
[ "$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`
[ -z "$timeout_retry_count" ] && timeout_retry_count="2";[ "$timeout_retry_count" -eq "0" ] && timeout_retry_count="1"
markdown_splitline="\n\n---\n\n";markdown_linefeed="\n\n";markdown_tab=" ";markdown_space=" ";greenfont="<font color=#92D050>";bluefont="<font color=#76CCFF>";fontend="</font>";
tabletab=${bluefont}┋${fontend};boldstar="**";titlel4="####";titlebold="**";titleboldend="**";titleblue="<font color=#76CCFF>";titlegreen="<font color=#92D050>";titleend="</font>";titlered="<font color=#FF6666>"
[ ! -z "$send_we" ] && [ "$send_we" -eq "1" ] && markdown_splitline="\n\n-------\n\n" && markdown_tab=" "
[ ! -z "$send_we" ] && [ "$send_we" -eq "2" ] && percentsym=25 && markdown_splitline="%0D%0A%0D%0A" && markdown_linefeed="%0D%0A%0D%0A" && greenfont="" && bluefont="" && fontend="" && tabletab=" " && boldstar=""
[ ! -z "$send_we" ] && [ "$send_we" -eq "3" ] && titlel4="" && titlebold="【" && titleboldend="】" && titleblue="" && titlegreen="" && titleend="" && titlered="" && greenfont="" && bluefont="" && fontend="" && tabletab=" " && boldstar="" && markdown_splitline="\n---\n" && markdown_linefeed="\n"
[ ! -z "$send_we" ] && [ "$send_we" -eq "4" ] && titlel4="" && titlebold="【" && titleboldend="】" && titleblue="" && titlegreen="" && titleend="" && titlered="" && greenfont="" && bluefont="" && fontend="" && tabletab=" " && boldstar="" && markdown_splitline="%0D%0A%0D%0A" && markdown_linefeed="%0D%0A%0D%0A" && percentsym=25 && [ -z "$bark_srv" ] && bark_srv="https://api.day.app"
# [ ! -z "$content_content" ] && [ "$content_content" -eq "1" ] && str_title_start="" && str_title_end="" && str_splitline="" && str_linefeed="" && str_tab=""
[ ! -z "$bark_token" ] && [ -z "$bark_srv" ] && bark_srv="https://api.day.app"
# 字符串读取
str_title_start=`/usr/bin/jq -r '.str_title_start' ${jsonpath}`
str_title_end=`/usr/bin/jq -r '.str_title_end' ${jsonpath}`
str_linefeed=`/usr/bin/jq -r '.str_linefeed' ${jsonpath}`
str_splitline=`/usr/bin/jq -r '.str_splitline' ${jsonpath}`
str_space=`/usr/bin/jq -r '.str_space' ${jsonpath}`
str_tab=`/usr/bin/jq -r '.str_tab' ${jsonpath}`
font_red=`/usr/bin/jq -r '.font_red' ${jsonpath}`
font_green=`/usr/bin/jq -r '.font_green' ${jsonpath}`
font_green2=`/usr/bin/jq -r '.font_green2' ${jsonpath}`
font_blue=`/usr/bin/jq -r '.font_blue' ${jsonpath}`
font_purple=`/usr/bin/jq -r '.font_purple' ${jsonpath}`
font_end=`/usr/bin/jq -r '.font_end' ${jsonpath}`
font_end2=`/usr/bin/jq -r '.font_end2' ${jsonpath}`
percentsym=`/usr/bin/jq -r '.percentsym' ${jsonpath}`
boldstar=`/usr/bin/jq -r '.boldstar' ${jsonpath}`
table_tab=`/usr/bin/jq -r '.tabletab' ${jsonpath}`
( echo "$lite_enable"|grep -q "content" ) && str_title_start="" && str_title_end="" && str_splitline="" && str_linefeed="" && str_tab=""
}
# 初始化
function pushbot_init(){
@ -43,15 +78,34 @@ function pushbot_init(){
fi
down_oui &
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
[ ! -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 "$cu_version" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法获取依赖项 curl 版本号,请确认插件是否正常运行" >> ${logfile}
[ -z "$dd_webhook" ] && [ -z "$pp_token" ] && [ -z "$we_webhook" ] && [ -z "$fs_webhook" ] && [ -z "$bark_token" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【】请填写正确的Token/Webhook " >> ${logfile} && return 1
[ -z "${dd_webhook}${pp_token}${we_webhook}${fs_webhook}${bark_token}" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【】请填写正确的Token/Webhook " >> ${logfile} && return 1
local interfacelist=`getinterfacelist` && [ -z "$interfacelist" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法正确获取接口信息,请确认插件是否正常运行" >> ${logfile}
return 0
}
# 推送
function diy_send(){
( ! echo "$lite_enable"|grep -q "content" ) && ( ! echo "$lite_enable"|grep -q "nowtime" ) && local nowtime=`date "+%Y-%m-%d %H:%M:%S"`
local diyurl=`/usr/bin/jq -r .url ${3}` && local diyurl=`eval echo ${diyurl}`
local type=`/usr/bin/jq -r '.type' ${3}` && local type=`eval echo ${type}`
local data=`/usr/bin/jq -r '.data' ${3}` && local data=`eval echo ${data}`
local content_type=`/usr/bin/jq -r '.content_type' ${3}`
/usr/bin/jq ".type + $type" ${jsonpath} > ${tempjsonpath}
/usr/bin/jq -r '.[]' ${tempjsonpath}|grep -w "null" && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】参数值错误,请检查设置项 `/usr/bin/jq -r '.' ${tempjsonpath}|grep "null"`" >> ${logfile} && return 1
[ -f ${tempjsonpath} ] && local logrow=$(grep -c "" ${tempjsonpath}) || local logrow="0"
[ $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}
curl -X POST -H "$content_type" -d "${data}" "${diyurl}"
}
# 下载设备MAC厂商信息
function down_oui(){
[ -f ${oui_base} ] && local logrow=$(grep -c "" ${oui_base}) || local logrow="0"
@ -74,8 +128,8 @@ utstarcom\|volans\|xerox\|xiaomi\|zdc\|zhongxing\|smartisan" > ${oui_base} && ec
# 清理临时文件
function deltemp(){
unset title content
rm -f ${dir}title ${dir}content ${dir}top ${dir}tmp_downlist ${dir}send_enable.lock >/dev/null 2>&1
unset title content ipAddress_logrow online_list online_mac mac_online_status
rm -f ${dir}title ${dir}content ${dir}tmp_downlist ${dir}send_enable.lock ${tempjsonpath} >/dev/null 2>&1
LockFile unlock
[ -f ${logfile} ] && local logrow=$(grep -c "" ${logfile}) || local logrow="0"
[ $logrow -gt 500 ] && sed -i '1,100d' ${logfile} && echo "`date "+%Y-%m-%d %H:%M:%S"` 【清理】日志超出上限,删除前 100 条" >> ${logfile}
@ -99,16 +153,15 @@ function getip(){
elif [ $1 == "hostipv4" ] ;then
function get_hostipv4()
{
[ -z "$ipv4_urllist" ] && local ipv4_urllist="www.cip.cc myip.ipip.net ipv4.ddnspod.com ifcfg.cn speed.neu.edu.cn/getIP.php ddns.oray.com/checkip www.net.cn/static/customercare/yourip.asp"
local url_number=`expr $(echo "$ipv4_urllist"|grep -o ' '|wc -l) + 1`
local ipv4_URL=`echo "$ipv4_urllist"|awk -v i=$(rand 1 $url_number) '{print $i}'`
local url_number=`echo "$ipv4_urllist"|wc -l`
local ipv4_URL=`echo "$ipv4_urllist"| sed -n "$(rand 1 $url_number)p"|sed -e 's/\r//g'`
[ ! -z "$ipv4_interface" ] && local hostIP=$(curl -k -s -4 --interface ${ipv4_interface} -m 5 ${ipv4_URL}) || local hostIP=$(curl -k -s -4 -m 5 ${ipv4_URL})
echo $hostIP|grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'|head -n1
}
local hostIP=`get_hostipv4`
[ -z "$hostIP" ] && local hostIP=`get_hostipv4`
[ -z "$hostIP" ] && local hostIP=`get_hostipv4`
echo $hostIP
echo $hostIP # 重试,偷懒,有空再优化
elif [ $1 == "wanipv6" ] ;then
[ ! -z "$ipv6_interface" ] && local wanIPv6=$(ip addr show ${ipv6_interface}|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|awk '{print $2}')
[ -z "$ipv6_interface" ] && local 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|awk '{print $2}')
@ -116,11 +169,10 @@ function getip(){
elif [ $1 == "hostipv6" ] ;then
function get_hostipv6()
{
[ -z "$ipv6_urllist" ] && local ipv6_urllist="ip.sb ipv6.ddnspod.com api-ipv6.ip.sb/ip speed.neu6.edu.cn/getIP.php v6.myip.la/json"
local urlv6_number=`expr $(echo "$ipv6_urllist"|grep -o ' '|wc -l) + 1`
local ipv6_URL=`echo "$ipv6_urllist"|awk -v i=$(rand 1 $url_number) '{print $i}'`
local urlv6_number=`echo "$ipv6_urllist"|wc -l`
local ipv6_URL=`echo "$ipv6_urllist"| sed -n "$(rand 1 $urlv6_number)p"|sed -e 's/\r//g'`
[ ! -z "$ipv6_interface" ] && local hostIPv6=$(curl -k -s -6 --interface ${ipv6_interface} -m 5 ${ipv6_URL}) || local hostIPv6=$(curl -k -s -6 -m 5 ${ipv6_URL})
echo $hostIPv6|grep -oE '([\da-fA-F0-9]{1,4}(:{1,2})){1,15}[\da-fA-F0-9]{1,4}'
echo $hostIPv6|grep -oE '([\da-fA-F0-9]{1,4}(:{1,2})){1,15}[\da-fA-F0-9]{1,4}'|head -n1
}
local hostIPv6=`get_hostipv6`
[ -z "$hostIPv6" ] && local hostIPv6=`get_hostipv6`
@ -210,17 +262,18 @@ function getcpu(){
# 获取SOC温度 (取所有传感器温度最大值)
function soc_temp(){
[ -z "$soc_code" ] && soc_code="cat /sys/class/thermal/thermal_zone*/temp|sort -nr|head -n1|cut -c-2"
[ "$soc_code" == "sensors" ] && soc_code="sensors|grep °C|sed -nr 's#^.*:.*\+(.*)°C .*#\1#gp'|sort -nr|head -n1"
echo "$soc_code"|awk '{run=$0;system(run)}' 2>/dev/null
[ -z "$soc_code" ] && local soctemp=`sensors 2>/dev/null|grep °C|sed -nr 's#^.*:.*\+(.*)°C .*#\1#gp'|sort -nr|head -n1`
[ -z "$soc_code" ] && [ -z "$soctemp" ] && local soctemp=`cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null|sort -nr|head -n1|cut -c-2`
[ ! -z "$soctemp" ] && echo "$soctemp" && return
[ ! -z "$soc_code" ] && echo "$soc_code"|awk '{run=$0;system(run)}' 2>/dev/null
}
# 流量数据
function usage(){
[ ! -f "/usr/sbin/wrtbwmon" ] || [ ! "$1" ] && return
if [ $1 == "update" ] ;then
function version_le() { test "$(echo "$@"|tr " " "\n"|sort -V|head -n 1)" == "$1"; }
function version_ge() { test "$(echo "$@"|tr " " "\n"|sort -rV|head -n 1)" == "$1"; }
function version_le() { test "$(echo "$@"|tr " " "\n"|sort -n|head -n 1)" == "$1"; }
function version_ge() { test "$(echo "$@"|tr " " "\n"|sort -r|head -n 1)" == "$1"; }
[ ! -z "$wr_version" ] && ( version_ge "${wr_version}" "1.2.0" ) && wrtbwmon -f ${dir}usage.db 2>/dev/null && return
[ ! -z "$wr_version" ] && ( version_le "${wr_version}" "1.0.0" ) || [ -z "$wr_version" ] && wrtbwmon update ${dir}usage.db 2>/dev/null && return
elif [ $1 == "get" ] ;then
@ -239,7 +292,7 @@ function usage(){
# 流量数据单位换算
function bytes_for_humans {
[ ! "$1" ] && return
[ "$1" -gt 1073741824 ] && echo "`awk 'BEGIN{printf "%.2f\n",'$1'/'1073741824'}'`G" && return
[ "$1" -gt 1073741824 ] && echo "`awk 'BEGIN{printf "%.2f\n",'$1'/'1073741824'}'` G" && return
[ "$1" -gt 1048576 ] && echo "`awk 'BEGIN{printf "%.2f\n",'$1'/'1048576'}'` M" && return
[ "$1" -gt 1024 ] && echo "`awk 'BEGIN{printf "%.2f\n",'$1'/'1024'}'` K" && return
echo "${1} bytes"
@ -271,18 +324,18 @@ function get_client_usage(){
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|head -n1`
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 ip_total=`usage get $mac` && [ ! -z "$ip_total" ] && local ip_total="${str_linefeed}${str_tab}总计流量: ${str_space}${str_space}${str_space}${str_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}${titlel4} ${titlered}设备流量异常${titleend}${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}"
content="${content}${str_splitline}${str_title_start}${font_red} 设备流量异常${font_end}${str_title_end}${str_linefeed}${str_tab}客户端名:${str_space}${str_space}${str_space}${str_space}${str_space}${ip_name}${str_linefeed}${str_tab}客户端IP ${str_space}${str_space}${str_space}${str_space}${ip}${str_linefeed}${str_tab}客户端MAC${str_space}${str_space}${str_space}${str_space}${mac}$ip_total${str_linefeed}${str_tab}一分钟内流量: ${str_space}${str_space}${tmp_usage}${str_linefeed}${str_tab}在线时间: ${str_space}${str_space}${str_space}${str_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}"
content="${content}${str_splitline}${str_tab}客户端名:${str_space}${str_space}${str_space}${str_space}${str_space}${ip_name}${str_linefeed}${str_tab}客户端IP ${str_space}${str_space}${str_space}${str_space}${ip}${str_linefeed}${str_tab}客户端MAC${str_space}${str_space}${str_space}${str_space}${mac}$ip_total${str_linefeed}${str_tab}一分钟内流量: ${str_space}${str_space}${str_space}${tmp_usage}${str_linefeed}${str_tab}在线时间: ${str_space}${str_space}${str_space}${str_space}${time1}"
else
title="设备状态变化"
content="${content}${markdown_splitline}${titlel4} ${titlered}设备流量异常${titleend}${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}"
content="${content}${str_splitline}${str_title_start}${font_red} 设备流量异常${font_end}${str_title_end}${str_linefeed}${str_tab}客户端名:${str_space}${str_space}${str_space}${str_space}${str_space}${ip_name}${str_linefeed}${str_tab}客户端IP ${str_space}${str_space}${str_space}${str_space}${ip}${str_linefeed}${str_tab}客户端MAC${str_space}${str_space}${str_space}${str_space}${mac}$ip_total${str_linefeed}${str_tab}一分钟内流量: ${str_space}${str_space}${str_space}${tmp_usage}${str_linefeed}${str_tab}在线时间: ${str_space}${str_space}${str_space}${str_space}${time1}"
fi
fi
done
@ -342,9 +395,9 @@ function cut_str {
# 随机数
function rand(){
min=$1
max=$(($2- $min + 1))
num=$(date +%s%N)
local min=$1
local max=$(($2- $min + 1))
local num=$(date +%s%N)
echo $(($num % $max + $min))
}
@ -360,7 +413,7 @@ function pushbot_first(){
done
wait
unset ip IPLIST
local IPLIST=`cat /proc/net/arp|grep "0x2\|0x6"|awk '{print $1}'|grep -v "^169.254."|grep -v "^$"|sort -u`
local IPLIST=`cat /proc/net/arp|grep "0x2\|0x6"|awk '{print $1}'|grep -v "^169.254."|grep -v "^$"|sort -u|grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'`
for ip in $IPLIST; do
read -u 5
{
@ -370,7 +423,6 @@ function pushbot_first(){
done
wait
}
# 创建计划任务
function pushbot_cron(){
function del_cron(){
@ -381,11 +433,11 @@ function pushbot_cron(){
/etc/init.d/cron start
}
del_cron
if [ -z "$pushbot_enable" ] || [ -z "$send_mode" -a -z "$reset_regularly" ]; then
if [ -z "$pushbot_enable" ]; then
re_cron
return
fi
# 重置流量
if [ ! -z "$reset_regularly" ] && [ "$reset_regularly" -eq "1" ]; then
crontab -l 2>/dev/null > conf && echo -e "0 0 * * * rm /tmp/pushbot/usage.db >/dev/null 2>&1" >> conf && crontab conf && rm -f conf >/dev/null 2>&1
@ -409,8 +461,7 @@ function pushbot_disturb(){
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
unset sheep_starttime
rm -f ${dir}sheep_usage ${dir}old_sheep_usage 2>/dev/null
disturb_text="【钉钉推送】"
[ ! -z "$send_we" ] && [ "$send_we" -eq "1" ] && disturb_text="【企业微信推送】"
disturb_text=`/usr/bin/jq -r '._api' ${jsonpath}`
return 0
else
[ -z "$sheep_starttime" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【免打扰】夜深了,该休息了" >> ${logfile} && sheep_starttime=`date +%s`
@ -436,17 +487,20 @@ function LockFile(){
LockFile lock
fi
[ $1 = "unlock" ] && rm -f ${dir}pushbot.lock >/dev/null 2>&1
return
return 0
}
# 检测黑白名单
function blackwhitelist(){
[ ! "$1" ] && return 1
[ -z "$pushbot_whitelist" ] && [ -z "$pushbot_blacklist" ] && [ -z "$pushbot_interface" ] && return
[ ! -z "$pushbot_whitelist" ] && ( ! echo "$pushbot_whitelist"|grep -q -i -w $1) && return
[ ! -z "$pushbot_blacklist" ] && ( echo "$pushbot_blacklist"|grep -q -i -w $1) && return
[ ! -z "$pushbot_interface" ] && ( echo `getinterface ${1}`|grep -q -i -w $pushbot_interface ) && return
return 1
[ -z "$pushbot_whitelist" ] && [ -z "$pushbot_blacklist" ] && [ -z "$pushbot_interface" ] && [ -z "$MAC_online_list" ] && [ -z "$MAC_offline_list" ] && return 0
[ ! -z "$pushbot_whitelist" ] && ( echo "$pushbot_whitelist"|grep -q -i -w $1 ) && return 1
[ ! -z "$pushbot_blacklist" ] && ( ! echo "$pushbot_blacklist"|grep -q -i -w $1 ) && return 1
[ ! -z "$pushbot_interface" ] && ( ! echo `getinterface ${1}`|grep -q -i -w $pushbot_interface ) && return 1
[ ! -z "$MAC_online_list" ] && [ ! -z "$mac_online_status" ] && return 1
[ ! -z "$MAC_online_list" ] && ( echo "$MAC_online_list"|grep -q -i -w $1 ) && return 1
[ ! -z "$MAC_offline_list" ] && [ -z "$mac_online_status" ] && return 1
return 0
}
function get_client(){
@ -514,7 +568,7 @@ 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" ] && return
if [ ! -z "$system_time_event" ]; then
local interfaceuptime=`getinterfaceuptime`
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
@ -659,39 +713,41 @@ function ip_changes(){
echo "`date "+%Y-%m-%d %H:%M:%S"` ${disturb_text}当前IP${IPv4}" >> ${logfile}
echo IPv4 $IPv4 > ${dir}ip && echo -e IPv6 $last_IPv6 >> ${dir}ip
title="IP 地址变化"
content="${content}${markdown_splitline}${titlel4} ${titlegreen}IP 地址变化${titleend}${markdown_linefeed}${markdown_tab}当前 IP${IPv4}"
content="${content}${str_splitline}${str_title_start}${font_green} IP 地址变化${font_end}${str_title_end}${str_linefeed}${str_tab}当前 IP${IPv4}"
elif [ ! -z "$pushbot_ipv4" ] && [ "$pushbot_ipv4" -ne "0" ] && [ -z "$IPv4" ]; then
echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】获取 IPv4 地址失败" >> ${logfile}
fi
if [ ! -z "$pushbot_ipv6" ] && [ "$pushbot_ipv6" -ne "0" ] && [ ! -z "$IPv6" ] && ( ! echo "$IPv6"|grep -w -q ${last_IPv6} ); then
echo "`date "+%Y-%m-%d %H:%M:%S"` ${disturb_text}当前IPv6${IPv6}" >> ${logfile}
echo IPv4 $IPv4 > ${dir}ip && echo -e IPv6 $IPv6 >> ${dir}ip
[ -z "$title" ] && title="IPv6 地址变化"
[ ! -z "$title" ] && title="IP 地址变化"
content="${content}${markdown_splitline}${titlel4} ${titlegreen}IPv6 地址变化${titleend}${markdown_linefeed}${markdown_tab}当前 IPv6${IPv6}"
content="${content}${str_splitline}${str_title_start}${font_green} IPv6 地址变化${font_end}${str_title_end}${str_linefeed}${str_tab}当前 IPv6${IPv6}"
elif [ ! -z "$pushbot_ipv6" ] && [ "$pushbot_ipv6" -ne "0" ] && [ -z "$IPv6" ]; then
echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】获取 IPv6 地址失败" >> ${logfile}
fi
else
echo "`date "+%Y-%m-%d %H:%M:%S"` ${disturb_text}路由器已经重启!" >> ${logfile}
[ ! -z "$pushbot_ipv4" ] && [ "$pushbot_ipv4" -ne "0" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 当前IP: ${IPv4}" >> ${logfile}
[ ! -z "$pushbot_ipv6" ] && [ "$pushbot_ipv6" -ne "0" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 当前IPv6: ${IPv6}" >> ${logfile}
echo IPv4 $IPv4 > ${dir}ip && echo -e IPv6 $IPv6 >> ${dir}ip
title="路由器重新启动"
content="${content}${markdown_splitline}${titlel4} ${titlegreen}路由器重新启动${titleend}"
[ ! -z "$pushbot_ipv4" ] && [ "$pushbot_ipv4" -ne "0" ] && content="${content}${markdown_linefeed}${markdown_tab}当前IP${IPv4}"
[ ! -z "$pushbot_ipv6" ] && [ "$pushbot_ipv6" -ne "0" ] && content="${content}${markdown_linefeed}${markdown_tab}当前IPv6${IPv6}"
content="${content}${str_splitline}${str_title_start}${font_green} 路由器重新启动${font_end}${str_title_end}"
[ ! -z "$pushbot_ipv4" ] && [ "$pushbot_ipv4" -ne "0" ] && content="${content}${str_linefeed}${str_tab}当前IP${IPv4}"
[ ! -z "$pushbot_ipv6" ] && [ "$pushbot_ipv6" -ne "0" ] && content="${content}${str_linefeed}${str_tab}当前IPv6${IPv6}"
fi
if [ ! -z "$content" ] ;then
[ -z "$ddns_enabled" ] && ddns_enabled=$(uci show ddns|grep "enabled"|grep "1")
[ -z "$ddns_enabled" ] && ddns_logrow=0 || ddns_logrow=$(echo "$ddns_enabled"|wc -l)
if [ $ddns_logrow -ge 1 ]; then
/etc/init.d/ddns stop >/dev/null 2>&1
sleep 10
/etc/init.d/ddns start >/dev/null 2>&1
/etc/init.d/ddns restart >/dev/null 2>&1
fi
[ -z "$zerotier_enabled" ] && zerotier_enabled=$(uci get zerotier.sample_config.enabled)
if [ ! -z "$zerotier_enabled" ] && [ $zerotier_enabled -eq "1" ] ; then
/etc/init.d/zerotier restart >/dev/null 2>&1
fi
fi
}
@ -700,34 +756,46 @@ function ip_changes(){
function up(){
[ -f ${dir}ipAddress ] && ( cat ${dir}ipAddress|grep -q -w $1 ) && return
local ip_mac=`getmac $1`
local ip_name=`getname ${1} ${ip_mac}`
local ip_interface=`getinterface ${ip_mac}`
getping ${1} ${up_timeout} "1";local ping_online=$?
if [ "$ping_online" -eq "0" ]; then
LockFile lock
[ ! -z "$pushbot_blacklist" ] && local tmp_mac=`echo "${pushbot_blacklist}"|grep -w -i ${ip_mac}`
[ ! -z "$pushbot_whitelist" ] && local tmp_mac=`echo "${pushbot_whitelist}"|grep -w -i ${ip_mac}`
if [ ! -z "$tmp_mac" ] && ( cat ${dir}ipAddress|grep -q -w -i ${tmp_mac} ); then
usage down $1
echo "$1 ${ip_mac} ${ip_name} `date +%s` ${ip_interface}" >> ${dir}ipAddress
LockFile unlock && return
elif [ ! -z "$tmp_mac" ] && [ -f "${dir}tmp_downlist" ] && ( cat ${dir}tmp_downip|grep -q -w -i ${tmp_mac} ); then
local tmp_downip=`cat ${dir}tmp_downlist|grep -w -i ${tmp_mac}|awk '{print $1}'|grep -v "^$"|sort -u|head -n1`
usage down $tmp_downip
sed -i "/^${tmp_downip} /d" ${dir}tmp_downlist
LockFile unlock && return
fi
[ -f "${dir}tmp_downlist" ] && local tmp_downip=`cat ${dir}tmp_downlist|grep -w ${1}|grep -v "^$"|sort -u|head -n1`
if [ ! -z "$tmp_downip" ]; then
cat ${dir}tmp_downlist|grep -w ${1}|grep -v "^$"|sort -u|head -n1 >> ${dir}ipAddress
sed -i "/^${1} /d" ${dir}tmp_downlist
else
usage down $1
local ip_name=`getname ${1} ${ip_mac}`
blackwhitelist ${ip_mac};local ip_blackwhite=$?
echo "$1 ${ip_mac} ${ip_name} `date +%s` ${ip_interface}" >> ${dir}ipAddress
blackwhitelist ${ip_mac};local ip_blackwhite=$?
[ -f "${dir}send_enable.lock" ] || [ -z "$pushbot_up" ] || [ -z "$ip_blackwhite" ] && LockFile unlock && return
[ ! -z "$pushbot_up" ] && [ "$pushbot_up" -ne "1" ] && LockFile unlock && return
[ ! -z "$ip_blackwhite" ] && [ "$ip_blackwhite" -ne "0" ] && LockFile unlock && return
[ -z "$ip_blackwhite" ] || [ "$ip_blackwhite" -ne "0" ] && LockFile unlock && return
[ -f "${dir}title" ] && local title=`cat ${dir}title`
[ -f "${dir}content" ] && local content=`cat ${dir}content`
[ -f "${dir}content" ] && local content=`cat ${dir}content`
if [ -z "$title" ]; then
local title="$ip_name 连接了你的路由器"
local content="${markdown_splitline}${titlel4} ${titlegreen}新设备连接${titleend}${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}${1}${markdown_linefeed}${markdown_tab}客户端MAC${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip_mac}${markdown_linefeed}${markdown_tab}网络接口:${markdown_space}${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip_interface}"
local 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}${ip_name}${str_linefeed}${str_tab}客户端IP ${str_space}${str_space}${str_space}${str_space}${1}${str_linefeed}${str_tab}客户端MAC${str_space}${str_space}${str_space}${str_space}${ip_mac}${str_linefeed}${str_tab}网络接口:${str_space}${str_space}${str_space}${str_space}${str_space}${ip_interface}"
elif ( echo ${title}|grep -q "连接了你的路由器" ); then
local title="${ip_name} ${title}"
local 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}${1}${markdown_linefeed}${markdown_tab}客户端MAC${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip_mac}${markdown_linefeed}${markdown_tab}网络接口:${markdown_space}${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip_interface}"
local content="${str_splitline}${str_tab}客户端名:${str_space}${str_space}${str_space}${str_space}${str_space}${ip_name}${str_linefeed}${str_tab}客户端IP ${str_space}${str_space}${str_space}${str_space}${1}${str_linefeed}${str_tab}客户端MAC${str_space}${str_space}${str_space}${str_space}${ip_mac}${str_linefeed}${str_tab}网络接口:${str_space}${str_space}${str_space}${str_space}${str_space}${ip_interface}"
else
local title="设备状态变化"
local content="${markdown_splitline}${titlel4} ${titlegreen}新设备连接${titleend}${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}${1}${markdown_linefeed}${markdown_tab}客户端MAC${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip_mac}${markdown_linefeed}${markdown_tab}网络接口:${markdown_space}${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip_interface}"
fi
local 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}${ip_name}${str_linefeed}${str_tab}客户端IP ${str_space}${str_space}${str_space}${str_space}${1}${str_linefeed}${str_tab}客户端MAC${str_space}${str_space}${str_space}${str_space}${ip_mac}${str_linefeed}${str_tab}网络接口:${str_space}${str_space}${str_space}${str_space}${str_space}${ip_interface}"
fi
echo "`date "+%Y-%m-%d %H:%M:%S"` ${disturb_text}新设备 ${ip_name} ${1} 连接了">> ${logfile}
#[ ! -z "$pushbot_blacklist" ] && local title="你偷偷关注的设备上线了"
[ ! -z "$title" ] && echo "$title" >${dir}title
@ -769,21 +837,24 @@ function down_send(){
blackwhitelist ${ip_mac};local ip_blackwhite=$?
[ -z "$pushbot_down" ] || [ -z "$ip_blackwhite" ] && continue
[ ! -z "$pushbot_down" ] && [ "$pushbot_down" -ne "1" ] && continue
[ ! -z "$ip_blackwhite" ] && [ "$ip_blackwhite" -ne "0" ] && continue
[ -z "$ip_blackwhite" ] || [ "$ip_blackwhite" -ne "0" ] && continue
[ ! -z "$pushbot_blacklist" ] && local tmp_mac=`echo "${pushbot_blacklist}"|grep -w -i ${ip_mac}`
[ ! -z "$pushbot_whitelist" ] && local tmp_mac=`echo "${pushbot_whitelist}"|grep -w -i ${ip_mac}`
[ ! -z "$tmp_mac" ] && ( cat ${dir}ipAddress|grep -q -w -i ${tmp_mac} ) && continue
local ip_name=`getname ${ip} ${ip_mac}`
local time_up=`cat ${dir}tmp_downlist|grep -w ${ip}|awk '{print $4}'|grep -v "^$"|sort -u|head -n1`
local ip_total=`usage get $ip_mac` && [ ! -z "$ip_total" ] && local ip_total="${markdown_linefeed}${markdown_tab}总计流量: ${markdown_space}${markdown_space}${markdown_space}${markdown_space}${ip_total}"
local ip_total=`usage get $ip_mac` && [ ! -z "$ip_total" ] && local ip_total="${str_linefeed}${str_tab}总计流量: ${str_space}${str_space}${str_space}${str_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}${titlel4} ${titlered}设备断开连接${titleend}${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}${ip_mac}$ip_total${markdown_linefeed}${markdown_tab}在线时间: ${markdown_space}${markdown_space}${markdown_space}${markdown_space}${time1}"
content="${content}${str_splitline}${str_title_start}${font_red} 设备断开连接${font_end}${str_title_end}${str_linefeed}${str_tab}客户端名:${str_space}${str_space}${str_space}${str_space}${str_space}${ip_name}${str_linefeed}${str_tab}客户端IP ${str_space}${str_space}${str_space}${str_space}${ip}${str_linefeed}${str_tab}客户端MAC${str_space}${str_space}${str_space}${str_space}${ip_mac}$ip_total${str_linefeed}${str_tab}在线时间: ${str_space}${str_space}${str_space}${str_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}${ip_mac}$ip_total${markdown_linefeed}${markdown_tab}在线时间: ${markdown_space}${markdown_space}${markdown_space}${markdown_space}${time1}"
content="${content}${str_splitline}${str_tab}客户端名:${str_space}${str_space}${str_space}${str_space}${str_space}${ip_name}${str_linefeed}${str_tab}客户端IP ${str_space}${str_space}${str_space}${str_space}${ip}${str_linefeed}${str_tab}客户端MAC${str_space}${str_space}${str_space}${str_space}${ip_mac}$ip_total${str_linefeed}${str_tab}在线时间: ${str_space}${str_space}${str_space}${str_space}${time1}"
else
title="设备状态变化"
content="${content}${markdown_splitline}${titlel4} ${titlered}设备断开连接${titleend}${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}${ip_mac}$ip_total${markdown_linefeed}${markdown_tab}在线时间: ${markdown_space}${markdown_space}${markdown_space}${markdown_space}${time1}"
content="${content}${str_splitline}${str_title_start}${font_red} 设备断开连接${font_end}${str_title_end}${str_linefeed}${str_tab}客户端名:${str_space}${str_space}${str_space}${str_space}${str_space}${ip_name}${str_linefeed}${str_tab}客户端IP ${str_space}${str_space}${str_space}${str_space}${ip}${str_linefeed}${str_tab}客户端MAC${str_space}${str_space}${str_space}${str_space}${ip_mac}$ip_total${str_linefeed}${str_tab}在线时间: ${str_space}${str_space}${str_space}${str_space}${time1}"
fi
echo "`date "+%Y-%m-%d %H:%M:%S"` ${disturb_text}设备 ${ip_name} ${ip} 断开连接 " >> ${logfile}
done
@ -792,29 +863,30 @@ function down_send(){
# 当前设备列表
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}usage.db ] && local ip_total_db="总计流量"
content="${content}${markdown_splitline}${titlel4} ${titlebold}${titleblue}现有在线设备 ${logrow} 台,具体如下${titleend}${titleboldend}${markdown_linefeed}${markdown_tab}IP 地址${markdown_tab}${tabletab}${ip_total_db}${tabletab}${boldstar}客户端名${boldstar}"
[ -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}"
local IPLIST=`cat ${dir}ipAddress|awk '{print $1}'`
for ip in $IPLIST; do
local ip_mac=`getmac ${ip}`
local ip_total=`usage get ${ip_mac}`
local ip_name=`getname ${ip} ${ip_mac}`
local ip_name=`cut_str $ip_name 15`
if [ "${#ip}" -lt "15" ]; then
if [ "${#ip}" -lt "15" ]; then
local n=`expr 15 - ${#ip}`
for i in `seq 1 $n`; do
local ip="${ip}"
local ip="${ip}${str_space}"
done
unset i n
fi
if [ ! -z "$ip_total" ]; then
if [ ! -z "$ip_total" ]; then
local n=`expr 11 - ${#ip_total}`
for i in `seq 1 $n`; do
local ip_total="${ip_total}"
local ip_total="${ip_total}${str_space}"
done
fi
content="${content}${markdown_linefeed}${markdown_tab}${ip}${tabletab}${ip_total}${tabletab}${boldstar}${greenfont}${ip_name}${fontend}${boldstar}"
content="${content}${str_linefeed}${str_tab}${ip}${ip_total}${boldstar}${font_green2}${ip_name}${font_end2}${boldstar}"
unset i n ip_total ip_mac ip_name
done
}
@ -825,18 +897,18 @@ function cpu_load(){
[ -z "$temperature_time" ] && temperature_time=`date +%s`
local cpu_wendu=`soc_temp`;
[ -z "$cpu_wendu" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取设备温度,请检查命令" >> ${logfile}
if [ "$cpu_wendu" -gt "$temperature" ]; then
echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!警报!!】 CPU 温度过高: ${cpu_wendu}" >> ${logfile}
else
temperature_time=`date +%s`
fi
if [ "$((`date +%s`-$temperature_time))" -ge "300" ] && [ -z "$temperaturecd_time" ]; then
title="CPU 温度过高!"
temperaturecd_time=`date +%s`
echo "`date "+%Y-%m-%d %H:%M:%S"` ${disturb_text} CPU 温 度过高: ${cpu_wendu}" >> ${logfile}
content="${content}${markdown_splitline}${titlel4} ${titlered}CPU 温度过高${titleend}${markdown_linefeed}${markdown_tab}CPU 温度已连续五分钟超过预设${markdown_linefeed}${markdown_tab}接下来一小时不再提示${markdown_linefeed}${markdown_tab}当前温度:${cpu_wendu}"
echo "`date "+%Y-%m-%d %H:%M:%S"` ${disturb_text} CPU 温度过高: ${cpu_wendu}" >> ${logfile}
content="${content}${str_splitline}${str_title_start}${font_red} CPU 温度过高${font_end}${str_title_end}${str_linefeed}${str_tab}CPU 温度已连续五分钟超过预设${str_linefeed}${str_tab}接下来一小时不再提示${str_linefeed}${str_tab}当前温度:${cpu_wendu}℃"
elif [ ! -z "$temperaturecd_time" ] && [ "$((`date +%s`-$temperaturecd_time))" -ge "3300" ] ;then
unset temperaturecd_time
fi
@ -846,14 +918,14 @@ function cpu_load(){
[ -z "$cpuload_time" ] && cpuload_time=`date +%s`
local cpu_fuzai=`cat /proc/loadavg|awk '{print $1}'` 2>/dev/null
[ -z "$cpu_fuzai" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】无法读取设备负载,请检查命令" >> ${logfile}
if [ `expr $cpu_fuzai \> $cpuload` -eq "1" ]; then
echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!警报!!】 CPU 负载过高: ${cpu_fuzai}" >> ${logfile}
cputop log
else
cpuload_time=`date +%s`
fi
if [ "$((`date +%s`-$cpuload_time))" -ge "300" ] && [ -z "$cpucd_time" ]; then
unset getlogtop
if [ ! -z "$title" ] && ( echo "$title"|grep -q "过高" ); then
@ -863,7 +935,7 @@ function cpu_load(){
fi
cpucd_time=`date +%s`
echo "`date "+%Y-%m-%d %H:%M:%S"` ${disturb_text} CPU 负 载过高: ${cpu_fuzai}" >> ${logfile}
content="${content}${markdown_splitline}${titlel4} ${titlered}CPU 负载过高${titleend}${markdown_linefeed}${markdown_tab}CPU 负载已连续五分钟超过预设${markdown_linefeed}${markdown_tab}接下来一小时不再提示${markdown_linefeed}${markdown_tab}当前负载:${cpu_fuzai}"
content="${content}${str_splitline}${font_red}CPU 负载过高${font_end}${str_linefeed}${str_tab}CPU 负载已连续五分钟超过预设${str_linefeed}${str_tab}接下来一小时不再提示${str_linefeed}${str_tab}当前负载:${cpu_fuzai}"
cputop
elif [ ! -z "$cpucd_time" ] && [ "$((`date +%s`-$cpucd_time))" -ge "3300" ] ;then
unset cpucd_time
@ -872,65 +944,214 @@ function cpu_load(){
}
function cputop(){
[ -z "$1" ] && content="${content}${markdown_splitline}${titlel4} 当前 CPU 占用前三的进程"
local i=1 && local top_i=5 && `top -bn 1 > ${dir}top` >/dev/null 2>&1
while [ $i -le 3 ]; do
if ( ! cat ${dir}top|awk 'NR=='${top_i}|grep -q "top -bn 1" ); then
local top_name=`cat ${dir}top|awk 'NR=='${top_i}|awk '{print $8}'`;[ "$top_name" == "/bin/sh" ] || [ "$top_name" == "/bin/bash" ] && local top_name=`cat ${dir}top|awk 'NR=='${top_i}|awk '{print $9}'`
local top_load=`cat ${dir}top|awk 'NR=='${top_i}|awk '{print $7}'`
local temp_top="${top_name} ${top_load}"
[ ! -z "$1" ] && local logtop="$logtop $temp_top"
[ -z "$1" ] && content="${content}${markdown_linefeed}${markdown_tab}${temp_top}"
local i=`expr ${i} + 1`
fi
local top_i=`expr ${top_i} + 1`
[ -z "$1" ] && content="${content}${str_splitline}${str_title_start} 当前 CPU 占用前三的进程${str_title_end}"
local gettop=`top -bn 1|grep -v "top -bn 1"`
for i in `seq 5 7`; do
local top_name=`echo "${gettop}"|awk 'NR=='${i}|awk '{print ($8 ~ /\/bin\/sh|\/bin\/bash/) ? $9 : $8}'`
local top_load=`echo "${gettop}"|awk 'NR=='${i}|awk '{print $7}'`
local temp_top="${top_name} ${top_load}"
[ ! -z "$1" ] && local logtop="$logtop $temp_top"
[ -z "$1" ] && content="${content}${str_linefeed}${str_tab}${temp_top}"
done
unset i
[ ! -z "$1" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!警报!!】 CPU 占用前三: ${logtop}" >> ${logfile}
rm -f ${dir}top >/dev/null 2>&1
}
# 生成日志监控文件,避免后台影响 wait 语句
function get_syslog(){
kill -9 `pgrep -f "logread -f -p notice"` 2>/dev/null
[ -z "$web_logged" ] && [ -z "$ssh_logged" ] && [ -z "$web_login_failed" ] && [ -z "$ssh_login_failed" ] && return
rm -f ${dir}login_monitor >/dev/null 2>&1
cat>${dir}get_syslog<<EOF
#!/bin/sh
logread -f -p notice >> ${dir}login_monitor &
EOF
chmod 0755 ${dir}get_syslog && ${dir}get_syslog
rm -f ${dir}get_syslog >/dev/null 2>&1
}
# 登录提醒通知
function login_send(){
[ -z "$web_logged" ] && [ -z "$ssh_logged" ] && [ -z "$web_login_failed" ] && [ -z "$ssh_login_failed" ] && return
[ ! -f ${dir}login_monitor ] && return
cat ${dir}login_monitor|grep -i "accepted login"|awk '{print $4" "$NF}' >> ${dir}web_login
cat ${dir}login_monitor|grep -i "Password auth succeeded\|Pubkey auth succeeded"|grep -Eo "[0-9]{2}:[0-9]{2}:[0-9]{2}.*[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"|awk '{print $1" "$NF" "$5}' >> ${dir}ssh_login
cat ${dir}login_monitor|grep -i "failed login"|grep -Eo "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" >> ${dir}web_failed
cat ${dir}login_monitor|grep -i "Bad password attempt\|Login attempt for nonexistent user from"|grep -Eo "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" >> ${dir}ssh_failed
echo "" > ${dir}login_monitor
add_ip_black
local login_ip_list=`cat ${dir}web_login|awk '{print $2}'|grep -v "^$"|sort -u|head -n1`
for login_ip in $login_ip_list; do
[ -z "$login_ip" ] && continue
echo "$ip_white_list"|grep -w -q "$login_ip" && continue
local web_login_time=`cat ${dir}web_login|grep -w ${login_ip}|awk '{print $1}'|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 "$title" ]; then
title="${login_ip} 通过 Web 登录了路由器"
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
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}"
else
title="设备状态变化"
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
echo "`date "+%Y-%m-%d %H:%M:%S"` ${disturb_text}设备 ${login_ip} 通过 web ${web_login_mode} 登录了路由器 " >> ${logfile}
done
echo "" > ${dir}web_login
unset login_ip login_ip_list
local login_ip_list=`cat ${dir}ssh_login|awk '{print $2}'|grep -v "^$"|sort -u|head -n1`
for login_ip in $login_ip_list; do
[ -z "$login_ip" ] && continue
echo "$ip_white_list"|grep -w -q "$login_ip" && continue
local ssh_login_time=`cat ${dir}ssh_login|grep -w ${login_ip}|awk '{print $1}'|grep -v "^$"|sort -u|head -n1`
local ssh_login_mode=`cat ${dir}ssh_login|grep -w ${login_ip}|awk '{print $3}'|grep -v "^$"|sort -u|head -n1`
[ ! -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 "$title" ]; then
title="${login_ip} 通过 SSH 登录了路由器"
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
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}"
else
title="设备状态变化"
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
echo "`date "+%Y-%m-%d %H:%M:%S"` 【info】设备 ${login_ip} 通过 SSH ${ssh_login_mode} 登录了路由器 " >> ${logfile}
done
echo "" > ${dir}ssh_login
unset login_ip login_ip_list
local login_ip_list=`cat ${dir}web_failed|awk '{print $1}'|grep -v "^$"|sort -u|head -n1`
for login_ip in $login_ip_list; do
[ -z "$login_ip" ] && continue
echo "$ip_white_list"|grep -w -q "$login_ip" && continue
local web_login_sum=`cat ${dir}web_failed|grep -w "${login_ip}"|wc -l`
if [ "$web_login_sum" -ge "$login_max_num" ] ;then
if [ ! -z "$web_login_failed" ] && [ "$web_login_failed" -eq "1" ]; then
if [ -z "$title" ]; then
title="${login_ip} 通过 Web 频繁尝试登录"
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
title="${login_ip} ${title}"
content="${content}${str_splitline}${str_tab}设备 IP ${str_space}${str_space}${str_space}${str_space}${login_ip}"
else
title="设备状态变化"
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
sed -i "/^${login_ip}$/d" ${dir}web_failed
echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】设备 ${login_ip} 通过 Web 频繁尝试登录" >> ${logfile}
add_ip_black $login_ip
fi
done
unset login_ip
local login_ip_list=`cat ${dir}ssh_failed|awk '{print $1}'|grep -v "^$"|sort -u|head -n1`
for login_ip in $login_ip_list; do
[ -z "$login_ip" ] && continue
echo "$ip_white_list"|grep -w -q "$login_ip" && continue
local ssh_login_sum=`cat ${dir}ssh_failed|grep -w "${login_ip}"|wc -l`
if [ "$ssh_login_sum" -ge "$login_max_num" ] ;then
if [ ! -z "$ssh_login_failed" ] && [ "$ssh_login_failed" -eq "1" ]; then
if [ -z "$title" ]; then
title="${login_ip} 通过 SSH 频繁尝试登录"
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
title="${login_ip} ${title}"
content="${content}${str_splitline}${str_tab}设备 IP ${str_space}${str_space}${str_space}${str_space}${login_ip}"
else
title="设备状态变化"
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
sed -i "/^${login_ip}$/d" ${dir}ssh_failed
echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】设备 ${login_ip} 通过 SSH 频繁尝试登录" >> ${logfile}
add_ip_black $login_ip
fi
done
unset login_ip
}
# 添加黑名单
function add_ip_black(){
[ -f "${ip_blacklist_path}" ] && local logrow=$(grep -c "" ${ip_blacklist_path}) || local logrow="0"
[ ! -f "${ip_blacklist_path}" ] && local logrow="0"
[ ! -z "$web_login_black" ] && [ "$web_login_black" -eq "0" ] || [ -z "$web_login_black" ] && local logrow="0"
ipset flush ip_blacklist >/dev/null 2>&1
if [ $logrow -le "0" ]; then
iptables -D INPUT -m set --match-set ip_blacklist src -j DROP >/dev/null 2>&1
ipset destroy ip_blacklist >/dev/null 2>&1
return
fi
ipset list ip_blacklist >/dev/null 2>&1 || ipset create ip_blacklist hash:ip timeout ${ip_black_timeout} >/dev/null 2>&1
iptables -C INPUT -m set --match-set ip_blacklist src -j DROP >/dev/null 2>&1 || iptables -I INPUT -m set --match-set ip_blacklist src -j DROP >/dev/null 2>&1
echo "$1" >> ${ip_blacklist_path}
for ip_black in `cat ${ip_blacklist_path}`; do
ip_black=`echo "$ip_black"|grep -Eo "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"`
ipset -! add ip_blacklist $ip_black >/dev/null 2>&1
done
ipset list ip_blacklist|grep -Eo "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" > ${ip_blacklist_path}
}
# 发送定时数据
function send(){
echo "`date "+%Y-%m-%d %H:%M:%S"` 【定时数据】创建定时任务" >> ${logfile}
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 "$client_list" ] && [ "$client_list" -eq "1" ] && > ${dir}send_enable.lock && pushbot_first &
[ ! -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" ] && [ ! -z "$client_list" ] && [ "$client_list" -eq "1" ] && > ${dir}send_enable.lock && pushbot_first &
if [ ! -z "$router_status" ] && [ "$router_status" -eq "1" ]; then
if [ -z "$1" ] && [ ! -z "$router_status" ] && [ "$router_status" -eq "1" ]; then
local systemload=`cat /proc/loadavg|awk '{print $1" "$2" "$3}'`
local cpuload=`getcpu`
local ramload=`free -m|sed -n '2p'|awk '{printf "%.2f%%\n",($3/$2)*100}'`
local systemstatustime=`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)}'`;unset run_days run_hour run_minute run_second
local send_content="${send_content}${markdown_splitline}${titlel4} ${titlebold}${titleblue}系统运行状态${titleend}${titleboldend}"
local send_content="${send_content}${markdown_linefeed}${markdown_tab}平均负载:${systemload}"
local send_content="${send_content}${markdown_linefeed}${markdown_tab}CPU占用${cpuload}${percentsym}"
local send_content="${send_content}${markdown_linefeed}${markdown_tab}内存占用:${ramload}${percentsym}"
local send_content="${send_content}${markdown_linefeed}${markdown_tab}${systemstatustime}"
local send_content="${send_content}${str_splitline}${str_title_start}${font_blue} 系统运行状态${font_end}${str_title_end}"
local send_content="${send_content}${str_linefeed}${str_tab}平均负载:${systemload}"
local send_content="${send_content}${str_linefeed}${str_tab}CPU占用${cpuload}${percentsym}"
local send_content="${send_content}${str_linefeed}${str_tab}内存占用:${ramload}${percentsym}"
local send_content="${send_content}${str_linefeed}${str_tab}${systemstatustime}"
fi
[ ! -z "$router_temp" ] && [ "$router_temp" -eq "1" ] && local cputemp=`soc_temp` && local send_content="${send_content}${markdown_splitline}${titlel4} ${titlebold}${titleblue}设备温度${titleend}${titleboldend}${markdown_linefeed}${markdown_tab}CPU${cputemp}℃" #%e2%84%83="℃"
if [ -z "$1" ] && [ ! -z "$router_temp" ] && [ "$router_temp" -eq "1" ]; then
local cputemp=`soc_temp`
[ ! -z "$cputemp" ] && local send_content="${send_content}${str_splitline}${str_title_start}${font_blue} 设备温度${font_end}${str_title_end}${str_linefeed}${str_tab}CPU${cputemp}℃"
[ -z "$cputemp" ] && local send_content="${send_content}${str_splitline}${str_title_start}${font_red} 设备温度${font_end}${str_title_end}${str_linefeed}${str_tab}无法获取设备温度"
fi
if [ ! -z "$router_wan" ] && [ "$router_wan" -eq "1" ]; then
if [ -z "$1" ] && [ ! -z "$router_wan" ] && [ "$router_wan" -eq "1" ]; then
local send_wanIP=`getip wanipv4`;local send_hostIP=`getip hostipv4`
local send_content="${send_content}${markdown_splitline}${titlel4} ${titlebold}${titleblue}WAN 口信息${titleend}${titleboldend}${markdown_linefeed}${markdown_tab}接口ip:${send_wanIP}"
local send_content="${send_content}${markdown_linefeed}${markdown_tab}外网ip:${send_hostIP}"
local send_content="${send_content}${str_splitline}${str_title_start}${font_blue} WAN 口信息${font_end}${str_title_end}${str_linefeed}${str_tab}接口ip:${send_wanIP}"
local send_content="${send_content}${str_linefeed}${str_tab}外网ip:${send_hostIP}"
if [ ! -z "$pushbot_ipv6" ] && [ "$pushbot_ipv6" -ne "0" ]; then
local send_wanIPv6=`getip wanipv6`;local send_hostIPv6=`getip hostipv6`
local send_content="${send_content}${markdown_linefeed}${markdown_tab}ipv6 :${send_wanIPv6}"
local send_content="${send_content}${markdown_linefeed}${markdown_tab}外网v6:${send_hostIPv6}"
local send_content="${send_content}${str_linefeed}${str_tab}ipv6 :${send_wanIPv6}"
local send_content="${send_content}${str_linefeed}${str_tab}外网v6:${send_hostIPv6}"
fi
( ! echo "$send_wanIP"|grep -q -w ${send_hostIP} ) && local send_content="${send_content}${markdown_linefeed}${markdown_tab}外网 ip 与接口 ip 不一致,你的 ip 不是公网 ip"
( ! echo "$send_wanIP"|grep -q -w ${send_hostIP} ) && local send_content="${send_content}${str_linefeed}${str_tab}外网 ip 与接口 ip 不一致,你的 ip 不是公网 ip"
local interfaceuptime=`getinterfaceuptime`
[ ! -z "$interfaceuptime" ] && local wanstatustime=`getinterfaceuptime|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)}'` && unset run_days run_hour run_minute run_second
local send_content="${send_content}${markdown_linefeed}${markdown_tab}${wanstatustime}"
local send_content="${send_content}${str_linefeed}${str_tab}${wanstatustime}"
fi
if [ ! -z "$client_list" ] && [ "$client_list" -eq "1" ]; then
if [ -z "$1" ] && [ ! -z "$client_list" ] && [ "$client_list" -eq "1" ]; then
wait
local IPLIST=`cat ${dir}ipAddress 2>/dev/null|awk '{print $1}'`
[ -z "$IPLIST" ] && local send_content="${send_content}${markdown_splitline}${titlel4} ${titlebold}${titlered}当前无在线设备${titleend}${titleboldend}" || local send_content="${send_content}${markdown_splitline}${titlel4} ${titlebold}${titleblue}在线设备${titleend}${titleboldend}"
[ -f ${dir}ipAddress ] && local logrow=$(grep -c "" ${dir}ipAddress) || local logrow="0"
[ "$logrow" -eq "0" ] && local send_content="${send_content}${str_splitline}${str_title_start}${font_red} 当前无在线设备${font_end}${str_title_end}" || local send_content="${send_content}${str_splitline}${str_title_start}${font_blue} 现有在线设备 ${logrow} 台${font_end}${str_title_end}"
for ip in $IPLIST; do
local time_up=`cat ${dir}ipAddress|grep -w ${ip}|awk '{print $4}'|grep -v "^$"|sort -u|head -n1`
local time1=`date +%s`
@ -939,24 +1160,16 @@ function send(){
local ip_name=`getname ${ip} ${ip_mac}`
local ip_total=`usage get ${ip_mac}`;[ ! -z "$ip_total" ] && local ip_total="总计流量:${ip_total} "
local ip_name=`cut_str $ip_name 18`
local send_content="${send_content}${markdown_linefeed}${markdown_tab}${greenfont}【${ip_name}】${fontend} ${ip}${markdown_linefeed}${markdown_tab}${ip_total}在线 ${time1}"
local send_content="${send_content}${str_linefeed}${str_tab}${font_green2}【${ip_name}】${font_end2} ${ip}${str_linefeed}${str_tab}${ip_total}在线 ${time1}"
unset ip_total time_down time_up time1 ip_mac ip_name
done
fi
[ ! -z "$device_name" ] && local send_title="【$device_name】${send_title}"
local send_title=`echo "$send_title"|sed $'s/\ / /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'`
[ -z "$send_content" ] && local send_content="${markdown_splitline}${titlel4} ${titlered}我遇到了一个难题${titleend}${markdown_linefeed}${markdown_tab}定时发送选项错误,你没有选择需要发送的项目,该怎么办呢${markdown_splitline}"
local nowtime=`date "+%Y-%m-%d %H:%M:%S"`
pushbot_send="curl -s \"https://oapi.dingtalk.com/robot/send?access_token=${dd_webhook}\" -H 'Content-Type: application/json' -d '{\"msgtype\": \"markdown\",\"markdown\": {\"title\":\"${send_title}\",\"text\":\"${titlel4} <font color=#6A65FF>${send_title}</font>${markdown_linefeed}${nowtime}${markdown_linefeed}${send_content}\"}}'"
wechatent_send="curl -s \"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${we_webhook}\" -H 'Content-Type: application/json' -d '{\"msgtype\": \"markdown\",\"markdown\": {\"title\":\"${send_title}\",\"content\":\"${titlel4} <font color=#6A65FF>${send_title}</font>${markdown_linefeed}${nowtime}${markdown_linefeed}${send_content}\"}}'"
feishu_send="curl -X POST https://open.feishu.cn/open-apis/bot/v2/hook/${fs_webhook} -H 'Content-Type: application/json' -d '{\"msg_type\": \"post\",\"content\": {\"post\": {\"zh_cn\": {\"title\": \"${send_title}\",\"content\": [[{\"tag\": \"text\",\"text\": \"${nowtime}${markdown_linefeed}${send_content}\"}]]}}}}'"
[ "$send_disturb" -eq "0" ] && [ -z "$send_we" ] && eval $pushbot_send >/dev/null 2>&1
[ "$send_disturb" -eq "0" ] && [ ! -z "$send_we" ] && [ "$send_we" -eq "1" ] && eval $wechatent_send >/dev/null 2>&1
[ "$send_disturb" -eq "0" ] && [ ! -z "$send_we" ] && [ "$send_we" -eq "2" ] && curl -s "http://pushplus.plus/send?token=${pp_token}" -d "&channel=${pp_channel}&webhook=${pp_webhook}&topic=${pp_topic}&title=${send_title}&content=${nowtime}${markdown_linefeed}${send_content}&template=markdown" >/dev/null 2>&1
[ "$send_disturb" -eq "0" ] && [ ! -z "$send_we" ] && [ "$send_we" -eq "3" ] && eval $feishu_send >/dev/null 2>&1
[ "$send_disturb" -eq "0" ] && [ ! -z "$send_we" ] && [ "$send_we" -eq "4" ] && curl -s "${bark_srv}/${bark_token}/${send_title}/${nowtime}${markdown_linefeed}${send_content}?isArchive=1" >/dev/null 2>&1
[ -z "$send_content" ] && local send_content="${str_splitline}${str_title_start} 我遇到了一个难题${str_title_end}${str_linefeed}${str_tab}定时发送选项错误,你没有选择需要发送的项目,该怎么办呢${str_splitline}"
[ "$send_disturb" -eq "0" ] && diy_send "${send_title}" "${send_content}" "${jsonpath}" >/dev/null 2>&1
[ $? -eq 1 ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】定时推送失败,请检查网络或设置信息" >> ${logfile} || echo "`date "+%Y-%m-%d %H:%M:%S"` ${disturb_text}定时推送任务完成" >> ${logfile}
deltemp
echo "`date "+%Y-%m-%d %H:%M:%S"` ${disturb_text}定时推送任务完成" >> ${logfile}
}
# 初始化
@ -979,6 +1192,7 @@ if [ "$1" ] ;then
[ $1 == "send" ] && send
[ $1 == "soc" ] && echo `soc_temp` > ${dir}soc_tmp
[ $1 == "client" ] && get_client
[ $1 == "test" ] && send test
exit
fi
@ -995,11 +1209,19 @@ while [ "$pushbot_enable" -eq "1" ]; do
pushbot_disturb;disturb=$?
# 外网IP变化检测
if [ ! -z "$pushbot_ipv4" ] && [ ! -z "$pushbot_ipv6" ] && [ "$pushbot_ipv4" -ne "0" ] || [ "$pushbot_ipv6" -ne "0" ]; then
[ -f ${dir}ipAddress ] && ipAddress_logrow=$(grep -c "" ${dir}ipAddress) || ipAddress_logrow="0";
if [ $ipAddress_logrow -ne "0" ]; then
online_list=`cat ${dir}ipAddress|awk '{print $2}'|grep -v "^$"|sort -u`
for online_mac in $online_list; do
[ ! -z "$online_mac" ] && mac_online_status="`echo "$mark_mac_list"|grep -i $online_mac|grep -v "^$"|sort -u|head -n1`${mac_online_status}"
done
fi
if [ "$pushbot_ipv4" -ne "0" ] || [ "$pushbot_ipv6" -ne "0" ]; then
rand_geturl
ip_changes
fi
# 设备列表
if [ ! -f "${dir}send_enable.lock" ]; then
[ ! -z "$title" ] && echo "$title" > ${dir}title
@ -1008,36 +1230,32 @@ while [ "$pushbot_enable" -eq "1" ]; do
[ -f "${dir}title" ] && title=`cat ${dir}title` && rm -f ${dir}title >/dev/null 2>&1
[ -f "${dir}content" ] && content=`cat ${dir}content` && rm -f ${dir}content >/dev/null 2>&1
fi
# 离线缓存区推送
[ ! -f "${dir}send_enable.lock" ] && down_send
# 当前设备列表
[ ! -z "$content" ] && [ ! -f "${dir}send_enable.lock" ] && [ -z "$content_current_device" ] || [ "$content_current_device" -eq "0" ] && current_device
[ ! -z "$content" ] && [ ! -f "${dir}send_enable.lock" ] && current_device
# 无人值守任务
[ ! -f "${dir}send_enable.lock" ] && unattended
# CPU 检测
[ ! -f "${dir}send_enable.lock" ] && cpu_load
# 异常流量检测
[ ! -f "${dir}send_enable.lock" ] && get_client_usage
# 登录提醒通知
[ ! -f "${dir}send_enable.lock" ] && login_send
# 通知
if [ ! -f "${dir}send_enable.lock" ] && [ ! -z "$title" ] && [ ! -z "$content" ]; then
[ -z "$content_nowtime" ] || [ "$content_nowtime" -eq "0" ] && nowtime=`date "+%Y-%m-%d %H:%M:%S"`
[ ! -z "$device_name" ] && title="【$device_name】$title"
title=`echo "$title"|sed $'s/\ / /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'`
[ ! -z "$content_content" ] && [ "$content_content" -eq "1" ] && content=""
pushbot_send="curl -s \"https://oapi.dingtalk.com/robot/send?access_token=${dd_webhook}\" -H 'Content-Type: application/json' -d '{\"msgtype\": \"markdown\",\"markdown\": {\"title\":\"${title}\",\"text\":\"${titlel4} ${titlebold}<font color=#6A65FF>${title}</font>${titleboldend}${markdown_linefeed}${nowtime}${markdown_linefeed}${content}${markdown_linefeed}${titlebold}<font color=#6A65FF>${title}</font>${titleboldend}\"}}'"
wechatent_send="curl -s \"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${we_webhook}\" -H 'Content-Type: application/json' -d '{\"msgtype\": \"markdown\",\"markdown\": {\"title\":\"${title}\",\"content\":\"${titlel4} ${titlebold}<font color=#6A65FF>${title}</font>${titleboldend}${markdown_linefeed}${nowtime}${markdown_linefeed}${content}${markdown_linefeed}${titlebold}<font color=#6A65FF>${title}</font>${titleboldend}\"}}'"
feishu_send="curl -X POST https://open.feishu.cn/open-apis/bot/v2/hook/${fs_webhook} -H 'Content-Type: application/json' -d '{\"msg_type\": \"post\",\"content\": {\"post\": {\"zh_cn\": {\"title\": \"${title}\",\"content\": [[{\"tag\": \"text\",\"text\": \"${nowtime}${markdown_linefeed}${content}\"}]]}}}}'"
[ "$disturb" -eq "0" ] && [ -z "$send_we" ] && eval $pushbot_send >/dev/null 2>&1
[ "$disturb" -eq "0" ] && [ ! -z "$send_we" ] && [ "$send_we" -eq "1" ] && eval $wechatent_send >/dev/null 2>&1
[ "$disturb" -eq "0" ] && [ ! -z "$send_we" ] && [ "$send_we" -eq "2" ] && curl -s "http://pushplus.plus/send?token=${pp_token}" -d "&channel=${pp_channel}&webhook=${pp_webhook}&topic=${pp_topic}&title=${title}&content=${nowtime}${markdown_linefeed}${content}&template=markdown" >/dev/null 2>&1
[ "$disturb" -eq "0" ] && [ ! -z "$send_we" ] && [ "$send_we" -eq "3" ] && eval $feishu_send 2>&1
[ "$disturb" -eq "0" ] && [ ! -z "$send_we" ] && [ "$send_we" -eq "4" ] && curl -s "${bark_srv}/${bark_token}/${title}/${nowtime}${markdown_linefeed}${content}?isArchive=1" >/dev/null 2>&1
fi
( echo "$lite_enable"|grep -q "content" ) && content="$title"
[ "$disturb" -eq "0" ] && diy_send "${title}" "${content}" "${jsonpath}" >/dev/null 2>&1
[ $? -eq 1 ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】推送失败,请检查网络或设置信息 " >> ${logfile}
fi
while [ -f "${dir}send_enable.lock" ]; do
sleep $sleeptime