vesta/bin/v_change_web_domain_sslcert

110 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# info: changing domain ssl certificate
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user="$1"
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
certificate="$3"
# Importing variables
source $VESTA/conf/vars.conf
source $V_FUNC/shared_func.sh
source $V_FUNC/domain_func.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '3' "$#" 'user domain certificate'
# Checking argument format
format_validation 'user' 'domain' 'certificate'
# Checking web system is enabled
is_system_enabled 'web'
# Checking user
is_user_valid
# Checking user is active
is_user_suspended
# Checking domain exist
is_web_domain_valid
# Checking domain is not suspened
is_domain_suspended 'web_domains'
# Check SSL is added
is_web_domain_value_exist '$SSL_CERT'
# Checking ssl certificate
is_web_domain_cert_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Get template name
tpl_name=$(get_web_domain_value '$TPL')
tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
# Defininig config
conf="$V_HOME/$user/conf/shttpd.conf"
# Defining ssl key and certificate
ssl_cert="$V_HOME/$user/conf/$certificate.crt"
ssl_key="$V_HOME/$user/conf/$certificate.key"
# Defining search phrase
search_phrase='SSLCertificateFile'
# Defining replace string
str_repl=" SSLCertificateFile $ssl_cert"
# Changing sslhome
change_web_config
# Defining search phrase
search_phrase='SSLCertificateKeyFile'
# Defining replace string
str_repl=" SSLCertificateKeyFile $ssl_key"
# Changing sslhome
change_web_config
# Adding certificate to user dir
if [ ! -e "$ssl_cert" ]; then
cp -f $V_USERS/$user/cert/$certificate.crt $ssl_cert
cp -f $V_USERS/$user/cert/$certificate.key $ssl_key
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Get old sslhome value
old_ssl_cert=$(get_web_domain_value '$SSL_CERT')
# Adding sslcert in config
update_web_domain_value '$SSL_CERT' "$certificate"
# Adding task to the vesta pipe
restart_schedule 'web'
# Logging
log_history "$V_EVENT" "$V_SCRIPT $user $domain $old_ssl_cert"
log_event 'system' "$V_EVENT"
exit $OK