| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #!/bin/bash
- # info: add dns domain
- # options: user domain ip [template] [exp] [soa] [ttl]
- #
- # The function adds DNS zone with records defined in the template. If the exp
- # argument isn't stated, the expiration date value will be set to next year.
- # The soa argument is responsible for the relevant record. By default the first
- # user's NS server is used. TTL is set as common for the zone and for all of
- # its records with a default value of 14400 seconds.
- #----------------------------------------------------------#
- # 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 +%F -d "+ 1 year")
- exp=${5-$next_year}
- soa=$6
- ttl=${7-14400}
- # Importing variables
- source $VESTA/conf/vars.conf
- source $V_CONF/vesta.conf
- source $V_FUNC/shared.func
- source $V_FUNC/domain.func
- #----------------------------------------------------------#
- # 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 0 ]; 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
- i=1
- ns=$(get_user_value '$NS')
- for nameserver in ${ns//,/ };do
- eval ns$i=$nameserver
- i=$((i + 1))
- done
- if [ -z "$soa" ]; then
- soa="$ns1"
- fi
- # Adding zone to dns 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/%ns3%/$ns3/g" \
- -e "s/%ns4%/$ns4/g" \
- -e "s/%ns5%/$ns5/g" \
- -e "s/%ns6%/$ns6/g" \
- -e "s/%ns7%/$ns7/g" \
- -e "s/%ns8%/$ns8/g" \
- -e "s/%date%/$V_DATE/g" > $V_USERS/$user/dns/$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_delete_dns_domain $user $domain"
- log_event 'system' "$V_EVENT"
- exit
|