firewall.module
· 766 B · Text
Surowy
function firewall::restore_blocks() {
local blocks_dir
blocks_dir="$(ctx::blocks)"
# Restore rules from meta files (new system)
rule::restore_all
# Restore per-client full-blocks (wgctl block/unblock system)
for block_file in "${blocks_dir}"/*.block; do
[[ -f "$block_file" ]] || continue
local name
name=$(basename "$block_file" .block)
while IFS=" " read -r client_ip target port proto; do
if [[ -z "$target" ]]; then
firewall::block_all "$client_ip" "$name"
elif [[ -n "$port" ]]; then
firewall::block_port "$client_ip" "$target" "$port" "${proto:-tcp}"
else
firewall::block_ip "$client_ip" "$target"
fi
done < "$block_file"
log::wg "Restored block rules for: ${name}"
done
}
| 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 | } |