diff --git a/luci-app-ssr-plus/po/zh-cn/ssr-plus.po b/luci-app-ssr-plus/po/zh-cn/ssr-plus.po index 1e33f7a7a..0b77345ea 100644 --- a/luci-app-ssr-plus/po/zh-cn/ssr-plus.po +++ b/luci-app-ssr-plus/po/zh-cn/ssr-plus.po @@ -543,6 +543,9 @@ msgstr "分流模式下的 DNS 查询模式" msgid "Anti-pollution DNS Server For Shunt Mode" msgstr "分流模式下的访问国外域名 DNS 服务器" +msgid "Custom DNS Server for mosdns" +msgstr "MOSDNS 自定义 DNS 服务器" + msgid "Disable IPv6 In MOSDNS Query Mode (Shunt Mode)" msgstr "禁止 MOSDNS 返回 IPv6 记录 (分流模式)" diff --git a/luci-app-wechatpush/README.md b/luci-app-wechatpush/README.md index 5e14f2f4f..1de1c2f59 100644 --- a/luci-app-wechatpush/README.md +++ b/luci-app-wechatpush/README.md @@ -1,92 +1,96 @@ -## 简介 - -[![Lastest Release](https://img.shields.io/github/release/tty228/luci-app-wechatpush.svg?style=flat)](https://github.com/tty228/luci-app-wechatpush/releases) -[![GitHub All Releases](https://img.shields.io/github/downloads/tty228/luci-app-wechatpush/total)](https://github.com/tty228/luci-app-wechatpush/releases) - -[中文文档](README.md) | [English](README_en.md) - -这是一款用于 OpenWRT 路由器上进行 微信/Telegram 推送的插件 - -推送服务支持列表: - -| 推送应用 | 方式 | 接口说明 | -| :-------- | :----- | :----- | -| 微信 | Server酱 | https://sct.ftqq.com/ -| 微信 | 推送加 | http://www.pushplus.plus/ -| 微信 | WxPusher | https://wxpusher.zjiecode.com/docs -| 企业微信 | 应用推送 | https://work.weixin.qq.com/api/doc/90000/90135/90248 -| Telegram | bot | https://t.me/BotFather - -精力有限,如需要钉钉推送、飞书推送、Bark 推送等请尝试另一个分支 https://github.com/zzsj0928/luci-app-pushbot ,或使用自定义 API 设置 - -因插件一开始只支持 Server酱,故此插件命名为 luci-app-serverchan,但后续已经越来越臃肿,想改很久了,趁这次升级 js, 插件更名为 luci-app-wechatpush - -v3.0.0 安装时会自动从 luci-app-serverchan 移植配置信息,并删除原插件,如有缺漏,请在 /etc/config/serverchan.bak 查看,安装后可能需刷新浏览器页面,否则 luci 页面入口不会更换为新插件 URL(此功能择期移除) - -v2.06.2 之后的版本不再支持 LuCI 18.06,如需编译,请使用 openwrt-18.06 分支,拉取源码时请使用 `git clone -b openwrt-18.06 https://github.com/tty228/luci-app-wechatpush.git` 命令 - - -## 主要功能 - -- [x] 路由 IP、IPv6 变动推送 -- [x] 设备 上线、离线 推送 -- [x] 设备在线列表及流量使用情况 -- [x] CPU 负载、温度监视、PVE 宿主机温度监控 -- [x] 路由运行状态定时推送 -- [x] 路由 Web、SSH 登录提示,自动拉黑、端口敲门 -- [x] 无人值守任务 - - -## 说明 - -**关于安装:** - -插件依赖 iputils-arping + curl + jq + bash,对于内存有限的路由器,请酌情安装,**在安装之前,请先运行 `opkg update` 命令,以便在安装过程中安装依赖。** - -基于 X86 OpenWrt v23.05.0 制作,不同系统不同设备,可能会遇到各种问题,**如获取到错误的温度信息、页面显示错误、报错等,自行适配** - -**关于主机名:** - -对于设备未宣告主机名、光猫拨号上网、OpenWrt 作为旁路网关等各类情况导致的获取主机名失败,可以通过以下方式设置主机名 - -- 使用设备名备注 -- 在高级设置处配置从光猫获取 -- 开启 MAC 设备数据库 - - -**关于设备在线状态:** - -默认使用 ping/arping 来主动探测设备在线状态,以对抗 Wi-Fi 休眠机制,主动探测较为耗时但可以获得较为精准的设备在线状态 - -- 如遇设备休眠频繁,请在高级设置处自行调整超时设置 -- 如果不需要太过精准的设备在线信息,只需要其余功能,可以在高级设置中关闭主动探测 - - -**关于流量统计信息:** - -流量统计功能依赖 wrtbwmon ,需自行选装或编译,**该插件与 Routing/NAT 、Flow Offloading 、代理上网等插件冲突,开启后将会无法获取流量,请自行选择** - - -**关于 bug 提交:** - -提交 bug 时请尽量带上以下信息 - -- 设备信息及插件版本号 -- 执行 `/usr/share/wechatpush/wechatpush` 后的提示信息 -- 报错后的日志信息、`/tmp/wechatpush/` 目录下的文件信息 -- `bash -x /usr/share/wechatpush/wechatpush t1` 的详细运行信息 - - -## 下载 - -| 支持的 OpenWrt 版本 | 下载地址 | -| :-------- | :----- | -| openwrt-19.07.0 ... latest | [![Lastest Release](https://img.shields.io/github/release/tty228/luci-app-wechatpush.svg?style=flat)](https://github.com/tty228/luci-app-wechatpush/releases) -| openwrt-18.06 | [![Release v2.06.2](https://img.shields.io/badge/release-v2.06.2-lightgrey.svg)](https://github.com/tty228/luci-app-wechatpush/releases/tag/v2.06.2) - - -## 捐赠 - -如果你觉得此项目对你有帮助,请捐助我们,使项目能持续发展和更加完善。 - -![image](https://github.com/tty228/Python-100-Days/blob/master/res/WX.jpg) +## 简介 + +[![Lastest Release](https://img.shields.io/github/release/tty228/luci-app-wechatpush.svg?style=flat)](https://github.com/tty228/luci-app-wechatpush/releases) +[![GitHub All Releases](https://img.shields.io/github/downloads/tty228/luci-app-wechatpush/total)](https://github.com/tty228/luci-app-wechatpush/releases) + +[中文文档](README.md) | [English](README_en.md) + +这是一款用于 OpenWRT 路由器上进行 微信/Telegram 推送的插件 + +推送服务支持列表: + +| 推送应用 | 方式 | 接口说明 | +| :-------- | :----- | :----- | +| 微信 | Server酱 | https://sct.ftqq.com/ +| 微信 | 推送加 | http://www.pushplus.plus/ +| 微信 | WxPusher | https://wxpusher.zjiecode.com/docs +| 企业微信 | 应用推送 | https://work.weixin.qq.com/api/doc/90000/90135/90248 +| Telegram | bot | https://t.me/BotFather + +精力有限,如需要钉钉推送、飞书推送、Bark 推送等请尝试另一个分支 https://github.com/zzsj0928/luci-app-pushbot ,或使用自定义 API 设置 + +因插件一开始只支持 Server酱,故此插件命名为 luci-app-serverchan,但后续已经越来越臃肿,想改很久了,趁这次升级 js, 插件更名为 luci-app-wechatpush + +v3.0.0 安装时会自动从 luci-app-serverchan 移植配置信息,并删除原插件,如有缺漏,请在 /etc/config/serverchan.bak 查看,安装后可能需刷新浏览器页面,否则 luci 页面入口不会更换为新插件 URL(此功能择期移除) + +v2.06.2 之后的版本不再支持 LuCI 18.06,如需编译,请使用 openwrt-18.06 分支,拉取源码时请使用 `git clone -b openwrt-18.06 https://github.com/tty228/luci-app-wechatpush.git` 命令 + + +## 主要功能 + +- [x] 路由 IP、IPv6 变动推送 +- [x] 设备 上线、离线 推送 +- [x] 设备在线列表及流量使用情况 +- [x] CPU 负载、温度监视、PVE 宿主机温度监控 +- [x] 路由运行状态定时推送 +- [x] 路由 Web、SSH 登录提示,自动拉黑、端口敲门 +- [x] 无人值守任务 + + +## 说明 + +**关于安装:** + +插件依赖 iputils-arping + curl + jq + bash,对于内存有限的路由器,请酌情安装,**在安装之前,请先运行 `opkg update` 命令,以便在安装过程中安装依赖。** + +基于 X86 OpenWrt v23.05.0 制作,不同系统不同设备,可能会遇到各种问题,**如获取到错误的温度信息、页面显示错误、报错等,自行适配** + +**关于主机名:** + +对于设备未宣告主机名、光猫拨号上网、OpenWrt 作为旁路网关等各类情况导致的获取主机名失败,可以通过以下方式设置主机名 + +- 使用设备名备注 +- 在高级设置处配置从光猫获取 +- 开启 MAC 设备数据库 + + +**关于设备在线状态:** + +默认使用 ping/arping 来主动探测设备在线状态,以对抗 Wi-Fi 休眠机制,主动探测较为耗时但可以获得较为精准的设备在线状态 + +- 如遇设备休眠频繁,请在高级设置处自行调整超时设置 +- 如果不需要太过精准的设备在线信息,只需要其余功能,可以在高级设置中关闭主动探测 + + +**关于流量统计信息:** + +流量统计功能依赖 wrtbwmon ,需自行选装或编译,**该插件与 Routing/NAT 、Flow Offloading 、代理上网等插件冲突,开启后将会无法获取流量,请自行选择** + +**关于硬盘信息:** + +当 OpenWrt 系统或远程主机(PVE)未安装 lsblk 时,硬盘总容量信息可能与实际不一致 +当 OpenWrt 系统或远程主机(PVE)未安装 smartctl 时,硬盘温度、通电时间、健康度等信息不可用 + +**关于 bug 提交:** + +提交 bug 时请尽量带上以下信息 + +- 设备信息及插件版本号 +- 执行 `/usr/share/wechatpush/wechatpush` 后的提示信息 +- 报错后的日志信息、`/tmp/wechatpush/` 目录下的文件信息 +- `bash -x /usr/share/wechatpush/wechatpush t1` 的详细运行信息 + + +## 下载 + +| 支持的 OpenWrt 版本 | 下载地址 | +| :-------- | :----- | +| openwrt-19.07.0 ... latest | [![Lastest Release](https://img.shields.io/github/release/tty228/luci-app-wechatpush.svg?style=flat)](https://github.com/tty228/luci-app-wechatpush/releases) +| openwrt-18.06 | [![Release v2.06.2](https://img.shields.io/badge/release-v2.06.2-lightgrey.svg)](https://github.com/tty228/luci-app-wechatpush/releases/tag/v2.06.2) + + +## 捐赠 + +如果你觉得此项目对你有帮助,请捐助我们,使项目能持续发展和更加完善。 + +![image](https://github.com/tty228/Python-100-Days/blob/master/res/WX.jpg) diff --git a/luci-app-wechatpush/README_en.md b/luci-app-wechatpush/README_en.md index e84d82570..5a5814018 100644 --- a/luci-app-wechatpush/README_en.md +++ b/luci-app-wechatpush/README_en.md @@ -1,81 +1,86 @@ -# Introduction - -[![Lastest Release](https://img.shields.io/github/release/tty228/luci-app-wechatpush.svg?style=flat)](https://github.com/tty228/luci-app-wechatpush/releases) -[![GitHub All Releases](https://img.shields.io/github/downloads/tty228/luci-app-wechatpush/total)](https://github.com/tty228/luci-app-wechatpush/releases) - -[中文文档](README.md) | [English](README_en.md) - -A plugin for OpenWRT routers to send various information notifications to a mobile phone via WeChat or Telegram. -Supported services: -| Push application | Method | description | -| :-------- | :----- | :----- | -| WeChat | Server Chan | https://sct.ftqq.com/ -| WeChat | PushPlus | http://www.pushplus.plus/ -| WeChat | WxPusher | https://wxpusher.zjiecode.com/docs -| WeChat for Enterprise | Application Push | https://work.weixin.qq.com/api/doc/90000/90135/90248 -| Telegram | bot | https://t.me/BotFather - -Limited resources are available. If you need services such as DingTalk push, Feishu push, Bark push, etc., please try another branch at https://github.com/zzsj0928/luci-app-pushbot, or use custom API settings. - -## Main Features - -- [x] Push notifications for changes in router IP and IPv6. -- [x] Push notifications for device online/offline status. -- [x] Device online list and traffic usage. -- [x] CPU load and temperature monitoring, PVE host temperature monitoring. -- [x] Periodic push notifications for router status. -- [x] Web and SSH login prompts for the router, automatic blacklist and port knocking. -- [x] Unattended tasks. - -## Instructions - -**Regarding Installation:** - -The plugin requires dependencies on iputils-arping + curl + jq + bash. For routers with limited memory, please consider the installation carefully. **Before installing, please run the opkg update command to install dependencies during the installation process.** - -Developed based on X86 OpenWrt v23.05.0, different systems and devices may encounter various issues. **If you encounter errors in temperature information retrieval, display errors, or other issues, please adapt accordingly.** - -**Regarding Hostnames:** - -For devices that do not declare hostnames, devices connected via optical modem dial-up, OpenWrt used as a bypass gateway, and other scenarios where hostname retrieval fails, you can set the hostname using the following methods: - -- Use device name remarks. -- Configure to obtain the hostname from the optical modem in advanced settings. -- Enable MAC device database. - - -**Regarding Device Online Status:** - -By default, ping/arping is used to actively detect device online status to counter Wi-Fi sleep mechanism. Active detection takes more time but provides more accurate device online status. - -- If devices frequently go into sleep mode, please adjust the timeout settings in advanced settings. -- If you don't require highly precise device online information and only need other features, you can disable active detection in advanced settings. - - -**Regarding Traffic Statistics:** - -Traffic statistics functionality depends on `wrtbwmon`. Please install or compile it yourself. **Enabling this plugin will conflict with Routing/NAT, Flow Offloading, proxy internet access, and other plugins, resulting in the inability to obtain traffic statistics. Please choose accordingly.** - - -**Regarding Bug Submissions:** - -When submitting a bug, please provide the following information if possible: - -- Device information and plugin version number. -- Prompt information after executing `/usr/share/wechatpush/wechatpush`. -- Log information and file information in the `/tmp/wechatpush/` directory after encountering an error. -- Detailed execution information of `bash -x /usr/share/wechatpush/wechatpush t1`. - -## DownLoad - -| Supported OpenWrt Versions | Download Link | -| :-------- | :----- | -| openwrt-19.07.0 ... latest | [![Lastest Release](https://img.shields.io/github/release/tty228/luci-app-wechatpush.svg?style=flat)](https://github.com/tty228/luci-app-wechatpush/releases) -| openwrt-18.06 | [![Release v2.06.2](https://img.shields.io/badge/release-v2.06.2-lightgrey.svg)](https://github.com/tty228/luci-app-wechatpush/releases/tag/v2.06.2) - -## Donate - -If you feel that this project is helpful to you, please donate to us so that the project can continue to develop and be more perfect. - -![image](https://github.com/tty228/Python-100-Days/blob/master/res/WX.jpg) - +# Introduction + +[![Lastest Release](https://img.shields.io/github/release/tty228/luci-app-wechatpush.svg?style=flat)](https://github.com/tty228/luci-app-wechatpush/releases) +[![GitHub All Releases](https://img.shields.io/github/downloads/tty228/luci-app-wechatpush/total)](https://github.com/tty228/luci-app-wechatpush/releases) + +[中文文档](README.md) | [English](README_en.md) + +A plugin for OpenWRT routers to send various information notifications to a mobile phone via WeChat or Telegram. +Supported services: +| Push application | Method | description | +| :-------- | :----- | :----- | +| WeChat | Server Chan | https://sct.ftqq.com/ +| WeChat | PushPlus | http://www.pushplus.plus/ +| WeChat | WxPusher | https://wxpusher.zjiecode.com/docs +| WeChat for Enterprise | Application Push | https://work.weixin.qq.com/api/doc/90000/90135/90248 +| Telegram | bot | https://t.me/BotFather + +Limited resources are available. If you need services such as DingTalk push, Feishu push, Bark push, etc., please try another branch at https://github.com/zzsj0928/luci-app-pushbot, or use custom API settings. + +## Main Features + +- [x] Push notifications for changes in router IP and IPv6. +- [x] Push notifications for device online/offline status. +- [x] Device online list and traffic usage. +- [x] CPU load and temperature monitoring, PVE host temperature monitoring. +- [x] Periodic push notifications for router status. +- [x] Web and SSH login prompts for the router, automatic blacklist and port knocking. +- [x] Unattended tasks. + +## Instructions + +**Regarding Installation:** + +The plugin requires dependencies on iputils-arping + curl + jq + bash. For routers with limited memory, please consider the installation carefully. **Before installing, please run the opkg update command to install dependencies during the installation process.** + +Developed based on X86 OpenWrt v23.05.0, different systems and devices may encounter various issues. **If you encounter errors in temperature information retrieval, display errors, or other issues, please adapt accordingly.** + +**Regarding Hostnames:** + +For devices that do not declare hostnames, devices connected via optical modem dial-up, OpenWrt used as a bypass gateway, and other scenarios where hostname retrieval fails, you can set the hostname using the following methods: + +- Use device name remarks. +- Configure to obtain the hostname from the optical modem in advanced settings. +- Enable MAC device database. + + +**Regarding Device Online Status:** + +By default, ping/arping is used to actively detect device online status to counter Wi-Fi sleep mechanism. Active detection takes more time but provides more accurate device online status. + +- If devices frequently go into sleep mode, please adjust the timeout settings in advanced settings. +- If you don't require highly precise device online information and only need other features, you can disable active detection in advanced settings. + + +**Regarding Traffic Statistics:** + +Traffic statistics functionality depends on `wrtbwmon`. Please install or compile it yourself. **Enabling this plugin will conflict with Routing/NAT, Flow Offloading, proxy internet access, and other plugins, resulting in the inability to obtain traffic statistics. Please choose accordingly.** + +**About Hard Drive Information:** + +When the OpenWrt system or remote host (PVE) does not have lsblk installed, the total hard drive capacity information may be inconsistent with the actual capacity. + +When the OpenWrt system or remote host (PVE) does not have smartctl installed, information such as hard drive temperature, uptime, and health status will not be available. + +**Regarding Bug Submissions:** + +When submitting a bug, please provide the following information if possible: + +- Device information and plugin version number. +- Prompt information after executing `/usr/share/wechatpush/wechatpush`. +- Log information and file information in the `/tmp/wechatpush/` directory after encountering an error. +- Detailed execution information of `bash -x /usr/share/wechatpush/wechatpush t1`. + +## DownLoad + +| Supported OpenWrt Versions | Download Link | +| :-------- | :----- | +| openwrt-19.07.0 ... latest | [![Lastest Release](https://img.shields.io/github/release/tty228/luci-app-wechatpush.svg?style=flat)](https://github.com/tty228/luci-app-wechatpush/releases) +| openwrt-18.06 | [![Release v2.06.2](https://img.shields.io/badge/release-v2.06.2-lightgrey.svg)](https://github.com/tty228/luci-app-wechatpush/releases/tag/v2.06.2) + +## Donate + +If you feel that this project is helpful to you, please donate to us so that the project can continue to develop and be more perfect. + +![image](https://github.com/tty228/Python-100-Days/blob/master/res/WX.jpg) + diff --git a/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/advanced.js b/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/advanced.js index 5f2784697..0d403ad31 100644 --- a/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/advanced.js +++ b/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/advanced.js @@ -78,7 +78,7 @@ return view.extend({ var _this = this; return fs.exec(programPath, ['soc']).then(function (res) { if (!res.stdout) { - throw new Error(_('Returned temperature value is empty')); + throw new Error(_('Returned value is empty')); } _this.description = res.stdout.trim(); return _this.map.reset(); diff --git a/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/config.js b/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/config.js index e8c3d009f..9e03382ae 100644 --- a/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/config.js +++ b/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/config.js @@ -303,6 +303,22 @@ return view.extend({ o.description = _('Please enter the device MAC and device alias separated by a space, such as:
XX:XX:XX:XX:XX:XX My Phone
192.168.1.2 My PC
Please use the 「Save」 button in the text box.'); // 推送内容 + o = s.taboption('content', form.Button, '_getip', _('Test IP acquisition command'), _('You may need to save the configuration before sending.')); + o.inputstyle = 'action'; + o.onclick = function () { + var _this = this; + return fs.exec(programPath, ['getip']).then(function (res) { + if (!res.stdout) { + throw new Error(_('Returned value is empty')); + } + _this.description = res.stdout.trim(); + return _this.map.reset(); + }).catch(function (err) { + _this.description = _('Fetch failed:') + err.message; + return _this.map.reset(); + }); + }; + o = s.taboption('content', cbiRichListValue, 'get_ipv4_mode', _('IPv4 Dynamic Notification')); o.value('', _('Close'), _(' ')); diff --git a/luci-app-wechatpush/po/zh_Hans/wechatpush.po b/luci-app-wechatpush/po/zh_Hans/wechatpush.po index cb27ccf23..7c43f6852 100644 --- a/luci-app-wechatpush/po/zh_Hans/wechatpush.po +++ b/luci-app-wechatpush/po/zh_Hans/wechatpush.po @@ -275,6 +275,10 @@ msgstr "设备别名" msgid "Please enter the device MAC and device alias separated by a space, such as:
XX:XX:XX:XX:XX:XX My Phone
192.168.1.2 My PC
Please use the 「Save」 button in the text box." msgstr "请输入设备 MAC 和设备别名,用空格隔开,例如:
XX:XX:XX:XX:XX:XX 我的手机
192.168.1.2 我的电脑
文本框请使用「保存」按钮" +#: applications/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/config.js:306 +msgid "Test IP acquisition command" +msgstr "测试 IP 获取命令" + #: applications/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/config.js:306 msgid "IPv4 Dynamic Notification" msgstr "IPv4 变动通知" @@ -806,8 +810,9 @@ msgid "Test temperature command" msgstr "测试温度命令" #: applications/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/advanced.js:82 -msgid "Returned temperature value is empty" -msgstr "返回的温度值为空" +#: applications/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/config.js:312 +msgid "Returned value is empty" +msgstr "返回值为空" #: applications/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/advanced.js:87 msgid "Fetch failed:" diff --git a/luci-app-wechatpush/root/usr/share/wechatpush/wechatpush b/luci-app-wechatpush/root/usr/share/wechatpush/wechatpush index 1479a46c6..c43e9eec7 100755 --- a/luci-app-wechatpush/root/usr/share/wechatpush/wechatpush +++ b/luci-app-wechatpush/root/usr/share/wechatpush/wechatpush @@ -534,7 +534,7 @@ function cut_str { [ ! "$2" ] && return if [ $(length_str "$1") -le "$2" ]; then - echo "$1" + echo -n "$1" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' return fi @@ -551,7 +551,7 @@ function cut_str { done local text=$(echo -n "$1" | cut -d ' ' -f $max_column) if [ $(length_str "$text") -le "$2" ]; then - echo "$text" + echo "$text" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' return fi fi @@ -565,7 +565,7 @@ function cut_str { done temp_length=$(expr $temp_length - 1) - echo "$(echo -n "$1" | cut -c -$temp_length)".. + echo "$(echo -n "$1" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | cut -c -$temp_length).." } @@ -838,6 +838,11 @@ function ip_changes(){ [ "$get_ipv6_mode" -eq "1" ] && local IPv6=`getip wanipv6` && local IPv6_URL="网络接口" [ "$get_ipv6_mode" -eq "2" ] && local IPv6=`getip hostipv6` && local IPv6_URL=`echo ${IPv6}|jq -r '.URL'` && local IPv6=`echo ${IPv6}|jq -r '.IP'` + if [ "$1" ] && [ $1 == "getip" ]; then + echo "IPv4:$IPv4
地址:$(get_ip_attribution $IPv4)
接口:$IPv4_URL
IPv6:$IPv6
地址:$(get_ip_attribution $IPv6)
接口:$IPv6_URL" + return + fi + # 存在临时文件 if [ -f ${dir}ip ]; then local last_IPv4=$(cat "${dir}ip"|grep IPv4|awk '{print $2}'|grep -v "^$"|sort -u|head -n1) @@ -1112,7 +1117,9 @@ function get_disk() { pve_disk_names=() # 查询本地硬盘名 - local_disk_names=($(lsblk | awk '$NF=="disk" {print $1}' | sort -u)) + local_disk_names=($(lsblk 2>/dev/null | awk '$NF=="disk" {print $1}' | sort -u)) + # 如未安装 lsblk,查找以 /dev/ 开头,但挂载点不是根目录 / 的设备,然后提取硬盘的名称(准确性较低) + [ -z "$local_disk_names" ] && local_disk_names=($(df -h 2>/dev/null | awk '$1 ~ /^\/dev/ {if ($NF ~ /^\/[a-zA-Z0-9]/) { sub("/dev/", "", $1); sub(/[0-9]+$/, "", $1); print $1 }}')) local_disk_tags=($(for _ in "${local_disk_names[@]}"; do echo "local"; done)) # 查询远程硬盘名 @@ -1140,8 +1147,8 @@ function get_disk() { file_path="${dir}disk_info/${tmp_name}${disk_type}" # 如果不能获取值,使用分区名重试(因为不清楚是 OpenWrt 的原因还是 smartctl 版本的原因,使用出错重试的方式) - eval ${tmp_command} smartctl -i -n standby "/dev/${tmp_name}" | grep -qE "$error_pattern" && { - tmp_name=$(df -h | awk "/^\\/dev\\/${tmp_name}/ {print \$1}" | awk -F '/' '{print $NF}' | head -n1) + eval ${tmp_command} smartctl -i -n standby "/dev/${tmp_name}" 2>/dev/null | grep -qE "$error_pattern" && { + tmp_name=$(eval ${tmp_command} df -h | awk "/^\\/dev\\/${tmp_name}/ {print \$1}" | awk -F '/' '{print $NF}' | head -n1) [ -z "$tmp_name" ] && continue } @@ -1149,18 +1156,18 @@ function get_disk() { last_disk_time=$(date -r "${file_path}" +%s 2>/dev/null) || last_disk_time=0 if [ $(( $(date +%s) - $last_disk_time )) -gt 86000 ]; then - disk_info=$(eval ${tmp_command} smartctl -i -n standby "/dev/${tmp_name}") + disk_info=$(eval ${tmp_command} smartctl -i -n standby "/dev/${tmp_name}" 2>/dev/null) echo "$disk_info" | grep -qE "$error_pattern" && { continue } || \ echo "$disk_info" | grep -q "STANDBY" && { echo "$disk_info" > "${file_path}" } || \ - eval ${tmp_command} smartctl -a -j /dev/${tmp_name} > ${file_path} + eval ${tmp_command} smartctl -a -j /dev/${tmp_name} 2>/dev/null> ${file_path} fi # 硬盘状态 - if [ -f "${file_path}" ] && ( ! cat "${file_path}" | grep -q -v "STANDBY" ); then + if [ -f "${file_path}" ] && [ -s "${file_path}" ] && ( ! cat "${file_path}" | grep -q -v "STANDBY" ); then disk_name=$(awk '/Device Model/{print $NF}' "$file_path") [[ -n $disk_name && $disk_name != null && $disk_name != 0 ]] && { disk_name=$(cut_str "$disk_name" "20") @@ -1170,9 +1177,12 @@ function get_disk() { elif [ -f "${file_path}" ]; then # 硬盘名称 disk_name=$(jq -r .model_name ${file_path}) + [ -z "$disk_name" ] && disk_name=$(cat /sys/block/"${all_disk_names[i]}"/device/model) [[ -n $disk_name && $disk_name != null && $disk_name != 0 ]] && { disk_name=$(cut_str "$disk_name" "20") - disk_name="${disk_name}_$(eval ${tmp_command} lsblk -o NAME,SIZE | awk "/^${all_disk_names[i]}/ {print \$NF}")" + disk_size=$(eval ${tmp_command} lsblk -o NAME,SIZE 2>/dev/null | awk "/^${all_disk_names[i]}/ {print \$NF}") + [ -z "$disk_size" ] && disk_size=$(eval ${tmp_command} df -h 2>/dev/null | awk -v tmp_disk_name="${all_disk_names[i]}" '$1 ~ "^/dev/"tmp_disk_name {print $2}') + disk_name="${disk_name}_${disk_size}" } printf "${str_linefeed}${str_title_start} 硬盘名称:${disk_name}${disk_type}${str_title_end}" >> "$output_dir/get_disk" # 硬盘温度 @@ -1182,7 +1192,8 @@ function get_disk() { disk_time=$(jq -r .power_on_time.hours ${file_path}) [[ -n $disk_time && $disk_time != null ]] && printf "${str_linefeed}${str_tab}通电时间:${disk_time}h" >> "$output_dir/get_disk" # 空间使用 - disk_use=$(eval ${tmp_command} lsblk -o NAME,FSUSE%,TYPE | awk -v part_name="${all_disk_names[i]}" '$NF == "part" && $1 ~ part_name && NF > 2 {sub(".*" part_name, part_name, $1); printf "%s: %s ", $1, $2} END {print ""}') + disk_use=$(eval ${tmp_command} lsblk -o NAME,FSUSE%,TYPE 2>/dev/null | awk -v part_name="${all_disk_names[i]}" '$NF == "part" && $1 ~ part_name && NF > 2 {sub(".*" part_name, part_name, $1); printf "%s: %s ", $1, $2} END {print ""}') + [ -z "$disk_use" ] && disk_use=$(eval ${tmp_command} df -h 2>/dev/null | awk -v part_name="${all_disk_names[i]}" '$1 ~ "^/dev/"part_name && NF > 1 {sub("/dev/", "", $1); sub(/[0-9]+$/, "", $1); printf "%s: %s ", $1, $5} END {print ""}') [ -n "$disk_use" ] && [ -n "${disk_use// }" ] && echo -e -n "${str_linefeed}${str_tab}空间使用:${disk_use}" >> "$output_dir/get_disk" # 寿命使用 disk_health=$(jq -r .nvme_smart_health_information_log.percentage_used ${file_path}) @@ -1211,10 +1222,10 @@ function get_disk() { # 查询 IP 归属地 function get_ip_attribution(){ ip="$1" - [ -f ${dir}ipAddress ] && ( cat ${dir}ipAddress|grep -q -w -i "$ip" ) && echo "本地网络" && return + [ -f ${dir}ipAddress ] && ( cat ${dir}ipAddress|grep -q -w -i "$ip" ) && echo "本地局域网" && return ip_attribution_urls=$(cat /usr/share/wechatpush/api/ip_attribution.list) while IFS= read -r ip_attribution_command; do - login_ip_attribution=$(eval "$ip_attribution_command" 2>/dev/null) + local login_ip_attribution=$(eval "$ip_attribution_command" 2>/dev/null) [ "$login_ip_attribution" == "null" ] && unset login_ip_attribution [ -n "$login_ip_attribution" ] && break done <<< "$ip_attribution_urls" @@ -1249,7 +1260,7 @@ function login_send(){ fi [ -n "$log_only" ] && echo "`date "+%Y-%m-%d"` ${login_time} 【info】设备 ${login_ip} 通过 Web ${login_mode} 登录了路由器 " >> ${logfile} && continue - login_ip_attribution=$(get_ip_attribution ${login_ip}) + local login_ip_attribution=$(get_ip_attribution ${login_ip}) [ -n "$login_ip_attribution" ] && content_attribution="${str_linefeed}${str_tab}IP 归属地: ${str_space}${str_space}${str_space}${str_space}${login_ip_attribution}" [ -n "$login_mode" ] && content_mode="${str_linefeed}${str_tab}登录方式: ${str_space}${str_space}${str_space}${str_space}${login_mode}" if { [ -z "$login_disturb" ] || [ "$login_disturb" -ne "1" ]; }; then @@ -1282,7 +1293,7 @@ function login_send(){ fi [ -n "$log_only" ] && echo "`date "+%Y-%m-%d"` ${login_time} 【info】设备 ${login_ip} 通过 SSH ${login_mode} 登录了路由器 " >> ${logfile} && continue - login_ip_attribution=$(get_ip_attribution ${login_ip}) + local login_ip_attribution=$(get_ip_attribution ${login_ip}) [ -n "$login_ip_attribution" ] && content_attribution="${str_linefeed}${str_tab}IP 归属地: ${str_space}${str_space}${str_space}${str_space}${login_ip_attribution}" [ ! -z "$login_mode" ] && content_mode="${str_linefeed}${str_tab}登录方式: ${str_space}${str_space}${str_space}${str_space}${login_mode}" if { [ -z "$login_disturb" ] || [ "$login_disturb" -ne "1" ]; }; then @@ -1304,7 +1315,7 @@ function login_send(){ # Web 非法登录 [ -f ${dir}web_failed ] && for login_ip in `cat ${dir}web_failed | sort -u`; do [ -z "$login_ip" ] && continue - login_ip_attribution=$(get_ip_attribution ${login_ip}) + local login_ip_attribution=$(get_ip_attribution ${login_ip}) [ -n "$login_ip_attribution" ] && content_attribution="${str_linefeed}${str_tab}IP 归属地: ${str_space}${str_space}${str_space}${str_space}${login_ip_attribution}" || unset content_attribution echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】设备 ${login_ip} (${login_ip_attribution}) 通过 Web 频繁尝试登录" >> ${logfile} [ -n "$login_disturb" ] && [ "$login_disturb" -eq "1" ] && continue @@ -1324,7 +1335,7 @@ function login_send(){ # SSH 非法登录 [ -f ${dir}ssh_failed ] && for login_ip in `cat ${dir}ssh_failed | sort -u`; do [ -z "$login_ip" ] && continue - login_ip_attribution=$(get_ip_attribution ${login_ip}) + local login_ip_attribution=$(get_ip_attribution ${login_ip}) [ -n "$login_ip_attribution" ] && content_attribution="${str_linefeed}${str_tab}IP 归属地: ${str_space}${str_space}${str_space}${str_space}${login_ip_attribution}" || unset content_attribution echo "`date "+%Y-%m-%d %H:%M:%S"` 【!!!】设备 ${login_ip} (${login_ip_attribution}) 通过 SSH 频繁尝试登录" >> ${logfile} [ -n "$login_disturb" ] && [ "$login_disturb" -eq "1" ] && continue @@ -1598,7 +1609,7 @@ function send(){ send_content="${send_content}${str_linefeed}【${tmp_name}】 ${ip_total}${str_linefeed}${str_tab}${tmp_ip} 在线 ${time_online}" done < "${dir}tmp_sort_file" fi - + [ ! -z "$device_name" ] && send_title="【$device_name】${send_title}" [ -z "$send_content" ] && 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}" "$1" >/dev/null 2>&1 @@ -1612,6 +1623,12 @@ function send(){ if [ "$1" ] ;then [ $1 == "soc" ] && get_config "soc_code" "server_host" "server_port" [ $1 == "soc" ] && soc_temp && exit $? + [ $1 == "getip" ] && { + get_config "get_ipv4_mode" "ipv4_interface" "get_ipv6_mode" "ipv6_interface" + ipv4_urllist=`cat /usr/share/wechatpush/api/ipv4.list` 2>/dev/null + ipv6_urllist=`cat /usr/share/wechatpush/api/ipv6.list` 2>/dev/null + ip_changes getip && exit $? + } read_config [ $1 == "send" ] && send && exit $? [ $1 == "test" ] && send test && exit $?