v_change_dns_domain_ip 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. # info: change dns domain ip address
  3. # options: user domain ip
  4. #
  5. # The function for changing the main ip of DNS zone.
  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. ip=$3
  14. # Importing variables
  15. source $VESTA/conf/vars.conf
  16. source $V_CONF/vesta.conf
  17. source $V_FUNC/shared.func
  18. source $V_FUNC/domain.func
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. # Checking arg number
  23. check_args '3' "$#" 'user domain ip'
  24. # Checking argument format
  25. format_validation 'user' 'domain' 'ip'
  26. # Checking web system is enabled
  27. is_system_enabled 'dns'
  28. # Checking user
  29. is_user_valid
  30. # Checking user is active
  31. is_user_suspended
  32. # Checking domain exist
  33. is_dns_domain_valid
  34. # Checking domain is not suspened
  35. is_domain_suspended 'dns'
  36. #----------------------------------------------------------#
  37. # Action #
  38. #----------------------------------------------------------#
  39. # Get old ip
  40. old_ip=$(get_dns_domain_value '$IP')
  41. # Changing ip
  42. update_dns_domain_value '$IP' "$ip"
  43. # Changing records
  44. sed -i "s/$old_ip/$ip/g" $V_USERS/$user/dns/$domain
  45. # Updating zone
  46. update_domain_zone
  47. #----------------------------------------------------------#
  48. # Vesta #
  49. #----------------------------------------------------------#
  50. # Adding task to the vesta pipe
  51. restart_schedule 'dns'
  52. # Logging
  53. log_history "$V_EVENT" "$V_SCRIPT $user $domain $old_ip"
  54. log_event 'system' "$V_EVENT"
  55. exit