vesta/bin/v-add-dns-record

128 lines
3.7 KiB
Plaintext
Raw Normal View History

2013-01-19 23:07:26 +02:00
#!/bin/bash
2013-05-28 16:09:07 +03:00
# info: add dns record
2013-01-19 23:07:26 +02:00
# options: USER DOMAIN RECORD TYPE VALUE [PRIORITY] [ID] [RESTART]
#
# The call is used for adding new DNS record. Complex records of TXT, MX and
# SRV types can be used by a filling in the 'value' argument. The function also
# gets an id parameter for definition of certain record identifier or for the
# regulation of records.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
2015-11-06 17:38:58 +02:00
# Argument definition
2013-01-19 23:07:26 +02:00
user=$1
domain=$2
2013-01-19 23:07:26 +02:00
record=$(idn -t --quiet -u "$3" )
record=$(echo "$record" | tr '[:upper:]' '[:lower:]')
rtype=$(echo "$4"| tr '[:lower:]' '[:upper:]')
dvalue=$(idn -t --quiet -u "$5" )
priority=$6
id=$7
restart=$8
if [ -z "$priority" ]; then
priority=10
fi
2013-01-19 23:07:26 +02:00
2016-06-28 15:38:11 +03:00
domain_idn="$domain"
if [[ "$domain" = *[![:ascii:]]* ]]; then
domain_idn=$(idn -t --quiet -a $domain)
fi
2013-01-19 23:07:26 +02:00
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
2013-01-19 23:07:26 +02:00
2014-01-25 20:02:10 +02:00
# Null priority for none MX/SRV records
if [ "$rtype" != 'MX' ] && [ "$rtype" != 'SRV' ]; then
priority=''
fi
# Add trailing dot at the end of NS/CNAME/MX/PTR/SRV record
if [[ $rtype =~ NS|CNAME|MX|PTR|SRV ]]; then
2014-01-25 20:02:10 +02:00
trailing_dot=$(echo $dvalue | grep "\.$")
if [ -z $trailing_dot ]; then
dvalue="$dvalue."
fi
fi
2013-01-19 23:07:26 +02:00
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '5' "$#" 'USER DOMAIN RECORD TYPE VALUE [PRIORITY] [ID] [RESTART]'
is_format_valid 'user' 'domain' 'record' 'rtype' 'dvalue'
2013-05-29 13:16:09 +03:00
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
2013-01-19 23:07:26 +02:00
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'dns' 'DOMAIN' "$domain"
is_object_unsuspended 'dns' 'DOMAIN' "$domain"
is_package_full 'DNS_RECORDS'
get_next_dnsrecord
is_format_valid 'id'
2013-03-27 01:16:14 +02:00
is_object_new "dns/$domain" 'ID' "$id"
2014-01-25 20:02:10 +02:00
is_dns_fqnd "$rtype" "$dvalue"
is_dns_nameserver_valid "$domain" "$rtype" "$dvalue"
2013-01-19 23:07:26 +02:00
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
2013-01-19 23:07:26 +02:00
# Adding record
zone="$USER_DATA/dns/$domain.conf"
dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date'"
2013-01-19 23:07:26 +02:00
echo "$dns_rec" >> $zone
chmod 660 $zone
# Sorting records
2014-01-25 20:02:10 +02:00
sort_dns_records
2013-01-19 23:07:26 +02:00
# Updating zone
2014-03-23 18:49:18 +02:00
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
2015-10-15 15:03:23 +03:00
update_domain_serial
2014-03-23 18:49:18 +02:00
update_domain_zone
fi
2013-01-19 23:07:26 +02:00
2014-03-23 18:49:18 +02:00
# Updating dns-cluster queue
2013-05-28 16:09:07 +03:00
if [ ! -z "$DNS_CLUSTER" ]; then
2013-09-12 11:00:30 +03:00
# Check for first sync
dlock=$(grep "domain $user $domain" $VESTA/data/queue/dns-cluster.pipe)
if [ -z "$dlock" ]; then
cmd="$BIN/v-add-remote-dns-record $user $domain $id"
echo "$cmd" >> $VESTA/data/queue/dns-cluster.pipe
fi
2013-05-28 16:09:07 +03:00
fi
2013-01-19 23:07:26 +02:00
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
2015-11-06 17:38:58 +02:00
# Update counters
2013-01-19 23:07:26 +02:00
records="$(wc -l $USER_DATA/dns/$domain.conf | cut -f1 -d ' ')"
update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records"
increase_user_value "$user" '$U_DNS_RECORDS'
# Restart named
if [ "$restart" != 'no' ]; then
2013-05-28 16:09:07 +03:00
$BIN/v-restart-dns
2015-10-21 15:54:07 +03:00
check_result $? $E_RESTART 'dns failed to restart'
2013-01-19 23:07:26 +02:00
fi
# Logging
log_history "added $rtype dns record $record for $domain"
log_event "$OK" "$ARGUMENTS"
2013-01-19 23:07:26 +02:00
exit