v_change_sys_ip_status 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # info: change ip status
  3. # options: ip ip_status
  4. #
  5. # The function of changing an ip address's status.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. ip=$1
  11. ip_status=$2
  12. # Importing variables
  13. source $VESTA/conf/vars.conf
  14. source $V_CONF/vesta.conf
  15. source $V_FUNC/shared.func
  16. source $V_FUNC/ip.func
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. # Checking arg number
  21. check_args '2' "$#" 'ip ip_status'
  22. # Checking argument format
  23. format_validation 'ip' 'ip_status'
  24. # Checking system ip
  25. is_sys_ip_valid
  26. # Checking current status
  27. current_status=$(get_sys_ip_value '$STATUS')
  28. if [ "$ip_status" = "$current_status" ]; then
  29. echo "Error: status is already set"
  30. log_event 'debug' "$E_EXISTS $V_EVENT"
  31. exit $E_EXISTS
  32. fi
  33. # Parsing current ip usage
  34. web_domains=$(get_sys_ip_value '$U_WEB_DOMAINS')
  35. sys_user=$(get_sys_ip_value '$U_SYS_USERS')
  36. ip_owner=$(get_sys_ip_value '$OWNER')
  37. # Checking condition
  38. if [ "$web_domains" -ne '0' ] && [ "$sys_user" != "$ip_owner" ]; then
  39. echo "Error: ip is used"
  40. log_event 'debug' "$E_INUSE $V_EVENT"
  41. exit $E_INUSE
  42. fi
  43. #----------------------------------------------------------#
  44. # Action #
  45. #----------------------------------------------------------#
  46. # Changing ip name
  47. update_sys_ip_value '$STATUS' "$ip_status"
  48. #----------------------------------------------------------#
  49. # Vesta #
  50. #----------------------------------------------------------#
  51. # Logging
  52. log_event 'system' "$V_EVENT"
  53. exit