knockd.sh 1.2 KB

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