Skip to content

Commit 212d577

Browse files
SakuraFallingMad1715173329
authored andcommitted
luci-app-wechatpush: bump to 3.6.10
1 parent d1af796 commit 212d577

File tree

6 files changed

+55
-31
lines changed

6 files changed

+55
-31
lines changed

applications/luci-app-wechatpush/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include $(TOPDIR)/rules.mk
22

33
PKG_NAME:=luci-app-wechatpush
4-
PKG_VERSION:=3.6.8
4+
PKG_VERSION:=3.6.10
55

66
PKG_MAINTAINER:=tty228 <tty228@yeah.net>
77
PKG_CONFIG_DEPENDS:= \

applications/luci-app-wechatpush/root/usr/libexec/wechatpush-call

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ dir="/tmp/wechatpush" && mkdir -p "${dir}"
55
oui_base="${dir}/oui_base.txt"
66
oui_data=$(uci get wechatpush.config.oui_data 2>/dev/null)
77
oui_url="https://standards-oui.ieee.org/oui/oui.txt"
8-
lang=$(echo "${LANG:-${LANGUAGE:-${LC_ALL:-${LC_MESSAGES:-zh_cn}}}}" | awk -F'[ .@]' '{print tolower($1)}' | sed 's/-/_/') 2>/dev/null
8+
lang=$(uci get luci.main.lang 2>/dev/null)
9+
if [ -z "$lang" ] || [[ "$lang" == "auto" ]]; then
10+
lang=$(echo "${LANG:-${LANGUAGE:-${LC_ALL:-${LC_MESSAGES:-zh_cn}}}}" | awk -F'[ .@]' '{print tolower($1)}' | sed 's/-/_/' 2>/dev/null)
11+
fi
912

