v-delete-user-2fa 1.5 KB

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