Просмотр исходного кода

New config path. New permission policy. Improved rebuild scripts.

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

+ 2 - 0
bin/v_add_cron_job

@@ -67,6 +67,8 @@ v_str="$v_str' WDAY='$wday' CMD='$command' SUSPEND='no' DATE='$V_DATE'"
 # Adding to crontab
 # Adding to crontab
 echo "$v_str">>$V_USERS/$user/cron.conf
 echo "$v_str">>$V_USERS/$user/cron.conf
 
 
+chmod 660 $V_USERS/$user/cron.conf
+
 # Sorting jobs by id
 # Sorting jobs by id
 sort_cron_jobs
 sort_cron_jobs
 
 

+ 2 - 1
bin/v_add_db_base

@@ -90,7 +90,8 @@ increase_user_value "$user" '$U_DATABASES'
 # Adding db to db conf
 # Adding db to db conf
 v_str="DB='$database' USER='$db_user' HOST='$host' TYPE='$type'"
 v_str="DB='$database' USER='$db_user' HOST='$host' TYPE='$type'"
 v_str="$v_str CHARSET='$encoding' U_DISK='0' SUSPEND='no' DATE='$V_DATE'"
 v_str="$v_str CHARSET='$encoding' U_DISK='0' SUSPEND='no' DATE='$V_DATE'"
-echo "$v_str">>$V_USERS/$user/db.conf
+echo "$v_str" >> $V_USERS/$user/db.conf
+chmod 660 $V_USERS/$user/db.conf
 
 
 # Hiding password
 # Hiding password
 V_EVENT="$V_DATE $V_SCRIPT $user $database $db_user ***** $type $host"
 V_EVENT="$V_DATE $V_SCRIPT $user $database $db_user ***** $type $host"

+ 7 - 1
bin/v_add_dns_domain

@@ -103,14 +103,20 @@ cat $V_DNSTPL/$template.tpl |\
 dns_rec="DOMAIN='$domain' IP='$ip' TPL='$template' TTL='$ttl' EXP='$exp'"
 dns_rec="DOMAIN='$domain' IP='$ip' TPL='$template' TTL='$ttl' EXP='$exp'"
 dns_rec="$dns_rec SOA='$soa' SUSPEND='no' DATE='$V_DATE'"
 dns_rec="$dns_rec SOA='$soa' SUSPEND='no' DATE='$V_DATE'"
 echo "$dns_rec" >> $V_USERS/$user/dns.conf
 echo "$dns_rec" >> $V_USERS/$user/dns.conf
+chmod 660 $V_USERS/$user/dns.conf
 
 
 # Adding zone in named.conf
 # Adding zone in named.conf
-named="zone \"$domain_idn\" {type master; file \"/etc/namedb/$domain.db\";};"
+named="zone \"$domain_idn\" {type master; file"
+named="$named \"$V_HOME/$user/conf/dns/$domain.db\";};"
 echo "$named" >> /etc/named.conf
 echo "$named" >> /etc/named.conf
 
 
 # Updating domain dns zone
 # Updating domain dns zone
+conf="$V_HOME/$user/conf/dns/$domain.db"
 update_domain_zone
 update_domain_zone
 
 
+chmod 640 $conf
+chown root:named $conf
+
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Vesta                              #
 #                       Vesta                              #

+ 32 - 10
bin/v_add_user

@@ -75,26 +75,32 @@ esac
 echo "$password" | /usr/bin/passwd "$user" --stdin >/dev/null 2>&1
 echo "$password" | /usr/bin/passwd "$user" --stdin >/dev/null 2>&1
 
 
 # Building directory tree
 # Building directory tree
-if [ ! -z "$BACKUP_SYSTEM" ] && [ "$BACKUP_SYSTEM" != 'no' ]; then
-    mkdir $V_HOME/$user/backup
-    chmod 751 $V_HOME/$user/backup
-fi
+mkdir $V_HOME/$user/conf
+chmod 751 $V_HOME/$user/conf/web
 
 
 if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
 if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
-    mkdir $V_HOME/$user/conf
+    mkdir $V_HOME/$user/conf/web
     mkdir $V_HOME/$user/web
     mkdir $V_HOME/$user/web
     mkdir $V_HOME/$user/tmp
     mkdir $V_HOME/$user/tmp
-    chmod 751 $V_HOME/$user/conf
+    chmod 751 $V_HOME/$user/conf/web
     chmod 751 $V_HOME/$user/web
     chmod 751 $V_HOME/$user/web
     chmod 777 $V_HOME/$user/tmp
     chmod 777 $V_HOME/$user/tmp
     chown $user:$user $V_HOME/$user/web
     chown $user:$user $V_HOME/$user/web
 fi
 fi
 
 
 if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
 if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
+    mkdir $V_HOME/$user/conf/mail
     mkdir $V_HOME/$user/mail
     mkdir $V_HOME/$user/mail
     chmod 751 $V_HOME/$user/mail
     chmod 751 $V_HOME/$user/mail
+    chmod 751 $V_HOME/$user/conf/mail
+fi
+
+if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS_SYSTEM" != 'no' ]; then
+    mkdir $V_HOME/$user/conf/dns
+    chmod 751 $V_HOME/$user/conf/dns
 fi 
 fi 
 
 
