luci-app-passwall: sync upstream

last commit: 3c2d4f2d4f
This commit is contained in:
actions 2024-05-25 17:30:05 +08:00
parent ffc5ac375e
commit 5a09275b10
8 changed files with 229 additions and 36 deletions

View File

@ -130,19 +130,41 @@ o = s:option(Flag, "auto_update", translate("Enable auto update subscribe"))
o.default = 0 o.default = 0
o.rmempty = false o.rmempty = false
---- Week update rules ---- Week Update
o = s:option(ListValue, "week_update", translate("Week update rules")) o = s:option(ListValue, "week_update", translate("Update Mode"))
o:value(8, translate("Loop Mode"))
o:value(7, translate("Every day")) o:value(7, translate("Every day"))
for e = 1, 6 do o:value(e, translate("Week") .. e) end o:value(1, translate("Every Monday"))
o:value(0, translate("Week") .. translate("day")) o:value(2, translate("Every Tuesday"))
o.default = 0 o:value(3, translate("Every Wednesday"))
o:value(4, translate("Every Thursday"))
o:value(5, translate("Every Friday"))
o:value(6, translate("Every Saturday"))
o:value(0, translate("Every Sunday"))
o.default = 7
o:depends("auto_update", true) o:depends("auto_update", true)
o.rmempty = true
---- Day update rules ---- Time Update
o = s:option(ListValue, "time_update", translate("Day update rules")) o = s:option(ListValue, "time_update", translate("Update Time(every day)"))
for e = 0, 23 do o:value(e, e .. translate("oclock")) end for t = 0, 23 do o:value(t, t .. ":00") end
o.default = 0 o.default = 0
o:depends("auto_update", true) o:depends("week_update", "0")
o:depends("week_update", "1")
o:depends("week_update", "2")
o:depends("week_update", "3")
o:depends("week_update", "4")
o:depends("week_update", "5")
o:depends("week_update", "6")
o:depends("week_update", "7")
o.rmempty = true
---- Interval Update
o = s:option(ListValue, "interval_update", translate("Update Interval(hour)"))
for t = 1, 24 do o:value(t, t .. " " .. translate("hour")) end
o.default = 2
o:depends("week_update", "8")
o.rmempty = true
o = s:option(Value, "user_agent", translate("User-Agent")) o = s:option(Value, "user_agent", translate("User-Agent"))
o.default = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0" o.default = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0"

View File

@ -48,18 +48,40 @@ o.default = 0
o.rmempty = false o.rmempty = false
---- Week Update ---- Week Update
o = s:option(ListValue, "week_update", translate("Week update rules")) o = s:option(ListValue, "week_update", translate("Update Mode"))
o:value(8, translate("Loop Mode"))
o:value(7, translate("Every day")) o:value(7, translate("Every day"))
for e = 1, 6 do o:value(e, translate("Week") .. e) end o:value(1, translate("Every Monday"))
o:value(0, translate("Week") .. translate("day")) o:value(2, translate("Every Tuesday"))
o.default = 0 o:value(3, translate("Every Wednesday"))
o:value(4, translate("Every Thursday"))
o:value(5, translate("Every Friday"))
o:value(6, translate("Every Saturday"))
o:value(0, translate("Every Sunday"))
o.default = 7
o:depends("auto_update", true) o:depends("auto_update", true)
o.rmempty = true
---- Time Update ---- Time Update
o = s:option(ListValue, "time_update", translate("Day update rules")) o = s:option(ListValue, "time_update", translate("Update Time(every day)"))
for e = 0, 23 do o:value(e, e .. translate("oclock")) end for t = 0, 23 do o:value(t, t .. ":00") end
o.default = 0 o.default = 0
o:depends("auto_update", true) o:depends("week_update", "0")
o:depends("week_update", "1")
o:depends("week_update", "2")
o:depends("week_update", "3")
o:depends("week_update", "4")
o:depends("week_update", "5")
o:depends("week_update", "6")
o:depends("week_update", "7")
o.rmempty = true
---- Interval Update
o = s:option(ListValue, "interval_update", translate("Update Interval(hour)"))
for t = 1, 24 do o:value(t, t .. " " .. translate("hour")) end
o.default = 2
o:depends("week_update", "8")
o.rmempty = true
if has_xray or has_singbox then if has_xray or has_singbox then
o = s:option(Value, "v2ray_location_asset", translate("Location of V2ray/Xray asset"), translate("This variable specifies a directory where geoip.dat and geosite.dat files are.")) o = s:option(Value, "v2ray_location_asset", translate("Location of V2ray/Xray asset"), translate("This variable specifies a directory where geoip.dat and geosite.dat files are."))

