v-delete-sys-ssh-jail 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. # info: delete system ssh jail
  3. # options: NONE
  4. #
  5. # example: v-delete-sys-ssh-jail
  6. #
  7. # This function disables ssh jailed environment
  8. #----------------------------------------------------------#
  9. # Variables & Functions #
  10. #----------------------------------------------------------#
  11. # Includes
  12. # shellcheck source=/etc/hestiacp/hestia.conf
  13. source /etc/hestiacp/hestia.conf
  14. # shellcheck source=/usr/local/hestia/func/main.sh
  15. source $HESTIA/func/main.sh
  16. # load config file
  17. source_conf "$HESTIA/conf/hestia.conf"
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. # Perform verification if read-only mode is enabled
  22. check_hestia_demo_mode
  23. #----------------------------------------------------------#
  24. # Action #
  25. #----------------------------------------------------------#
  26. # Unregister /usr/sbin/jailbash
  27. sed -i "/\/usr\/sbin\/jailbash/d" /etc/shells
  28. # Remove jailbash from /usr/sbin
  29. if [ -x /usr/sbin/jailbash ]; then
  30. rm -f /usr/sbin/jailbash
  31. rm -f /etc/apparmor.d/bwrap-userns-restrict
  32. service apparmor reload > /dev/null 2>&1
  33. fi
  34. # Checking sshd directives
  35. config='/etc/ssh/sshd_config'
  36. ssh_i=$(grep -n "^# Hestia SSH Chroot" $config)
  37. # Backing up config
  38. cp $config $config.bak
  39. # Disabling jailed ssh
  40. if [ -n "$ssh_i" ]; then
  41. fline=$(echo "$ssh_i" | cut -f 1 -d :)
  42. lline=$((fline + 4))
  43. sed -i "${fline},${lline}d" $config
  44. restart='yes'
  45. fi
  46. # Validating opensshd config
  47. if [ "$restart" = 'yes' ]; then
  48. subj="OpenSSH restart failed"
  49. email=$(grep CONTACT "$HESTIA/data/users/$ROOT_USER/user.conf" | cut -f 2 -d \')
  50. /usr/sbin/sshd -t > /dev/null 2>&1
  51. if [ "$?" -ne 0 ]; then
  52. mail_text="OpenSSH can not be restarted. Please check config:
  53. \n\n$(/usr/sbin/sshd -t)"
  54. echo -e "$mail_text" | $SENDMAIL -s "$subj" $email
  55. else
  56. service sshd restart > /dev/null 2>&1
  57. fi
  58. fi
  59. # Remove group ssh-jailed
  60. groupdel ssh-jailed 2> /dev/null
  61. #----------------------------------------------------------#
  62. # Hestia #
  63. #----------------------------------------------------------#
  64. # Logging
  65. $BIN/v-log-action "system" "Warning" "Plugins" "SSH Chroot Jail disabled."
  66. log_event "$OK" "$ARGUMENTS"
  67. exit