+
 # Set permissions
 # Set permissions
 chmod -R a+x $V_HOME/$user
 chmod -R a+x $V_HOME/$user
 
 
@@ -111,36 +117,51 @@ fi
 
 
 # Adding user dir
 # Adding user dir
 mkdir $V_USERS/$user
 mkdir $V_USERS/$user
+chmod 770 $V_USERS/$user
 
 
 # Creating configuration files and pipes
 # Creating configuration files and pipes
-touch $V_USERS/$user/user.conf
+touch $V_USERS/$user/backup.conf
+chmod 660 $V_USERS/$user/backup.conf
+touch $V_USERS/$user/history.log
+chmod 660 $V_USERS/$user/history.log
+touch $V_USERS/$user/billing.log
+chmod 660 $V_USERS/$user/billing.log
+
 echo "v_update_user_disk $user" >> $V_QUEUE/disk.pipe
 echo "v_update_user_disk $user" >> $V_QUEUE/disk.pipe
 
 
 if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
 if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
     mkdir $V_USERS/$user/ssl
     mkdir $V_USERS/$user/ssl
+    chmod 770 $V_USERS/$user/ssl
     touch $V_USERS/$user/web.conf
     touch $V_USERS/$user/web.conf
+    chmod 660 $V_USERS/$user/web.conf
     echo "$V_BIN/v_update_web_domains_traff $user" >> $V_QUEUE/traffic.pipe
     echo "$V_BIN/v_update_web_domains_traff $user" >> $V_QUEUE/traffic.pipe
     echo "v_update_web_domains_disk $user" >> $V_QUEUE/disk.pipe
     echo "v_update_web_domains_disk $user" >> $V_QUEUE/disk.pipe
 fi
 fi
 
 
 if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS_SYSTEM" != 'no' ]; then
 if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS_SYSTEM" != 'no' ]; then
-    touch $V_USERS/$user/dns.conf
     mkdir $V_USERS/$user/dns
     mkdir $V_USERS/$user/dns
+    chmod 770 $V_USERS/$user/dns
+    touch $V_USERS/$user/dns.conf
+    chmod 660 $V_USERS/$user/dns.conf
 fi
 fi
 
 
 if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
 if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
-    touch $V_USERS/$user/mail_domains.conf
-    touch $V_USERS/$user/mail_boxes.conf
+    mkdir $V_USERS/$user/mail
+    chmod 770 $V_USERS/$user/mail
+    touch $V_USERS/$user/mail.conf
+    chmod 660 $V_USERS/$user/mail.conf
     echo "v_upd_mail_domains_disk $user" >> $V_QUEUE/disk.pipe
     echo "v_upd_mail_domains_disk $user" >> $V_QUEUE/disk.pipe
 fi
 fi
 
 
 if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
 if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
     touch $V_USERS/$user/db.conf
     touch $V_USERS/$user/db.conf
+    chmod 660 $V_USERS/$user/db.conf
     echo "v_update_db_bases_disk $user" >> $V_QUEUE/disk.pipe
     echo "v_update_db_bases_disk $user" >> $V_QUEUE/disk.pipe
 fi
 fi
 
 
 if [ ! -z "$CRON_SYSTEM" ] && [ "$CRON_SYSTEM" != 'no' ]; then
 if [ ! -z "$CRON_SYSTEM" ] && [ "$CRON_SYSTEM" != 'no' ]; then
     touch $V_USERS/$user/cron.conf
     touch $V_USERS/$user/cron.conf
+    chmod 660 $V_USERS/$user/cron.conf
 fi
 fi
 
 
 # Filling user config
 # Filling user config
@@ -163,6 +184,7 @@ U_DATABASES='0'
 U_MAIL_DOMAINS='0'
 U_MAIL_DOMAINS='0'
 U_CRON_JOBS='0'
 U_CRON_JOBS='0'
 DATE='$V_DATE'" > $V_USERS/$user/user.conf
 DATE='$V_DATE'" > $V_USERS/$user/user.conf
+chmod 660 $V_USERS/$user/user.conf
 
 
 # Hiding password
 # Hiding password
 V_EVENT="$V_DATE $V_SCRIPT $user ***** $email $package $fname $lname"
 V_EVENT="$V_DATE $V_SCRIPT $user ***** $email $package $fname $lname"

+ 5 - 2
bin/v_add_web_domain

@@ -99,7 +99,7 @@ email="$user@$domain"
 docroot="$V_HOME/$user/web/$domain/public_html"
 docroot="$V_HOME/$user/web/$domain/public_html"
 docroot_string="DocumentRoot $docroot"
 docroot_string="DocumentRoot $docroot"
 
 
-conf="$V_HOME/$user/conf/httpd.conf"
+conf="$V_HOME/$user/conf/web/httpd.conf"
 tpl_file="$V_WEBTPL/apache_$template.tpl"
 tpl_file="$V_WEBTPL/apache_$template.tpl"
 
 
 # Parsing template keys
 # Parsing template keys
