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
786 B

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