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.

69 lines
1.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. # (C) 2021 Gerald Kerma
  3. START=99
  4. USE_PROCD=1
  5. NAME=crowdsec-firewall-bouncer
  6. PROG=/usr/bin/cs-firewall-bouncer
  7. CONFIG=/etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
  8. BACKEND=iptables
  9. VARCONFIGDIR=/var/etc/crowdsec/bouncers
  10. VARCONFIG=/var/etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
  11. FW_BACKEND="iptables"
  12. service_triggers() {
  13. procd_add_reload_trigger crowdsec-firewall-bouncer
  14. }
  15. init_config() {
  16. ## CheckFirewall
  17. iptables="true"
  18. which iptables > /dev/null
  19. FW_BACKEND=""
  20. if [[ $? != 0 ]]; then
  21. echo "iptables is not present"
  22. iptables="false"
  23. else
  24. FW_BACKEND="iptables"
  25. echo "iptables found"
  26. fi
  27. nftables="true"
  28. which nft > /dev/null
  29. if [[ $? != 0 ]]; then
  30. echo "nftables is not present"
  31. nftables="false"
  32. else
  33. FW_BACKEND="nftables"
  34. echo "nftables found"
  35. fi
  36. if [ "$nftables" = "true" -a "$iptables" = "true" ]; then
  37. echo "Found nftables(default) and iptables..."
  38. fi
  39. if [ "$FW_BACKEND" = "iptables" ]; then
  40. which ipset > /dev/null
  41. if [[ $? != 0 ]]; then
  42. echo "ipset not found, install it !"
  43. fi
  44. fi
  45. BACKEND=$FW_BACKEND
  46. # Create tmp dir & permissions if needed
  47. if [ ! -d "${VARCONFIGDIR}" ]; then
  48. mkdir -m 0755 -p "${VARCONFIGDIR}"
  49. fi;
  50. cp $CONFIG $VARCONFIG
  51. sed -i "s,^\(\s*mode\s*:\s*\).*\$,\1$BACKEND," $VARCONFIG
  52. }
  53. start_service() {
  54. init_config
  55. procd_open_instance
  56. procd_set_param command "$PROG" -c "$VARCONFIG"
  57. procd_close_instance
  58. }