v-delete-user-2fa 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. # info: delete 2fa of existing user
  3. # options: USER
  4. # labels: hestia panel
  5. #
  6. # example: v-delete-user-2fa admin
  7. #
  8. # The function deletes 2fa token of a user.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. user=$1
  14. # Includes
  15. # shellcheck source=/usr/local/hestia/func/main.sh
  16. source $HESTIA/func/main.sh
  17. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  18. source $HESTIA/conf/hestia.conf
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. check_args '1' "$#" 'USER'
  23. is_format_valid 'user' 'system'
  24. is_object_valid 'user' 'USER' "$user"
  25. # Perform verification if read-only mode is enabled
  26. check_hestia_demo_mode
  27. #----------------------------------------------------------#
  28. # Action #
  29. #----------------------------------------------------------#
  30. # Reading user values
  31. source $USER_DATA/user.conf
  32. # Check if 2FA is enabled
  33. if [ -z "$TWOFA" ]; then
  34. echo "Error: two-factor authentication is not enabled"
  35. exit $E_NOTEXIST
  36. fi
  37. # Remove 2FA from user config
  38. update_user_value "$user" '$TWOFA' ""
  39. update_user_value "$user" '$QRCODE' ""
  40. #----------------------------------------------------------#
  41. # Hestia #
  42. #----------------------------------------------------------#
  43. log_history "[WARNING] two-factor authentication disabled for $user"
  44. log_event "$OK" "$ARGUMENTS"
  45. exit