From a61a6e979eac35c08896760a58fbce66627749e0 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Fri, 24 Jun 2016 16:31:43 +0300 Subject: [PATCH] refactoring: log_event(), is_format_valid() --- bin/v-add-cron-job | 5 +- bin/v-add-cron-vesta-autoupdate | 4 +- bin/v-add-dns-domain | 11 +- bin/v-add-dns-record | 4 +- bin/v-add-domain | 6 +- bin/v-add-mail-account | 4 +- bin/v-add-mail-domain | 9 +- bin/v-add-sys-sftp-jail | 3 +- bin/v-add-user | 6 +- bin/v-add-web-domain | 6 +- bin/v-add-web-domain-proxy | 6 +- bin/v-backup-user | 283 ++++------ bin/v-change-database-owner | 1 - bin/v-change-dns-domain-tpl | 27 +- bin/v-change-domain-owner | 16 +- bin/v-change-fs-file-permission | 6 +- bin/v-change-mail-account-password | 2 +- bin/v-change-sys-ip-name | 6 +- bin/v-change-sys-ip-nat | 6 +- bin/v-change-sys-ip-owner | 3 +- bin/v-change-sys-ip-status | 2 +- bin/v-change-user-package | 28 +- bin/v-change-user-password | 2 +- bin/v-change-user-template | 4 +- bin/v-change-web-domain-backend-tpl | 2 +- bin/v-change-web-domain-ip | 14 +- bin/v-change-web-domain-proxy-tpl | 2 +- bin/v-change-web-domain-tpl | 5 +- bin/v-delete-domain | 10 +- bin/v-delete-sys-sftp-jail | 3 +- bin/v-delete-user | 40 +- bin/v-delete-web-domain | 13 +- bin/v-delete-web-domain-alias | 8 +- bin/v-generate-ssl-cert | 15 +- bin/v-list-dns-template | 2 +- bin/v-list-sys-users | 2 +- bin/v-list-user-ips | 6 +- bin/v-restart-cron | 5 +- bin/v-restart-dns | 7 +- bin/v-restart-ftp | 6 +- bin/v-restart-mail | 6 +- bin/v-restart-proxy | 6 +- bin/v-restart-service | 4 +- bin/v-restart-web | 6 +- bin/v-restart-web-backend | 6 +- bin/v-restore-user | 838 +++++++++++----------------- bin/v-suspend-web-domain | 2 +- bin/v-unsuspend-web-domain | 2 +- bin/v-update-dns-templates | 2 +- bin/v-update-user-backup-exclusions | 8 +- bin/v-update-user-backups | 278 --------- bin/v-update-web-domain-stat | 4 +- 52 files changed, 582 insertions(+), 1170 deletions(-) delete mode 100755 bin/v-update-user-backups diff --git a/bin/v-add-cron-job b/bin/v-add-cron-job index 2a1a7c9b2..6b67eab43 100755 --- a/bin/v-add-cron-job +++ b/bin/v-add-cron-job @@ -17,7 +17,7 @@ hour=$3 day=$4 month=$5 wday=$6 -command=$(echo $7 | sed "s/'/%quote%/g") +command=$(echo $7 |sed "s/'/%quote%/g") job=$8 restart=$9 @@ -25,8 +25,7 @@ restart=$9 source $VESTA/func/main.sh source $VESTA/conf/vesta.conf -# Assigning new value -A7="$command" +HIDE=7 #----------------------------------------------------------# diff --git a/bin/v-add-cron-vesta-autoupdate b/bin/v-add-cron-vesta-autoupdate index 3ad0ba4ea..8b8d13677 100755 --- a/bin/v-add-cron-vesta-autoupdate +++ b/bin/v-add-cron-vesta-autoupdate @@ -40,8 +40,8 @@ time=$(echo "$time_n_date" |cut -f 1 -d \ ) date=$(echo "$time_n_date" |cut -f 2 -d \ ) # Define time somewhere at night -min=$(gen_password '012345' '2') -hour=$(gen_password '1234567' '1') +min=$(generate_password '012345' '2') +hour=$(generate_password '1234567' '1') day='*' month='*' wday='*' diff --git a/bin/v-add-dns-domain b/bin/v-add-dns-domain index df9ab30ae..d1db42e2e 100755 --- a/bin/v-add-dns-domain +++ b/bin/v-add-dns-domain @@ -17,8 +17,13 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain=$(echo $domain | sed -e 's/\.*$//g' -e 's/^\.*//g') -domain=$(echo $domain | tr '[:upper:]' '[:lower:]') -domain_idn=$(idn -t --quiet -a "$domain") +if [[ "$domain" =~ [[:upper:]] ]]; then + domain=$(echo "$domain" |tr '[:upper:]' '[:lower:]') +fi +domain_idn="$domain" +if [[ "$domain" = *[![:ascii:]]* ]]; then + domain_idn=$(idn -t --quiet -a $domain) +fi ip=$3 ns1=$4 ns2=$5 @@ -48,7 +53,7 @@ is_object_unsuspended 'user' 'USER' "$user" is_domain_new 'dns' is_package_full 'DNS_DOMAINS' template=$(get_user_value '$DNS_TEMPLATE') -is_dns_template_valid +is_dns_template_valid $template if [ ! -z "$ns1" ]; then ns1=$(echo $4 | sed -e 's/\.*$//g' -e 's/^\.*//g') diff --git a/bin/v-add-dns-record b/bin/v-add-dns-record index 1cdb57d79..f522f77dc 100755 --- a/bin/v-add-dns-record +++ b/bin/v-add-dns-record @@ -14,9 +14,7 @@ # Argument definition user=$1 -domain=$(idn -t --quiet -u "$2" ) -domain=$(echo $domain | tr '[:upper:]' '[:lower:]') -domain_idn=$(idn -t --quiet -a "$domain") +domain=$2 record=$(idn -t --quiet -u "$3" ) record=$(echo "$record" | tr '[:upper:]' '[:lower:]') rtype=$(echo "$4"| tr '[:lower:]' '[:upper:]') diff --git a/bin/v-add-domain b/bin/v-add-domain index c18c9cb56..0880442f9 100755 --- a/bin/v-add-domain +++ b/bin/v-add-domain @@ -39,11 +39,9 @@ is_object_unsuspended 'user' 'USER' "$user" # Get ip if it wasn't defined if [ -z "$ip" ]; then - ip=$(get_user_ip $user) + get_user_ip $user if [ -z "$ip" ]; then - echo "Error: no avaiable IP address" - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST + check_result $E_NOTEXIST "no avaiable IP address" fi fi diff --git a/bin/v-add-mail-account b/bin/v-add-mail-account index 77e44dfae..586871a47 100755 --- a/bin/v-add-mail-account +++ b/bin/v-add-mail-account @@ -38,7 +38,7 @@ is_object_valid 'user' 'USER' "$user" is_object_unsuspended 'user' 'USER' "$user" is_object_valid 'mail' 'DOMAIN' "$domain" is_object_unsuspended 'mail' 'DOMAIN' "$domain" -is_package_full 'MAIL_USER' +is_package_full 'MAIL_ACCOUNTS' is_mail_new "$account" is_password_valid @@ -48,7 +48,7 @@ is_password_valid #----------------------------------------------------------# # Generating hashed password -salt=$(gen_password "$PW_MATRIX" "8") +salt=$(generate_password "$PW_MATRIX" "8") md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)" # Adding account info into password file diff --git a/bin/v-add-mail-domain b/bin/v-add-mail-domain index 68ac1fa1a..62858ef32 100755 --- a/bin/v-add-mail-domain +++ b/bin/v-add-mail-domain @@ -13,8 +13,13 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain=$(echo $domain | sed -e 's/\.*$//g' -e 's/^\.*//g') -domain=$(echo $domain | tr '[:upper:]' '[:lower:]') -domain_idn=$(idn -t --quiet -a "$domain") +if [[ "$domain" =~ [[:upper:]] ]]; then + domain=$(echo "$domain" |tr '[:upper:]' '[:lower:]') +fi +domain_idn="$domain" +if [[ "$domain" = *[![:ascii:]]* ]]; then + domain_idn=$(idn -t --quiet -a $domain) +fi antispam=${3-yes} antivirus=${4-yes} dkim=${5-yes} diff --git a/bin/v-add-sys-sftp-jail b/bin/v-add-sys-sftp-jail index 896fb0506..7953f1518 100755 --- a/bin/v-add-sys-sftp-jail +++ b/bin/v-add-sys-sftp-jail @@ -58,12 +58,11 @@ fi if [ "$restart" = 'yes' ]; then subj="OpenSSH restart failed" email=$(grep CONTACT $VESTA/data/users/admin/user.conf |cut -f 2 -d \') - send_mail="$VESTA/web/inc/mail-wrapper.php" /usr/sbin/sshd -t >/dev/null 2>&1 if [ "$?" -ne 0 ]; then mail_text="OpenSSH can not be restarted. Please check config: \n\n$(/usr/sbin/sshd -t)" - echo -e "$mail_text" | $send_mail -s "$subj" $email + echo -e "$mail_text" |$SENDMAIL -s "$subj" $email else service ssh restart >/dev/null 2>&1 service sshd restart >/dev/null 2>&1 diff --git a/bin/v-add-user b/bin/v-add-user index 27d0da204..66730a3f7 100755 --- a/bin/v-add-user +++ b/bin/v-add-user @@ -24,9 +24,7 @@ source $VESTA/conf/vesta.conf is_user_free() { check_sysuser=$(cut -f 1 -d : /etc/passwd | grep -w "$user" ) if [ ! -z "$check_sysuser" ] || [ -e "$USER_DATA" ]; then - echo "Error: user $user exists" - log_event "$E_EXISTS" "$ARGUMENTS" - exit $E_EXISTS + check_result $E_EXISTS "user $user exists" fi } @@ -155,7 +153,7 @@ $pkg_data CONTACT='$email' CRON_REPORTS='yes' MD5='$(awk -v user=$user -F : 'user == $1 {print $2}' /etc/shadow)' -RKEY='$(gen_password)' +RKEY='$(generate_password)' SUSPENDED='no' SUSPENDED_USERS='0' SUSPENDED_WEB='0' diff --git a/bin/v-add-web-domain b/bin/v-add-web-domain index ab0a5ffa6..6a8cf1983 100755 --- a/bin/v-add-web-domain +++ b/bin/v-add-web-domain @@ -61,7 +61,7 @@ is_object_valid 'user' 'USER' "$user" is_object_unsuspended 'user' 'USER' "$user" is_package_full 'WEB_DOMAINS' 'WEB_ALIASES' is_domain_new 'web' "$domain,$aliases" -is_ip_valid "$ip" +is_ip_valid "$ip" "$user" #----------------------------------------------------------# @@ -133,8 +133,8 @@ fi # Increasing counters increase_ip_value "$local_ip" -increase_user_value "$user" '$U_WEB_DOMAINS' "$alias_number" -increase_user_value "$user" '$U_WEB_ALIASES' +increase_user_value "$user" '$U_WEB_DOMAINS' +increase_user_value "$user" '$U_WEB_ALIASES' "$alias_number" # Generating timestamp time_n_date=$(date +'%T %F') diff --git a/bin/v-add-web-domain-proxy b/bin/v-add-web-domain-proxy index 44c4d8a00..373263523 100755 --- a/bin/v-add-web-domain-proxy +++ b/bin/v-add-web-domain-proxy @@ -55,11 +55,11 @@ local_ip=$(get_real_ip $IP) # Preparing domain values for the template substitution PROXY_EXT="$extentions" -add_web_config "$PROXY_SYSTEM" "$PROXY.tpl" +add_web_config "$PROXY_SYSTEM" "$template.tpl" # Adding proxy for ssl if [ "$SSL" = 'yes' ]; then - add_web_config "$PROXY_SYSTEM" "$PROXY.stpl" + add_web_config "$PROXY_SYSTEM" "$template.stpl" fi @@ -68,7 +68,7 @@ fi #----------------------------------------------------------# # Update config -update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$PROXY" +update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$template" update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions" # Restarting web server diff --git a/bin/v-backup-user b/bin/v-backup-user index 7d294b9b2..88db71d16 100755 --- a/bin/v-backup-user +++ b/bin/v-backup-user @@ -41,7 +41,7 @@ is_backup_enabled # Set backup directory if undefined if [ -z "$BACKUP" ]; then - BACKUP=/home/backup + BACKUP=/backup fi mkdir -p $BACKUP @@ -49,28 +49,20 @@ mkdir -p $BACKUP start_time=$(date '+%s') # Set notification email and subject -if [ "$notify" != 'no' ]; then - subj="$user → backup failed" - email=$(get_user_value '$CONTACT') -else - subj="$user → backup failed" - email=$(grep CONTACT $VESTA/data/users/admin/user.conf |cut -f 2 -d \') -fi +subj="$user → backup failed" +email=$(grep CONTACT $VESTA/data/users/admin/user.conf |cut -f 2 -d \') -# Check load average +# Checking load average la=$(cat /proc/loadavg |cut -f 1 -d ' ' |cut -f 1 -d '.') i=0 while [ "$la" -ge "$BACKUP_LA_LIMIT" ]; do - echo "$(date "+%F %T") LoadAverage $la is above threshold. Sleeping..." - sleep 120 - if [ "$i" -ge "5" ]; then - mail_top=$(top -b| head -n 30) - mail_text="LoadAverage $i is above threshold\n\n$mail_top\n" - echo -e "$mail_text" |$send_mail -s "$subj" $email - echo "Error: LA is too high" + echo -e "$(date "+%F %T") Load Average $la" + sleep 60 + if [ "$i" -ge "15" ]; then + la_error="LoadAverage $la is above threshold" + echo "$la_error" |$SENDMAIL -s "$subj" $email $notify sed -i "/ $user /d" $VESTA/data/queue/backup.pipe - log_event "$E_LA" "$ARGUMENTS" - exit $E_LA + check_result $E_LA "$la_error" fi la=$(cat /proc/loadavg |cut -f 1 -d ' ' |cut -f 1 -d '.') (( ++i)) @@ -79,48 +71,40 @@ done # Creating temporary directory tmpdir=$(mktemp -p $BACKUP -d) if [ "$?" -ne 0 ]; then - echo "Can't create tmp dir $tmpdir" |$send_mail -s "$subj" $email - echo "Error: can't create tmp dir" - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST + echo "Can't create tmp dir $tmpdir" |$SENDMAIL -s "$subj" $email $notify + check_result $E_NOTEXIST "can't create tmp dir" fi # Backup sys configs -echo -e "-- SYSTEM --" -msg="-- SYSTEM --" +echo "-- SYSTEM --" |tee $BACKUP/$user.log mkdir $tmpdir/vesta -echo -e "$(date "+%F %T") $user.conf" -msg="$msg\n$(date "+%F %T") $user.conf" +echo -e "$(date "+%F %T") $user.conf" |tee -a $BACKUP/$user.log cp -r $USER_DATA/user.conf $tmpdir/vesta/ +cp -r $USER_DATA/ssl $tmpdir/vesta/ if [ -e "$USER_DATA/stats.log" ]; then - echo -e "$(date "+%F %T") stats.log" - msg="$msg\n$(date "+%F %T") stats.log" + echo -e "$(date "+%F %T") stats.log" |tee -a $BACKUP/$user.log cp -r $USER_DATA/stats.log $tmpdir/vesta/ fi if [ -e "$USER_DATA/history.log" ]; then - echo -e "$(date "+%F %T") history.log" - msg="$msg\n$(date "+%F %T") history.log" + echo -e "$(date "+%F %T") history.log" |tee -a $BACKUP/$user.log cp -r $USER_DATA/history.log $tmpdir/vesta/ fi if [ -e "$USER_DATA/backup-excludes.conf" ]; then - echo -e "$(date "+%F %T") backup-excludes.conf" - msg="$msg\n$(date "+%F %T") backup-excludes.conf" + echo -e "$(date "+%F %T") backup-excludes.conf" |tee -a $BACKUP/$user.log cp -r $USER_DATA/backup-excludes.conf $tmpdir/vesta/ fi # Backup PAM mkdir $tmpdir/pam -echo -e "$(date "+%F %T") pam" -msg="$msg\n$(date "+%F %T") pam" +echo -e "$(date "+%F %T") pam" |tee -a $BACKUP/$user.log grep "^$user:" /etc/passwd > $tmpdir/pam/passwd grep "^$user:" /etc/shadow > $tmpdir/pam/shadow grep "^$user:" /etc/group > $tmpdir/pam/group echo -msg="$msg\n" # Parsing excludes if [ -e "$USER_DATA/backup-excludes.conf" ]; then @@ -129,8 +113,7 @@ fi # WEB domains if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB" != '*' ]; then - echo "-- WEB --" - msg="$msg\n-- WEB --" + echo -e "\n-- WEB --" |tee -a $BACKUP/$user.log mkdir $tmpdir/web/ # Parsing domain exclusions @@ -140,8 +123,7 @@ if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB" != '*' ]; then if [ -z "$exclusion" ]; then web_list="$web_list $domain" else - echo "$(date "+%F %T") excluding $domain" - msg="$msg\n$(date "+%F %T") excluding $domain" + echo "$(date "+%F %T") excluding $domain"|tee -a $BACKUP/$user.log fi done web_list=$(echo "$web_list" |sed -e "s/ */\ /g" -e "s/^ //") @@ -150,8 +132,7 @@ if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB" != '*' ]; then for domain in $web_list; do ((i ++)) - echo -e "$(date "+%F %T") $domain" - msg="$msg\n$(date "+%F %T") $domain" + echo -e "$(date "+%F %T") $domain" |tee -a $BACKUP/$user.log mkdir -p $tmpdir/web/$domain/conf mkdir -p $tmpdir/web/$domain/vesta @@ -222,7 +203,7 @@ if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB" != '*' ]; then # Backup files cd $HOMEDIR/$user/web/$domain - tar -cpf $tmpdir/web/$domain/domain_data.tar * ${fargs[@]} + tar -cpf $tmpdir/web/$domain/domain_data.tar * ${fargs[@]} # Compress archive gzip -$BACKUP_GZIP $tmpdir/web/$domain/domain_data.tar @@ -230,20 +211,15 @@ if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB" != '*' ]; then # Print total if [ "$i" -eq 1 ]; then - echo -e "$(date "+%F %T") *** $i domain ***" - msg="$msg\n$(date "+%F %T") *** $i domain ***" + echo -e "$(date "+%F %T") *** $i domain ***" |tee -a $BACKUP/$user.log else - echo -e "$(date "+%F %T") *** $i domains ***" - msg="$msg\n$(date "+%F %T") *** $i domains ***" + echo -e "$(date "+%F %T") *** $i domains ***"|tee -a $BACKUP/$user.log fi - echo - msg="$msg\n" fi # DNS domains if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS" != '*' ]; then - echo "-- DNS --" - msg="$msg\n-- DNS --" + echo -e "\n-- DNS --" |tee -a $BACKUP/$user.log mkdir $tmpdir/dns/ # Parsing domain exclusions @@ -261,8 +237,7 @@ if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS" != '*' ]; then i=0 for domain in $dns_list; do ((i ++)) - echo -e "$(date "+%F %T") $domain" - msg="$msg\n$(date "+%F %T") $domain" + echo -e "$(date "+%F %T") $domain" |tee -a $BACKUP/$user.log # Building directory tree mkdir -p $tmpdir/dns/$domain/conf @@ -282,20 +257,15 @@ if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS" != '*' ]; then # Print total if [ "$i" -eq 1 ]; then - echo -e "$(date "+%F %T") *** $i domain ***" - msg="$msg\n$(date "+%F %T") *** $i domain ***" + echo -e "$(date "+%F %T") *** $i domain ***" |tee -a $BACKUP/$user.log else - echo -e "$(date "+%F %T") *** $i domains ***" - msg="$msg\n$(date "+%F %T") *** $i domains ***" + echo -e "$(date "+%F %T") *** $i domains ***"|tee -a $BACKUP/$user.log fi - echo - msg="$msg\n" fi # Mail domains if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL" != '*' ]; then - echo "-- MAIL --" - msg="$msg\n-- MAIL --" + echo -e "\n-- MAIL --" |tee -a $BACKUP/$user.log mkdir $tmpdir/mail/ # Parsing domain exclusions @@ -305,8 +275,7 @@ if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL" != '*' ]; then if [ -z "$check_exl" ]; then mail_list="$mail_list $domain" else - echo "$(date "+%F %T") excluding $domain" - msg="$msg\n$(date "+%F %T") excluding $domain" + echo "$(date "+%F %T") excluding $domain"|tee -a $BACKUP/$user.log fi done mail_list=$(echo "$mail_list" |sed -e "s/ */\ /g" -e "s/^ //") @@ -314,8 +283,7 @@ if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL" != '*' ]; then i=0 for domain in $mail_list; do ((i ++)) - echo -e "$(date "+%F %T") $domain" - msg="$msg\n$(date "+%F %T") $domain" + echo -e "$(date "+%F %T") $domain" |tee -a $BACKUP/$user.log mkdir -p $tmpdir/mail/$domain/conf mkdir -p $tmpdir/mail/$domain/vesta domain_idn=$(idn -t --quiet -a "$domain") @@ -342,13 +310,13 @@ if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL" != '*' ]; then # Checking exlusions if [ -z "$exclusion" ] && [[ "$MAIL_SYSTEM" =~ exim ]]; then - echo "$(date "+%F %T") + $account@$domain" - msg="$msg\n$(date "+%F %T") + $account@$domain" + echo "$(date "+%F %T") + $account@$domain" |\ + tee -a $BACKUP/$user.log touch $tmpdir/mail/$domain/accounts.tar tar -rpf $tmpdir/mail/$domain/accounts.tar $account else - echo "$(date "+%F %T") excluding account $account" - msg="$msg\n$(date "+%F %T") excluding account $account" + echo "$(date "+%F %T") excluding mail account $account" |\ + tee -a $BACKUP/$user.log fi done @@ -360,21 +328,16 @@ if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL" != '*' ]; then # Print total if [ "$i" -eq 1 ]; then - echo -e "$(date "+%F %T") *** $i domain ***" - msg="$msg\n$(date "+%F %T") *** $i domain ***" + echo -e "$(date "+%F %T") *** $i domain ***" |tee -a $BACKUP/$user.log else - echo -e "$(date "+%F %T") *** $i domains ***" - msg="$msg\n$(date "+%F %T") *** $i domains ***" + echo -e "$(date "+%F %T") *** $i domains ***"|tee -a $BACKUP/$user.log fi - echo - msg="$msg\n" fi # Databases if [ ! -z "$DB_SYSTEM" ] && [ "$DB" != '*' ]; then - echo "-- DB --" - msg="$msg\n-- DB --" + echo -e "\n-- DB --" |tee -a $BACKUP/$user.log mkdir $tmpdir/db/ # Parsing database exclusions @@ -383,8 +346,8 @@ if [ ! -z "$DB_SYSTEM" ] && [ "$DB" != '*' ]; then if [ -z "$exclusion" ]; then db_list="$db_list $database" else - echo "$(date "+%F %T") excluding $database" - msg="$msg\n$(date "+%F %T") excluding $database" + echo "$(date "+%F %T") excluding $database" |\ + tee -a $BACKUP/$user.log fi done @@ -395,9 +358,7 @@ if [ ! -z "$DB_SYSTEM" ] && [ "$DB" != '*' ]; then ((i ++)) get_database_values - echo -e "$(date "+%F %T") $database ($TYPE)" - msg="$msg\n$(date "+%F %T") $database ($TYPE)" - + echo -e "$(date "+%F %T") $database ($TYPE)" |tee -a $BACKUP/$user.log mkdir -p $tmpdir/db/$database/conf mkdir -p $tmpdir/db/$database/vesta @@ -417,20 +378,17 @@ if [ ! -z "$DB_SYSTEM" ] && [ "$DB" != '*' ]; then # Print total if [ "$i" -eq 1 ]; then - echo -e "$(date "+%F %T") *** $i database ***" - msg="$msg\n$(date "+%F %T") *** $i database ***" + echo -e "$(date "+%F %T") *** $i database ***" |\ + tee -a $BACKUP/$user.log else - echo -e "$(date "+%F %T") *** $i databases ***" - msg="$msg\n$(date "+%F %T") *** $i databases ***" + echo -e "$(date "+%F %T") *** $i databases ***"|\ + tee -a $BACKUP/$user.log fi - echo - msg="$msg\n" fi # Cron jobs if [ ! -z "$CRON_SYSTEM" ] && [ "$CRON" != '*' ]; then - echo "-- CRON --" - msg="$msg\n-- CRON --" + echo -e "\n-- CRON --" |tee -a $BACKUP/$user.log mkdir $tmpdir/cron/ # Backup cron.conf @@ -444,20 +402,17 @@ if [ ! -z "$CRON_SYSTEM" ] && [ "$CRON" != '*' ]; then # Print total if [ "$cron_record" -eq 1 ]; then - echo -e "$(date "+%F %T") *** $cron_record job ***" - msg="$msg\n$(date "+%F %T") *** $cron_record job ***" + echo -e "$(date "+%F %T") *** $cron_record job ***" |\ + tee -a $BACKUP/$user.log else - echo -e "$(date "+%F %T") *** $cron_record jobs ***" - msg="$msg\n$(date "+%F %T") *** $cron_record jobs ***" + echo -e "$(date "+%F %T") *** $cron_record jobs ***" |\ + tee -a $BACKUP/$user.log fi - echo - msg="$msg\n" fi # User Directories if [ "$USER" != '*' ]; then - echo "-- User Dir --" - msg="$msg\n-- User Dir --" + echo -e "\n-- User Dir --" |tee -a $BACKUP/$user.log mkdir $tmpdir/user_dir cd $HOMEDIR/$user @@ -471,8 +426,8 @@ if [ "$USER" != '*' ]; then fargs+=(-not) fargs+=(-path) fargs+=("./$xpath*") - echo "$(date "+%F %T") excluding directory $xpath" - msg="$msg\n$(date "+%F %T") excluding directory $xpath" + echo "$(date "+%F %T") excluding directory $xpath" |\ + tee -a $BACKUP/$user.log done IFS=$'\n' @@ -484,8 +439,7 @@ if [ "$USER" != '*' ]; then if [ -z "$exclusion" ]; then ((i ++)) udir_list="$udir_list $udir" - echo -e "$(date "+%F %T") adding $udir" - msg="$msg\n$(date "+%F %T") adding $udir" + echo -e "$(date "+%F %T") adding $udir" |tee -a $BACKUP/$user.log # Backup files and dirs tar -cpf $tmpdir/user_dir/$udir.tar $udir @@ -499,14 +453,12 @@ if [ "$USER" != '*' ]; then # Print total if [ "$i" -eq 1 ]; then - echo -e "$(date "+%F %T") *** $i user directory ***" - msg="$msg\n$(date "+%F %T") *** $i directory ***" + echo -e "$(date "+%F %T") *** $i user directory ***" |\ + tee -a $BACKUP/$user.log else - echo -e "$(date "+%F %T") *** $i directories ***" - msg="$msg\n$(date "+%F %T") *** $i directories ***" + echo -e "$(date "+%F %T") *** $i directories ***" |\ + tee -a $BACKUP/$user.log fi - echo - msg="$msg\n" fi # Get backup size @@ -533,23 +485,20 @@ local_backup(){ # Removing old backup for backup in $(echo "$backup_list" |head -n $backups_rm_number); do backup_date=$(echo $backup |sed -e "s/$user.//" -e "s/.tar$//") - echo -e "$(date "+%F %T") Roated: $backup_date" - msg="$msg\n$(date "+%F %T") Rotated: $backup_date" + echo -e "$(date "+%F %T") Roated: $backup_date" |\ + tee -a $BACKUP/$user.log rm -f $BACKUP/$backup done fi # Checking disk space disk_usage=$(df $BACKUP |tail -n1 |tr ' ' '\n' |grep % |cut -f 1 -d %) - if [ "$disk_usage" -ge "$BACKUP_DISK_LIMIT" ]; then rm -rf $tmpdir - echo "Not enough disk space to run backup" |\ - $send_mail -s "$subj" $email - echo "Error: Not enough disk space" + rm -f $BACKUP/$user.log sed -i "/ $user /d" $VESTA/data/queue/backup.pipe - log_event "$E_DISK" "$ARGUMENTS" - exit $E_DISK + echo "Not enough disk space" |$SENDMAIL -s "$subj" $email $notify + check_result "$E_DISK" "Not enough dsk space" fi # Creating final tarball @@ -558,8 +507,8 @@ local_backup(){ chmod 640 $BACKUP/$user.$date.tar chown admin:$user $BACKUP/$user.$date.tar localbackup='yes' - echo -e "$(date "+%F %T") Local: $BACKUP/$user.$date.tar" - msg="$msg\n$(date "+%F %T") Local: $BACKUP/$user.$date.tar" + echo -e "$(date "+%F %T") Local: $BACKUP/$user.$date.tar" |\ + tee -a $BACKUP/$user.log U_BACKUPS=$(ls $BACKUP/ |grep "^$user." |wc -l) update_user_value "$user" '$U_BACKUPS' "$U_BACKUPS" } @@ -582,12 +531,12 @@ EOF ftp_backup() { # Checking config if [ ! -e "$VESTA/conf/ftp.backup.conf" ]; then - ftp_conf_error="Can't open $VESTA/conf/ftp.backup.conf" - echo "$ftp_conf_error" |$send_mail -s "$subj" $email - echo "Error: $VESTA/conf/ftp.backup.conf doesn't exist" + error="ftp.backup.conf doesn't exist" + rm -rf $tmpdir + rm -f $BACKUP/$user.log + echo "$error" |$SENDMAIL -s "$subj" $email $notify sed -i "/ $user /d" $VESTA/data/queue/backup.pipe - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST + check_result "$E_NOTEXIST" "$error" fi # Parse config @@ -600,13 +549,12 @@ ftp_backup() { # Checking variables if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then + error="Can't parse ftp backup configuration" rm -rf $tmpdir - echo "Can't parse ftp backup configuration" |\ - $send_mail -s "$subj" $email - echo "Error: Parsing error" + rm -f $BACKUP/$user.log + echo "$error" |$SENDMAIL -s "$subj" $email $notify sed -i "/ $user /d" $VESTA/data/queue/backup.pipe - log_event "$E_PARSING" "$ARGUMENTS" - exit $E_PARSING + check_result "$E_PARSING" "$error" fi @@ -617,13 +565,12 @@ ftp_backup() { fconn=$(ftpc) ferror=$(echo $fconn |grep -i -e failed -e error -e "Can't" -e "not conn") if [ ! -z "$ferror" ]; then + error="Error: can't login to ftp ftp://$USERNAME@$HOST" rm -rf $tmpdir - echo "Can't login to ftp://$USERNAME@$HOST" |\ - $send_mail -s "$subj" $email - echo "Error: can't login to ftp ftp://$USERNAME@$HOST" + rm -f $BACKUP/$user.log + echo "$error" |$SENDMAIL -s "$subj" $email $notify sed -i "/ $user /d" $VESTA/data/queue/backup.pipe - log_event "$E_CONNECT" "$ARGUMENTS" - exit $E_CONNECT + check_result "$E_CONNECT" "$error" fi # Check ftp permissions @@ -632,13 +579,12 @@ ftp_backup() { ftpc "mkdir $ftmpdir" "rm $ftmpdir" ftp_result=$(ftpc "mkdir $ftmpdir" "rm $ftmpdir" |grep -v Trying) if [ ! -z "$ftp_result" ] ; then + error="Can't create ftp backup folder ftp://$HOST$BPATH" rm -rf $tmpdir - echo "Can't create ftp backup folder ftp://$HOST$BPATH" |\ - $send_mail -s "$subj" $email - echo "Error: cant's create ftp folder ftp://$HOST$BPATH" + rm -f $BACKUP/$user.log + echo "$error" |$SENDMAIL -s "$subj" $email $notify sed -i "/ $user /d" $VESTA/data/queue/backup.pipe - log_event "$E_FTP" "$ARGUMENTS" - exit $E_FTP + check_result "$E_FTP" "$error" fi # Checking retention @@ -648,8 +594,8 @@ ftp_backup() { backups_rm_number=$((backups_count - BACKUPS + 1)) for backup in $(echo "$backup_list" |head -n $backups_rm_number); do backup_date=$(echo $backup |sed -e "s/$user.//" -e "s/.tar$//") - echo -e "$(date "+%F %T") Roated ftp backup: $backup_date" - msg="$msg\n$(date "+%F %T") Roated ftp backup: $backup_date" + echo -e "$(date "+%F %T") Roated ftp backup: $backup_date" |\ + tee -a $BACKUP/$user.log ftpc "cd $BPATH" "delete $backup" done fi @@ -729,12 +675,12 @@ sftp_backup() { # Checking config if [ ! -e "$VESTA/conf/sftp.backup.conf" ]; then - sftp_conf_error="Can't open $VESTA/conf/sftp.backup.conf" - echo "$sftp_conf_error" |$send_mail -s "$subj" $email - echo "Error: $VESTA/conf/sftp.backup.conf doesn't exist" + error="Can't open sftp.backup.conf" + rm -rf $tmpdir + rm -f $BACKUP/$user.log + echo "$error" |$SENDMAIL -s "$subj" $email $notify sed -i "/ $user /d" $VESTA/data/queue/backup.pipe - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST + check_result "$E_NOTEXIST" "$error" fi # Parse config @@ -747,17 +693,17 @@ sftp_backup() { # Checking variables if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then + error="Can't parse sftp backup configuration" rm -rf $tmpdir - echo "Can't parse sftp backup configuration" |\ - $send_mail -s "$subj" $email - echo "Error: Parsing error" + rm -f $BACKUP/$user.log + echo "$error" |$SENDMAIL -s "$subj" $email $notify sed -i "/ $user /d" $VESTA/data/queue/backup.pipe - log_event "$E_PARSING" "$ARGUMENTS" - exit $E_PARSING + check_result "$E_PARSING" "$error" fi # Debug info - echo -e "$(date "+%F %T") Remote: sftp://$HOST/$BPATH/$user.$date.tar" + echo -e "$(date "+%F %T") Remote: sftp://$HOST/$BPATH/$user.$date.tar" |\ + tee -a $BACKUP/$user.log # Checking network connection and write permissions sftmpdir="$BPATH/vst.bK76A9SUkt" @@ -765,33 +711,32 @@ sftp_backup() { sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1 rc=$? if [[ "$rc" != 0 ]]; then - rm -rf $tmpdir case $rc in - $E_CONNECT) echo "Error: can't login to sftp host $HOST" |\ - $send_mail -s "$subj" $email;; - $E_FTP) echo "Error: can't create temp folder on sftp $HOST" |\ - $send_mail -s "$subj" $email;; + $E_CONNECT) error="Can't login to sftp host $HOST" ;; + $E_FTP) error="Can't create temp folder on sftp $HOST" ;; esac + rm -rf $tmpdir + rm -f $BACKUP/$user.log + echo "$error" |$SENDMAIL -s "$subj" $email $notify sed -i "/ $user /d" $VESTA/data/queue/backup.pipe - log_event "$rc" "$ARGUMENTS" - exit "$rc" + check_result "$rc" "$error" fi # Checking retention - backup_list=$(sftpc "cd $BPATH" "ls -l" |awk '{print $9}' |grep "^$user\.") + backup_list=$(sftpc "cd $BPATH" "ls -l" |awk '{print $9}'|grep "^$user\.") backups_count=$(echo "$backup_list" |wc -l) if [ "$backups_count" -ge "$BACKUPS" ]; then backups_rm_number=$((backups_count - BACKUPS + 1)) - for backup in $(echo "$backup_list" |head -n $backups_rm_number); do + for backup in $(echo "$backup_list" |head -n $backups_rm_number); do backup_date=$(echo $backup |sed -e "s/$user.//" -e "s/.tar.*$//") - echo -e "$(date "+%F %T") Roated sftp backup: $backup_date" - msg="$msg\n$(date "+%F %T") Roated sftp backup: $backup_date" + echo -e "$(date "+%F %T") Roated sftp backup: $backup_date" |\ + tee -a $BACKUP/$user.log sftpc "cd $BPATH" "rm $backup" > /dev/null 2>&1 done fi # Uploading backup archive - echo -e "$(date "+%F %T") Uploading $user.$date.tar ..." + echo "$(date "+%F %T") Uploading $user.$date.tar"|tee -a $BACKUP/$user.log if [ "$localbackup" = 'yes' ]; then cd $BACKUP sftpc "cd $BPATH" "put $user.$date.tar" > /dev/null 2>&1 @@ -804,8 +749,7 @@ sftp_backup() { fi } -echo "-- SUMMARY --" -msg="$msg\n-- SUMMARY --" +echo -e "\n-- SUMMARY --" |tee -a $BACKUP/$user.log # Switching on backup system types for backup_type in $(echo -e "${BACKUP_SYSTEM//,/\\n}"); do @@ -831,10 +775,8 @@ if [ "$run_time" -eq 1 ]; then min=minute fi -echo "$(date "+%F %T") Size: $size Mb" -msg="$msg\n$(date "+%F %T") Size: $size Mb" -echo "$(date "+%F %T") Runtime: $run_time $min" -msg="$msg\n$(date "+%F %T") Runtime: $run_time $min" +echo "$(date "+%F %T") Size: $size Mb" |tee -a $BACKUP/$user.log +echo "$(date "+%F %T") Runtime: $run_time $min" |tee -a $BACKUP/$user.log #----------------------------------------------------------# @@ -866,10 +808,11 @@ chmod 660 $USER_DATA/backup.conf sed -i "/v-backup-user $user /d" $VESTA/data/queue/backup.pipe # Send notification -if [ "$notify" != 'no' ]; then +if [ -e "$BACKUP/$user.log" ]; then subj="$user → backup has been completed" email=$(get_user_value '$CONTACT') - echo -e "$msg" |$send_mail -s "$subj" $email + cat $BACKUP/$user.log #|$SENDMAIL -s "$subj" $email $notify + rm $BACKUP/$user.log fi # Logging diff --git a/bin/v-change-database-owner b/bin/v-change-database-owner index 274f7aad6..d84d8eb2d 100755 --- a/bin/v-change-database-owner +++ b/bin/v-change-database-owner @@ -80,7 +80,6 @@ $BIN/v-suspend-database $owner $database > /dev/null 2>&1 eval $db_data dump="$tmpdir/$database.$TYPE.sql" grants="$tmpdir/$database.$TYPE.$DBUSER" -send_mail='/bin/true' case $TYPE in mysql) dump_mysql_database ;; pgsql) dump_pgsql_database ;; diff --git a/bin/v-change-dns-domain-tpl b/bin/v-change-dns-domain-tpl index db68c94c7..b0304a48a 100755 --- a/bin/v-change-dns-domain-tpl +++ b/bin/v-change-dns-domain-tpl @@ -35,7 +35,7 @@ is_object_valid 'user' 'USER' "$user" is_object_unsuspended 'user' 'USER' "$user" is_object_valid 'dns' 'DOMAIN' "$domain" is_object_unsuspended 'dns' 'DOMAIN' "$domain" -is_dns_template_valid +is_dns_template_valid "$template" #----------------------------------------------------------# @@ -52,8 +52,31 @@ for nameserver in ${ns//,/ };do (( ++i)) done +# Reading template +template_data=$(cat $DNSTPL/$template.tpl) + +# Deleting unused nameservers +if [ -z "$ns3" ]; then + template_data=$(echo "$template_data" |grep -v %ns3%) +fi +if [ -z "$ns4" ]; then + template_data=$(echo "$template_data" |grep -v %ns4%) +fi +if [ -z "$ns5" ]; then + template_data=$(echo "$template_data" |grep -v %ns5%) +fi +if [ -z "$ns6" ]; then + template_data=$(echo "$template_data" |grep -v %ns6%) +fi +if [ -z "$ns7" ]; then + template_data=$(echo "$template_data" |grep -v %ns7%) +fi +if [ -z "$ns8" ]; then + template_data=$(echo "$template_data" |grep -v %ns8%) +fi + # Changing tpl -cat $DNSTPL/$template.tpl |\ +echo "$template_data" |\ sed -e "s/%ip%/$ip/g" \ -e "s/%domain_idn%/$domain_idn/g" \ -e "s/%domain%/$domain/g" \ diff --git a/bin/v-change-domain-owner b/bin/v-change-domain-owner index 66ab4ca35..c6be1c89b 100755 --- a/bin/v-change-domain-owner +++ b/bin/v-change-domain-owner @@ -1,6 +1,6 @@ #!/bin/bash -# info: change ip owner -# options: DOMAIN USER [IP] +# info: change domain owner +# options: DOMAIN USER # # The function of changing domain ownership. @@ -12,7 +12,6 @@ # Argument definition domain=$1 user=$2 -ip=$3 # Includes source $VESTA/func/ip.sh @@ -24,20 +23,13 @@ source $VESTA/conf/vesta.conf # Verifications # #----------------------------------------------------------# -check_args '2' "$#" 'DOMAIN USER [IP]' +check_args '2' "$#" 'DOMAIN USER' is_format_valid 'domain' 'user' is_object_valid 'user' 'USER' "$user" is_object_unsuspended 'user' 'USER' "$user" -if [ ! -z "$ip" ]; then - is_ip_valid - is_ip_avalable -fi - owner=$(v-search-domain-owner $domain) if [ -z "$owner" ]; then - echo "Error: domain $domain doesn't exist" - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST + check_result $E_NOTEXIST "domain $domain doesn't exist" fi if [ "$owner" = "$user" ]; then exit diff --git a/bin/v-change-fs-file-permission b/bin/v-change-fs-file-permission index 29e47babb..3e6ae6b54 100755 --- a/bin/v-change-fs-file-permission +++ b/bin/v-change-fs-file-permission @@ -28,7 +28,7 @@ if [ -z $homedir ]; then fi # Checking source file -if [ ! -f "$src_file" ]; then +if [ ! -fe "$src_file" ]; then echo "Error: source file doesn't exist $src_file" exit 3 fi @@ -41,11 +41,11 @@ if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then fi # Changing file permissions -sudo -u $user chmod $permissions "$src_file" >/dev/null 2>&1 +sudo -u $user chmod -R $permissions "$src_file" >/dev/null 2>&1 if [ $? -ne 0 ]; then echo "Error: access permission on $src_file was not changed" exit 3 fi # Exiting -exit +exit \ No newline at end of file diff --git a/bin/v-change-mail-account-password b/bin/v-change-mail-account-password index 80d0713b6..da6b788c5 100755 --- a/bin/v-change-mail-account-password +++ b/bin/v-change-mail-account-password @@ -44,7 +44,7 @@ is_password_valid #----------------------------------------------------------# # Generating hashed password -salt=$(gen_password "$PW_MATRIX" "8") +salt=$(generate_password "$PW_MATRIX" "8") md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)" if [[ "$MAIL_SYSTEM" =~ exim ]]; then diff --git a/bin/v-change-sys-ip-name b/bin/v-change-sys-ip-name index 8e77805c1..bf930096a 100755 --- a/bin/v-change-sys-ip-name +++ b/bin/v-change-sys-ip-name @@ -25,10 +25,8 @@ source $VESTA/conf/vesta.conf check_args '2' "$#" 'IP IP_NAME' is_format_valid 'ip' -if [ ! -z "$ip_name" ]; then - is_format_valid 'ip_name' -fi -is_ip_valid +is_format_valid 'ip_name' +is_ip_valid "$ip" #----------------------------------------------------------# diff --git a/bin/v-change-sys-ip-nat b/bin/v-change-sys-ip-nat index 3af6e7168..8f6815558 100755 --- a/bin/v-change-sys-ip-nat +++ b/bin/v-change-sys-ip-nat @@ -26,10 +26,8 @@ source $VESTA/conf/vesta.conf check_args '2' "$#" 'IP NAT_IP [RESTART]' is_format_valid 'ip' -if [ ! -z "$nat_ip" ]; then - is_format_valid 'nat_ip' -fi -is_ip_valid +is_format_valid 'nat_ip' +is_ip_valid "$ip" #----------------------------------------------------------# diff --git a/bin/v-change-sys-ip-owner b/bin/v-change-sys-ip-owner index 952b6ca12..5ea71c348 100755 --- a/bin/v-change-sys-ip-owner +++ b/bin/v-change-sys-ip-owner @@ -27,11 +27,10 @@ check_args '2' "$#" 'IP USER' is_format_valid 'ip' 'user' is_object_valid 'user' 'USER' "$user" is_object_unsuspended 'user' 'USER' "$user" -is_ip_valid +is_ip_valid "$ip" is_ip_key_empty '$U_WEB_DOMAINS' is_ip_key_empty '$U_SYS_USERS' - #----------------------------------------------------------# # Action # #----------------------------------------------------------# diff --git a/bin/v-change-sys-ip-status b/bin/v-change-sys-ip-status index 64c9513f5..ef48af7b7 100755 --- a/bin/v-change-sys-ip-status +++ b/bin/v-change-sys-ip-status @@ -25,7 +25,7 @@ source $VESTA/conf/vesta.conf check_args '2' "$#" 'IP IP_STATUS' is_format_valid 'ip' 'ip_status' -is_ip_valid +is_ip_valid "$ip" if [ "$ip_status" = "$(get_ip_value '$STATUS')" ]; then echo "Error: status $ip_status is already set" log_event "$E_EXISTS" "$ARGUMENTS" diff --git a/bin/v-change-user-package b/bin/v-change-user-package index 7f8feee31..bb0b21d88 100755 --- a/bin/v-change-user-package +++ b/bin/v-change-user-package @@ -40,51 +40,37 @@ is_package_avalable() { # Checking usage agains package limits if [ "$WEB_DOMAINS" != 'unlimited' ]; then if [ "$WEB_DOMAINS" -lt "$U_WEB_DOMAINS" ]; then - echo "Error: Package doesn't cover WEB_DOMAIN usage" - log_event "$E_LIMIT" "$ARGUMENTS" - exit $E_LIMIT + check_result $E_LIMIT "Package doesn't cover WEB_DOMAIN usage" fi fi if [ "$DNS_DOMAINS" ! = 'unlimited' ]; then if [ "$DNS_DOMAINS" -lt "$U_DNS_DOMAINS" ]; then - echo "Error: Package doesn't cover DNS_DOMAIN usage" - log_event "$E_LIMIT" "$ARGUMENTS" - exit $E_LIMIT + check_result $E_LIMIT "Package doesn't cover DNS_DOMAIN usage" fi fi if [ "$MAIL_DOMAINS" != 'unlimited' ]; then if [ "$MAIL_DOMAINS" -lt "$U_MAIL_DOMAINS" ]; then - echo "Error: Package doesn't cover MAIL_DOMAIN usage" - log_event "$E_LIMIT" "$ARGUMENTS" - exit $E_LIMIT + check_result $E_LIMIT "Package doesn't cover MAIL_DOMAIN usage" fi fi if [ "$DATABASES" != 'unlimited' ]; then if [ "$DATABASES" -lt "$U_DATABASES" ]; then - echo "Error: Package doesn't cover DATABASE usage" - log_event "$E_LIMIT" "$ARGUMENTS" - exit $E_LIMIT + check_result $E_LIMIT "Package doesn't cover DATABASE usage" fi fi if [ "$CRON_JOBS" != 'unlimited' ]; then if [ "$CRON_JOBS" -lt "$U_CRON_JOBS" ]; then - echo "Error: Package doesn't cover CRON usage" - log_event "$E_LIMIT" "$ARGUMENTS" - exit $E_LIMIT + check_result $E_LIMIT "Package doesn't cover CRON usage" fi fi if [ "$DISK_QUOTA" != 'unlimited' ]; then if [ "$DISK_QUOTA" -lt "$U_DISK" ]; then - echo "Error: Package doesn't cover DISK usage" - log_event "$E_LIMIT" "$ARGUMENTS" - exit $E_LIMIT + check_result $E_LIMIT "Package doesn't cover DISK usage" fi fi if [ "$BANDWIDTH" != 'unlimited' ]; then if [ "$BANDWIDTH" -lt "$U_BANDWIDTH" ]; then - echo "Error: Package doesn't cover BANDWIDTH usage" - log_event "$E_LIMIT" "$ARGUMENTS" - exit $E_LIMIT + check_result $E_LIMIT "Package doesn't cover BANDWIDTH usage" fi fi } diff --git a/bin/v-change-user-password b/bin/v-change-user-password index 196239bc3..a420502a1 100755 --- a/bin/v-change-user-password +++ b/bin/v-change-user-password @@ -43,7 +43,7 @@ md5=$(awk -v user=$user -F : 'user == $1 {print $2}' /etc/shadow) #----------------------------------------------------------# # Changing RKEY value -update_user_value "$user" '$RKEY' "$(gen_password)" +update_user_value "$user" '$RKEY' "$(generate_password)" update_user_value "$user" '$MD5' "$md5" # Logging diff --git a/bin/v-change-user-template b/bin/v-change-user-template index 7ba774fbb..5a3295352 100755 --- a/bin/v-change-user-template +++ b/bin/v-change-user-template @@ -35,11 +35,11 @@ is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# case $type in - WEB) is_web_template_valid; + WEB) is_web_template_valid $template; update_user_value "$user" '$WEB_TEMPLATE' "$template";; PROXY) is_proxy_template_valid $template; update_user_value "$user" '$PROXY_TEMPLATE' "$template";; - DNS) is_dns_template_valid; + DNS) is_dns_template_valid $template; update_user_value "$user" '$DNS_TEMPLATE' "$template";; *) check_args '1' '0' 'USER TYPE TEMPLATE' esac diff --git a/bin/v-change-web-domain-backend-tpl b/bin/v-change-web-domain-backend-tpl index 186ab136f..40b11df1f 100755 --- a/bin/v-change-web-domain-backend-tpl +++ b/bin/v-change-web-domain-backend-tpl @@ -35,7 +35,7 @@ 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_web_backend_template_valid $template +is_backend_template_valid $template #----------------------------------------------------------# diff --git a/bin/v-change-web-domain-ip b/bin/v-change-web-domain-ip index 8ca71f030..b3e19432f 100755 --- a/bin/v-change-web-domain-ip +++ b/bin/v-change-web-domain-ip @@ -11,9 +11,8 @@ # Argument definition user=$1 -domain=$(idn -t --quiet -u "$2" ) -domain_idn=$(idn -t --quiet -a "$domain") -new_domain=$(echo $3 |tr '[:upper:]' '[:lower:]') +domain=$2 +ip=$3 restart=$4 # Includes @@ -34,8 +33,7 @@ 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_ip_valid -is_ip_avalable +is_ip_valid "$ip" "$user" #----------------------------------------------------------# @@ -46,6 +44,12 @@ is_ip_avalable get_domain_values 'web' old=$(get_real_ip $IP) new=$ip +if [[ "$domain" = *[![:ascii:]]* ]]; then + domain_idn=$(idn -t --quiet -a $domain) +else + domain_idn=$domain +fi + # Replacing vhost replace_web_config "$WEB_SYSTEM" "$TPL.tpl" diff --git a/bin/v-change-web-domain-proxy-tpl b/bin/v-change-web-domain-proxy-tpl index 60b27017f..cb51169b9 100755 --- a/bin/v-change-web-domain-proxy-tpl +++ b/bin/v-change-web-domain-proxy-tpl @@ -48,7 +48,7 @@ is_proxy_template_valid $template # Parsing domain values get_domain_values 'web' -ip=$(get_real_ip $IP) +local_ip=$(get_real_ip $IP) # Delete old vhost del_web_config "$PROXY_SYSTEM" "$PROXY.tpl" diff --git a/bin/v-change-web-domain-tpl b/bin/v-change-web-domain-tpl index f844b7512..3366c313d 100755 --- a/bin/v-change-web-domain-tpl +++ b/bin/v-change-web-domain-tpl @@ -35,7 +35,7 @@ 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_web_template_valid +is_web_template_valid "$template" #----------------------------------------------------------# @@ -44,7 +44,7 @@ is_web_template_valid # Parsing domain values get_domain_values 'web' -ip=$(get_real_ip $IP) +local_ip=$(get_real_ip $IP) # Deleting domain del_web_config "$WEB_SYSTEM" "$TPL.tpl" @@ -53,7 +53,6 @@ if [ "$SSL" = 'yes' ]; then fi # Defining variables for new vhost config -TPL=$template prepare_web_domain_values add_web_config "$WEB_SYSTEM" "$TPL.tpl" if [ "$SSL" = 'yes' ]; then diff --git a/bin/v-delete-domain b/bin/v-delete-domain index f53478464..a315d3a87 100755 --- a/bin/v-delete-domain +++ b/bin/v-delete-domain @@ -35,7 +35,7 @@ is_object_unsuspended 'user' 'USER' "$user" # Working on Web domain if [ ! -z "$WEB_SYSTEM" ]; then - str=$(grep "DOMAIN='$domain'" $USER_DATA/web.conf |grep "SUSPENDED='no") + str=$(grep "DOMAIN='$domain'" $USER_DATA/web.conf) if [ ! -z "$str" ]; then domain_found='yes' $BIN/v-delete-web-domain $user $domain 'no' @@ -45,7 +45,7 @@ fi # Working on DNS domain if [ ! -z "$DNS_SYSTEM" ]; then - str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf |grep "SUSPENDED='no") + str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf) if [ ! -z "$str" ]; then domain_found='yes' $BIN/v-delete-dns-domain $user $domain 'no' @@ -55,7 +55,7 @@ fi # Working on Mail domain if [ ! -z "$MAIL_SYSTEM" ]; then - str=$(grep "DOMAIN='$domain'" $USER_DATA/mail.conf |grep "SUSPENDED='no") + str=$(grep "DOMAIN='$domain'" $USER_DATA/mail.conf) if [ ! -z "$str" ]; then domain_found='yes' $BIN/v-delete-mail-domain $user $domain @@ -65,9 +65,7 @@ fi # Checking domain search result if [ -z "$domain_found" ]; then - echo "Error: domain $domain doesn't exist" - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST + check_result $E_NOTEXISTS "domain $domain doesn't exist" fi # Restarting services diff --git a/bin/v-delete-sys-sftp-jail b/bin/v-delete-sys-sftp-jail index c48fd65f6..e04a15c06 100755 --- a/bin/v-delete-sys-sftp-jail +++ b/bin/v-delete-sys-sftp-jail @@ -63,12 +63,11 @@ fi if [ "$restart" = 'yes' ]; then subj="OpenSSH restart failed" email=$(grep CONTACT $VESTA/data/users/admin/user.conf |cut -f 2 -d \') - send_mail="$VESTA/web/inc/mail-wrapper.php" /usr/sbin/sshd -t >/dev/null 2>&1 if [ "$?" -ne 0 ]; then mail_text="OpenSSH can not be restarted. Please check config: \n\n$(/usr/sbin/sshd -t)" - echo -e "$mail_text" | $send_mail -s "$subj" $email + echo -e "$mail_text" |$SENDMAIL -s "$subj" $email else service ssh restart >/dev/null 2>&1 service sshd restart >/dev/null 2>&1 diff --git a/bin/v-delete-user b/bin/v-delete-user index 68c374b58..c452f0a0e 100755 --- a/bin/v-delete-user +++ b/bin/v-delete-user @@ -38,52 +38,37 @@ fi # Action # #----------------------------------------------------------# -# Checking web system is enabled +# Deleting web domains if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then $BIN/v-unsuspend-web-domains $user $restart $BIN/v-delete-web-domains $user $restart - rv="$?" - if [ "$rv" -ne '0' ]; then - exit $rv - fi + check_result "$?" "web domain deletion failed" fi -# Checking dns system is enabled +# Deleting dns domains if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS_SYSTEM" != 'no' ]; then $BIN/v-unsuspend-dns-domains $user $restart $BIN/v-delete-dns-domains $user $restart - rv="$?" - if [ "$rv" -ne '0' ]; then - exit $rv - fi + check_result "$?" "dns domain deletion failed" fi -# Checking mail system is enabled +# Deleting mail domains if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then $BIN/v-unsuspend-mail-domains $user $BIN/v-delete-mail-domains $user - rv="$?" - if [ "$rv" -ne '0' ]; then - exit $rv - fi + check_result "$?" "mail domain deletion failed" fi -# Checking db system is enabled +# Deleting databases if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then $BIN/v-unsuspend-databases $user $BIN/v-delete-databases $user - rv="$?" - if [ "$rv" -ne '0' ]; then - exit $rv - fi + check_result "$?" "database deletion failed" fi -# Checking ip +# Releasing user ips $BIN/v-delete-user-ips "$user" -rv="$?" -if [ "$rv" -ne '0' ]; then - exit $rv -fi +check_result "$?" "user ip release failed" # Deleteing user pipes sed -i "/ $user$/d" $VESTA/data/queue/disk.pipe @@ -96,14 +81,13 @@ fi # Deleting system user /usr/sbin/userdel -f $user >> /dev/null 2>&1 - -if [ "$?" != 0 ]; then +if [ $? -ne 0 ]; then sed -i "/^$user:/d" /etc/passwd sed -i "/^$user:/d" /etc/shadow fi /usr/sbin/groupdel $user >> /dev/null 2>&1 -if [ "$?" != 0 ]; then +if [ $? -ne 0 ]; then sed -i "/^$user:/d" /etc/group fi diff --git a/bin/v-delete-web-domain b/bin/v-delete-web-domain index a44bc63d0..878ea472c 100755 --- a/bin/v-delete-web-domain +++ b/bin/v-delete-web-domain @@ -17,15 +17,6 @@ user=$1 domain=$2 restart=$3 -# Additional argument formatting -if [[ "$domain" =~ [[:upper:]] ]]; then - domain=$(echo "$domain" |tr '[:upper:]' '[:lower:]') -fi -domain_idn="$domain" -if [[ "$domain" = *[![:ascii:]]* ]]; then - domain_idn=$(idn -t --quiet -a $tmp_alias) -fi - # Includes source $VESTA/func/main.sh source $VESTA/func/domain.sh @@ -57,6 +48,10 @@ fi # Parsing domain values get_domain_values 'web' +domain_idn="$domain" +if [[ "$domain" = *[![:ascii:]]* ]]; then + domain_idn=$(idn -t --quiet -a $domain) +fi local_ip=$(get_real_ip $IP) # Deleting domain from web.conf diff --git a/bin/v-delete-web-domain-alias b/bin/v-delete-web-domain-alias index 8c3cccd8e..2a2180610 100755 --- a/bin/v-delete-web-domain-alias +++ b/bin/v-delete-web-domain-alias @@ -35,11 +35,8 @@ is_object_unsuspended 'user' 'USER' "$user" is_object_valid 'web' 'DOMAIN' "$domain" is_object_unsuspended 'web' 'DOMAIN' "$domain" get_domain_values 'web' -ip=$(get_real_ip $IP) -if [ -z "$(echo $ALIAS | tr ',' '\n' | grep ^$dom_alias$)" ]; then - echo "Error: alias $dom_alias doesn't exist" - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST +if [ -z "$(echo $ALIAS |tr ',' '\n' |grep ^$dom_alias$)" ]; then + check_result $E_NOTEXIST "alias $dom_alias doesn't exist" fi @@ -48,6 +45,7 @@ fi #----------------------------------------------------------# # Preparing domain values for the template substitution +local_ip=$(get_real_ip $IP) ALIAS=$(echo "$ALIAS" |\ sed -e "s/,/\n/g"|\ sed -e "s/^$dom_alias$//g"|\ diff --git a/bin/v-generate-ssl-cert b/bin/v-generate-ssl-cert index 4ae895820..80912d789 100755 --- a/bin/v-generate-ssl-cert +++ b/bin/v-generate-ssl-cert @@ -12,7 +12,6 @@ # Argument definition domain=$1 domain=$(echo $domain |sed -e 's/\.*$//g' -e 's/^\.*//g') -domain=$(echo $domain |tr '[:upper:]' '[:lower:]') domain_alias=$domain email=$2 country=$3 @@ -70,6 +69,15 @@ is_format_valid 'domain_alias' 'format' # Action # #----------------------------------------------------------# +if [[ "$domain" = *[![:ascii:]]* ]]; then + domain_idn=$(idn -t --quiet -a $domain) +else + domain_idn=$domain +fi +if [[ "$email" = *[![:ascii:]]* ]]; then + email=$(idn -t --quiet -a $email) +fi + # Create temporary work directory workdir=$(mktemp -d) cd $workdir @@ -79,7 +87,7 @@ openssl genrsa $KEY_SIZE > $domain.key 2>/dev/null # Generate the CSR subj="/C=$country/ST=$state/localityName=$city/O=$org" -subj="$subj/organizationalUnitName=$org_unit/commonName=$domain" +subj="$subj/organizationalUnitName=$org_unit/commonName=$domain_idn" subj="$subj/emailAddress=$email" if [ -z "$aliases" ]; then openssl req -sha256\ @@ -87,7 +95,7 @@ if [ -z "$aliases" ]; then -batch \ -subj "$subj" \ -key $domain.key \ - -out $domain.csr >/dev/null 2>&1 + -out $domain.csr #>/dev/null 2>&1 else for alias in $(echo $domain,$aliases |tr ',' '\n' |sort -u); do dns_aliases="${dns_aliases}DNS:$alias," @@ -118,6 +126,7 @@ openssl x509 -req -sha256 \ -signkey $domain.key \ -out $domain.crt >/dev/null 2>&1 + # Listing certificates if [ -e "$domain.crt" ]; then crt=$(cat $domain.crt | sed ':a;N;$!ba;s/\n/\\n/g' ) diff --git a/bin/v-list-dns-template b/bin/v-list-dns-template index f82473c21..2697c1750 100755 --- a/bin/v-list-dns-template +++ b/bin/v-list-dns-template @@ -82,7 +82,7 @@ csv_list() { check_args '1' "$#" 'TEMPLATE [FORMAT]' is_format_valid 'template' -is_dns_template_valid +is_dns_template_valid "$template" #----------------------------------------------------------# diff --git a/bin/v-list-sys-users b/bin/v-list-sys-users index 7cbf7f629..cd297338b 100755 --- a/bin/v-list-sys-users +++ b/bin/v-list-sys-users @@ -18,7 +18,7 @@ source $VESTA/func/main.sh # JSON list function json_list() { - objects=$(echo "$users" |wc -l) + objects=$(grep @ /etc/passwd |wc -l) i=1 echo '[' while read user; do diff --git a/bin/v-list-user-ips b/bin/v-list-user-ips index cacae76c1..dad6f6f8c 100755 --- a/bin/v-list-user-ips +++ b/bin/v-list-user-ips @@ -66,7 +66,7 @@ plain_list() { # CSV list function csv_list() { echo "IP,OWNER,STATUS,NAME,NAT" - for IP in $(ls $VESTA/data/ips/); do + for IP in $ips; do source $VESTA/data/ips/$IP echo "$IP,$OWNER,$STATUS,$NAME,$NAT" done @@ -88,10 +88,10 @@ is_object_valid 'user' 'USER' "$user" # Defining fileds to select owner='admin' -owner_ips=$(grep -A 1 "OWNER='$owner'" $VESTA/data/ips/*) +owner_ips=$(grep -A 1 -H "OWNER='$owner'" $VESTA/data/ips/*) owner_ips=$(echo "$owner_ips" |grep "STATUS='shared'") owner_ips=$(echo "$owner_ips" |cut -f 7 -d / |cut -f 1 -d -) -user_ips=$(grep "OWNER='$user'" $VESTA/data/ips/*) +user_ips=$(grep -H "OWNER='$user'" $VESTA/data/ips/*) user_ips=$(echo "$user_ips" |cut -f 7 -d / |cut -f 1 -d :) ips=$(echo -e "$user_ips\n$owner_ips" |sort -u |sed "/^$/d") fields='$IP $OWNER $STATUS $NAME $NAT' diff --git a/bin/v-restart-cron b/bin/v-restart-cron index 232e359c2..8fcaf2bec 100755 --- a/bin/v-restart-cron +++ b/bin/v-restart-cron @@ -14,14 +14,13 @@ source $VESTA/func/main.sh source $VESTA/conf/vesta.conf send_email_report() { - send_mail="$VESTA/web/inc/mail-wrapper.php" email=$(grep CONTACT $VESTA/data/users/admin/user.conf) email=$(echo "$email" | cut -f 2 -d "'") tmpfile=$(mktemp) subj="$(hostname): $CRON_SYSTEM restart failed" service $CRON_SYSTEM configtest >> $tmpfile 2>&1 service $CRON_SYSTEM restart >> $tmpfile 2>&1 - cat $tmpfile | $send_mail -s "$subj" $email + cat $tmpfile |$SENDMAIL -s "$subj" $email rm -f $tmpfile } @@ -50,7 +49,7 @@ if [ $? -ne 0 ]; then service $CRON_SYSTEM restart >/dev/null 2>&1 if [ $? -ne 0 ]; then send_email_report - exit $E_RESTART + check_result $E_RESTART "$CRON_SYSTEM restart failed" fi fi diff --git a/bin/v-restart-dns b/bin/v-restart-dns index 9945f32e9..8e84d66ef 100755 --- a/bin/v-restart-dns +++ b/bin/v-restart-dns @@ -19,15 +19,13 @@ send_email_report() { else dns_conf='/etc/bind/named.conf' fi - - send_mail="$VESTA/web/inc/mail-wrapper.php" email=$(grep CONTACT $VESTA/data/users/admin/user.conf) email=$(echo "$email" | cut -f 2 -d "'") tmpfile=$(mktemp) subj="$(hostname): $DNS_SYSTEM restart failed" /usr/sbin/named-checkconf $dns_conf >> $tmpfile 2>&1 service $DNS_SYSTEM restart >> $tmpfile 2>&1 - cat $tmpfile | $send_mail -s "$subj" $email + cat $tmpfile |$SENDMAIL -s "$subj" $email rm -f $tmpfile } @@ -56,8 +54,7 @@ if [ $? -ne 0 ]; then service $DNS_SYSTEM restart >/dev/null 2>&1 if [ $? -ne 0 ]; then send_email_report - echo "Error: $DNS_SYSTEM restart failed" - exit $E_RESTART + check_result $E_RESTART "$DNS_SYSTEM restart failed" fi fi diff --git a/bin/v-restart-ftp b/bin/v-restart-ftp index ab0c78abb..9ab2d7714 100755 --- a/bin/v-restart-ftp +++ b/bin/v-restart-ftp @@ -14,14 +14,13 @@ source $VESTA/func/main.sh source $VESTA/conf/vesta.conf send_email_report() { - send_mail="$VESTA/web/inc/mail-wrapper.php" email=$(grep CONTACT $VESTA/data/users/admin/user.conf) email=$(echo "$email" | cut -f 2 -d "'") tmpfile=$(mktemp) subj="$(hostname): $FTP_SYSTEM restart failed" service $FTP_SYSTEM configtest >> $tmpfile 2>&1 service $FTP_SYSTEM restart >> $tmpfile 2>&1 - cat $tmpfile | $send_mail -s "$subj" $email + cat $tmpfile |$SENDMAIL -s "$subj" $email rm -f $tmpfile } @@ -48,8 +47,7 @@ fi service $FTP_SYSTEM restart >/dev/null 2>&1 if [ $? -ne 0 ]; then send_email_report - echo "Error: $FTP_SYSTEM restart failed" - exit $E_RESTART + check_result $E_RESTART "$FTP_SYSTEM restart failed" fi # Update restart queue diff --git a/bin/v-restart-mail b/bin/v-restart-mail index fc8f339f9..2784cd3d1 100755 --- a/bin/v-restart-mail +++ b/bin/v-restart-mail @@ -14,14 +14,13 @@ source $VESTA/func/main.sh source $VESTA/conf/vesta.conf send_email_report() { - send_mail="$VESTA/web/inc/mail-wrapper.php" email=$(grep CONTACT $VESTA/data/users/admin/user.conf) email=$(echo "$email" | cut -f 2 -d "'") tmpfile=$(mktemp) subj="$(hostname): $MAIL_SYSTEM restart failed" service $MAIL_SYSTEM configtest >> $tmpfile 2>&1 service $MAIL_SYSTEM restart >> $tmpfile 2>&1 - cat $tmpfile | $send_mail -s "$subj" $email + cat $tmpfile |$SENDMAIL -s "$subj" $email rm -f $tmpfile } @@ -48,8 +47,7 @@ fi service $MAIL_SYSTEM restart >/dev/null 2>&1 if [ $? -ne 0 ]; then send_email_report - echo "Error: $MAIL_SYSTEM restart failed" - exit $E_RESTART + check_result $E_RESTART "$MAIL_SYSTEM restart failed" fi # Update restart queue diff --git a/bin/v-restart-proxy b/bin/v-restart-proxy index 31fcddc74..79776ce71 100755 --- a/bin/v-restart-proxy +++ b/bin/v-restart-proxy @@ -14,14 +14,13 @@ source $VESTA/func/main.sh source $VESTA/conf/vesta.conf send_email_report() { - send_mail="$VESTA/web/inc/mail-wrapper.php" email=$(grep CONTACT $VESTA/data/users/admin/user.conf) email=$(echo "$email" | cut -f 2 -d "'") tmpfile=$(mktemp) subj="$(hostname): $PROXY_SYSTEM restart failed" service $PROXY_SYSTEM configtest >> $tmpfile 2>&1 service $PROXY_SYSTEM restart >> $tmpfile 2>&1 - cat $tmpfile | $send_mail -s "$subj" $email + cat $tmpfile |$SENDMAIL -s "$subj" $email rm -f $tmpfile } @@ -48,8 +47,7 @@ fi service $PROXY_SYSTEM restart >/dev/null 2>&1 if [ $? -ne 0 ]; then send_email_report - echo "Error: $PROXY_SYSTEM restart failed" - exit $E_RESTART + check_result $E_RESTART "$PROXY_SYSTEM restart failed" fi # Update restart queue diff --git a/bin/v-restart-service b/bin/v-restart-service index d539c1a39..5df3e2559 100755 --- a/bin/v-restart-service +++ b/bin/v-restart-service @@ -30,13 +30,13 @@ check_args '1' "$#" 'SERVICE' if [ "$service" != "iptables" ]; then service $service restart >/dev/null 2>&1 if [ $? -ne 0 ]; then - exit $E_RESTART + check_result $E_RESTART "$service restart failed" fi else $BIN/v-stop-firewall $BIN/v-update-firewall if [ $? -ne 0 ]; then - exit $E_RESTART + check_result $E_RESTART "$service restart failed" fi fi diff --git a/bin/v-restart-web b/bin/v-restart-web index 78c1e7a57..4b62a8a0b 100755 --- a/bin/v-restart-web +++ b/bin/v-restart-web @@ -14,14 +14,13 @@ source $VESTA/func/main.sh source $VESTA/conf/vesta.conf send_email_report() { - send_mail="$VESTA/web/inc/mail-wrapper.php" email=$(grep CONTACT $VESTA/data/users/admin/user.conf) email=$(echo "$email" | cut -f 2 -d "'") tmpfile=$(mktemp) subj="$(hostname): $WEB_SYSTEM restart failed" service $WEB_SYSTEM configtest >> $tmpfile 2>&1 service $WEB_SYSTEM restart >> $tmpfile 2>&1 - cat $tmpfile | $send_mail -s "$subj" $email + cat $tmpfile |$SENDMAIL -s "$subj" $email rm -f $tmpfile } @@ -62,8 +61,7 @@ if [ "$rc" -ne 0 ]; then service $WEB_SYSTEM restart >/dev/null 2>&1 if [ $? -ne 0 ]; then send_email_report - echo "Error: $WEB_SYSTEM restart failed" - exit $E_RESTART + check_result $E_RESTART "$WEB_SYSTEM restart failed" fi fi diff --git a/bin/v-restart-web-backend b/bin/v-restart-web-backend index b2e747ef0..54ba8daa5 100755 --- a/bin/v-restart-web-backend +++ b/bin/v-restart-web-backend @@ -14,14 +14,13 @@ source $VESTA/func/main.sh source $VESTA/conf/vesta.conf send_email_report() { - send_mail="$VESTA/web/inc/mail-wrapper.php" email=$(grep CONTACT $VESTA/data/users/admin/user.conf) email=$(echo "$email" | cut -f 2 -d "'") tmpfile=$(mktemp) subj="$(hostname): $WEB_BACKEND restart failed" service $WEB_BACKEND configtest >> $tmpfile 2>&1 service $WEB_BACKEND restart >> $tmpfile 2>&1 - cat $tmpfile | $send_mail -s "$subj" $email + cat $tmpfile |$SENDMAIL -s "$subj" $email rm -f $tmpfile } @@ -48,8 +47,7 @@ fi service $WEB_BACKEND restart >/dev/null 2>&1 if [ $? -ne 0 ]; then send_email_report - echo "Error: $WEB_BACKEND restart failed" - exit $E_RESTART + check_result $E_RESTART "$WEB_BACKEND restart failed" fi # Update restart queue diff --git a/bin/v-restore-user b/bin/v-restore-user index d2a7eae5b..1c5de3652 100755 --- a/bin/v-restore-user +++ b/bin/v-restore-user @@ -25,7 +25,7 @@ notify=${9-no} # Define backup dir if [ -z "$BACKUP" ]; then - BACKUP=/home/backup/ + BACKUP=/backup fi # Includes @@ -38,10 +38,15 @@ source $VESTA/conf/vesta.conf # Check backup function is_backup_valid() { - if [ ! -e "$BACKUP/$backup" ]; then - echo "Error: backup doesn't exist" - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST + if [ ! -e "$1" ]; then + check_result $E_NOTEXIST "backup $1 doesn't exist" + fi +} + +# Check backup ownership function +is_backup_available() { + if ! [[ $2 =~ ^$1.[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].tar$ ]]; then + check_result $E_FORBIDEN "permission denied" fi } @@ -53,170 +58,145 @@ is_backup_valid() { args_usage='USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIR] [NOTIFY]' check_args '2' "$#" "$args_usage" is_format_valid 'user' 'backup' -is_backup_valid -is_backup_available +is_backup_valid "$BACKUP/$backup" +is_backup_available "$user" "$backup" #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Define email wrapper -send_mail="$VESTA/web/inc/mail-wrapper.php" - -# Check user +# Checking user existance on the server check_user=$(is_object_valid 'user' 'USER' "$user") if [ -z "$check_user" ]; then is_object_unsuspended 'user' 'USER' "$user" - - if [ "$notify" != 'no' ]; then - subj="$user → restore failed" - email=$(get_user_value '$CONTACT') - else - subj="$user → restore failed" - email=$(grep CONTACT $VESTA/data/users/admin/user.conf |cut -f2 -d \') - fi -else - # Set flag for user creation - create_user="yes" - - # Set notification email and subject subj="$user → restore failed" + email=$(get_user_value '$CONTACT') +else + create_user="yes" email=$(grep CONTACT $VESTA/data/users/admin/user.conf | cut -f2 -d \') fi -# Check disk usage + +# Checking avaiable disk space disk_usage=$(df $BACKUP |tail -n1 |tr ' ' '\n' |grep % |cut -f 1 -d %) if [ "$disk_usage" -ge "$BACKUP_DISK_LIMIT" ]; then - rm -rf $tmpdir - echo "Not enough disk space to run restore" | $send_mail -s "$subj" $email - echo "Error: Not enough disk space" + echo "Error: Not enough disk space" |$SENDMAIL -s "$subj" $email $notify sed -i "/ $user /d" $VESTA/data/queue/backup.pipe - log_event "$E_DISK" "$ARGUMENTS" - exit $E_DISK + check_result $E_DISK "Not enough disk space" fi -# Check load average -la=$(cat /proc/loadavg | cut -f 1 -d ' ' | cut -f 1 -d '.') +# Checking load average +la=$(cat /proc/loadavg |cut -f 1 -d ' ' |cut -f 1 -d '.') i=0 while [ "$la" -ge "$BACKUP_LA_LIMIT" ]; do - echo "$(date "+%F %T") Load Average $la" - echo + echo -e "$(date "+%F %T") Load Average $la" sleep 60 if [ "$i" -ge "15" ]; then - echo "LoadAverage $i is above threshold" |$send_mail -s "$subj" $email - echo "Error: LA is too high" + la_error="LoadAverage $la is above threshold" + echo "Error: $la_error" |$SENDMAIL -s "$subj" $email $notify sed -i "/ $user /d" $VESTA/data/queue/backup.pipe - log_event "$E_LA" "$ARGUMENTS" - exit $E_LA + check_result $E_LA "$la_error" fi + la=$(cat /proc/loadavg |cut -f 1 -d ' ' |cut -f 1 -d '.') (( ++i)) done # Creating temporary directory tmpdir=$(mktemp -p $BACKUP -d) if [ "$?" -ne 0 ]; then - echo "Can't create tmp dir $tmpdir" | $send_mail -s "$subj" $email - echo "Error: can't create tmp dir" - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST + echo "Can't create tmp dir $tmpdir" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_NOTEXIST" "can't create tmp dir" fi -# User +# Restoring user account if [ "$create_user" = 'yes' ]; then - echo "-- USER --" - msg="$msg\n-- USER --" + echo "-- USER --" |tee $tmpdir/restore.log + echo -e "$(date "+%F %T") $user" |tee -a $tmpdir/restore.log - echo -e "$(date "+%F %T") $user" - msg="$msg\n$(date "+%F %T") $user" - - # unpack user container + # Unpacking user container tar xf $BACKUP/$backup -C $tmpdir ./vesta if [ "$?" -ne 0 ]; then - echo "Error: can't unpack user contaner" - echo "Can't unpack user contaner" | $send_mail -s "$subj" $email rm -rf $tmpdir - exit $E_PARSING + echo "Can't unpack user contaner" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "can't unpack user contaner" fi - # Restore cron records + # Restoring user.conf mkdir $USER_DATA cp $tmpdir/vesta/user.conf $USER_DATA/ + cp -r $tmpdir/vesta/ssl $USER_DATA/ >/dev/null 2>&1 + cp $tmpdir/vesta/backup-excludes.conf $USER_DATA/ >/dev/null 2>&1 - # Rebuild cron + # Rebuilding user rebuild_user_conf - - echo - msg="$msg\n" fi -# WEB -if [ "$web" != 'no' ]; then - echo "-- WEB --" - msg="$msg\n-- WEB --" +# Unpacking pam container +tar xf $BACKUP/$backup -C $tmpdir ./pam +if [ "$?" -ne 0 ]; then + rm -rf $tmpdir + echo "Can't unpack PAM contaner" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "can't unpack PAM contaner" +fi +old_user=$(cut -f 1 -d : $tmpdir/pam/passwd) +old_uid=$(cut -f 3 -d : $tmpdir/pam/passwd) +new_uid=$(grep "^$user:" /etc/passwd |cut -f 3 -d :) - # Unpack pam container - tar xf $BACKUP/$backup -C $tmpdir ./pam - if [ "$?" -ne 0 ]; then - echo "Error: can't unpack PAM contaner" - echo "Can't unpack PAM contaner" | $send_mail -s "$subj" $email - rm -rf $tmpdir - exit $E_PARSING + +# Restoring web domains +if [ "$web" != 'no' ] && [ ! -z "$WEB_SYSTEM" ]; then + echo -e "\n-- WEB --" |tee -a $tmpdir/restore.log + + # Creating web domain restore list + backup_domains=$(tar -tf $BACKUP/$backup |grep "^./web") + backup_domains=$(echo "$backup_domains" |grep domain_data.tar.gz) + backup_domains=$(echo "$backup_domains" |cut -f 3 -d /) + if [ -z "$web" ] || [ "$web" = '*' ]; then + domains="$backup_domains" + else + echo "$web" |tr ',' '\n' > $tmpdir/selected.txt + domains=$(echo "$backup_domains" |egrep -f $tmpdir/selected.txt) fi - # Get user id - old_uid=$(cut -f 3 -d : $tmpdir/pam/passwd) - new_uid=$(grep "^$user:" /etc/passwd | cut -f 3 -d :) + # Restoring web domain + for domain in $domains; do + echo -e "$(date "+%F %T") $domain" |tee -a $tmpdir/restore.log - # Create domain list - domain_list=$(tar -tf $BACKUP/$backup | grep "^./web" |\ - grep domain_data.tar.gz | cut -f 3 -d '/') - if [ ! -z "$web" ]; then - dom_include_list=$(mktemp) - for domain_include in ${web//,/ }; do - echo "^$domain_include$" >> $dom_include_list - done - domain_list=$(echo "$domain_list" | egrep -f $dom_include_list ) - rm -f $dom_include_list - fi - - for domain in $domain_list; do - echo -e "$(date "+%F %T") $domain" - msg="$msg\n$(date "+%F %T") $domain" - - # unpack domain container - tar xf $BACKUP/$backup -C $tmpdir ./web/$domain - if [ "$?" -ne 0 ]; then - echo "Error: can't unpack $domain web contaner" - echo "Can't unpack $domain web contaner" |\ - $send_mail -s "$subj" $email - rm -rf $tmpdir - exit $E_PARSING - fi - - # Restore domain config + # Checking domain existance check_config=$(grep "DOMAIN='$domain'" $USER_DATA/web.conf) if [ -z "$check_config" ]; then - - # Parse domain config - eval $(cat $tmpdir/web/$domain/vesta/web.conf) - - # Check if domain new check_new=$(is_domain_new 'web' $domain) if [ ! -z "$check_new" ]; then - echo "Error: web domain $domain belongs to another user" - echo "Web domain $domain belongs to another user" |\ - $send_mail -s "$subj" $email rm -rf $tmpdir - log_event "$E_EXISTS" "$ARGUMENTS" - exit $E_EXISTS + error="$domain belongs to another user" + echo "$error" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "$error" fi + fi - # Check if domain alias is new + # Unpacking domain container + tar xf $BACKUP/$backup -C $tmpdir ./web/$domain + if [ "$?" -ne 0 ]; then + rm -rf $tmpdir + error="Can't unpack $domain web container" + echo "$error" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "$error" + fi + + # Restoring web.conf + if [ -z "$check_config" ]; then + eval $(cat $tmpdir/web/$domain/vesta/web.conf) + + # Deleting conflicting aliases for dom_alias in ${ALIAS//,/ }; do check_new=$(is_domain_new 'web' $dom_alias) if [ ! -z "$check_new" ]; then - # Delete conflicting alias ALIAS=$(echo "$ALIAS" |\ sed "s/,/\n/g"|\ sed "s/^$dom_alias$//g"|\ @@ -225,73 +205,54 @@ if [ "$web" != 'no' ]; then fi done - # Check ip address - check_ip=$(is_ip_valid $IP) - if [ -z "$check_ip" ]; then - check_ip=$(is_ip_avalable $IP) - fi + # Checking ip address + check_ip=$(is_ip_valid $IP $user) if [ ! -z "$check_ip" ]; then - IP=$(get_user_ip $user) - if [ -z "$IP" ]; then - echo "Error: no avaiable IP address" - echo "No available IP address" |\ - $send_mail -s "$subj" $email - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST - fi - echo "$IP" > $tmpdir/ip_mapping.$domain + local_ip='' + get_user_ip $user + old_ip=$IP + IP=$ip fi - # Check web template - check_tpl=$(is_web_template_valid) - if [ ! -e "$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl" ]; then - TPL="default" - if [ ! -e "$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl" ]; then - echo "Error: no avaiable web template" - echo "No available web template" |\ - $send_mail -s "$subj" $email - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST - fi + # Checking web template + check_tpl=$(is_web_template_valid $TPL) + if [ ! -z "$check_tpl" ]; then + TPL='default' fi - # Check proxy template - if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then - if [ ! -e "$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl" ]; then - PROXY="default" - if [ ! -e "$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl" ]; then - echo "Error: no avaiable proxy template" - echo "No available proxy tpl" |\ - $send_mail -s "$subj" $email - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST - fi - fi + # Checking proxy template + check_proxy_tpl=$(is_proxy_template_valid $PROXY) + if [ ! -z "$check_proxy_tpl" ]; then + PROXY='default' fi - # Convert ftp user + # Checking backend template + check_backend_tpl=$(is_backend_template_valid $BACKEND) + if [ ! -z "$check_proxy_tpl" ]; then + BACKEND='default' + fi + + # Converting ftp users if [ ! -z "$FTP_USER" ]; then - FTP_USER=$(echo "$FTP_USER" | cut -f 2,3,4,5,6,7 -d '_') + FTP_USER=$(echo "$FTP_USER" |sed -e "s/${old_user}_//") FTP_USER="${user}_${FTP_USER}" fi - # Convert stats user + # Converting stats users if [ ! -z "$STATS_USER" ]; then - STATS_USER=$(echo "$STATS_USER" | cut -f 2,3,4,5,6,7 -d '_') + STATS_USER=$(echo "$STATS_USER" |sed -e "s/${old_user}_//") STATS_USER="${user}_${STATS_USER}" fi - # Set default backend template - if [ ! -z "$WEB_BACKEND" ]; then - if [ ! -z "$BACKEND" ]; then - if [ ! -e "$WEBTPL/$WEB_BACKEND/$BACKEND.tpl" ]; then - BACKEND='default' - fi - else - BACKEND='default' - fi + # Copying ssl certificates + if [ "$SSL" = 'yes' ]; then + for crt in $(ls $tmpdir/web/$domain/conf |grep ssl); do + crt=$(echo "$crt" |sed "s/ssl.//") + cp -f $tmpdir/web/$domain/conf/ssl.$crt $USER_DATA/ssl/$crt + done fi + # Concatenating web.conf keys str="DOMAIN='$domain' IP='$IP' IP6='$IP6' ALIAS='$ALIAS'" str="$str TPL='$TPL' SSL='$SSL' SSL_HOME='$SSL_HOME'" str="$str FTP_USER='$FTP_USER' FTP_MD5='$FTP_MD5'" @@ -302,537 +263,360 @@ if [ "$web" != 'no' ]; then str="$str TIME='$(date +%T)' DATE='$(date +%F)'" echo $str >> $USER_DATA/web.conf - # Copy ssl certificate - if [ "$SSL" = 'yes' ]; then - for crt in $(ls $tmpdir/web/$domain/conf |grep ssl); do - crt=$(echo "$crt" |sed "s/ssl.//") - cp -f $tmpdir/web/$domain/conf/ssl.$crt $USER_DATA/ssl/$crt - done - fi - - # Rebuild backend + # Rebuilding backend if [ ! -z "$WEB_BACKEND" ]; then $BIN/v-add-web-domain-backend $user $domain $BACKEND fi - # Rebuild web config + # Rebuilding vhost rebuild_web_domain_conf - - # Adding vhost - web_conf="/etc/$WEB_SYSTEM/conf.d/vesta.conf" - tmp_conf="$HOMEDIR/$user/conf/web/tmp_$WEB_SYSTEM.conf" - conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf" - cat $tmp_conf >> $conf - rm -f $tmp_conf - web_include=$(grep "$conf" $web_conf) - if [ -z "$web_include" ] && [ "$WEB_SYSTEM" != 'nginx' ]; then - echo "Include $conf" >> $web_conf - fi - if [ -z "$web_include" ] && [ "$WEB_SYSTEM" = 'nginx' ]; then - echo "include $conf;" >> $web_conf - fi - - # Adding SSL vhost - if [ "$SSL" = 'yes' ]; then - tmp_conf="$HOMEDIR/$user/conf/web/tmp_s$WEB_SYSTEM.conf" - conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf" - cat $tmp_conf >> $conf - rm -f $tmp_conf - fi - ssl_include=$(grep "$conf" $web_conf) - if [ -z "$ssl_include" ] && [ "$WEB_SYSTEM" != 'nginx' ]; then - echo "Include $conf" >> $web_conf - fi - if [ -z "$ssl_include" ] && [ "$WEB_SYSTEM" = 'nginx' ]; then - echo "include $conf;" >> $web_conf - fi - - # Proxy - if [ ! -z "$PROXY_SYSTEM" ]; then - # Adding proxy vhost - proxy_conf="/etc/$PROXY_SYSTEM/conf.d/vesta.conf" - if [ ! -z "$PROXY" ]; then - tmp_conf="$HOMEDIR/$user/conf/web/tmp_$PROXY_SYSTEM.conf" - conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf" - cat $tmp_conf >> $conf - rm -f $tmp_conf - fi - proxy_include=$(grep "$conf" $proxy_conf) - if [ -z "$proxy_include" ]; then - echo "include $conf;" >> $proxy_conf - fi - - # Adding SSL proxy vhost - if [ ! -z "$PROXY" ] && [ "$SSL" = 'yes' ]; then - tmp_conf="$HOMEDIR/$user/conf/web/tmp_s$PROXY_SYSTEM.conf" - conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf" - cat $tmp_conf >> $conf - rm -f $tmp_conf - proxy_include=$(grep "$conf" $proxy_conf) - if [ -z "$proxy_include" ]; then - echo "include $conf;" >> $proxy_conf - fi - fi - fi fi - # Restore data + # Restoring web domain data tar -xzpf $tmpdir/web/$domain/domain_data.tar.gz \ -C $HOMEDIR/$user/web/$domain/ if [ "$?" -ne 0 ]; then - echo "Error: can't unpack $domain data tarball" - echo "Can't can't unpack $domain data tarball" |\ - $send_mail -s "$subj" $email rm -rf $tmpdir - exit $E_PARSING + error="can't unpack $domain data tarball" + echo "$error" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "$error" fi - # Fix for tar < 1.24 + # Applying Fix for tar < 1.24 find $HOMEDIR/$user/web/$domain -type d \ -exec chown -h $user:$user {} \; - # ReChown files if uid differs + # Re-chowning files if uid differs if [ "$old_uid" -ne "$new_uid" ]; then find $HOMEDIR/$user/web/$domain/ -user $old_uid \ -exec chown -h $user:$user {} \; fi - done - # Add user to traff queue + # Adding user to traff queue sed -i "/ $user /d" $VESTA/data/queue/traffic.pipe echo "$BIN/v-update-web-domains-traff $user" >>\ $VESTA/data/queue/traffic.pipe - # Restart WEB + # Restarting web server $BIN/v-restart-web - if [ $? -ne 0 ]; then - exit $E_RESTART - fi - - # Restart Proxy + check_result $? "Web restart failed" if [ ! -z "$PROXY_SYSTEM" ]; then $BIN/v-restart-proxy - if [ $? -ne 0 ]; then - exit $E_RESTART - fi + check_result $? "Proxy restart failed" fi - - echo - msg="$msg\n" fi -# DNS -if [ "$dns" != 'no' ]; then - echo "-- DNS --" - msg="$msg\n-- DNS --" +# Restoring dns domains +if [ "$dns" != 'no' ] && [ ! -z "$DNS_SYSTEM" ]; then + echo -e "\n-- DNS --" |tee -a $tmpdir/restore.log - # Create domain list - domain_list=$(tar -tf $BACKUP/$backup | grep "^./dns" |\ - grep dns.conf | cut -f 3 -d '/') - if [ ! -z "$dns" ]; then - dom_include_list=$(mktemp) - for domain_include in ${dns//,/ }; do - echo "^$domain_include$" >> $dom_include_list - done - domain_list=$(echo "$domain_list" | egrep -f $dom_include_list ) - rm -f $dom_include_list + # Creating dns domain restore list + backup_domains=$(tar -tf $BACKUP/$backup |grep "^./dns") + backup_domains=$(echo "$backup_domains" |grep domain_data.tar.gz) + backup_domains=$(echo "$backup_domains" |cut -f 3 -d /) + if [ -z "$dns" ] || [ "$dns" = '*' ]; then + domains="$backup_domains" + else + echo "$dns" |tr ',' '\n' > $tmpdir/selected.txt + domains=$(echo "$backup_domains" |egrep -f $tmpdir/selected.txt) fi - for domain in $domain_list; do - echo -e "$(date "+%F %T") $domain" - msg="$msg\n$(date "+%F %T") $domain" + # Restoring dns domain + for domain in $domains; do + echo -e "$(date "+%F %T") $domain" |tee -a $tmpdir/restore.log - # unpack domain container - tar xf $BACKUP/$backup -C $tmpdir ./dns/$domain - if [ "$?" -ne 0 ]; then - echo "Error: can't unpack $domain dns contaner" - echo "Can't unpack $domain dns contaner" |\ - $send_mail -s "$subj" $email - rm -rf $tmpdir - exit $E_PARSING - fi - - # Restore domain config + # Checking domain existance check_config=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf) if [ -z "$check_config" ]; then - - # Parse domain config - eval $(cat $tmpdir/dns/$domain/vesta/dns.conf) - - # Check if domain new check_new=$(is_domain_new 'dns' $domain) if [ ! -z "$check_new" ]; then - echo "Error: dns domain $domain belongs to another user" - echo "DNS domain $domain belongs to another user" |\ - $send_mail -s "$subj" $email rm -rf $tmpdir - log_event "$E_EXISTS" "$ARGUMENTS" - exit $E_EXISTS + error="$domain belongs to another user" + echo "$error" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "$error" + fi + fi + + # Unpacking domain container + tar xf $BACKUP/$backup -C $tmpdir ./dns/$domain + if [ "$?" -ne 0 ]; then + rm -rf $tmpdir + error="Can't unpack $domain dns container" + echo "$error" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "$error" + fi + + # Restoring dns.conf + if [ -z "$check_config" ]; then + eval $(cat $tmpdir/dns/$domain/vesta/dns.conf) + + # Checking ip address + check_ip=$(is_ip_valid $IP $user) + if [ ! -z "$check_ip" ]; then + local_ip='' + get_user_ip $user + old_ip=$IP + IP=$ip fi - # Check ip address - if [ -e "$tmpdir/ip_mapping.$domain" ]; then - OLD=$IP - IP=$(cat $tmpdir/ip_mapping.$domain) - sed -i "s/$OLD/$IP/g" $tmpdir/dns/$domain/vesta/$domain.conf - else - check_ip=$(is_ip_valid $IP) - if [ ! -z "$check_ip" ]; then - if [ -z "$IP" ]; then - IP=$(get_user_ip $user) - fi - fi - fi - if [ -z "$IP" ]; then - echo "Error: no avaiable IP address" - echo "No available IP address" | $send_mail -s "$subj" $email - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST - fi - - # Check dns template - check_tpl=$(is_dns_template_valid) + # Checking dns template + check_tpl=$(is_dns_template_valid $TPL) if [ ! -z "$check_tpl" ]; then - templates=$(ls -t $VESTA/data/templates/dns/ |\ - grep '\.tpl' |\ - cut -f 1 -d '.') - if [ ! -z "$(echo $templates |grep default)" ]; then - TPL=$(echo "$templates" |grep default |head -n1) - else - TPL=$("$templates" |head -n1) - fi - - if [ -z "$TPL" ]; then - echo "Error: no avaiable dns template" - echo "No available dns template" |\ - $send_mail -s "$subj" $email - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST - fi + TPL='default' fi + # Concatenating dns.conf keys str="DOMAIN='$domain' IP='$IP' TPL='$TPL' TTL='$TTL' EXP='$EXP'" str="$str SOA='$SOA' RECORDS='$RECORDS' SUSPENDED='no'" str="$str TIME='$(date +%T)' DATE='$(date +%F)'" echo $str >> $USER_DATA/dns.conf fi - # Restore dns records + # Restoring dns records cp -f $tmpdir/dns/$domain/vesta/$domain.conf $USER_DATA/dns/ - # Rebuild dns config + # Rebuilding dns domain rebuild_dns_domain_conf done - # Restart DNS + # Restarting DNS $BIN/v-restart-dns - if [ $? -ne 0 ]; then - exit $E_RESTART - fi - - echo - msg="$msg\n" + check_result $? "DNS restart failed" fi -# MAIL -if [ "$mail" != 'no' ]; then - echo "-- MAIL --" - msg="$msg\n-- MAIL --" +# Restoring mail domains +if [ "$mail" != 'no' ] && [ ! -z "$MAIL_SYSTEM" ]; then + echo -e "\n-- MAIL --" |tee -a $tmpdir/restore.log - # Unpack pam container - tar xf $BACKUP/$backup -C $tmpdir ./pam - if [ "$?" -ne 0 ]; then - echo "Error: can't unpack PAM contaner" - echo "Can't unpack PAM contaner" | $send_mail -s "$subj" $email - rm -rf $tmpdir - exit $E_PARSING + # Creating mail domain restore list + backup_domains=$(tar -tf $BACKUP/$backup |grep "^./mail") + backup_domains=$(echo "$backup_domains" |grep domain_data.tar.gz) + backup_domains=$(echo "$backup_domains" |cut -f 3 -d /) + if [ -z "$mail" ] || [ "$mail" = '*' ]; then + domains="$backup_domains" + else + echo "$mail" |tr ',' '\n' > $tmpdir/selected.txt + domains=$(echo "$backup_domains" |egrep -f $tmpdir/selected.txt) fi - # Get user id - old_uid=$(cut -f 3 -d : $tmpdir/pam/passwd) - new_uid=$(grep "^$user:" /etc/passwd | cut -f 3 -d :) - - # Create domain list - domain_list=$(tar -tf $BACKUP/$backup | grep "^./mail" |\ - grep mail.conf | cut -f 3 -d '/') - if [ ! -z "$mail" ]; then - dom_include_list=$(mktemp) - for domain_include in ${mail//,/ }; do - echo "^$domain_include$" >> $dom_include_list - done - domain_list=$(echo "$domain_list" | egrep -f $dom_include_list ) - rm -f $dom_include_list - fi - - for domain in $domain_list; do - echo -e "$(date "+%F %T") $domain" - msg="$msg\n$(date "+%F %T") $domain" - - # unpack domain container - tar xf $BACKUP/$backup -C $tmpdir ./mail/$domain - if [ "$?" -ne 0 ]; then - echo "Error: can't unpack $domain mail contaner" - echo "Can't can't unpack $domain mail contaner" |\ - $send_mail -s "$subj" $email - rm -rf $tmpdir - exit $E_PARSING - fi - - # Restore domain config - domain_idn=$(idn -t --quiet -a "$domain") + # Restoring dns domain + for domain in $domains; do + echo -e "$(date "+%F %T") $domain" |tee -a $tmpdir/restore.log + # Checking domain existance check_config=$(grep "DOMAIN='$domain'" $USER_DATA/mail.conf) if [ -z "$check_config" ]; then - - # Parse domain config - eval $(cat $tmpdir/mail/$domain/vesta/mail.conf) - - # Check if domain new check_new=$(is_domain_new 'mail' $domain) if [ ! -z "$check_new" ]; then - echo "Error: mail domain $domain belongs to another user" - echo "Mail domain $domain belongs to another user" |\ - $send_mail -s "$subj" $email rm -rf $tmpdir - log_event "$E_EXISTS" "$ARGUMENTS" - exit $E_EXISTS + error="$domain belongs to another user" + echo "$error" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "$error" fi - - str="DOMAIN='$domain' ANTIVIRUS='$ANTIVIRUS' ANTISPAM='$ANTISPAM'" - str="$str DKIM='$DKIM' ACCOUNTS='$ACCOUNTS' U_DISK='$U_DISK'" - str="$str CATCHALL='$CATCHALL' SUSPENDED='no'" - str="$str TIME='$(date +%T)' DATE='$(date +%F)'" - echo $str >> $USER_DATA/mail.conf fi - # Restore DKIM + # Unpacking domain container + tar xf $BACKUP/$backup -C $tmpdir ./mail/$domain + if [ "$?" -ne 0 ]; then + rm -rf $tmpdir + error="Can't unpack $domain mail container" + echo "$error" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "$error" + fi + + # Restoring mail.conf + if [ -z "$check_config" ]; then + cat $tmpdir/mail/$domain/vesta/mail.conf >> $USER_DATA/mail.conf + fi + + # Restoring DKIM if [ -e "$tmpdir/mail/$domain/vesta/$domain.pem" ]; then cp -f $tmpdir/mail/$domain/vesta/$domain.pem $USER_DATA/mail/ cp -f $tmpdir/mail/$domain/vesta/$domain.pub $USER_DATA/mail/ fi - # Restore email accounts + # Restoring email accounts cp -f $tmpdir/mail/$domain/vesta/$domain.conf $USER_DATA/mail/ - # Rebuild mail config + # Rebuilding mail config rebuild_mail_domain_conf - # Restore emails + # Restoring emails if [ -e "$tmpdir/mail/$domain/accounts.tar.gz" ]; then tar -xzpf $tmpdir/mail/$domain/accounts.tar.gz \ -C $HOMEDIR/$user/mail/$domain_idn/ if [ "$?" -ne 0 ]; then - echo "Error: can't unpack $domain mail account tarball" - echo "Can't unpack $domain mail account tarball" |\ - $send_mail -s "$subj" $email rm -rf $tmpdir - exit $E_PARSING + error="Can't unpack $domain mail account container" + echo "$error" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "$error" fi - # ReChown files if uid differs + # Re-chowning files if uid differs if [ "$old_uid" -ne "$new_uid" ]; then find $HOMEDIR/$user/mail/$domain_idn -user $old_uid \ -exec chown -h $user:mail {} \; fi - fi done - echo - msg="$msg\n" fi -# DB -if [ "$db" != 'no' ]; then - echo "-- DB --" - msg="$msg\n-- DB --" +# Restoring databases +if [ "$db" != 'no' ] && [ ! -z "$DB_SYSTEM" ]; then + echo -e "\n-- DB --" |tee -a $tmpdir/restore.log - # Create domain list - db_list=$(tar -tf $BACKUP/$backup | grep "^./db" |\ - grep db.conf | cut -f 3 -d '/' |sort -u) - if [ ! -z "$db" ]; then - db_include_list=$(mktemp) - for db_include in ${db//,/ }; do - echo "^$db_include$" >> $db_include_list - done - db_list=$(echo "$db_list" | egrep -f $db_include_list ) - rm -f $db_include_list + # Creating database restore list + backup_databases=$(tar -tf $BACKUP/$backup |grep "^./db") + backup_databases=$(echo "$backup_databases" |grep db.conf) + backup_databases=$(echo "$backup_databases" |cut -f 3 -d / |sort -u) + if [ -z "$db" ] || [ "$db" = '*' ]; then + databases="$backup_databases" + else + echo "$db" |tr ',' '\n' > $tmpdir/selected.txt + databases=$(echo "$backup_databases" |egrep -f $tmpdir/selected.txt) fi - for db in $db_list; do + # Restoring database + for database in $databases; do + echo -e "$(date "+%F %T") $database" |tee -a $tmpdir/restore.log - # unpack db container - tar xf $BACKUP/$backup -C $tmpdir ./db/$db + # Checking database existance + check_config=$(grep "DB='$db'" $USER_DATA/db.conf) + + # Unpacking database container + tar xf $BACKUP/$backup -C $tmpdir ./db/$database if [ "$?" -ne 0 ]; then - echo "Error: can't unpack $db database contaner" - echo "Can't unpack $db database contaner" |\ - $send_mail -s "$subj" $email rm -rf $tmpdir - exit $E_PARSING + error="Can't unpack $database database container" + echo "$error" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "$error" fi - # Restore domain config - check_config=$(grep "DB='$db'" $USER_DATA/db.conf) + # Restore database config if [ -z "$check_config" ]; then - - # Parse database config - eval $(cat $tmpdir/db/$db/vesta/db.conf) - - # Convert database & database user - DB=$(echo "$DB" | cut -f 2,3,4,5,6,7 -d '_') + eval $(cat $tmpdir/db/$database/vesta/db.conf) + DB=$(echo "$DB" |sed -e "s/${old_user}_//") DB="${user}_${DB}" - DBUSER=$(echo "$DBUSER" | cut -f 2,3,4,5,6,7 -d '_') + DBUSER=$(echo "$DBUSER" |sed -e "s/${old_user}_//") DBUSER="${user}_${DBUSER}" - str="DB='$DB' DBUSER='$DBUSER' MD5='$MD5' HOST='$HOST'" str="$str TYPE='$TYPE' CHARSET='$CHARSET' U_DISK='$U_DISK'" str="$str SUSPENDED='no' TIME='$(date +%T)' DATE='$(date +%F)'" echo $str >> $USER_DATA/db.conf else - eval $(grep "DB='$db'" $USER_DATA/db.conf) + eval $(grep "DB='$database'" $USER_DATA/db.conf) fi - echo -e "$(date "+%F %T") $DB" - msg="$msg\n$(date "+%F %T") $DB" + # Unziping database dump + gzip -d $tmpdir/db/$database/$database.*.sql.gz - # Unzip database dump - gzip -d $tmpdir/db/$db/$db.*.sql.gz - - # Get database values - get_database_values - - # Rebuild db + # Importing database dump + database_dump="$tmpdir/db/$database/$database.$TYPE.sql" case $TYPE in mysql) rebuild_mysql_database; - import_mysql_database $tmpdir/db/$db/$db.$TYPE.sql ;; + import_mysql_database $database_dump ;; pgsql) rebuild_pgsql_database; - import_pgsql_database $tmpdir/db/$db/$db.$TYPE.sql ;; + import_pgsql_database $database_dump ;; esac done - echo - msg="$msg\n" fi -# Cron -if [ "$cron" != 'no' ]; then - echo "-- CRON --" - msg="$msg\n-- CRON --" +# Restoring cron jobs +if [ "$cron" != 'no' ] && [ ! -z "CRON_SYSTEM" ]; then + echo -e "\n-- CRON --" |tee -a $tmpdir/restore.log - # unpack cron container + # Unpacking cron container tar xf $BACKUP/$backup -C $tmpdir ./cron if [ "$?" -ne 0 ]; then - echo "Error: can't unpack cron contaner" - echo "Can't unpack cron contaner" | $send_mail -s "$subj" $email rm -rf $tmpdir - exit $E_PARSING + error="Can't unpack cron container" + echo "$error" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "$error" fi - cron_record=$(wc -l $tmpdir/cron/cron.conf |cut -f 1 -d' ') - if [ "$cron_record" -eq 1 ]; then - echo -e "$(date "+%F %T") $cron_record record" - msg="$msg\n$(date "+%F %T") $cron_record record" + jobs=$(wc -l $tmpdir/cron/cron.conf |cut -f 1 -d' ') + if [ "$jobs" -eq 1 ]; then + echo -e "$(date "+%F %T") $jobs cron job" |tee -a $tmpdir/restore.log else - echo -e "$(date "+%F %T") $cron_record records" - msg="$msg\n$(date "+%F %T") $cron_record records" + echo -e "$(date "+%F %T") $jobs cron jobs"|tee -a $tmpdir/restore.log fi - # Restore cron records + # Restoring cron jobs cp $tmpdir/cron/cron.conf $USER_DATA/cron.conf - # Rebuild cron + # Rebuilding cron jobs sync_cron_jobs - # Restart cron + # Restarting cron $BIN/v-restart-cron - if [ $? -ne 0 ]; then - exit $E_RESTART - fi - - echo - msg="$msg\n" + check_result $? "CRON restart failed" fi -# Restore user directories +# Restoring user files and directories if [ "$udir" != 'no' ]; then - echo "-- USER DIR --" - msg="$msg\n-- USER DIR --" + echo -e "\n-- USER FILES --" |tee -a $tmpdir/restore.log - # unpack user dir container + # Unpacking user dir container if [ ! -z "$(tar -tf $BACKUP/$backup |grep './user_dir')" ]; then - # Unpack pam container - tar xf $BACKUP/$backup -C $tmpdir ./pam - if [ "$?" -ne 0 ]; then - echo "Error: can't unpack PAM contaner" - echo "Can't unpack PAM contaner" | $send_mail -s "$subj" $email - rm -rf $tmpdir - exit $E_PARSING + # Creating user dir restore list + backup_dirs=$(tar -tf $BACKUP/$backup |grep "^./user_dir") + backup_dirs=$(echo "$backup_dirs" |grep tar.gz) + backup_dirs=$(echo "$backup_dirs" |cut -f 3 -d /) + backup_dirs=$(echo "$backup_dirs" |sed "s/.tar.gz//") + if [ -z "$udir" ] || [ "$udir" = '*' ]; then + user_dirs="$backup_dirs" + else + echo "$udir" |tr ',' '\n' > $tmpdir/selected.txt + user_dirs=$(echo "$backup_dirs" |egrep -f $tmpdir/selected.txt) fi - # Get user id - old_uid=$(cut -f 3 -d : $tmpdir/pam/passwd) - new_uid=$(grep "^$user:" /etc/passwd | cut -f 3 -d :) - - # Create user dir list - udir_list=$(tar -tf $BACKUP/$backup | grep "^./user_dir" |\ - grep tar.gz | cut -f 3 -d '/' | sed "s/.tar.gz//") - - if [ ! -z "$udir" ]; then - udir_include_list=$(mktemp) - for udir_include in ${udir//,/ }; do - echo "^$udir_include$" >> $udir_include_list - done - udir_list=$(echo "$udir_list" | egrep -f $udir_include_list ) - rm -f $udir_include_list - fi - - for user_dir in $udir_list; do - echo -e "$(date "+%F %T") $user_dir" - msg="$msg\n$(date "+%F %T") $user_dir" - - # unpack user_dir container + for user_dir in $user_dirs; do + echo -e "$(date "+%F %T") $user_dir" |tee -a $tmpdir/restore.log tar xf $BACKUP/$backup -C $tmpdir ./user_dir/$user_dir.tar.gz if [ "$?" -ne 0 ]; then - echo "Error: can't unpack $user_dir user dir contaner" - echo "Can't unpack $user_dir user dir contaner" |\ - $send_mail -s "$subj" $email - rm -rf $tmpdir - exit $E_PARSING + error="can't unpack $user_dir user dir contaner" + echo "$error" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "$error" fi tar xzf $tmpdir/user_dir/$user_dir.tar.gz -C $HOMEDIR/$user if [ "$?" -ne 0 ]; then - echo "Error: can't unpack $user_dir user dir contaner" - echo "Can't unpack $user_dir user dir contaner" |\ - $send_mail -s "$subj" $email - rm -rf $tmpdir - exit $E_PARSING + error="can't unpack $user_dir user dir contaner" + echo "$error" |$SENDMAIL -s "$subj" $email $notify + sed -i "/ $user /d" $VESTA/data/queue/backup.pipe + check_result "$E_PARSING" "$error" fi - # ReChown files if uid differs + # Re-chowning files if uid differs if [ "$old_uid" -ne "$new_uid" ]; then find $HOMEDIR/$user/$user_dir -user $old_uid \ -exec chown -h $user:$user {} \; fi done fi - echo - msg="$msg\n" fi -# Remove temporary data +# Sending mail notification +subj="$user → restore has been completed" +cat $tmpdir/restore.log |$SENDMAIL -s "$subj" $email $notify + +# Deleting temporary data rm -rf $tmpdir -# Clean restore queue +# Cleaning restore queue sed -i "/v-restore-user $user /d" $VESTA/data/queue/backup.pipe -# Send notification -if [ "$notify" != 'no' ]; then - subj="$user → restore has been completed" - email=$(get_user_value '$CONTACT') - echo -e "$msg" | $send_mail -s "$subj" $email -fi - #----------------------------------------------------------# # Vesta # diff --git a/bin/v-suspend-web-domain b/bin/v-suspend-web-domain index 387ff759d..c31796046 100755 --- a/bin/v-suspend-web-domain +++ b/bin/v-suspend-web-domain @@ -43,7 +43,7 @@ is_object_unsuspended 'web' 'DOMAIN' "$domain" # Parsing domain values get_domain_values 'web' SUSPENDED='yes' -ip=$(get_real_ip $IP) +local_ip=$(get_real_ip $IP) # Preparing domain values for the template substitution prepare_web_domain_values diff --git a/bin/v-unsuspend-web-domain b/bin/v-unsuspend-web-domain index c1821fc39..3b21248e3 100755 --- a/bin/v-unsuspend-web-domain +++ b/bin/v-unsuspend-web-domain @@ -41,7 +41,7 @@ is_object_suspended 'web' 'DOMAIN' "$domain" # Parsing domain values get_domain_values 'web' SUSPENDED='no' -ip=$(get_real_ip $IP) +local_ip=$(get_real_ip $IP) # Preparing domain values for the template substitution prepare_web_domain_values diff --git a/bin/v-update-dns-templates b/bin/v-update-dns-templates index 1db87781c..31361d001 100755 --- a/bin/v-update-dns-templates +++ b/bin/v-update-dns-templates @@ -25,7 +25,7 @@ source $VESTA/conf/vesta.conf tmpdir=$(mktemp -d --dry-run) mkdir $tmpdir cd $tmpdir -wget http://c.vestacp.com/$VERSION/rhel/templates.tar.gz -q +wget http://c.vestacp.com/rhel/7/templates.tar.gz -q if [ "$?" -ne 0 ]; then echo "Error: can't download template.tar.gz" log_event "$E_CONNECT" "$ARGUMENTS" diff --git a/bin/v-update-user-backup-exclusions b/bin/v-update-user-backup-exclusions index 9a7a4a1d7..c4b913267 100755 --- a/bin/v-update-user-backup-exclusions +++ b/bin/v-update-user-backup-exclusions @@ -19,9 +19,7 @@ source $VESTA/conf/vesta.conf is_file_available() { if [ ! -e "$vfile" ]; then - echo "Error: file $vfile doesn't exist" - log_event "$E_NOTEXIST" "$ARGUMENTS" - exit $E_NOTEXIST + check_result $E_NOTEXIST "file $vfile doesn't exist" fi } @@ -29,9 +27,7 @@ is_file_valid() { exclude="[!$#&;()\]" vcontent=$(cat $vfile) if [[ "$vcontent" =~ $exclude ]]; then - echo "Error: invalid characters in the exlusion list" - log_event "$E_INVALID" "$ARGUMENTS" - exit $E_INVALID + check_result $E_INVALID "invalid characters in the exlusion list" fi } diff --git a/bin/v-update-user-backups b/bin/v-update-user-backups deleted file mode 100755 index 4125a6bbb..000000000 --- a/bin/v-update-user-backups +++ /dev/null @@ -1,278 +0,0 @@ -#!/bin/bash -# info: update user backups -# options: USER -# -# The function rescan backup directory and updates backup database. - - -#----------------------------------------------------------# -# Variable&Function # -#----------------------------------------------------------# - -# Includes -source $VESTA/func/main.sh -source $VESTA/conf/vesta.conf - -# Argument definition -user=$1 -type="${2-$BACKUP_SYSTEM}" - -# Defining tar parser function -get_backup_info() { - backup=$1 - backup_type="$2" - - backup_name=$(basename $backup ) - backup_date=$(echo $backup_name |cut -f 2 -d '.' ) - backup_time=$(stat --printf=%y $backup |cut -f 2 -d ' ' |cut -f 1 -d '.') - backup_size=$(du -sm $backup |cut -f 1 ) - backup_data=$(tar -tf $backup) - - vst_data=$(echo "$backup_data" |grep "^./vesta/" |grep -v "^./vesta/$") - if [ -z "$vst_data" ]; then - vst='' - else - vst='yes' - fi - - pam_data=$(echo "$backup_data" |grep "^./pam/" |grep -v "^./pam/$") - if [ -z "$pam_data" ]; then - pam='' - else - pam='yes' - fi - - web_data=$(echo "$backup_data" |grep "^./web/" |grep -v "^./web/$" |sort) - if [ -z "$web_data" ]; then - web='' - else - i=1 - for domain in $web_data; do - domain="$(basename $domain |sed 's/.tar.gz$//')" - if [ "$i" -eq 1 ]; then - web="$domain" - i=2 - else - web="$web,$domain" - fi - done - fi - - dns_data=$(echo "$backup_data" |grep "^./dns/" |grep ".db$" |sort) - if [ -z "$dns_data" ]; then - dns='' - else - i=1 - for domain in $dns_data; do - domain="$(basename $domain |sed 's/.db$//')" - if [ "$i" -eq 1 ]; then - dns="$domain" - i=2 - else - dns="$dns,$domain" - fi - done - fi - - mail_data=$(echo "$backup_data"|grep "^./mail/"|grep -v "^./mail/$"|sort) - if [ -z "$mail_data" ]; then - ml='' - else - i=1 - for domain in $mail_data; do - domain="$(basename $domain |sed 's/.tar.gz$//')" - if [ "$i" -eq 1 ]; then - ml="$domain" - i=2 - else - ml="$ml,$domain" - fi - done - fi - - db_data=$(echo "$backup_data"|grep "^./db/"|grep ".sql.gz$"|sort) - if [ -z "$db_data" ]; then - db='' - else - i=1 - for dbase in $db_data; do - dbase=$(basename $dbase |sed "s/.\(my\|pg\)sql.sql.gz$//") - if [ "$i" -eq 1 ]; then - db="$dbase" - i=2 - else - db="$db,$dbase" - fi - done - fi - - ssl_data=$(echo "$backup_data"|grep "^./ssl/"|grep ".crt$"|sort) - if [ -z "$ssl_data" ]; then - ssl='' - else - i=1 - for certificate in $ssl_data; do - certificate=$(basename $certificate |sed "s/.crt$//") - if [ "$i" -eq 1 ]; then - ssl="$certificate" - i=2 - else - ssl="$ssl,$certificate" - fi - done - fi - - cron_data=$(echo "$backup_data" |grep "^./cron/" |grep -v "^./cron/$") - if [ -z "$cron_data" ]; then - cron='' - else - cron='yes' - fi - - echo -n "DATE='$backup_date' TIME='$backup_time' RUNTIME='0'" - echo -n " SIZE='$backup_size' TYPE='$backup_type' VESTA='$vst' PAM='$pam'" - echo " WEB='$web' DNS='$dns' MAIL='$ml' DB='$db' SSL='$ssl' CRON='$cron'" -} - -# Defining ftp command function -ftpc() { - ftp -n $HOST $PORT <> $tmp_file - done -fi - -# Checking ftp -if [ "$type" = 'ftp' ]; then - tmpdir=$(mktemp -p $BACKUP -d) - ftmpdir=$(basename $tmpdir) - init_ftp_variables - check_ftp_connection - backups=$(ftpc ls|awk '{print $9}'|grep "^$user.") - - for backup in $backups; do - cd $tmpdir - if [ ! -z "$(ftpc "get $backup")" ]; then - echo "Error: FTP transfer error" - log_event "$E_FTP" "$ARGUMENTS" - exit $E_FTP - fi - get_backup_info $tmpdir/$backup $type >> $tmp_file - rm -f $tmpdir/$backup - done - rm -rf $tmpdir -fi - -# Checking both local and ftp -if [ "$type" = 'ftp,local' ] || [ "$type" = 'local,ftp' ]; then - - tmpdir=$(mktemp -p $BACKUP -d) - ftmpdir=$(basename $tmpdir) - init_ftp_variables - check_ftp_connection - ftp_backups=$(ftpc ls|awk '{print $9}'|grep "^$user.") - local_backups=$(ls $BACKUP/ |grep "^$user." |sort) - backups=$(echo -e "$local_backups\n$ftp_backups" |\ - sort |uniq -c | awk '{print $1" "$2}') - - for backup in $(echo "$backups"|grep "^1 "|cut -f 2 -d ' '); do - check_ftp=$(echo $ftp_backups|grep -w $backup) - if [ ! -z "$check_ftp" ]; then - cd $tmpdir - if [ ! -z "$(ftpc "get $backup")" ]; then - echo "Error: FTP transfer error" - log_event "$E_FTP" "$ARGUMENTS" - exit $E_FTP - fi - get_backup_info $tmpdir/$backup ftp >> $tmp_file - rm -f $tmpdir/$backup - else - get_backup_info $BACKUP/$backup local >> $tmp_file - fi - done - - for backup in $(echo "$backups"|grep "^2 "|cut -f 2 -d ' '); do - get_backup_info $BACKUP/$backup $type >> $tmp_file - done - rm -rf $tmpdir -fi - -# Checking if there was any output -if [ -e "$tmp_file" ]; then - cat $tmp_file | sort > $USER_DATA/backup.conf - rm $tmp_file -else - rm $USER_DATA/backup.conf - touch $USER_DATA/backup.conf -fi - - -#----------------------------------------------------------# -# Vesta # -#----------------------------------------------------------# - -# Logging -log_event "$OK" "$ARGUMENTS" - -exit diff --git a/bin/v-update-web-domain-stat b/bin/v-update-web-domain-stat index b03bb8fc7..56dfc93af 100755 --- a/bin/v-update-web-domain-stat +++ b/bin/v-update-web-domain-stat @@ -43,9 +43,7 @@ get_domain_values 'web' # Checking config config="$HOMEDIR/$user/conf/web/$STATS.$domain.conf" if [ ! -e "$config" ]; then - echo "Error: Parsing error" - log_event "$E_PARSING" "$ARGUMENTS" - exit $E_PARSING + check_result $E_NOTEXISTS "$config doesn't exist" fi # Checking statistics directory