Sfoglia il codice sorgente

Merge branch 'bugfix-backend' into develop

Kristan Kenney 6 anni fa
parent
commit
d106876d6e

+ 1 - 0
bin/v-backup-user

@@ -937,6 +937,7 @@ if [ -e "$BACKUP/$user.log" ]; then
     email=$(get_user_value '$CONTACT')
     cat $BACKUP/$user.log |$SENDMAIL -s "$subj" $email $notify
     rm $BACKUP/$user.log
+    $BIN/v-add-user-notification $user "$subj" "$email"
 fi
 
 # Logging

+ 0 - 4
bin/v-change-sys-hestia-ssl

@@ -49,10 +49,6 @@ else
     is_web_domain_cert_valid
 fi
 
-# Moving old certificate
-mv $HESTIA/ssl/certificate.crt $HESTIA/ssl/certificate.crt.back
-mv $HESTIA/ssl/certificate.key $HESTIA/ssl/certificate.key.back
-
 # Adding new certificate
 cp -f $ssl_dir/certificate.crt $HESTIA/ssl/certificate.crt
 cp -f $ssl_dir/certificate.key $HESTIA/ssl/certificate.key

+ 10 - 1
bin/v-change-sys-release

@@ -36,11 +36,20 @@ if [ -z "$branch" ]; then
     echo ""
     exit
 else
