v-add-domain 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. # info: add web/dns/mail domain
  3. # options: USER DOMAIN [IP] [RESTART]
  4. #
  5. # example: v-add-domain admin example.com
  6. #
  7. # This function adds web/dns/mail domain to a server.
  8. #----------------------------------------------------------#
  9. # Variables & Functions #
  10. #----------------------------------------------------------#
  11. # Argument definition
  12. user=$1
  13. domain=$2
  14. ip=$3
  15. restart=$4
  16. # Includes
  17. # shellcheck source=/etc/hestiacp/hestia.conf
  18. source /etc/hestiacp/hestia.conf
  19. # shellcheck source=/usr/local/hestia/func/main.sh
  20. source $HESTIA/func/main.sh
  21. # shellcheck source=/usr/local/hestia/func/ip.sh
  22. source $HESTIA/func/ip.sh
  23. # load config file
  24. source_conf "$HESTIA/conf/hestia.conf"
  25. #----------------------------------------------------------#
  26. # Verifications #
  27. #----------------------------------------------------------#
  28. check_args '2' "$#" 'USER DOMAIN [IP] [RESTART]'
  29. is_format_valid 'user' 'domain' 'restart'
  30. if [ -n "$ip" ]; then
  31. is_format_valid 'ip'
  32. fi
  33. is_object_valid 'user' 'USER' "$user"
  34. is_object_unsuspended 'user' 'USER' "$user"
  35. # Perform verification if read-only mode is enabled
  36. check_hestia_demo_mode
  37. #----------------------------------------------------------#
  38. # Action #
  39. #----------------------------------------------------------#
  40. # Get ip if it wasn't defined
  41. if [ -z "$ip" ]; then
  42. get_user_ip
  43. if [ -z "$ip" ]; then
  44. check_result "$E_NOTEXIST" "no available IP address"
  45. fi
  46. fi
  47. # Working on web domain
  48. if [ -n "$WEB_SYSTEM" ]; then
  49. check1=$(is_package_full 'WEB_DOMAINS')
  50. if [ $? -eq 0 ]; then
  51. ipv6="" # empty, not used yet
  52. $BIN/v-add-web-domain-ipv46 "$user" "$domain" "$ip" "$ipv6" 'no'
  53. check_result $? "can't add web domain"
  54. fi
  55. fi
  56. # Working on DNS domain
  57. if [ -n "$DNS_SYSTEM" ]; then
  58. check2=$(is_package_full 'DNS_DOMAINS')
  59. if [ $? -eq 0 ]; then
  60. $BIN/v-add-dns-domain "$user" "$domain" "$ip" "" "" "" "" "" "" "" "" "no"
  61. check_result $? "can't add dns domain"
  62. fi
  63. fi
  64. # Working on mail domain
  65. if [ -n "$MAIL_SYSTEM" ]; then
  66. check3=$(is_package_full 'MAIL_DOMAINS')
  67. if [ $? -eq 0 ]; then
  68. $BIN/v-add-mail-domain $user $domain 'no'
  69. check_result $? "can't add mail domain"
  70. fi
  71. fi
  72. if [[ "$check1" != '' && "$check2" != '' && "$check3" != '' ]]; then
  73. check_result 8 "Package limit reached"
  74. fi
  75. # Restarting services
  76. $BIN/v-restart-web "$restart"
  77. check_result $? "can't restart web" > /dev/null
  78. $BIN/v-restart-proxy "$restart"
  79. check_result $? "can't restart proxy" > /dev/null
  80. $BIN/v-restart-dns "$restart"
  81. check_result $? "can't restart dns" > /dev/null
  82. #----------------------------------------------------------#
  83. # Hestia #
  84. #----------------------------------------------------------#
  85. exit