nuno 已修改 2 months ago. 還原成這個修訂版本
1 file changed, 24 insertions
firewall.module(檔案已創建)
| @@ -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 | + | } | |
上一頁
下一頁