@@ -167,8 +167,10 @@ done
 # Changing file owner
 # Changing file owner
 chown -R $user:$user $V_HOME/$user/web/$domain
 chown -R $user:$user $V_HOME/$user/web/$domain
 chown root:$user /var/log/httpd/domains/$domain.*
 chown root:$user /var/log/httpd/domains/$domain.*
+chown root:apache $conf
 
 
 # Changing file permissions
 # Changing file permissions
+chmod 640 $conf
 chmod 551 $V_HOME/$user/web/$domain
 chmod 551 $V_HOME/$user/web/$domain
 chmod 751 $V_HOME/$user/web/$domain/private
 chmod 751 $V_HOME/$user/web/$domain/private
 chmod 751 $V_HOME/$user/web/$domain/cgi-bin
 chmod 751 $V_HOME/$user/web/$domain/cgi-bin
@@ -218,7 +220,8 @@ v_str="$v_str SSL='no' SSL_HOME='single'"
 v_str="$v_str NGINX='' NGINX_EXT='' SUSPEND='no' DATE='$V_DATE'"
 v_str="$v_str NGINX='' NGINX_EXT='' SUSPEND='no' DATE='$V_DATE'"
 
 
 # Registering domain
 # Registering domain
-echo "$v_str" >>$V_USERS/$user/web.conf
+echo "$v_str" >> $V_USERS/$user/web.conf
+chmod 660 $V_USERS/$user/web.conf
 
 
 # Adding task to the vesta pipe
 # Adding task to the vesta pipe
 restart_schedule 'web'
 restart_schedule 'web'

+ 11 - 3
bin/v_add_web_domain_nginx

@@ -67,12 +67,16 @@ get_web_domain_values
 NGINX="$template"
 NGINX="$template"
 NGINX_EXT="$extentions"
 NGINX_EXT="$extentions"
 tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.tpl"
 tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.tpl"
-conf="$V_HOME/$user/conf/nginx.conf"
+conf="$V_HOME/$user/conf/web/nginx.conf"
 
 
 # Preparing domain values for the template substitution
 # Preparing domain values for the template substitution
 upd_web_domain_values
 upd_web_domain_values
 add_web_config
 add_web_config
 
 
+# Set permission and ownership
+chown root:nginx $conf
+chmod 640 $conf
+
 # Checking main vesta httpd config
 # Checking main vesta httpd config
 main_conf='/etc/nginx/conf.d/vesta_users.conf'
 main_conf='/etc/nginx/conf.d/vesta_users.conf'
 main_conf_check=$(grep "$conf" $main_conf )
 main_conf_check=$(grep "$conf" $main_conf )
@@ -80,13 +84,16 @@ if [ -z "$main_conf_check" ]; then
     echo "include $conf;" >>$main_conf
     echo "include $conf;" >>$main_conf
 fi
 fi
 
 
-
+# Checking ssl
 if [ "$SSL" = 'yes' ]; then
 if [ "$SSL" = 'yes' ]; then
     proxy_string="proxy_pass     https://$ip:$WEB_SSL_PORT;"
     proxy_string="proxy_pass     https://$ip:$WEB_SSL_PORT;"
     tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
     tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
-    conf="$V_HOME/$user/conf/snginx.conf"
+    conf="$V_HOME/$user/conf/web/snginx.conf"
     add_web_config
     add_web_config
 
 
+    chown root:nginx $conf
+    chmod 640 $conf
+
     main_conf='/etc/nginx/conf.d/vesta_users.conf'
     main_conf='/etc/nginx/conf.d/vesta_users.conf'
     main_conf_check=$(grep "$conf" $main_conf )
     main_conf_check=$(grep "$conf" $main_conf )
     if [ -z "$main_conf_check" ]; then
     if [ -z "$main_conf_check" ]; then
@@ -95,6 +102,7 @@ if [ "$SSL" = 'yes' ]; then
 fi
 fi
 
 
 
 
+
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Vesta                              #
 #                       Vesta                              #
 #----------------------------------------------------------#
 #----------------------------------------------------------#

+ 13 - 6
bin/v_add_web_domain_ssl

@@ -76,10 +76,11 @@ if [ -e "$ssl_dir/$domain.ca" ]; then
     cp -f $ssl_dir/$domain.ca $V_USERS/$user/ssl/$domain.ca
     cp -f $ssl_dir/$domain.ca $V_USERS/$user/ssl/$domain.ca
     cat $V_USERS/$user/ssl/$domain.ca >> $V_USERS/$user/ssl/$domain.pem
     cat $V_USERS/$user/ssl/$domain.ca >> $V_USERS/$user/ssl/$domain.pem
 fi
 fi
+chmod 660 $V_USERS/$user/ssl/$domain.*
 
 
 # Parsing domain values
 # Parsing domain values
 get_web_domain_values
 get_web_domain_values
-conf="$V_HOME/$user/conf/shttpd.conf"
+conf="$V_HOME/$user/conf/web/shttpd.conf"
 tpl_file="$V_WEBTPL/apache_$TPL.stpl"
 tpl_file="$V_WEBTPL/apache_$TPL.stpl"
 SSL_HOME="$ssl_home"
 SSL_HOME="$ssl_home"
 
 
