v-delete-database-temp-user 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/bash
  2. # info: deletes temp database user
  3. # options: USER DATABASE DBUSER [TYPE] [HOST]
  4. #
  5. # example: v-delete-database-temp-user user wordress hestia_sso_user mysql
  6. #
  7. # Revokes "temp user" access to a database and removes the user
  8. # To be used in combination with v-add-database-temp-user
  9. #----------------------------------------------------------#
  10. # Variables & Functions #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. user=$1
  14. database=$2
  15. dbuser=$3
  16. type=${4-mysql}
  17. host=$5
  18. # Includes
  19. # shellcheck source=/etc/hestiacp/hestia.conf
  20. source /etc/hestiacp/hestia.conf
  21. # shellcheck source=/usr/local/hestia/func/main.sh
  22. source $HESTIA/func/main.sh
  23. # shellcheck source=/usr/local/hestia/func/db.sh
  24. source $HESTIA/func/db.sh
  25. # load config file
  26. source_conf "$HESTIA/conf/hestia.conf"
  27. #----------------------------------------------------------#
  28. # Verifications #
  29. #----------------------------------------------------------#
  30. check_args '3' "$#" 'USER DATABASE DBUSER [TYPE] [HOST]'
  31. is_format_valid 'user' 'database' 'dbuser'
  32. is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
  33. is_object_valid 'user' 'USER' "$user"
  34. is_object_unsuspended 'user' 'USER' "$user"
  35. is_object_valid 'db' 'DB' "$database"
  36. is_object_unsuspended 'db' 'DB' "$database"
  37. get_next_dbhost
  38. if [[ $dbuser != *"hestia_sso"* ]]; then
  39. echo "DBUSER is invalid SSO user"
  40. exit "$E_INVALID"
  41. fi
  42. # Perform verification if read-only mode is enabled
  43. check_hestia_demo_mode
  44. #----------------------------------------------------------#
  45. # Action #
  46. #----------------------------------------------------------#
  47. # Get database values
  48. get_database_values
  49. delete_mysql_database_temp_user
  50. #----------------------------------------------------------#
  51. # Hestia #
  52. #----------------------------------------------------------#
  53. # Logging
  54. $BIN/v-log-action "$user" "Info" "Database" "Revoked user access (Database: $database, User: $dbuser)."
  55. log_event "$OK" "$ARGUMENTS"
  56. exit