1013
translate() {
1114
# 处理特殊字符
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
cip.cc/${ip} | sed -n 's/地址[[:space:]]*:[[:space:]]*\(.*\)/\1/p'
21
https://ip.rss.ink/v1/qqwry?ip=${ip} | jq -r '.data.area'
32
ip.plus/${ip} | sed -n 's/.*来自: //p'
3+
http://ip-api.com/json/${ip}?lang=zh-CN | jq -r '"\(.country) \(.regionName) \(.city)"'

applications/luci-app-wechatpush/root/usr/share/wechatpush/api/ipv4.list

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ ddns.oray.com/checkip
22
www.net.cn/static/customercare/yourip.asp
33
ip.3322.net
44
ip.threep.top
5+
ip.atomo.cn
6+
ip.ddnspod.com
7+
4.ipw.cn
8+
ipv4.ip.mir6.com
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
ipv6.ddnspod.com
21
speed.neu6.edu.cn/getIP.php
32
6.ipw.cn
3+
ip.atomo.cn
4+
ip.ddnspod.com
5+
v6.ip.zxinc.org/getip
6+
ipv6.ip.mir6.com

applications/luci-app-wechatpush/root/usr/share/wechatpush/wechatpush

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
# 读取设置文件
77
get_config() {
88
while [[ "$*" != "" ]]; do
9-
eval "${1}='$(uci get wechatpush.config.$1 2>/dev/null)'"
9+
[[ "$1" == "lang" ]] && {
10+
lang=$(uci get luci.main.lang 2>/dev/null)
11+
if [ -z "$lang" ] || [[ "$lang" == "auto" ]]; then
12+
lang=$(echo "${LANG:-${LANGUAGE:-${LC_ALL:-${LC_MESSAGES:-zh_cn}}}}" | awk -F'[ .@]' '{print tolower($1)}' | sed 's/-/_/' 2>/dev/null)
13+
fi
14+
} || {
15+
eval "${1}='$(uci get wechatpush.config.$1 2>/dev/null)'"
16+
}
1017
shift
1118
done
1219
}
@@ -36,7 +43,7 @@ wait_and_cat() {
3643
# 初始化设置信息
3744
read_config() {
3845
get_config \
39-
"enable" "lite_enable" "device_name" "proxy_address" "sleeptime" "oui_data" "reset_regularly" "debuglevel" \
46+
"enable" "lite_enable" "device_name" "proxy_address" "sleeptime" "oui_data" "reset_regularly" "debuglevel" "lang" \
4047
"jsonpath" "sckey" "sc3key" "sc3uid" "sc3tags" "corpid" "userid" "agentid" "corpsecret" "mediapath" "wxpusher_apptoken" "wxpusher_uids" "wxpusher_topicIds" "pushplus_token" "tg_token" "chat_id" "recipient_email" \
4148
"get_ipv4_mode" "ipv4_interface" "get_ipv6_mode" "ipv6_interface" \
4249
"device_notification" "cpu_notification" "cpu_load_threshold" "temperature_threshold" \
@@ -61,10 +68,17 @@ read_config() {
6168
(echo "$device_info_helper" | grep -q "mikrotik_info") && mikrotik_info_enable="true"
6269
(echo "$device_info_helper" | grep -q "openwrt_info") && openwrt_info_enable="true"
6370
op_host_ips=$(echo "$op_host_ips" | sed 's/ /\n/g') 2>/dev/null
64-
for str_version in "wrtbwmon" "iputils-arping" "curl" "iw"; do
65-
eval $(echo ${str_version:0:2}"_version")=$(opkg list-installed | grep -w ^${str_version} | awk '{print $3}') 2>/dev/null
66-
done
67-
(opkg list-installed | grep -w -q "^firewall4") && nftables_version="true"
71+
if [ -x "/usr/bin/apk" ]; then
72+
for str_version in "wrtbwmon" "iputils-arping" "curl" "iw"; do
73+
eval $(echo ${str_version:0:2}"_version")=$(apk list | grep -w ^${str_version} | grep 'installed' | awk '{print $1}' | awk -F ${str_version}"-" '{print $2}') 2>/dev/null
74+
done
75+
(apk list | grep -w -q "^firewall4" | grep 'installed') && nftables_version="true"
76+
else
77+
for str_version in "wrtbwmon" "iputils-arping" "curl" "iw"; do
78+
eval $(echo ${str_version:0:2}"_version")=$(opkg list-installed | grep -w ^${str_version} | awk '{print $3}') 2>/dev/null
79+
done
80+
(opkg list-installed | grep -w -q "^firewall4") && nftables_version="true"
81+
fi
6882
devices_json="${dir}/devices.json"
6983
tmp_devices_json="${dir}/devices.json.tmp"
7084
tempjsonpath="${dir}/temp.json"
@@ -83,7 +97,6 @@ read_config() {
8397
mark_mac_list=$(echo "$mark_mac_list" | sed 's/ /\n/g' | sed 's/-/ /') 2>/dev/null
8498
ipv4_urllist=$(cat /usr/share/wechatpush/api/ipv4.list) 2>/dev/null
8599
ipv6_urllist=$(cat /usr/share/wechatpush/api/ipv6.list) 2>/dev/null
86-
lang=$(echo "${LANG:-${LANGUAGE:-${LC_ALL:-${LC_MESSAGES:-zh_cn}}}}" | awk -F'[ .@]' '{print tolower($1)}' | sed 's/-/_/') 2>/dev/null
87100
[ -z "$get_ipv4_mode" ] && get_ipv4_mode=0
88101
[ -z "$get_ipv6_mode" ] && get_ipv6_mode=0
89102
[ -z "$sleeptime" ] && sleeptime="60"
@@ -127,7 +140,7 @@ init() {
127140
[ -z "$ip_version" ] && log_change "[ERROR] $(translate "Cannot get iputils-arping version, please confirm if plugin is running properly")"
128141
[ -z "$cu_version" ] && log_change "[ERROR] $(translate "Cannot get curl version, please confirm if plugin is running properly")"
129142

130-
[ -n "$jsonpath" ] && [ -z "${sckey}${sc3key}${sc3uid}${sc3tags}${tg_token}${pushplus_token}${corpid}${wxpusher_apptoken}${wxpusher_uids}${wxpusher_topicIds}" -a "${jsonpath}" != "/usr/share/wechatpush/api/diy.json" ] && log_change "[ERROR] $(translate "Please fill in the correct API key")" && return 1
143+
[ -n "$jsonpath" ] && [ -z "${sckey}${sc3key}${sc3uid}${sc3tags}${tg_token}${pushplus_token}${corpid}${wxpusher_apptoken}${wxpusher_uids}${wxpusher_topicIds}${recipient_email}" -a "${jsonpath}" != "/usr/share/wechatpush/api/diy.json" ] && log_change "[ERROR] $(translate "Please fill in the correct API key")" && return 1
131144

132145
local interfacelist=$(getinterfacelist) && [ -z "$interfacelist" ] && log_change "[WARN] $(translate "Multiple interfaces detected or configuration error, may not get interface uptime information, please confirm if plugin is running properly")"
133146

@@ -289,10 +302,11 @@ main() {
289302
fi
290303
}
291304
[ $1 == "getip" ] && {
292-
get_config "get_ipv4_mode" "ipv4_interface" "get_ipv6_mode" "ipv6_interface"
305+
get_config "get_ipv4_mode" "ipv4_interface" "get_ipv6_mode" "ipv6_interface" "lang"
293306
ipv4_urllist=$(cat /usr/share/wechatpush/api/ipv4.list) 2>/dev/null
294307
ipv6_urllist=$(cat /usr/share/wechatpush/api/ipv6.list) 2>/dev/null
295308
output_dir="${dir}/json_output" && mkdir -p "$output_dir"
309+
devices_json="${dir}/devices.json"
296310
ip_changes getip && exit $?
297311
}
298312
silent_run read_config
@@ -404,7 +418,7 @@ process_and_check() {
404418
[ -z "$1" ] && return 1
405419
local value=$(echo "$1" | tr -d '\n\r' | awk '$1=$1' | sed 's/_/ /g' | grep -v "^$" | sort -u | head -n1)
406420
[ "$value" == "unknown" ] && value=""
407-
[ -n "$value" ] && [ -n "$2" ] && echo $(cut_str "$value" "$2") && return 0
421+
[ -n "$value" ] && [ -n "$2" ] && echo "$(cut_str "$value" "$2")" && return 0
408422
[ -n "$value" ] && echo "$value" && return 0
409423
return 1
410424
}
@@ -622,7 +636,7 @@ getip() {
622636
local ipv4_URL
623637
while IFS= read -r ipv4_URL; do
624638
[ -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}")
625-
[ -z "$tmp_hostIP" ] && log_change "[DEBUG] $(translate "Failed to get IP, current API: %s & %s" "$ipv4_URL" "$ipv4_interface")"
639+
#[ -z "$tmp_hostIP" ] && log_change "[DEBUG] $(translate "Failed to get IP, current API: %s & %s" "$ipv4_URL" "$ipv4_interface")"
626640
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)
627641
[ -n "$tmp_hostIP" ] && local tmp_hostIP="{\"IP\":\"${tmp_hostIP}\", \"URL\":\"${ipv4_URL}\"}" && break
628642
done <<<"$sorted_ipv4_urllist"
@@ -638,7 +652,7 @@ getip() {
638652
local ipv6_URL
639653
while IFS= read -r ipv6_URL; do
640654
[ -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}")
641-
[ -z "$tmp_hostIPv6" ] && log_change "[DEBUG] $(translate "Failed to get IPv6, current API: %s & %s" "$ipv6_URL" "$ipv6_interface")"
655+
#[ -z "$tmp_hostIPv6" ] && log_change "[DEBUG] $(translate "Failed to get IPv6, current API: %s & %s" "$ipv6_URL" "$ipv6_interface")"
642656
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)
643657
[ -n "$tmp_hostIPv6" ] && local tmp_hostIP="{\"IP\":\"${tmp_hostIPv6}\", \"URL\":\"${ipv6_URL}\"}" && break
644658
done <<<"$sorted_ipv6_urllist"
@@ -797,7 +811,7 @@ getinterfaceuptime() {
797811
# 查询 IP 归属地
798812
get_ip_attribution() {
799813
ip="$1"
800-
jq -e --arg ip "$ip" '.devices[] | select(.ip == $ip) | .ip' "$devices_json" >/dev/null && echo "本地局域网" && return
814+
jq -e --arg ip "$ip" '.devices[] | select(.ip == $ip)' "$devices_json" >/dev/null 2>&1 && echo "本地局域网" && return
801815
local ip_attribution_urls=$(cat /usr/share/wechatpush/api/ip_attribution.list)
802816
local sorted_attribution_urls=$(echo "$ip_attribution_urls" | awk 'BEGIN {srand()} {print rand() "\t" $0}' | sort -k1,1n | cut -f2-)
803817
local ip_attribution_url
@@ -888,9 +902,9 @@ getping() {
888902
# 避免无效的 arp 条目
889903
if [ -n "$arp_entry_count" ] && [ "$arp_entry_count" -le 1 ]; then
890904
ip_ms=$(run_with_tag arping -I "$interface" -c 20 -f -w "$timeout" "$ip" 2>/dev/null)
891-
echo "$ip_ms" | grep -q "ms" && break || ip_ms=$(run_with_tag ping -c 5 -w "$timeout" "$ip" 2>/dev/null | grep -v '100% packet loss')
905+
echo "$ip_ms" | grep -q "ms" && break || ip_ms=$(run_with_tag ping -c 5 -w 3 "$ip" 2>/dev/null | grep -v '100% packet loss')
892906
else
893-
ip_ms=$(run_with_tag ping -c 5 -w "$timeout" "$ip" 2>/dev/null | grep -v '100% packet loss')
907+
ip_ms=$(run_with_tag ping -c 5 -w 3 "$ip" 2>/dev/null | grep -v '100% packet loss')
894908
echo "$ip_ms" | grep -q "ms" && break || ip neigh del "$ip" dev "$interface" 2>/dev/null # 清理无效条目
895909
fi
896910
sleep 1
@@ -1212,7 +1226,7 @@ check_cpu_load() {
12121226
log_change "[WARN] $(translate "CPU temperature too high: %s" "$cpu_temp")"
12131227

12141228
local cpu_overload_duration=$(time_for_humans $(($(date +%s) - $temp_last_overload_time)))
1215-
local content="${content}\
1229+
content="${content}\
12161230
${str_splitline}\
12171231
${str_title_start}$(translate "CPU Temperature Alert")${str_title_end}\
12181232
${str_linefeed}${str_tab} - $(translate "CPU temperature has exceeded threshold for %s" "$cpu_overload_duration")\
@@ -1248,7 +1262,7 @@ ${str_linefeed}${str_tab} - $(translate "Current temperature: %s℃" "$cpu_temp"
12481262
log_change "${disturb_text} $(translate "CPU load too high: %s" "${cpu_load}")"
12491263

12501264
local cpu_load_duration=$(time_for_humans $(($(date +%s) - $cpu_last_overload_time)))
1251-
local content="${content}\
1265+
content="${content}\
12521266
${str_splitline}\
12531267
${str_title_start}$(translate "CPU Load Alert")${str_title_end}\
12541268
${str_linefeed}${str_tab} - $(translate "CPU load has exceeded threshold for %s" "$cpu_load_duration")\
@@ -1496,7 +1510,7 @@ getgateway() {
14961510
echo "$get_gateway" | jq --arg gateway_host_ip "$gateway_host_ip" '
14971511
to_entries | map(select(.value | type == "object" and has("ip"))) | map({
14981512
ip: .value.ip,
1499-
name: (.value.devName // "unknown"),
1513+
name: (if .value.model != "" then .value.model else .value.devName end // "unknown"),
15001514
mac: "unknown",
15011515
type: (if .key | startswith("wifi") then "WiFi" else "LAN" end),
15021516
parent: (if .key | startswith("wifi") then $gateway_host_ip else "" end)
@@ -2644,31 +2658,31 @@ diy_send() {
26442658

26452659
if [[ "$diyurl" =~ ^https?:// ]]; then
26462660
[ -n "$proxy_address" ] && local proxy_cmd="-x $proxy_address"
2647-
run_with_tag curl $proxy_cmd --connect-timeout 30 --max-time 60 --retry 2 -X POST -H "$content_type" -d "$data" "${diyurl}"
2661+
local curl_response=$(run_with_tag curl $proxy_cmd --connect-timeout 30 --max-time 60 --retry 2 -X POST -H "$content_type" -d "$data" "${diyurl}")
26482662
else
26492663
local command=$(jq -r '.command' ${3}) && local command=$(eval echo ${command})
2650-
run_with_tag jq -r "$command" "$data" | eval "$diyurl"
2664+
local curl_response=$(run_with_tag jq -r "$command" "$data" | eval "$diyurl")
26512665
fi
26522666
local RETVAL=$?
26532667

26542668
if [ $RETVAL -ne 0 ] || [[ -n "$4" && "$4" == "test" ]]; then
26552669
[ $RETVAL -ne 0 ] && log_change "[ERROR] $(translate "Network or URL error, push failed, curl returned %s, please check the following debug information" "$RETVAL")"
26562670
[ -n "$4" ] && log_change "[DEBUG] $(translate "Push test enabled, current curl return value is %s" "$RETVAL")"
2671+
log_change "[INFO] Response: $curl_response"
26572672

26582673
echo '{"url":"'${diyurl}'","content_type":"'${content_type}'","type":'$(jq "$type" ${3})'}' >${dir}/debug_send_json
26592674
echo -e "${send_title}" "${send_content}" >${dir}/debug_send_content
26602675
cat ${tempjsonpath} >${dir}/debug_send_data
26612676

2662-
! jq -r '.' ${dir}/debug_send_json && log_change "[ERROR] $(translate "Format error after variable substitution, please check %s for unescaped special characters or syntax errors" "$dir")"
2677+
! jq -r '.' ${dir}/debug_send_json && log_change "[ERROR] $(translate "Format error after variable substitution, please check %s for unescaped special characters or syntax errors" "${dir}/debug_send_json")"
26632678

2664-
log_change "[DEBUG] $(translate "JSON file saved to: %s" "$dir")"
2665-
log_change "[DEBUG] $(translate "Push content preview saved to: %s" "$dir")"
2666-
log_change "[DEBUG] $(translate "If no message received, please check %s or use the following command to test manually" "$dir")"
2679+
log_change "[DEBUG] $(translate "JSON file saved to: %s" "${dir}/debug_send_json")"
2680+
log_change "[DEBUG] $(translate "Push content preview saved to: %s" "${dir}/debug_send_content")"
2681+
log_change "[DEBUG] $(translate "If no message received, please check %s or use the following command to test manually" "${dir}/debug_send_data")"
26672682
log_change "[DEBUG] curl -X POST -H \"$content_type\" -d \"@${dir}/debug_send_data\" \"${diyurl}\""
2668-
return 1
2669-
else
2670-
return 0
2683+
[ $RETVAL -ne 0 ] && return 1
26712684
fi
2685+
return 0
26722686
}
26732687

26742688
# ------------------------------------

0 commit comments

Comments
 (0)