vesta/bin/v_add_dns_domain
2011-06-14 00:22:25 +03:00

110 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
# info: adding dns domain
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user="$1"
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
ip="$3"
template="${4-default}"
next_year=$(date +%d-%m-%y -d "+ 1 year")
exp="${5-$next_year}"
soa="$6"
ttl="${7-14400}"
# Importing variables
source $VESTA/conf/vars.conf
source $V_FUNC/shared_func.sh
source $V_FUNC/domain_func.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '3' "$#" 'user domain ip [template] [exp] [soa] [ttl]'
# Checking argument format
format_validation 'user' 'domain' 'ip' 'template' 'exp' 'ttl'
# Checking dns system is enabled
is_system_enabled 'dns'
# Checking user
is_user_valid
# Checking user is active
is_user_suspended
# Checking domain
is_domain_new 'quiet'
if [ $? -ne $OK ]; then
# Checking domain owner
is_domain_owner
# Checking domain service
is_dns_domain_free
fi
# Checking package
is_package_full 'dns'
# Checking template
is_template_valid 'dns'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining variables
ns1=$(get_user_value '$NS1')
ns2=$(get_user_value '$NS2')
if [ -z "$soa" ]; then
soa="$ns1"
fi
# Adding zone to zones dir
cat $V_DNSTPL/$template.tpl |\
sed -e "s/%ip%/$ip/g" \
-e "s/%domain_idn%/$domain_idn/g" \
-e "s/%domain%/$domain/g" \
-e "s/%ns1%/$ns1/g" \
-e "s/%ns2%/$ns2/g" \
-e "s/%date%/$V_DATE/g" > $V_USERS/$user/zones/$domain
# Adding dns.conf record
dns_rec="DOMAIN='$domain' IP='$ip' TPL='$template' TTL='$ttl' EXP='$exp'"
dns_rec="$dns_rec SOA='$soa' SUSPEND='no' DATE='$V_DATE'"
echo "$dns_rec" >> $V_USERS/$user/dns.conf
# Adding zone in named.conf
named="zone \"$domain_idn\" {type master; file \"/etc/namedb/$domain.db\";};"
echo "$named" >> /etc/named.conf
# Updating domain dns zone
update_domain_zone
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Increasing domain value
increase_user_value "$user" '$U_DNS_DOMAINS'
# Adding task to the vesta pipe
restart_schedule 'dns'
# Logging
log_history "$V_EVENT" "v_del_dns_domain $user $domain"
log_event 'system' "$V_EVENT"
exit $OK