最終更新 2 months ago

nuno revised this gist 2 months ago. Go to revision

1 file changed, 24 insertions

firewall.module(file created)

@@ -0,0 +1,24 @@
1 + function 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 + }
Newer Older