Files
VestaCP/bin/v_list_dns_template
2012-01-03 21:47:10 +02:00

134 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
# info: list dns template
# options: template [format]
#
# The function for obtaining the DNS template parameters.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
template=$1
format=${2-shell}
# Importing variables
source $VESTA/conf/vars.conf
source $V_FUNC/shared.func
source $V_FUNC/domain.func
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking args
check_args '1' "$#" 'template [format]'
# Checking argument format
format_validation 'template'
# Checking template
is_template_valid 'dns'
# Json func
json_list_dns() {
# Print top bracket
echo '{'
# Count fields
fileds_count=$(echo $fields| wc -w )
# Reading file line by line
while read line; do
# New delimeter
IFS=$'\n'
# Assing key=value pair
eval $line
# Closing bracket if there already was output
if [ -n "$data" ]; then
echo -e ' },'
fi
i=1
IFS=' '
for field in $fields; do
eval value=\"$field\"
value=$(echo "$value" | sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
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 < $conf
# Closing bracket if there was output
if [ -n "$data" ]; then
echo -e ' }'
fi
# Printing bottom bracket
echo -e '}'
}
# Shell function
shell_list_dns() {
if [ -z "$nohead" ] ; then
# Print brief info
echo "${fields//$/}"
for a in $fields; do
echo -e "------ \c"
done
echo
fi
# Reading file line by line
while read line ; do
# Assing key=value pair
eval $line
# Print result
eval echo "$fields" | sed -e "s/%quote%/'/g"
done < $conf
}
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining config
conf=$V_DNSTPL/$template.tpl
# Defining fileds to select
fields='$RECORD $TYPE $VALUE'
# Listing domains
case $format in
json) json_list_dns ;;
plain) nohead=1; shell_list_dns ;;
shell) shell_list_dns | column -t ;;
*) check_args '1' '0' 'template [format]';;
esac
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit