add dns zones when editing webaliases

This commit is contained in:
Serghey Rodin 2012-07-25 10:43:25 +03:00
commit 530fc3b63d
6 changed files with 142 additions and 44 deletions

View file

@ -1,5 +1,5 @@
#!/bin/bash
# info: add dns domain or dns record based on web domain alias
# info: add dns domain or dns record based on web domain alias restart
# options: user domain
#
# The function adds dns domain or dns record based on web domain alias.
@ -11,8 +11,13 @@
# Argument defenition
user=$1
domain=$(echo $domain | sed -e 's/\.*$//g' -e 's/^\.*//g')
domain=$(echo $2 | sed -e 's/\.*$//g' -e 's/^\.*//g')
domain_idn=$(idn -t --quiet -a "$domain")
dom_alias=$(idn -t --quiet -u "$3" )
dom_alias=$(echo $dom_alias | sed -e 's/\.*$//g' -e 's/^\.*//g')
dom_alias=$(echo $dom_alias | tr '[:upper:]' '[:lower:]')
dom_alias_idn=$(idn -t --quiet -a "$dom_alias" )
restart="$4"
# Includes
source $VESTA/conf/vesta.conf
@ -24,7 +29,7 @@ source $VESTA/func/domain.sh
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'user domain'
check_args '3' "$#" 'user domain alias'
validate_format 'user' 'domain'
is_system_enabled "$WEB_SYSTEM"
is_system_enabled "$DNS_SYSTEM"
@ -41,34 +46,35 @@ is_object_unsuspended 'web' 'DOMAIN' "$domain"
# Parsing domain values
get_domain_values 'web'
OLD_IFS=$IFS
IFS=','
for web_alias in $ALIAS; do
# Check if parent dns domain exist
sub_domain=$(echo $web_alias | cut -f1 -d .)
pr_domain=$(echo $web_alias | sed -e "s/^$sub_domain.//" )
check_parent=$(grep "DOMAIN='$pr_domain'" $USER_DATA/dns.conf)
if [ -z "$check_parent" ]; then
check_dom=$(grep "DOMAIN='$web_alias'" $USER_DATA/dns.conf)
if [ -z "$check_dom" ]; then
$BIN/v_add_dns_domain $user $web_alias $IP
fi
# Check if it a simple domain
if [ $(echo -e "${dom_alias//\./\n}" | wc -l) -le 2 ]; then
if [ ! -e "$USER_DATA/dns/$dom_alias.conf" ]; then
$BIN/v_add_dns_domain $user $dom_alias $IP '' '' '' '' '' $restart
fi
else
# Check subdomain
sub=$(echo "$dom_alias" | cut -f1 -d . -s)
dom=$(echo "$dom_alias" | sed -e "s/^$sub.//" )
if [ ! -e "$USER_DATA/dns/$dom.conf" ]; then
$BIN/v_add_dns_domain $user $dom $IP '' '' '' '' '' $restart
$BIN/v_add_dns_domain_record $user $dom "$sub" A $IP '' '' $restart
else
check_rec=$(grep "RECORD='$sub_domain'" $USER_DATA/dns/$pr_domain.conf)
if [ -z "$check_rec" ]; then
$BIN/v_add_dns_domain_record $user $pr_domain $sub_domain A $IP
if [ "$sub" == '*' ]; then
rec=$(grep -w "RECORD='\*'" $USER_DATA/dns/$dom.conf)
else
rec=$(grep -w "RECORD='$sub'" $USER_DATA/dns/$dom.conf)
fi
if [ -z "$rec" ]; then
$BIN/v_add_dns_domain_record $user $dom "$sub" A $IP '' '' $restart
fi
fi
done
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Restart web server
$BIN/v_restart_dns "$EVENT"
# Logging
log_history "$EVENT"
log_event "$OK" "$EVENT"

80
bin/v_delete_dns_on_web_alias Executable file
View file

@ -0,0 +1,80 @@
#!/bin/bash
# info: delete dns domain or dns record based on web domain alias
# options: user domain
#
# The function deletes dns domain or dns record based on web domain alias.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
domain=$(echo $2 | sed -e 's/\.*$//g' -e 's/^\.*//g')
domain_idn=$(idn -t --quiet -a "$domain")
dom_alias=$(idn -t --quiet -u "$3" )
dom_alias=$(echo $dom_alias | sed -e 's/\.*$//g' -e 's/^\.*//g')
dom_alias=$(echo $dom_alias | tr '[:upper:]' '[:lower:]')
dom_alias_idn=$(idn -t --quiet -a "$dom_alias" )
restart="$4"
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'user domain alias'
validate_format 'user' 'domain'
is_system_enabled "$WEB_SYSTEM"
is_system_enabled "$DNS_SYSTEM"
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Parsing domain values
get_domain_values 'web'
# Check if it a simple domain
if [ $(echo -e "${dom_alias//\./\n}" | wc -l) -le 2 ]; then
if [ -e "$USER_DATA/dns/$dom_alias.conf" ]; then
$BIN/v_delete_dns_domain $user $dom_alias $IP $restart
fi
else
# Check subdomain
sub=$(echo "$dom_alias" | cut -f1 -d . -s)
root=$(echo "$dom_alias" | sed -e "s/^$sub.//" )
if [ -e "$USER_DATA/dns/$root.conf" ]; then
if [ "$sub" == '*' ]; then
rec=$(grep -w "RECORD='\*'" $USER_DATA/dns/$root.conf)
else
rec=$(grep -w "RECORD='$sub'" $USER_DATA/dns/$root.conf)
fi
if [ ! -z "$rec" ]; then
eval "$rec"
$BIN/v_delete_dns_domain_record $user "$root" "$ID"
fi
fi
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_history "$EVENT"
log_event "$OK" "$EVENT"
exit

View file

@ -58,7 +58,6 @@ done
recalc_user_disk_usage
# Logging
log_history "$EVENT"
log_event "$OK" "$EVENT"
exit