| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #!/bin/bash
- # info: list user nameservers
- # options: user [format]
- #
- # Function for obtainig the list of user's DNS servers.
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Argument defenition
- user=$1
- format=${2-shell}
- # Includes
- source $VESTA/func/main.sh
- # Json function
- json_list_ns() {
- ns=$(grep "^NS='" $USER_DATA/user.conf |cut -f 2 -d \')
- echo '['
- i=1
- nslistc=$(echo -e "${ns//,/\n}"|wc -l)
- for nameserver in ${ns//,/ };do
- if [ "$i" -ne "$nslistc" ]; then
- echo -e "\t\"$nameserver\","
- else
- echo -e "\t\"$nameserver\""
- fi
- (( ++i))
- done
- echo "]"
- }
- # Shell function
- shell_list_ns() {
- ns=$(grep "^NS='" $USER_DATA/user.conf |cut -f 2 -d \')
- if [ -z "$nohead" ]; then
- echo "NAMESERVER"
- echo "----------"
- fi
- for nameserver in ${ns//,/ };do
- echo "$nameserver"
- done
- }
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- check_args '1' "$#" 'user [format]'
- validate_format 'user'
- is_object_valid 'user' 'USER' "$user"
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Listing nameservers
- case $format in
- json) json_list_ns ;;
- plain) nohead=1; shell_list_ns ;;
- shell) shell_list_ns ;;
- *) check_args '1' '0' 'user [format]'
- esac
- #----------------------------------------------------------#
- # Vesta #
- #----------------------------------------------------------#
- exit
|