@@ -92,12 +93,15 @@ upd_web_domain_values
 # Adding domain to the shttpd.conf
 # Adding domain to the shttpd.conf
 add_web_config
 add_web_config
 
 
+chown root:apache $conf
+chmod 640 $conf
+
 # Adding certificate to user dir
 # Adding certificate to user dir
-cp -f $V_USERS/$user/ssl/$domain.crt $V_HOME/$user/conf/ssl.$domain.crt
-cp -f $V_USERS/$user/ssl/$domain.key $V_HOME/$user/conf/ssl.$domain.key
-cp -f $V_USERS/$user/ssl/$domain.pem $V_HOME/$user/conf/ssl.$domain.pem
+cp -f $V_USERS/$user/ssl/$domain.crt $V_HOME/$user/conf/web/ssl.$domain.crt
+cp -f $V_USERS/$user/ssl/$domain.key $V_HOME/$user/conf/web/ssl.$domain.key
+cp -f $V_USERS/$user/ssl/$domain.pem $V_HOME/$user/conf/web/ssl.$domain.pem
 if [ -e "$V_USERS/$user/ssl/$domain.ca" ]; then
 if [ -e "$V_USERS/$user/ssl/$domain.ca" ]; then
-    cp -f $V_USERS/$user/ssl/$domain.ca $V_HOME/$user/conf/ssl.$domain.ca
+    cp -f $V_USERS/$user/ssl/$domain.ca $V_HOME/$user/conf/web/ssl.$domain.ca
 fi
 fi
 
 
 # Running template trigger
 # Running template trigger
@@ -115,10 +119,13 @@ fi
 # Checking  nginx
 # Checking  nginx
 if [ ! -z "$NGINX" ]; then
 if [ ! -z "$NGINX" ]; then
     # Adding domain to the snginx.conf
     # Adding domain to the snginx.conf
-    conf="$V_HOME/$user/conf/snginx.conf"
+    conf="$V_HOME/$user/conf/web/snginx.conf"
     tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
     tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
     add_web_config
     add_web_config
 
 
+    chown root:nginx $conf
+    chmod 640 $conf
+
     # Checking vesta nginx config
     # Checking vesta nginx config
     main_conf='/etc/nginx/conf.d/vesta_users.conf'
     main_conf='/etc/nginx/conf.d/vesta_users.conf'
     main_conf_check=$(grep "$conf" $main_conf )
     main_conf_check=$(grep "$conf" $main_conf )

+ 1 - 1
bin/v_add_web_domain_stat

@@ -81,7 +81,7 @@ cat $V_WEBTPL/$type.tpl |\
         -e "s/%home%/${V_HOME////\/}/g" \
         -e "s/%home%/${V_HOME////\/}/g" \
         -e "s/%alias%/${aliases//,/ }/g" \
         -e "s/%alias%/${aliases//,/ }/g" \
         -e "s/%alias_idn%/${aliases_idn//,/ }/g" \
         -e "s/%alias_idn%/${aliases_idn//,/ }/g" \
-    > $V_HOME/$user/conf/$type.$domain.conf
+    > $V_HOME/$user/conf/web/$type.$domain.conf
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#

+ 1 - 0
bin/v_backup_user

@@ -503,6 +503,7 @@ backup_str="$backup_str MAIL='${mail_list// /,}'"
 backup_str="$backup_str DB='${db_list// /,}'"
 backup_str="$backup_str DB='${db_list// /,}'"
 backup_str="$backup_str CRON='$cron_list'"
 backup_str="$backup_str CRON='$cron_list'"
 echo "$backup_str" >> $V_USERS/$user/backup.conf
 echo "$backup_str" >> $V_USERS/$user/backup.conf
+chmod 660 $V_USERS/$user/backup.conf
 
 
 # Logging
 # Logging
 log_event 'system' "$V_EVENT"
 log_event 'system' "$V_EVENT"

+ 3 - 3
bin/v_delete_dns_domain

@@ -54,13 +54,13 @@ tpl_name=$(get_dns_domain_value '$TPL')
 old_ip=$(get_dns_domain_value '$IP')
 old_ip=$(get_dns_domain_value '$IP')
 
 
 # Deleting domain in named.conf
 # Deleting domain in named.conf
-rm_string=$(grep -n /etc/namedb/$domain.db $named_conf|cut -d : -f 1)
+rm_string=$(grep -n /conf/dns/$domain.db $named_conf |cut -d : -f 1)
 if [ ! -z "$rm_string" ]; then
 if [ ! -z "$rm_string" ]; then
     sed -i "$rm_string d" $named_conf
     sed -i "$rm_string d" $named_conf
 fi
 fi
 
 
-if [ -e "/etc/namedb/$domain.db" ]; then
-    rm -f /etc/namedb/$domain.db
+if [ -e "$V_HOME/$user/conf/dns/$domain.db" ]; then
+    rm -f $V_HOME/$user/conf/dns/$domain.db
 fi
 fi
 
 
 
 

+ 7 - 4
bin/v_rebuild_dns_domains

@@ -103,8 +103,12 @@ for domain in $domains; do
     sort_dns_records
     sort_dns_records
 
 
     # Updating zone
     # Updating zone
+    conf="$V_HOME/$user/conf/dns/$domain.db"
     update_domain_zone
     update_domain_zone
 
 
