| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #!/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}
- # Importing variables
- source $VESTA/conf/vars.conf
- source $V_FUNC/shared.func
- # Json function
- json_list_ns() {
- ns=$(grep "^NS='" $V_USERS/$user/user.conf |cut -f 2 -d \')
- # Print top bracket
- echo '['
- i=1
- nslistc=$(echo -e "${ns//,/\n}"|wc -l)
- # Listing servers
- 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='" $V_USERS/$user/user.conf |cut -f 2 -d \')
- if [ -z "$nohead" ]; then
- # Print result
- echo "NAMESERVER"
- echo "----------"
- fi
- for nameserver in ${ns//,/ };do
- echo "$nameserver"
- done
- }
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- # Checking args
- check_args '1' "$#" 'user [format]'
- # Checking argument format
- format_validation 'user'
- # Checking user
- is_user_valid
- #----------------------------------------------------------#
- # 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
|