v-add-domain 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # info: add web/dns/mail domain
  3. # options: USER DOMAIN [IP] [RESTART]
  4. #
  5. # The function adds web/dns/mail domain to a server.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. domain=$2
  12. ip=$3
  13. restart="${4-yes}"
  14. # Includes
  15. source $VESTA/func/main.sh
  16. source $VESTA/func/ip.sh
  17. source $VESTA/conf/vesta.conf
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. check_args '2' "$#" 'USER DOMAIN [IP] [RESTART]'
  22. validate_format 'user' 'domain'
  23. if [ ! -z "$ip" ] ; then
  24. validate_format 'ip'
  25. fi
  26. is_object_valid 'user' 'USER' "$user"
  27. is_object_unsuspended 'user' 'USER' "$user"
  28. #----------------------------------------------------------#
  29. # Action #
  30. #----------------------------------------------------------#
  31. # Get ip if it wasn't defined
  32. if [ -z "$ip" ]; then
  33. ip=$(get_user_ip $user)
  34. if [ -z "$ip" ]; then
  35. echo "Error: no avaiable IP address"
  36. log_event "$E_NOTEXIST" "$EVENT"
  37. exit $E_NOTEXIST
  38. fi
  39. fi
  40. # Working on web domain
  41. if [ ! -z "$WEB_SYSTEM" ]; then
  42. $BIN/v-add-web-domain $user $domain $ip 'no'
  43. check_result $? "can't add web domain" >/dev/null
  44. fi
  45. # Working on DNS domain
  46. if [ ! -z "$DNS_SYSTEM" ]; then
  47. $BIN/v-add-dns-domain $user $domain $ip "" "" "" "" "" 'no'
  48. check_result $? "can't add dns domain" >/dev/null
  49. fi
  50. # Working on mail domain
  51. if [ ! -z "$MAIL_SYSTEM" ]; then
  52. $BIN/v-add-mail-domain $user $domain
  53. check_result $? "can't add mail domain" >/dev/null
  54. fi
  55. # Restarting services
  56. if [ "$restart" != 'no' ]; then
  57. $BIN/v-restart-web
  58. check_result $? "can't restart web" > /dev/null
  59. if [ ! -z "$PROXY_SYSTEM" ]; then
  60. $BIN/v-restart-proxy
  61. check_result $? "can't restart proxy" > /dev/null
  62. fi
  63. $BIN/v-restart-dns
  64. check_result $? "can't restart dns" > /dev/null
  65. fi
  66. #----------------------------------------------------------#
  67. # Vesta #
  68. #----------------------------------------------------------#
  69. exit