+    chmod 640 $conf
+    chown root:named $conf
+
     # Bind config check
     # Bind config check
     nconf='/etc/named.conf'
     nconf='/etc/named.conf'
 
 
@@ -114,10 +118,9 @@ for domain in $domains; do
             sed -i "$rm_string d" $nconf
             sed -i "$rm_string d" $nconf
         fi
         fi
     else
     else
-	check_string=$(grep /etc/namedb/$domain.db $nconf)
-	if [ -z "$check_string" ]; then
-            named="zone \"$domain_idn\""
-            named="$named {type master; file \"/etc/namedb/$domain.db\";};"
+	if [ -z "$(grep /$domain.db $nconf)" ]; then
+            named="zone \"$domain_idn\" {type master; file"
+            named="$named \"$V_HOME/$user/conf/dns/$domain.db\";};"
             echo "$named" >> /etc/named.conf
             echo "$named" >> /etc/named.conf
         fi
         fi
     fi
     fi

+ 55 - 14
bin/v_rebuild_web_domains

@@ -65,20 +65,58 @@ for domain in $(shell_list) ; do
 
 
     # Adding domain to the tmp_httpd.conf
     # Adding domain to the tmp_httpd.conf
     tpl_file="$V_WEBTPL/apache_$TPL.tpl"
     tpl_file="$V_WEBTPL/apache_$TPL.tpl"
-    conf="$V_HOME/$user/conf/tmp_httpd.conf"
+    conf="$V_HOME/$user/conf/web/tmp_httpd.conf"
     add_web_config
     add_web_config
+    chown root:apache $conf
+    chmod 640 $conf
 
 
     # Running template trigger
     # Running template trigger
     if [ -x $V_WEBTPL/apache_$TPL.sh ]; then
     if [ -x $V_WEBTPL/apache_$TPL.sh ]; then
         $V_WEBTPL/apache_$TPL.sh $user $domain $ip $V_HOME $docroot
         $V_WEBTPL/apache_$TPL.sh $user $domain $ip $V_HOME $docroot
     fi
     fi
 
 
+    # Checking stats
+    if [ ! -z "$STATS" ]; then
+    cat $V_WEBTPL/$STATS.tpl |\
+        sed -e "s/%ip%/$ip/g" \
+            -e "s/%web_port%/$WEB_PORT/g" \
+            -e "s/%web_ssl_port%/$WEB_SSL_PORT/g" \
+            -e "s/%proxy_port%/$PROXY_PORT/g" \
+            -e "s/%proxy_ssl_port%/$PROXY_SSL_PORT/g" \
+            -e "s/%domain_idn%/$domain_idn/g" \
+            -e "s/%domain%/$domain/g" \
+            -e "s/%user%/$user/g" \
+            -e "s/%home%/${V_HOME////\/}/g" \
+            -e "s/%alias%/${aliases//,/ }/g" \
+            -e "s/%alias_idn%/${aliases_idn//,/ }/g" \
+        > $V_HOME/$user/conf/web/$STATS.$domain.conf
+
+        stats_string="$V_BIN/v_update_web_domain_stat $user $domain"
+        check_stats_pipe=$(grep "$stats_string" $V_QUEUE/stats.pipe)
+        if [ -z "$check_stats_pipe" ]; then
+            echo "$stats_string" >> $V_QUEUE/stats.pipe
+        fi
+    fi
+
     # Checking ssl
     # Checking ssl
     if [ "$SSL" = 'yes' ]; then
     if [ "$SSL" = 'yes' ]; then
         # Adding domain to the shttpd.conf
         # Adding domain to the shttpd.conf
-        conf="$V_HOME/$user/conf/tmp_shttpd.conf"
+        conf="$V_HOME/$user/conf/web/tmp_shttpd.conf"
         tpl_file="$V_WEBTPL/apache_$TPL.stpl"
         tpl_file="$V_WEBTPL/apache_$TPL.stpl"
         add_web_config
         add_web_config
+        chown root:apache $conf
+        chmod 640 $conf
+
+        cp -f $V_USERS/$user/ssl/$domain.crt \
+            $V_HOME/$user/conf/web/ssl.$domain.crt
+        cp -f $V_USERS/$user/ssl/$domain.key \
+            $V_HOME/$user/conf/web/ssl.$domain.key
+        cp -f $V_USERS/$user/ssl/$domain.pem \
+            $V_HOME/$user/conf/web/ssl.$domain.pem
+        if [ -e "$V_USERS/$user/ssl/$domain.ca" ]; then
+            cp -f $V_USERS/$user/ssl/$domain.ca \
+                $V_HOME/$user/conf/web/ssl.$domain.ca
+        fi
 
 
         # Running template trigger
         # Running template trigger
         if [ -x $V_WEBTPL/apache_$TPL.sh ]; then
         if [ -x $V_WEBTPL/apache_$TPL.sh ]; then
@@ -91,8 +129,10 @@ for domain in $(shell_list) ; do
     # Checking nginx
     # Checking nginx
     if [ ! -z "$NGINX" ]; then
     if [ ! -z "$NGINX" ]; then
         tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.tpl"
         tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.tpl"
