v_list_sys_ips 2.7 KB

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