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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. # info: add dns domain or dns record based on web domain alias restart
  3. # options: user domain
  4. #
  5. # The function adds dns domain or dns record based on web domain alias.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. domain=$(echo $2 | sed -e 's/\.*$//g' -e 's/^\.*//g')
  12. domain_idn=$(idn -t --quiet -a "$domain")
  13. dom_alias=$(idn -t --quiet -u "$3" )
  14. dom_alias=$(echo $dom_alias | sed -e 's/\.*$//g' -e 's/^\.*//g')
  15. dom_alias=$(echo $dom_alias | tr '[:upper:]' '[:lower:]')
  16. dom_alias_idn=$(idn -t --quiet -a "$dom_alias" )
  17. restart="$4"
  18. # Includes
  19. source $VESTA/conf/vesta.conf
  20. source $VESTA/func/main.sh
  21. source $VESTA/func/domain.sh
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. check_args '3' "$#" 'user domain alias'
  26. validate_format 'user' 'domain'
  27. is_system_enabled "$WEB_SYSTEM"
  28. is_system_enabled "$DNS_SYSTEM"
  29. is_object_valid 'user' 'USER' "$user"
  30. is_object_unsuspended 'user' 'USER' "$user"
  31. is_object_valid 'web' 'DOMAIN' "$domain"
  32. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  33. #----------------------------------------------------------#
  34. # Action #
  35. #----------------------------------------------------------#
  36. # Parsing domain values
  37. get_domain_values 'web'
  38. # Check if it a simple domain
  39. if [ $(echo -e "${dom_alias//\./\n}" | wc -l) -le 2 ]; then
  40. if [ ! -e "$USER_DATA/dns/$dom_alias.conf" ]; then
  41. $BIN/v-add-dns-domain $user $dom_alias $IP '' '' '' '' '' $restart
  42. fi
  43. else
  44. # Check subdomain
  45. sub=$(echo "$dom_alias" | cut -f1 -d . -s)
  46. dom=$(echo "$dom_alias" | sed -e "s/^$sub.//" )
  47. if [ ! -e "$USER_DATA/dns/$dom.conf" ]; then
  48. $BIN/v-add-dns-domain $user $dom $IP '' '' '' '' '' $restart
  49. $BIN/v-add-dns-domain-record $user $dom "$sub" A $IP '' '' $restart
  50. else
  51. if [ "$sub" == '*' ]; then
  52. rec=$(grep -w "RECORD='\*'" $USER_DATA/dns/$dom.conf)
  53. else
  54. rec=$(grep -w "RECORD='$sub'" $USER_DATA/dns/$dom.conf)
  55. fi
  56. if [ -z "$rec" ]; then
  57. $BIN/v-add-dns-domain-record $user $dom "$sub" A $IP '' '' $restart
  58. fi
  59. fi
  60. fi
  61. #----------------------------------------------------------#
  62. # Vesta #
  63. #----------------------------------------------------------#
  64. # No Logging
  65. exit