简化 IP 获取逻辑

删除了更新获取 API 的设定
This commit is contained in:
tty228 2024-07-13 01:47:53 +08:00
parent 855b328835
commit ebb5736306
5 changed files with 45 additions and 98 deletions

View File

@ -132,6 +132,8 @@ return view.extend({
o = s.taboption('basic', form.Flag, 'enable', _('Enabled')); o = s.taboption('basic', form.Flag, 'enable', _('Enabled'));
o = s.taboption('basic', cbiRichListValue, 'jsonpath', _('Push Mode')); o = s.taboption('basic', cbiRichListValue, 'jsonpath', _('Push Mode'));
o.value('', _('Close'),
_('Do not use push notifications, only use other features.'));
o.value('/usr/share/wechatpush/api/serverchan.json', _('WeChat serverchan'), o.value('/usr/share/wechatpush/api/serverchan.json', _('WeChat serverchan'),
_('Using serverchan API, simple configuration, supports multiple push methods')); _('Using serverchan API, simple configuration, supports multiple push methods'));
o.value('/usr/share/wechatpush/api/qywx_mpnews.json', _('WeChat Work Image Message'), o.value('/usr/share/wechatpush/api/qywx_mpnews.json', _('WeChat Work Image Message'),
@ -231,6 +233,12 @@ return view.extend({
o = s.taboption('basic', form.Value, 'proxy_address', _('Proxy Address')); o = s.taboption('basic', form.Value, 'proxy_address', _('Proxy Address'));
o.description = _('When you want to use a proxy to push information, you can use this option.<br/>This may be helpful for scenarios like trusted IPs for WeChat Work.Using special characters may cause sending failure.<br/>Example:<br/>http://username:password@127.0.0.1:1080<br/>socks5://username:password@127.0.0.1:1080'); o.description = _('When you want to use a proxy to push information, you can use this option.<br/>This may be helpful for scenarios like trusted IPs for WeChat Work.Using special characters may cause sending failure.<br/>Example:<br/>http://username:password@127.0.0.1:1080<br/>socks5://username:password@127.0.0.1:1080');
o.depends('jsonpath', '/usr/share/wechatpush/api/serverchan.json');
o.depends('jsonpath', '/usr/share/wechatpush/api/qywx_mpnews.json');
o.depends('jsonpath', '/usr/share/wechatpush/api/wxpusher.json');
o.depends('jsonpath', '/usr/share/wechatpush/api/pushplus.json');
o.depends('jsonpath', '/usr/share/wechatpush/api/telegram.json');
o.depends('jsonpath', '/usr/share/wechatpush/api/diy.json');
o = s.taboption('basic', form.Button, '_test', _('Send Test'), _('You may need to save the configuration before sending.')); o = s.taboption('basic', form.Button, '_test', _('Send Test'), _('You may need to save the configuration before sending.'));
o.inputstyle = 'add'; o.inputstyle = 'add';
@ -249,6 +257,12 @@ return view.extend({
return _this.map.reset(); return _this.map.reset();
}); });
} }
o.depends('jsonpath', '/usr/share/wechatpush/api/serverchan.json');
o.depends('jsonpath', '/usr/share/wechatpush/api/qywx_mpnews.json');
o.depends('jsonpath', '/usr/share/wechatpush/api/wxpusher.json');
o.depends('jsonpath', '/usr/share/wechatpush/api/pushplus.json');
o.depends('jsonpath', '/usr/share/wechatpush/api/telegram.json');
o.depends('jsonpath', '/usr/share/wechatpush/api/diy.json');
o = s.taboption('basic', form.Value, 'device_name', _('Device Name')); o = s.taboption('basic', form.Value, 'device_name', _('Device Name'));
o.description = _('The device name will be displayed in the push message title to identify the source device of the message.'); o.description = _('The device name will be displayed in the push message title to identify the source device of the message.');
@ -357,24 +371,6 @@ return view.extend({
}; };
o.description = _('Access a random address from the list above,URLs in the list are specific to Chinese websites. If you need to use this feature, please replace the URLs with the ones available to you.<br/>Please use the 「Save」 button in the text box.'); o.description = _('Access a random address from the list above,URLs in the list are specific to Chinese websites. If you need to use this feature, please replace the URLs with the ones available to you.<br/>Please use the 「Save」 button in the text box.');
o = s.taboption('content', form.Button, '_update_ipv4_list', _('Update IPv4 list'));
o.inputstyle = 'add';
o.onclick = function () {
var _this = this;
return fs.exec('/usr/libexec/wechatpush-call', ['update_ip_list', 'ipv4']).then(function (res) {
if (res.code === 0)
_this.description = _('Update successful');
else if (res.code === 1)
_this.description = _('Update failed');
return _this.map.reset();
}).catch(function (err) {
ui.addNotification(null, E('p', [_('Unknown error: %s.').format(err)]));
_this.description = _('Update failed');
return _this.map.reset();
});
}
o.depends('get_ipv4_mode', '2');
o = s.taboption('content', cbiRichListValue, 'get_ipv6_mode', _('IPv6 Dynamic Notification')); o = s.taboption('content', cbiRichListValue, 'get_ipv6_mode', _('IPv6 Dynamic Notification'));
o.value('', _('Close'), o.value('', _('Close'),
_(' ')); _(' '));
@ -408,29 +404,6 @@ return view.extend({
}; };
o.description = _('Access a random address from the list above,URLs in the list are specific to Chinese websites. If you need to use this feature, please replace the URLs with the ones available to you.<br/>Please use the 「Save」 button in the text box.'); o.description = _('Access a random address from the list above,URLs in the list are specific to Chinese websites. If you need to use this feature, please replace the URLs with the ones available to you.<br/>Please use the 「Save」 button in the text box.');
o = s.taboption('content', form.Button, '_update_ipv6_list', _('Update IPv6 list'));
o.inputstyle = 'add';
o.onclick = function () {
var _this = this;
return fs.exec('/usr/libexec/wechatpush-call', ['update_ip_list', 'ipv6']).then(function (res) {
if (res.code === 0)
_this.description = _('Update successful');
else if (res.code === 1)
_this.description = _('Update failed');
return _this.map.reset();
}).catch(function (err) {
ui.addNotification(null, E('p', [_('Unknown error: %s.').format(err)]));
_this.description = _('Update failed');
return _this.map.reset();
});
}
o.depends('get_ipv6_mode', '2');
o = s.taboption('content', form.Flag, 'auto_update_ip_list', _('Automatically update API list'));
o.description = _('When multiple IP retrieval attempts fail, try to automatically update the list file from GitHub');
o.depends('get_ipv4_mode', '2');
o.depends('get_ipv6_mode', '2');
o = s.taboption('content', form.MultiValue, 'device_notification', _('Device Online/Offline Notification')); o = s.taboption('content', form.MultiValue, 'device_notification', _('Device Online/Offline Notification'));
o.value('online', _('Online Notification')); o.value('online', _('Online Notification'));
o.value('offline', _('Offline Notification')); o.value('offline', _('Offline Notification'));

View File

@ -56,6 +56,10 @@ msgstr "免打扰"
msgid "Push Mode" msgid "Push Mode"
msgstr "推送模式" msgstr "推送模式"
#: applications/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/config.js:134
msgid "Do not use push notifications, only use other features."
msgstr "不使用推送通知,仅使用其他功能"
#: applications/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/config.js:135 #: applications/luci-app-wechatpush/htdocs/luci-static/resources/view/wechatpush/config.js:135
msgid "WeChat serverchan" msgid "WeChat serverchan"
msgstr "微信 Server 酱" msgstr "微信 Server 酱"

View File

@ -35,14 +35,6 @@ down_oui() {
if [ "$1" == "clear_log" ]; then if [ "$1" == "clear_log" ]; then
# 清空日志 # 清空日志
>"${logfile}" >"${logfile}"
elif [ "$1" == "update_list" ]; then
# 更新 API 列表
echo "$(date "+%Y-%m-%d %H:%M:%S") 【info】开始更新 ${2} API 列表" >>"${logfile}"
curl -fsSL --connect-timeout 15 --max-time 30 -o "/tmp/wechatpush/${2}.list" "https://raw.githubusercontent.com/tty228/luci-app-wechatpush/master/root/usr/share/wechatpush/api/${2}.list" >/dev/null 2>&1
local RETVAL=$?
[ ${RETVAL} -ne 0 ] && echo "$(date "+%Y-%m-%d %H:%M:%S") 【!!!】${2} API 列表更新失败,返回码为 ${RETVAL}" >>"${logfile}" && return 1
mv -f "/tmp/wechatpush/${2}.list" "/usr/share/wechatpush/api/${2}.list"
echo "$(date "+%Y-%m-%d %H:%M:%S") 【info】${2} API 列表更新成功" >>"${logfile}"
elif [ "$1" == "down_oui" ]; then elif [ "$1" == "down_oui" ]; then
# 更新 MAC 信息列表 # 更新 MAC 信息列表
[ $(file_date "$oui_base") -lt 86400 ] && echo "$(date "+%Y-%m-%d %H:%M:%S") 【info】MAC 信息文件无需更新" >>"${logfile}" && exit 2 [ $(file_date "$oui_base") -lt 86400 ] && echo "$(date "+%Y-%m-%d %H:%M:%S") 【info】MAC 信息文件无需更新" >>"${logfile}" && exit 2

View File

@ -2,5 +2,3 @@ ddns.oray.com/checkip
www.net.cn/static/customercare/yourip.asp www.net.cn/static/customercare/yourip.asp
ip.3322.net ip.3322.net
ip.threep.top ip.threep.top
10086.cn/web-Center/commonservice/getUserIp.do --referer http://10086.cn -XPOST
https://www.taobao.com/help/getip.php -H 'authority: www.taobao.com'

View File

@ -38,7 +38,7 @@ read_config() {
get_config \ get_config \
"enable" "lite_enable" "device_name" "proxy_address" "sleeptime" "oui_data" "reset_regularly" "debuglevel" \ "enable" "lite_enable" "device_name" "proxy_address" "sleeptime" "oui_data" "reset_regularly" "debuglevel" \
"jsonpath" "sckey" "corpid" "userid" "agentid" "corpsecret" "mediapath" "wxpusher_apptoken" "wxpusher_uids" "wxpusher_topicIds" "pushplus_token" "tg_token" "chat_id" \ "jsonpath" "sckey" "corpid" "userid" "agentid" "corpsecret" "mediapath" "wxpusher_apptoken" "wxpusher_uids" "wxpusher_topicIds" "pushplus_token" "tg_token" "chat_id" \
"get_ipv4_mode" "ipv4_interface" "get_ipv6_mode" "ipv6_interface" "auto_update_ip_list" \ "get_ipv4_mode" "ipv4_interface" "get_ipv6_mode" "ipv6_interface" \
"device_notification" "cpu_notification" "cpu_load_threshold" "temperature_threshold" \ "device_notification" "cpu_notification" "cpu_load_threshold" "temperature_threshold" \
"client_usage" "client_usage_max" "client_usage_disturb" "client_usage_whitelist" \ "client_usage" "client_usage_max" "client_usage_disturb" "client_usage_whitelist" \
"login_notification" "login_max_num" "login_web_black" "login_ip_black_timeout" "login_ip_white_list" "port_knocking_enable" "login_ip_white_timeout" "login_port_white" "login_port_forward_list" \ "login_notification" "login_max_num" "login_web_black" "login_ip_black_timeout" "login_ip_white_list" "port_knocking_enable" "login_ip_white_timeout" "login_port_white" "login_port_forward_list" \
@ -88,7 +88,7 @@ read_config() {
[ -z "$server_port" ] && server_port="22" [ -z "$server_port" ] && server_port="22"
output_dir="${dir}/json_output" output_dir="${dir}/json_output"
mkdir -p "$output_dir" mkdir -p "$output_dir"
if (echo "$lite_enable" | grep -q "content"); then if (echo "$lite_enable" | grep -q "content") || [ -z "$jsonpath" ]; then
str_title_start="" && str_title_end="" && str_splitline="" && str_linefeed="" && str_tab="" str_title_start="" && str_title_end="" && str_splitline="" && str_linefeed="" && str_tab=""
else else
read_json "str_title_start" "$jsonpath" read_json "str_title_start" "$jsonpath"
@ -121,7 +121,7 @@ init() {
[ ! -f "/usr/sbin/wrtbwmon" ] && log_change "【info】未安装 wrtbwmon ,流量统计不可用" [ ! -f "/usr/sbin/wrtbwmon" ] && log_change "【info】未安装 wrtbwmon ,流量统计不可用"
[ -z "$ip_version" ] && log_change "【!!!】无法获取依赖项 iputils-arping 版本号,请确认插件是否正常运行" [ -z "$ip_version" ] && log_change "【!!!】无法获取依赖项 iputils-arping 版本号,请确认插件是否正常运行"
[ -z "$cu_version" ] && log_change "【!!!】无法获取依赖项 curl 版本号,请确认插件是否正常运行" [ -z "$cu_version" ] && log_change "【!!!】无法获取依赖项 curl 版本号,请确认插件是否正常运行"
[ -z "${sckey}${tg_token}${pushplus_token}${corpid}${wxpusher_apptoken}${wxpusher_uids}${wxpusher_topicIds}" -a "${jsonpath}" != "/usr/share/wechatpush/api/diy.json" ] && log_change "【!!!】请填写正确的 key" && return 1 [ -n "$jsonpath" ] && [ -z "${sckey}${tg_token}${pushplus_token}${corpid}${wxpusher_apptoken}${wxpusher_uids}${wxpusher_topicIds}" -a "${jsonpath}" != "/usr/share/wechatpush/api/diy.json" ] && log_change "【!!!】请填写正确的 key" && return 1
local interfacelist=$(getinterfacelist) && [ -z "$interfacelist" ] && log_change "【!!!】存在多个接口或配置错误,可能无法获取接口在线时间等信息,请确认插件是否正常运行" local interfacelist=$(getinterfacelist) && [ -z "$interfacelist" ] && log_change "【!!!】存在多个接口或配置错误,可能无法获取接口在线时间等信息,请确认插件是否正常运行"
[ -n "$notification_temp" ] && [ -n "$temperature_threshold" ] && local cpu_temp=$(soc_temp) || local cpu_temp="null" [ -n "$notification_temp" ] && [ -n "$temperature_threshold" ] && local cpu_temp=$(soc_temp) || local cpu_temp="null"
[ -z "$cpu_temp" ] && log_change "【!!!】无法读取设备温度,请检查命令" [ -z "$cpu_temp" ] && log_change "【!!!】无法读取设备温度,请检查命令"
@ -508,52 +508,33 @@ getip() {
[ -n "$ipv4_interface" ] && local wanIP=$(/sbin/ifconfig ${ipv4_interface} | awk '/inet addr/ {print $2}' | awk -F: '{print $2}' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') [ -n "$ipv4_interface" ] && local wanIP=$(/sbin/ifconfig ${ipv4_interface} | awk '/inet addr/ {print $2}' | awk -F: '{print $2}' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')
[ -z "$ipv4_interface" ] && local wanIP=$(getinterfacelist | grep '\"address\"' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') [ -z "$ipv4_interface" ] && local wanIP=$(getinterfacelist | grep '\"address\"' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')
echo "$wanIP" echo "$wanIP"
# 从 URL 获取 IPv4 # 从 URL 获取 IPv4
elif [ $1 == "hostipv4" ]; then elif [ $1 == "hostipv4" ]; then
local url_number=$(echo "$ipv4_urllist" | wc -l) local sorted_ipv4_urllist=$(echo "$ipv4_urllist" | awk 'BEGIN {srand()} {print rand() "\t" $0}' | sort -k1,1n | cut -f2-)
local rand_number=$(rand 1 $url_number) local ipv4_URL
get_hostipv4() { while IFS= read -r ipv4_URL; do
local ipv4_URL=$(echo "$ipv4_urllist" | sed -n "${1}p" | sed -e 's/\r//g')
[ -n "$ipv4_interface" ] && local tmp_hostIP=$(eval "curl --connect-timeout 2 -m 2 -k -s -4 --interface ${ipv4_interface} -m 5 ${ipv4_URL}") || local tmp_hostIP=$(eval "curl --connect-timeout 2 -m 2 -k -s -4 -m 5 ${ipv4_URL}") [ -n "$ipv4_interface" ] && local tmp_hostIP=$(eval "curl --connect-timeout 2 -m 2 -k -s -4 --interface ${ipv4_interface} -m 5 ${ipv4_URL}") || local tmp_hostIP=$(eval "curl --connect-timeout 2 -m 2 -k -s -4 -m 5 ${ipv4_URL}")
[ -z "$tmp_hostIP" ] && log_change "【info】IP 获取失败,当前使用的 API 为 $ipv4_URL & ${ipv4_interface}" [ -z "$tmp_hostIP" ] && log_change "【info】IP 获取失败,当前使用的 API 为 $ipv4_URL & ${ipv4_interface}"
local tmp_hostIP=$(echo $tmp_hostIP | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -n1) local tmp_hostIP=$(echo $tmp_hostIP | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -n1)
echo "{\"IP\":\"${tmp_hostIP}\", \"URL\":\"${ipv4_URL}\"}" [ -n "$tmp_hostIP" ] && local tmp_hostIP="{\"IP\":\"${tmp_hostIP}\", \"URL\":\"${ipv4_URL}\"}" && break
} done <<<"$sorted_ipv4_urllist"
local hostIP=$(get_hostipv4 ${rand_number}) echo $tmp_hostIP
[ -z $(echo $hostIP | jq -r '.IP') ] && local rand_number=$(expr $rand_number + 1) && [ $rand_number -gt $url_number ] && local rand_number=1
[ -z $(echo $hostIP | jq -r '.IP') ] && local hostIP=$(get_hostipv4 ${rand_number})
[ -z $(echo $hostIP | jq -r '.IP') ] && local rand_number=$(expr $rand_number + 1) && [ $rand_number -gt $url_number ] && local rand_number=1
[ -z $(echo $hostIP | jq -r '.IP') ] && local hostIP=$(get_hostipv4 ${rand_number})
[ -n "$list_auto_up" ] && [ "$list_auto_up" -eq "1" ] && [ -z $(echo $hostIP | jq -r '.IP') ] && /usr/libexec/wechatpush-call "auto_update_ip_list" "ipv4"
[ -z $(echo $hostIP | jq -r '.IP') ] && ipv4_urllist=$(cat /usr/share/wechatpush/api/ipv4.list) 2>/dev/null
echo $hostIP
# 从接口获取 IPv6 # 从接口获取 IPv6
elif [ $1 == "wanipv6" ]; then elif [ $1 == "wanipv6" ]; then
[ -n "$ipv6_interface" ] && local wanIPv6=$(ip -6 addr show dev ${ipv6_interface} | grep "inet6" | grep "global dynamic noprefixroute" | awk '{print $2}' | grep -Ev "^(fc|fd)" | tail -n 1 | grep -oE "([\da-fA-F0-9]{1,4}(:{1,2})){1,15}[\da-fA-F0-9]{1,4}") [ -n "$ipv6_interface" ] && local wanIPv6=$(ip -6 addr show dev ${ipv6_interface} | grep "inet6" | grep "global dynamic noprefixroute" | awk '{print $2}' | grep -Ev "^(fc|fd)" | tail -n 1 | grep -oE "([\da-fA-F0-9]{1,4}(:{1,2})){1,15}[\da-fA-F0-9]{1,4}")
[ -z "$ipv6_interface" ] && local wanIPv6=$(ip -6 addr show | grep "inet6" | grep "global dynamic noprefixroute" | awk '{print $2}' | grep -Ev "^(fc|fd)" | tail -n 1 | grep -oE "([\da-fA-F0-9]{1,4}(:{1,2})){1,15}[\da-fA-F0-9]{1,4}") [ -z "$ipv6_interface" ] && local wanIPv6=$(ip -6 addr show | grep "inet6" | grep "global dynamic noprefixroute" | awk '{print $2}' | grep -Ev "^(fc|fd)" | tail -n 1 | grep -oE "([\da-fA-F0-9]{1,4}(:{1,2})){1,15}[\da-fA-F0-9]{1,4}")
echo "$wanIPv6" echo "$wanIPv6"
# 从 URL 获取 IPv6 # 从 URL 获取 IPv6
elif [ $1 == "hostipv6" ]; then elif [ $1 == "hostipv6" ]; then
local urlv6_number=$(echo "$ipv6_urllist" | wc -l) local sorted_ipv6_urllist=$(echo "$ipv6_urllist" | awk 'BEGIN {srand()} {print rand() "\t" $0}' | sort -k1,1n | cut -f2-)
local rand_numberv6=$(rand 1 $urlv6_number) local ipv6_URL
get_hostipv6() { while IFS= read -r ipv6_URL; do
local ipv6_URL=$(echo "$ipv6_urllist" | sed -n "${1}p" | sed -e 's/\r//g')
[ -n "$ipv6_interface" ] && local tmp_hostIPv6=$(eval "curl --connect-timeout 2 -m 2 -k -s -6 --interface ${ipv6_interface} -m 5 ${ipv6_URL}") || local tmp_hostIPv6=$(eval "curl --connect-timeout 2 -m 2 -k -s -6 -m 5 ${ipv6_URL}") [ -n "$ipv6_interface" ] && local tmp_hostIPv6=$(eval "curl --connect-timeout 2 -m 2 -k -s -6 --interface ${ipv6_interface} -m 5 ${ipv6_URL}") || local tmp_hostIPv6=$(eval "curl --connect-timeout 2 -m 2 -k -s -6 -m 5 ${ipv6_URL}")
[ -z "$tmp_hostIPv6" ] && log_change "【info】IP 获取失败,当前使用的 API 为 $ipv6_URL & ${ipv6_interface}" [ -z "$tmp_hostIPv6" ] && log_change "【info】IP 获取失败,当前使用的 API 为 $ipv6_URL & ${ipv6_interface}"
local tmp_hostIPv6=$(echo $tmp_hostIPv6 | grep -oE "([\da-fA-F0-9]{1,4}(:{1,2})){1,15}[\da-fA-F0-9]{1,4}" | head -n1) local tmp_hostIPv6=$(echo $tmp_hostIPv6 | grep -oE "([\da-fA-F0-9]{1,4}(:{1,2})){1,15}[\da-fA-F0-9]{1,4}" | head -n1)
echo "{\"IP\":\"${tmp_hostIPv6}\", \"URL\":\"${ipv6_URL}\"}" [ -n "$tmp_hostIPv6" ] && local tmp_hostIP="{\"IP\":\"${tmp_hostIPv6}\", \"URL\":\"${ipv6_URL}\"}" && break
} done <<<"$sorted_ipv6_urllist"
local hostIPv6=$(get_hostipv6 ${rand_numberv6}) echo $tmp_hostIP
[ -z $(echo $hostIPv6 | jq -r '.IP') ] && local rand_numberv6=$(expr $rand_numberv6 + 1) && [ $rand_numberv6 -gt $urlv6_number ] && local rand_numberv6=1
[ -z $(echo $hostIPv6 | jq -r '.IP') ] && local hostIPv6=$(get_hostipv6 ${rand_numberv6})
[ -z $(echo $hostIPv6 | jq -r '.IP') ] && local rand_numberv6=$(expr $rand_numberv6 + 1) && [ $rand_numberv6 -gt $urlv6_number ] && local rand_numberv6=1
[ -z $(echo $hostIPv6 | jq -r '.IP') ] && local hostIPv6=$(get_hostipv6 ${rand_numberv6})
[ -n "$list_auto_up" ] && [ "$list_auto_up" -eq "1" ] && [ -z $(echo $hostIP | jq -r '.IP') ] && /usr/libexec/wechatpush-call "auto_update_ip_list" "ipv6"
[ -z $(echo $hostIPv6 | jq -r '.IP') ] && ipv4_urllist=$(cat /usr/share/wechatpush/api/ipv6.list) 2>/dev/null
echo $hostIPv6
fi fi
} }
@ -686,20 +667,15 @@ getinterfaceuptime() {
get_ip_attribution() { get_ip_attribution() {
ip="$1" ip="$1"
jq -e --arg ip "$ip" '.devices[] | select(.ip == $ip) | .ip' "$devices_json" >/dev/null && echo "本地局域网" && return jq -e --arg ip "$ip" '.devices[] | select(.ip == $ip) | .ip' "$devices_json" >/dev/null && echo "本地局域网" && return
ip_attribution_urls=$(cat /usr/share/wechatpush/api/ip_attribution.list) local ip_attribution_urls=$(cat /usr/share/wechatpush/api/ip_attribution.list)
local url_number=$(echo "$ip_attribution_urls" | wc -l) local sorted_attribution_urls=$(echo "$ip_attribution_urls" | awk 'BEGIN {srand()} {print rand() "\t" $0}' | sort -k1,1n | cut -f2-)
local rand_number=$(rand 1 $url_number) local ip_attribution_url
get_attribution() { while IFS= read -r ip_attribution_url; do
local ip_attribution_url=$(echo "$ip_attribution_urls" | sed -n "${1}p" | sed -e 's/\r//g')
local login_ip_attribution=$(eval curl --connect-timeout 2 -m 2 -k -s "$ip_attribution_url" 2>/dev/null) local login_ip_attribution=$(eval curl --connect-timeout 2 -m 2 -k -s "$ip_attribution_url" 2>/dev/null)
#logfile=logfile="${dir}/wechatpush.log" # 此处保留排查时使用 #logfile=logfile="${dir}/wechatpush.log" # 此处保留排查时使用
#[ -z "$login_ip_attribution" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【info】归属地获取超时当前使用的 API 为 $ip_attribution_url" >> ${logfile} #[ -z "$login_ip_attribution" ] && echo "`date "+%Y-%m-%d %H:%M:%S"` 【info】归属地获取超时当前使用的 API 为 $ip_attribution_url" >> ${logfile}
echo "$login_ip_attribution" [ -n "$login_ip_attribution" ] && echo "$login_ip_attribution" && break
} done <<<"$sorted_attribution_urls"
local ip_attribution=$(get_attribution ${rand_number})
[ -z "$ip_attribution" ] && local rand_number=$(expr $rand_number + 1) && [ $rand_number -gt $url_number ] && local rand_number=1
[ -z "$ip_attribution" ] && local ip_attribution=$(get_attribution ${rand_number})
echo "$ip_attribution"
} }
# 查询 NetBIOS # 查询 NetBIOS
@ -862,7 +838,8 @@ disturb() {
if [ $(date +%H) -ge $do_not_disturb_endtime -a $do_not_disturb_starttime -lt $do_not_disturb_endtime ] || [ $(date +%H) -lt $do_not_disturb_starttime -a $do_not_disturb_starttime -lt $do_not_disturb_endtime ] || [ $(date +%H) -lt $do_not_disturb_starttime -a $(date +%H) -ge $do_not_disturb_endtime -a $do_not_disturb_starttime -gt $do_not_disturb_endtime ]; then if [ $(date +%H) -ge $do_not_disturb_endtime -a $do_not_disturb_starttime -lt $do_not_disturb_endtime ] || [ $(date +%H) -lt $do_not_disturb_starttime -a $do_not_disturb_starttime -lt $do_not_disturb_endtime ] || [ $(date +%H) -lt $do_not_disturb_starttime -a $(date +%H) -ge $do_not_disturb_endtime -a $do_not_disturb_starttime -gt $do_not_disturb_endtime ]; then
unset sheep_starttime unset sheep_starttime
rm -f ${dir}/sheep_usage ${dir}/old_sheep_usage 2>/dev/null rm -f ${dir}/sheep_usage ${dir}/old_sheep_usage 2>/dev/null
disturb_text=$(jq -r '._api' ${jsonpath}) [ -z "$jsonpath" ] && disturb_text="【info】"
[ -n "$jsonpath" ] && disturb_text=$(jq -r '._api' ${jsonpath})
return 0 return 0
# 免打扰 # 免打扰
else else
@ -1240,6 +1217,8 @@ get_disk() {
[ -n "$fstab_config" ] && local mount_point=$(uci get ${fstab_config}.target 2>/dev/null) [ -n "$fstab_config" ] && local mount_point=$(uci get ${fstab_config}.target 2>/dev/null)
[ -n "$mount_point" ] && local disk_use=$(df -h 2>/dev/null | awk -v mount="$mount_point" '$NF == mount {sub("^/dev/", "", $1); printf "%s: %s\n", $1, $5}') [ -n "$mount_point" ] && local disk_use=$(df -h 2>/dev/null | awk -v mount="$mount_point" '$NF == mount {sub("^/dev/", "", $1); printf "%s: %s\n", $1, $5}')
} }
# 如果获取到了多个分区,屏蔽使用空间为 0% 的分区
[ -n "$disk_use" ] && [ $(echo "$disk_use" | wc -l) -ne "1" ] && disk_use=$(echo "$disk_use" | grep -v -w "0%")
[ -n "$disk_use" ] && disk_use=$(echo "$disk_use" | sed ':a;N;$!ba;s/\n/'"${str_linefeed}${str_tab}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}"'/g') [ -n "$disk_use" ] && disk_use=$(echo "$disk_use" | sed ':a;N;$!ba;s/\n/'"${str_linefeed}${str_tab}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}${str_space}"'/g')
[ -n "$disk_use" ] && [ -n "${disk_use// /}" ] && echo -e -n "${str_linefeed}${str_tab}空间使用:${disk_use}" >>"$output_dir/get_disk" [ -n "$disk_use" ] && [ -n "${disk_use// /}" ] && echo -e -n "${str_linefeed}${str_tab}空间使用:${disk_use}" >>"$output_dir/get_disk"
# 寿命使用 # 寿命使用
@ -1901,7 +1880,7 @@ process_login() {
# 发送定时数据 # 发送定时数据
send() { send() {
pid=$$ pid=$$
echo "$pid" > "${dir}/send_pid" echo "$pid" >"${dir}/send_pid"
log_change "【定时数据】创建定时任务" log_change "【定时数据】创建定时任务"
>"${dir}/send_enable.lock" >"${dir}/send_enable.lock"
disturb disturb
@ -2117,6 +2096,7 @@ down_send() {
# 推送 # 推送
diy_send() { diy_send() {
[ -z "$jsonpath" ] && return
(! echo "$lite_enable" | grep -q "content") && (! echo "$lite_enable" | grep -q "nowtime") && local nowtime=$(date "+%Y-%m-%d %H:%M:%S") (! echo "$lite_enable" | grep -q "content") && (! echo "$lite_enable" | grep -q "nowtime") && local nowtime=$(date "+%Y-%m-%d %H:%M:%S")
! jq -r '.' ${3} >/dev/null 2>&1 && log_change "【】json 文件格式错误,这不是一个标准的 json 文件,请检查 ${3} 文件是否有特殊符号未转义或语法错误" && return 1 ! jq -r '.' ${3} >/dev/null 2>&1 && log_change "【】json 文件格式错误,这不是一个标准的 json 文件,请检查 ${3} 文件是否有特殊符号未转义或语法错误" && return 1
local diyurl=$(jq -r .url ${3}) && local diyurl=$(eval echo ${diyurl}) local diyurl=$(jq -r .url ${3}) && local diyurl=$(eval echo ${diyurl})