v-insert-dns-domain 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. # info: insert dns domain
  3. # options: USER DATA [SRC] [FLUSH] [RESTART]
  4. #
  5. # The function inserts raw record to the dns.conf
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. data=$2
  12. src=$3
  13. flush=$4
  14. restart=$5
  15. # Includes
  16. source $VESTA/func/main.sh
  17. source $VESTA/func/domain.sh
  18. source $VESTA/conf/vesta.conf
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. check_args '2' "$#" 'USER DATA [SRC] [RESTART]'
  23. validate_format 'user' 'data'
  24. is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
  25. is_object_valid 'user' 'USER' "$user"
  26. is_object_unsuspended 'user' 'USER' "$user"
  27. eval $data
  28. domain="$DOMAIN"
  29. if [ "$flush" = 'no' ]; then
  30. is_domain_new 'dns'
  31. fi
  32. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. # Flush records
  36. if [ "$flush" = 'records' ]; then
  37. rm -f $USER_DATA/dns/$DOMAIN.conf
  38. touch $USER_DATA/dns/$DOMAIN.conf
  39. chmod 660 $USER_DATA/dns/$DOMAIN.conf
  40. exit
  41. fi
  42. # Flush domain
  43. if [ "$flush" = 'domain' ]; then
  44. sed -i "/DOMAIN='$DOMAIN'/d" $USER_DATA/dns.conf 2> /dev/null
  45. fi
  46. # Prepare values for the insert
  47. dns_rec="DOMAIN='$DOMAIN' IP='$IP' TPL='$TPL' TTL='$TTL' EXP='$EXP'"
  48. dns_rec="$dns_rec SOA='$SOA' SRC='$src' RECORDS='$RECORDS'"
  49. dns_rec="$dns_rec SUSPENDED='$SUSPENDED' TIME='$TIME' DATE='$DATE'"
  50. echo "$dns_rec" >> $USER_DATA/dns.conf
  51. # Set permission
  52. chmod 660 $USER_DATA/dns.conf
  53. #----------------------------------------------------------#
  54. # Vesta #
  55. #----------------------------------------------------------#
  56. # Restart named
  57. if [ "$restart" != 'no' ]; then
  58. $BIN/v-restart-dns $restart
  59. if [ $? -ne 0 ]; then
  60. exit E_RESTART
  61. fi
  62. fi
  63. # Logging
  64. log_event "$OK" "$EVENT"
  65. exit