|
| 1 | +#!/bin/bash |
| 2 | +# info: change web domain nginx template |
| 3 | +# options: user domain template [extentions] [restart] |
| 4 | +# |
| 5 | +# The function changes template of nginx.conf configuration file. The content |
| 6 | +# of webdomain directories remains untouched. |
| 7 | + |
| 8 | + |
| 9 | +#----------------------------------------------------------# |
| 10 | +# Variable&Function # |
| 11 | +#----------------------------------------------------------# |
| 12 | + |
| 13 | +# Argument defenition |
| 14 | +user=$1 |
| 15 | +domain=$(idn -t --quiet -u "$2" ) |
| 16 | +domain_idn=$(idn -t --quiet -a "$domain") |
| 17 | +template=$3 |
| 18 | +default_extentions="jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls,\ |
| 19 | +exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp,rtf,js,mp3,avi,mpeg,flv,html,htm" |
| 20 | +extentions=${4-$default_extentions} |
| 21 | +restart="$5" |
| 22 | + |
| 23 | + |
| 24 | +# Includes |
| 25 | +source $VESTA/conf/vesta.conf |
| 26 | +source $VESTA/func/main.sh |
| 27 | +source $VESTA/func/domain.sh |
| 28 | + |
| 29 | + |
| 30 | +#----------------------------------------------------------# |
| 31 | +# Verifications # |
| 32 | +#----------------------------------------------------------# |
| 33 | + |
| 34 | +check_args '3' "$#" 'user domain template [extentions] [restart]' |
| 35 | +validate_format 'user' 'domain' 'template' |
| 36 | +is_system_enabled "$PROXY_SYSTEM" |
| 37 | +is_object_valid 'user' 'USER' "$user" |
| 38 | +is_object_unsuspended 'user' 'USER' "$user" |
| 39 | +is_object_valid 'web' 'DOMAIN' "$domain" |
| 40 | +is_object_unsuspended 'web' 'DOMAIN' "$domain" |
| 41 | +is_object_value_exist 'web' 'DOMAIN' "$domain" '$NGINX' |
| 42 | +is_nginx_template_valid |
| 43 | + |
| 44 | + |
| 45 | +#----------------------------------------------------------# |
| 46 | +# Action # |
| 47 | +#----------------------------------------------------------# |
| 48 | + |
| 49 | +# Parsing domain values |
| 50 | +get_domain_values 'web' |
| 51 | +tpl_file="$WEBTPL/ngingx_vhost_$NGINX.tpl" |
| 52 | +conf="$HOMEDIR/$user/conf/web/nginx.conf" |
| 53 | + |
| 54 | +# Delete old vhost |
| 55 | +del_web_config |
| 56 | + |
| 57 | +# Checking ssl |
| 58 | +if [ "$SSL" = 'yes' ]; then |
| 59 | + tpl_file="$WEBTPL/ngingx_vhost_$NGINX.stpl" |
| 60 | + conf="$HOMEDIR/$user/conf/web/snginx.conf" |
| 61 | + del_web_config |
| 62 | +fi |
| 63 | + |
| 64 | +# Add new vhost |
| 65 | +NGINX="$template" |
| 66 | +NGINX_EXT="$extentions" |
| 67 | +tpl_file="$WEBTPL/ngingx_vhost_$NGINX.tpl" |
| 68 | +conf="$HOMEDIR/$user/conf/web/nginx.conf" |
| 69 | +upd_web_domain_values |
| 70 | +add_web_config |
| 71 | +chown root:nginx $conf |
| 72 | +chmod 640 $conf |
| 73 | + |
| 74 | +# Checking ssl |
| 75 | +if [ "$SSL" = 'yes' ]; then |
| 76 | + proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;" |
| 77 | + tpl_file="$WEBTPL/ngingx_vhost_$NGINX.stpl" |
| 78 | + conf="$HOMEDIR/$user/conf/web/snginx.conf" |
| 79 | + add_web_config |
| 80 | + chown root:nginx $conf |
| 81 | + chmod 640 $conf |
| 82 | +fi |
| 83 | + |
| 84 | + |
| 85 | +#----------------------------------------------------------# |
| 86 | +# Vesta # |
| 87 | +#----------------------------------------------------------# |
| 88 | + |
| 89 | +# Update config |
| 90 | +update_object_value 'web' 'DOMAIN' "$domain" '$NGINX' "$NGINX" |
| 91 | +update_object_value 'web' 'DOMAIN' "$domain" '$NGINX_EXT' "$extentions" |
| 92 | + |
| 93 | +# Restart web |
| 94 | +if [ "$restart" != 'no' ]; then |
| 95 | + $BIN/v_restart_web "$EVENT" |
| 96 | +fi |
| 97 | + |
| 98 | +# Logging |
| 99 | +log_history "$EVENT" |
| 100 | +log_event "$OK" "$EVENT" |
| 101 | + |
| 102 | +exit |
0 commit comments