v_add_dns_domain 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/bin/bash
  2. # info: add dns domain
  3. # options: user domain ip [template] [exp] [soa] [ttl]
  4. #
  5. # The function adds DNS zone with records defined in the template. If the exp
  6. # argument isn't stated, the expiration date value will be set to next year.
  7. # The soa argument is responsible for the relevant record. By default the first
  8. # user's NS server is used. TTL is set as common for the zone and for all of
  9. # its records with a default value of 14400 seconds.
  10. #----------------------------------------------------------#
  11. # Variable&Function #
  12. #----------------------------------------------------------#
  13. # Argument defenition
  14. user=$1
  15. domain=$(idn -t --quiet -u "$2" )
  16. domain_idn=$(idn -t --quiet -a "$domain")
  17. ip=$3
  18. template=${4-default}
  19. next_year=$(date +%F -d "+ 1 year")
  20. exp=${5-$next_year}
  21. soa=$6
  22. ttl=${7-14400}
  23. # Importing variables
  24. source $VESTA/conf/vars.conf
  25. source $V_CONF/vesta.conf
  26. source $V_FUNC/shared.func
  27. source $V_FUNC/domain.func
  28. #----------------------------------------------------------#
  29. # Verifications #
  30. #----------------------------------------------------------#
  31. # Checking arg number
  32. check_args '3' "$#" 'user domain ip [template] [exp] [soa] [ttl]'
  33. # Checking argument format
  34. format_validation 'user' 'domain' 'ip' 'template' 'exp' 'ttl'
  35. # Checking dns system is enabled
  36. is_system_enabled 'dns'
  37. # Checking user
  38. is_user_valid
  39. # Checking user is active
  40. is_user_suspended
  41. # Checking domain
  42. is_domain_new 'quiet'
  43. if [ $? -ne 0 ]; then
  44. # Checking domain owner
  45. is_domain_owner
  46. # Checking domain service
  47. is_dns_domain_free
  48. fi
  49. # Checking package
  50. is_package_full 'dns'
  51. # Checking template
  52. is_template_valid 'dns'
  53. #----------------------------------------------------------#
  54. # Action #
  55. #----------------------------------------------------------#
  56. # Defining variables
  57. i=1
  58. ns=$(get_user_value '$NS')
  59. for nameserver in ${ns//,/ };do
  60. eval ns$i=$nameserver
  61. i=$((i + 1))
  62. done
  63. if [ -z "$soa" ]; then
  64. soa="$ns1"
  65. fi
  66. # Adding zone to dns dir
  67. cat $V_DNSTPL/$template.tpl |\
  68. sed -e "s/%ip%/$ip/g" \
  69. -e "s/%domain_idn%/$domain_idn/g" \
  70. -e "s/%domain%/$domain/g" \
  71. -e "s/%ns1%/$ns1/g" \
  72. -e "s/%ns2%/$ns2/g" \
  73. -e "s/%ns3%/$ns3/g" \
  74. -e "s/%ns4%/$ns4/g" \
  75. -e "s/%ns5%/$ns5/g" \
  76. -e "s/%ns6%/$ns6/g" \
  77. -e "s/%ns7%/$ns7/g" \
  78. -e "s/%ns8%/$ns8/g" \
  79. -e "s/%date%/$V_DATE/g" > $V_USERS/$user/dns/$domain
  80. # Adding dns.conf record
  81. dns_rec="DOMAIN='$domain' IP='$ip' TPL='$template' TTL='$ttl' EXP='$exp'"
  82. dns_rec="$dns_rec SOA='$soa' SUSPEND='no' DATE='$V_DATE'"
  83. echo "$dns_rec" >> $V_USERS/$user/dns.conf
  84. # Adding zone in named.conf
  85. named="zone \"$domain_idn\" {type master; file \"/etc/namedb/$domain.db\";};"
  86. echo "$named" >> /etc/named.conf
  87. # Updating domain dns zone
  88. update_domain_zone
  89. #----------------------------------------------------------#
  90. # Vesta #
  91. #----------------------------------------------------------#
  92. # Increasing domain value
  93. increase_user_value "$user" '$U_DNS_DOMAINS'
  94. # Adding task to the vesta pipe
  95. restart_schedule 'dns'
  96. # Logging
  97. log_history "$V_EVENT" "v_delete_dns_domain $user $domain"
  98. log_event 'system' "$V_EVENT"
  99. exit