v-list-sys-ips 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. # Includes
  12. source $VESTA/func/main.sh
  13. # Json function
  14. json_list_ips() {
  15. echo '{'
  16. ip_list=$(ls $VESTA/data/ips/)
  17. fileds_count=$(echo "$fields" | wc -w)
  18. for IP in $ip_list; do
  19. ip_data=$(cat $VESTA/data/ips/$IP)
  20. eval $ip_data
  21. if [ -n "$data" ]; then
  22. echo -e ' },'
  23. fi
  24. i=1
  25. for field in $fields; do
  26. eval value=$field
  27. if [ $i -eq 1 ]; then
  28. (( ++i))
  29. echo -e "\t\"$value\": {"
  30. else
  31. if [ $i -lt $fileds_count ]; then
  32. (( ++i))
  33. echo -e "\t\t\"${field//$/}\": \"$value\","
  34. else
  35. echo -e "\t\t\"${field//$/}\": \"$value\""
  36. data=1
  37. fi
  38. fi
  39. done
  40. done
  41. if [ -n "$data" ]; then
  42. echo -e ' }'
  43. fi
  44. echo -e '}'
  45. }
  46. # Shell function
  47. shell_list_ips() {
  48. ip_list=$(ls $VESTA/data/ips/)
  49. if [ -z "$nohead" ]; then
  50. echo "${fields//$/}"
  51. for a in $fields; do
  52. echo -e "--------- \c"
  53. done
  54. echo
  55. fi
  56. for IP in $ip_list; do
  57. ip_data=$(cat $VESTA/data/ips/$IP)
  58. eval $ip_data
  59. eval echo "$fields"
  60. done
  61. }
  62. #----------------------------------------------------------#
  63. # Action #
  64. #----------------------------------------------------------#
  65. # Defining fileds to select
  66. conf=$VESTA/data/ips/*
  67. fields="\$IP \$OWNER \$STATUS \$NAME \$U_SYS_USERS \$U_WEB_DOMAINS"
  68. fields="$fields \$INTERFACE \$NETMASK \$TIME \$DATE"
  69. # Listing ip addresses
  70. case $format in
  71. json) json_list_ips ;;
  72. plain) nohead=1; shell_list_ips ;;
  73. shell) fields='$IP $NETMASK $OWNER $STATUS $U_WEB_DOMAINS';
  74. shell_list_ips | column -t ;;
  75. *) check_args '1' '0' '[format]'
  76. esac
  77. #----------------------------------------------------------#
  78. # Vesta #
  79. #----------------------------------------------------------#
  80. exit