Hi to all.
I've got this code:
#!/bin/sh
OPNSENSE_URL="https://ip:port"
API_KEY="key"
API_SECRET="secret"
ALIAS_NAME="NNN_ips"
IP_FILE="/tmp/NNN_ips.txt"
add_ip_to_alias() {
local ip="$1"
curl -k -X POST \
-H "Content-Type: application/json" \
-u "${API_KEY}:${API_SECRET}" \
-d "{\"address\":\"${ip}\"}" \
"${OPNSENSE_URL}/api/firewall/alias_util/add/${ALIAS_NAME}"
}
apply_changes() {
curl -k -X POST \
-H "Content-Type: application/json" \
-u "${API_KEY}:${API_SECRET}" \
-d "{}" \
"${OPNSENSE_URL}/api/firewall/alias/reconfigure"
}
while IFS= read -r ip; do
if [ -n "$ip" ]; then
add_ip_to_alias "$ip"
echo "$ip"
fi
done < "$IP_FILE"
apply_changes
But it adds one address at a time, which is not very efficient. Is it possible to send the whole list to the API at once, so that the adding can be done in one request?