v-change-database-password 1.7 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/func/main.sh
  16. source $VESTA/func/db.sh
  17. source $VESTA/conf/vesta.conf
  18. # Hiding password
  19. A3='******'
  20. EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
  21. #----------------------------------------------------------#
  22. # Verifications #
  23. #----------------------------------------------------------#
  24. check_args '3' "$#" 'USER DATABASE DBPASS'
  25. validate_format 'user' 'database' 'dbpass'
  26. is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
  27. is_object_valid 'user' 'USER' "$user"
  28. is_object_unsuspended 'user' 'USER' "$user"
  29. is_object_valid 'db' 'DB' "$database"
  30. is_object_unsuspended 'db' 'DB' "$database"
  31. #----------------------------------------------------------#
  32. # Action #
  33. #----------------------------------------------------------#
  34. # Get database values
  35. get_database_values
  36. case $TYPE in
  37. mysql) change_mysql_password ;;
  38. pgsql) change_pgsql_password ;;
  39. esac
  40. #----------------------------------------------------------#
  41. # Vesta #
  42. #----------------------------------------------------------#
  43. # Update config value
  44. update_object_value 'db' 'DB' "$database" '$MD5' "$md5"
  45. # Logging
  46. log_history "changed $database database password"
  47. log_event "$OK" "$EVENT"
  48. exit