Serghey Rodin 14 лет назад
Родитель
Сommit
fb40168aa3

+ 8 - 13
bin/v_add_user

@@ -17,15 +17,12 @@ package=${4-default}
 fname=$5
 lname=$6
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
 is_user_free() {
-    # Parsing domain values
     check_sysuser=$(cut -f 1 -d : /etc/passwd | grep -w "$user" )
-
-    # Checking result
     if [ ! -z "$check_sysuser" ] || [ -e "$USER_DATA" ]; then
         echo "Error: user $user exist"
         log_event "$E_EXISTS" "$EVENT"
@@ -38,16 +35,13 @@ is_user_free() {
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '3' "$#" 'user password email [package] [fname] [lname]'
+validate_format 'user' 'password' 'email' 'package'
+if [ ! -z "$fname" ]; then
+    validate_format 'fname' 'lname'
+fi
 
-# Checking argument format
-validate_format 'user' 'password' 'email' 'package' 'fname' 'lname'
-
-# Checking user
 is_user_free "$user"
-
-# Checking package
 is_package_valid "$package"
 
 
@@ -75,7 +69,6 @@ echo "$password" | /usr/bin/passwd "$user" --stdin &>/dev/null
 
 # Building directory tree
 mkdir $HOMEDIR/$user/conf
-chmod 751 $HOMEDIR/$user/conf/web
 
 if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
     mkdir $HOMEDIR/$user/conf/web
@@ -206,6 +199,7 @@ U_MAIL_ACCOUNTS='0'
 U_DATABASES='0'
 U_CRON_JOBS='0'
 U_BACKUPS='0'
+TIME='$TIME'
 DATE='$DATE'" > $USER_DATA/user.conf
 chmod 660 $USER_DATA/user.conf
 
@@ -215,7 +209,8 @@ if [ "$user" != 'admin' ]; then
 fi
 
 # Hiding password
-EVENT="$DATE $SCRIPT $user ***** $email $package $fname $lname"
+EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
+EVENT="$EVENT ARGUMENTS='$user ***** $email $package $fname $lname'"
 
 # Logging
 log_event "$OK" "$EVENT"

+ 2 - 11
bin/v_add_user_backup

@@ -12,7 +12,7 @@
 # Argument defenition
 user=$1
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -21,19 +21,10 @@ source $VESTA/func/shared.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '1' "$#" 'user'
-
-# Checking argument format
 validate_format 'user'
-
-# Checking backup system is enabled
-is_system_enabled 'BACKUP_SYSTEM'
-
-# Checking user
+is_system_enabled "$BACKUP_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user backups
 is_backup_enabled
 
 

+ 2 - 2
bin/v_add_web_domain_cgi

@@ -17,7 +17,7 @@ user=$1
 domain=$(idn -t --quiet -u "$2" )
 domain_idn=$(idn -t --quiet -a "$domain")
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
@@ -70,7 +70,7 @@ fi
 # Update config value
 update_object_value 'web' 'DOMAIN' "$domain" '$CGI' 'yes'
 
-# Adding task to the vesta pipe
+# Restart web server
 $BIN/v_restart_web "$EVENT"
 
 # Logging

+ 2 - 2
bin/v_add_web_domain_nginx

@@ -19,7 +19,7 @@ default_extentions="jpg,jpeg,gif,png,ico,css,zip,tgz,gz,rar,bz2,doc,xls,exe,\
 pdf,ppt,txt,tar,wav,bmp,rtf,js,mp3,avi,mpeg,html,htm"
 extentions=${4-$default_extentions}
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
@@ -93,7 +93,7 @@ fi
 update_object_value 'web' 'DOMAIN' "$domain" '$NGINX' "$NGINX"
 update_object_value 'web' 'DOMAIN' "$domain" '$NGINX_EXT' "$extentions"
 
-# Adding task to the vesta pipe
+# Restart web server
 $BIN/v_restart_web "$EVENT"
 
 log_history "$EVENT"

+ 25 - 63
bin/v_backup_user

@@ -12,7 +12,7 @@
 # Argument defenition
 user=$1
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
@@ -23,36 +23,23 @@ source $VESTA/func/db.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '1' "$#" 'user'
-
-# Checking argument format
 validate_format 'user'
-
-# Checking backup system is enabled
-is_system_enabled 'BACKUP_SYSTEM'
-
-# Checking user
+is_system_enabled "$BACKUP_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user backups
+is_object_unsuspended 'user' 'USER' "$user"
 is_backup_enabled
-
-# Checking load averages
 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
-
     sleep 60
-
     if [ "$i" -ge "15" ]; then
         echo "Error: LA is too high"
-        log_event 'debug' "$E_LA $EVENT"
+        log_event "$E_LA" "$EVENT"
         exit $E_LA
     fi
-
     (( ++i))
 done
 
@@ -76,8 +63,6 @@ echo
 echo "1.0" > $tmpdir/backup_version
 echo "$VERSION" > $tmpdir/vesta_version
 
-
-
 # Vesta
 echo "-- VESTA --"
 vst='yes'
@@ -103,7 +88,6 @@ if [ -e "$USER_DATA/backup.excludes" ]; then
     cp -r $USER_DATA/backup.excludes $tmpdir/vesta/
 fi
 
-
 echo
 
 # PAM
@@ -139,13 +123,7 @@ then
 
     # Parsing unsuspeneded domains
     conf="$USER_DATA/web.conf"
-    field='$DOMAIN'
-    search_string='DOMAIN='
-    domains=$(dom_clear_search)
-    domain_list=''
-
-    # Cleaning excludes
-    for domain in $domains; do
+    for domain in $(search_objects 'web' 'SUSPENDED' "*" 'DOMAIN'); do
 	check_exl=$(echo "$WEB"|grep -w $domain)
         if [ -z "$check_exl" ]; then
             web_list="$web_list $domain"
@@ -163,8 +141,8 @@ then
 
         # Packing data folders
         cd $HOMEDIR/$user/web/$domain
-        tar -cf $tmpdir/web/$domain/$domain.tar \
-            public_html public_shtml private document_errors cgi-bin stats
+        domain_direcotries=$(ls |grep -v logs)
+        tar -cf $tmpdir/web/$domain/$domain.tar $domain_direcotries
 
         # Creating web.config
         cd $tmpdir/web/$domain/
@@ -233,13 +211,7 @@ then
     mkdir $tmpdir/dns/
 
     # Parsing unsuspeneded domains
-    conf="$USER_DATA/dns.conf"
-    field='$DOMAIN'
-    search_string='DOMAIN='
-    domains=$(dom_clear_search)
-
-    # Cleaning excludes
-    for domain in $domains; do
+    for domain in $(search_objects 'dns' 'SUSPENDED' "*" 'DOMAIN'); do
 	check_exl=$(echo "$DNS"|grep -w $domain)
         if [ -z "$check_exl" ]; then
             dns_list="$dns_list $domain"
@@ -258,8 +230,8 @@ then
         grep "DOMAIN='$domain'" $conf > dns.conf
 
         # Backingup dns recods
-        cp $USER_DATA/dns/$domain $domain
-        cp $USER_DATA/conf/dns/$domain.db $domain.db
+        cp $USER_DATA/dns/$domain.conf $domain.conf
+        cp $HOMEDIR/$user/conf/dns/$domain.db $domain.db
     done
     echo
 fi
@@ -274,13 +246,7 @@ if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ] && [ "$DB" != '*' ]; then
     mkdir $tmpdir/db/
 
     # Parsing unsuspeneded domains
-    conf="$USER_DATA/db.conf"
-    field='$DB'
-    search_string='DB='
-    dbs=$(dom_clear_search)
-
-    # Cleaning excludes
-    for database in $dbs; do
+    for database in $(search_objects 'db' 'SUSPENDED' "*" 'DB'); do
 	check_exl=$(echo "$DB"|grep -w $database)
         if [ -z "$check_exl" ]; then
             db_list="$db_list $database"
@@ -289,23 +255,17 @@ if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ] && [ "$DB" != '*' ]; then
     db_list=$(echo "$db_list" | sed -e "s/  */\ /g" -e "s/^ //")
 
     for database in $db_list; do