View File

@ -838,23 +838,44 @@ msgstr "规则版本"
msgid "Enable auto update rules" msgid "Enable auto update rules"
msgstr "开启自动更新规则" msgstr "开启自动更新规则"
msgid "Week update rules" msgid "Update Time(every day)"
msgstr "更新时间星期" msgstr "更新时间(每天)"
msgid "Day update rules" msgid "Update Interval(hour)"
msgstr "更新时间小时" msgstr "更新间隔(小时)"
msgid "Update Mode"
msgstr "更新模式"
msgid "Loop Mode"
msgstr "循环"
msgid "Every day" msgid "Every day"
msgstr "每天" msgstr "每天"
msgid "day" msgid "Every Monday"
msgstr "日" msgstr "每周一"
msgid "Week" msgid "Every Tuesday"
msgstr "周" msgstr ""
msgid "oclock" msgid "Every Wednesday"
msgstr "点" msgstr "每周三"
msgid "Every Thursday"
msgstr "每周四"
msgid "Every Friday"
msgstr "每周五"
msgid "Every Saturday"
msgstr "每周六"
msgid "Every Sunday"
msgstr "每周日"
msgid "hour"
msgstr "小时"
msgid "Location of V2ray/Xray asset" msgid "Location of V2ray/Xray asset"
msgstr "V2ray/Xray 资源文件目录" msgstr "V2ray/Xray 资源文件目录"

View File

