1
0
mirror of https://github.com/serghey-rodin/vesta.git synced 2025-03-11 12:22:56 -07:00
vesta/bin/v-insert-dns-domain

84 lines
2.2 KiB
Plaintext
Raw Permalink Normal View History

2013-05-19 15:00:08 +03:00
#!/bin/bash
2013-05-28 16:09:07 +03:00
# info: insert dns domain
2013-05-31 12:46:32 +03:00
# options: USER DATA [SRC] [FLUSH] [RESTART]
2013-05-19 15:00:08 +03:00
#
2013-05-28 16:09:07 +03:00
# The function inserts raw record to the dns.conf
2013-05-19 15:00:08 +03:00
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
2015-11-06 17:38:58 +02:00
# Argument definition
2013-05-19 15:00:08 +03:00
user=$1
2013-05-28 16:09:07 +03:00
data=$2
src=$3
flush=$4
2013-05-31 12:46:32 +03:00
restart=$5
2013-05-19 15:00:08 +03:00
# Includes
source $VESTA/func/main.sh
2013-10-07 21:32:55 +03:00
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
2013-05-19 15:00:08 +03:00
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
2015-10-21 15:54:07 +03:00
check_args '2' "$#" 'USER DATA [SRC] [FLUSH] [RESTART]'
is_format_valid 'user' 'data'
2013-05-29 13:16:09 +03:00
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
2013-05-19 15:00:08 +03:00
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
2013-10-07 21:32:55 +03:00
eval $data
domain="$DOMAIN"
2013-11-27 09:02:40 +02:00
if [ "$flush" = 'no' ]; then
2016-06-25 11:07:45 +03:00
is_domain_new 'dns' $domain
2013-11-27 09:02:40 +02:00
fi
2013-05-19 15:00:08 +03:00
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
2013-11-27 09:02:40 +02:00
# Flush records
if [ "$flush" = 'records' ]; then
rm -f $USER_DATA/dns/$DOMAIN.conf
touch $USER_DATA/dns/$DOMAIN.conf
chmod 660 $USER_DATA/dns/$DOMAIN.conf
fi
# Flush domain
if [ "$flush" != 'no' ]; then
2013-11-27 09:02:40 +02:00
sed -i "/DOMAIN='$DOMAIN'/d" $USER_DATA/dns.conf 2> /dev/null
fi
# 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-05-28 16:09:07 +03:00
# Prepare values for the insert
dns_rec="DOMAIN='$DOMAIN' IP='$IP' TPL='$TPL' TTL='$TTL' EXP='$EXP'"
2015-10-15 15:03:23 +03:00
dns_rec="$dns_rec SOA='$SOA' SERIAL="$SERIAL" SRC='$src' RECORDS='$RECORDS'"
dns_rec="$dns_rec SUSPENDED='$SUSPENDED' TIME='$time' DATE='$date'"
2013-05-28 16:09:07 +03:00
echo "$dns_rec" >> $USER_DATA/dns.conf
2013-05-19 15:00:08 +03:00
2013-11-27 09:02:40 +02:00
# Set permission
chmod 660 $USER_DATA/dns.conf
2013-05-19 15:00:08 +03:00
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
2015-10-28 16:34:41 +02:00
# Restarting named
$BIN/v-restart-dns $restart
check_result $? "Bind restart failed" >/dev/null
2013-05-31 12:46:32 +03:00
2013-05-19 15:00:08 +03:00
# Logging
log_event "$OK" "$ARGUMENTS"
2013-05-19 15:00:08 +03:00
exit