v-change-dns-record 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # info: change dns domain record
  3. # options: USER DOMAIN ID VALUE [PRIORITY] [RESTART]
  4. #
  5. # The function for changing DNS record.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. domain=$(idn -t --quiet -u "$2" )
  12. domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
  13. domain_idn=$(idn -t --quiet -a "$domain")
  14. id=$3
  15. dvalue=$(idn -t --quiet -u "$4" )
  16. dvalue=$(echo $dvalue | tr '[:upper:]' '[:lower:]')
  17. priority=$5
  18. restart=$6
  19. # Includes
  20. source $VESTA/func/main.sh
  21. source $VESTA/func/domain.sh
  22. source $VESTA/conf/vesta.conf
  23. #----------------------------------------------------------#
  24. # Verifications #
  25. #----------------------------------------------------------#
  26. check_args '4' "$#" 'USER DOMAIN ID VALUE [PRIORITY] [RESTART]'
  27. validate_format 'user' 'domain' 'id' 'dvalue'
  28. is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
  29. is_object_valid 'user' 'USER' "$user"
  30. is_object_unsuspended 'user' 'USER' "$user"
  31. is_object_valid 'dns' 'DOMAIN' "$domain"
  32. is_object_unsuspended 'dns' 'DOMAIN' "$domain"
  33. is_object_valid "dns/$domain" 'ID' "$id"
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. # Parsing domain config
  38. line=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf)
  39. eval $line
  40. # Null priority for none MX/SRV records
  41. if [ "$TYPE" != 'MX' ] && [ "$TYPE" != 'SRV' ]; then
  42. priority=''
  43. fi
  44. # Add trailing dot at the end of NS/CNAME/MX/PTR/SRV record
  45. fqdn_type=$(echo $TYPE | grep "[NS|CNAME|MX|PTR|SRV]")
  46. if [ ! -z "$fqdn_type" ]; then
  47. trailing_dot=$(echo $dvalue | grep "\.$")
  48. if [ -z $trailing_dot ]; then
  49. dvalue="$dvalue."
  50. fi
  51. fi
  52. # Additional verifications
  53. is_dns_fqnd "$TYPE" "$dvalue"
  54. is_dns_nameserver_valid "$domain" "$TYPE" "$dvalue"
  55. # Deleting old record
  56. sed -i "/^ID='$id'/d" $USER_DATA/dns/$domain.conf
  57. # Adding record
  58. dns_rec="ID='$id' RECORD='$RECORD' TYPE='$TYPE' PRIORITY='$priority'"
  59. dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
  60. echo "$dns_rec" >> $USER_DATA/dns/$domain.conf
  61. # Sorting records
  62. sort_dns_records
  63. # Updating zone
  64. update_domain_zone
  65. # dns-cluster
  66. if [ ! -z "$DNS_CLUSTER" ]; then
  67. # Check for first sync
  68. dlock=$(grep "domain $user $domain" $VESTA/data/queue/dns-cluster.pipe)
  69. if [ -z "$dlock" ]; then
  70. cmd="$BIN/v-add-remote-dns-domain $user $domain records"
  71. echo "$cmd" >> $VESTA/data/queue/dns-cluster.pipe
  72. fi
  73. fi
  74. #----------------------------------------------------------#
  75. # Vesta #
  76. #----------------------------------------------------------#
  77. # Restart named
  78. if [ "$restart" != 'no' ]; then
  79. $BIN/v-restart-dns
  80. if [ $? -ne 0 ]; then
  81. exit E_RESTART
  82. fi
  83. fi
  84. # Logging
  85. log_history "changed dns record on $domain to $dvalue"
  86. log_event "$OK" "$EVENT"
  87. exit