packages/net/crowdsec-firewall-bouncer/files/crowdsec-firewall-bouncer.defaults
Kerma Gérald 676a621647 crowdsec-firewall-bouncer: initial package v0.0.15
/net/crowdsec-firewall-bouncer/

crowdsec-firewall-bouncer will fetch new and old decisions from
 a CrowdSec API to add them in a blocklist used by supported firewalls.

Signed-off-by: Kerma Gérald <gandalf@gk2.net>
2021-10-09 11:53:43 +02:00

23 lines
786 B
Bash

#!/bin/sh
API_KEY=""
CONFIG=/etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
## Gen&ConfigApiKey
if grep -q "${API_KEY}" "$CONFIG"; then
echo API key already registered...
else
SUFFIX=`tr -dc A-Za-z0-9 </dev/urandom | head -c 8`
API_KEY=`/usr/bin/cscli bouncers add cs-firewall-bouncer-${SUFFIX} -o raw`
sed -i "s,^\(\s*api_key\s*:\s*\).*\$,\1$API_KEY," $CONFIG
fi
# unfortunately, UCI doesn't provide a nice way to add an anonymous section only if it doesn't already exist
if ! uci show firewall | grep -q firewall.cs; then
name="$(uci add firewall include)"
uci set "firewall.${name}.path=/etc/firewall.cs"
uci set "firewall.${name}.enabled=1"
uci set "firewall.${name}.reload=1"
echo -e "Adding the following UCI config:\n $(uci changes)"
uci commit
fi
exit 0