@ -1143,19 +1143,36 @@ clean_log() {
} }
clean_crontab() { clean_crontab() {
[ -f "/tmp/lock/${CONFIG}_cron.lock" ] && return
touch /etc/crontabs/root touch /etc/crontabs/root
#sed -i "/${CONFIG}/d" /etc/crontabs/root >/dev/null 2>&1 #sed -i "/${CONFIG}/d" /etc/crontabs/root >/dev/null 2>&1
sed -i "/$(echo "/etc/init.d/${CONFIG}" | sed 's#\/#\\\/#g')/d" /etc/crontabs/root >/dev/null 2>&1 sed -i "/$(echo "/etc/init.d/${CONFIG}" | sed 's#\/#\\\/#g')/d" /etc/crontabs/root >/dev/null 2>&1
sed -i "/$(echo "lua ${APP_PATH}/rule_update.lua log" | sed 's#\/#\\\/#g')/d" /etc/crontabs/root >/dev/null 2>&1 sed -i "/$(echo "lua ${APP_PATH}/rule_update.lua log" | sed 's#\/#\\\/#g')/d" /etc/crontabs/root >/dev/null 2>&1
sed -i "/$(echo "lua ${APP_PATH}/subscribe.lua start" | sed 's#\/#\\\/#g')/d" /etc/crontabs/root >/dev/null 2>&1 sed -i "/$(echo "lua ${APP_PATH}/subscribe.lua start" | sed 's#\/#\\\/#g')/d" /etc/crontabs/root >/dev/null 2>&1
pgrep -af "${CONFIG}/" | awk '/tasks\.sh/{print $1}' | xargs kill -9 >/dev/null 2>&1
rm -rf /tmp/lock/${CONFIG}_tasks.lock
} }
start_crontab() { start_crontab() {
if [ "$ENABLED_DEFAULT_ACL" == 1 ] || [ "$ENABLED_ACLS" == 1 ]; then
start_daemon=$(config_t_get global_delay start_daemon 0)
[ "$start_daemon" = "1" ] && $APP_PATH/monitor.sh > /dev/null 2>&1 &
fi
[ -f "/tmp/lock/${CONFIG}_cron.lock" ] && {
rm -rf "/tmp/lock/${CONFIG}_cron.lock"
echolog "当前为计划任务自动运行,不重新配置定时任务。"
return
}
clean_crontab clean_crontab
[ "$ENABLED" != 1 ] && { [ "$ENABLED" != 1 ] && {
/etc/init.d/cron restart /etc/init.d/cron restart
return return
} }
auto_on=$(config_t_get global_delay auto_on 0) auto_on=$(config_t_get global_delay auto_on 0)
if [ "$auto_on" = "1" ]; then if [ "$auto_on" = "1" ]; then
time_off=$(config_t_get global_delay time_off) time_off=$(config_t_get global_delay time_off)
@ -1181,7 +1198,11 @@ start_crontab() {
if [ "$autoupdate" = "1" ]; then if [ "$autoupdate" = "1" ]; then
local t="0 $dayupdate * * $weekupdate" local t="0 $dayupdate * * $weekupdate"
[ "$weekupdate" = "7" ] && t="0 $dayupdate * * *" [ "$weekupdate" = "7" ] && t="0 $dayupdate * * *"
echo "$t lua $APP_PATH/rule_update.lua log > /dev/null 2>&1 &" >>/etc/crontabs/root if [ "$weekupdate" = "8" ]; then
update_loop=1
else
echo "$t lua $APP_PATH/rule_update.lua log all cron > /dev/null 2>&1 &" >>/etc/crontabs/root
fi
echolog "配置定时任务:自动更新规则。" echolog "配置定时任务:自动更新规则。"
fi fi
@ -1202,17 +1223,23 @@ start_crontab() {
for name in $(ls ${TMP_SUB_PATH}); do for name in $(ls ${TMP_SUB_PATH}); do
week_update=$(echo $name | awk -F '_' '{print $1}') week_update=$(echo $name | awk -F '_' '{print $1}')
time_update=$(echo $name | awk -F '_' '{print $2}') time_update=$(echo $name | awk -F '_' '{print $2}')
cfgids=$(echo -n $(cat ${TMP_SUB_PATH}/${name}) | sed 's# #,#g')
local t="0 $time_update * * $week_update" local t="0 $time_update * * $week_update"
[ "$week_update" = "7" ] && t="0 $time_update * * *" [ "$week_update" = "7" ] && t="0 $time_update * * *"
cfgids=$(echo -n $(cat ${TMP_SUB_PATH}/${name}) | sed 's# #,#g') if [ "$week_update" = "8" ]; then
echo "$t lua $APP_PATH/subscribe.lua start $cfgids > /dev/null 2>&1 &" >>/etc/crontabs/root update_loop=1
else
echo "$t lua $APP_PATH/subscribe.lua start $cfgids cron > /dev/null 2>&1 &" >>/etc/crontabs/root
fi
done done
rm -rf $TMP_SUB_PATH rm -rf $TMP_SUB_PATH
} }
if [ "$ENABLED_DEFAULT_ACL" == 1 ] || [ "$ENABLED_ACLS" == 1 ]; then if [ "$ENABLED_DEFAULT_ACL" == 1 ] || [ "$ENABLED_ACLS" == 1 ]; then
start_daemon=$(config_t_get global_delay start_daemon 0) [ "$update_loop" = "1" ] && {
[ "$start_daemon" = "1" ] && $APP_PATH/monitor.sh > /dev/null 2>&1 & $APP_PATH/tasks.sh > /dev/null 2>&1 &
echolog "自动更新:启动循环更新进程。"
}
else else
echolog "运行于非代理模式,仅允许服务启停的定时任务。" echolog "运行于非代理模式,仅允许服务启停的定时任务。"
fi fi
@ -1221,6 +1248,7 @@ start_crontab() {
} }
stop_crontab() { stop_crontab() {
[ -f "/tmp/lock/${CONFIG}_cron.lock" ] && return
clean_crontab clean_crontab
/etc/init.d/cron restart /etc/init.d/cron restart
#echolog "清除定时执行命令。" #echolog "清除定时执行命令。"
@ -1717,7 +1745,7 @@ stop() {
delete_ip2route delete_ip2route
kill_all v2ray-plugin obfs-local kill_all v2ray-plugin obfs-local
pgrep -f "sleep.*(6s|9s|58s)" | xargs kill -9 >/dev/null 2>&1 pgrep -f "sleep.*(6s|9s|58s)" | xargs kill -9 >/dev/null 2>&1
pgrep -af "${CONFIG}/" | awk '! /app\.sh|subscribe\.lua|rule_update\.lua/{print $1}' | xargs kill -9 >/dev/null 2>&1 pgrep -af "${CONFIG}/" | awk '! /app\.sh|subscribe\.lua|rule_update\.lua|tasks\.sh/{print $1}' | xargs kill -9 >/dev/null 2>&1
unset V2RAY_LOCATION_ASSET unset V2RAY_LOCATION_ASSET
unset XRAY_LOCATION_ASSET unset XRAY_LOCATION_ASSET
stop_crontab stop_crontab

View File

@ -8,6 +8,8 @@ local jsonc = require "luci.jsonc"
local name = 'passwall' local name = 'passwall'
local api = require ("luci.passwall.api") local api = require ("luci.passwall.api")
local arg1 = arg[1] local arg1 = arg[1]
local arg2 = arg[2]
local arg3 = arg[3]
local rule_path = "/usr/share/" .. name .. "/rules" local rule_path = "/usr/share/" .. name .. "/rules"
local reboot = 0 local reboot = 0
@ -35,6 +37,10 @@ local geosite_api = "https://api.github.com/repos/Loyalsoldier/v2ray-rules-dat/
local asset_location = ucic:get_first(name, 'global_rules', "v2ray_location_asset", "/usr/share/v2ray/") local asset_location = ucic:get_first(name, 'global_rules', "v2ray_location_asset", "/usr/share/v2ray/")
local use_nft = ucic:get(name, "@global_forwarding[0]", "use_nft") or "0" local use_nft = ucic:get(name, "@global_forwarding[0]", "use_nft") or "0"
if arg3 == "cron" then
arg2 = nil
end
local log = function(...) local log = function(...)
if arg1 then if arg1 then
if arg1 == "log" then if arg1 == "log" then
@ -369,8 +375,8 @@ local function fetch_geosite()
return 0 return 0
end end
if arg[2] then if arg2 then
string.gsub(arg[2], '[^' .. "," .. ']+', function(w) string.gsub(arg2, '[^' .. "," .. ']+', function(w)
if w == "gfwlist" then if w == "gfwlist" then
gfwlist_update = 1 gfwlist_update = 1
end end
@ -459,6 +465,15 @@ ucic:save(name)
luci.sys.call("uci commit " .. name) luci.sys.call("uci commit " .. name)
if reboot == 1 then if reboot == 1 then
if arg3 == "cron" then
local f = io.open("/var/lock/" .. name .. ".lock", "r")
if f == nil then
luci.sys.call("touch /tmp/lock/" .. name .. "_cron.lock")
else
f:close()
end
end
log("重启服务,应用新的规则。") log("重启服务,应用新的规则。")
if use_nft == "1" then if use_nft == "1" then
luci.sys.call("sh /usr/share/" .. name .. "/nftables.sh flush_nftset_reload > /dev/null 2>&1 &") luci.sys.call("sh /usr/share/" .. name .. "/nftables.sh flush_nftset_reload > /dev/null 2>&1 &")

View File

@ -1164,6 +1164,16 @@ local function update_node(manual)
uci:commit(appname) uci:commit(appname)
end end
if arg[3] == "cron" then
local f = io.open("/var/lock/" .. appname .. ".lock", "r")
if f == nil then
luci.sys.call("touch /tmp/lock/" .. appname .. "_cron.lock")
else
f:close()
end
end
luci.sys.call("/etc/init.d/" .. appname .. " restart > /dev/null 2>&1 &") luci.sys.call("/etc/init.d/" .. appname .. " restart > /dev/null 2>&1 &")
end end

View File

@ -0,0 +1,75 @@
#!/bin/sh
## 循环更新脚本
CONFIG=passwall
APP_PATH=/usr/share/$CONFIG
TMP_PATH=/tmp/etc/$CONFIG
LOCK_FILE=/tmp/lock/${CONFIG}_tasks.lock
CFG_UPDATE_INT=0
config_n_get() {
local ret=$(uci -q get "${CONFIG}.${1}.${2}" 2>/dev/null)
echo "${ret:=$3}"
}
config_t_get() {
local index=${4:-0}
local ret=$(uci -q get "${CONFIG}.@${1}[${index}].${2}" 2>/dev/null)
echo "${ret:=${3}}"
}
exec 99>"$LOCK_FILE"
flock -n 99
if [ "$?" != 0 ]; then
exit 0
fi
while true
do
if [ "$CFG_UPDATE_INT" -ne 0 ]; then
autoupdate=$(config_t_get global_rules auto_update)
weekupdate=$(config_t_get global_rules week_update)
hourupdate=$(config_t_get global_rules interval_update)
hourupdate=$(expr "$hourupdate" \* 60)
if [ "$autoupdate" = "1" ]; then
[ "$weekupdate" = "8" ] && {
[ "$(expr "$CFG_UPDATE_INT" % "$hourupdate")" -eq 0 ] && lua $APP_PATH/rule_update.lua log all cron > /dev/null 2>&1 &
}
fi
TMP_SUB_PATH=$TMP_PATH/sub_tasks
mkdir -p $TMP_SUB_PATH
for item in $(uci show ${CONFIG} | grep "=subscribe_list" | cut -d '.' -sf 2 | cut -d '=' -sf 1); do
if [ "$(config_n_get $item auto_update 0)" = "1" ]; then
cfgid=$(uci show ${CONFIG}.$item | head -n 1 | cut -d '.' -sf 2 | cut -d '=' -sf 1)
remark=$(config_n_get $item remark)
week_update=$(config_n_get $item week_update)
hour_update=$(config_n_get $item interval_update)
echo "$cfgid" >> $TMP_SUB_PATH/${week_update}_${hour_update}
fi
done
[ -d "${TMP_SUB_PATH}" ] && {
for name in $(ls ${TMP_SUB_PATH}); do
week_update=$(echo $name | awk -F '_' '{print $1}')
hour_update=$(echo $name | awk -F '_' '{print $2}')
hour_update=$(expr "$hour_update" \* 60)
cfgids=$(echo -n $(cat ${TMP_SUB_PATH}/${name}) | sed 's# #,#g')
[ "$week_update" = "8" ] && {
[ "$(expr "$CFG_UPDATE_INT" % "$hour_update")" -eq 0 ] && lua $APP_PATH/subscribe.lua start $cfgids cron > /dev/null 2>&1 &
}
done
rm -rf $TMP_SUB_PATH
}
fi
CFG_UPDATE_INT=$(expr "$CFG_UPDATE_INT" + 10)
sleep 600
done 2>/dev/null

View File

@ -133,7 +133,7 @@ index 9682502..c8688e2 100644
-- [[ Subscribe Settings ]]-- -- [[ Subscribe Settings ]]--
s = m:section(TypedSection, "global_subscribe", "") s = m:section(TypedSection, "global_subscribe", "")
diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe_config.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe_config.lua diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe_config.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe_config.lua
index 55bb691..e13625a 100644 index 4d07ef4..d4d8c2c 100644
--- a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe_config.lua --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe_config.lua
+++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe_config.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe_config.lua
@@ -45,7 +45,6 @@ end @@ -45,7 +45,6 @@ end
@ -157,7 +157,7 @@ index 72997c3..04b70f3 100644
-- [[ Delay Settings ]]-- -- [[ Delay Settings ]]--
s = m:section(TypedSection, "global_delay", translate("Delay Settings")) s = m:section(TypedSection, "global_delay", translate("Delay Settings"))
diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/rule.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/rule.lua diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/rule.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/rule.lua
index 375cf9c..5823ce3 100644 index 8e6947d..505f689 100644
--- a/luci-app-passwall/luasrc/model/cbi/passwall/client/rule.lua --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/rule.lua
+++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/rule.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/rule.lua
@@ -4,8 +4,6 @@ local has_xray = api.finded_com("xray") @@ -4,8 +4,6 @@ local has_xray = api.finded_com("xray")