v_change_database_password 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. # info: change database password
  3. # options: user database dbpass
  4. #
  5. # The function for changing database user password to a database. It uses the
  6. # full name of database as argument.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument defenition
  11. user=$1
  12. database=$2
  13. dbpass=$3
  14. # Includes
  15. source $VESTA/conf/vesta.conf
  16. source $VESTA/func/main.sh
  17. source $VESTA/func/db.sh
  18. # Hiding password
  19. A3='******'
  20. EVENT="DATE='$DATE' TIME='$TIME' CMD='$SCRIPT' A1='$A1' A2='$A2' A3='$A3'"
  21. EVENT="$EVENT A4='$A4' A5='$A5' A6='$A6' A7='$A7' A8='$A8' A9='$A9'"
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. check_args '3' "$#" 'user database dbpass'
  26. validate_format 'user' 'database' 'dbpass'
  27. is_system_enabled "$DB_SYSTEM"
  28. is_object_valid 'user' 'USER' "$user"
  29. is_object_unsuspended 'user' 'USER' "$user"
  30. is_object_valid 'db' 'DB' "$database"
  31. is_object_unsuspended 'db' 'DB' "$database"
  32. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. # Get database values
  36. get_database_values
  37. case $TYPE in
  38. mysql) change_mysql_password ;;
  39. pgsql) change_pgsql_password ;;
  40. esac
  41. #----------------------------------------------------------#
  42. # Vesta #
  43. #----------------------------------------------------------#
  44. # Update config value
  45. update_object_value 'db' 'DB' "$database" '$MD5' "$md5"
  46. # Logging
  47. log_event "$OK" "$EVENT"
  48. exit