#!/usr/bin/env bash
set -Eeuo pipefail

if ! command -v iptables >/dev/null 2>&1; then
    echo "iptables not installed; NICE Monitoring firewall profile cannot be applied" >&2
    exit 1
fi

allow_tcp() {
    local port="$1"
    if ! iptables -C INPUT -p tcp --dport "$port" -j ACCEPT 2>/dev/null; then
        iptables -I INPUT 1 -p tcp --dport "$port" -j ACCEPT
    fi
}

# HTTPS management/frontend.
allow_tcp 443
# Zabbix server trapper: Agent2 active checks, proxies, sender.
allow_tcp 10051