-        conf="$V_HOME/$user/conf/tmp_nginx.conf"
+        conf="$V_HOME/$user/conf/web/tmp_nginx.conf"
         add_web_config
         add_web_config
+        chown root:nginx $conf
+        chmod 640 $conf
 
 
         if [ "$SSL" = 'yes' ]; then
         if [ "$SSL" = 'yes' ]; then
             if [ "$SUSPEND" = 'yes' ]; then
             if [ "$SUSPEND" = 'yes' ]; then
@@ -102,16 +142,18 @@ for domain in $(shell_list) ; do
             fi
             fi
     
     
             tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
             tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
-            conf="$V_HOME/$user/conf/tmp_snginx.conf"
+            conf="$V_HOME/$user/conf/web/tmp_snginx.conf"
             add_web_config
             add_web_config
+            chown root:nginx $conf
+            chmod 640 $conf
         fi
         fi
 	ngix_change='yes'
 	ngix_change='yes'
     fi
     fi
 done
 done
 
 
 # Renaming tmp config
 # Renaming tmp config
-tmp_conf="$V_HOME/$user/conf/tmp_httpd.conf"
-conf="$V_HOME/$user/conf/httpd.conf"
+tmp_conf="$V_HOME/$user/conf/web/tmp_httpd.conf"
+conf="$V_HOME/$user/conf/web/httpd.conf"
 if [ -e "$tmp_conf" ]; then
 if [ -e "$tmp_conf" ]; then
     mv $tmp_conf $conf
     mv $tmp_conf $conf
 fi
 fi
@@ -119,14 +161,14 @@ fi
 # Checking include in main httpd.conf
 # Checking include in main httpd.conf
 main_conf='/etc/httpd/conf.d/vesta.conf'
 main_conf='/etc/httpd/conf.d/vesta.conf'
 main_conf_check=$(grep "$conf" $main_conf )
 main_conf_check=$(grep "$conf" $main_conf )
-if [ ! -z "$domains" ] && [ -z "$main_conf_check" ]; then
+if [ ! -z "$domain" ] && [ -z "$main_conf_check" ]; then
     echo "Include $conf" >>$main_conf
     echo "Include $conf" >>$main_conf
 fi
 fi
 
 
 # Checking ssl 
 # Checking ssl 
 if [ "$ssl_change" = 'yes' ]; then
 if [ "$ssl_change" = 'yes' ]; then
-    tmp_conf="$V_HOME/$user/conf/tmp_shttpd.conf"
-    conf="$V_HOME/$user/conf/shttpd.conf"
+    tmp_conf="$V_HOME/$user/conf/web/tmp_shttpd.conf"
+    conf="$V_HOME/$user/conf/web/shttpd.conf"
     mv $tmp_conf $conf
     mv $tmp_conf $conf
 
 
     # Checking include in main httpd.conf
     # Checking include in main httpd.conf
@@ -139,11 +181,10 @@ fi
 # Checking nginx
 # Checking nginx
 if [ "$ngix_change" = 'yes' ]; then
 if [ "$ngix_change" = 'yes' ]; then
     nginx_conf='/etc/nginx/conf.d/vesta_users.conf'
     nginx_conf='/etc/nginx/conf.d/vesta_users.conf'
-    tmp_conf="$V_HOME/$user/conf/tmp_nginx.conf"
-    conf="$V_HOME/$user/conf/nginx.conf"
+    tmp_conf="$V_HOME/$user/conf/web/tmp_nginx.conf"
+    conf="$V_HOME/$user/conf/web/nginx.conf"
     mv $tmp_conf $conf
     mv $tmp_conf $conf
 
 
-
     nginx_conf_check=$(grep "$conf" $nginx_conf )
     nginx_conf_check=$(grep "$conf" $nginx_conf )
     if [ -z "$nginx_conf_check" ]; then
     if [ -z "$nginx_conf_check" ]; then
         echo "include $conf;" >>$nginx_conf
         echo "include $conf;" >>$nginx_conf
@@ -151,8 +192,8 @@ if [ "$ngix_change" = 'yes' ]; then
 
 
     # Checking ssl for nginx
     # Checking ssl for nginx
     if [ "$ssl_change" = 'yes' ]; then
     if [ "$ssl_change" = 'yes' ]; then
-        tmp_conf="$V_HOME/$user/conf/tmp_snginx.conf"
-        conf="$V_HOME/$user/conf/snginx.conf"
+        tmp_conf="$V_HOME/$user/conf/web/tmp_snginx.conf"
+        conf="$V_HOME/$user/conf/web/snginx.conf"
         mv $tmp_conf $conf
         mv $tmp_conf $conf
         nginx_conf_check=$(grep "$conf" $nginx_conf )
         nginx_conf_check=$(grep "$conf" $nginx_conf )
         if [ -z "$nginx_conf_check" ]; then
         if [ -z "$nginx_conf_check" ]; then

+ 2 - 2
bin/v_restart_cron

