From 8139ec30940581af1ea746a09a9393c1b10d09cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LZ=EF=BC=88=E5=A6=99=E5=A6=99=E5=91=9C=EF=BC=89?= <73221087+larsonzh@users.noreply.github.com> Date: Fri, 8 Nov 2024 20:22:58 +0800 Subject: [PATCH] v4.6.8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.完善和优化代码运行的安全性、稳定性及可靠性。 --- source_codes/install.sh | 24 ++++++++--- source_codes/lz/Changelog.txt | 3 ++ source_codes/lz/configs/lz_rule_config.sh | 2 +- .../lz/func/lz_clear_custom_scripts_data.sh | 2 +- .../lz/func/lz_define_global_variables.sh | 2 +- source_codes/lz/func/lz_initialize_config.sh | 2 +- source_codes/lz/func/lz_rule_address_query.sh | 2 +- source_codes/lz/func/lz_rule_func.sh | 2 +- source_codes/lz/func/lz_rule_status.sh | 2 +- source_codes/lz/func/lz_vpn_daemon.sh | 4 +- source_codes/lz/interface/lz_rule_service.sh | 43 +++++++++++++++++-- source_codes/lz/js/lz_policy_routing.js | 2 +- source_codes/lz/lz_rule.sh | 36 +++++++++++++--- source_codes/lz/uninstall.sh | 16 +++++-- .../lz/webs/LZ_Policy_Routing_Content.asp | 2 +- 15 files changed, 116 insertions(+), 28 deletions(-) diff --git a/source_codes/install.sh b/source_codes/install.sh index 7c629f85..38271ecc 100644 --- a/source_codes/install.sh +++ b/source_codes/install.sh @@ -1,5 +1,5 @@ #!/bin/sh -# install.sh v4.6.7 +# install.sh v4.6.8 # By LZ 妙妙呜 (larsonzhang@gmail.com) # LZ RULE script for Asuswrt-Merlin Router @@ -13,13 +13,19 @@ # shellcheck disable=SC2317 # Don't warn about unreachable commands in this function -LZ_VERSION=v4.6.7 +LZ_VERSION=v4.6.8 TIMEOUT=10 CURRENT_PATH="${0%/*}" [ "${CURRENT_PATH:0:1}" != '/' ] && CURRENT_PATH="$( pwd )${CURRENT_PATH#*.}" -SYSLOG="/tmp/syslog.log" +PATH_LOCK="/var/lock" LOCK_FILE_ID="555" +LOCK_FILE="${PATH_LOCK}/lz_rule.lock" PATH_BASE="/jffs/scripts" -[ "$( echo "${1}" | tr T t )" = t ] && PATH_BASE="${HOME}" +HANNER="$( echo "${1}" | tr T t )" +[ "${HANNER}" = t ] && { + PATH_BASE="$( readlink -f "/root" )" + { [ -z "${PATH_BASE}" ] || [ "${PATH_BASE}" = '/' ]; } && PATH_BASE="$( readlink -f "/tmp" )" +} +SYSLOG="/tmp/syslog.log" lzdate() { date +"%F %T"; } { @@ -51,7 +57,7 @@ elif [ "${USER}" = "root" ]; then fi AVAL_SPACE= -if [ "${1}" = "entware" ]; then +if { [ "${HANNER}" = "entware" ] || [ "${HANNER}" = "entwareX" ]; }; then if which opkg > /dev/null 2>&1; then for sditem in $( df | awk '$1 ~ /^\/dev\/sd/ {print $1":-"$4":-"$6}' ) do @@ -134,6 +140,11 @@ fi echo " Installation in progress..." | tee -ai "${SYSLOG}" 2> /dev/null +if { [ "${HANNER}" != "X" ] && [ "${HANNER}" != "entwareX" ]; }; then + [ ! -d "${PATH_LOCK}" ] && { mkdir -p "${PATH_LOCK}" > /dev/null 2>&1; chmod 777 "${PATH_LOCK}" > /dev/null 2>&1; } + eval "exec ${LOCK_FILE_ID}<>${LOCK_FILE}"; flock -x "${LOCK_FILE_ID}" > /dev/null 2>&1; +fi + PATH_LZ="${PATH_BASE}/lz" if ! mkdir -p "${PATH_LZ}" > /dev/null 2>&1; then { @@ -144,6 +155,7 @@ if ! mkdir -p "${PATH_LZ}" > /dev/null 2>&1; then echo " LZ script installation failed." echo -e " $(lzdate)\n" } | tee -ai "${SYSLOG}" 2> /dev/null + { [ "${HANNER}" != "X" ] && [ "${HANNER}" != "entwareX" ]; } && flock -u "${LOCK_FILE_ID}" > /dev/null 2>&1 exit 1 fi @@ -432,6 +444,8 @@ fi echo -e " $(lzdate)\n" } | tee -ai "${SYSLOG}" 2> /dev/null +{ [ "${HANNER}" != "X" ] && [ "${HANNER}" != "entwareX" ]; } && flock -u "${LOCK_FILE_ID}" > /dev/null 2>&1 + exit 0 #END diff --git a/source_codes/lz/Changelog.txt b/source_codes/lz/Changelog.txt index 2043abd2..07493f0f 100644 --- a/source_codes/lz/Changelog.txt +++ b/source_codes/lz/Changelog.txt @@ -1,3 +1,6 @@ +v4.6.8 (2024/11/8) + 1.完善和优化代码运行的安全性、稳定性及可靠性。 + v4.6.7 (2024/11/8) 1.解决本软件网络安装过程中,ASD 进程误删关键文件导致 安装失败的问题。 diff --git a/source_codes/lz/configs/lz_rule_config.sh b/source_codes/lz/configs/lz_rule_config.sh index d211fa47..e1878b36 100644 --- a/source_codes/lz/configs/lz_rule_config.sh +++ b/source_codes/lz/configs/lz_rule_config.sh @@ -1,5 +1,5 @@ #!/bin/sh -# lz_rule_config.sh v4.6.7 +# lz_rule_config.sh v4.6.8 # By LZ 妙妙呜 (larsonzhang@gmail.com) # 本软件采用CIDR(无类别域间路由,Classless Inter-Domain Routing)技术,是一个在Internet上创建附加地 diff --git a/source_codes/lz/func/lz_clear_custom_scripts_data.sh b/source_codes/lz/func/lz_clear_custom_scripts_data.sh index aef7267b..f2f723ff 100644 --- a/source_codes/lz/func/lz_clear_custom_scripts_data.sh +++ b/source_codes/lz/func/lz_clear_custom_scripts_data.sh @@ -1,5 +1,5 @@ #!/bin/sh -# lz_clear_custom_scripts_data.sh v4.6.7 +# lz_clear_custom_scripts_data.sh v4.6.8 # By LZ 妙妙呜 (larsonzhang@gmail.com) ## 清除用户自定义脚本数据 diff --git a/source_codes/lz/func/lz_define_global_variables.sh b/source_codes/lz/func/lz_define_global_variables.sh index 15aaeb36..0f943092 100644 --- a/source_codes/lz/func/lz_define_global_variables.sh +++ b/source_codes/lz/func/lz_define_global_variables.sh @@ -1,5 +1,5 @@ #!/bin/sh -# lz_define_global_variables.sh v4.6.7 +# lz_define_global_variables.sh v4.6.8 # By LZ 妙妙呜 (larsonzhang@gmail.com) # QnkgTFog5aaZ5aaZ5ZGc77yI6Juk6J+G5aKp5YS/77yJ(首次运行标识,切勿修改) diff --git a/source_codes/lz/func/lz_initialize_config.sh b/source_codes/lz/func/lz_initialize_config.sh index fad6882c..762959b3 100644 --- a/source_codes/lz/func/lz_initialize_config.sh +++ b/source_codes/lz/func/lz_initialize_config.sh @@ -1,5 +1,5 @@ #!/bin/sh -# lz_initialize_config.sh v4.6.7 +# lz_initialize_config.sh v4.6.8 # By LZ 妙妙呜 (larsonzhang@gmail.com) ## 初始化脚本配置 diff --git a/source_codes/lz/func/lz_rule_address_query.sh b/source_codes/lz/func/lz_rule_address_query.sh index 5846856c..7e47f8b5 100644 --- a/source_codes/lz/func/lz_rule_address_query.sh +++ b/source_codes/lz/func/lz_rule_address_query.sh @@ -1,5 +1,5 @@ #!/bin/sh -# lz_rule_address_query.sh v4.6.7 +# lz_rule_address_query.sh v4.6.8 # By LZ 妙妙呜 (larsonzhang@gmail.com) ## 网址信息查询脚本 diff --git a/source_codes/lz/func/lz_rule_func.sh b/source_codes/lz/func/lz_rule_func.sh index efa118c0..f5b5d4cb 100644 --- a/source_codes/lz/func/lz_rule_func.sh +++ b/source_codes/lz/func/lz_rule_func.sh @@ -1,5 +1,5 @@ #!/bin/sh -# lz_rule_func.sh v4.6.7 +# lz_rule_func.sh v4.6.8 # By LZ 妙妙呜 (larsonzhang@gmail.com) #BEGIN diff --git a/source_codes/lz/func/lz_rule_status.sh b/source_codes/lz/func/lz_rule_status.sh index 99d17816..3e3806d3 100644 --- a/source_codes/lz/func/lz_rule_status.sh +++ b/source_codes/lz/func/lz_rule_status.sh @@ -1,5 +1,5 @@ #!/bin/sh -# lz_rule_status.sh v4.6.7 +# lz_rule_status.sh v4.6.8 # By LZ 妙妙呜 (larsonzhang@gmail.com) ## 显示脚本运行状态脚本 diff --git a/source_codes/lz/func/lz_vpn_daemon.sh b/source_codes/lz/func/lz_vpn_daemon.sh index 4e8ae060..10668b43 100644 --- a/source_codes/lz/func/lz_vpn_daemon.sh +++ b/source_codes/lz/func/lz_vpn_daemon.sh @@ -1,5 +1,5 @@ #!/bin/sh -# lz_vpn_daemon.sh v4.6.7 +# lz_vpn_daemon.sh v4.6.8 # By LZ 妙妙呜 (larsonzhang@gmail.com) ## 虚拟专网客户端路由刷新处理后台守护进程脚本 @@ -10,7 +10,7 @@ #BEGIN ## 版本号 -LZ_VERSION=v4.6.7 +LZ_VERSION=v4.6.8 ## 项目接口文件部署路径 PATH_INTERFACE="${0%/*}" diff --git a/source_codes/lz/interface/lz_rule_service.sh b/source_codes/lz/interface/lz_rule_service.sh index b396c708..365f302b 100644 --- a/source_codes/lz/interface/lz_rule_service.sh +++ b/source_codes/lz/interface/lz_rule_service.sh @@ -1,5 +1,5 @@ #!/bin/sh -# lz_rule_service.sh v4.6.7 +# lz_rule_service.sh v4.6.8 # By LZ 妙妙呜 (larsonzhang@gmail.com) ## 服务接口脚本 @@ -15,6 +15,8 @@ PATH_LZ="${PATH_LZ%/*}" [ ! -s "${PATH_LZ}/lz_rule.sh" ] && return [ "${1}" = "stop" ] && [ "${2}" = "LZRule" ] && "${PATH_LZ}/lz_rule.sh" "STOP" [ "${1}" != "start" ] && [ "${1}" != "restart" ] && return +PATH_LOCK="/var/lock" LOCK_FILE_ID="555" +LOCK_FILE="${PATH_LOCK}/lz_rule.lock" get_repo_site() { local remoteRepo="https://gitee.com/" @@ -207,6 +209,8 @@ case "${2}" in ;; LZDetectVersion) detect_version() { + [ ! -d "${PATH_LOCK}" ] && { mkdir -p "${PATH_LOCK}" > /dev/null 2>&1; chmod 777 "${PATH_LOCK}" > /dev/null 2>&1; } + eval "exec ${LOCK_FILE_ID}<>${LOCK_FILE}"; flock -x "${LOCK_FILE_ID}" > /dev/null 2>&1; local PATH_WEB_LZR="$( readlink "/www/user" )/lzr" echo 'var versionStatus = "InProgress";' > "${PATH_WEB_LZR}/detect_version.js" local LZ_REPO="$( get_repo_site )" @@ -226,11 +230,14 @@ case "${2}" in printf "%s [%s]:\n" "$( date +"%F %T" )" "${$}" } >> "/tmp/syslog.log" fi + flock -u "${LOCK_FILE_ID}" > /dev/null 2>&1 } detect_version & ;; LZDoUpdate) do_update() { + [ ! -d "${PATH_LOCK}" ] && { mkdir -p "${PATH_LOCK}" > /dev/null 2>&1; chmod 777 "${PATH_LOCK}" > /dev/null 2>&1; } + eval "exec ${LOCK_FILE_ID}<>${LOCK_FILE}"; flock -x "${LOCK_FILE_ID}" > /dev/null 2>&1; [ -d "${PATH_LZ}/tmp/doupdate" ] && rm -rf "${PATH_LZ}/tmp/doupdate" 2> /dev/null local LZ_REPO="$( get_repo_site )" local remoteVer="$( get_last_version "${LZ_REPO}" )" @@ -286,10 +293,36 @@ case "${2}" in if [ -s "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" ]; then chmod 775 "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" sed -i "s/elif \[ \"\${USER}\" = \"root\" \]; then/elif \[ \"\${USER}\" = \"\" \]; then/g" "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" 2> /dev/null - if [ "${PATH_LZ}" = "/jffs/scripts/lz" ]; then - "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" && [ -s "${PATH_LZ}/lz_rule.sh" ] && "${PATH_LZ}/lz_rule.sh" + local oldRemote="$( awk -v ver="${remoteVer##*v}" 'BEGIN{ + ret = 0; + split(ver, arr, "."); + for (i = 1; i < 4; ++i) { + if (arr[i] !~ /[0-9]+/) + arr[i] = 0 + 0; + else + arr[i] = arr[i] + 0; + } + if (arr[1] == 4 && arr[2] == 6 && arr[3] >= 8) + ret = 1; + else if (arr[1] == 4 && arr[2] > 6) + ret = 1; + else if (arr[1] > 4) + ret = 1; + delete arr; + print ret; + }' )" + if [ "${oldRemote}" != "0" ]; then + if [ "${PATH_LZ}" = "/jffs/scripts/lz" ]; then + "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" "X" && upgrade_restart="1" + else + "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" "entwareX" && upgrade_restart="1" + fi else - "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" "entware" && [ -s "${PATH_LZ}/lz_rule.sh" ] && "${PATH_LZ}/lz_rule.sh" + if [ "${PATH_LZ}" = "/jffs/scripts/lz" ]; then + "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" && upgrade_restart="1" + else + "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" "entware" && upgrade_restart="1" + fi fi else { @@ -313,6 +346,8 @@ case "${2}" in printf "%s [%s]:\n" "$( date +"%F %T" )" "${$}" } >> "/tmp/syslog.log" fi + flock -u "${LOCK_FILE_ID}" > /dev/null 2>&1 + [ "${upgrade_restart}" ] && [ -s "${PATH_LZ}/lz_rule.sh" ] && "${PATH_LZ}/lz_rule.sh" } do_update & ;; diff --git a/source_codes/lz/js/lz_policy_routing.js b/source_codes/lz/js/lz_policy_routing.js index 028ce73c..90da7ef9 100644 --- a/source_codes/lz/js/lz_policy_routing.js +++ b/source_codes/lz/js/lz_policy_routing.js @@ -1,5 +1,5 @@ /* -# lz_policy_routing.js v4.6.7 +# lz_policy_routing.js v4.6.8 # By LZ 妙妙呜 (larsonzhang@gmail.com) # LZ JavaScript for Asuswrt-Merlin Router diff --git a/source_codes/lz/lz_rule.sh b/source_codes/lz/lz_rule.sh index f67f5307..a453c6d8 100644 --- a/source_codes/lz/lz_rule.sh +++ b/source_codes/lz/lz_rule.sh @@ -1,5 +1,5 @@ #!/bin/sh -# lz_rule.sh v4.6.7 +# lz_rule.sh v4.6.8 # By LZ 妙妙呜 (larsonzhang@gmail.com) # 本软件采用CIDR(无类别域间路由,Classless Inter-Domain Routing)技术,是一个在Internet上创建附加地 @@ -86,7 +86,7 @@ ## -------------全局数据定义及初始化------------------- ## 版本号 -LZ_VERSION=v4.6.7 +LZ_VERSION=v4.6.8 ## 治理ASD进程删我文件 ## 0--启用(缺省);非0--躺平 @@ -1744,10 +1744,36 @@ if lz_project_file_management "${1}"; then if [ -s "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" ]; then chmod 775 "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" sed -i "s/elif \[ \"\${USER}\" = \"root\" \]; then/elif \[ \"\${USER}\" = \"\" \]; then/g" "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" 2> /dev/null - if [ "${PATH_LZ}" = "/jffs/scripts/lz" ]; then - "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" && upgrade_restart="1" + local oldRemote="$( awk -v ver="${remoteVer##*v}" 'BEGIN{ + ret = 0; + split(ver, arr, "."); + for (i = 1; i < 4; ++i) { + if (arr[i] !~ /[0-9]+/) + arr[i] = 0 + 0; + else + arr[i] = arr[i] + 0; + } + if (arr[1] == 4 && arr[2] == 6 && arr[3] >= 8) + ret = 1; + else if (arr[1] == 4 && arr[2] > 6) + ret = 1; + else if (arr[1] > 4) + ret = 1; + delete arr; + print ret; + }' )" + if [ "${oldRemote}" != "0" ]; then + if [ "${PATH_LZ}" = "/jffs/scripts/lz" ]; then + "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" "X" && upgrade_restart="1" + else + "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" "entwareX" && upgrade_restart="1" + fi else - "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" "entware" && upgrade_restart="1" + if [ "${PATH_LZ}" = "/jffs/scripts/lz" ]; then + "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" && upgrade_restart="1" + else + "${PATH_LZ}/tmp/doupdate/lz_rule-${remoteVer}/install.sh" "entware" && upgrade_restart="1" + fi fi else { diff --git a/source_codes/lz/uninstall.sh b/source_codes/lz/uninstall.sh index b6a94565..a8c66092 100644 --- a/source_codes/lz/uninstall.sh +++ b/source_codes/lz/uninstall.sh @@ -1,5 +1,5 @@ #!/bin/sh -# uninstall.sh v4.6.7 +# uninstall.sh v4.6.8 # By LZ (larsonzhang@gmail.com) # LZ RULE script for Asuswrt-Merlin Router @@ -8,9 +8,13 @@ #BEGIN -LZ_VERSION=v4.6.7 +LZ_VERSION=v4.6.8 CURRENT_PATH="${0%/*}" [ "${CURRENT_PATH:0:1}" != '/' ] && CURRENT_PATH="$( pwd )${CURRENT_PATH#*.}" +PATH_LOCK="/var/lock" LOCK_FILE_ID="555" +LOCK_FILE="${PATH_LOCK}/lz_rule.lock" +PATH_HOME="$( readlink -f "/root" )" +{ [ -z "${PATH_HOME}" ] || [ "${PATH_HOME}" = '/' ]; } && PATH_HOME="$( readlink -f "/tmp" )" SYSLOG="/tmp/syslog.log" lzdate() { date +"%F %T"; } @@ -22,6 +26,9 @@ lzdate() { date +"%F %T"; } echo } | tee -ai "${SYSLOG}" 2> /dev/null +[ ! -d "${PATH_LOCK}" ] && { mkdir -p "${PATH_LOCK}" > /dev/null 2>&1; chmod 777 "${PATH_LOCK}" > /dev/null 2>&1; } +eval "exec ${LOCK_FILE_ID}<>${LOCK_FILE}"; flock -x "${LOCK_FILE_ID}" > /dev/null 2>&1; + if [ ! -f "${CURRENT_PATH}/lz_rule.sh" ]; then { echo "$(lzdate)" [$$]: "${CURRENT_PATH}/lz_rule.sh" does not exist. @@ -29,6 +36,7 @@ if [ ! -f "${CURRENT_PATH}/lz_rule.sh" ]; then echo " LZ script uninstallation failed." echo -e " $(lzdate)\n\n" } | tee -ai "${SYSLOG}" 2> /dev/null + flock -u "${LOCK_FILE_ID}" > /dev/null 2>&1 exit "1" else chmod +x "${CURRENT_PATH}/lz_rule.sh" > /dev/null 2>&1 @@ -105,7 +113,9 @@ rmdir "${CURRENT_PATH}" > /dev/null 2>&1 echo -e " $(lzdate)\n\n" } | tee -ai "${SYSLOG}" 2> /dev/null -[ ! -d "${CURRENT_PATH}" ] && { cd "${CURRENT_PATH%/*}/" || { cd "${HOME}/" || exit "0"; }; } +flock -u "${LOCK_FILE_ID}" > /dev/null 2>&1 + +[ ! -d "${CURRENT_PATH}" ] && { cd "${CURRENT_PATH%/*}/" || { cd "${PATH_HOME}/" || exit "0"; }; } exit "0" diff --git a/source_codes/lz/webs/LZ_Policy_Routing_Content.asp b/source_codes/lz/webs/LZ_Policy_Routing_Content.asp index 77aca673..4c08981a 100644 --- a/source_codes/lz/webs/LZ_Policy_Routing_Content.asp +++ b/source_codes/lz/webs/LZ_Policy_Routing_Content.asp @@ -83,7 +83,7 @@ url: '/ext/lzr/LZRGlobal.html', dataType: 'text', success: function(response) { - // v4.6.7 + // v4.6.8 retVal = (response.match(/QnkgTFog5aaZ5aaZ5ZGc77yI6Juk6J[\+]G5aKp5YS[\/]77yJ/m) != null) ? true : false; } });