v_list_sys_ip 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/bash
  2. # info: listing system ip
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. ip=$1
  8. IP=$ip
  9. format=${2-shell}
  10. # Importing variables
  11. source $VESTA/conf/vars.conf
  12. source $V_FUNC/shared_func.sh
  13. source $V_FUNC/ip_func.sh
  14. # Json function
  15. json_list_ip() {
  16. i=1
  17. fileds_count=$(echo "$fields" | wc -w)
  18. ip_data=$(cat $V_IPS/$IP)
  19. # Print top bracket
  20. echo '{'
  21. # Assign key=value
  22. for key in $ip_data; do
  23. eval ${key%%=*}=${key#*=}
  24. done
  25. for field in $fields; do
  26. eval value=$field
  27. # Checking first field
  28. if [ $i -eq 1 ]; then
  29. echo -e "\t\"$value\": {"
  30. else
  31. if [ $fileds_count -eq $i ]; then
  32. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  33. else
  34. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  35. fi
  36. fi
  37. (( ++i))
  38. done
  39. # If there was any output
  40. if [ -n "$value" ]; then
  41. echo -e ' }'
  42. fi
  43. # Printing bottom json bracket
  44. echo -e '}'
  45. }
  46. # Shell function
  47. shell_list_ip() {
  48. line=$(cat $V_IPS/$IP)
  49. # Assing key=value
  50. for key in $line; do
  51. eval ${key%%=*}=${key#*=}
  52. done
  53. # Print result line
  54. for field in $fields; do
  55. eval key="$field"
  56. echo "${field//$/}: $key "
  57. done
  58. }
  59. #----------------------------------------------------------#
  60. # Verifications #
  61. #----------------------------------------------------------#
  62. # Checking args
  63. check_args '1' "$#" 'ip [format]'
  64. # Checking argument format
  65. format_validation 'ip'
  66. # Checking ip
  67. is_sys_ip_valid
  68. #----------------------------------------------------------#
  69. # Action #
  70. #----------------------------------------------------------#
  71. conf=$V_IPS/$IP
  72. # Defining fileds to select
  73. fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS
  74. $INTERFACE $NETMASK $DATE'
  75. # Listing ip
  76. case $format in
  77. json) json_list_ip ;;
  78. plain) shell_list_ip ;;
  79. shell) shell_list_ip | column -t ;;
  80. *) check_args '1' '0' 'ip [format]'
  81. esac
  82. #----------------------------------------------------------#
  83. # Vesta #
  84. #----------------------------------------------------------#
  85. # Logging
  86. log_event 'system' "$V_EVENT"
  87. exit