v_change_dns_domain_record 2.2 KB

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