最后活跃于 2 months ago

修订 109b2bea2f79be9bec4ef25625fe71e7a221a6c7

firewall.module 原始文件
1function firewall::restore_blocks() {
2 local blocks_dir
3 blocks_dir="$(ctx::blocks)"
4
5 # Restore rules from meta files (new system)
6 rule::restore_all
7
8 # Restore per-client full-blocks (wgctl block/unblock system)
9 for block_file in "${blocks_dir}"/*.block; do
10 [[ -f "$block_file" ]] || continue
11 local name
12 name=$(basename "$block_file" .block)
13 while IFS=" " read -r client_ip target port proto; do
14 if [[ -z "$target" ]]; then
15 firewall::block_all "$client_ip" "$name"
16 elif [[ -n "$port" ]]; then
17 firewall::block_port "$client_ip" "$target" "$port" "${proto:-tcp}"
18 else
19 firewall::block_ip "$client_ip" "$target"
20 fi
21 done < "$block_file"
22 log::wg "Restored block rules for: ${name}"
23 done
24}