v_change_dns_domain_record 2.1 KB

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