diff --git a/bin/v_add_cron_job b/bin/v_add_cron_job index 0d765978..ab785ef6 100755 --- a/bin/v_add_cron_job +++ b/bin/v_add_cron_job @@ -70,7 +70,7 @@ sync_cron_jobs increase_user_value $user '$U_CRON_JOBS' # Restart crond -$BIN/v_restart_cron +$BIN/v_restart_cron "$EVENT" # Logging log_history "$EVENT" diff --git a/bin/v_add_cron_report b/bin/v_add_cron_report index 68ea3f6d..926b7d95 100755 --- a/bin/v_add_cron_report +++ b/bin/v_add_cron_report @@ -45,7 +45,7 @@ sync_cron_jobs #----------------------------------------------------------# # Restart crond -$BIN/v_restart_cron +$BIN/v_restart_cron "$EVENT" # Logging log_history "$EVENT" diff --git a/bin/v_add_dns_domain b/bin/v_add_dns_domain index 90b29997..8859d44a 100755 --- a/bin/v_add_dns_domain +++ b/bin/v_add_dns_domain @@ -109,7 +109,7 @@ increase_user_value "$user" '$U_DNS_DOMAINS' increase_user_value "$user" '$U_DNS_RECORDS' "$records" # Restart named -$BIN/v_restart_dns +$BIN/v_restart_web "$EVENT" # Logging log_history "$EVENT" diff --git a/bin/v_add_dns_domain_record b/bin/v_add_dns_domain_record index 5369f140..4ff4daa6 100755 --- a/bin/v_add_dns_domain_record +++ b/bin/v_add_dns_domain_record @@ -79,7 +79,7 @@ update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records" increase_user_value "$user" '$U_DNS_RECORDS' # Restart named -$BIN/v_restart_dns +$BIN/v_restart_dns "$EVENT" # Logging log_history "$EVENT" diff --git a/bin/v_add_sys_ip b/bin/v_add_sys_ip index c1a5c9b0..d46e04fb 100755 --- a/bin/v_add_sys_ip +++ b/bin/v_add_sys_ip @@ -106,7 +106,7 @@ fi # Adding task to the vesta pipe if [ "$web_restart" = 'yes' ]; then - $BIN/v_restart_web + $BIN/v_restart_web "$EVENT" fi # Logging diff --git a/bin/v_add_web_domain b/bin/v_add_web_domain index 2413400f..0e67f928 100755 --- a/bin/v_add_web_domain +++ b/bin/v_add_web_domain @@ -22,7 +22,7 @@ domain_idn=$(idn -t --quiet -a "$domain") ip=$3 template=${4-default} -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -33,32 +33,15 @@ source $VESTA/func/ip.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain ip [template]' - -# Checking argument format validate_format 'user' 'domain' 'ip' 'template' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain -is_domain_new 'dns' - -# Checking ip +is_domain_new 'web' +is_ip_valid is_ip_avalable - -# Checking package is_package_full 'WEB_DOMAINS' - -# Checking template -templates=$(get_user_value '$WEB_TPL') is_apache_template_valid @@ -89,7 +72,6 @@ group="$user" email="$user@$domain" docroot="$HOMEDIR/$user/web/$domain/public_html" docroot_string="DocumentRoot $docroot" - conf="$HOMEDIR/$user/conf/web/httpd.conf" tpl_file="$WEBTPL/apache_$template.tpl" @@ -192,34 +174,26 @@ fi # Vesta # #----------------------------------------------------------# -# Increasing ip value +# Increasing counters increase_ip_value "$ip" - -# Increasing domain value increase_user_value "$user" '$U_WEB_DOMAINS' increase_user_value "$user" '$U_WEB_ALIASES' # Defining domain variables -v_str="DOMAIN='$domain'" -v_str="$v_str IP='$ip' IP6=''" -v_str="$v_str U_DISK='0'" -v_str="$v_str U_BANDWIDTH='0'" -v_str="$v_str TPL='$template'" -v_str="$v_str ALIAS='$aliases'" -v_str="$v_str $template_data" # Inserting PHP, CGI and ELOG keys -v_str="$v_str STATS='' STATS_AUTH=''" -v_str="$v_str SSL='no' SSL_HOME='single'" -v_str="$v_str NGINX='' NGINX_EXT='' SUSPENDED='no' DATE='$DATE'" +str="DOMAIN='$domain' IP='$ip' IP6='' ALIAS='$aliases' TPL='$template'" +str="$str $template_data SSL='no' SSL_HOME='single' NGINX='' NGINX_EXT=''" +str="$str STATS='' STATS_USER='' U_DISK='0' U_BANDWIDTH='0' SUSPENDED='no'" +str="$str TIME='$TIME' DATE='$DATE'" # Registering domain -echo "$v_str" >> $USER_DATA/web.conf +echo "$str" >> $USER_DATA/web.conf chmod 660 $USER_DATA/web.conf -# Adding task to the vesta pipe -$BIN/v_restart_web +# Restart web server +$BIN/v_restart_web "$EVENT" # Logging -log_history "$EVENT" "v_delete_web_domain $user $domain" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_add_web_domain_alias b/bin/v_add_web_domain_alias index 78fdbdaa..8af02c30 100755 --- a/bin/v_add_web_domain_alias +++ b/bin/v_add_web_domain_alias @@ -19,7 +19,7 @@ dom_alias=$(idn -t --quiet -u "$3" ) dom_alias=$(echo $dom_alias | tr '[:upper:]' '[:lower:]') dom_alias_idn=$(idn -t --quiet -a "$dom_alias" ) -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -29,31 +29,14 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain dom_alias' - -# Checking argument format validate_format 'user' 'domain' 'dom_alias' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Checking alias on the server +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" is_domain_new 'web' "$dom_alias" - -# Checking package is_package_full 'WEB_ALIASES' @@ -109,15 +92,15 @@ fi #----------------------------------------------------------# # Adding new alias -update_domain_value 'web' '$ALIAS' "$ALIAS" +update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS" # Update counters increase_user_value "$user" '$U_WEB_ALIASES' # Adding task to the vesta pipe -$BIN/v_restart_web +$BIN/v_restart_web "$EVENT" -log_history "$EVENT" "v_delete_web_domain_alias $user $domain $dom_alias" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_add_web_domain_cgi b/bin/v_add_web_domain_cgi index ab04a362..177e520f 100755 --- a/bin/v_add_web_domain_cgi +++ b/bin/v_add_web_domain_cgi @@ -27,29 +27,14 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'user domain' - -# Checking argument format validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Checking cgi is not added -is_domain_key_empty 'web' '$CGI' +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_object_value_empty 'web' 'DOMAIN' "$domain" '$CGI' #----------------------------------------------------------# @@ -82,14 +67,14 @@ fi # Vesta # #----------------------------------------------------------# -# Adding elog in config -update_domain_value 'web' '$CGI' 'yes' +# Update config value +update_object_value 'web' 'DOMAIN' "$domain" '$CGI' 'yes' # Adding task to the vesta pipe -$BIN/v_restart_web +$BIN/v_restart_web "$EVENT" # Logging -log_history "$EVENT" "v_delete_web_domain_cgi $user $domain" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_add_web_domain_elog b/bin/v_add_web_domain_elog index 3ce44db3..95f4a9d3 100755 --- a/bin/v_add_web_domain_elog +++ b/bin/v_add_web_domain_elog @@ -15,7 +15,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -25,29 +25,14 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'user domain' - -# Checking argument format validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Checking errorlog is not added -is_domain_key_empty 'web' '$ELOG' +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_object_value_empty 'web' 'DOMAIN' "$domain" '$ELOG' #----------------------------------------------------------# @@ -96,14 +81,14 @@ fi # Vesta # #----------------------------------------------------------# -# Adding elog in config -update_domain_value 'web' '$ELOG' 'yes' +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$ELOG' 'yes' # Adding task to the vesta pipe -$BIN/v_restart_web +$BIN/v_restart_web "$EVENT" # Logging -log_history "$EVENT" "v_delete_web_domain_elog $user $domain" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_add_web_domain_nginx b/bin/v_add_web_domain_nginx index afb9c520..6e26149f 100755 --- a/bin/v_add_web_domain_nginx +++ b/bin/v_add_web_domain_nginx @@ -29,31 +29,14 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'user domain [template] [extentions]' - -# Checking argument format validate_format 'user' 'domain' 'template' 'extentions' - -# Checking proxy system is enabled -is_system_enabled 'proxy' - -# Checking user +is_system_enabled "$PROXY_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Check nginx is not added -is_domain_key_empty 'web' '$NGINX' - -# Checking template +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_object_value_empty 'web' 'DOMAIN' "$domain" '$NGINX' is_nginx_template_valid @@ -106,14 +89,14 @@ fi # Vesta # #----------------------------------------------------------# -# Adding nginx params to config -update_domain_value 'web' '$NGINX' "$NGINX" -update_domain_value 'web' '$NGINX_EXT' "$extentions" +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$NGINX' "$NGINX" +update_object_value 'web' 'DOMAIN' "$domain" '$NGINX_EXT' "$extentions" # Adding task to the vesta pipe -$BIN/v_restart_web +$BIN/v_restart_web "$EVENT" -log_history "$EVENT" "v_delete_web_domain_nginx $user $domain" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_add_web_domain_ssl b/bin/v_add_web_domain_ssl index 594f22bb..d3eb91df 100755 --- a/bin/v_add_web_domain_ssl +++ b/bin/v_add_web_domain_ssl @@ -21,7 +21,7 @@ domain_idn=$(idn -t --quiet -a "$domain") ssl_dir=$3 ssl_home=${4-single} -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -32,31 +32,15 @@ source $VESTA/func/ip.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain ssl_dir [ssl_home]' - -# Checking argument format validate_format 'user' 'domain' 'ssl_dir' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Check ssl is not added -is_domain_key_empty 'web' '$SSL' - -# Checking ssl certificate +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_object_value_empty 'web' 'DOMAIN' "$domain" '$SSL' +is_sys_ip_owner is_web_domain_cert_valid @@ -80,9 +64,6 @@ conf="$HOMEDIR/$user/conf/web/shttpd.conf" tpl_file="$WEBTPL/apache_$TPL.stpl" SSL_HOME="$ssl_home" -# Checking ip ownership -is_sys_ip_owner - # Preparing domain values for the template substitution upd_web_domain_values @@ -139,11 +120,14 @@ fi increase_user_value "$user" '$U_WEB_SSL' # Adding ssl values -update_domain_value 'web' '$SSL_HOME' "$SSL_HOME" -update_domain_value 'web' '$SSL' 'yes' +update_object_value 'web' 'DOMAIN' "$domain" '$SSL_HOME' "$SSL_HOME" +update_object_value 'web' 'DOMAIN' "$domain" '$SSL' "yes" + +# Restart web server +$BIN/v_restart_web "$EVENT" # Logging -log_history "$EVENT" "v_delete_web_domain_ssl $user $domain" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_add_web_domain_stat_auth b/bin/v_add_web_domain_stat_auth deleted file mode 100755 index b8d58937..00000000 --- a/bin/v_add_web_domain_stat_auth +++ /dev/null @@ -1,103 +0,0 @@ -#!/bin/bash -# info: add password protection to web domain statistics -# options: user domain auth_user auth_password -# -# The call is used for securing the web statistics page. - - -#----------------------------------------------------------# -# Variable&Function # -#----------------------------------------------------------# - -# Argument defenition -user=$1 -domain=$(idn -t --quiet -u "$2" ) -auth_user=$3 -auth_pass=$4 - -# Importing variables -source $VESTA/conf/vesta.conf -source $VESTA/func/shared.sh -source $VESTA/func/domain.sh - - -#----------------------------------------------------------# -# Verifications # -#----------------------------------------------------------# - -# Checking arg number -check_args '4' "$#" 'user domain auth_user auth_password' - -# Checking argument format -validate_format 'user' 'domain' 'auth_user' 'auth_pass' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user -is_object_valid 'user' 'USER' "$user" - -# Checking user is active -is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - - -#----------------------------------------------------------# -# Action # -#----------------------------------------------------------# - -# Definining statistic dir -stat_dir="$HOMEDIR/$user/web/$domain/stats" - -# Adding htaccess file -if [ ! -e "$stat_dir/.htaccess" ]; then - echo "AuthUserFile $stat_dir/.htpasswd" > $stat_dir/.htaccess - echo "AuthName \"Only for admins\"" >> $stat_dir/.htaccess - echo "AuthType Basic" >> $stat_dir/.htaccess - echo "Require valid-user" >> $stat_dir/.htaccess - echo "" >> $stat_dir/.htaccess -fi - -# Generating htaccess user and password -if [ ! -e "$stat_dir/.htpasswd" ]; then - htpasswd -bc $stat_dir/.htpasswd "$auth_user" "$auth_pass" &>/dev/null -else - htpasswd -b $stat_dir/.htpasswd "$auth_user" "$auth_pass" &>/dev/null -fi - - -#----------------------------------------------------------# -# Vesta # -#----------------------------------------------------------# - -# Get current value -curr_val=$(get_domain_value 'web' '$STATS_AUTH') -check_uniq=$(echo "$curr_val" | grep -w "$auth_user") - -# Checking current users -if [ -z "$curr_val" ] || [ "$curr_val" = 'no' ]; then - a_users="$auth_user" -else - if [ -z "$check_uniq" ]; then - a_users="$curr_val,$auth_user" - else - a_users="$curr_val" - fi -fi - -# Adding stats user in config -update_domain_value 'web' '$STATS_AUTH' "$a_users" - -# Hiding password -EVENT="$DATE $SCRIPT $user $domain $auth_user *****" - -# Logging -log_history "$EVENT" "v_delete_web_domain_stat_auth $user $domain $auth_user" -log_event "$OK" "$EVENT" - -exit diff --git a/bin/v_add_web_domain_stat b/bin/v_add_web_domain_stats similarity index 81% rename from bin/v_add_web_domain_stat rename to bin/v_add_web_domain_stats index 89bc944f..59d6f3ca 100755 --- a/bin/v_add_web_domain_stat +++ b/bin/v_add_web_domain_stats @@ -19,7 +19,7 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") type=$3 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -29,32 +29,15 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain type' - -# Checking argument format validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user -is_object_valid 'user' 'USER' "$user" "$user" - -# Checking user is active -is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Checking statistic type +is_system_enabled "$WEB_SYSTEM" is_type_valid "$STATS_SYSTEM" "$type" - -# Check statistic is not added -is_domain_key_empty 'web' '$STATS' +is_object_valid 'user' 'USER' "$user" "$user" +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_object_value_empty 'web' 'DOMAIN' "$domain" '$STATS' #----------------------------------------------------------# @@ -87,14 +70,14 @@ cat $WEBTPL/$type.tpl |\ # Vesta # #----------------------------------------------------------# -# Adding command to pipe +# Schedule statistic processing echo "$BIN/v_update_web_domain_stat $user $domain" >> $V_QUEUE/stats.pipe -# Adding stats in config -update_domain_value 'web' '$STATS' "$type" +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$STATS' "$type" # Logging -log_history "$EVENT" "v_delete_web_domain_stat $user $domain" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_add_web_domain_stats_user b/bin/v_add_web_domain_stats_user new file mode 100755 index 00000000..cd64b07f --- /dev/null +++ b/bin/v_add_web_domain_stats_user @@ -0,0 +1,72 @@ +#!/bin/bash +# info: add password protection to web domain statistics +# options: user domain stats_user stats_password +# +# The call is used for securing the web statistics page. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=$1 +domain=$(idn -t --quiet -u "$2" ) +stats_user=$3 +stats_pass=$4 + +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/shared.sh +source $VESTA/func/domain.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '4' "$#" 'user domain stats_user stats_pass' +validate_format 'user' 'domain' 'stats_user' 'stats_pass' +is_system_enabled "$WEB_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_empty 'web' 'DOMAIN' "$domain" '$STATS_USER' + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Definining statistic dir +stats_dir="$HOMEDIR/$user/web/$domain/stats" + +# Adding htaccess file +rm -f $stats_dir/.htaccess +echo "AuthUserFile $stats_dir/.htpasswd +AuthName \"Web Statistics\" +AuthType Basic +Require valid-user" > $stats_dir/.htaccess + +# Generating htaccess user and password +rm -f $stats_dir/.htpasswd +htpasswd -bc $stats_dir/.htpasswd "$stats_user" "$stats_pass" &>/dev/null + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Adding stats user in config +update_object_value 'web' 'DOMAIN' "$domain" '$STATS_USER' "$stats_user" + +# Hiding password +EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'" +EVENT="$EVENT ARGUMENTS='$user $domain $stats_user *****'" + +# Logging +log_history "$EVENT" +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v_change_cron_job b/bin/v_change_cron_job index c25783dd..c7afcec8 100755 --- a/bin/v_change_cron_job +++ b/bin/v_change_cron_job @@ -64,7 +64,7 @@ sync_cron_jobs #----------------------------------------------------------# # Restart crond -$BIN/v_restart_cron +$BIN/v_restart_cron "$EVENT" # Logging log_history "$EVENT" diff --git a/bin/v_change_dns_domain_ip b/bin/v_change_dns_domain_ip index a712d626..74b12e8e 100755 --- a/bin/v_change_dns_domain_ip +++ b/bin/v_change_dns_domain_ip @@ -53,7 +53,7 @@ update_domain_zone #----------------------------------------------------------# # Restart named -$BIN/v_restart_dns +$BIN/v_restart_dns "$EVENT" # Logging log_history "$EVENT" diff --git a/bin/v_change_dns_domain_record b/bin/v_change_dns_domain_record index e79d7a58..2bc44285 100755 --- a/bin/v_change_dns_domain_record +++ b/bin/v_change_dns_domain_record @@ -70,7 +70,7 @@ update_domain_zone #----------------------------------------------------------# # Restart named -$BIN/v_restart_dns +$BIN/v_restart_dns "$EVENT" # Logging log_history "$EVENT" diff --git a/bin/v_change_dns_domain_soa b/bin/v_change_dns_domain_soa index bc07f29b..94cc1e15 100755 --- a/bin/v_change_dns_domain_soa +++ b/bin/v_change_dns_domain_soa @@ -51,7 +51,7 @@ update_domain_zone #----------------------------------------------------------# # Restart named -$BIN/v_restart_dns +$BIN/v_restart_dns "$EVENT" # Logging log_history "$EVENT" diff --git a/bin/v_change_dns_domain_tpl b/bin/v_change_dns_domain_tpl index 43f6ce81..a4c8f8b2 100755 --- a/bin/v_change_dns_domain_tpl +++ b/bin/v_change_dns_domain_tpl @@ -79,7 +79,7 @@ update_domain_zone #----------------------------------------------------------# # Restart named -$BIN/v_restart_dns +$BIN/v_restart_dns "$EVENT" # Logging log_history "$EVENT" diff --git a/bin/v_change_dns_domain_ttl b/bin/v_change_dns_domain_ttl index cb7a610d..be8a4b06 100755 --- a/bin/v_change_dns_domain_ttl +++ b/bin/v_change_dns_domain_ttl @@ -50,7 +50,7 @@ update_domain_zone #----------------------------------------------------------# # Restart named -$BIN/v_restart_dns +$BIN/v_restart_dns "$EVENT" # Logging log_history "$EVENT" diff --git a/bin/v_change_web_domain_ip b/bin/v_change_web_domain_ip index e138816f..d17df465 100755 --- a/bin/v_change_web_domain_ip +++ b/bin/v_change_web_domain_ip @@ -16,7 +16,7 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") ip=$3 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -27,28 +27,14 @@ source $VESTA/func/ip.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain ip' - -# Checking argument format validate_format 'user' 'domain' 'ip' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Checking ip +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_ip_valid is_ip_avalable @@ -90,20 +76,18 @@ fi # Vesta # #----------------------------------------------------------# -# Increasing ip value +# Update counters increase_ip_value "$new" - -# Decreasing old ip value decrease_ip_value "$old" -# Adding ip in config -update_domain_value 'web' '$IP' "$new" +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$IP' "$ip" -# Adding task to the vesta pipe -$BIN/v_restart_web +# Restart web server +$BIN/v_restart_web "$EVENT" # Logging -log_history "$EVENT" "$SCRIPT $user $domain $old_ip" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_change_web_domain_sslcert b/bin/v_change_web_domain_sslcert index 974c4b20..accf4ea6 100755 --- a/bin/v_change_web_domain_sslcert +++ b/bin/v_change_web_domain_sslcert @@ -16,7 +16,7 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") ssl_dir=$3 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -26,31 +26,14 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain ssl_dir' - -# Checking argument format validate_format 'user' 'domain' 'ssl_dir' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Check SSL is added -is_domain_value_exist 'web' '$SSL' - -# Checking ssl certificate +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_object_value_exist 'web' 'DOMAIN' "$domain" '$SSL' is_web_domain_cert_valid @@ -86,11 +69,11 @@ fi # Vesta # #----------------------------------------------------------# -# Adding task to the vesta pipe -$BIN/v_restart_web +# Restart web server +$BIN/v_restart_web "$EVENT" # Logging -log_history "$EVENT" "$SCRIPT $user $domain $tmpdir" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_change_web_domain_sslhome b/bin/v_change_web_domain_sslhome index ae2b393c..6a062054 100755 --- a/bin/v_change_web_domain_sslhome +++ b/bin/v_change_web_domain_sslhome @@ -11,7 +11,7 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") ssl_home=$3 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -21,29 +21,14 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain ssl_home' - -# Checking argument format validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Check SSL is added -is_domain_value_exist 'web' '$SSL' +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_object_value_exist 'web' 'DOMAIN' "$domain" '$SSL' #----------------------------------------------------------# @@ -55,7 +40,7 @@ get_domain_values 'web' old_ssl_home=$SSL_HOME SSL_HOME=$ssl_home tpl_file="$WEBTPL/apache_$TPL.stpl" -conf="$HOMEDIR/$user/conf/shttpd.conf" +conf="$HOMEDIR/$user/conf/web/shttpd.conf" # Parsing tpl_option case $SSL_HOME in @@ -72,7 +57,7 @@ replace_web_config # Checking nginx config if [ ! -z "$NGINX" ]; then tpl_file="$WEBTPL/ngingx_vhost_$NGINX.stpl" - conf="$HOMEDIR/$user/conf/snginx.conf" + conf="$HOMEDIR/$user/conf/web//snginx.conf" replace_web_config fi @@ -81,14 +66,14 @@ fi # Vesta # #----------------------------------------------------------# -# Adding sslhome in config -update_domain_value 'web' '$SSL_HOME' "$SSL_HOME" +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$SSL_HOME' "$SSL_HOME" -# Adding task to the vesta pipe -$BIN/v_restart_web +# Restart web server +$BIN/v_restart_web "$EVENT" # Logging -log_history "$EVENT" "$SCRIPT $user $domain $old_ssl_home" +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 2c753bdd..cccdd2a1 100755 --- a/bin/v_change_web_domain_tpl +++ b/bin/v_change_web_domain_tpl @@ -16,7 +16,7 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") template=$3 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -26,29 +26,13 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain template' - -# Checking argument format validate_format 'user' 'domain' 'template' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Checking template -templates=$(get_user_value '$WEB_TPL') +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" is_apache_template_valid @@ -176,20 +160,20 @@ fi #----------------------------------------------------------# # Changing tpl in config -update_domain_value 'web' '$TPL' "$template" +update_object_value 'web' 'DOMAIN' "$domain" '$TPL' "$template" # Updating db keys for keys in $(cat $WEBTPL/apache_$template.descr|grep -v '#'); do key=$(echo "$keys"| cut -f 1 -d '=' |sed -e "s/^/\$/g") value=$(echo "$keys" |cut -f 2 -d \') - update_domain_value 'web' "$key" "$value" + update_object_value 'web' 'DOMAIN' "$domain" "$key" "$value" done -# Adding task to the vesta pipe -$BIN/v_restart_web +# Restart web +$BIN/v_restart_web "$EVENT" # Logging -log_history "$EVENT" "v_change_web_domain_tpl $user $domain $old_tpl" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_delete_cron_job b/bin/v_delete_cron_job index 6f8c6ab1..088f31e0 100755 --- a/bin/v_delete_cron_job +++ b/bin/v_delete_cron_job @@ -53,7 +53,7 @@ sync_cron_jobs decrease_user_value "$user" '$U_CRON_JOBS' # Restart crond -$BIN/v_restart_cron +$BIN/v_restart_cron "$EVENT" # Logging log_history "$EVENT" diff --git a/bin/v_delete_cron_reports b/bin/v_delete_cron_reports index a18a09bf..313265b2 100755 --- a/bin/v_delete_cron_reports +++ b/bin/v_delete_cron_reports @@ -45,7 +45,7 @@ sync_cron_jobs #----------------------------------------------------------# # Restart crond -$BIN/v_restart_cron +$BIN/v_restart_cron "$EVENT" # Logging log_history "$EVENT" diff --git a/bin/v_delete_dns_domain b/bin/v_delete_dns_domain index 670a2278..c7870d81 100755 --- a/bin/v_delete_dns_domain +++ b/bin/v_delete_dns_domain @@ -59,7 +59,7 @@ decrease_user_value "$user" '$U_DNS_RECORDS' "$records" # Restart named if [ "$restart" != 'no' ]; then - $BIN/v_restart_dns + $BIN/v_restart_dns "$EVENT" fi diff --git a/bin/v_delete_dns_domain_record b/bin/v_delete_dns_domain_record index bb360686..1187d8a6 100755 --- a/bin/v_delete_dns_domain_record +++ b/bin/v_delete_dns_domain_record @@ -50,7 +50,7 @@ update_domain_zone #----------------------------------------------------------# # Restart named -$BIN/v_restart_dns +$BIN/v_restart_dns "$EVENT" # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_delete_dns_domains b/bin/v_delete_dns_domains index ca1cd941..80ce154c 100755 --- a/bin/v_delete_dns_domains +++ b/bin/v_delete_dns_domains @@ -42,7 +42,7 @@ done #----------------------------------------------------------# # Restart named -$BIN/v_restart_dns +$BIN/v_restart_dns "$EVENT" # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_delete_sys_ip b/bin/v_delete_sys_ip index 5d4895ef..243b6889 100755 --- a/bin/v_delete_sys_ip +++ b/bin/v_delete_sys_ip @@ -98,7 +98,7 @@ fi # Adding task to the vesta pipe if [ "$web_restart" = 'yes' ]; then - $BIN/v_restart_web + $BIN/v_restart_web "$EVENT" fi # Logging diff --git a/bin/v_delete_web_domain b/bin/v_delete_web_domain index 6ddb25c6..bf9e9706 100755 --- a/bin/v_delete_web_domain +++ b/bin/v_delete_web_domain @@ -16,8 +16,9 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") +restart=$3 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -28,26 +29,13 @@ source $VESTA/func/ip.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'user domain' - -# Checking argument format validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" #----------------------------------------------------------# @@ -119,7 +107,7 @@ sed -i "/DOMAIN='$domain'/ d" $USER_DATA/web.conf # Checking last ssl domain ssl_dom=$(grep "SSL='yes'" $USER_DATA/web.conf | wc -l) if [ "$ssl_dom" -eq '0' ]; then - sed -i "s/ Include /#Include /" $HOMEDIR/$user/conf/web/httpd.conf + sed -i "s/ Include /#Include /" $HOMEDIR/$user/conf/web/httpd.conf fi # Checking last domain @@ -152,22 +140,18 @@ if [ -z "$last_nginx" ]; then rm -f $HOMEDIR/$user/conf/web/nginx.conf fi -# Decreasing ip value +# Decrease counters decrease_ip_value "$IP" - -# Decreasing domain value decrease_user_value "$user" '$U_WEB_DOMAINS' - -# Decreasing web aliases decrease_user_value "$user" '$U_WEB_ALIASES' "$aliases" - -# Decreasing web ssl if [ "$SSL" = 'yes' ]; then decrease_user_value "$user" '$U_WEB_SSL' fi -# Adding task to the vesta pipe -$BIN/v_restart_web +# Restart web server +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 83872d49..1460cc82 100755 --- a/bin/v_delete_web_domain_alias +++ b/bin/v_delete_web_domain_alias @@ -17,7 +17,7 @@ domain_idn=$(idn -t --quiet -a "$domain" ) dom_alias=$(idn -t --quiet -u "$3" ) dom_alias_idn=$(idn -t --quiet -a "$dom_alias" ) -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -27,36 +27,21 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain dom_alias' - -# Checking argument format validate_format 'user' 'domain' 'dom_alias' - -# Checking web system is enabled is_system_enabled 'WEB_SYSTEM' - -# Checking user is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Checking alias is added +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" get_domain_values 'web' -check_alias=$(echo ${ALIAS//,/ }|grep -w "$dom_alias") -if [ -z "$check_alias" ]; then - echo "Error: alias not exist" - log_event 'debug' "$E_NOTEXIST $EVENT" +if [ -z "$(echo $ALIAS | tr ',' '\n' | grep ^$dom_alias$)" ]; then + echo "Error: alias $dom_alias not exist" + log_event "$E_NOTEXIST" "$EVENT" exit $E_NOTEXIST fi + #----------------------------------------------------------# # Action # #----------------------------------------------------------# @@ -105,17 +90,17 @@ fi # Vesta # #----------------------------------------------------------# -# Deleting alias -update_domain_value 'web' '$ALIAS' "$ALIAS" +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS" # Update counters decrease_user_value "$user" '$U_WEB_ALIASES' -# Adding task to the vesta pipe -$BIN/v_restart_web +# Restart web server +$BIN/v_restart_web "$EVENT" # Logging -log_history "$EVENT" "v_add_web_domain_alias $user $domain $dom_alias" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_delete_web_domain_cgi b/bin/v_delete_web_domain_cgi index 252127cd..d9175e8d 100755 --- a/bin/v_delete_web_domain_cgi +++ b/bin/v_delete_web_domain_cgi @@ -17,7 +17,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -27,29 +27,14 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'user domain' - -# Checking argument format validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Checking cgi is added -is_domain_value_exist 'web' '$CGI' +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_object_value_exist 'web' 'DOMAIN' "$domain" '$CGI' #----------------------------------------------------------# @@ -81,14 +66,14 @@ fi # Vesta # #----------------------------------------------------------# -# Deleting cgi in config -update_domain_value 'web' '$CGI' 'no' +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$CGI' 'no' -# Adding task to the vesta pipe -$BIN/v_restart_web +# Restart web server +$BIN/v_restart_web "$EVENT" # Logging -log_history "$EVENT" "v_add_web_domain_cgi $user $domain" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_delete_web_domain_elog b/bin/v_delete_web_domain_elog index 8e081c92..69eef9d7 100755 --- a/bin/v_delete_web_domain_elog +++ b/bin/v_delete_web_domain_elog @@ -16,7 +16,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -26,29 +26,14 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'user domain' - -# Checking argument format validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Check errorlog is added -is_domain_value_exist 'web' '$ELOG' +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_object_value_exist 'web' 'DOMAIN' "$domain" '$ELOG' #----------------------------------------------------------# @@ -97,14 +82,14 @@ fi # Vesta # #----------------------------------------------------------# -# Deleting elog in config -update_domain_value 'web' '$ELOG' 'no' +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$ELOG' 'no' -# Adding task to the vesta pipe -$BIN/v_restart_web +# Restart web server +$BIN/v_restart_web "$EVENT" # Logging -log_history "$EVENT" "v_add_web_domain_elog $user $domain" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_delete_web_domain_nginx b/bin/v_delete_web_domain_nginx index 596d8a02..3e1b237c 100755 --- a/bin/v_delete_web_domain_nginx +++ b/bin/v_delete_web_domain_nginx @@ -14,7 +14,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -24,29 +24,14 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'user domain' - -# Checking argument format validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Checking ssl is added -is_domain_value_exist 'web' '$NGINX' +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_object_value_exist 'web' 'DOMAIN' "$domain" '$NGINX' #----------------------------------------------------------# @@ -56,13 +41,13 @@ is_domain_value_exist 'web' '$NGINX' # Defining domain parameters get_domain_values 'web' tpl_file="$WEBTPL/ngingx_vhost_$NGINX.tpl" -conf="$HOMEDIR/$user/conf/nginx.conf" +conf="$HOMEDIR/$user/conf/web/nginx.conf" del_web_config # Checking ssl if [ "$SSL" = 'yes' ]; then tpl_file="$WEBTPL/ngingx_vhost_$NGINX.stpl" - conf="$HOMEDIR/$user/conf/snginx.conf" + conf="$HOMEDIR/$user/conf/web/snginx.conf" del_web_config fi @@ -71,9 +56,9 @@ fi # Vesta # #----------------------------------------------------------# -# Deleting nginx keys -update_domain_value 'web' '$NGINX' '' -update_domain_value 'web' '$NGINX_EXT' '' +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$NGINX' '' +update_object_value 'web' 'DOMAIN' "$domain" '$NGINX_EXT' '' # Checking last nginx domain conf='/etc/nginx/conf.d/vesta_users.conf' @@ -89,11 +74,11 @@ if [ -z "$last_nginx" ]; then rm -f $HOMEDIR/$user/conf/web/nginx.conf fi -# Adding task to the vesta pipe -$BIN/v_restart_web +# Restart web server +$BIN/v_restart_web "$EVENT" # Logging -log_history "$EVENT" "v_add_web_domain_nginx $user $domain $NGINX $NGINX_EXT" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_delete_web_domain_ssl b/bin/v_delete_web_domain_ssl index 7222bd74..622efc00 100755 --- a/bin/v_delete_web_domain_ssl +++ b/bin/v_delete_web_domain_ssl @@ -14,7 +14,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -24,29 +24,14 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'user domain' - -# Checking argument format validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Checking ssl is added -is_domain_value_exist 'web' '$SSL' +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_object_value_exist 'web' 'DOMAIN' "$domain" '$SSL' #----------------------------------------------------------# @@ -79,13 +64,13 @@ chown -R $user:$user $tmpdir # Vesta # #----------------------------------------------------------# -# Deleting ssl in config -update_domain_value 'web' '$SSL' 'no' +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$SSL' 'no' # Checking last ssl domain ssl_dom=$(grep "SSL='yes'" $USER_DATA/web.conf) main_conf='/etc/httpd/conf.d/vesta.conf' -conf="$HOMEDIR/$user/conf/shttpd.conf" +conf="$HOMEDIR/$user/conf/web/shttpd.conf" if [ -z "$ssl_dom" ]; then sed -i "/Include ${conf////\/}/d" $main_conf rm -f $conf @@ -96,19 +81,18 @@ conf='/etc/nginx/conf.d/vesta_users.conf' last_nginx=$(grep -v "NGINX=''" $USER_DATA/web.conf) last_snginx=$(echo "$last_nginx" | grep "SSL='yes'") if [ -z "$last_snginx" ]; then -if [ -z "$last_nginx" ]; then - sed -i "/$user\/conf\/snginx.conf/d" $conf - rm -f $HOMEDIR/$user/conf/snginx.conf + sed -i "/$user\/conf\/web\/snginx.conf/d" $conf + rm -f $HOMEDIR/$user/conf/web/snginx.conf fi # Decreasing domain value decrease_user_value "$user" '$U_WEB_SSL' -# Adding task to the vesta pipe -$BIN/v_restart_web +# Restart web server +$BIN/v_restart_web "$EVENT" # Logging -log_history "$EVENT" "v_add_web_domain_ssl $user $domain $tmpdir $SSL_HOME" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_delete_web_domain_stat b/bin/v_delete_web_domain_stats similarity index 70% rename from bin/v_delete_web_domain_stat rename to bin/v_delete_web_domain_stats index c7804c94..cf7b66e0 100755 --- a/bin/v_delete_web_domain_stat +++ b/bin/v_delete_web_domain_stats @@ -14,7 +14,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -24,29 +24,14 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'user domain' - -# Checking argument format validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Checking stats enabled -is_domain_value_exist 'web' '$STATS' +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_object_value_exist 'web' 'DOMAIN' "$domain" '$STATS' #----------------------------------------------------------# @@ -54,16 +39,16 @@ is_domain_value_exist 'web' '$STATS' #----------------------------------------------------------# # Defining statistic type -type=$(get_domain_value 'web' '$STATS') +get_domain_values 'web' # Defining statistic dir -stat_dir="$HOMEDIR/$user/web/$domain/stats" +stats_dir="$HOMEDIR/$user/web/$domain/stats" # Deleting dir content -rm -rf $stat_dir/* +rm -rf $stats_dir/* # Deleting config -rm -f $HOMEDIR/$user/conf/$type.$domain.conf +rm -f $HOMEDIR/$user/conf/web/$STATS.$domain.conf #----------------------------------------------------------# @@ -73,11 +58,11 @@ rm -f $HOMEDIR/$user/conf/$type.$domain.conf # Deleting pipe command sed -i "/ $domain$/d" $V_QUEUE/stats.pipe -# Deleting stats -update_domain_value 'web' '$STATS' '' +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$STATS' '' # Logging -log_history "$EVENT" "v_add_web_domain_stat $user $doman $type" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_delete_web_domain_stat_auth b/bin/v_delete_web_domain_stats_user similarity index 50% rename from bin/v_delete_web_domain_stat_auth rename to bin/v_delete_web_domain_stats_user index 368c1859..4b2825e5 100755 --- a/bin/v_delete_web_domain_stat_auth +++ b/bin/v_delete_web_domain_stats_user @@ -1,6 +1,6 @@ #!/bin/bash # info: disable webdomain stats authentication support -# options: user domain [auth_user] +# options: user domain # # The function removes authentication of statistics system. If the script is # called without naming a certain user, all users will be removed. After @@ -15,9 +15,8 @@ # Argument defenition user=$1 domain=$(idn -t --quiet -u "$2" ) -auth_user=$3 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -27,29 +26,14 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number -check_args '2' "$#" 'user domain [auth_user]' - -# Checking argument format +check_args '2' "$#" 'user domain' validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' - -# Checking stats auth enabled -is_domain_value_exist 'web' '$STATS_AUTH' +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" +is_object_value_exist 'web' 'DOMAIN' "$domain" '$STATS_USER' #----------------------------------------------------------# @@ -57,50 +41,16 @@ is_domain_value_exist 'web' '$STATS_AUTH' #----------------------------------------------------------# # Definining statistic dir -stat_dir="$HOMEDIR/$user/web/$domain/stats" - -# Checking auth_user -if [ ! -z "$auth_user" ]; then - validate_format 'auth_user' - htpasswd -D $stat_dir/.htpasswd "$auth_user" &>/dev/null -fi - -# Checking htpasswd current users -lines=$(wc -l $stat_dir/.htpasswd |cut -f 1 -d ' ') -if [ -z "$auth_user" ] || [ "$lines" -eq '0' ]; then - rm -f $stat_dir/.htpasswd - rm -f $stat_dir/.htaccess -fi +rm -f $HOMEDIR/$user/web/$domain/stats/.htpasswd +rm -f $HOMEDIR/$user/web/$domain/stats/.htaccess #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# -# Checking auth_user -if [ ! -z "$auth_user" ]; then - # Get current value - curr_val=$(get_domain_value 'web' '$STATS_AUTH') - - # Deleteting auth_user - new_val=$(echo "$curr_val" |\ - sed -e "s/,/\n/g"|\ - sed -e "s/^$auth_user$//g"|\ - sed -e "/^$/d"|\ - sed -e ':a;N;$!ba;s/\n/,/g') - - # Checking it was last user - if [ -z "$new_val" ]; then - new_val='' - fi - -else - # User empty, deleting all - new_val='' -fi - -# Deleting stats auth_user -update_domain_value 'web' '$STATS_AUTH' "$new_val" +# Update config +update_object_value 'web' 'DOMAIN' "$domain" '$STATS_USER' '' # Logging log_history "$EVENT" diff --git a/bin/v_delete_web_domains b/bin/v_delete_web_domains index 6c029e9f..9400f807 100755 --- a/bin/v_delete_web_domains +++ b/bin/v_delete_web_domains @@ -12,26 +12,18 @@ # Argument defenition user=$1 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh -source $VESTA/func/domain.sh #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '1' "$#" 'user' - -# Checking argument format validate_format 'user' - -# Checking web system is enabled -is_system_enabled 'WEB_SYSTEM' - -# Checking user +is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" @@ -39,26 +31,9 @@ is_object_valid 'user' 'USER' "$user" # Action # #----------------------------------------------------------# -# Defining config -conf="$USER_DATA/web.conf" - -# Defining fileds to select -field='$DOMAIN' - -# Defining search string -search_string="SUSPENDED='no'" - -# Parsing domain list -domains=$(dom_clear_search) - # Starting delete loop -for domain in $domains; do - $BIN/v_delete_web_domain "$user" "$domain" - rv="$?" - if [ "$rv" -ne '0' ]; then - log_event 'debug' "$rv $EVENT" - exit $rv - fi +for domain in $(search_objects 'web' 'SUSPENDED' "no" 'DOMAIN'); do + $BIN/v_delete_web_domain "$user" "$domain" 'no' done diff --git a/bin/v_get_web_domain_value b/bin/v_get_web_domain_value index 168e4d75..dc6148e4 100755 --- a/bin/v_get_web_domain_value +++ b/bin/v_get_web_domain_value @@ -17,7 +17,7 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") key=$(echo "$3"| tr '[:lower:]' '[:upper:]'|sed -e "s/^/$/") -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -27,31 +27,19 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking args check_args '3' "$#" 'user domain key' - -# Checking argument format validate_format 'user' 'domain' - -# Checking user is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'web' - -# Checking domain is not suspened -is_domain_suspended 'web' +is_object_valid 'web' 'DOMAIN' "$domain" #----------------------------------------------------------# # Action # #----------------------------------------------------------# -value=$(get_domain_value 'web' "$key") -echo "$value" +get_domain_values 'web' +eval echo $key #----------------------------------------------------------# diff --git a/bin/v_rebuild_cron_jobs b/bin/v_rebuild_cron_jobs index 2e5c70cf..e825cd1c 100755 --- a/bin/v_rebuild_cron_jobs +++ b/bin/v_rebuild_cron_jobs @@ -40,7 +40,7 @@ sync_cron_jobs #----------------------------------------------------------# # Restart crond -$BIN/v_restart_cron +$BIN/v_restart_cron "$EVENT" # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_rebuild_dns_domains b/bin/v_rebuild_dns_domains index e495f851..d3099219 100755 --- a/bin/v_rebuild_dns_domains +++ b/bin/v_rebuild_dns_domains @@ -121,7 +121,7 @@ update_user_value "$user" '$U_DNS_RECORDS' "$user_records" update_user_value "$user" '$SUSPENDED_DNS' "$suspended_dns" # Restart named -$BIN/v_restart_dns +$BIN/v_restart_dns "$EVENT" # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_rebuild_web_domains b/bin/v_rebuild_web_domains index 56979381..cbec76b3 100755 --- a/bin/v_rebuild_web_domains +++ b/bin/v_rebuild_web_domains @@ -228,7 +228,7 @@ update_user_value "$user" '$U_WEB_SSL' "$user_ssl" update_user_value "$user" '$U_WEB_ALIASES' "$user_aliases" # Adding task to the vesta pipe -$BIN/v_restart_web +$BIN/v_restart_web "$EVENT" # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_restart_cron b/bin/v_restart_cron index 8f0b3c14..9e3de9fb 100755 --- a/bin/v_restart_cron +++ b/bin/v_restart_cron @@ -11,6 +11,9 @@ # Includes source $VESTA/conf/vesta.conf +source $VESTA/func/shared.sh +EVENT=${1-$EVENT} + #----------------------------------------------------------# # Action # @@ -20,8 +23,11 @@ source $VESTA/conf/vesta.conf if [ "$CRON_SYSTEM" = 'crond' ]; then /etc/init.d/crond 'reload' &>/dev/null if [ $? -ne 0 ]; then - echo "$E_RESTART $1" - exit $E_RESTART + /etc/init.d/crond 'restart' &>/dev/null + if [ $? -ne 0 ]; then + log_event "$E_RESTART" "$EVENT" + exit $E_RESTART + fi fi fi diff --git a/bin/v_restart_dns b/bin/v_restart_dns index ecd345d0..2f34074b 100755 --- a/bin/v_restart_dns +++ b/bin/v_restart_dns @@ -10,9 +10,9 @@ #----------------------------------------------------------# # Includes -source /etc/profile.d/vesta.sh source $VESTA/conf/vesta.conf - +source $VESTA/func/shared.sh +EVENT=${1-$EVENT} #----------------------------------------------------------# # Action # @@ -21,9 +21,11 @@ source $VESTA/conf/vesta.conf if [ "$DNS_SYSTEM" = 'bind' ]; then /etc/init.d/named reload &>/dev/null if [ $? -ne 0 ]; then - #$VESTA/func/report_issue 'sys' 'cron' - echo "$E_RESTART $1" - exit $E_RESTART + /etc/init.d/named restart &>/dev/null + if [ $? -ne 0 ]; then + log_event "$E_RESTART" "$EVENT" + exit $E_RESTART + fi fi fi diff --git a/bin/v_restart_web b/bin/v_restart_web index 68096d52..ad90ae12 100755 --- a/bin/v_restart_web +++ b/bin/v_restart_web @@ -9,56 +9,48 @@ # Variable&Function # #----------------------------------------------------------# -# Importing variables +# Includes source $VESTA/conf/vesta.conf - -# Restart functions -apache() { - /etc/init.d/httpd status &>/dev/null - if [ $? -eq 0 ]; then - /etc/init.d/httpd graceful &>/dev/null - if [ $? -ne 0 ]; then - echo "$E_RESTART $1" - exit $E_RESTART - fi - else - /etc/init.d/httpd start &>/dev/null - if [ $? -ne 0 ]; then - echo "$E_RESTART $1" - exit $E_RESTART - fi - fi -} - -nginx() { - /etc/init.d/nginx status &>/dev/null - if [ $? -eq 0 ]; then - /etc/init.d/nginx reload &>/dev/null - if [ $? -ne 0 ]; then - echo "$E_RESTART $1" - exit $E_RESTART - fi - else - /etc/init.d/nginx start &>/dev/null - if [ $? -ne 0 ]; then - echo "$E_RESTART $1" - exit $E_RESTART - fi - fi -} - +source $VESTA/func/shared.sh +EVENT=${1-$EVENT} #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Checking system if [ "$WEB_SYSTEM" = 'apache' ]; then - apache $1 + /etc/init.d/httpd status &>/dev/null + if [ $? -eq 0 ]; then + /etc/init.d/httpd graceful &>/dev/null + if [ $? -ne 0 ]; then + log_event "$E_RESTART" "$EVENT" + exit $E_RESTART + fi + else + /etc/init.d/httpd start &>/dev/null + if [ $? -ne 0 ]; then + log_event "$E_RESTART" "$EVENT" + exit $E_RESTART + fi + fi fi if [ "$PROXY_SYSTEM" = 'nginx' ]; then - nginx $1 + /etc/init.d/nginx status &>/dev/null + if [ $? -eq 0 ]; then + /etc/init.d/nginx reload &>/dev/null + if [ $? -ne 0 ]; then + log_event "$E_RESTART" "$EVENT" + exit $E_RESTART + fi + else + /etc/init.d/nginx start &>/dev/null + if [ $? -ne 0 ]; then + log_event "$E_RESTART" "$EVENT" + exit $E_RESTART + fi + fi + fi @@ -66,5 +58,4 @@ fi # Vesta # #----------------------------------------------------------# -# Logging exit diff --git a/bin/v_suspend_cron_job b/bin/v_suspend_cron_job index e7f04faa..77fea374 100755 --- a/bin/v_suspend_cron_job +++ b/bin/v_suspend_cron_job @@ -48,7 +48,7 @@ sync_cron_jobs # Restart crond if [ "$restart" != 'no' ]; then - $BIN/v_restart_cron + $BIN/v_restart_cron "$EVENT" fi # Logging diff --git a/bin/v_suspend_cron_jobs b/bin/v_suspend_cron_jobs index fb940857..df0a3c1e 100755 --- a/bin/v_suspend_cron_jobs +++ b/bin/v_suspend_cron_jobs @@ -41,7 +41,7 @@ done #----------------------------------------------------------# # Restart crond -$BIN/v_restart_cron +$BIN/v_restart_cron "$EVENT" # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_suspend_dns_domain b/bin/v_suspend_dns_domain index 50b66735..9c851cff 100755 --- a/bin/v_suspend_dns_domain +++ b/bin/v_suspend_dns_domain @@ -50,7 +50,7 @@ increase_user_value "$user" '$SUSPENDED_DNS' # Restart named if [ "$restart" != 'no' ]; then - $BIN/v_restart_dns + $BIN/v_restart_dns "$EVENT" fi # Logging diff --git a/bin/v_suspend_dns_domains b/bin/v_suspend_dns_domains index 8c177ca1..f4f82ba1 100755 --- a/bin/v_suspend_dns_domains +++ b/bin/v_suspend_dns_domains @@ -42,7 +42,7 @@ done #----------------------------------------------------------# # Adding task to the vesta pipe -$BIN/v_restart_dns +$BIN/v_restart_dns "$EVENT" # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_suspend_user b/bin/v_suspend_user index ec3921a0..070c8393 100755 --- a/bin/v_suspend_user +++ b/bin/v_suspend_user @@ -75,9 +75,9 @@ fi #----------------------------------------------------------# # Adding task to the vesta pipe -$BIN/v_restart_cron -$BIN/v_restart_web -$BIN/v_restart_dns +$BIN/v_restart_cron "$EVENT" +$BIN/v_restart_web "$EVENT" +$BIN/v_restart_dns "$EVENT" # Changing suspend value update_user_value "$user" '$SUSPENDED' 'yes' diff --git a/bin/v_suspend_web_domain b/bin/v_suspend_web_domain index bbc88d12..dfc836f2 100755 --- a/bin/v_suspend_web_domain +++ b/bin/v_suspend_web_domain @@ -99,7 +99,7 @@ update_domain_value 'web' '$SUSPENDED' 'yes' increase_user_value "$user" '$SUSPENDED_WEB' # Adding task to the vesta pipe -$BIN/v_restart_web +$BIN/v_restart_web "$EVENT" # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_unsuspend_cron_job b/bin/v_unsuspend_cron_job index 79617036..1e22fbc6 100755 --- a/bin/v_unsuspend_cron_job +++ b/bin/v_unsuspend_cron_job @@ -48,7 +48,7 @@ sync_cron_jobs # Restart crond if [ "$restart" != 'no' ]; then - $BIN/v_restart_cron + $BIN/v_restart_cron "$EVENT" fi # Logging diff --git a/bin/v_unsuspend_cron_jobs b/bin/v_unsuspend_cron_jobs index 189e136d..49296455 100755 --- a/bin/v_unsuspend_cron_jobs +++ b/bin/v_unsuspend_cron_jobs @@ -41,7 +41,7 @@ done #----------------------------------------------------------# # Restart crond -$BIN/v_restart_cron +$BIN/v_restart_cron "$EVENT" # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_unsuspend_dns_domain b/bin/v_unsuspend_dns_domain index 66705014..c8f060d7 100755 --- a/bin/v_unsuspend_dns_domain +++ b/bin/v_unsuspend_dns_domain @@ -50,7 +50,7 @@ decrease_user_value "$user" '$SUSPENDED_DNS' # Restart named if [ "$restart" != 'no' ]; then - $BIN/v_restart_dns + $BIN/v_restart_dns "$EVENT" fi # Logging diff --git a/bin/v_unsuspend_dns_domains b/bin/v_unsuspend_dns_domains index 90320f5e..a0980747 100755 --- a/bin/v_unsuspend_dns_domains +++ b/bin/v_unsuspend_dns_domains @@ -42,7 +42,7 @@ done #----------------------------------------------------------# # Restart named -$BIN/v_restart_dns +$BIN/v_restart_dns "$EVENT" # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_unsuspend_user b/bin/v_unsuspend_user index ed7f5f0f..13f59c20 100755 --- a/bin/v_unsuspend_user +++ b/bin/v_unsuspend_user @@ -72,9 +72,9 @@ fi #----------------------------------------------------------# # Adding task to the vesta pipe -$BIN/v_restart_cron -$BIN/v_restart_web -$BIN/v_restart_dns +$BIN/v_restart_cron "$EVENT" +$BIN/v_restart_web "$EVENT" +$BIN/v_restart_dns "$EVENT" # Changing suspend value update_user_value "$user" '$SUSPENDED' 'no' diff --git a/bin/v_unsuspend_web_domain b/bin/v_unsuspend_web_domain index ce15bbf9..d8caa0d9 100755 --- a/bin/v_unsuspend_web_domain +++ b/bin/v_unsuspend_web_domain @@ -94,7 +94,7 @@ update_domain_value 'web' '$SUSPENDED' 'no' decrease_user_value "$user" '$SUSPENDED_WEB' # Adding task to the vesta pipe -$BIN/v_restart_web +$BIN/v_restart_web "$EVENT" # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_update_sys_ip b/bin/v_update_sys_ip index 667afa73..397069bd 100755 --- a/bin/v_update_sys_ip +++ b/bin/v_update_sys_ip @@ -95,7 +95,7 @@ increase_user_value "$user" '$IP_OWNED' # Adding task to the vesta pipe if [ "$web_restart" = 'yes' ]; then - $BIN/v_restart_web + $BIN/v_restart_web "$EVENT" fi # Logging diff --git a/func/domain.sh b/func/domain.sh index 00717247..6ad15448 100644 --- a/func/domain.sh +++ b/func/domain.sh @@ -1,11 +1,11 @@ # Web template check is_apache_template_valid() { - c=$(echo "$templates" | grep -w "$template") + c=$(echo "$(get_user_value '$WEB_TPL')" | grep -w "$template") t="$WEBTPL/apache_$template.tpl" d="$WEBTPL/apache_$template.descr" s="$WEBTPL/apache_$template.stpl" if [ -z "$c" ] || [ ! -e $t ] || [ ! -e $d ] || [ ! -e $s ]; then - echo "Error: $template not found" + echo "Error: template $template not found" log_event "$E_NOTEXIST" "$EVENT" exit $E_NOTEXIST fi @@ -38,19 +38,19 @@ is_dns_template_valid() { is_domain_new() { config_type="$1" dom=${2-$domain} - check_all=$(grep -w $dom $V_USERS/*/*.conf) + check_all=$(grep -w $dom $VESTA/data/users/*/*.conf) if [ ! -z "$check_all" ]; then check_ownership=$(grep -w $dom $USER_DATA/*.conf) if [ ! -z "$check_ownership" ]; then check_type=$(grep -w $dom $USER_DATA/$config_type.conf) if [ ! -z "$check_type" ]; then echo "Error: domain $dom exist" - log_event 'debug' "$E_EXISTS $EVENT" + log_event "$E_EXISTS" "$EVENT" exit $E_EXISTS fi else echo "Error: domain $dom exist" - log_event 'debug' "$E_EXISTS $EVENT" + log_event "$E_EXISTS" "$EVENT" exit $E_EXISTS fi fi @@ -58,12 +58,9 @@ is_domain_new() { # Update domain zone update_domain_zone() { - # Definigng variables conf="$HOMEDIR/$user/conf/dns/$domain.db" line=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf) fields='$RECORD\t$TTL\tIN\t$TYPE\t$PRIORITY\t$VALUE' - - # Checking serial if [ -e $conf ]; then zn_serial=$(head $conf|grep 'SOA' -A1|tail -n 1|sed -e "s/ //g") s_date=$(echo ${zn_serial:0:8}) @@ -83,12 +80,8 @@ update_domain_zone() { serial="$(date +'%Y%m%d01')" fi - # Parsing dns domains conf eval $line - - # Converting SOA to ascii SOA=$(idn --quiet -a -t "$SOA") - # Adding zone header echo "\$TTL $TTL @ IN SOA $SOA. root.$domain_idn. ( $serial @@ -97,22 +90,18 @@ update_domain_zone() { 1209600 180 ) " > $conf - - # Adding zone records while read line ; do - # Defining new delimeter IFS=$'\n' - # Parsing key=value for key in $(echo $line|sed -e "s/' /'\n/g"); do eval ${key%%=*}="${key#*=}" done - # Converting utf records to ascii RECORD=$(idn --quiet -a -t "$RECORD") eval echo -e "\"$fields\""|sed -e "s/%quote%/'/g" >> $conf done < $USER_DATA/dns/$domain.conf } +# Get next DNS record ID get_next_dnsrecord(){ if [ -z "$id" ]; then curr_str=$(grep "ID=" $USER_DATA/dns/$domain.conf | cut -f 2 -d \' |\ @@ -121,15 +110,15 @@ get_next_dnsrecord(){ fi } +# Sort DNS records sort_dns_records() { - # Defining conf conf="$USER_DATA/dns/$domain.conf" cat $conf |sort -n -k 2 -t \' >$conf.tmp mv -f $conf.tmp $conf } +# Add web config add_web_config() { - # Adding template to config cat $tpl_file | \ sed -e "s/%ip%/$ip/g" \ -e "s/%web_port%/$WEB_PORT/g" \ @@ -159,25 +148,22 @@ add_web_config() { >> $conf } +# Get config top and bottom line numbers get_web_config_brds() { - # Defining template borders serv_line=$(grep -ni 'Name %domain_idn%' "$tpl_file" |cut -f 1 -d :) if [ -z "$serv_line" ]; then - log_event 'debug' "$E_PARSING $EVENT" + log_event "$E_PARSING" "$EVENT" return $E_PARSING fi - # Template lines last_line=$(wc -l $tpl_file|cut -f 1 -d ' ') bfr_line=$((serv_line - 1)) aftr_line=$((last_line - serv_line - 1)) - # Config lines str=$(grep -ni "Name $domain_idn" $conf | cut -f 1 -d :) top_line=$((str - serv_line + 1)) bottom_line=$((top_line + last_line -1)) - # Check for multialias (8k alias issue) multi=$(sed -n "$top_line,$bottom_line p" $conf |grep ServerAlias |wc -l) if [ "$multi" -ge 2 ]; then bottom_line=$((bottom_line + multi -1)) @@ -185,173 +171,98 @@ get_web_config_brds() { } +# Change web config change_web_config() { - # Get config borders get_web_config_brds || exit $? - - # Parsing config vhost=$(grep -A $aftr_line -B $bfr_line -ni "Name $domain_idn" $conf) str=$(echo "$vhost" | grep -F "$search_phrase" | head -n 1) - - # Parsing string position and content str_numb=$(echo "$str" | sed -e "s/-/=/" | cut -f 1 -d '=') str_cont=$(echo "$str" | sed -e "s/-/=/" | cut -f 2 -d '=') - # Escaping chars str_repl=$(echo "$str_repl" | sed \ -e 's/\\/\\\\/g' \ -e 's/&/\\&/g' \ -e 's/\//\\\//g') - # Changing config if [ ! -z "$str" ]; then sed -i "$str_numb s/.*/$str_repl/" $conf fi } +# Replace web config replace_web_config() { - # Get config borders get_web_config_brds || exit $? - - # Escaping chars clean_new=$(echo "$new" | sed \ -e 's/\\/\\\\/g' \ -e 's/&/\\&/g' \ -e 's/\//\\\//g') - clean_old=$(echo "$old" | sed \ -e 's/\\/\\\\/g' \ -e 's/&/\\&/g' \ -e 's/\//\\\//g') - # Replacing string in config sed -i "$top_line,$bottom_line s/$clean_old/$clean_new/" $conf } -# Get domain values +# Get domain variables get_domain_values() { for line in $(grep "DOMAIN='$domain'" $USER_DATA/$1.conf); do eval $line done } +# SSL certificate verification is_web_domain_cert_valid() { - - # Checking file existance if [ ! -e "$ssl_dir/$domain.crt" ] || [ ! -e "$ssl_dir/$domain.key" ]; then - echo "Error: ssl certificate not exist" - log_event 'debug' "$E_NOTEXIST $EVENT" + echo "Error: $ssl_dir/$domain.[crt|key] not found" + log_event "$E_NOTEXIST" "$EVENT" exit $E_NOTEXIST fi - # Checking certificate crt=$(openssl verify $ssl_dir/$domain.crt 2>/dev/null |grep '/C=') if [ -z "$crt" ]; then - echo "Error: ssl certificate invalid" - log_event 'debug' "$E_INVALID $EVENT" + echo "Error: certificate is not valid" + log_event "$E_INVALID" "$EVENT" exit $E_INVALID fi - # Checking certificate key - openssl rsa -in "$ssl_dir/$domain.key" -check >/dev/null 2>/dev/null + openssl rsa -in "$ssl_dir/$domain.key" -check &>/dev/null if [ "$?" -ne 0 ]; then - echo "Error: ssl key invalid" - log_event 'debug' "$E_INVALID $EVENT" + echo "Error: ssl key is not valid" + log_event "$E_INVALID" "$EVENT" exit $E_INVALID fi - # Checking certificate authority if [ -e "$ssl_dir/$domain.ca" ]; then ca=$(openssl verify $ssl_dir/$domain.ca 2>/dev/null |grep '/C=') if [ -z "$ca" ]; then - echo "Error: ssl certificate invalid" - log_event 'debug' "$E_INVALID $EVENT" + echo "Error: ssl certificate authority is not valid" + log_event "$E_INVALID" "$EVENT" exit $E_INVALID fi fi - # Checking server - openssl s_server -quiet \ - -cert $ssl_dir/$domain.crt -key $ssl_dir/$domain.key & + openssl s_server -quiet -cert $ssl_dir/$domain.crt \ + -key $ssl_dir/$domain.key & pid=$! - sleep 1 - disown > /dev/null 2>&1 - kill $pid > /dev/null 2>&1 - result=$? - if [ "$result" -ne '0' ]; then - echo "Error: ssl certificate key pair invalid" - log_event 'debug' "$E_INVALID $EVENT" + sleep 0.5 + disown &> /dev/null + kill $pid &> /dev/null + if [ "$?" -ne '0' ]; then + echo "Error: ssl certificate key pair is not valid" + log_event "$E_INVALID" "$EVENT" exit $E_INVALID fi } -is_dns_record_valid() { - # Checking record id - check_id=$(grep "^ID='$id'" $USER_DATA/dns/$domain) - - if [ -z "$check_id" ]; then - echo "Error: ID not exist" - log_event 'debug' "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST - fi -} - -is_domain_value_exist() { - domain_type="$1" - key="$2" - - # Parsing domains - string=$( grep "DOMAIN='$domain'" $USER_DATA/$domain_type.conf ) - - # Parsing key=value - eval $string - - # Self reference - eval value="$key" - - # Checking result - if [ -z "$value" ] || [ "$value" = 'no' ]; then - echo "Error: ${key//$/} is empty" - log_event 'debug' "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST - fi -} - +# Delete web configuartion del_web_config() { - # Get config borders get_web_config_brds || exit $? - - # Deleting lines from config sed -i "$top_line,$bottom_line d" $conf } -dom_clear_search(){ - # Defining delimeter - IFS=$'\n' - - # Reading file line by line - for line in $(grep $search_string $conf); do - # Parsing key=val - eval $line - - # Print result line - eval echo "$field" - done -} - -dom_clear_list() { - # Reading file line by line - while read line ; do - # Parsing key=value - eval $line - - # Print result line - eval echo "$field" - done < $conf -} - +# Add ip virtual hosting support namehost_ip_support() { - # Checking httpd config for NameHost string number if [ "$WEB_SYSTEM" = 'apache' ]; then conf_line=$(grep -n "NameVirtual" $conf|tail -n 1|cut -f 1 -d ':') if [ ! -z "$conf_line" ]; then @@ -360,7 +271,6 @@ namehost_ip_support() { conf_ins='1' fi - # Checking ssl support if [ "$WEB_SSL" = 'mod_ssl' ]; then sed -i "$conf_ins i NameVirtualHost $ip:$WEB_SSL_PORT" $conf sed -i "$conf_ins i Listen $ip:$WEB_SSL_PORT" $conf @@ -369,67 +279,54 @@ namehost_ip_support() { sed -i "$conf_ins i NameVirtualHost $ip:$WEB_PORT" $conf sed -i "$conf_ins i Listen $ip:$WEB_PORT" $conf - # Checking proxy support if [ "$PROXY_SYSTEM" = 'nginx' ]; then cat $WEBTPL/ngingx_ip.tpl | sed -e "s/%ip%/$ip/g" \ -e "s/%web_port%/$WEB_PORT/g" \ -e "s/%proxy_port%/$PROXY_PORT/g" >>$nconf - # Adding to rpaf ip pool as well ips=$(grep 'RPAFproxy_ips' $rconf) sed -i "s/$ips/$ips $ip/g" $rconf fi - - # Scheduling restart web_restart='yes' fi } +# Disable virtual ip hosting support namehost_ip_disable() { - #Checking web system if [ "$WEB_SYSTEM" = 'apache' ]; then sed -i "/NameVirtualHost $ip:/d" $conf sed -i "/Listen $ip:/d" $conf - # Checking proxy support if [ "$PROXY_SYSTEM" = 'nginx' ]; then tpl_ln=$(wc -l $WEBTPL/ngingx_ip.tpl | cut -f 1 -d ' ') ip_line=$(grep -n "%ip%" $WEBTPL/ngingx_ip.tpl |head -n1 |\ cut -f 1 -d :) - conf_line=$(grep -n -w $ip $nconf|head -n1|cut -f 1 -d :) - - # Checking parsed lines if [ -z "$tpl_ln" ] || [ -z "$ip_line" ] || [ -z "$conf_line" ] then echo "Error: nginx config paring error" - log_event 'debug' "$E_PARSING $EVENT" + log_event "$E_PARSING" "$EVENT" exit $E_PARSING fi - up_line=$((ip_line - 1)) first_line=$((conf_line - up_line)) last_line=$((conf_line - ip_line + tpl_ln)) - # Checking parsed lines if [ -z "$first_line" ] || [ -z "$last_line" ]; then echo "Error: nginx config paring error" - log_event 'debug' "$E_PARSING $EVENT" + log_event "$E_PARSING" "$EVENT" exit $E_PARSING fi sed -i "$first_line,$last_line d" $nconf - - # Deleting from rpaf ip pool as well ips=$(grep 'RPAFproxy_ips' $rconf) new_ips=$(echo "$ips"|sed -e "s/$ip//") sed -i "s/$ips/$new_ips/g" $rconf fi - - # Scheduling restart web_restart='yes' fi } +# Update web domain values upd_web_domain_values() { ip=$IP group="$user" @@ -438,7 +335,6 @@ upd_web_domain_values() { docroot_string="DocumentRoot $docroot" proxy_string="proxy_pass http://$ip:$WEB_PORT;" - # Parsing domain aliases i=1 j=1 OLD_IFS="$IFS" @@ -447,7 +343,6 @@ upd_web_domain_values() { alias_string='' for dalias in $ALIAS; do dalias=$(idn -t --quiet -a $dalias) - # Spliting ServerAlias lines check_8k="$server_alias $dalias" if [ "${#check_8k}" -ge '8100' ]; then if [ "$j" -eq 1 ]; then @@ -476,15 +371,12 @@ upd_web_domain_values() { fi IFS=$OLD_IFS - - # Checking error log status if [ "$ELOG" = 'no' ]; then elog='#' else elog='' fi - # Checking cgi if [ "$CGI" != 'yes' ]; then cgi='#' cgi_option='-ExecCGI' @@ -493,13 +385,11 @@ upd_web_domain_values() { cgi_option='+ExecCGI' fi - # Checking suspend if [ "$SUSPENDED" = 'yes' ]; then docroot_string="Redirect / http://$url" proxy_string="rewrite ^(.*)\$ http://$url;" fi - # Defining SSL vars ssl_crt="$HOMEDIR/$user/conf/web/ssl.$domain.crt" ssl_key="$HOMEDIR/$user/conf/web/ssl.$domain.key" ssl_pem="$HOMEDIR/$user/conf/web/ssl.$domain.pem" @@ -514,22 +404,3 @@ upd_web_domain_values() { esac } -is_mail_account_free() { - acc=${1-$account} - check_acc=$(grep -w $acc $USER_DATA/mail/$domain.conf) - if [ ! -z "$check_acc" ]; then - echo "Error: account $acc exists" - log_event 'debug' "$E_EXISTS $EVENT" - exit $E_EXISTS - fi -} - -is_mail_account_valid() { - acc=${1-$account} - check_acc=$(grep -w $acc $USER_DATA/mail/$domain.conf) - if [ -z "$check_acc" ]; then - echo "Error: account $acc not exist" - log_event 'debug' "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST - fi -} diff --git a/func/ip.sh b/func/ip.sh index cf821bd0..d70fad68 100644 --- a/func/ip.sh +++ b/func/ip.sh @@ -1,3 +1,41 @@ +# Validationg ip address +is_ip_valid() { + check_ifc=$(/sbin/ifconfig |grep "inet addr:$ip") + if [ ! -e "$VESTA/data/ips/$ip" ] || [ -z "$check_ifc" ]; then + echo "Error: IP $ip not exist" + log_event "$E_NOTEXIST" "$EVENT" + exit $E_NOTEXIST + fi +} + +# Check if ip availabile for user +is_ip_avalable() { + ip_data=$(cat $VESTA/data/ips/$ip) + owner=$(echo "$ip_data"|grep OWNER= | cut -f 2 -d \') + status=$(echo "$ip_data"|grep OWNER= | cut -f 2 -d \') + shared=no + if [ 'admin' = "$owner" ] && [ "$status" = 'shared' ]; then + shared='yes' + fi + if [ "$owner" != "$user" ] && [ "$shared" != 'yes' ]; then + echo "Error: User $user don't have permission to use $ip" + log_event "$E_FORBIDEN" "$EVENT" + exit $E_FORBIDEN + fi +} + +# Check ip ownership +is_sys_ip_owner() { + # Parsing ip + owner=$(grep 'OWNER=' $VESTA/data/ips/$IP|cut -f 2 -d \') + if [ "$owner" != "$user" ]; then + echo "Error: IP $IP not owned" + log_event "$E_FORBIDEN" "$EVENT" + exit $E_FORBIDEN + fi +} + + is_sys_ip_free() { # Parsing system ips ip_list=$(/sbin/ifconfig|grep 'inet addr:'|cut -f 2 -d ':'|cut -f 1 -d " ") @@ -25,17 +63,6 @@ get_next_interface_number() { echo ":$n" } -is_sys_ip_valid() { - # Parsing ifconfig - check_ifc=$(/sbin/ifconfig |grep "inet addr:$ip") - - # Checking ip existance - if [ ! -e "$VESTA/data/ips/$ip" ] || [ -z "$check_ifc" ]; then - echo "Error: IP not exist" - log_event 'debug' "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST - fi -} is_ip_key_empty() { key="$1" @@ -88,43 +115,7 @@ update_sys_ip_value() { $conf } -is_ip_avalable() { - # Checking ip existance - if [ ! -e "$VESTA/data/ips/$ip" ]; then - echo "Error: IP not exist" - log_event 'debug' "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST - fi - # Parsing ip data - ip_data=$(cat $VESTA/data/ips/$ip) - ip_owner=$(echo "$ip_data" | grep 'OWNER=' | cut -f 2 -d \' ) - ip_status=$(echo "$ip_data" | grep 'STATUS=' | cut -f 2 -d \' ) - - # Parsing user data - if [ 'admin' = "$ip_owner" ] && [ "$ip_status" = 'shared' ]; then - ip_shared='yes' - else - ip_shared='no' - fi - - if [ "$ip_owner" != "$user" ] && [ "$ip_shared" != 'yes' ]; then - echo "Error: ip not owned by user" - log_event 'debug' "$E_FORBIDEN $EVENT" - exit $E_FORBIDEN - fi -} - -is_sys_ip_owner() { - # Parsing ip - ip="$IP" - ip_owner=$(grep 'OWNER=' $VESTA/data/ips/$ip|cut -f 2 -d \') - if [ "$ip_owner" != "$user" ]; then - echo "Error: IP not owned" - log_event 'debug' "$E_FORBIDEN $EVENT" - exit $E_FORBIDEN - fi -} get_ip_name() { # Prinitng name diff --git a/func/shared.sh b/func/shared.sh index 0a6d150e..e661fa31 100644 --- a/func/shared.sh +++ b/func/shared.sh @@ -113,7 +113,7 @@ is_package_valid() { # Validate system type is_type_valid() { if [ -z "$(echo $1 | grep -w $2)" ]; then - echo "Error: unknown type" + echo "Error: $2 is unknown type" log_event "$E_INVALID" "$EVENT" exit $E_INVALID fi @@ -193,6 +193,30 @@ is_object_unsuspended() { fi } +# Check if object value is empty +is_object_value_empty() { + str=$(grep "$2='$3'" $USER_DATA/$1.conf) + eval $str + eval value=$4 + if [ ! -z "$value" ] && [ "$value" != 'no' ]; then + echo "Error: ${4//$}=$value (not empty)" + log_event "$E_EXISTS" "$EVENT" + exit $E_EXISTS + fi +} + +# Check if object value is empty +is_object_value_exist() { + str=$(grep "$2='$3'" $USER_DATA/$1.conf) + eval $str + eval value=$4 + if [ -z "$value" ] || [ "$value" = 'no' ]; then + echo "Error: ${4//$}=$value (not exist)" + log_event "$E_NOTEXIST" "$EVENT" + exit $E_NOTEXIST + fi +} + # Get object value get_object_value() { object=$(grep "$2='$3'" $USER_DATA/$1.conf) @@ -617,8 +641,6 @@ validate_format(){ account) validate_format_username "$arg" "$arg_name" ;; antispam) validate_format_boolean "$arg" ;; antivirus) validate_format_boolean "$arg" ;; - auth_pass) validate_format_password "$arg" ;; - auth_user) validate_format_username "$arg" "$arg_name" ;; backup) validate_format_date "$arg" ;; charset) validate_format_username "$arg" "$arg_name" ;; charsets) validate_format_common "$arg" 'charsets' ;; @@ -667,6 +689,8 @@ validate_format(){ rtype) validate_format_dns_type "$arg" ;; shell) validate_format_shell "$arg" ;; soa) validate_format_domain "$arg" ;; + stats_pass) validate_format_password "$arg" ;; + stats_user) validate_format_username "$arg" "$arg_name" ;; template) validate_format_username "$arg" "$arg_name" ;; ttl) validate_format_int "$arg" ;; url) validate_format_url "$arg" ;;