| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #!/bin/bash
- # info: list dns template
- # options: TEMPLATE [FORMAT]
- #
- # The function for obtaining the DNS template parameters.
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Argument definition
- template=$1
- format=${2-shell}
- # Includes
- source $VESTA/func/main.sh
- source $VESTA/func/domain.sh
- # JSON list function
- json_list() {
- IFS=$'\n'
- i=1
- objects=$(grep ID $DNSTPL/$template.tpl |wc -l)
- echo "{"
- while read str; do
- eval $str
- VALUE=$(echo "$VALUE" |sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
- echo -n ' "'$ID'": {
- "RECORD": "'$RECORD'",
- "TYPE": "'$TYPE'",
- "PRIORITY": "'$PRIORITY'",
- "VALUE": "'$VALUE'",
- "ID": "'$ID'"
- }'
- if [ "$i" -lt "$objects" ]; then
- echo ','
- else
- echo
- fi
- ((i++))
- done < <(cat $DNSTPL/$template.tpl)
- echo '}'
- }
- # SHELL list function
- shell_list() {
- IFS=$'\n'
- echo "ID^RECORD^TYPE^VALUE"
- echo "--^------^----^-----"
- while read str; do
- eval $str
- echo "$ID^$RECORD^$TYPE^$VALUE"
- done < <(cat $DNSTPL/$template.tpl)
- }
- # PLAIN list function
- plain_list() {
- IFS=$'\n'
- while read str; do
- eval $str
- VALUE=$(echo "$VALUE" |sed -e "s/%quote%/\\'/g")
- echo -e "$ID\t$RECORD\t$TYPE\t$PRIORITY\t$VALUE"
- done < <(cat $DNSTPL/$template.tpl)
- }
- # CSV list function
- csv_list() {
- IFS=$'\n'
- echo "ID,RECORD,TYPE,PRIORITY,VALUE"
- while read str; do
- eval $str
- VALUE=$(echo "$VALUE" |sed -e "s/%quote%/\\'/g")
- echo "$ID,$RECORD,$TYPE,$PRIORITY,\"$VALUE\""
- done < <(cat $DNSTPL/$template.tpl)
- }
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- check_args '1' "$#" 'TEMPLATE [FORMAT]'
- is_format_valid 'template'
- is_dns_template_valid "$template"
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Listing data
- case $format in
- json) json_list ;;
- plain) plain_list ;;
- csv) csv_list ;;
- shell) shell_list |column -t -s '^';;
- esac
- #----------------------------------------------------------#
- # Vesta #
- #----------------------------------------------------------#
- exit
|