| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #!/bin/bash
- # info: change web domain ip
- # options: USER DOMAIN DOMAIN [RESTART]
- #
- # The call is used for changing domain ip
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Argument definition
- user=$1
- domain=$2
- ip=$3
- restart=$4
- # Includes
- source $VESTA/func/main.sh
- source $VESTA/func/domain.sh
- source $VESTA/func/ip.sh
- source $VESTA/conf/vesta.conf
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- check_args '3' "$#" 'USER DOMAIN IP [RESTART]'
- is_format_valid 'user' 'domain' 'ip'
- is_system_enabled "$WEB_SYSTEM" 'WEB_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"
- is_ip_valid "$ip" "$user"
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Preparing variables for vhost replace
- get_domain_values 'web'
- old=$(get_real_ip $IP)
- new=$ip
- if [[ "$domain" = *[![:ascii:]]* ]]; then
- domain_idn=$(idn -t --quiet -a $domain)
- else
- domain_idn=$domain
- fi
- # Replacing vhost
- replace_web_config "$WEB_SYSTEM" "$TPL.tpl"
- if [ "$SSL" = 'yes' ]; then
- replace_web_config "$WEB_SYSTEM" "$TPL.stpl"
- fi
- # Replacing proxy vhost
- if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
- replace_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
- if [ "$SSL" = 'yes' ]; then
- replace_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
- fi
- fi
- #----------------------------------------------------------#
- # Vesta #
- #----------------------------------------------------------#
- # Update counters
- increase_ip_value "$new"
- decrease_ip_value "$old"
- # Update config
- update_object_value 'web' 'DOMAIN' "$domain" '$IP' "$3"
- # Restart web server
- if [ "$restart" != 'no' ]; then
- $BIN/v-restart-web
- check_result $? "WEB restart failed" >/dev/null
- if [ ! -z "$PROXY_SYSTEM" ]; then
- $BIN/v-restart-proxy
- check_result $? "Proxy restart failed" >/dev/null
- fi
- fi
- # Logging
- log_history "changed web domain $domain ip to $3"
- log_event "$OK" "$ARGUMENTS"
- exit
|