knockd.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. # TODO check if root
  3. echo -e '
  4. _ __ _
  5. | |/ /_ _ ___ __| |__
  6. | . <| . \/ _ \/ _| / /
  7. |_|\_\_||_\___/\__|_\_\
  8. '
  9. echo -e "Installing knockd to control ssh port opening"
  10. . bin/checkroot.sh
  11. # get the current position
  12. _cwd="$(pwd)"
  13. # check for assets forlder
  14. _assets="$_cwd/assets"
  15. if [ ! -d "$_assets" ]; then
  16. _assets="$_cwd/../assets"
  17. if [ ! -d "$_assets" ]; then
  18. echo "!! can't find assets directory !!"
  19. exit
  20. fi
  21. fi
  22. sleep 2
  23. apk add knock
  24. echo -n "checking if ufw is installed"
  25. ufw_installed=$(apk list -I | grep "ufw")
  26. if ! $ufw_installed; then
  27. echo -n "ufw installed"
  28. mv /etc/knockd.conf /etc/knockd.conf.ori
  29. cp "$_assets"/knockd.conf /etc/knockd.conf
  30. echo -n "define a sequence number for opening ssh (as 7000,8000,9000) : "
  31. read sq
  32. sed -i "s/7000,8000,9000/$sq/g" /etc/knockd.conf
  33. rc-update add knockd
  34. /etc/init.d/knockd start
  35. ufw delete allow ssh
  36. echo -e "knockd installed and configured"
  37. echo -e "please note this sequence for future ssh knocking"
  38. echo "$sq"
  39. else
  40. #. bin/ufw.sh
  41. echo -n "ufw not installed, needed by knockd, configuration aborted"
  42. fi
  43. sleep 3