update 2026-08-27 00:43:46

This commit is contained in:
action committed 2026-08-27 00:43:46 +08:00
1 parent 1bfa02b7c5
commit f5a34d6fcf
1988 files changed
+833 -1523314

No files matched your search

@@ -34,28 +34,35 @@ local function ln_run(s, d, command, output)
return string.format("%s >%s 2>&1 &", d .. " " .. command, output)
end
local function remove_firewall_rules(defer_commit)
local to_delete = {}
uci:foreach("firewall", "rule", function(rule)
local name = rule[".name"]
if name and name:find(CONFIG, 1, true) == 1 then
table.insert(to_delete, name)
end
end)
if #to_delete > 0 then
for _, name in ipairs(to_delete) do
cmd("uci delete firewall." .. name)
end
if not defer_commit then
api.sh_uci_commit("firewall")
cmd("/etc/init.d/firewall reload >/dev/null 2>&1")
end
return true
end
return false
end
local function start()
local enabled = tonumber(api.uci_get_s("@global[0]", "enable") or 0)
if enabled == nil or enabled == 0 then
return
end
-- ==================== 启动前:清理所有旧防火墙规则 ====================
local fw_changed = false
local to_delete = {}
uci:foreach("firewall", "rule", function(rule)
if rule[".name"]:find(CONFIG) == 1 then
table.insert(to_delete, rule[".name"])
end
end)
for _, name in ipairs(to_delete) do
cmd("uci delete firewall." .. name)
fw_changed = true
end
if fw_changed then
cmd("uci commit firewall")
end
-- =========================================================================
-- 启动前清理所有旧防火墙规则
local fw_changed = remove_firewall_rules(true)
cmd(string.format("mkdir -p %s %s", CONFIG_PATH, TMP_BIN_PATH))
cmd(string.format("touch %s", LOG_APP_FILE))
@@ -170,43 +177,22 @@ local function start()
firewall_num = firewall_num + 1
local uid = CONFIG .. "_" .. id
cmd("uci set firewall." .. uid .. "=rule")
cmd("uci set firewall." .. uid .. ".name='".. uid .."'")
cmd("uci set firewall." .. uid .. ".src='" .. (server.firewall_allow_src or "wan") .. "'")
cmd("uci set firewall." .. uid .. ".dest_port='" .. port .. "'")
cmd("uci set firewall." .. uid .. ".target='ACCEPT'")
-- uci:section("firewall", "rule", uid)
-- uci:set("firewall", uid, "name", uid)
-- uci:set("firewall", uid, "src", server.firewall_allow_src or "wan")
-- uci:set("firewall", uid, "dest_port", port)
-- uci:set("firewall", uid, "target", "ACCEPT")
api.sh_uci_set("firewall", uid, "name", uid)
api.sh_uci_set("firewall", uid, "src", server.firewall_allow_src or "wan")
api.sh_uci_set("firewall", uid, "dest_port", port)
api.sh_uci_set("firewall", uid, "target", "ACCEPT")
end
end
end)
if firewall_num > 0 or fw_changed then
-- api.uci_save(uci, "firewall", true, true)
cmd("uci commit firewall")
api.sh_uci_commit("firewall")
cmd("/etc/init.d/firewall reload >/dev/null 2>&1")
end
end
local function stop()
cmd(string.format("/bin/busybox top -bn1 | grep -v 'grep' | grep '%s/' | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1", CONFIG_PATH))
if true then
local to_delete = {}
uci:foreach("firewall", "rule", function(rule)
if rule[".name"]:find(CONFIG) == 1 then
table.insert(to_delete, rule[".name"])
end
end)
if #to_delete > 0 then
for _, name in ipairs(to_delete) do
cmd("uci delete firewall." .. name)
end
cmd("uci commit firewall")
cmd("/etc/init.d/firewall reload >/dev/null 2>&1")
end
end
remove_firewall_rules()
cmd(string.format("rm -rf %s %s", CONFIG_PATH, LOG_APP_FILE))
end