@@ -22,8 +22,8 @@ source $V_CONF/vesta.conf
 if [ "$CRON_SYSTEM" = 'crond' ]; then
 if [ "$CRON_SYSTEM" = 'crond' ]; then
     /etc/init.d/crond 'reload' >/dev/null 2>&1
     /etc/init.d/crond 'reload' >/dev/null 2>&1
     if [ $? -ne 0 ]; then
     if [ $? -ne 0 ]; then
-        echo "$E_PARSING $V_EVENT"
-        exit $E_PARSING
+        echo "$E_RESTART $1"
+        exit $E_RESTART
     fi
     fi
 fi
 fi
 
 

+ 4 - 2
bin/v_restart_dns

@@ -11,7 +11,8 @@
 
 
 # Importing variables
 # Importing variables
 source /etc/profile.d/vesta.sh
 source /etc/profile.d/vesta.sh
-source $VESTA/conf/vesta.conf
+source $VESTA/conf/vars.conf
+source $V_CONF/vesta.conf
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -22,7 +23,8 @@ if [ "$DNS_SYSTEM" = 'bind' ]; then
     /etc/init.d/named reload >/dev/null 2>&1
     /etc/init.d/named reload >/dev/null 2>&1
     if [ $? -ne 0 ]; then
     if [ $? -ne 0 ]; then
         #$V_FUNC/report_issue 'sys' 'cron'
         #$V_FUNC/report_issue 'sys' 'cron'
-        echo "$E_RESTART_FAILED $V_EVENT"
+        echo "$E_RESTART $1"
+        exit $E_RESTART
     fi
     fi
 fi
 fi
 
 

+ 6 - 4
bin/v_restart_web

@@ -18,7 +18,8 @@ apache() {
     /etc/init.d/httpd 'graceful' >/dev/null 2>&1
     /etc/init.d/httpd 'graceful' >/dev/null 2>&1
     if [ $? -ne 0 ]; then
     if [ $? -ne 0 ]; then
         #$V_FUNC/report_issue 'web' 'apache'
         #$V_FUNC/report_issue 'web' 'apache'
-        echo "$E_RESTART_FAILED $V_EVENT"
+        echo "$E_RESTART $1"
+        exit $E_RESTART
     fi
     fi
 }
 }
 
 
@@ -26,7 +27,8 @@ nginx() {
     /etc/init.d/nginx 'reload' >/dev/null 2>&1
     /etc/init.d/nginx 'reload' >/dev/null 2>&1
     if [ $? -ne 0 ]; then
     if [ $? -ne 0 ]; then
         #$V_FUNC/report_issue 'web' 'nginx'
         #$V_FUNC/report_issue 'web' 'nginx'
-        echo "$E_RESTART_FAILED $V_EVENT"
+        echo "$E_RESTART $1"
+        exit $E_RESTART
     fi
     fi
 }
 }
 
 
