Fix change IP and suspending web domain

This commit is contained in:
MadeITBelgium 2017-09-23 14:13:09 +00:00
commit 668da0178e
7 changed files with 51 additions and 25 deletions

View file

@ -49,15 +49,18 @@ else
ip='' ip=''
fi fi
# Get old ip
get_domain_values 'dns'
if [ -z "$ip" ] && [ -z "$IP6" ]; then
check_result $E_INVALID "IP or IPv6 is required"
fi
#----------------------------------------------------------# #----------------------------------------------------------#
# Action # # Action #
#----------------------------------------------------------# #----------------------------------------------------------#
# Get old ip
get_domain_values 'dns'
old=$IP old=$IP
new=$ip
ipv6=$IP6
if [ -z "$old" ]; then if [ -z "$old" ]; then
#Create new #Create new
@ -71,13 +74,21 @@ else
# Changing records # Changing records
sed -i "s/$old/$ip/g" $USER_DATA/dns/$domain.conf sed -i "s/$old/$ip/g" $USER_DATA/dns/$domain.conf
else else
ip=""
ipv6=$IP6
#Delete configs #Delete configs
remove_dns_config_records remove_dns_config_records
fi fi
fi fi
# Changing ip # Changing ip
update_object_value 'dns' 'DOMAIN' "$domain" '$IP' "$new" update_object_value 'dns' 'DOMAIN' "$domain" '$IP' "$ip"
#update counters
records="$(wc -l $USER_DATA/dns/$domain.conf | cut -f1 -d ' ')"
update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records"
records=$(wc -l $USER_DATA/dns/*.conf | cut -f 1 -d ' ')
update_user_value "$user" '$U_DNS_RECORDS' "$records"
# Updating zone # Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then if [[ "$DNS_SYSTEM" =~ named|bind ]]; then

View file

@ -47,15 +47,17 @@ else
ipv6='' ipv6=''
fi fi
# Get old ip
get_domain_values 'dns'
if [ -z @"$ipv6" ] && [ -z "$IP" ]; then
check_result $E_INVALID "IP or IPv6 is required"
fi
#----------------------------------------------------------# #----------------------------------------------------------#
# Action # # Action #
#----------------------------------------------------------# #----------------------------------------------------------#
# Get old ip
get_domain_values 'dns'
old=$IP6 old=$IP6
new=$ipv6
ip=$IP
if [ -z "$old" ]; then if [ -z "$old" ]; then
#Create new #Create new
@ -66,18 +68,25 @@ if [ -z "$old" ]; then
ip="" ip=""
add_dns_config_records add_dns_config_records
else else
if [ ! -z "$ip" ]; then if [ ! -z "$ipv6" ]; then
# Changing records # Changing records
sed -i "s/$old/$ipv6/g" $USER_DATA/dns/$domain.conf sed -i "s/$old/$ipv6/g" $USER_DATA/dns/$domain.conf
else else
#Delete configs #Delete configs
ipv6=$old ipv6=""
ip=$IP
remove_dns_config_records remove_dns_config_records
fi fi
fi fi
# Changing ip # Changing ip
update_object_value 'dns' 'DOMAIN' "$domain" '$IP6' "$new" update_object_value 'dns' 'DOMAIN' "$domain" '$IP6' "$ipv6"
#update counters
records="$(wc -l $USER_DATA/dns/$domain.conf | cut -f1 -d ' ')"
update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records"
records=$(wc -l $USER_DATA/dns/*.conf | cut -f 1 -d ' ')
update_user_value "$user" '$U_DNS_RECORDS' "$records"
# Updating zone # Updating zone
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then if [[ "$DNS_SYSTEM" =~ named|bind ]]; then

View file

@ -54,6 +54,10 @@ fi
# Preparing variables for vhost replace # Preparing variables for vhost replace
get_domain_values 'web' get_domain_values 'web'
if [ -z "$ip" ] && [ -z "$IP6" ]; then
check_result $E_INVALID "IP or IPv6 is required"
fi
old=$(get_real_ip $IP) old=$(get_real_ip $IP)
new=$ip new=$ip

View file

@ -52,6 +52,10 @@ fi
# Preparing variables for vhost replace # Preparing variables for vhost replace
get_domain_values 'web' get_domain_values 'web'
if [ -z "$ipv6" ] && [ -z "$IP" ]; then
check_result $E_INVALID "IP or IPv6 is required"
fi
old=$IP6 old=$IP6
new=$ipv6 new=$ipv6

View file

@ -76,6 +76,8 @@ fi
# Rebuilding vhost IPv6 # Rebuilding vhost IPv6
if [ ! -z "$IP6" ]; then if [ ! -z "$IP6" ]; then
local_ip=""
ipv6=$IP6
old=$IP6 old=$IP6
del_web_config "$WEB_SYSTEM" "$TPL.tpl" del_web_config "$WEB_SYSTEM" "$TPL.tpl"
add_web_config "$WEB_SYSTEM" "$TPL.tpl" add_web_config "$WEB_SYSTEM" "$TPL.tpl"

View file

@ -75,6 +75,8 @@ fi
# Rebuilding vhost IPv6 # Rebuilding vhost IPv6
if [ ! -z "$IP6" ]; then if [ ! -z "$IP6" ]; then
old=$IP6 old=$IP6
local_ip=""
ipv6=$IP6
del_web_config "$WEB_SYSTEM" "$TPL.tpl" del_web_config "$WEB_SYSTEM" "$TPL.tpl"
add_web_config "$WEB_SYSTEM" "$TPL.tpl" add_web_config "$WEB_SYSTEM" "$TPL.tpl"
if [ "$SSL" = 'yes' ]; then if [ "$SSL" = 'yes' ]; then

View file

@ -535,8 +535,6 @@ add_dns_config() {
if [ ! -z $ipv6 ]; then if [ ! -z $ipv6 ]; then
spfipv6="ip6:$ipv6"; spfipv6="ip6:$ipv6";
fi fi
echo $spfipv4
echo $spfipv6
# Adding dns zone to the user config # Adding dns zone to the user config
echo "$template_data" | grep -v '%ip' |\ echo "$template_data" | grep -v '%ip' |\
@ -606,15 +604,13 @@ add_dns_config_records() {
template_data=$(echo "$template_data" |grep "%ipv6%") template_data=$(echo "$template_data" |grep "%ipv6%")
fi fi
new_lines=$(echo "$template_data" |\ echo "$template_data" |\
sed -e "s/%ip%/$ip/g" \ sed -e "s/%ip%/$ip/g" \
-e "s/%ipv6%/$ipv6/g" \ -e "s/%ipv6%/$ipv6/g" \
-e "s/%time%/$time/g" \ -e "s/%time%/$time/g" \
-e "s/%date%/$date/g" \ -e "s/%date%/$date/g" \
|awk -F 'ID=' '{print $2}' \ |awk -F 'ID=' '{print $2}' \
|cut -d\' --complement -s -f1,2) |cut -d\' --complement -s -f1,2 \
echo "$new_lines"\
| while read line; do | while read line; do
id="" id=""
get_next_dnsrecord get_next_dnsrecord
@ -626,7 +622,7 @@ add_dns_config_records() {
remove_dns_config_records() { remove_dns_config_records() {
template_data=$(cat $DNSTPL/$TPL.tpl) template_data=$(cat $DNSTPL/$TPL.tpl)
# Adding dns zone to the user config # Search template data
template_data=$(echo "$template_data" |grep -v "v=spf1" |egrep "%ip(v6)?%") template_data=$(echo "$template_data" |grep -v "v=spf1" |egrep "%ip(v6)?%")
if [ -z "$ip" ]; then if [ -z "$ip" ]; then
template_data=$(echo "$template_data" |grep "%ip%") template_data=$(echo "$template_data" |grep "%ip%")
@ -635,16 +631,14 @@ remove_dns_config_records() {
template_data=$(echo "$template_data" |grep "%ipv6%") template_data=$(echo "$template_data" |grep "%ipv6%")
fi fi
delete_lines=$(echo "$template_data" |\ echo "$template_data" |\
sed -e "s/%ip%/$old/g" \ sed -e "s/%ip%/$old/g" \
-e "s/%ipv6%/$old/g" \ -e "s/%ipv6%/$old/g" \
|awk -F 'ID=' '{print $2}' \ |awk -F 'ID=' '{print $2}' \
|cut -d\' --complement -s -f1,2 \ |cut -d\' --complement -s -f1,2 \
|awk -F 'TIME=' '{print $1}'); |awk -F ' SUSPENDED=' '{print $1}' \
echo "$delete_lines"\
| while read line; do | while read line; do
sed -i '/$line/d' $USER_DATA/dns/$domain.conf sed -i "/$line/d" $USER_DATA/dns/$domain.conf
done done
} }