Utoljára aktív 2 months ago

nuno gist felülvizsgálása 2 months ago. Revízióhoz ugrás

1 file changed, 39 insertions

gistfile1.txt(fájl létrehozva)

@@ -0,0 +1,39 @@
1 + function firewall::apply_preset() {
2 + local name="$1"
3 + local client_ip="$2"
4 + local preset_file
5 + preset_file="$(ctx::preset::path "${name}.preset")"
6 +
7 + if [[ ! -f "$preset_file" ]]; then
8 + log::error "Preset not found: ${name}"
9 + return 1
10 + fi
11 +
12 + source "$preset_file"
13 +
14 + if [[ -n "${BLOCK_IPS:-}" ]]; then
15 + for ip in $BLOCK_IPS; do
16 + firewall::block_ip "$client_ip" "$ip"
17 + firewall::save_block "$client_ip" "$client_ip" "$ip"
18 + done
19 + fi
20 +
21 + if [[ -n "${BLOCK_SUBNETS:-}" ]]; then
22 + for subnet in $BLOCK_SUBNETS; do
23 + firewall::block_subnet "$client_ip" "$subnet"
24 + firewall::save_block "$client_ip" "$client_ip" "$subnet"
25 + done
26 + fi
27 +
28 + if [[ -n "${BLOCK_PORTS:-}" ]]; then
29 + for entry in $BLOCK_PORTS; do
30 + local target port proto
31 + IFS=":" read -r target port proto <<< "$entry"
32 + proto="${proto:-tcp}"
33 + firewall::block_port "$client_ip" "$target" "$port" "$proto"
34 + firewall::save_block "$name" "$client_ip" "$target" "$port" "$proto"
35 + done
36 + fi
37 +
38 + log::wg_preset "Applied preset '${name}' to: ${client_ip}"
39 + }
Újabb Régebbi