| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #!/bin/bash
- # info: change web domain proxy template
- # options: USER DOMAIN TEMPLATE [EXTENTIONS] [RESTART]
- #
- # The function changes proxy template
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Argument defenition
- user=$1
- domain=$(idn -t --quiet -u "$2" )
- domain_idn=$(idn -t --quiet -a "$domain")
- template=$3
- default_extentions="jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls,\
- exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp,rtf,js,mp3,avi,mpeg,flv,html,htm"
- extentions=${4-$default_extentions}
- restart="$5"
- # 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 TEMPLATE [EXTENTIONS] [RESTART]'
- validate_format 'user' 'domain' 'template'
- is_system_enabled "$PROXY_SYSTEM" 'PROXY_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_object_value_exist 'web' 'DOMAIN' "$domain" '$PROXY'
- is_proxy_template_valid
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Parsing domain values
- get_domain_values 'web'
- tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl"
- old_tpl=$PROXY
- conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
- ip=$(get_real_ip $IP)
- # Delete old vhost
- del_web_config
- # Add new vhost
- PROXY="$template"
- PROXY_EXT="$extentions"
- tpl_file="$WEBTPL/$PROXY_SYSTEM/$template.tpl"
- upd_web_domain_values
- add_web_config
- chown root:$user $conf
- chmod 640 $conf
- # Checking SSL
- if [ "$SSL" = 'yes' ]; then
- tpl_file="$WEBTPL/$PROXY_SYSTEM/$old_tpl.stpl"
- conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
- del_web_config
- tpl_file="$WEBTPL/$PROXY_SYSTEM/$template.stpl"
- add_web_config
- chown root:$user $conf
- chmod 640 $conf
- fi
- # Running template trigger
- if [ -x $WEBTPL/$PROXY_SYSTEM/$template.sh ]; then
- $WEBTPL/$PROXY_SYSTEM/$template.sh $user $domain $ip $HOMEDIR $docroot
- fi
- #----------------------------------------------------------#
- # Vesta #
- #----------------------------------------------------------#
- # Update config
- update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$PROXY"
- update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions"
- # Restart web
- if [ "$restart" != 'no' ]; then
- $BIN/v-restart-proxy
- if [ $? -ne 0 ]; then
- exit E_RESTART
- fi
- fi
- # Logging
- log_history "changed proxy template for $domain to $template"
- log_event "$OK" "$EVENT"
- exit
|