v_add_dns_domain_record 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. # info: add dns domain record
  3. # options: user domain record type value [id]
  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_idn=$(idn -t --quiet -a "$domain")
  16. record=$(idn -t --quiet -u "$3" )
  17. rtype=$(echo "$4"| tr '[:lower:]' '[:upper:]')
  18. dvalue=$(idn -t --quiet -u "$5" )
  19. id=$6
  20. # Importing variables
  21. source $VESTA/conf/vars.conf
  22. source $V_CONF/vesta.conf
  23. source $V_FUNC/shared.func
  24. source $V_FUNC/domain.func
  25. #----------------------------------------------------------#
  26. # Verifications #
  27. #----------------------------------------------------------#
  28. # Checking arg number
  29. check_args '5' "$#" 'user domain record type value [id]'
  30. # Checking argument format
  31. format_validation 'user' 'domain' 'record' 'rtype' 'dvalue'
  32. # Checking web system is enabled
  33. is_system_enabled 'dns'
  34. # Checking user
  35. is_user_valid
  36. # Checking user is active
  37. is_user_suspended
  38. # Checking domain exist
  39. is_dns_domain_valid
  40. # Checking domain is active
  41. is_domain_suspended 'dns'
  42. # Defining if emtpy
  43. if [ -z "$id"] ; then
  44. id=$(get_next_dns_record)
  45. fi
  46. # Checking id format
  47. format_validation 'id'
  48. # Checking id
  49. is_dns_record_free
  50. #----------------------------------------------------------#
  51. # Action #
  52. #----------------------------------------------------------#
  53. # Defining zone path
  54. zone="$V_USERS/$user/dns/$domain"
  55. # Adding record
  56. dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' VALUE='$dvalue'"
  57. dns_rec="$dns_rec SUSPEND='no' DATE='$V_DATE'"
  58. echo "$dns_rec" >> $zone
  59. # Sorting records
  60. sort_dns_records
  61. # Updating zone
  62. update_domain_zone
  63. #----------------------------------------------------------#
  64. # Vesta #
  65. #----------------------------------------------------------#
  66. # Adding task to the vesta pipe
  67. restart_schedule 'dns'
  68. # Logging
  69. log_history "$V_EVENT" "v_delete_dns_domain_record $user $domain $id"
  70. log_event 'system' "$V_EVENT"
  71. exit