+    # Check that requested branch exists
+    echo "Checking for existence of $branch branch..."
+    branch_check=$(curl -s --head -w %{http_code} https://raw.githubusercontent.com/hestiacp/hestiacp/$branch/src/deb/hestia/control -o /dev/null)
+    if [ $branch_check -ne "200" ]; then
+        echo "Error: invalid branch name specified."
+        exit 1
+    fi
+
     # Remove old branch variable
     sed -i "/RELEASE_BRANCH/d" $HESTIA/conf/hestia.conf
+    
     # Set new branch variable
     echo "RELEASE_BRANCH='$branch'" >> $HESTIA/conf/hestia.conf
-    echo "Changed system to follow release branch: $branch"
+    echo "Changed system release to update from Git branch: $branch"
 fi
 
 #----------------------------------------------------------#

+ 5 - 15
bin/v-change-sys-webmail

@@ -9,9 +9,6 @@
 #                    Variable&Function                     #
 #----------------------------------------------------------#
 
-# Argument definition
-WEBMAIL=$1
-
 # Includes
 source $HESTIA/func/main.sh
 source $HESTIA/conf/hestia.conf
@@ -23,12 +20,6 @@ export $WEBMAIL_ALIAS
 OLD_ALIAS=$WEBMAIL_ALIAS
 NEW_ALIAS=$1
 
-#----------------------------------------------------------#
-#                    Verifications                         #
-#----------------------------------------------------------#
-
-check_args '1' "$#" 'WEBMAIL'
-
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
@@ -41,18 +32,17 @@ for user in `ls /usr/local/hestia/data/users/`; do
 done
 
 # Set new webmail alias
-sed -i "s|WEBMAIL_ALIAS='$OLD_ALIAS'|WEBMAIL_ALIAS='$NEW_ALIAS'|gI" $HESTIA/conf/hestia.conf
+$BIN/v-change-sys-config-value 'WEBMAIL_ALIAS' $NEW_ALIAS
 
 for user in `ls /usr/local/hestia/data/users/`; do
     for domain in $($BIN/v-list-web-domains $user plain |cut -f 1); do
-        echo "Changing webmail alias for $domain"
         $BIN/v-add-webmail $user $domain
     done
 done
 
-# Update alias (non-subdomain) configuration to match
-sed -i "s|Alias \/webmail|Alias \/$NEW_ALIAS|gI" /etc/apache2/conf.d/roundcube.conf
-sed -i "s|location \/webmail|location \/$NEW_ALIAS|gI" /etc/nginx/conf.d/webmail.inc
+# Update global directory alias configuration
+sed -i "s|Alias \/$OLD_ALIAS|Alias \/$NEW_ALIAS|gI" /etc/apache2/conf.d/roundcube.conf
+sed -i "s|location \/$OLD_ALIAS|location \/$NEW_ALIAS|gI" /etc/nginx/conf.d/webmail.inc
 
 #----------------------------------------------------------#
 #                       Hestia                             #
@@ -63,7 +53,7 @@ $BIN/v-restart-web $restart
 $BIN/v-restart-proxy $restart
 
 # Logging
-log_history "changed system webmail alias to $NEW_ALIAS"
+log_history "changed global webmail alias to $NEW_ALIAS"
 log_event "$OK" "$ARGUMENTS"
 
 exit

+ 2 - 2
bin/v-change-web-domain-dirlist

@@ -51,7 +51,7 @@ if [ "$mode" = "on" ]; then
         # Enable directory listing for SSL-enforced domains
         sed -i "s/-Index/+Index/g" $HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.ssl.conf
     fi
-    echo "INFO: Enabled directory browsing for $domain."
+    echo "Enabled directory browsing for $domain."
 else
     # Disable directory listing
     sed -i "s/+Index/-Index/g" $HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.conf
@@ -59,7 +59,7 @@ else
         # Enable directory listing for SSL-enforced domains
         sed -i "s/+Index/-Index/g" $HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.ssl.conf
     fi
-    echo "INFO: Disabled directory browsing for $domain."
+    echo "Disabled directory browsing for $domain."
 fi
 
 

+ 65 - 0
bin/v-rebuild-database

@@ -0,0 +1,65 @@
+#!/bin/bash
+# info: rebuild databases
+# options: USER
+#
+# The function for rebuilding a single database for a user
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument definition
+user=$1
+database=$2
+
+# Includes
+source $HESTIA/func/main.sh
+source $HESTIA/func/db.sh
+source $HESTIA/func/rebuild.sh
+source $HESTIA/conf/hestia.conf
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+check_args '2' "$#" 'USER DATABASE'
+is_format_valid 'user'
+is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
+is_object_valid 'user' 'USER' "$user"
+is_object_valid 'db' 'DB' "$database"
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Get database values
+get_database_values
+
+# Switching on db type
+case $TYPE in
+    mysql) rebuild_mysql_database ;;
+    pgsql) rebuild_pgsql_database ;;
+esac
+
+U_DISK_DB=$((U_DISK_DB + U_DISK))
+U_DATABASES=$((U_DATABASES + 1))
+if [ "$SUSPENDED" = 'yes' ]; then
+    SUSPENDED_DB=$((SUSPENDED_DB + 1))
+fi
+
+update_user_value "$user" '$SUSPENDED_DB' "$SUSPENDED_DB"
+update_user_value "$user" '$U_DATABASES' "$U_DATABASES"
+update_user_value "$user" '$U_DISK_DB' "$U_DISK_DB"
+
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+# Logging
+log_event "$OK" "$ARGUMENTS"
+
+exit

+ 70 - 0
bin/v-rebuild-mail-domain

