You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
781 B

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