v_add_dns_domain_record 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # info: add dns domain record
  3. # options: user domain record type value [priority] [id] [restart]
  4. #
  5. # The call is used for adding new DNS record. Complex records of TXT, MX and
  6. # SRV types can be used by a filling in the 'value' argument. The function also
  7. # gets an id parameter for definition of certain record identifier or for the
  8. # regulation of records.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument defenition
  13. user=$1
  14. domain=$(idn -t --quiet -u "$2" )
  15. domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
  16. domain_idn=$(idn -t --quiet -a "$domain")
  17. record=$(idn -t --quiet -u "$3" )
  18. record=$(echo "$record" | tr '[:upper:]' '[:lower:]')
  19. rtype=$(echo "$4"| tr '[:lower:]' '[:upper:]')
  20. dvalue=$(idn -t --quiet -u "$5" )
  21. dvalue=$(echo "$dvalue" | tr '[:upper:]' '[:lower:]')
  22. priority=$6
  23. id=$7
  24. restart=$8
  25. # Includes
  26. source $VESTA/conf/vesta.conf
  27. source $VESTA/func/main.sh
  28. source $VESTA/func/domain.sh
  29. #----------------------------------------------------------#
  30. # Verifications #
  31. #----------------------------------------------------------#
  32. check_args '5' "$#" 'user domain record type value [priority] [id] [restart]'
  33. validate_format 'user' 'domain' 'record' 'rtype' 'dvalue'
  34. is_system_enabled "$DNS_SYSTEM"
  35. is_object_valid 'user' 'USER' "$user"
  36. is_object_unsuspended 'user' 'USER' "$user"
  37. is_object_valid 'dns' 'DOMAIN' "$domain"
  38. is_object_unsuspended 'dns' 'DOMAIN' "$domain"
  39. is_package_full 'DNS_RECORDS'
  40. get_next_dnsrecord
  41. validate_format 'id'
  42. is_object_free "dns/$domain" 'ID' "$id"
  43. #----------------------------------------------------------#
  44. # Action #
  45. #----------------------------------------------------------#
  46. if [ "$rtype" != 'MX' ] && [ "$rtype" != 'SRV' ]; then
  47. priority=''
  48. fi
  49. # Adding record
  50. zone="$USER_DATA/dns/$domain.conf"
  51. dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
  52. dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
  53. echo "$dns_rec" >> $zone
  54. chmod 660 $zone
  55. # Sorting records
  56. sort_dns_records
  57. # Updating zone
  58. update_domain_zone
  59. #----------------------------------------------------------#
  60. # Vesta #
  61. #----------------------------------------------------------#
  62. # Upddate counters
  63. records="$(wc -l $USER_DATA/dns/$domain.conf | cut -f1 -d ' ')"
  64. update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records"
  65. increase_user_value "$user" '$U_DNS_RECORDS'
  66. # Restart named
  67. if [ "$restart" != 'no' ]; then
  68. $BIN/v_restart_dns "$EVENT"
  69. fi
  70. # Logging
  71. log_history "$EVENT"
  72. log_event "$OK" "$EVENT"
  73. exit