mirror of
https://github.com/bolucat/Archive.git
synced 2026-04-23 00:17:16 +08:00
Update On Thu Jan 2 19:33:20 CET 2025
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
require 'nixio'
|
||||
require 'luci.sys'
|
||||
local luci = luci
|
||||
local ucic = luci.model.uci.cursor()
|
||||
local jsonc = require "luci.jsonc"
|
||||
local name = 'passwall2'
|
||||
local api = require "luci.passwall2.api"
|
||||
local name = api.appname
|
||||
local fs = api.fs
|
||||
local sys = api.sys
|
||||
local uci = api.uci
|
||||
local jsonc = api.jsonc
|
||||
|
||||
local arg1 = arg[1]
|
||||
local arg2 = arg[2]
|
||||
local arg3 = arg[3]
|
||||
@@ -14,13 +14,13 @@ local arg3 = arg[3]
|
||||
local reboot = 0
|
||||
local geoip_update = 0
|
||||
local geosite_update = 0
|
||||
local asset_location = ucic:get_first(name, 'global_rules', "v2ray_location_asset", "/usr/share/v2ray/")
|
||||
local asset_location = uci:get_first(name, 'global_rules', "v2ray_location_asset", "/usr/share/v2ray/")
|
||||
|
||||
-- Custom geo file
|
||||
local geoip_api = ucic:get_first(name, 'global_rules', "geoip_url", "https://api.github.com/repos/Loyalsoldier/v2ray-rules-dat/releases/latest")
|
||||
local geosite_api = ucic:get_first(name, 'global_rules', "geosite_url", "https://api.github.com/repos/Loyalsoldier/v2ray-rules-dat/releases/latest")
|
||||
local geoip_api = uci:get_first(name, 'global_rules', "geoip_url", "https://api.github.com/repos/Loyalsoldier/v2ray-rules-dat/releases/latest")
|
||||
local geosite_api = uci:get_first(name, 'global_rules', "geosite_url", "https://api.github.com/repos/Loyalsoldier/v2ray-rules-dat/releases/latest")
|
||||
--
|
||||
local use_nft = ucic:get(name, "@global_forwarding[0]", "use_nft") or "0"
|
||||
local use_nft = uci:get(name, "@global_forwarding[0]", "use_nft") or "0"
|
||||
|
||||
if arg3 == "cron" then
|
||||
arg2 = nil
|
||||
@@ -67,9 +67,9 @@ local function fetch_geoip()
|
||||
f:write(content:gsub("geoip.dat", "/tmp/geoip.dat"), "")
|
||||
f:close()
|
||||
|
||||
if nixio.fs.access(asset_location .. "geoip.dat") then
|
||||
luci.sys.call(string.format("cp -f %s %s", asset_location .. "geoip.dat", "/tmp/geoip.dat"))
|
||||
if luci.sys.call('sha256sum -c /tmp/geoip.dat.sha256sum > /dev/null 2>&1') == 0 then
|
||||
if fs.access(asset_location .. "geoip.dat") then
|
||||
sys.call(string.format("cp -f %s %s", asset_location .. "geoip.dat", "/tmp/geoip.dat"))
|
||||
if sys.call('sha256sum -c /tmp/geoip.dat.sha256sum > /dev/null 2>&1') == 0 then
|
||||
log("geoip 版本一致,无需更新。")
|
||||
return 1
|
||||
end
|
||||
@@ -77,8 +77,8 @@ local function fetch_geoip()
|
||||
for _2, v2 in ipairs(json.assets) do
|
||||
if v2.name and v2.name == "geoip.dat" then
|
||||
sret = curl(v2.browser_download_url, "/tmp/geoip.dat")
|
||||
if luci.sys.call('sha256sum -c /tmp/geoip.dat.sha256sum > /dev/null 2>&1') == 0 then
|
||||
luci.sys.call(string.format("mkdir -p %s && cp -f %s %s", asset_location, "/tmp/geoip.dat", asset_location .. "geoip.dat"))
|
||||
if sys.call('sha256sum -c /tmp/geoip.dat.sha256sum > /dev/null 2>&1') == 0 then
|
||||
sys.call(string.format("mkdir -p %s && cp -f %s %s", asset_location, "/tmp/geoip.dat", asset_location .. "geoip.dat"))
|
||||
reboot = 1
|
||||
log("geoip 更新成功。")
|
||||
return 1
|
||||
@@ -118,9 +118,9 @@ local function fetch_geosite()
|
||||
f:write(content:gsub("[^%s]+.dat", "/tmp/geosite.dat"), "")
|
||||
f:close()
|
||||
|
||||
if nixio.fs.access(asset_location .. "geosite.dat") then
|
||||
luci.sys.call(string.format("cp -f %s %s", asset_location .. "geosite.dat", "/tmp/geosite.dat"))
|
||||
if luci.sys.call('sha256sum -c /tmp/geosite.dat.sha256sum > /dev/null 2>&1') == 0 then
|
||||
if fs.access(asset_location .. "geosite.dat") then
|
||||
sys.call(string.format("cp -f %s %s", asset_location .. "geosite.dat", "/tmp/geosite.dat"))
|
||||
if sys.call('sha256sum -c /tmp/geosite.dat.sha256sum > /dev/null 2>&1') == 0 then
|
||||
log("geosite 版本一致,无需更新。")
|
||||
return 1
|
||||
end
|
||||
@@ -128,8 +128,8 @@ local function fetch_geosite()
|
||||
for _2, v2 in ipairs(json.assets) do
|
||||
if v2.name and (v2.name == "geosite.dat" or v2.name == "dlc.dat") then
|
||||
sret = curl(v2.browser_download_url, "/tmp/geosite.dat")
|
||||
if luci.sys.call('sha256sum -c /tmp/geosite.dat.sha256sum > /dev/null 2>&1') == 0 then
|
||||
luci.sys.call(string.format("mkdir -p %s && cp -f %s %s", asset_location, "/tmp/geosite.dat", asset_location .. "geosite.dat"))
|
||||
if sys.call('sha256sum -c /tmp/geosite.dat.sha256sum > /dev/null 2>&1') == 0 then
|
||||
sys.call(string.format("mkdir -p %s && cp -f %s %s", asset_location, "/tmp/geosite.dat", asset_location .. "geosite.dat"))
|
||||
reboot = 1
|
||||
log("geosite 更新成功。")
|
||||
return 1
|
||||
@@ -161,8 +161,8 @@ if arg2 then
|
||||
end
|
||||
end)
|
||||
else
|
||||
geoip_update = ucic:get_first(name, 'global_rules', "geoip_update", 1)
|
||||
geosite_update = ucic:get_first(name, 'global_rules', "geosite_update", 1)
|
||||
geoip_update = uci:get_first(name, 'global_rules', "geoip_update", 1)
|
||||
geosite_update = uci:get_first(name, 'global_rules', "geosite_update", 1)
|
||||
end
|
||||
if geoip_update == 0 and geosite_update == 0 then
|
||||
os.exit(0)
|
||||
@@ -184,23 +184,22 @@ if tonumber(geosite_update) == 1 then
|
||||
os.remove("/tmp/geosite.dat.sha256sum")
|
||||
end
|
||||
|
||||
ucic:set(name, ucic:get_first(name, 'global_rules'), "geoip_update", geoip_update)
|
||||
ucic:set(name, ucic:get_first(name, 'global_rules'), "geosite_update", geosite_update)
|
||||
ucic:save(name)
|
||||
luci.sys.call("uci commit " .. name)
|
||||
uci:set(name, uci:get_first(name, 'global_rules'), "geoip_update", geoip_update)
|
||||
uci:set(name, uci:get_first(name, 'global_rules'), "geosite_update", geosite_update)
|
||||
api.uci_save(uci, name, true)
|
||||
|
||||
if reboot == 1 then
|
||||
if arg3 == "cron" then
|
||||
if not nixio.fs.access("/var/lock/" .. name .. ".lock") then
|
||||
luci.sys.call("touch /tmp/lock/" .. name .. "_cron.lock")
|
||||
if not fs.access("/var/lock/" .. name .. ".lock") then
|
||||
sys.call("touch /tmp/lock/" .. name .. "_cron.lock")
|
||||
end
|
||||
end
|
||||
|
||||
log("重启服务,应用新的规则。")
|
||||
if use_nft == "1" then
|
||||
luci.sys.call("sh /usr/share/" .. name .. "/nftables.sh flush_nftset_reload > /dev/null 2>&1 &")
|
||||
sys.call("sh /usr/share/" .. name .. "/nftables.sh flush_nftset_reload > /dev/null 2>&1 &")
|
||||
else
|
||||
luci.sys.call("sh /usr/share/" .. name .. "/iptables.sh flush_ipset_reload > /dev/null 2>&1 &")
|
||||
sys.call("sh /usr/share/" .. name .. "/iptables.sh flush_ipset_reload > /dev/null 2>&1 &")
|
||||
end
|
||||
end
|
||||
log("规则更新完毕...")
|
||||
|
||||
Reference in New Issue
Block a user