v-suspend-user 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/bash
  2. # info: suspend user
  3. # options: USER [RESTART]
  4. # labels: panel
  5. #
  6. # example: v-suspend-user alice yes
  7. #
  8. # The function suspends a certain user and all his objects.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. user=$1
  14. restart=$2
  15. # Includes
  16. # shellcheck source=/usr/local/hestia/func/main.sh
  17. source $HESTIA/func/main.sh
  18. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  19. source $HESTIA/conf/hestia.conf
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. check_args '1' "$#" 'USER [RESTART]'
  24. is_format_valid 'user'
  25. is_object_valid 'user' 'USER' "$user"
  26. is_object_unsuspended 'user' 'USER' "$user"
  27. if [ "$user" = 'admin' ]; then
  28. exit
  29. fi
  30. # Perform verification if read-only mode is enabled
  31. check_hestia_demo_mode
  32. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. # Do not restrict access to SFTP/FTP/SSH if POLICY_USER_VIEW_SUSPENDED is set to yes
  36. if [ -z "$POLICY_USER_VIEW_SUSPENDED" ] || [ "$POLICY_USER_VIEW_SUSPENDED" = 'no' ]; then
  37. # Adding '!' in front of the password
  38. /usr/sbin/usermod --lock $user
  39. # Suspending ftp accounts
  40. for ftp in $(grep "^${user}_" /etc/passwd |cut -f 1 -d : ); do
  41. /usr/sbin/usermod --lock $ftp 2>/dev/null
  42. done
  43. fi
  44. # Suspending web domains
  45. if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
  46. $BIN/v-suspend-web-domains $user $restart
  47. fi
  48. # Suspending mail domains
  49. if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
  50. $BIN/v-suspend-mail-domains $user
  51. fi
  52. # Suspending dns domains
  53. if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS_SYSTEM" != 'no' ]; then
  54. $BIN/v-suspend-dns-domains $user $restart
  55. fi
  56. # Suspending datbabases
  57. if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
  58. $BIN/v-suspend-databases $user
  59. fi
  60. # Suspending cron jobs
  61. if [ ! -z "$CRON_SYSTEM" ] && [ "$CRON_SYSTEM" != 'no' ]; then
  62. $BIN/v-suspend-cron-jobs $user $restart
  63. fi
  64. #----------------------------------------------------------#
  65. # Hestia #
  66. #----------------------------------------------------------#
  67. # Restarting system services
  68. $BIN/v-restart-web $restart
  69. check_result $? "Web restart failed" >/dev/null
  70. $BIN/v-restart-proxy $restart
  71. check_result $? "Proxy restart failed" >/dev/null
  72. $BIN/v-restart-dns $restart
  73. check_result $? "DNS restart failed" >/dev/null
  74. $BIN/v-restart-cron $restart
  75. check_result $? "Cron restart failed" >/dev/null
  76. # Changing suspend value
  77. update_user_value "$user" '$SUSPENDED' 'yes'
  78. increase_user_value 'admin' '$SUSPENDED_USERS'
  79. # Logging
  80. $BIN/v-log-action "system" "Info" "Users" "Suspended user account (Name: $user)."
  81. log_event "$OK" "$ARGUMENTS"
  82. exit