@@ -0,0 +1,70 @@
+#!/bin/bash
+# info: rebuild mail domain
+# options: USER DOMAIN
+#
+# The function rebuilds configuration files for a single domain.
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument definition
+user=$1
+domain=$2
+
+# Includes
+source $HESTIA/func/main.sh
+source $HESTIA/func/domain.sh
+source $HESTIA/func/rebuild.sh
+source $HESTIA/conf/hestia.conf
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+check_args '2' "$#" 'USER DOMAIN'
+is_format_valid 'user'
+is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
+is_object_valid 'user' 'USER' "$user"
+is_object_unsuspended 'user' 'USER' "$user"
+is_object_valid 'mail' 'DOMAIN' "$domain"
+
+if [ "$MAIL_SYSTEM" = 'remote' ]; then
+    exit
+fi
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Rebuild mail domain configuration
+rebuild_mail_domain_conf
+
+# Rebuild webmail configuration
+if [ ! -z "$WEB_SYSTEM" ] || [ ! -z "$PROXY_SYSTEM" ]; then
+    $BIN/v-delete-webmail $user $domain ''
+    $BIN/v-add-webmail $user $domain ''
+fi
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+# Updating counters
+update_user_value "$user" '$U_MAIL_DOMAINS' "$U_MAIL_DOMAINS"
+update_user_value "$user" '$U_MAIL_DKIM' "$U_MAIL_DKIM"
+update_user_value "$user" '$U_MAIL_ACCOUNTS' "$U_MAIL_ACCOUNTS"
+update_user_value "$user" '$U_MAIL_SSL' "$U_MAIL_SSL"
+update_user_value "$user" '$SUSPENDED_MAIL' "$SUSPENDED_MAIL"
+update_user_value "$user" '$U_DISK_MAIL' "$U_DISK_MAIL"
+
+# Update disk usage statistics
+$BIN/v-update-user-disk $user
+
+# Logging
+log_event "$OK" "$ARGUMENTS"
+
+exit

+ 3 - 9
bin/v-rebuild-mail-domains

@@ -45,19 +45,12 @@ U_MAIL_SSL=0
 SUSPENDED_MAIL=0
 U_DISK_MAIL=0
 
-# Checking mail folder
-if [ ! -d "$USER_DATA/mail" ]; then
-    rm -f $USER_DATA/mail
-    mkdir $USER_DATA/mail
-fi
-
 # Starting loop
 for domain in $(search_objects 'mail' 'SUSPENDED' "*" 'DOMAIN'); do
     rebuild_mail_domain_conf
     if [ ! -z "$WEB_SYSTEM" ] || [ ! -z "$PROXY_SYSTEM" ]; then
         $BIN/v-delete-webmail $user $domain ''
-        $BIN/v-add-webmail $user $domain '' 
-        sleep 0.5
+        $BIN/v-add-webmail $user $domain ''
     fi
 done
 
@@ -74,7 +67,8 @@ update_user_value "$user" '$U_MAIL_SSL' "$U_MAIL_SSL"
 update_user_value "$user" '$SUSPENDED_MAIL' "$SUSPENDED_MAIL"
 update_user_value "$user" '$U_DISK_MAIL' "$U_DISK_MAIL"
 
-recalc_user_disk_usage
+# Update disk usage statistics
+$BIN/v-update-user-disk $user
 
 # Logging
 log_event "$OK" "$ARGUMENTS"

+ 6 - 0
bin/v-rebuild-user

@@ -44,6 +44,12 @@ fi
 # Rebuild user
 rebuild_user_conf
 
+# Update user counters
+$BIN/v-update-user-counters $user
+
+# Update account usage statistics
+$BIN/v-update-user-stats $user
+
 
 #----------------------------------------------------------#
 #                       Hestia                             #

+ 50 - 0
bin/v-rebuild-users

@@ -0,0 +1,50 @@
+#!/bin/bash
+# info: rebuild system user
+# options: USER [RESTART]
+#
+# The function rebuilds system user accounts.
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument definition
+restart=$1
+
+# Includes
+source $HESTIA/func/main.sh
+source $HESTIA/func/rebuild.sh
+source $HESTIA/conf/hestia.conf
+
+# Export sbin
+export PATH=$PATH:/usr/sbin
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+check_args '1' "$#" 'USER [RESTART]'
+is_format_valid 'user'
+is_object_valid 'user' 'USER' "$user"
+is_object_unsuspended 'user' 'USER' "$user"
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Rebuild loop
+for user in $($BIN/v-list-users plain |cut -f 1); do
+    $BIN/v-rebuild-user $user
+done
+
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+# Logging
+log_event "$OK" "$ARGUMENTS"
+
+exit

+ 2 - 1
bin/v-schedule-letsencrypt-domain

