v-change-sys-db-alias 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. # info: change phpmyadmin/phppgadmin alias url
  3. # options: TYPE ALIAS
  4. # labels: hestia
  5. #
  6. # example: v-change-sys-db-alias pma phpmyadmin
  7. # # Sets phpMyAdmin alias to phpmyadmin
  8. #
  9. # example: v-change-sys-db-alias pga phppgadmin
  10. # # Sets phpPgAdmin alias to phppgadmin
  11. #
  12. # This function changes the database editor url in
  13. # apache2 or nginx configuration.
  14. #----------------------------------------------------------#
  15. # Variable&Function #
  16. #----------------------------------------------------------#
  17. # Argument definition
  18. type=$1
  19. alias=$2
  20. # Includes
  21. # shellcheck source=/etc/hestiacp/hestia.conf
  22. source /etc/hestiacp/hestia.conf
  23. # shellcheck source=/usr/local/hestia/func/main.sh
  24. source $HESTIA/func/main.sh
  25. # load config file
  26. source_conf "$HESTIA/conf/hestia.conf"
  27. #----------------------------------------------------------#
  28. # Verifications #
  29. #----------------------------------------------------------#
  30. check_args '2' "$#" 'type alias'
  31. is_common_format_valid "$alias" "Alias"
  32. # Perform verification if read-only mode is enabled
  33. check_hestia_demo_mode
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. # Detect common allowed entries for phpMyAdmin
  38. if [ "$type" = "pma" ] || [ "$type" = "PMA" ] || [ "$type" = "phpmyadmin" ]; then
  39. # Set database editor friendly name
  40. db_editor="phpMyAdmin"
  41. # Set new alias value
  42. $BIN/v-change-sys-config-value 'DB_PMA_ALIAS' "$alias"
  43. # Replace old configuration files and update alias
  44. if [ -e "/etc/apache2/conf.d/phpmyadmin.inc" ]; then
  45. rm -f /etc/apache2/conf.d/phpmyadmin.inc
  46. cp -f $HESTIA_INSTALL_DIR/pma/apache.conf /etc/apache2/conf.d/phpmyadmin.inc
  47. sed -i "s|%pma_alias%|$alias|g" /etc/apache2/conf.d/phpmyadmin.inc
  48. # Restart services
  49. $HESTIA/bin/v-restart-service apache2
  50. fi
  51. if [ -e "/etc/nginx/conf.d/phpmyadmin.inc" ]; then
  52. rm -f /etc/nginx/conf.d/phpmyadmin.inc
  53. cp -f $HESTIA_INSTALL_DIR/nginx/phpmyadmin.inc /etc/nginx/conf.d/phpmyadmin.inc
  54. sed -i "s|%pma_alias%|$alias|g" /etc/nginx/conf.d/phpmyadmin.inc
  55. # Restart services
  56. $HESTIA/bin/v-restart-service nginx
  57. fi
  58. fi
  59. # Detect common allowed entries for phpPgAdmin
  60. if [ "$type" = "pga" ] || [ "$type" = "PGA" ] || [ "$type" = "phppgadmin" ]; then
  61. # Set database editor friendly name
  62. db_editor="phpPgAdmin"
  63. # Set new alias value
  64. $BIN/v-change-sys-config-value 'DB_PGA_ALIAS' "$alias"
  65. # Replace old configuration files and update alias
  66. if [ -e "/etc/apache2/conf.d/phppgadmin.inc" ]; then
  67. rm -f /etc/apache2/conf.d/phppgadmin.inc
  68. cp -f $HESTIA_INSTALL_DIR/pga/phppgadmin.conf /etc/apache2/conf.d/phppgadmin.inc
  69. sed -i "s|%pga_alias%|$alias|g" /etc/apache2/conf.d/phppgadmin.inc
  70. # Restart services
  71. $HESTIA/bin/v-restart-service apache2
  72. fi
  73. if [ -e "/etc/nginx/conf.d/phppgadmin.inc" ]; then
  74. rm -f /etc/nginx/conf.d/phppgadmin.inc
  75. cp -f $HESTIA_INSTALL_DIR/nginx/phppgadmin.inc /etc/nginx/conf.d/phppgadmin.inc
  76. sed -i "s|%pga_alias%|$alias|g" /etc/nginx/conf.d/phppgadmin.inc
  77. # Restart services
  78. $HESTIA/bin/v-restart-service nginx
  79. fi
  80. fi
  81. #----------------------------------------------------------#
  82. # Hestia #
  83. #----------------------------------------------------------#
  84. # Logging
  85. $BIN/v-log-action "system" "Info" "System" "System access alias changed (Tool: $db_editor, Alias: $alias)."
  86. log_event "$OK" "$ARGUMENTS"
  87. exit