v_list_sys_ips 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.sh
  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. for key in $ip_data; do
  23. eval ${key%%=*}=${key#*=}
  24. done
  25. # Closing bracket if there already was output
  26. if [ -n "$data" ]; then
  27. echo -e ' },'
  28. fi
  29. i=1
  30. for field in $fields; do
  31. eval value=$field
  32. if [ $i -eq 1 ]; then
  33. # Printing parrent
  34. (( ++i))
  35. echo -e "\t\"$value\": {"
  36. else
  37. # Printing child
  38. if [ $i -lt $fileds_count ]; then
  39. (( ++i))
  40. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  41. else
  42. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  43. data=1
  44. fi
  45. fi
  46. done
  47. done
  48. # Closing bracket if there was output
  49. if [ -n "$data" ]; then
  50. echo -e ' }'
  51. fi
  52. # Printing bottom bracket
  53. echo -e '}'
  54. }
  55. # Shell function
  56. shell_list_ips() {
  57. ip_list=$(ls $V_IPS/)
  58. if [ -z "$nohead" ]; then
  59. # Print brief info
  60. echo "${fields//$/}"
  61. for a in $fields; do
  62. echo -e "--------- \c"
  63. done
  64. echo
  65. fi
  66. # Starting main loop
  67. for IP in $ip_list; do
  68. # Reading user data
  69. ip_data=$(cat $V_IPS/$IP)
  70. # Assign key/value config
  71. for key in $ip_data; do
  72. eval ${key%%=*}=${key#*=}
  73. done
  74. # Print result line
  75. eval echo "$fields"
  76. done
  77. }
  78. #----------------------------------------------------------#
  79. # Action #
  80. #----------------------------------------------------------#
  81. conf=$V_IPS/*
  82. # Defining fileds to select
  83. fields="\$IP \$OWNER \$STATUS \$NAME \$U_SYS_USERS \$U_WEB_DOMAINS"
  84. field=s"$fields \$INTERFACE \$NETMASK \$DATE"
  85. # Listing domains
  86. case $format in
  87. json) json_list_ips ;;
  88. plain) nohead=1; shell_list_ips ;;
  89. shell) fields='$IP $NETMASK $OWNER $STATUS $U_WEB_DOMAINS';
  90. shell_list_ips | column -t ;;
  91. *) check_args '1' '0' '[format]'
  92. esac
  93. #----------------------------------------------------------#
  94. # Vesta #
  95. #----------------------------------------------------------#
  96. # Logging
  97. log_event 'system' "$V_EVENT"
  98. exit