#!/bin/bash
# info: get dns domain value
# options: USER DOMAIN KEY
#
# example: v-get-dns-domain-value admin example.com SOA
#
# This function for getting a certain DNS domain parameter.

#----------------------------------------------------------#
#                Variables & Functions                     #
#----------------------------------------------------------#

# Argument definition
user=$1
domain=$2
domain_idn=$2
key=$3

# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"

# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?

#----------------------------------------------------------#
#                    Verifications                         #
#----------------------------------------------------------#

check_args '3' "$#" 'USER DOMAIN KEY'
is_format_valid 'user' 'domain' 'key'
is_object_valid 'user' 'USER' "$user"
is_object_valid 'dns' 'DOMAIN' "$domain"

key=$(echo "$key" | tr '[:lower:]' '[:upper:]' | sed "s/^/$/")

#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

# Print
get_object_value 'dns' 'DOMAIN' "$domain" "$key"

#----------------------------------------------------------#
#                       Hestia                             #
#----------------------------------------------------------#

# Logging
log_event "$OK" "$ARGUMENTS"

exit