@@ -48,10 +48,11 @@ fi
 $BIN/v-add-cron-letsencrypt-job
 
 # Adding LE task
-echo "$BIN/v-add-letsencrypt-domain $user $domain '$aliases' yes yes" \
+echo "$BIN/v-add-letsencrypt-domain $user $domain '$aliases' no yes" \
     >> $HESTIA/data/queue/letsencrypt.pipe
 
 
+
 #----------------------------------------------------------#
 #                       Hestia                             #
 #----------------------------------------------------------#

+ 30 - 28
bin/v-update-host-certificate

@@ -1,7 +1,6 @@
 #!/bin/bash
-# info: update hosts certificates for exim, dovecot & hestia-nginx
-# options: user
-# options: hostname
+# info: update host certificate for hestia
+# options: USER HOSTNAME
 #
 # Function updates certificates for hestia
 
@@ -12,7 +11,7 @@
 
 whoami=$(whoami)
 if [ "$whoami" != "root" ] && [ "$whoami" != "admin" ] ; then
-    echo "You must be root or admin to execute this script";
+    echo "Error: this script must be run as root or admin.";
     exit 1;
 fi
 
@@ -40,8 +39,8 @@ is_object_unsuspended 'user' 'USER' "$user"
 is_object_valid 'web' 'DOMAIN' "$hostname"
 is_object_unsuspended 'web' 'DOMAIN' "$hostname"
 
-if [ ! -f "/home/$user/conf/web/$hostname/ssl.$hostname.pem" ]; then
-    echo "This domain does not have certificate";
+if [ ! -f "/home/$user/conf/web/$hostname/ssl/$hostname.pem" ]; then
+    echo "Error: domain $hostname does not have an SSL certificate.";
     exit 1;
 fi
 
@@ -53,31 +52,34 @@ fi
 backup_datetime=`date '+%Y-%m-%d_%H-%M-%S'`
 
 # Copy hostnames certificates from user dir
-cp /home/$user/conf/web/$hostname/$hostname.pem $HESTIA/ssl/certificate.crt
-cp /home/$user/conf/web/$hostname/$hostname.key $HESTIA/ssl/certificate.key
-
-# Checking exim username for later chowning
-exim_user="exim";
-check_exim_username=$(grep -c '^Debian-exim:' /etc/passwd)
-if [ "$check_exim_username" -eq 1 ]; then
-    exim_user="Debian-exim"
+cp /home/$user/conf/web/$hostname/ssl/$hostname.pem $HESTIA/ssl/certificate.crt
+cp /home/$user/conf/web/$hostname/ssl/$hostname.key $HESTIA/ssl/certificate.key
+
+# Enable fallback support for mail domains that do not support SSL
+if [[ "$MAIL_SYSTEM" =~ exim ]]; then
+    # Checking exim username for later chowning
+    exim_user="exim";
+    check_exim_username=$(grep -c '^Debian-exim:' /etc/passwd)
+    if [ "$check_exim_username" -eq 1 ]; then
+        exim_user="Debian-exim"
+    fi
+
+    # Assign exim permissions to certificate
+    chown $exim_user:mail $HESTIA/ssl/certificate.crt
+    chown $exim_user:mail $HESTIA/ssl/certificate.key
 fi
 
-# Assign exim permissions
-chown $exim_user:mail $HESTIA/ssl/certificate.crt
-chown $exim_user:mail $HESTIA/ssl/certificate.key
-
-# Restart exim, dovecot & hestia
-$BIN/v-restart-mail
-if [ ! -z "$IMAP_SYSTEM" ]; then
-    $BIN/v-restart-service "$IMAP_SYSTEM"
-fi
-if [ ! -z "$FTP_SYSTEM" ]; then
-    $BIN/v-restart-service "$FTP_SYSTEM"
-fi
-if [ -f "/var/run/hestia-nginx.pid" ]; then
-    kill -HUP $(cat /var/run/hestia-nginx.pid)
+# Restart services
+$BIN/v-restart-web
+$BIN/v-restart-proxy
+if [ ! -z "$MAIL_SYSTEM" ]; then
+    # Restart exim (and dovecot if applicable)
+    $BIN/v-restart-mail
+    if [ ! -z "$IMAP_SYSTEM" ]; then
+        $BIN/v-restart-service "$IMAP_SYSTEM"
+    fi
 fi