-        type=$(get_db_value '$TYPE')
-        host=$(get_db_value '$HOST')
-        db_user=$(get_db_value '$USER')
-        dump="$tmpdir/db/$database.$type.sql"
-        grants="$tmpdir/db/$database.$type.$db_user"
-
-        echo -e "$(date "+%F %T") $database $type"
-
-        case $type in
-            mysql) dump_db_mysql ;;
-            pgsql) dump_db_pgsql ;;
+        get_database_values
+        dump="$tmpdir/db/$database.$TYPE.sql"
+        grants="$tmpdir/db/$database.$TYPE.$DBUSER"
+        echo -e "$(date "+%F %T") $database $TYPE"
+        case $TYPE in
+            mysql) dump_mysql_database ;;
+            pgsql) dump_pgsql_database ;;
         esac
-
         if [ ! -z "$BACKUP_GZIP" ]; then 
             gzip -$BACKUP_GZIP $dump
         fi
-
     done
     echo
 fi
@@ -333,6 +293,9 @@ size="$(du -shm $tmpdir | cut -f 1)"
 
 # Get current time
 end_time=$(date '+%s')
+DATE=$(date +%F)
+TIME=$(date +%T)
+
 
 # Defining local storage function
 local_backup(){
@@ -349,7 +312,6 @@ local_backup(){
     # Checking retention
     backup_list=$(ls -lrt $BACKUP/ | awk '{print $9}' |grep "^$user\.")
     backups_count=$(echo "$backup_list" | wc -l)
-
     if [ "$BACKUPS" -le "$backups_count" ]; then
         backups_rm_number=$((backups_count - BACKUPS))
         (( ++backups_rm_number))
@@ -367,7 +329,7 @@ local_backup(){
     disk_usage=$(df $BACKUP | awk '{print $5}'|tail -n1|cut -f 1 -d '%')
     if [ "$disk_usage" -ge "$BACKUP_DISK_LIMIT" ]; then
         echo "Error: Not enough disk space"
-        log_event 'debug' "$E_DISK $EVENT"
+        log_event "$E_DISK" "$EVENT"
         exit $E_DISK
     fi
 
@@ -402,7 +364,7 @@ ftp_backup(){
     if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ] ||\
         [ -z "$BPATH" ]; then
         echo "Error: Parsing error"
-        log_event 'debug' "$E_PARSING $EVENT"
+        log_event "$E_PARSING" "$EVENT"
         exit $E_PARSING
     fi
 
@@ -417,7 +379,7 @@ ftp_backup(){
              rm $ftmpdir"
     if [ ! -z "$(ftpc "$command")" ] ; then
         echo "Error: FTP error"
-        log_event 'debug' "$E_FTP $EVENT"
+        log_event "$E_FTP" "$EVENT"
         exit $E_FTP
     fi
 
@@ -489,7 +451,7 @@ for backup_record in $deprecated; do
 done
 
 # Concatenating string
-backup_str="DATE='$DATE' TIME='$current_time' RUNTIME='$run_time'"
+backup_str="DATE='$DATE' TIME='$TIME' RUNTIME='$run_time'"
 backup_str="$backup_str TYPE='$BACKUP_SYSTEM' SIZE='$size'"
 backup_str="$backup_str VESTA='$vst'"
 backup_str="$backup_str PAM='$pam'"

+ 6 - 5
bin/v_backup_users

@@ -13,7 +13,7 @@
 # mostly by cron wich not read it by itself
 source /etc/profile.d/vesta.sh
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -22,11 +22,12 @@ source $VESTA/func/shared.sh
 #                       Action                             #
 #----------------------------------------------------------#
 
-user_list=$(ls $V_USERS/)
-
 # Updating user billing
-for user in $user_list; do 
-    $BIN/v_backup_user $user &>> $VESTA/logs/backup.log 
+for user in $(ls $VESTA/data/users); do
+    check_suspend=$(grep "SUSPENDED='no'" $VESTA/data/users/$user/user.conf)
+    if [ ! -z "$check_suspend" ]; then
+        $BIN/v_backup_user $user >> $VESTA/log/backup.log 2>&1
+    fi
 done
 
 #----------------------------------------------------------#

+ 1 - 1
bin/v_change_sys_ip_owner

@@ -13,7 +13,7 @@
 ip=$1
 user=$2
 
-# Importing variables
+# Includes
 source $VESTA/func/shared.sh
 source $VESTA/func/ip.sh
 

+ 3 - 14
bin/v_change_user_contact

@@ -13,7 +13,7 @@
 user=$1
 email=$2
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -22,16 +22,9 @@ source $VESTA/func/shared.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '2' "$#" 'user email'
-
-# Checking argument format
 validate_format 'user' 'email'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 
 
@@ -39,13 +32,9 @@ is_object_unsuspended 'user' 'USER' "$user"
 #                       Action                             #
 #----------------------------------------------------------#
 
-# Get old value
-old_email=$(get_user_value '$CONTACT')
-
 # Changing user contact email
+old_email=$get_user_value '$CONTACT')
 update_user_value "$user" '$CONTACT' "$email"
-
-# Changing passwd file
 pw_str=$(grep -n "^$user:" /etc/passwd)
 str=$(echo "$pw_str" | cut -f 1 -d :)
 sed -i "$str s/$old_email/$email/g" /etc/passwd
@@ -56,7 +45,7 @@ sed -i "$str s/$old_email/$email/g" /etc/passwd
 #----------------------------------------------------------#
 
 # Logging
-log_history "$EVENT" "$SCRIPT $user $old_email"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 
 exit

+ 2 - 9
bin/v_change_user_name

@@ -14,7 +14,7 @@ user=$1
 fname=$2
 lname=$3
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -23,16 +23,9 @@ source $VESTA/func/shared.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking args
 check_args '3' "$#" 'user fname lname'
-
-# Checking argument format
 validate_format 'user' 'fname' 'lname'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 
 
@@ -54,7 +47,7 @@ update_user_value "$user" '$LNAME' "$lname"
 #----------------------------------------------------------#
 
 # Logging
-log_history "$EVENT" "$SCRIPT $user $old_fname $old_lname"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 
 exit

+ 2 - 13
bin/v_change_user_ns

@@ -20,7 +20,7 @@ ns6=$7
 ns7=$8
 ns8=$9
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -37,31 +37,23 @@ validate_format 'user' 'ns1' 'ns2'
 if [ ! -z "$ns3" ]; then
     validate_format 'ns3'
 fi
-
 if [ ! -z "$ns4" ]; then
     validate_format 'ns4'
 fi
-
 if [ ! -z "$ns5" ]; then
     validate_format 'ns5'
 fi
-
 if [ ! -z "$ns6" ]; then
     validate_format 'ns6'
 fi
-
 if [ ! -z "$ns7" ]; then
     validate_format 'ns7'
 fi
-
 if [ ! -z "$ns8" ]; then
     validate_format 'ns8'
 fi
 
-# Checking user
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 
 
@@ -69,9 +61,6 @@ is_object_unsuspended 'user' 'USER' "$user"
 #                       Action                             #
 #----------------------------------------------------------#
 
-# Get old values
-old_ns=$(get_user_value '$NS')
-
 # Merging values
 ns="$ns1,$ns2,$ns3,$ns4,$ns5,$ns6,$ns7,$ns8"
 ns=$(echo "$ns"|sed -e "s/,,//g" -e "s/,$//")
@@ -85,7 +74,7 @@ update_user_value "$user" '$NS' "$ns"
 #----------------------------------------------------------#
 
 # Logging
-log_history "$EVENT" "$SCRIPT $user ${old_ns//,/ }"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 
 exit

+ 3 - 18
bin/v_change_user_package

@@ -13,7 +13,7 @@
 user=$1
 package=$2
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -25,7 +25,6 @@ is_package_avalable() {
         eval ${key%%=*}=${key#*=}
     done
 
-    # Clearing vars
     WEB_DOMAINS='0'
     DATABASES='0'
     MAIL_DOMAINS='0'
@@ -33,11 +32,8 @@ is_package_avalable() {
     DISK_QUOTA='0'
     BANDWIDTH='0'
 
-    # Parsing package
     pkg_data=$(cat $VESTA/data/packages/$package.pkg)
-    for key in $pkg_data; do
-        eval ${key%%=*}=${key#*=}
-    done
+    eval $pkg_data
 
     # Comparing user data with package
     if [[ "$WEB_DOMAINS" -lt "$U_WEB_DOMAINS" ]] ||\
@@ -48,17 +44,15 @@ is_package_avalable() {
        [[ "$DISK_QUOTA" -lt "$U_DISK" ]] ||\
        [[ "$BANDWIDTH" -lt "$U_BANDWIDTH" ]]; then
         echo "Error: Upgrade package"
-        log_event 'debug' "$E_LIMIT $v_log"
+        log_event "$E_LIMIT" "$EVENT"
         exit $E_LIMIT
     fi
 }
 
 change_user_package() {
-    # Parsing user data
     usr_data=$(cat $USER_DATA/user.conf)
     eval $usr_data
 
-    # Parsing package
     pkg_data=$(cat $VESTA/data/packages/$package.pkg)
     eval $pkg_data
 
@@ -116,19 +110,10 @@ DATE='$DATE'" > $USER_DATA/user.conf
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '2' "$#" 'user package'
-
-# Checking argument format
 validate_format 'user' 'package'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
-
-# Checking package
 is_package_valid
-
-# Checking current data 
 is_package_avalable
 
 

+ 2 - 9
bin/v_change_user_password

@@ -13,7 +13,7 @@
 user=$1
 password=$2
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -22,16 +22,9 @@ source $VESTA/func/shared.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '2' "$#" 'user password'
-
-# Checking argument format
 validate_format 'user' 'password'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 
 
@@ -51,7 +44,7 @@ echo "$password" | /usr/bin/passwd "$user" --stdin &>/dev/null
 update_user_value "$user" '$RKEY' "$(gen_password)"
 
 # Hiding password
-EVENT="$DATE $SCRIPT $user *****"
+EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT' ARGUMENTS='$user *****'"
 
 # Logging
 log_event "$OK" "$EVENT"

+ 3 - 10
bin/v_change_user_shell

@@ -13,7 +13,7 @@
 user=$1
 shell=$2
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -22,16 +22,9 @@ source $VESTA/func/shared.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '2' "$#" 'user shell'
-
-# Checking argument format
 validate_format 'user' 'shell'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 
 
@@ -40,11 +33,11 @@ is_object_unsuspended 'user' 'USER' "$user"
 #----------------------------------------------------------#
 
 # Get shell full path
-shell_path=$(/usr/bin/chsh --list-shells | grep -w "$shell" )
+shell_path=$(/usr/bin/chsh --list-shells | grep -w "$shell" |head -n1)
 
 # Changing passwd file
 /usr/bin/chsh -s "$shell_path" "$user" &>/dev/null
-
+shell=$(basename $shell_path)
 
 
 #----------------------------------------------------------#

+ 1 - 1
bin/v_delete_database_server

@@ -14,7 +14,7 @@
 type=$1
 host=$2
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/db.sh

+ 1 - 1
bin/v_delete_sys_ip

@@ -13,7 +13,7 @@
 # Argument defenition
 ip=$1
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/ip.sh

+ 4 - 13
bin/v_delete_user

@@ -13,7 +13,7 @@
 # Argument defenition
 user=$1
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
@@ -25,19 +25,10 @@ source $VESTA/func/ip.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '1' "$#" 'user'
-
-# Checking argument format
 validate_format 'user'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking user admin
 if [ "$user" = 'admin' ]; then
     exit
 fi
@@ -69,7 +60,7 @@ fi
 # Checking mail system is enabled
 if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
     $BIN/v_unsuspend_mail_domains $user
-    $BIN/v_del_mail_domains $user
+    #$BIN/v_delete_mail_domains $user
     rv="$?"
     if [ "$rv" -ne '0' ]; then
         exit $rv
@@ -78,8 +69,8 @@ fi
 
 # Checking db system is enabled
 if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
-    $BIN/v_unsuspend_db_bases $user
-    $BIN/v_delete_db_dbases $user
+    $BIN/v_unsuspend_databases $user
+    $BIN/v_delete_databases $user
     rv="$?"
     if [ "$rv" -ne '0' ]; then
         exit $rv

+ 4 - 12
bin/v_delete_user_ips

@@ -12,7 +12,7 @@
 # Argument defenition
 user=$1
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/ip.sh
@@ -22,23 +22,15 @@ source $VESTA/func/ip.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '1' "$#" 'user'
-
-# Checking argument format
 validate_format 'user'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking user vesta
 if [ "$user" = 'admin' ]; then
     exit
 fi
 
+
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
@@ -54,8 +46,8 @@ for ip in $ip_list; do
     is_ip_key_empty '$U_SYS_USERS'
 
     # Assig ip to main account
-    update_sys_ip_value '$OWNER' 'admin'
-    update_sys_ip_value '$STATUS' 'dedicated'
+    update_ip_value '$OWNER' 'admin'
+    update_ip_value '$STATUS' 'dedicated'
     increase_user_value 'admin' '$IP_OWNED'
     increase_user_value 'admin' '$IP_AVAIL'
 done

+ 1 - 9
bin/v_get_user_value

@@ -13,7 +13,7 @@
 user=$1
 key=$(echo "$2"| tr '[:lower:]' '[:upper:]'|sed -e "s/^/$/")
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -22,18 +22,10 @@ source $VESTA/func/shared.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking args
 check_args '2' "$#" 'user key'
-
-# Checking argument format
 validate_format 'user'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
 
-# Checking domain is not suspened
-is_object_unsuspended 'user' 'USER' "$user"
-
 
 #----------------------------------------------------------#
 #                       Action                             #

+ 67 - 0
bin/v_list_sys_shells

@@ -0,0 +1,67 @@
+#!/bin/bash
+# info: list system shells
+# options: [format]
+#
+# The function for obtaining the list of system shells.
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument defenition
+format=${1-shell}
+
+# Includes
+source $VESTA/func/shared.sh
+
+# Json function
+json_list_sh() {
+    shells=$(cat /etc/shells)
+    sh_counter=$(echo "$shells" | wc -l)
+    i=1
+    echo '['
+    for shell in $shells; do
+        shell=$(basename $shell)
+        if [ "$i" -lt "$sh_counter" ]; then
+            echo -e  "\t\"$shell\","
+        else
+            echo -e  "\t\"$shell\""
+        fi
+        (( ++i))
+    done
+    echo "]"
+}
+
+# Shell function
+shell_list_sh() {
+    shells=$(cat /etc/shells)
+    if [ -z "$nohead" ]; then
+        echo "SHELLS"
+        echo "----------"
+    fi
+    for shell in $shells; do
+        shell=$(basename $shell)
+        echo "$shell"
+    done
+}
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Listing domains
+case $format in 
+    json)   json_list_sh ;;
+    plain)  nohead=1; shell_list_sh ;;
+    shell)  shell_list_sh ;;
+    *)      check_args '1' '0' '[format]' ;;
+esac
+
+
+#----------------------------------------------------------#
+#                       Vesta                              #
+#----------------------------------------------------------#
+
+exit

+ 3 - 0
bin/v_list_user

@@ -47,6 +47,9 @@ shell_list_user() {
     source $VESTA/data/users/$user/user.conf
     for field in $fields; do
         eval key="$field"
+        if [ -z "$key" ]; then
+            key='NULL'
+        fi
         echo "${field//$/}: $key "
     done
 }

+ 1 - 6
bin/v_list_user_backups

@@ -13,20 +13,15 @@
 user=$1
 format=${2-shell}
 
-# Importing variables
+# Includes
 source $VESTA/func/shared.sh
 
 #----------------------------------------------------------#
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking args
 check_args '1' "$#" 'user [format]'
-
-# Checking argument format
 validate_format 'user'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
 
 

+ 1 - 16
bin/v_list_user_ips

@@ -13,18 +13,16 @@
 user=$1
 format=${2-shell}
 
-# Importing variables
+# Includes
 source $VESTA/func/shared.sh
 
 # Json function
 json_list_user_ips() {
-    # Print top bracket
     echo '{'
     fileds_count=$(echo "$fields" | wc -w)
     for IP in $(ls $VESTA/data/ips/); do
         source $VESTA/data/ips/$IP
         if [ "$OWNER" = "$user" ]; then
-            # Closing bracket if there already was output
             if [ -n "$data" ]; then
                 echo -e '        },'
             fi
@@ -32,11 +30,9 @@ json_list_user_ips() {
             for field in $fields; do
                 eval value=$field
                 if [ $i -eq 1 ]; then
-                    # Printing parrent
                     (( ++i))
                     echo -e "\t\"$value\": {"
                 else
-                    # Printing child
                     if [ $i -lt $fileds_count ]; then
                         (( ++i))
                         echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
@@ -52,11 +48,9 @@ json_list_user_ips() {
                 for field in $fields; do
                     eval value=$field
                     if [ $i -eq 1 ]; then
-                        # Printing parrent
                         (( ++i))
                         echo -e "\t\"$value\": {"
                     else
-                        # Printing child
                         if [ $i -lt $fileds_count ]; then
                             (( ++i))
                             echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
@@ -69,13 +63,9 @@ json_list_user_ips() {
             fi
         fi
     done
-
-    # Closing bracket if there was output
     if [ -n "$data" ]; then
         echo -e '        }'
     fi
-
-    # Printing bottom bracket
     echo -e '}'
 
 }
@@ -99,13 +89,8 @@ shell_list_user_ips() {
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '1' "$#" 'user [format]'
-
-# Checking argument format
 validate_format 'user'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
 
 

+ 1 - 11
bin/v_list_user_ns

@@ -13,17 +13,15 @@
 user=$1
 format=${2-shell}
 
-# Importing variables
+# Includes
 source $VESTA/func/shared.sh
 
 # Json function
 json_list_ns() {
     ns=$(grep "^NS='" $USER_DATA/user.conf |cut -f 2 -d \')
-    # Print top bracket
     echo '['
     i=1
     nslistc=$(echo -e "${ns//,/\n}"|wc -l)
-    # Listing servers
     for nameserver in ${ns//,/ };do
         if [ "$i" -ne "$nslistc" ]; then
             echo -e  "\t\"$nameserver\","
@@ -32,7 +30,6 @@ json_list_ns() {
         fi
         (( ++i))
     done
-
     echo "]"
 }
 
@@ -40,11 +37,9 @@ json_list_ns() {
 shell_list_ns() {
     ns=$(grep "^NS='" $USER_DATA/user.conf |cut -f 2 -d \')
     if [ -z "$nohead" ]; then
-        # Print result
         echo "NAMESERVER"
         echo "----------"
     fi
-
     for nameserver in ${ns//,/ };do
         echo "$nameserver"
     done
@@ -55,13 +50,8 @@ shell_list_ns() {
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking args
 check_args '1' "$#" 'user [format]'
-
-# Checking argument format
 validate_format 'user'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
 
 

+ 1 - 22
bin/v_list_user_packages

@@ -12,37 +12,27 @@
 # Argument defenition
 format=${1-shell}
 
-# Importing variables
+# Includes
 source $VESTA/func/shared.sh
 
 # Json function
 json_list_pkgs() {
-    # Print top bracket
     echo '{'
-
     fileds_count=$(echo "$fields" | wc -w)
-
-    # Starting main loop
     for package in $(ls $VESTA/data/packages); do
         PACKAGE=${package/.pkg/}
-        # Assing key=value
         pkg_data=$(cat $VESTA/data/packages/$package)
         eval $pkg_data
-
-        # Closing bracket if there already was output
         if [ -n "$data" ]; then
             echo -e '        },'
         fi
         i=1
         for field in $fields; do
             eval value=$field
-
             if [ $i -eq 1 ]; then
-                # Printing parrent
                 (( ++i))
                 echo -e "\t\"$value\": {"
             else
-                # Printing child
                 if [ $i -lt $fileds_count ]; then
                     (( ++i))
                     echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
@@ -53,40 +43,29 @@ json_list_pkgs() {
             fi
         done
     done
-
-    # Closing bracket if there was output
     if [ -n "$data" ]; then
         echo -e '        }'
     fi
-
-    # Printing bottom bracket
     echo -e '}'
 }
 
 # Shell fnction
 shell_list_pkgs() {
-    # Listing pkg files
     for package in $(ls $VESTA/data/packages); do
         PACKAGE=${package/.pkg/}
-        # Assign key=value
         pkg_descr=$(cat $VESTA/data/packages/$package)
         eval $pkg_descr
-
-
         if [ -z "$nohead" ]; then
             echo '----------'
         fi
-
         for field in $fields; do
             eval value=$field
             echo -e "${field//$/}: $value"
         done
-
     done
 }
 
 
-
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#

+ 1 - 16
bin/v_list_users

@@ -12,32 +12,22 @@
 # Argument defenition
 format=${1-shell}
 
-# Importing variables
-
 # Json function
 json_list_users() {
     echo '{'
     fileds_count=$(echo "$fields" | wc -w)
-
-    # Starting main loop
     for USER in $(ls $VESTA/data/users/); do
-        # Reading user data
         source $VESTA/data/users/$USER/user.conf
-
-        # Closing bracket if there already was output
         if [ -n "$data" ]; then
             echo -e '        },'
         fi
         i=1
         for field in $fields; do
             eval value=$field
-
             if [ $i -eq 1 ]; then
-                # Printing parrent
                 (( ++i))
                 echo -e "\t\"$value\": {"
             else
-                # Printing child
                 if [ $i -lt $fileds_count ]; then
                     (( ++i))
                     echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
@@ -48,27 +38,22 @@ json_list_users() {
             fi
         done
     done
-    # Closing bracket if there was output
     if [ -n "$data" ]; then
         echo -e '        }'
     fi
-
-    # Printing bottom bracket
     echo -e '}'
 }
 
 # Shell function
 shell_list_users() {
     if [  -z "$nohead" ]; then
-        # Print brief info
         echo "${fields//$/}"
         for a in $fields; do
             echo -e "--------- \c"
         done
-        echo                        # new line
+        echo
     fi
 
-    # Starting main loop
     for USER in $(ls $VESTA/data/users/); do
         source $VESTA/data/users/$USER/user.conf
         eval echo "$fields"

+ 1 - 1
bin/v_rebuild_web_domains

@@ -12,7 +12,7 @@
 # Argument defenition
 user=$1
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh

+ 1 - 122
bin/v_restore_user

@@ -13,143 +13,22 @@
 user=$1
 backup=$2
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/db.sh
 
-# Defining ftp command function
-ftpc() {
-    ftp -n $HOST $PORT <<EOF
-    quote USER $USERNAME
-    quote PASS $PASSWORD
-    binary
-    cd $BPATH
-    $1
-    quit
-EOF
-}
-
-init_ftp_variables() {
-    # Checking config
-    source $VESTA/conf/ftp.backup.conf
-    if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ] ||\
-        [ -z "$BPATH" ]; then
-        echo "Error: Parsing error"
-        log_event 'debug' "$E_PARSING $EVENT"
-        exit $E_PARSING
-    fi
-}
-
-check_ftp_connection(){
-    # Checking ftp permission
-    ftmpdir=$(mktemp -u -p $BPATH)
-    command="mkdir $ftmpdir
-             ls $ftmpdir
-             rm $ftmpdir"
-    if [ ! -z "$(ftpc "$command")" ] ; then
-        echo "Error: FTP error"
-        log_event 'debug' "$E_FTP $EVENT"
-        exit $E_FTP
-    fi
-}
-
 
 #----------------------------------------------------------#
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Get current time
-start_time=$(date '+%s')
-echo "$(date "+%F %T") System restore for user $user"
-echo
-
-# Checking arg number
-check_args '2' "$#" 'user backup'
-
-# Checking argument format
-validate_format 'user' 'backup'
-
-# Checking backup system is enabled
-is_system_enabled 'BACKUP_SYSTEM'
-
-# Checking load averages
-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
-    sleep 60
-    if [ "$i" -ge "15" ]; then
-        echo "Error: LA is too high"
-        log_event 'debug' "$E_LA $EVENT"
-        exit $E_LA
-    fi
-    (( ++i))
-done
-
-# Checking local backup existance
-if [ ! -e "$BACKUP/$user.$backup.tar" ]; then
-    if [ ! -z "$(echo $BACKUP_SYSTEM | grep -w ftp)" ]; then
-        init_ftp_variables
-        check_ftp_connection
-        if [ ! -z "$(ftpc ls |awk '{print $9}' |grep $user.$backup.)" ]; then
-            cd $BACKUP
-            echo "$(date "+%F %T") Downloading ftp backup"
-            ftpc "get $user.$backup.tar" &>/dev/null
-            echo "$(date "+%F %T") Downloaded $user.$backup.tar"
-        fi
-    fi
-fi
-
-if [ ! -e "$BACKUP/$user.$backup.tar" ]; then
-    echo "Error: $BACKUP/$user.$backup.tar  backup not found"
-    log_event 'debug' "$E_NOTEXIST $EVENT"
-    exit $E_NOTEXIST
-fi
-
-# Checking arguments
-if [ -z "$3" ]; then
-    # Define full backup variables
-    VESTA='yes'
-    PAM='yes'
-    WEB='yes'
-    DNS='yes'
-    DB='yes'
-    MAIL='yes'
-    SSL='yes'
-    CRON='yes'
-else
-    args=("$@")
-    for (( i=2; i<${#@}; i++)); do
-        key=$(echo ${args[$i]} | cut -f 1 -d :| tr '[:lower:]' '[:upper:]')
-        opt=$(echo ${args[$i]} | cut -f 2 -d :)
-        if [ -z "$(echo ${args[$i]} |grep :)" ]; then
-            eval $key='yes'
-        else
-            eval $key='opt'
-            eval ${key}_OPT=$opt
-        fi
-    done
-fi
-
 
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
-# Creating temporary directory
-tmpdir=$(mktemp -p $BACKUP -d)
-echo "TMPDIR is $tmpdir"
-cd $tmpdir
-echo "$(date "+%F %T") Extracting files from backup"
-tar -xf $BACKUP/$user.$backup.tar
-echo "$(date "+%F %T") Backup has been unpacked"
-
-# Checking Vesta
-
-
 
 #----------------------------------------------------------#
 #                       Vesta                              #

+ 1 - 1
bin/v_suspend_dns_domain

@@ -15,7 +15,7 @@ domain=$(idn -t --quiet -u "$2" )
 domain_idn=$(idn -t --quiet -a "$domain")
 restart="$3"
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 

+ 2 - 16
bin/v_suspend_user

@@ -12,7 +12,7 @@
 # Argument defenition
 user=$1
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -21,19 +21,10 @@ source $VESTA/func/shared.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '1' "$#" 'user'
-
-# Checking argument format
 validate_format 'user'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user status
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking user admin
 if [ "$user" = 'admin' ]; then
     exit
 fi
@@ -61,7 +52,7 @@ fi
 
 # Suspending datbabases
 if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
-    $BIN/v_suspend_db_bases $user
+    $BIN/v_suspend_databases $user
 fi
 
 # Suspending cron jobs
@@ -74,11 +65,6 @@ fi
 #                       Vesta                              #
 #----------------------------------------------------------#
 
-# Adding task to the vesta pipe
-$BIN/v_restart_cron "$EVENT"
-$BIN/v_restart_web "$EVENT"
-$BIN/v_restart_dns "$EVENT"
-
 # Changing suspend value
 update_user_value "$user" '$SUSPENDED' 'yes'
 increase_user_value 'admin' '$SUSPENDED_USERS'

+ 0 - 1
bin/v_suspend_web_domains

@@ -40,7 +40,6 @@ for domain in $(search_objects 'web' 'SUSPENDED' "no" 'DOMAIN'); do
     $BIN/v_suspend_web_domain "$user" "$domain" "$url" 'no'
 done
 
-
 #----------------------------------------------------------#
 #                       Vesta                              #
 #----------------------------------------------------------#

+ 1 - 1
bin/v_unsuspend_cron_jobs

@@ -12,7 +12,7 @@
 # Argument defenition
 user=$1
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 

+ 1 - 1
bin/v_unsuspend_databases

@@ -12,7 +12,7 @@
 # Argument defenition
 user=$1
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/db.sh

+ 4 - 4
bin/v_unsuspend_mail_domains

@@ -49,13 +49,13 @@ field='$DOMAIN'
 search_string="SUSPENDED='yes'"
 
 # Parsing suspeneded domains
-domains=$(dom_clear_search)
+#domains=$(dom_clear_search)
 
 
 # Starting unsuspend loop
-for domain in $domains; do
-    $BIN/v_unsuspend_mail_domain "$user" "$domain"
-done
+#for domain in $domains; do
+#    $BIN/v_unsuspend_mail_domain "$user" "$domain"
+#done
 
 
 #----------------------------------------------------------#

+ 2 - 14
bin/v_unsuspend_user

@@ -12,7 +12,7 @@
 # Argument defenition
 user=$1
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -21,16 +21,9 @@ source $VESTA/func/shared.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '1' "$#" 'user'
-
-# Checking argument format
 validate_format 'user'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user admin
 if [ "$user" = 'admin' ]; then
     exit
 fi
@@ -58,7 +51,7 @@ fi
 
 # Unsuspending datbabases
 if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
-    $BIN/v_unsuspend_db_bases $user
+    $BIN/v_unsuspend_databases $user
 fi
 
 # Unsuspending cron jobs
@@ -71,11 +64,6 @@ fi
 #                       Vesta                              #
 #----------------------------------------------------------#
 
-# Adding task to the vesta pipe
-$BIN/v_restart_cron "$EVENT"
-$BIN/v_restart_web "$EVENT"
-$BIN/v_restart_dns "$EVENT"
-
 # Changing suspend value
 update_user_value "$user" '$SUSPENDED' 'no'
 decrease_user_value 'admin' '$SUSPENDED_USERS'

+ 1 - 1
bin/v_update_databases_disk

@@ -12,7 +12,7 @@
 # Argument defenition
 user=$1
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 

+ 2 - 2
bin/v_update_sys_vesta

@@ -44,7 +44,7 @@ if [ "$version" != "$VERSION" ]; then
     # Checking download result
     if [ "$?" -ne "0" ]; then
         echo "Error: version tree update failed"
-        log_event 'debug' "$E_UPDATE $EVENT"
+        log_event "$E_UPDATE" "$EVENT"
         exit $E_UPDATE
     fi
 
@@ -90,7 +90,7 @@ if [ "$version" != "$VERSION" ]; then
             # Checking download result
             if [ "$?" -ne "0" ]; then
                 echo "Error: version tree update failed"
-                log_event 'debug' "$E_UPDATE $EVENT"
+                log_event "$E_UPDATE" "$EVENT"
                 exit $E_UPDATE
             fi
             bash  $BIN/updates/$update.sh

+ 9 - 29
bin/v_update_user_backups

@@ -9,7 +9,7 @@
 #                    Variable&Function                     #
 #----------------------------------------------------------#
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -19,8 +19,8 @@ type="${2-$BACKUP_SYSTEM}"
 
 # Defining tar parser function 
 get_backup_info() {
-    backup=$1           # full path to backup
-    backup_type="$2"    # backup type
+    backup=$1
+    backup_type="$2"
 
     backup_name=$(basename $backup )
     backup_date=$(echo $backup_name |cut -f 2 -d '.' )
@@ -28,7 +28,6 @@ get_backup_info() {
     backup_size=$(du -sm $backup |cut -f 1 )
     backup_data=$(tar -tf  $backup)
 
-    # Checking system data
     vst_data=$(echo "$backup_data" |grep "^./vesta/" |grep -v "^./vesta/$")
     if [ -z "$vst_data" ]; then
         vst=''
@@ -36,7 +35,6 @@ get_backup_info() {
         vst='yes'
     fi
 
-    # Checking pam
     pam_data=$(echo "$backup_data" |grep "^./pam/" |grep -v "^./pam/$")
     if [ -z "$pam_data" ]; then
         pam=''
@@ -44,7 +42,6 @@ get_backup_info() {
         pam='yes'
     fi
 
-    # Checking web data
     web_data=$(echo "$backup_data" |grep "^./web/" |grep -v "^./web/$" |sort)
     if [ -z "$web_data" ]; then
         web=''
@@ -61,7 +58,6 @@ get_backup_info() {
         done
     fi
 
-    # Checking dns data
     dns_data=$(echo "$backup_data" |grep "^./dns/" |grep ".db$" |sort)
     if [ -z "$dns_data" ]; then
         dns=''
@@ -78,7 +74,6 @@ get_backup_info() {
         done
     fi
 
-    # Checking mail
     mail_data=$(echo "$backup_data"|grep "^./mail/"|grep -v "^./mail/$"|sort)
     if [ -z "$mail_data" ]; then
         ml=''
@@ -95,7 +90,6 @@ get_backup_info() {
         done
     fi
 
-    # Checking databases
     db_data=$(echo "$backup_data"|grep "^./db/"|grep ".sql.gz$"|sort)
     if [ -z "$db_data" ]; then
         db=''
@@ -112,7 +106,6 @@ get_backup_info() {
         done
     fi
 
-    # Checking certificates
     ssl_data=$(echo "$backup_data"|grep "^./ssl/"|grep ".crt$"|sort)
     if [ -z "$ssl_data" ]; then
         ssl=''
@@ -129,8 +122,6 @@ get_backup_info() {
         done
     fi
 
-
-    # Checking cron data
     cron_data=$(echo "$backup_data" |grep "^./cron/" |grep -v "^./cron/$")
     if [ -z "$cron_data" ]; then
         cron=''
@@ -156,25 +147,23 @@ EOF
 }
 
 init_ftp_variables() {
-    # Checking config
     source $VESTA/conf/ftp.backup.conf
     if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ] ||\
         [ -z "$BPATH" ]; then
         echo "Error: Parsing error"
-        log_event 'debug' "$E_PARSING $EVENT"
+        log_event "$E_PARSING" "$EVENT"
         exit $E_PARSING
     fi
 }
 
 check_ftp_connection(){
-    # Checking ftp permission
     ftmpdir=$(mktemp -u -p $BPATH)
     command="mkdir $ftmpdir
              ls $ftmpdir
              rm $ftmpdir"
     if [ ! -z "$(ftpc "$command")" ] ; then
         echo "Error: FTP error"
-        log_event 'debug' "$E_FTP $EVENT"
+        log_event "$E_FTP" "$EVENT"
         exit $E_FTP
     fi
 }
@@ -185,22 +174,13 @@ check_ftp_connection(){
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '1' "$#" 'user'
-
-# Checking backup system is enabled
-is_system_enabled 'BACKUP_SYSTEM'
-
-# Checking argument format
+is_system_enabled "$BACKUP_SYSTEM"
 validate_format 'user'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
-
-# Checking load averages
 la=$(cat /proc/loadavg |cut -f 1 -d ' '|cut -f 1 -d '.')
 if [ "$la" -ge "$BACKUP_LA_LIMIT" ]; then
-    log_event 'debug' "$E_LA $EVENT"
+    log_event "$E_LA" "$EVENT"
     exit $E_LA
 fi
 
@@ -235,7 +215,7 @@ if [ "$type" = 'ftp' ]; then
         cd $tmpdir
         if [ ! -z "$(ftpc "get $backup")" ]; then
             echo "Error: FTP transfer error"
-            log_event 'debug' "$E_FTP $EVENT"
+            log_event "$E_FTP" "$EVENT"
             exit $E_FTP
         fi
         get_backup_info $tmpdir/$backup $type >> $tmp_file
@@ -262,7 +242,7 @@ if [ "$type" = 'ftp,local' ] || [ "$type" = 'local,ftp' ]; then
             cd $tmpdir
             if [ ! -z "$(ftpc "get $backup")" ]; then
                 echo "Error: FTP transfer error"
-                log_event 'debug' "$E_FTP $EVENT"
+                log_event "$E_FTP" "$EVENT"
                 exit $E_FTP
             fi
             get_backup_info $tmpdir/$backup ftp >> $tmp_file

+ 7 - 11
bin/v_update_user_counters

@@ -12,7 +12,7 @@
 # Argument defenition
 user=$1
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -21,15 +21,9 @@ source $VESTA/func/shared.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '0' "$#" 'user'
-
-# If user specified
 if [ ! -z "$user" ]; then
-    # Checking argument format
     validate_format 'user'
-
-    # Checking user
     is_object_valid 'user' 'USER' "$user"
 fi
 
@@ -40,13 +34,14 @@ fi
 
 # Creating user_list
 if [ -z "$user" ]; then
-    user_list=$(ls $V_USERS/)
+    user_list=$(ls $VESTA/data/users)
 else
     user_list="$user"
 fi
 
 # Updating user stats
 for user in $user_list; do
+    USER_DATA=$VESTA/data/users/$user
     # Cleaning counters
     SUSPENDED_USERS=0
     SUSPENDED_WEB=0
@@ -84,8 +79,9 @@ for user in $user_list; do
 
     # Checking users
     if [ "$user" = 'admin' ]; then
-        SUSPENDED_USERS=$(grep "SUSPENDED='yes'" $V_USERS/*/user.conf|wc -l)
-        U_USERS=$(ls $V_USERS/|wc -l)
+        SUSPENDED_USERS=$(grep "SUSPENDED='yes'" $VESTA/data/users/*/user.conf)
+	SUSPENDED_USERS=$(echo "$SUSPENDED_USERS" |wc -l)
+        U_USERS=$(ls $VESTA/data/users/|wc -l)
     fi
 
     # Checking ip
@@ -128,7 +124,7 @@ for user in $user_list; do
     for domain_str in $(cat $USER_DATA/dns.conf); do
         eval $domain_str
         U_DNS_DOMAINS=$((U_DNS_DOMAINS + 1))
-        records=$(wc -l $USER_DATA/dns/$DOMAIN| cut -f 1 -d ' ')
+        records=$(wc -l $USER_DATA/dns/$DOMAIN.conf| cut -f 1 -d ' ')
         U_DNS_RECORDS=$((U_DNS_RECORDS + records))
         if [ "$SUSPENDED" = 'yes' ]; then
             SUSPENDED_DNS=$((SUSPENDED_DNS + 1))

+ 1 - 6
bin/v_update_user_disk

@@ -12,7 +12,7 @@
 # Argument defenition
 user=$1
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 
@@ -21,13 +21,8 @@ source $VESTA/func/shared.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '1' "$#" 'user'
-
-# Checking argument format
 validate_format 'user'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
 
 

+ 4 - 11
bin/v_update_user_stats

@@ -16,7 +16,7 @@ user=$1
 #       mostly by cron wich not read it by itself
 source /etc/profile.d/vesta.sh
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
@@ -26,15 +26,9 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-# Checking arg number
 check_args '0' "$#" 'user'
-
-# If user specified
 if [ ! -z "$user" ]; then
-    # Checking argument format
     validate_format 'user'
-
-    # Checking user
     is_object_valid 'user' 'USER' "$user"
 fi
 
@@ -45,20 +39,19 @@ fi
 
 # Creating user_list
 if [ -z "$user" ]; then
-    user_list=$(ls $V_USERS/)
+    user_list=$(ls $VESTA/data/users)
 else
     user_list="$user"
 fi
 
 # Updating user stats
 for user in $user_list; do 
-
-    # Importing user values
+    USER_DATA=$VESTA/data/users/$user
     source $USER_DATA/user.conf
     DATE=$(date -d "$(date +'%m/01') -1day" +%F)
 
     # Compiling report string
-    s="DATE='$DATE' PACKAGE='$PACKAGE' IP_OWNED='$IP_OWNED'" 
+    s="DATE='$DATE' TIME='$TIME' PACKAGE='$PACKAGE' IP_OWNED='$IP_OWNED'" 
     s="$s U_DISK='$U_DISK' U_DISK_DIRS='$U_DISK_DIRS' U_DISK_WEB='$U_DISK_WEB'"
     s="$s U_DISK_MAIL='$U_DISK_MAIL' U_DISK_DB='$U_DISK_DB'" 
     s="$s U_DISK_DATABASES='$U_DISK_DATABASES'" 

+ 37 - 49
func/db.sh

@@ -218,7 +218,7 @@ change_mysql_password() {
 
 # Change PostgreSQL database password
 change_pgsql_password() {
-    host_str=$(grep "HOST='$host'" $VESTA/conf/pgsql.conf)
+    host_str=$(grep "HOST='$HOST'" $VESTA/conf/pgsql.conf)
     eval $host_str
     export PGPASSWORD="$PASSWORD"
     if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $TPL ]; then
@@ -308,74 +308,62 @@ delete_pgsql_database() {
     fi
 }
 
-
-dump_db_mysql() {
-    # Defining vars
-    host_str=$(grep "HOST='$host'" $VESTA/conf/mysql.conf)
-    for key in $host_str; do
-        eval ${key%%=*}=${key#*=}
-    done
-    sql="mysql -h $HOST -u $USER -p$PASSWORD -P$PORT -e"
-    dumper="mysqldump -h $HOST -u $USER -p$PASSWORD -P$PORT -r"
-
-    # Checking empty vars
+# Dump MySQL database
+dump_mysql_database() {
+    host_str=$(grep "HOST='$HOST'" $VESTA/conf/mysql.conf)
+    eval $host_str
     if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $PORT ]; then
-        echo "Error: config is broken"
-        log_event 'debug' "$E_PARSING $EVENT"
+        echo "Error: mysql config parsing failed"
+        log_event "$E_PARSING" "$EVENT"
         exit $E_PARSING
     fi
 
-    # Checking connection
-    $sql "SELECT VERSION()" >/dev/null 2>&1; code="$?"
-    if [ '0' -ne "$code" ]; then
-        echo "Error: Connect failed"
-        log_event 'debug' "$E_DB $EVENT"
+    query='SELECT VERSION()'
+    mysql -h $HOST -u $USER -p$PASSWORD -P $PORT -e "$query" &> /dev/null
+    if [ '0' -ne "$?" ]; then
+        echo "Error: Connection failed"
+        log_event  "$E_DB $EVENT"
         exit $E_DB
     fi
 
-    # Dumping database
-    $dumper $dump $database
+    mysqldump -h $HOST -u $USER -p$PASSWORD -P$PORT -r $dump $database
 
-    # Dumping user grants
-    $sql "SHOW GRANTS FOR $db_user@localhost" | grep -v "Grants for" > $grants
-    $sql "SHOW GRANTS FOR $db_user@'%'" | grep -v "Grants for" >> $grants
-}
+    query="SHOW GRANTS FOR '$DBUSER'@'localhost'"
+    mysql -h $HOST -u $USER -p$PASSWORD -P $PORT -e "$query" |\
+        grep -v "Grants for" > $grants
 
-dump_db_pgsql() {
-    # Defining vars
-    host_str=$(grep "HOST='$host'" $VESTA/conf/pgsql.conf)
-    for key in $host_str; do
-        eval ${key%%=*}=${key#*=}
-    done
+    query="SHOW GRANTS FOR '$DBUSER'@'%'"
+    mysql -h $HOST -u $USER -p$PASSWORD -P $PORT -e "$query" |\
+        grep -v "Grants for" > $grants
+}
 
+# Dump PostgreSQL database
+dump_pgsql_database() {
+    host_str=$(grep "HOST='$HOST'" $VESTA/conf/pgsql.conf)
+    eval $host_str
     export PGPASSWORD="$PASSWORD"
-    sql="psql -h $HOST -U $USER -p $PORT -c"
-    dumper="pg_dump -h $HOST -U $USER -p $PORT -c -d -O -x -i -f"
-    # Checking empty vars
     if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $TPL ]; then
-        echo "Error: config is broken"
-        log_event 'debug' "$E_PARSING $EVENT"
+        echo "Error: postgresql config parsing failed"
+        log_event "$E_PARSING" "$EVENT"
         exit $E_PARSING
     fi
 
-    # Checking connection
-    $sql "SELECT VERSION()" >/dev/null 2>&1;code="$?"
-    if [ '0' -ne "$code" ];  then
-        echo "Error: Connect failed"
-        log_event 'debug' "$E_DB $EVENT"
+    query='SELECT VERSION()'
+    psql -h $HOST -U $USER -p $PORT -c "$query" &> /dev/null
+    if [ '0' -ne "$?" ];  then
+        echo "Error: Connection failed"
+        log_event "$E_DB" "$EVENT"
         exit $E_DB
     fi
 
-    # Dumping database
-    $dumper $dump $database
+    pg_dump -h $HOST -U $USER -p $PORT -c -d -O -x -i -f $dump $database \
+        2> /dev/null
 
-    # Dumping user grants
-    md5=$($sql "SELECT rolpassword FROM pg_authid WHERE rolname='$db_user';")
-    md5=$(echo "$md5" | head -n 1 | cut -f 2 -d ' ')
-    pw_str="UPDATE pg_authid SET rolpassword='$md5' WHERE rolname='$db_user';"
-    gr_str="GRANT ALL PRIVILEGES ON DATABASE $database to '$db_user'"
+    query="SELECT rolpassword FROM pg_authid WHERE rolname='$DBUSER';"
+    md5=$(psql -h $HOST -U $USER -p $PORT -c "$query"|head -n1|cut -f 2 -d \ )
+    pw_str="UPDATE pg_authid SET rolpassword='$md5' WHERE rolname='$DBUSER';"
+    gr_str="GRANT ALL PRIVILEGES ON DATABASE $database to '$DBUSER'"
     echo -e "$pw_str\n$gr_str" >> $grants
-    export PGPASSWORD='pgsql'
 }
 
 # Check if database server is in use

+ 4 - 4
func/shared.sh

@@ -119,11 +119,11 @@ is_type_valid() {
     fi
 }
 
-# Checkk user backup settings
+# Check user backup settings
 is_backup_enabled() {
-    BACKUPS=$(grep "BACKUPS='" $USER_DATA/user.conf | cut -f 2 -d \')
+    BACKUPS=$(grep "^BACKUPS=" $USER_DATA/user.conf | cut -f2 -d \')
     if [ -z "$BACKUPS" ] || [[ "$BACKUPS" -le '0' ]]; then
-        echo "Error:  user backup disabled"
+        echo "Error: user backup disabled"
         log_event "$E_DISABLED" "$EVENT"
         exit $E_DISABLED
     fi
@@ -422,7 +422,7 @@ validate_format_url() {
 
 # Shell
 validate_format_shell() {
-    if [ -z "$(grep -x $1 /etc/shells)" ]; then
+    if [ -z "$(grep -w $1 /etc/shells)" ]; then
         echo "Error: shell $1 is not valid"
         log_event "$E_INVALID" "$EVENT"
         exit $E_INVALID