v_list_sys_ips 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/bash
  2. # info: list system ips
  3. # options: [format]
  4. #
  5. # The function for obtaining the list of system ip's.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. format=${1-shell}
  11. # Importing variables
  12. source $VESTA/conf/vars.conf
  13. source $V_FUNC/shared.func
  14. # Json function
  15. json_list_ips() {
  16. # Print top bracket
  17. echo '{'
  18. # Definining ip list
  19. ip_list=$(ls $V_IPS/)
  20. fileds_count=$(echo "$fields" | wc -w)
  21. # Starting main loop
  22. for IP in $ip_list; do
  23. # Assing key=value
  24. ip_data=$(cat $V_IPS/$IP)
  25. eval $ip_data
  26. # Closing bracket if there already was output
  27. if [ -n "$data" ]; then
  28. echo -e ' },'
  29. fi
  30. i=1
  31. for field in $fields; do
  32. eval value=$field
  33. if [ $i -eq 1 ]; then
  34. # Printing parrent
  35. (( ++i))
  36. echo -e "\t\"$value\": {"
  37. else
  38. # Printing child
  39. if [ $i -lt $fileds_count ]; then
  40. (( ++i))
  41. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  42. else
  43. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  44. data=1
  45. fi
  46. fi
  47. done
  48. done
  49. # Closing bracket if there was output
  50. if [ -n "$data" ]; then
  51. echo -e ' }'
  52. fi
  53. # Printing bottom bracket
  54. echo -e '}'
  55. }
  56. # Shell function
  57. shell_list_ips() {
  58. ip_list=$(ls $V_IPS/)
  59. if [ -z "$nohead" ]; then
  60. # Print brief info
  61. echo "${fields//$/}"
  62. for a in $fields; do
  63. echo -e "--------- \c"
  64. done
  65. echo
  66. fi
  67. # Starting main loop
  68. for IP in $ip_list; do
  69. # Reading user data
  70. ip_data=$(cat $V_IPS/$IP)
  71. # Assign key/value config
  72. eval $ip_data
  73. # Print result line
  74. eval echo "$fields"
  75. done
  76. }
  77. #----------------------------------------------------------#
  78. # Action #
  79. #----------------------------------------------------------#
  80. conf=$V_IPS/*
  81. # Defining fileds to select
  82. fields="\$IP \$OWNER \$STATUS \$NAME \$U_SYS_USERS \$U_WEB_DOMAINS"
  83. fields="$fields \$INTERFACE \$NETMASK \$DATE"
  84. # Listing domains
  85. case $format in
  86. json) json_list_ips ;;
  87. plain) nohead=1; shell_list_ips ;;
  88. shell) fields='$IP $NETMASK $OWNER $STATUS $U_WEB_DOMAINS';
  89. shell_list_ips | column -t ;;
  90. *) check_args '1' '0' '[format]'
  91. esac
  92. #----------------------------------------------------------#
  93. # Vesta #
  94. #----------------------------------------------------------#
  95. exit