1
0
mirror of https://github.com/serghey-rodin/vesta.git synced 2025-03-12 04:36:25 -07:00
vesta/bin/v-delete-dns-record

83 lines
2.3 KiB
Plaintext
Raw Normal View History

2013-01-19 23:07:26 +02:00
#!/bin/bash
# info: delete dns record
2013-05-28 16:09:07 +03:00
# options: USER DOMAIN ID [RESTART]
2013-01-19 23:07:26 +02:00
#
# The function for deleting a certain record of DNS zone.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
2015-11-06 17:38:58 +02:00
# Argument definition
2013-01-19 23:07:26 +02:00
user=$1
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
id=$3
2013-05-28 16:09:07 +03:00
restart=$4
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
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
2013-05-28 16:09:07 +03:00
check_args '3' "$#" 'USER DOMAIN ID [RESTART]'
is_format_valid 'user' 'domain' 'id'
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_object_valid "dns/$domain" 'ID' "$id"
2014-01-25 20:02:10 +02:00
is_dns_record_critical
2013-01-19 23:07:26 +02:00
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Deleting record
sed -i "/^ID='$id'/d" $USER_DATA/dns/$domain.conf
# 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-delete-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 #
#----------------------------------------------------------#
# Upddate counters
records="$(wc -l $USER_DATA/dns/$domain.conf | cut -f1 -d ' ')"
update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records"
decrease_user_value "$user" '$U_DNS_RECORDS'
2015-10-28 16:34:41 +02:00
# Restarting named
2013-05-28 16:09:07 +03:00
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
2015-10-28 16:34:41 +02:00
check_result $? "Bind restart failed" >/dev/null
2013-05-28 16:09:07 +03:00
fi
2013-01-19 23:07:26 +02:00
# Logging
log_history "deleted dns record $id on $domain"
log_event "$OK" "$ARGUMENTS"
2013-01-19 23:07:26 +02:00
exit