diff --git a/bin/v_add_web_domain_nginx b/bin/v_add_web_domain_nginx index 296b03b3..570db0fe 100755 --- a/bin/v_add_web_domain_nginx +++ b/bin/v_add_web_domain_nginx @@ -15,8 +15,8 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") template=${3-default} -default_extentions="jpg,jpeg,gif,png,ico,css,zip,tgz,gz,rar,bz2,doc,xls,exe,\ -pdf,ppt,txt,tar,wav,bmp,rtf,js,mp3,avi,mpeg,html,htm" +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" diff --git a/bin/v_add_web_domain_stats_user b/bin/v_add_web_domain_stats_user index ff856ca3..9ce696ac 100755 --- a/bin/v_add_web_domain_stats_user +++ b/bin/v_add_web_domain_stats_user @@ -37,7 +37,6 @@ 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" '$STATS' #----------------------------------------------------------# diff --git a/bin/v_change_dns_domain_ip b/bin/v_change_dns_domain_ip index 2b6f30da..b81f3cc6 100755 --- a/bin/v_change_dns_domain_ip +++ b/bin/v_change_dns_domain_ip @@ -14,6 +14,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") ip=$3 +restart=$4 # Includes source $VESTA/conf/vesta.conf @@ -53,7 +54,9 @@ update_domain_zone #----------------------------------------------------------# # Restart named -$BIN/v_restart_dns "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_dns "$EVENT" +fi # Logging log_history "$EVENT" diff --git a/bin/v_change_web_domain_ip b/bin/v_change_web_domain_ip index a9d291e9..9174b8b6 100755 --- a/bin/v_change_web_domain_ip +++ b/bin/v_change_web_domain_ip @@ -1,6 +1,6 @@ #!/bin/bash # info: change web domain ip address -# options: user domain ip +# options: user domain ip [restart] # # The call is used for changing the site ip address. The ip change will be # performed for a virtual apache host and for a configuration nginx file both. @@ -15,6 +15,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") ip=$3 +restart=$4 # Includes source $VESTA/conf/vesta.conf @@ -27,7 +28,7 @@ source $VESTA/func/ip.sh # Verifications # #----------------------------------------------------------# -check_args '3' "$#" 'user domain ip' +check_args '3' "$#" 'user domain ip [restart]' validate_format 'user' 'domain' 'ip' is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" @@ -84,7 +85,9 @@ decrease_ip_value "$old" update_object_value 'web' 'DOMAIN' "$domain" '$IP' "$ip" # Restart web server -$BIN/v_restart_web "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_web "$EVENT" +fi # Logging log_history "$EVENT" diff --git a/bin/v_change_web_domain_nginx_tpl b/bin/v_change_web_domain_nginx_tpl new file mode 100755 index 00000000..b93f1c98 --- /dev/null +++ b/bin/v_change_web_domain_nginx_tpl @@ -0,0 +1,102 @@ +#!/bin/bash +# info: change web domain nginx template +# options: user domain template [extentions] [restart] +# +# The function changes template of nginx.conf configuration file. The content +# of webdomain directories remains untouched. + + +#----------------------------------------------------------# +# 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/conf/vesta.conf +source $VESTA/func/main.sh +source $VESTA/func/domain.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '3' "$#" 'user domain template [extentions] [restart]' +validate_format 'user' 'domain' 'template' +is_system_enabled "$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" '$NGINX' +is_nginx_template_valid + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Parsing domain values +get_domain_values 'web' +tpl_file="$WEBTPL/ngingx_vhost_$NGINX.tpl" +conf="$HOMEDIR/$user/conf/web/nginx.conf" + +# Delete old vhost +del_web_config + +# Checking ssl +if [ "$SSL" = 'yes' ]; then + tpl_file="$WEBTPL/ngingx_vhost_$NGINX.stpl" + conf="$HOMEDIR/$user/conf/web/snginx.conf" + del_web_config +fi + +# Add new vhost +NGINX="$template" +NGINX_EXT="$extentions" +tpl_file="$WEBTPL/ngingx_vhost_$NGINX.tpl" +conf="$HOMEDIR/$user/conf/web/nginx.conf" +upd_web_domain_values +add_web_config +chown root:nginx $conf +chmod 640 $conf + +# Checking ssl +if [ "$SSL" = 'yes' ]; then + proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;" + tpl_file="$WEBTPL/ngingx_vhost_$NGINX.stpl" + conf="$HOMEDIR/$user/conf/web/snginx.conf" + add_web_config + chown root:nginx $conf + chmod 640 $conf +fi + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$NGINX' "$NGINX" +update_object_value 'web' 'DOMAIN' "$domain" '$NGINX_EXT' "$extentions" + +# Restart web +if [ "$restart" != 'no' ]; then + $BIN/v_restart_web "$EVENT" +fi + +# Logging +log_history "$EVENT" +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v_change_web_domain_stats b/bin/v_change_web_domain_stats new file mode 100755 index 00000000..01a95e37 --- /dev/null +++ b/bin/v_change_web_domain_stats @@ -0,0 +1,91 @@ +#!/bin/bash +# info: change web domain statistics +# options: user domain type +# +# The function of deleting site's system of statistics. Its type is +# automatically chooses from client's configuration file. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=$1 +domain=$(idn -t --quiet -u "$2" ) +type=$3 + +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/main.sh +source $VESTA/func/domain.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '3' "$#" 'user domain type' +validate_format 'user' 'domain' +is_system_enabled "$WEB_SYSTEM" +is_type_valid "$STATS_SYSTEM" "$type" +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" '$STATS' + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Defining statistic type +get_domain_values 'web' + +# Comparing stats types +if [ "$STATS" == $type ]; then + log_event "$OK" "$EVENT" + exit 0 +fi + +# Defining statistic dir +stats_dir="$HOMEDIR/$user/web/$domain/stats" + +# Deleting dir content +rm -rf $stats_dir/* + +# Deleting config +rm -f $HOMEDIR/$user/conf/web/$STATS.$domain.conf + +# Preparing domain values for the template substitution +upd_web_domain_values + +# Adding statistic config +cat $WEBTPL/$type.tpl |\ + sed -e "s/%ip%/$ip/g" \ + -e "s/%web_port%/$WEB_PORT/g" \ + -e "s/%web_ssl_port%/$WEB_SSL_PORT/g" \ + -e "s/%proxy_port%/$PROXY_PORT/g" \ + -e "s/%proxy_ssl_port%/$PROXY_SSL_PORT/g" \ + -e "s/%domain_idn%/$domain_idn/g" \ + -e "s/%domain%/$domain/g" \ + -e "s/%user%/$user/g" \ + -e "s/%home%/${HOMEDIR////\/}/g" \ + -e "s/%alias%/${aliases//,/ }/g" \ + -e "s/%alias_idn%/${aliases_idn//,/ }/g" \ + > $HOMEDIR/$user/conf/web/$type.$domain.conf + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$STATS' "$type" + +# Logging +log_history "$EVENT" +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v_change_web_domain_tpl b/bin/v_change_web_domain_tpl index ae09532b..5f42b541 100755 --- a/bin/v_change_web_domain_tpl +++ b/bin/v_change_web_domain_tpl @@ -1,6 +1,6 @@ #!/bin/bash # info: change web domain template -# options: user domain template +# options: user domain template [restart] # # The function changes template of httpd.conf configuration file. The content # of webdomain directories remains untouched. @@ -15,6 +15,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") template=$3 +restart=$4 # Includes source $VESTA/conf/vesta.conf @@ -26,7 +27,7 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -check_args '3' "$#" 'user domain template' +check_args '3' "$#" 'user domain template [restart]' validate_format 'user' 'domain' 'template' is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" @@ -170,7 +171,9 @@ for keys in $(cat $WEBTPL/apache_$template.descr|grep -v '#'); do done # Restart web -$BIN/v_restart_web "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_web "$EVENT" +fi # Logging log_history "$EVENT" diff --git a/bin/v_delete_web_domain_alias b/bin/v_delete_web_domain_alias index 14a68bb5..b6ef843d 100755 --- a/bin/v_delete_web_domain_alias +++ b/bin/v_delete_web_domain_alias @@ -1,6 +1,6 @@ #!/bin/bash # info: delete web domain alias -# options: user domain alias +# options: user domain alias [restart] # # The function of deleting the alias domain (parked domain). By this call # default www aliase can be removed as well. @@ -16,6 +16,7 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain" ) dom_alias=$(idn -t --quiet -u "$3" ) dom_alias_idn=$(idn -t --quiet -a "$dom_alias" ) +restart="$4" # Includes source $VESTA/conf/vesta.conf @@ -27,7 +28,7 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -check_args '3' "$#" 'user domain dom_alias' +check_args '3' "$#" 'user domain dom_alias [restart]' validate_format 'user' 'domain' 'dom_alias' is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" @@ -97,7 +98,9 @@ update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS" decrease_user_value "$user" '$U_WEB_ALIASES' # Restart web server -$BIN/v_restart_web "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_web "$EVENT" +fi # Logging log_history "$EVENT" diff --git a/bin/v_delete_web_domain_elog b/bin/v_delete_web_domain_elog index 013fd0e9..9b4acd16 100755 --- a/bin/v_delete_web_domain_elog +++ b/bin/v_delete_web_domain_elog @@ -1,6 +1,6 @@ #!/bin/bash # info: delete web domain error loggin support -# options: user domain +# options: user domain [restart] # # The function of disabling error logging feature. It comments ErrorLog # direcitve in apache or/and nginx configuration. The data already collected @@ -15,6 +15,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") +restart=$3 # Includes source $VESTA/conf/vesta.conf @@ -26,7 +27,7 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -check_args '2' "$#" 'user domain' +check_args '2' "$#" 'user domain [restart]' validate_format 'user' 'domain' is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" "$user" @@ -86,7 +87,9 @@ fi update_object_value 'web' 'DOMAIN' "$domain" '$ELOG' 'no' # Restart web server -$BIN/v_restart_web "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_web "$EVENT" +fi # Logging log_history "$EVENT" diff --git a/bin/v_delete_web_domain_nginx b/bin/v_delete_web_domain_nginx index dd0e6642..b33fdc6e 100755 --- a/bin/v_delete_web_domain_nginx +++ b/bin/v_delete_web_domain_nginx @@ -13,6 +13,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") +restart=$3 # Includes source $VESTA/conf/vesta.conf @@ -75,7 +76,9 @@ if [ -z "$last_nginx" ]; then fi # Restart web server -$BIN/v_restart_web "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_web "$EVENT" +fi # Logging log_history "$EVENT" diff --git a/bin/v_delete_web_domain_ssl b/bin/v_delete_web_domain_ssl index 0fb98a21..c6a739ad 100755 --- a/bin/v_delete_web_domain_ssl +++ b/bin/v_delete_web_domain_ssl @@ -13,6 +13,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") +restart=$3 # Includes source $VESTA/conf/vesta.conf @@ -89,7 +90,9 @@ fi decrease_user_value "$user" '$U_WEB_SSL' # Restart web server -$BIN/v_restart_web "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_web "$EVENT" +fi # Logging log_history "$EVENT" diff --git a/bin/v_list_web_domain b/bin/v_list_web_domain index f8bb6c29..e1b806bc 100755 --- a/bin/v_list_web_domain +++ b/bin/v_list_web_domain @@ -76,7 +76,7 @@ conf=$USER_DATA/web.conf # Defining fileds to select fields='$DOMAIN $IP $IP6 $U_DISK $U_BANDWIDTH $TPL $ALIAS $PHP $CGI $ELOG - $STATS $STATS_AUTH $SSL $SSL_HOME $NGINX $NGINX_EXT $SUSPENDED $DATE' + $STATS $STATS_USER $SSL $SSL_HOME $NGINX $NGINX_EXT $SUSPENDED $TIME $DATE' # Listing domains case $format in diff --git a/bin/v_list_web_domains b/bin/v_list_web_domains index c9783b71..c6deaf93 100755 --- a/bin/v_list_web_domains +++ b/bin/v_list_web_domains @@ -35,7 +35,7 @@ conf=$USER_DATA/web.conf # Defining fileds to select fields="\$DOMAIN \$IP \$IP6 \$U_DISK \$U_BANDWIDTH \$TPL \$ALIAS \$PHP \$CGI" -fields="$fields \$ELOG \$STATS \$STATS_AUTH \$SSL \$SSL_HOME \$NGINX" +fields="$fields \$ELOG \$STATS \$STATS_USER \$SSL \$SSL_HOME \$NGINX" fields="$fields \$NGINX_EXT \$SUSPENDED \$TIME \$DATE" # Listing domains diff --git a/data/packages/default.pkg b/data/packages/default.pkg index 11fd0516..d89deafe 100644 --- a/data/packages/default.pkg +++ b/data/packages/default.pkg @@ -1,6 +1,6 @@ WEB_DOMAINS='100' WEB_ALIASES='100' -WEB_TPL='default,phpfcgi,unlim' +WEB_TPL='default,phpfcgid,unlim' DNS_DOMAINS='100' DNS_RECORDS='100' MAIL_DOMAINS='100' diff --git a/data/templates/web/apache_unlim.stpl b/data/templates/web/apache_unlim.stpl index 7df4a2ed..50f6f916 100644 --- a/data/templates/web/apache_unlim.stpl +++ b/data/templates/web/apache_unlim.stpl @@ -16,11 +16,6 @@ SSLRequireSSL Options +Includes -Indexes %cgi_option% php_admin_value upload_tmp_dir %home%/%user%/tmp - php_admin_value upload_max_filesize 60M - php_admin_value max_execution_time 60 - php_admin_value post_max_size 60M - php_admin_value memory_limit 60M - php_admin_flag mysql.allow_persistent off php_admin_flag safe_mode off php_admin_value session.save_path %home%/%user%/tmp php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f %email%' diff --git a/data/templates/web/apache_unlim.tpl b/data/templates/web/apache_unlim.tpl index 35654011..20abb847 100644 --- a/data/templates/web/apache_unlim.tpl +++ b/data/templates/web/apache_unlim.tpl @@ -15,11 +15,6 @@ AllowOverride All Options +Includes -Indexes %cgi_option% php_admin_value upload_tmp_dir %home%/%user%/tmp - php_admin_value upload_max_filesize 60M - php_admin_value max_execution_time 60 - php_admin_value post_max_size 60M - php_admin_value memory_limit 60M - php_admin_flag mysql.allow_persistent off php_admin_flag safe_mode off php_admin_value session.save_path %home%/%user%/tmp php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f %email%' diff --git a/func/domain.sh b/func/domain.sh index 2b5a66b6..7a1e5869 100644 --- a/func/domain.sh +++ b/func/domain.sh @@ -17,7 +17,7 @@ is_nginx_template_valid() { d="$WEBTPL/ngingx_vhost_$template.descr" s="$WEBTPL/ngingx_vhost_$template.stpl" if [ ! -e $t ] || [ ! -e $d ] || [ ! -e $s ]; then - echo "Error: $template not found" + echo "Error: nginx $template not found" log_event "$E_NOTEXIST" "$EVENT" exit $E_NOTEXIST fi diff --git a/web/add/web/index.php b/web/add/web/index.php index 61c23451..ace74674 100644 --- a/web/add/web/index.php +++ b/web/add/web/index.php @@ -1,6 +1,6 @@ ', $output); @@ -92,7 +93,7 @@ if ($_SESSION['user'] == 'admin') { $valiases = preg_replace("/\n/", " ", $_POST['v_aliases']); $valiases = preg_replace("/,/", " ", $valiases); $valiases = preg_replace('/\s+/', ' ',$valiases); - + $valiases = trim($valiases); $aliases = explode(" ", $valiases); foreach ($aliases as $alias) { $alias = escapeshellarg($alias); @@ -146,23 +147,23 @@ if ($_SESSION['user'] == 'admin') { $tmpdir = $output[0]; // Certificate - if (!empty($_POST['v_ssl_cert'])) { + if (!empty($_POST['v_ssl_crt'])) { $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); - fwrite($fp, $_POST['v_ssl_cert']."\n"); + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); fclose($fp); } // Key if (!empty($_POST['v_ssl_key'])) { $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); - fwrite($fp, $_POST['v_ssl_key']."\n"); + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); fclose($fp); } - // Pem - if (!empty($_POST['v_ssl_pem'])) { - $fp = fopen($tmpdir."/".$_POST['v_domain'].".pem", 'w'); - fwrite($fp, $_POST['v_ssl_pem']."\n"); + // CA + if (!empty($_POST['v_ssl_ca'])) { + $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); fclose($fp); } @@ -199,9 +200,9 @@ if ($_SESSION['user'] == 'admin') { unset($v_domain); unset($v_aliases); unset($v_ssl); - unset($v_ssl_cert); + unset($v_ssl_crt); unset($v_ssl_key); - unset($v_ssl_pem); + unset($v_ssl_ca); } } } diff --git a/web/edit/user/index.php b/web/edit/user/index.php index b101c00b..6a82f189 100644 --- a/web/edit/user/index.php +++ b/web/edit/user/index.php @@ -1,6 +1,6 @@ ', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } else { + $data = json_decode(implode('', $output), true); + unset($output); + $v_username = $user; + $v_domain = $_GET['domain']; + $v_ip = $data[$v_domain]['IP']; + $v_template = $data[$v_domain]['TPL']; + $v_aliases = str_replace(',', "\n", $data[$v_domain]['ALIAS']); + $valiases = explode(",", $data[$v_domain]['ALIAS']); + $v_tpl = $data[$v_domain]['IP']; + $v_cgi = $data[$v_domain]['CGI']; + $v_elog = $data[$v_domain]['ELOG']; + $v_ssl = $data[$v_domain]['SSL']; + if ( $v_ssl == 'yes' ) { + exec (VESTA_CMD."v_list_web_domain_ssl ".$user." '".$v_domain."' json", $output, $return_var); + $ssl_str = json_decode(implode('', $output), true); + unset($output); + $v_ssl_crt = $ssl_str[$v_domain]['CRT']; + $v_ssl_key = $ssl_str[$v_domain]['KEY']; + $v_ssl_ca = $ssl_str[$v_domain]['CA']; + } + $v_ssl_home = $data[$v_domain]['SSL_HOME']; + $v_nginx = $data[$v_domain]['NGINX']; + $v_nginx_ext = str_replace(',', ', ', $data[$v_domain]['NGINX_EXT']); + $v_stats = $data[$v_domain]['STATS']; + $v_stats_user = $data[$v_domain]['STATS_USER']; + if (!empty($v_stats_user)) $v_stats_password = "••••••••"; + $v_suspended = $data[$v_domain]['SUSPENDED']; + if ( $v_suspended == 'yes' ) { + $v_status = 'suspended'; + } else { + $v_status = 'active'; + } + $v_time = $data[$v_domain]['TIME']; + $v_date = $data[$v_domain]['DATE']; + + exec (VESTA_CMD."v_list_user_ips ".$user." json", $output, $return_var); + $ips = json_decode(implode('', $output), true); + unset($output); + + exec (VESTA_CMD."v_list_web_templates ".$user." json", $output, $return_var); + $templates = json_decode(implode('', $output), true); + unset($output); + + exec (VESTA_CMD."v_list_web_stats json", $output, $return_var); + $stats = json_decode(implode('', $output), true); + unset($output); + } + + // Action + if (!empty($_POST['save'])) { + $v_domain = escapeshellarg($_POST['v_domain']); + + // IP + if (($v_ip != $_POST['v_ip']) && (empty($_SESSION['error_msg']))) { + $v_ip = escapeshellarg($_POST['v_ip']); + exec (VESTA_CMD."v_change_web_domain_ip ".$v_username." ".$v_domain." ".$v_ip." 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + $restart_web = 'yes'; + unset($output); + exec (VESTA_CMD."v_list_dns_domain ".$v_username." ".$v_domain." json", $output, $return_var); + if ((empty($_SESSION['error_msg'])) && ($return_var == 0 )) { + exec (VESTA_CMD."v_change_dns_domain_ip ".$v_username." ".$v_domain." ".$v_ip." 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + $restart_dns = 'yes'; + } + unset($output); + foreach($valiases as $v_alias ){ + exec (VESTA_CMD."v_list_dns_domain ".$v_username." '".$v_alias."' json", $output, $return_var); + if ((empty($_SESSION['error_msg'])) && ($return_var == 0 )) { + exec (VESTA_CMD."v_change_dns_domain_ip ".$v_username." '".$v_alias."' ".$v_ip, $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + $restart_dns = 'yes'; + } + unset($output); + } + } + + // Template + if (($v_template != $_POST['v_template']) && (empty($_SESSION['error_msg']))) { + $v_template = escapeshellarg($_POST['v_template']); + exec (VESTA_CMD."v_change_web_domain_tpl ".$v_username." ".$v_domain." ".$v_template." 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + $restart_web = 'yes'; + } + + // Aliases + if (empty($_SESSION['error_msg'])) { + $waliases = preg_replace("/\n/", " ", $_POST['v_aliases']); + $waliases = preg_replace("/,/", " ", $waliases); + $waliases = preg_replace('/\s+/', ' ',$waliases); + $waliases = trim($waliases); + $aliases = explode(" ", $waliases); + $v_aliases = str_replace(' ', "\n", $waliases); + $result = array_diff($valiases, $aliases); + foreach ($result as $alias) { + if (empty($_SESSION['error_msg'])) { + $restart_web = 'yes'; + $v_template = escapeshellarg($_POST['v_template']); + exec (VESTA_CMD."v_delete_web_domain_alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + exec (VESTA_CMD."v_list_dns_domain ".$v_username." '".$alias."' json", $output, $return_var); + if ((empty($_SESSION['error_msg'])) && ($return_var == 0 )) { + exec (VESTA_CMD."v_delete_dns_domain ".$v_username." '".$alias."'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + $restart_dns = 'yes'; + } + unset($output); + } + } + + $result = array_diff($aliases, $valiases); + foreach ($result as $alias) { + if (empty($_SESSION['error_msg'])) { + $restart_web = 'yes'; + $v_template = escapeshellarg($_POST['v_template']); + exec (VESTA_CMD."v_add_web_domain_alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + exec (VESTA_CMD."v_list_dns_domain ".$v_username." '".$alias."' json", $output, $return_var); + if ((empty($_SESSION['error_msg'])) && ($return_var == 0 )) { + exec (VESTA_CMD."v_add_dns_domain ".$v_username." '".$alias."' ".$v_ip, $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + $restart_dns = 'yes'; + } + unset($output); + } + } + } + + // Elog + if (($v_elog == 'yes') && (empty($_POST['v_elog'])) && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_delete_web_domain_elog ".$v_username." ".$v_domain." 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + $restart_web = 'yes'; + $v_elog = 'no'; + } + if (($v_elog == 'no') && (!empty($_POST['v_elog'])) && (empty($_SESSION['error_msg'])) ) { + exec (VESTA_CMD."v_add_web_domain_elog ".$v_username." ".$v_domain." 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + $restart_web = 'yes'; + $v_elog = 'yes'; + } + + // Nginx + if ((!empty($v_nginx)) && (empty($_POST['v_nginx'])) && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_delete_web_domain_nginx ".$v_username." ".$v_domain." 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + unset($v_nginx); + $restart_web = 'yes'; + } + if ((!empty($v_nginx)) && (!empty($_POST['v_nginx'])) && (empty($_SESSION['error_msg']))) { + $ext = preg_replace("/\n/", " ", $_POST['v_nginx_ext']); + $ext = preg_replace("/,/", " ", $ext); + $ext = preg_replace('/\s+/', ' ',$ext); + $ext = trim($ext); + $ext = str_replace(' ', ", ", $ext); + if ( $v_nginx_ext != $ext ) { + $ext = str_replace(', ', ",", $ext); + exec (VESTA_CMD."v_change_web_domain_nginx_tpl ".$v_username." ".$v_domain." 'default' ".escapeshellarg($ext)." 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + $v_nginx_ext = str_replace(',', ', ', $ext); + unset($output); + $restart_web = 'yes'; + } + } + if ((empty($v_nginx)) && (!empty($_POST['v_nginx'])) && (empty($_SESSION['error_msg']))) { + $nginx_ext = "'jpg,jpeg,gif,png,ico,css,zip,tgz,gz,rar,bz2,doc,xls,exe,pdf,ppt,txt,tar,wav,bmp,rtf,js,mp3,avi,mpeg,html,htm'"; + if (!empty($_POST['v_nginx_ext'])) { + $ext = preg_replace("/\n/", " ", $_POST['v_nginx_ext']); + $ext = preg_replace("/,/", " ", $ext); + $ext = preg_replace('/\s+/', ' ',$ext); + $ext = trim($ext); + $ext = str_replace(' ', ",", $ext); + $v_nginx_ext = str_replace(',', ', ', $ext); + } + exec (VESTA_CMD."v_add_web_domain_nginx ".$v_username." ".$v_domain." 'default' ".escapeshellarg($ext)." 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + $v_nginx = 'default'; + $restart_web = 'yes'; + } + + // SSL + if (( $v_ssl == 'yes' ) && (empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_delete_web_domain_ssl ".$v_username." ".$v_domain." 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + $v_ssl = 'no'; + $restart_web = 'yes'; + } + if (($v_ssl == 'yes') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { + if (( $v_ssl_crt != str_replace("\r\n", "\n", $_POST['v_ssl_crt'])) || ( $v_ssl_key != str_replace("\r\n", "\n", $_POST['v_ssl_key'])) || ( $v_ssl_ca != str_replace("\r\n", "\n", $_POST['v_ssl_ca']))) { + exec ('mktemp -d', $mktemp_output, $return_var); + $tmpdir = $mktemp_output[0]; + + // Certificate + if (!empty($_POST['v_ssl_crt'])) { + $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); + fclose($fp); + } + + // Key + if (!empty($_POST['v_ssl_key'])) { + $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); + fclose($fp); + } + + // CA + if (!empty($_POST['v_ssl_ca'])) { + $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); + fclose($fp); + } + + exec (VESTA_CMD."v_change_web_domain_sslcert ".$user." ".$v_domain." ".$tmpdir." 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + $restart_web = 'yes'; + $v_ssl_crt = $_POST['v_ssl_crt']; + $v_ssl_key = $_POST['v_ssl_key']; + $v_ssl_ca = $_POST['v_ssl_ca']; + } + } + if (( $v_ssl == 'yes') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { + if ( $v_ssl_home != $_POST['v_ssl_home'] ) { + $v_ssl_home = escapeshellarg($_POST['v_ssl_home']); + exec (VESTA_CMD."v_change_web_domain_sslhome ".$user." ".$v_domain." ".$v_ssl_home." 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + $v_ssl_home = $_POST['v_ssl_home']; + unset($output); + } + } + if (( $v_ssl == 'no') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { + if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_crt']))) $errors[] = 'ssl certificate'; + if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_key']))) $errors[] = 'ssl key'; + if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_home']))) $errors[] = 'ssl home'; + $v_ssl_home = escapeshellarg($_POST['v_ssl_home']); + if (!empty($errors[0])) { + foreach ($errors as $i => $error) { + if ( $i == 0 ) { + $error_msg = $error; + } else { + $error_msg = $error_msg.", ".$error; + } + } + $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank."; + } else { + exec ('mktemp -d', $mktemp_output, $return_var); + $tmpdir = $mktemp_output[0]; + + // Certificate + if (!empty($_POST['v_ssl_crt'])) { + $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); + fclose($fp); + } + + // Key + if (!empty($_POST['v_ssl_key'])) { + $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); + fclose($fp); + } + + // CA + if (!empty($_POST['v_ssl_ca'])) { + $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); + fclose($fp); + } + exec (VESTA_CMD."v_add_web_domain_ssl ".$user." ".$v_domain." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + $v_ssl = 'yes'; + $restart_web = 'yes'; + $v_ssl_crt = $_POST['v_ssl_crt']; + $v_ssl_key = $_POST['v_ssl_key']; + $v_ssl_ca = $_POST['v_ssl_ca']; + $v_ssl_home = $_POST['v_ssl_home']; + } + } + + // Web Stats + if ((!empty($v_stats)) && ($_POST['v_stats'] == 'none') && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_delete_web_domain_stats ".$v_username." ".$v_domain, $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + $v_stats = ''; + } + if ((!empty($v_stats)) && ($_POST['v_stats'] != $v_stats) && (empty($_SESSION['error_msg']))) { + $v_stats = escapeshellarg($_POST['v_stats']); + exec (VESTA_CMD."v_change_web_domain_stats ".$v_username." ".$v_domain." ".$v_stats, $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + } + if ((empty($v_stats)) && ($_POST['v_stats'] != 'none') && (empty($_SESSION['error_msg']))) { + $v_stats = escapeshellarg($_POST['v_stats']); + exec (VESTA_CMD."v_add_web_domain_stats ".$v_username." ".$v_domain." ".$v_stats, $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + } + + // Web Stats Auth + if ((!empty($v_stats_user)) && (empty($_POST['v_stats_auth'])) && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_delete_web_domain_stats_user ".$v_username." ".$v_domain, $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + $v_stats_user = ''; + $v_stats_password = ''; + } + if ((empty($v_stats_user)) && (!empty($_POST['v_stats_auth'])) && (empty($_SESSION['error_msg']))) { + if (empty($_POST['v_stats_user'])) $errors[] = 'stats username'; + if (empty($_POST['v_stats_password'])) $errors[] = 'stats password'; + if (!empty($errors[0])) { + foreach ($errors as $i => $error) { + if ( $i == 0 ) { + $error_msg = $error; + } else { + $error_msg = $error_msg.", ".$error; + } + } + $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank."; + } else { + $v_stats_user = escapeshellarg($_POST['v_stats_user']); + $v_stats_password = escapeshellarg($_POST['v_stats_password']); + exec (VESTA_CMD."v_add_web_domain_stats_user ".$v_username." ".$v_domain." ".$v_stats_user." ".$v_stats_password, $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + $v_stats_password = "••••••••"; + } + } + if ((!empty($v_stats_user)) && (!empty($_POST['v_stats_auth'])) && (empty($_SESSION['error_msg']))) { + if (empty($_POST['v_stats_user'])) $errors[] = 'stats user'; + if (empty($_POST['v_stats_password'])) $errors[] = 'stats password'; + if (!empty($errors[0])) { + foreach ($errors as $i => $error) { + if ( $i == 0 ) { + $error_msg = $error; + } else { + $error_msg = $error_msg.", ".$error; + } + } + $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank."; + } + if (($v_stats_user != $_POST['v_stats_user']) || ($_POST['v_stats_password'] != "••••••••" ) && (empty($_SESSION['error_msg']))) { + $v_stats_user = escapeshellarg($_POST['v_stats_user']); + $v_stats_password = escapeshellarg($_POST['v_stats_password']); + exec (VESTA_CMD."v_add_web_domain_stats_user ".$v_username." ".$v_domain." ".$v_stats_user." ".$v_stats_password, $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + $v_stats_password = "••••••••"; + } + } + + + // Restart web + if (!empty($restart_web) && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_restart_web", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + } + + // Restart dns + if (!empty($restart_dns) && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_restart_dns", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + } + + if (empty($_SESSION['error_msg'])) { + $_SESSION['ok_msg'] = "OK: changes has been saved."; + } + + } + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_web.html'); + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_web.html'); + unset($_SESSION['error_msg']); + unset($_SESSION['ok_msg']); +} + +// Footer +include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html'); diff --git a/web/templates/admin/add_user.html b/web/templates/admin/add_user.html index 9fe85557..49af8953 100644 --- a/web/templates/admin/add_user.html +++ b/web/templates/admin/add_user.html @@ -27,7 +27,7 @@ document.v_add_user.v_password.value = randomstring; Username - Password generate + Password generate Email $value) { - echo "\t\t\t\t