v-add-dns-on-web-alias 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # info: add dns domain or dns record after web domain alias
  3. # options: USER ALIAS IP [RESTART]
  4. #
  5. # The function adds dns domain or dns record based on web domain alias.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. alias=$2
  12. ip=$3
  13. restart=$4
  14. # Includes
  15. source $VESTA/func/main.sh
  16. source $VESTA/func/domain.sh
  17. source $VESTA/conf/vesta.conf
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. check_args '3' "$#" 'USER ALIAS IP [RESTART]'
  22. is_format_valid 'user' 'alias' 'ip'
  23. is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
  24. is_object_valid 'user' 'USER' "$user"
  25. is_object_unsuspended 'user' 'USER' "$user"
  26. if [ -e "$USER_DATA/dns/$alias.conf" ]; then
  27. exit
  28. fi
  29. #----------------------------------------------------------#
  30. # Action #
  31. #----------------------------------------------------------#
  32. # Logging
  33. log_event "$OK" "$ARGUMENTS"
  34. # Define additional vars
  35. sub_domain=$(echo "$alias" |awk -F '.' '{print $1}')
  36. top_domain=$(echo "$alias" |sed -e "s/^$sub_domain.//")
  37. domain_lvl=$(echo "$alias" |grep -o "\." |wc -l)
  38. # Adding second level domain
  39. if [ "$domain_lvl" -eq 1 ] || [ "${#top_domain}" -le '6' ]; then
  40. $BIN/v-add-dns-domain \
  41. $user $alias $ip '' '' '' '' '' $restart >> /dev/null
  42. exit
  43. fi
  44. # Adding top-level domain and then its sub
  45. $BIN/v-add-dns-domain $user $top_domain $ip '' '' '' '' $restart >> /dev/null
  46. # Checking top-level domain
  47. if [ ! -e "$USER_DATA/dns/$top_domain.conf" ]; then
  48. exit
  49. fi
  50. # Checking subdomain record
  51. if [ "$sub_domain" == '*' ]; then
  52. check_record=$(grep -w "RECORD='\*'" $USER_DATA/dns/$top_domain.conf)
  53. else
  54. check_record=$(grep -w "RECORD='$sub_domain'" $USER_DATA/dns/$top_domain.conf)
  55. fi
  56. # Adding subdomain record
  57. if [ -z "$check_record" ]; then
  58. $BIN/v-add-dns-record \
  59. $user $top_domain "$sub_domain" A $ip '' '' $restart >> /dev/null
  60. fi
  61. #----------------------------------------------------------#
  62. # Vesta #
  63. #----------------------------------------------------------#
  64. # No logging
  65. exit