@@ -37,11 +39,11 @@ nginx() {
 
 
 # Checking system
 # Checking system
 if [ "$WEB_SYSTEM" = 'apache' ]; then
 if [ "$WEB_SYSTEM" = 'apache' ]; then
-    apache
+    apache $1
 fi
 fi
 
 
 if [ "$PROXY_SYSTEM" = 'nginx' ]; then
 if [ "$PROXY_SYSTEM" = 'nginx' ]; then
-    nginx
+    nginx $1
 fi
 fi
 
 
 
 

+ 162 - 0
bin/v_restore_user

@@ -0,0 +1,162 @@
+#!/bin/bash
+# info: restore user
+# options: user backup
+#
+# The function for resotring user from backup.
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument defenition
+user=$1
+backup=$2
+
+# Importing variables
+source $VESTA/conf/vars.conf
+source $V_CONF/vesta.conf
+source $V_FUNC/shared.func
+source $V_FUNC/domain.func
+source $V_FUNC/db.func
+
+# 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 $V_CONF/ftp.backup.conf
+    if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ] ||\
+        [ -z "$BPATH" ]; then
+        echo "Error: Parsing error"
+        log_event 'debug' "$E_PARSING $V_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 $V_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
+format_validation 'user' 'backup'
+
+# Checking backup system is enabled
+is_system_enabled 'backup'
+
+# Checking load averages
+la=$(cat /proc/loadavg |cut -f 1 -d ' '|cut -f 1 -d '.')
+i=0
+while [ "$la" -ge "$V_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 $V_EVENT"
+        exit $E_LA
+    fi
+    (( ++i))
+done
+
+# Checking local backup existance
+if [ ! -e "$V_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 $V_BACKUP
+            echo "$(date "+%F %T") Downloading ftp backup"
+            ftpc "get $user.$backup.tar" >> /dev/null 2>/dev/null
+            echo "$(date "+%F %T") Downloaded $user.$backup.tar"
+        fi
+    fi
+fi
+
+if [ ! -e "$V_BACKUP/$user.$backup.tar" ]; then
+    echo "Error: $V_BACKUP/$user.$backup.tar  backup not found"
+    log_event 'debug' "$E_NOTEXIST $V_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 $V_BACKUP -d)
+echo "TMPDIR is $tmpdir"
+cd $tmpdir
+echo "$(date "+%F %T") Extracting files from backup"
+tar -xf $V_BACKUP/$user.$backup.tar
+echo "$(date "+%F %T") Backup has been unpacked"
+
+# Checking Vesta
+
+
+
+#----------------------------------------------------------#
+#                       Vesta                              #
+#----------------------------------------------------------#
+
+# Logging
+log_event 'system' "$V_EVENT"
+
+exit

+ 3 - 1
bin/v_update_user_bill

@@ -129,7 +129,8 @@ for user in $user_list; do
         check_month=$(grep -n "DATE='$DATE'" $billing|cut -f 1 -d :)
         check_month=$(grep -n "DATE='$DATE'" $billing|cut -f 1 -d :)
         if [ -z "$check_month" ]; then
         if [ -z "$check_month" ]; then
             # Updating as there no dublicates
             # Updating as there no dublicates
-            echo "$v_str" >>$billing
+            echo "$v_str" >> $billing
+            chmod 660 $billing
         else
         else
             # Replacing string with new data
             # Replacing string with new data
             sed -i "$check_month s/.*/$v_str/" $billing
             sed -i "$check_month s/.*/$v_str/" $billing
@@ -137,6 +138,7 @@ for user in $user_list; do
     else
     else
         # Creating billing log
         # Creating billing log
         echo "$v_str" >$billing
         echo "$v_str" >$billing
+        chmod 660 $billing
     fi
     fi
 done
 done
 
 

+ 1 - 1
bin/v_update_web_domain_stat

@@ -54,7 +54,7 @@ is_web_domain_value_exist '$STATS'
 stats=$(get_web_domain_value '$STATS')
 stats=$(get_web_domain_value '$STATS')
 
 
 # Checking config
 # Checking config
-config="$V_HOME/$user/conf/$stats.$domain.conf"
+config="$V_HOME/$user/conf/web/$stats.$domain.conf"
 if [ ! -e "$config" ]; then
 if [ ! -e "$config" ]; then
     echo "Error: Parsing error"
     echo "Error: Parsing error"
     log_event 'debug' "$E_PARSING $V_EVENT"
     log_event 'debug' "$E_PARSING $V_EVENT"

+ 1 - 0
conf/vars.conf

@@ -52,3 +52,4 @@ E_SSH=16
 E_DB=17
 E_DB=17
 E_RRD=18
 E_RRD=18
 E_UPDATE=19
 E_UPDATE=19
+E_RESTART=20

+ 4 - 6
func/domain.func

@@ -136,7 +136,6 @@ update_domain_zone() {
     # Definigng variables
     # Definigng variables
     line=$(grep "DOMAIN='$domain'" $V_USERS/$user/dns.conf)
     line=$(grep "DOMAIN='$domain'" $V_USERS/$user/dns.conf)
     fields='$RECORD\t$TTL\tIN\t$TYPE\t$VALUE'
     fields='$RECORD\t$TTL\tIN\t$TYPE\t$VALUE'
-    conf="/etc/namedb/$domain.db"
 
 
     # Checking serial
     # Checking serial
     if [ -e $conf ]; then
     if [ -e $conf ]; then
@@ -187,7 +186,6 @@ update_domain_zone() {
         VALUE=$(idn --quiet -a -t "$VALUE")
         VALUE=$(idn --quiet -a -t "$VALUE")
         eval echo -e "\"$fields\""|sed -e "s/%quote%/'/g" >> $conf
         eval echo -e "\"$fields\""|sed -e "s/%quote%/'/g" >> $conf
     done < $V_USERS/$user/dns/$domain
     done < $V_USERS/$user/dns/$domain
-
 }
 }
 
 
 get_next_dns_record() {
 get_next_dns_record() {
@@ -749,10 +747,10 @@ upd_web_domain_values() {
     fi
     fi
 
 
     # Defining SSL vars
     # Defining SSL vars
-    ssl_crt="$V_HOME/$user/conf/ssl.$domain.crt"
-    ssl_key="$V_HOME/$user/conf/ssl.$domain.key"
-    ssl_pem="$V_HOME/$user/conf/ssl.$domain.pem"
-    ssl_ca="$V_HOME/$user/conf/ssl.$domain.ca"
+    ssl_crt="$V_HOME/$user/conf/web/ssl.$domain.crt"
+    ssl_key="$V_HOME/$user/conf/web/ssl.$domain.key"
+    ssl_pem="$V_HOME/$user/conf/web/ssl.$domain.pem"
+    ssl_ca="$V_HOME/$user/conf/web/ssl.$domain.ca"
     if [ ! -e "$V_USERS/$user/ssl/$domain.ca" ]; then
     if [ ! -e "$V_USERS/$user/ssl/$domain.ca" ]; then
         ssl_ca_str='#'
         ssl_ca_str='#'
     fi
     fi

+ 1 - 1
func/shared.func

@@ -675,7 +675,7 @@ get_user_value() {
 restart_schedule() {
 restart_schedule() {
     type="$1"
     type="$1"
     if  [ -z "$RESTART_PERIOD" ]; then
     if  [ -z "$RESTART_PERIOD" ]; then
-        $V_BIN/v_restart_"$type"
+        $V_BIN/v_restart_"$type" "$V_EVENT"
     else
     else
         echo "$type" >> $V_QUEUE/restart.pipe
         echo "$type" >> $V_QUEUE/restart.pipe
     fi
     fi