+$BIN/v-restart-service "hestia"
 
 #----------------------------------------------------------#
 #                       Hestia                             #

+ 58 - 5
bin/v-update-sys-hestia-git

@@ -1,8 +1,52 @@
+#!/bin/bash
+
 # Autocompile Script for HestiaCP deb Files.
 
 # Define download function
 download_file() {
-  wget $1 -q --show-progress --progress=bar:force
+  local url=$1
+  local destination=$2
+  local force=$3
+
+  # Default destination is the curent working directory
+  local dstopt=""
+
+  if [ ! -z "$(echo "$url" | grep -E "\.(gz|gzip|bz2|zip|xz)$")" ]; then
+    # When an archive file is downloaded it will be first saved localy
+    dstopt="--directory-prefix=$ARCHIVE_DIR"
+    local is_archive="true"
+    local filename="${url##*/}"
+    if [ -z "$filename" ]; then
+      >&2 echo "[!] No filename was found in url, exiting ($url)"
+      exit 1
+    fi
+    if [ ! -z "$force" ] && [ -f "$ARCHIVE_DIR/$filename" ]; then
+      rm -f $ARCHIVE_DIR/$filename
+    fi
+  elif [ ! -z "$destination" ]; then
+    # Plain files will be written to specified location
+    dstopt="-O $destination"
+  fi
+  # check for corrupted archive
+  if [ -f "$ARCHIVE_DIR/$filename" ] && [ "$is_archive" = "true" ]; then
+    tar -tzf "$ARCHIVE_DIR/$filename" > /dev/null 2>&1
+    if [ $? -ne 0 ]; then
+      >&2 echo "[!] Archive $ARCHIVE_DIR/$filename is corrupted, redownloading"
+      rm -f $ARCHIVE_DIR/$filename
+    fi
+  fi
+
+  if [ ! -f "$ARCHIVE_DIR/$filename" ]; then
+    wget $url -q $dstopt --show-progress --progress=bar:force --limit-rate=3m
+  fi
+
+  if [ ! -z "$destination" ] && [ "$is_archive" = "true" ]; then
+    if [ "$destination" = "-" ]; then
+      cat "$ARCHIVE_DIR/$filename"
+    elif [ -d "$(dirname $destination)" ]; then
+      cp "$ARCHIVE_DIR/$filename" "$destination"
+    fi
+  fi
 }
 
 # Set compiling directory
@@ -11,7 +55,9 @@ DEB_DIR="$BUILD_DIR/debs/"
 INSTALL_DIR='/usr/local/hestia'
 
 # Set Version for compiling
