mirror of
https://github.com/serghey-rodin/vesta.git
synced 2026-03-11 06:30:35 +01:00
120 lines
2.8 KiB
Bash
Executable File
120 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# info: list system ips
|
|
# options: [format]
|
|
#
|
|
# The function for obtaining the list of system ip's.
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Variable&Function #
|
|
#----------------------------------------------------------#
|
|
|
|
# Argument defenition
|
|
format=${1-shell}
|
|
|
|
# Importing variables
|
|
source $VESTA/conf/vars.conf
|
|
source $V_FUNC/shared.func
|
|
|
|
# Json function
|
|
json_list_ips() {
|
|
# Print top bracket
|
|
echo '{'
|
|
|
|
# Definining ip list
|
|
ip_list=$(ls $V_IPS/)
|
|
|
|
fileds_count=$(echo "$fields" | wc -w)
|
|
|
|
# Starting main loop
|
|
for IP in $ip_list; do
|
|
# Assing key=value
|
|
ip_data=$(cat $V_IPS/$IP)
|
|
eval $ip_data
|
|
|
|
# Closing bracket if there already was output
|
|
if [ -n "$data" ]; then
|
|
echo -e ' },'
|
|
fi
|
|
i=1
|
|
for field in $fields; do
|
|
eval value=$field
|
|
|
|
if [ $i -eq 1 ]; then
|
|
# Printing parrent
|
|
(( ++i))
|
|
echo -e "\t\"$value\": {"
|
|
else
|
|
# Printing child
|
|
if [ $i -lt $fileds_count ]; then
|
|
(( ++i))
|
|
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
|
|
else
|
|
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
|
|
data=1
|
|
fi
|
|
fi
|
|
done
|
|
done
|
|
|
|
# Closing bracket if there was output
|
|
if [ -n "$data" ]; then
|
|
echo -e ' }'
|
|
fi
|
|
|
|
# Printing bottom bracket
|
|
echo -e '}'
|
|
}
|
|
|
|
# Shell function
|
|
shell_list_ips() {
|
|
ip_list=$(ls $V_IPS/)
|
|
|
|
if [ -z "$nohead" ]; then
|
|
# Print brief info
|
|
echo "${fields//$/}"
|
|
for a in $fields; do
|
|
echo -e "--------- \c"
|
|
done
|
|
echo
|
|
fi
|
|
|
|
# Starting main loop
|
|
for IP in $ip_list; do
|
|
# Reading user data
|
|
ip_data=$(cat $V_IPS/$IP)
|
|
|
|
# Assign key/value config
|
|
eval $ip_data
|
|
|
|
# Print result line
|
|
eval echo "$fields"
|
|
done
|
|
}
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Action #
|
|
#----------------------------------------------------------#
|
|
conf=$V_IPS/*
|
|
|
|
# Defining fileds to select
|
|
fields="\$IP \$OWNER \$STATUS \$NAME \$U_SYS_USERS \$U_WEB_DOMAINS"
|
|
fields="$fields \$INTERFACE \$NETMASK \$DATE"
|
|
|
|
# Listing domains
|
|
case $format in
|
|
json) json_list_ips ;;
|
|
plain) nohead=1; shell_list_ips ;;
|
|
shell) fields='$IP $NETMASK $OWNER $STATUS $U_WEB_DOMAINS';
|
|
shell_list_ips | column -t ;;
|
|
*) check_args '1' '0' '[format]'
|
|
esac
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Vesta #
|
|
#----------------------------------------------------------#
|
|
|
|
exit
|