v-delete-web-domain-httpauth 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. # info: delete http auth user
  3. # options: USER DOMAIN AUTH_USER [RESTART]
  4. # labels: web
  5. #
  6. # example: v-delete-web-domain-httpauth admin example.com alice
  7. #
  8. # The call is used for deleting http auth user
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. user=$1
  14. domain=$2
  15. auth_user=$3
  16. restart=${4-yes}
  17. # Includes
  18. # shellcheck source=/usr/local/hestia/func/main.sh
  19. source $HESTIA/func/main.sh
  20. # shellcheck source=/usr/local/hestia/func/domain.sh
  21. source $HESTIA/func/domain.sh
  22. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  23. source $HESTIA/conf/hestia.conf
  24. # Defining htpasswd file
  25. htaccess="$HOMEDIR/$user/conf/web/$domain/htaccess"
  26. htpasswd="$HOMEDIR/$user/conf/web/$domain/htpasswd"
  27. #----------------------------------------------------------#
  28. # Verifications #
  29. #----------------------------------------------------------#
  30. check_args '3' "$#" 'USER DOMAIN AUTH_USER [RESTART]'
  31. is_format_valid 'user' 'domain'
  32. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  33. is_object_valid 'user' 'USER' "$user"
  34. is_object_valid 'web' 'DOMAIN' "$domain"
  35. is_password_valid
  36. get_domain_values 'web'
  37. if [ -z "$(echo "$AUTH_USER" |tr : '\n' |grep ^$auth_user$)" ]; then
  38. echo "Error: auth user $auth_user doesn't exist"
  39. log_event "$E_NOTEXIST" "$ARGUMENTS"
  40. exit $E_NOTEXIST
  41. fi
  42. # Perform verification if read-only mode is enabled
  43. check_hestia_demo_mode
  44. #----------------------------------------------------------#
  45. # Action #
  46. #----------------------------------------------------------#
  47. # Deleting auth user
  48. sed -i "/^$auth_user:/d" $htpasswd
  49. # Deleting password protection
  50. if [ "$(echo "$AUTH_USER" |tr : '\n' |wc -l)" -le 1 ]; then
  51. rm -f $htaccess $htpasswd $shtaccess $shtpasswd
  52. restart_required='yes'
  53. fi
  54. # Restarting web server
  55. if [ "$restart" != 'no' ] && [ "$restart_required" = 'yes' ]; then
  56. $BIN/v-restart-web
  57. fi
  58. #----------------------------------------------------------#
  59. # Hestia #
  60. #----------------------------------------------------------#
  61. # Rebuilding FTP variables
  62. position=$(echo $AUTH_USER |tr ':' '\n' |grep -n '' |grep ":$auth_user$" |\
  63. cut -f 1 -d:)
  64. auth_user=$(echo $AUTH_USER |tr ':' '\n' |grep -n '' |grep -v "^$position:" |\
  65. cut -f 2 -d :| sed -e "/^$/d"| sed -e ':a;N;$!ba;s/\n/:/g')
  66. auth_hash=$(echo $AUTH_HASH |tr ':' '\n' |grep -n '' |grep -v "^$position:" |\
  67. cut -f 2 -d :| sed -e ':a;N;$!ba;s/\n/:/g')
  68. # Update config
  69. update_object_value 'web' 'DOMAIN' "$domain" '$AUTH_USER' "$auth_user"
  70. update_object_value 'web' 'DOMAIN' "$domain" '$AUTH_HASH' "$auth_hash"
  71. # Logging
  72. log_history "changed auth user $httpauth_user password on $domain"
  73. log_event "$OK" "$ARGUMENTS"
  74. exit