-HESTIA_V='0.10.0-190430_amd64'
+BUILD_VER=$(curl -s https://raw.githubusercontent.com/hestiacp/hestiacp/$branch/src/deb/hestia/control | grep "Version:" | cut -d' ' -f2)
+BUILD_ARCH='amd64'
+HESTIA_V="${BUILD_VER}_${BUILD_ARCH}"
 NGINX_V='1.16.0'
 OPENSSL_V='1.1.1b'
 PCRE_V='8.43'
@@ -30,12 +76,18 @@ timestamp() {
     date +%s
 }
 
-branch=$2
-install=$3
+branch=$1
+install=$2
 
 # Set install flags
 if [ ! -z "$1" ]; then
-  branch=$1
+    branch_check=$(curl -s --head -w %{http_code} https://raw.githubusercontent.com/hestiacp/hestiacp/$branch/src/deb/hestia/control -o /dev/null)
+    if [ $branch_check -ne "200" ]; then
+        echo "Error: invalid branch name specified."
+        exit 1
+    else
+      branch=$1
+    fi
 else
   source /usr/local/hestia/conf/hestia.conf
   branch=$RELEASE_BRANCH
@@ -47,6 +99,7 @@ else
   install="y"
 fi
 
+
 # Install needed software
 echo "Updating system APT repositories..."
 apt-get -qq update > /dev/null 2>&1

+ 3 - 3
bin/v-update-user-quota

@@ -30,8 +30,8 @@ is_object_valid 'user' 'USER' "$user"
 #                       Action                             #
 #----------------------------------------------------------#
 
-# Updating disk quota
-# Had quota equals package value. Soft quota equals 90% of package value for warnings.
+# Update disk quota
+# Hard quota quals package value. Soft quota equals 90% of package value.
 quota=$(get_user_value '$DISK_QUOTA')
 soft=$(echo "$quota * 1024"|bc |cut -f 1 -d .)
 hard=$(echo "$quota * 1024"|bc |cut -f 1 -d .)
@@ -39,7 +39,7 @@ hard=$(echo "$quota * 1024"|bc |cut -f 1 -d .)
 # Searching home mount point
 mnt=$(df -P /home |awk '{print $6}' |tail -n1)
 
-# Checking unlinmited quota
+# Checking unlimited quota
 if [ "$quota" = 'unlimited' ]; then
     setquota $user 0 0 0 0 $mnt 2>/dev/null
 else

+ 5 - 5
bin/v-update-user-stats

@@ -44,7 +44,7 @@ else
     user_list="$user"
 fi
 
-# Reset overal statistics
+# Reset overall statistics
 TOTAL_IP_OWNED=0
 TOTAL_U_DISK=0
 TOTAL_U_DISK_DIRS=0
@@ -92,10 +92,10 @@ for user in $user_list; do
     # Updating user stats log
     stats="$USER_DATA/stats.log"
     if [ -e "$stats" ]; then
-        # Checking dublicates
+        # Checking duplicates
         check_month=$(grep -n "DATE='$DATE'" $stats|cut -f 1 -d :)
         if [ -z "$check_month" ]; then
-            # Updating as there no dublicates
+            # Updating as there no duplicates
             echo "$s" >> $stats
             chmod 660 $stats
         else
@@ -150,10 +150,10 @@ s="$s U_CRON_JOBS='$TOTAL_U_CRON_JOBS' U_BACKUPS='$TOTAL_U_BACKUPS'"
 s="$s U_USERS='$TOTAL_USERS'"
 
 if [ -e "$stats" ]; then
-    # Checking dublicates
+    # Checking duplicates
     check_month=$(grep -n "DATE='$DATE'" $stats|cut -f 1 -d :)
     if [ -z "$check_month" ]; then
-        # Updating as there no dublicates
+        # Updating as there no duplicates
         echo "$s" >> $stats
         chmod 660 $stats
     else

+ 5 - 1
func/rebuild.sh

@@ -451,6 +451,11 @@ rebuild_mail_domain_conf() {
         SUSPENDED_MAIL=$((SUSPENDED_MAIL +1))
     fi
 
+    if [ ! -d "$USER_DATA/mail" ]; then
+        rm -f $USER_DATA/mail
+        mkdir $USER_DATA/mail
+    fi
+
     # Rebuilding exim config structure
     if [[ "$MAIL_SYSTEM" =~ exim ]]; then
         rm -f /etc/$MAIL_SYSTEM/domains/$domain_idn
@@ -552,7 +557,6 @@ rebuild_mail_domain_conf() {
 
     # Add missing SSL configuration flags to existing domains
     # for per-domain SSL migration
-
     sslcheck=$(grep "DOMAIN='$domain'" $USER_DATA/mail.conf | grep SSL)
     if [ -z "$sslcheck" ]; then
         sed -i "s|$domain'|$domain' SSL='no' LETSENCRYPT='no'|g" $USER_DATA/mail.conf