gistfile1.txt
· 1.0 KiB · Text
Sin formato
function firewall::apply_preset() {
local name="$1"
local client_ip="$2"
local preset_file
preset_file="$(ctx::preset::path "${name}.preset")"
if [[ ! -f "$preset_file" ]]; then
log::error "Preset not found: ${name}"
return 1
fi
source "$preset_file"
if [[ -n "${BLOCK_IPS:-}" ]]; then
for ip in $BLOCK_IPS; do
firewall::block_ip "$client_ip" "$ip"
firewall::save_block "$client_ip" "$client_ip" "$ip"
done
fi
if [[ -n "${BLOCK_SUBNETS:-}" ]]; then
for subnet in $BLOCK_SUBNETS; do
firewall::block_subnet "$client_ip" "$subnet"
firewall::save_block "$client_ip" "$client_ip" "$subnet"
done
fi
if [[ -n "${BLOCK_PORTS:-}" ]]; then
for entry in $BLOCK_PORTS; do
local target port proto
IFS=":" read -r target port proto <<< "$entry"
proto="${proto:-tcp}"
firewall::block_port "$client_ip" "$target" "$port" "$proto"
firewall::save_block "$name" "$client_ip" "$target" "$port" "$proto"
done
fi
log::wg_preset "Applied preset '${name}' to: ${client_ip}"
}
| 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 | } |