2013-01-19 23:07:26 +02:00
|
|
|
#!/bin/bash
|
2013-05-10 11:04:40 +03:00
|
|
|
# info: add webdomain proxy support
|
2013-01-19 23:07:26 +02:00
|
|
|
# options: USER DOMAIN [TEMPLATE] [EXTENTIONS] [RESTART]
|
|
|
|
#
|
2013-05-10 11:04:40 +03:00
|
|
|
# The function enables proxy support for a domain. This can significantly
|
|
|
|
# improve website speed.
|
2013-01-19 23:07:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Variable&Function #
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
2015-11-06 17:38:58 +02:00
|
|
|
# Argument definition
|
2013-01-19 23:07:26 +02:00
|
|
|
user=$1
|
2016-08-25 19:45:37 +03:00
|
|
|
domain=$2
|
2013-01-19 23:07:26 +02:00
|
|
|
template=$3
|
2019-12-29 20:16:00 +01:00
|
|
|
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,woff,woff2"
|
2013-01-19 23:07:26 +02:00
|
|
|
extentions=${4-$default_extentions}
|
|
|
|
restart="$5"
|
|
|
|
|
|
|
|
# Includes
|
|
|
|
source $VESTA/func/main.sh
|
|
|
|
source $VESTA/func/domain.sh
|
2013-02-05 22:58:40 +02:00
|
|
|
source $VESTA/func/ip.sh
|
2013-10-09 00:50:08 +03:00
|
|
|
source $VESTA/conf/vesta.conf
|
2013-01-19 23:07:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Verifications #
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
|
|
|
check_args '2' "$#" 'USER DOMAIN [TEMPLATE] [EXTENTIONS] [RESTART]'
|
2016-06-09 17:05:41 +03:00
|
|
|
is_format_valid 'user' 'domain' 'extentions'
|
2013-05-29 13:16:09 +03:00
|
|
|
is_system_enabled "$PROXY_SYSTEM" 'PROXY_SYSTEM'
|
2013-01-19 23:07:26 +02:00
|
|
|
is_object_valid 'user' 'USER' "$user"
|
|
|
|
is_object_unsuspended 'user' 'USER' "$user"
|
|
|
|
is_object_valid 'web' 'DOMAIN' "$domain"
|
|
|
|
is_object_unsuspended 'web' 'DOMAIN' "$domain"
|
2013-05-10 11:04:40 +03:00
|
|
|
is_object_value_empty 'web' 'DOMAIN' "$domain" '$PROXY'
|
|
|
|
if [ -z $template ]; then
|
|
|
|
template=$(get_user_value '$PROXY_TEMPLATE')
|
2013-01-19 23:07:26 +02:00
|
|
|
fi
|
2015-09-07 16:42:32 +03:00
|
|
|
is_proxy_template_valid $template
|
2013-01-19 23:07:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Action #
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
|
|
|
# Defining domain parameters
|
|
|
|
get_domain_values 'web'
|
2016-08-25 19:45:37 +03:00
|
|
|
prepare_web_domain_values
|
2016-06-09 17:05:41 +03:00
|
|
|
local_ip=$(get_real_ip $IP)
|
2013-01-19 23:07:26 +02:00
|
|
|
|
|
|
|
# Preparing domain values for the template substitution
|
2016-06-09 17:05:41 +03:00
|
|
|
PROXY_EXT="$extentions"
|
2016-06-24 16:31:43 +03:00
|
|
|
add_web_config "$PROXY_SYSTEM" "$template.tpl"
|
2013-01-19 23:07:26 +02:00
|
|
|
|
2016-06-09 17:05:41 +03:00
|
|
|
# Adding proxy for ssl
|
2013-01-19 23:07:26 +02:00
|
|
|
if [ "$SSL" = 'yes' ]; then
|
2016-06-24 16:31:43 +03:00
|
|
|
add_web_config "$PROXY_SYSTEM" "$template.stpl"
|
2013-06-10 10:59:35 +03:00
|
|
|
fi
|
|
|
|
|
2013-01-19 23:07:26 +02:00
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Vesta #
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
|
|
|
# Update config
|
2016-06-24 16:31:43 +03:00
|
|
|
update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$template"
|
2013-05-10 11:04:40 +03:00
|
|
|
update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions"
|
2013-01-19 23:07:26 +02:00
|
|
|
|
2015-10-28 16:34:41 +02:00
|
|
|
# Restarting web server
|
2017-01-11 16:52:11 +02:00
|
|
|
$BIN/v-restart-proxy $restart
|
|
|
|
check_result $? "Proxy restart failed" >/dev/null
|
2013-01-19 23:07:26 +02:00
|
|
|
|
2013-05-10 11:04:40 +03:00
|
|
|
log_history "enabled proxy support for $domain"
|
2016-06-09 17:05:41 +03:00
|
|
|
log_event "$OK" "$ARGUMENTS"
|
2013-01-19 23:07:26 +02:00
|
|
|
|
|
|
|
exit
|