Răsfoiți Sursa

Re-format shell files, nginx files and .sql files

Jakob Bouchard 3 ani în urmă
părinte
comite
3d8e6b15e1
100 a modificat fișierele cu 3516 adăugiri și 3504 ștergeri
  1. 6 6
      .github/workflows/lint.yml
  2. 13 14
      bin/v-acknowledge-user-notification
  3. 28 28
      bin/v-add-access-key
  4. 153 152
      bin/v-add-backup-host
  5. 16 16
      bin/v-add-cron-hestia-autoupdate
  6. 4 4
      bin/v-add-cron-job
  7. 1 1
      bin/v-add-cron-letsencrypt-job
  8. 1 1
      bin/v-add-cron-reports
  9. 1 1
      bin/v-add-cron-restart-job
  10. 16 15
      bin/v-add-database
  11. 47 42
      bin/v-add-database-host
  12. 8 8
      bin/v-add-database-temp-user
  13. 58 58
      bin/v-add-dns-domain
  14. 12 12
      bin/v-add-dns-on-web-alias
  15. 32 32
      bin/v-add-dns-record
  16. 12 12
      bin/v-add-domain
  17. 12 13
      bin/v-add-fastcgi-cache
  18. 10 11
      bin/v-add-firewall-ban
  19. 51 29
      bin/v-add-firewall-chain
  20. 65 66
      bin/v-add-firewall-ipset
  21. 19 20
      bin/v-add-firewall-rule
  22. 29 29
      bin/v-add-fs-archive
  23. 8 8
      bin/v-add-fs-directory
  24. 8 8
      bin/v-add-fs-file
  25. 378 381
      bin/v-add-letsencrypt-domain
  26. 18 18
      bin/v-add-letsencrypt-host
  27. 42 43
      bin/v-add-letsencrypt-user
  28. 31 33
      bin/v-add-mail-account
  29. 5 5
      bin/v-add-mail-account-alias
  30. 6 6
      bin/v-add-mail-account-autoreply
  31. 10 10
      bin/v-add-mail-account-forward
  32. 8 9
      bin/v-add-mail-account-fwd-only
  33. 82 82
      bin/v-add-mail-domain
  34. 1 1
      bin/v-add-mail-domain-antispam
  35. 1 1
      bin/v-add-mail-domain-antivirus
  36. 2 2
      bin/v-add-mail-domain-catchall
  37. 15 15
      bin/v-add-mail-domain-dkim
  38. 2 6
      bin/v-add-mail-domain-reject
  39. 6 6
      bin/v-add-mail-domain-smtp-relay
  40. 29 29
      bin/v-add-mail-domain-ssl
  41. 87 87
      bin/v-add-mail-domain-webmail
  42. 41 42
      bin/v-add-remote-dns-domain
  43. 22 21
      bin/v-add-remote-dns-host
  44. 27 28
      bin/v-add-remote-dns-record
  45. 3 3
      bin/v-add-sys-api-ip
  46. 23 23
      bin/v-add-sys-dependencies
  47. 23 23
      bin/v-add-sys-filemanager
  48. 3 3
      bin/v-add-sys-firewall
  49. 113 113
      bin/v-add-sys-ip
  50. 23 23
      bin/v-add-sys-pma-sso
  51. 25 25
      bin/v-add-sys-quota
  52. 91 92
      bin/v-add-sys-rainloop
  53. 133 133
      bin/v-add-sys-roundcube
  54. 28 28
      bin/v-add-sys-sftp-jail
  55. 1 1
      bin/v-add-sys-smtp-relay
  56. 86 86
      bin/v-add-user
  57. 2 2
      bin/v-add-user-2fa
  58. 5 5
      bin/v-add-user-composer
  59. 14 14
      bin/v-add-user-notification
  60. 65 66
      bin/v-add-user-package
  61. 19 15
      bin/v-add-user-sftp-jail
  62. 21 21
      bin/v-add-user-sftp-key
  63. 2 2
      bin/v-add-user-ssh-key
  64. 3 3
      bin/v-add-user-wp-cli
  65. 70 70
      bin/v-add-web-domain
  66. 14 14
      bin/v-add-web-domain-alias
  67. 1 1
      bin/v-add-web-domain-allow-users
  68. 20 21
      bin/v-add-web-domain-backend
  69. 33 32
      bin/v-add-web-domain-ftp
  70. 38 37
      bin/v-add-web-domain-httpauth
  71. 3 3
      bin/v-add-web-domain-proxy
  72. 35 35
      bin/v-add-web-domain-redirect
  73. 15 15
      bin/v-add-web-domain-ssl
  74. 10 11
      bin/v-add-web-domain-ssl-force
  75. 6 6
      bin/v-add-web-domain-ssl-hsts
  76. 6 6
      bin/v-add-web-domain-ssl-preset
  77. 22 23
      bin/v-add-web-domain-stats
  78. 10 9
      bin/v-add-web-domain-stats-user
  79. 38 38
      bin/v-add-web-php
  80. 580 586
      bin/v-backup-user
  81. 16 16
      bin/v-backup-users
  82. 3 3
      bin/v-change-cron-job
  83. 16 13
      bin/v-change-database-host-password
  84. 16 17
      bin/v-change-database-owner
  85. 4 3
      bin/v-change-database-password
  86. 20 19
      bin/v-change-database-user
  87. 14 14
      bin/v-change-dns-domain-dnssec
  88. 7 7
      bin/v-change-dns-domain-exp
  89. 9 9
      bin/v-change-dns-domain-ip
  90. 9 9
      bin/v-change-dns-domain-soa
  91. 52 52
      bin/v-change-dns-domain-tpl
  92. 9 9
      bin/v-change-dns-domain-ttl
  93. 28 29
      bin/v-change-dns-record
  94. 9 9
      bin/v-change-dns-record-id
  95. 231 231
      bin/v-change-domain-owner
  96. 13 13
      bin/v-change-firewall-rule
  97. 11 11
      bin/v-change-fs-file-permission
  98. 17 16
      bin/v-change-mail-account-password
  99. 8 8
      bin/v-change-mail-account-quota
  100. 17 17
      bin/v-change-mail-account-rate-limit

+ 6 - 6
.github/workflows/lint.yml

@@ -11,13 +11,13 @@ jobs:
     name: ShellCheck
     runs-on: ubuntu-latest
     steps:
-    - name: Checkout code
-      uses: actions/checkout@v3
+      - name: Checkout code
+        uses: actions/checkout@v3
 
-    - name: Run ShellCheck
-      uses: ludeeus/action-shellcheck@6d3f514f44620b9d4488e380339edc0d9bbe2fba
-      with:
-        severity: error
+      - name: Run ShellCheck
+        uses: ludeeus/action-shellcheck@6d3f514f44620b9d4488e380339edc0d9bbe2fba
+        with:
+          severity: error
 
   prettier:
     name: Prettier

+ 13 - 14
bin/v-acknowledge-user-notification

@@ -38,32 +38,31 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 
 # Updating notification
-update_object_value 'notifications' 'NID' "$id" '$ACK' 'yes' 2>/dev/null
+update_object_value 'notifications' 'NID' "$id" '$ACK' 'yes' 2> /dev/null
 
 # Checking last notification
 if [ -e "$USER_DATA/notifications.conf" ]; then
-    if [ -z "$(grep NID= $USER_DATA/notifications.conf)" ]; then
-        notice='no'
-    fi
-    if [ -z "$(grep "ACK='no'" $USER_DATA/notifications.conf)" ]; then
-        notice='no'
-    fi
+	if [ -z "$(grep NID= $USER_DATA/notifications.conf)" ]; then
+		notice='no'
+	fi
+	if [ -z "$(grep "ACK='no'" $USER_DATA/notifications.conf)" ]; then
+		notice='no'
+	fi
 else
-    notice='no'
+	notice='no'
 fi
 
-
 #----------------------------------------------------------#
 #                       Hestia                             #
 #----------------------------------------------------------#
 
 # Updating notification counter
 if [ "$notice" = 'no' ]; then
-    if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
-        sed -i "s/^TIME/NOTIFICATIONS='no'\nTIME/g" $USER_DATA/user.conf
-    else
-        update_user_value "$user" '$NOTIFICATIONS' "no"
-    fi
+	if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
+		sed -i "s/^TIME/NOTIFICATIONS='no'\nTIME/g" $USER_DATA/user.conf
+	else
+		update_user_value "$user" '$NOTIFICATIONS' "no"
+	fi
 fi
 
 # Logging

+ 28 - 28
bin/v-add-access-key

@@ -26,21 +26,21 @@ source $HESTIA/func/main.sh
 source_conf "$HESTIA/conf/hestia.conf"
 
 keygen() {
-    local LENGTH=${1:-20}
-    local USE_SPECIAL_CHARACTERS="${2:-no}"
+	local LENGTH=${1:-20}
+	local USE_SPECIAL_CHARACTERS="${2:-no}"
 
-    local MATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
-    if [[ "$USE_SPECIAL_CHARACTERS" == "yes" ]]; then
-        MATRIX+='_-='
-    fi
+	local MATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
+	if [[ "$USE_SPECIAL_CHARACTERS" == "yes" ]]; then
+		MATRIX+='_-='
+	fi
 
-    local PASS N
-    while [ ${N:=1} -le $LENGTH ]; do
-        PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"
-        let N+=1
-    done
+	local PASS N
+	while [ ${N:=1} -le $LENGTH ]; do
+		PASS="$PASS${MATRIX:$(($RANDOM % ${#MATRIX})):1}"
+		let N+=1
+	done
 
-    echo "$PASS"
+	echo "$PASS"
 }
 
 access_key_id="$(keygen)"
@@ -53,8 +53,8 @@ check_hestia_demo_mode
 permissions="$(cleanup_key_permissions "$permissions")"
 
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 #----------------------------------------------------------#
 #                    Verifications                         #
@@ -70,26 +70,26 @@ is_key_permissions_format_valid "$permissions" "$user"
 #----------------------------------------------------------#
 
 if [ ! -d "$HESTIA/data/access-keys/" ]; then
-    mkdir -p $HESTIA/data/access-keys/
-    chown root:root $HESTIA/data/access-keys/
-    chmod 750 $HESTIA/data/access-keys/
+	mkdir -p $HESTIA/data/access-keys/
+	chown root:root $HESTIA/data/access-keys/
+	chmod 750 $HESTIA/data/access-keys/
 fi
 
 if [[ -e "$HESTIA/data/access-keys/${access_key_id}" ]]; then
-    while [[ -e "$HESTIA/data/access-keys/${access_key_id}" ]]; do
-        access_key_id=$(keygen)
-    done
+	while [[ -e "$HESTIA/data/access-keys/${access_key_id}" ]]; do
+		access_key_id=$(keygen)
+	done
 fi
 
-echo "SECRET_ACCESS_KEY='$secret_access_key'" >"$HESTIA/data/access-keys/${access_key_id}"
-echo "USER='$user'" >>"$HESTIA/data/access-keys/${access_key_id}"
-echo "PERMISSIONS='$permissions'" >>"$HESTIA/data/access-keys/${access_key_id}"
-echo "COMMENT='$comment'" >>"$HESTIA/data/access-keys/${access_key_id}"
-echo "TIME='$time'" >>"$HESTIA/data/access-keys/${access_key_id}"
-echo "DATE='$date'" >>"$HESTIA/data/access-keys/${access_key_id}"
+echo "SECRET_ACCESS_KEY='$secret_access_key'" > "$HESTIA/data/access-keys/${access_key_id}"
+echo "USER='$user'" >> "$HESTIA/data/access-keys/${access_key_id}"
+echo "PERMISSIONS='$permissions'" >> "$HESTIA/data/access-keys/${access_key_id}"
+echo "COMMENT='$comment'" >> "$HESTIA/data/access-keys/${access_key_id}"
+echo "TIME='$time'" >> "$HESTIA/data/access-keys/${access_key_id}"
+echo "DATE='$date'" >> "$HESTIA/data/access-keys/${access_key_id}"
 # TODO Index reserved for future implementation
-echo "EXPIRES_IN=''" >>"$HESTIA/data/access-keys/${access_key_id}"
-echo "IP=''" >>"$HESTIA/data/access-keys/${access_key_id}"
+echo "EXPIRES_IN=''" >> "$HESTIA/data/access-keys/${access_key_id}"
+echo "IP=''" >> "$HESTIA/data/access-keys/${access_key_id}"
 
 chmod 640 "$HESTIA/data/access-keys/${access_key_id}"
 

+ 153 - 152
bin/v-add-backup-host

@@ -15,7 +15,8 @@
 type=$1
 host=$2
 user=$3
-raw_password=$4; HIDE=4
+raw_password=$4
+HIDE=4
 password=$(perl -e 'print quotemeta shift(@ARGV)' "${raw_password}")
 path=${5-/backup}
 port=$6
@@ -37,7 +38,7 @@ b2lnk="https://github.com/Backblaze/B2_Command_Line_Tool/releases/download/v$b2_
 
 # Defining ftp command function
 ftpc() {
-    ftp -p -n $host $port <<EOF
+	ftp -p -n $host $port << EOF
     quote USER $user
     quote PASS $password
     binary
@@ -50,8 +51,8 @@ EOF
 
 # Defining sftp command function
 sftpc() {
-    if [ "$privatekey" != "yes" ]; then
-    expect -f "-" <<EOF "$@"
+	if [ "$privatekey" != "yes" ]; then
+		expect -f "-" "$@" << EOF
         set count 0
         spawn /usr/bin/sftp -o StrictHostKeyChecking=no -o Port=$port $user@$host
         expect {
@@ -104,8 +105,8 @@ sftpc() {
 
         exit \$rc
 EOF
-else
-    expect -f "-" <<EOF "$@"
+	else
+		expect -f "-" "$@" << EOF
             set count 0
             spawn /usr/bin/sftp -o StrictHostKeyChecking=no -o Port=$port -i $raw_password $user@$host
             expect {
@@ -149,41 +150,41 @@ else
 
             exit \$rc
 EOF
-    fi
+	fi
 }
 
 #----------------------------------------------------------#
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-if [ "$type" != 'local' ];then
-    check_args '2' "$#" "TYPE HOST USERNAME PASSWORD [PATH] [PORT]"
-    is_format_valid 'host' 'path' 'port'
-    is_type_valid  'sftp,ftp,b2,rclone' "$type"
-    is_username_format_valid "$user" "username"
-    privatekey="no"
-    if [ -f "$raw_password" ]; then
-        if [[ $(cat  "$raw_password" | grep "OPENSSH PRIVATE") ]]; then
-            privatekey="yes"
-            password="$raw_password"
-        else
-            is_password_valid
-        fi
-    else
-        is_password_valid
-    fi
-    format_no_quotes "$password" "password"
-
-    if [ "$type" = 'sftp' ]; then
-        which expect >/dev/null 2>&1
-        check_result $? "expect command not found"  "$E_NOTEXIST"
-    fi
-    if [ "$type" != 'b2' ] && [ "$type" != 'rclone' ]; then
-        if ! (is_ip_format_valid "$host" >/dev/null); then
-            host "$host" >/dev/null 2>&1
-            check_result $? "host connection failed" "$E_CONNECT"
-        fi
-    fi
+if [ "$type" != 'local' ]; then
+	check_args '2' "$#" "TYPE HOST USERNAME PASSWORD [PATH] [PORT]"
+	is_format_valid 'host' 'path' 'port'
+	is_type_valid 'sftp,ftp,b2,rclone' "$type"
+	is_username_format_valid "$user" "username"
+	privatekey="no"
+	if [ -f "$raw_password" ]; then
+		if [[ $(cat "$raw_password" | grep "OPENSSH PRIVATE") ]]; then
+			privatekey="yes"
+			password="$raw_password"
+		else
+			is_password_valid
+		fi
+	else
+		is_password_valid
+	fi
+	format_no_quotes "$password" "password"
+
+	if [ "$type" = 'sftp' ]; then
+		which expect > /dev/null 2>&1
+		check_result $? "expect command not found" "$E_NOTEXIST"
+	fi
+	if [ "$type" != 'b2' ] && [ "$type" != 'rclone' ]; then
+		if ! (is_ip_format_valid "$host" > /dev/null); then
+			host "$host" > /dev/null 2>&1
+			check_result $? "host connection failed" "$E_CONNECT"
+		fi
+	fi
 fi
 
 # Perform verification if read-only mode is enabled
@@ -195,130 +196,130 @@ check_hestia_demo_mode
 
 # Checking network connection
 if [ "$type" = 'ftp' ]; then
-    if [ -z $port ]; then
-        port=21
-    fi
-    fconn=$(ftpc 2>&1)
-    ferror=$(echo $fconn |\
-        grep -i -e failed -e error -e "can't" -e "not conn" -e "incorrect")
-    if [ -n "$ferror" ]; then
-        echo "Error: can't login to ftp $user@$host"
-        log_event "$E_CONNECT" "$ARGUMENTS"
-        exit "$E_CONNECT"
-    fi
-
-    # Checking write permissions
-    if [ -z $path ]; then
-        ftmpdir="vst.bK76A9SUkt"
-    else
-        ftpc "mkdir $path" > /dev/null 2>&1
-        ftmpdir="$path/vst.bK76A9SUkt"
-    fi
-    ftp_result=$(ftpc "mkdir $ftmpdir" "rm $ftmpdir"|grep -v Trying)
-    if [ -n "$ftp_result" ] ; then
-        echo "$ftp_result"
-        rm -rf $tmpdir
-        echo "Error: can't create $ftmpdir folder on the ftp"
-        log_event "$E_FTP" "$ARGUMENTS"
-        exit "$E_FTP"
-    fi
+	if [ -z $port ]; then
+		port=21
+	fi
+	fconn=$(ftpc 2>&1)
+	ferror=$(echo $fconn \
+		| grep -i -e failed -e error -e "can't" -e "not conn" -e "incorrect")
+	if [ -n "$ferror" ]; then
+		echo "Error: can't login to ftp $user@$host"
+		log_event "$E_CONNECT" "$ARGUMENTS"
+		exit "$E_CONNECT"
+	fi
+
+	# Checking write permissions
+	if [ -z $path ]; then
+		ftmpdir="vst.bK76A9SUkt"
+	else
+		ftpc "mkdir $path" > /dev/null 2>&1
+		ftmpdir="$path/vst.bK76A9SUkt"
+	fi
+	ftp_result=$(ftpc "mkdir $ftmpdir" "rm $ftmpdir" | grep -v Trying)
+	if [ -n "$ftp_result" ]; then
+		echo "$ftp_result"
+		rm -rf $tmpdir
+		echo "Error: can't create $ftmpdir folder on the ftp"
+		log_event "$E_FTP" "$ARGUMENTS"
+		exit "$E_FTP"
+	fi
 fi
 
 if [ "$type" = 'sftp' ]; then
-    if [ -z $port ]; then
-        port=22
-    fi
-    if [ -z $path ]; then
-            sftmpdir="vst.bK76A9SUkt"
-            sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1
-    else
-        if sftpc "mkdir $path" > /dev/null 2>&1 ; then
-            sftmpdir="$path/vst.bK76A9SUkt"
-            sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1
-        else
-            sftmpdir="$path/vst.bK76A9SUkt"
-            sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1
-        fi
-    fi
-    rc=$?
-    if [[ "$rc" != 0 ]]; then
-        case $rc in
-            $E_CONNECT) echo "Error: can't login to sftp $user@$host";;
-            $E_FTP) echo "Error: can't create temp folder on the sftp host";;
-        esac
-        log_event "$rc" "$ARGUMENTS"
-        exit "$rc"
-    fi
+	if [ -z $port ]; then
+		port=22
+	fi
+	if [ -z $path ]; then
+		sftmpdir="vst.bK76A9SUkt"
+		sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1
+	else
+		if sftpc "mkdir $path" > /dev/null 2>&1; then
+			sftmpdir="$path/vst.bK76A9SUkt"
+			sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1
+		else
+			sftmpdir="$path/vst.bK76A9SUkt"
+			sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1
+		fi
+	fi
+	rc=$?
+	if [[ "$rc" != 0 ]]; then
+		case $rc in
+			$E_CONNECT) echo "Error: can't login to sftp $user@$host" ;;
+			$E_FTP) echo "Error: can't create temp folder on the sftp host" ;;
+		esac
+		log_event "$rc" "$ARGUMENTS"
+		exit "$rc"
+	fi
 fi
 
 if [ "$type" = 'b2' ]; then
-    # Download b2 binary
-    if [ ! -f "$b2cli" ]; then
-        if [ "$arch" = 'aarch64' ] || [ "$arch" = 'arm64' ]; then
-            echo "Error: B2 binary for arm64 must be downloaded manually."
-            exit 3
-        else
-            wget -O $b2cli $b2lnk > /dev/null 2>&1
-            chmod +x $b2cli > /dev/null 2>&1
-        fi
-        if [ ! -f "$b2cli" ]; then
-            echo "Error: Binary download failed, b2 doesnt work as expected."
-            exit 3
-        fi
-    fi
-
-    # Validate b2 binary
-    b2version="$(b2 version)"
-    if [[ ! "$b2version" =~ "b2 command line tool" ]]; then
-        echo "Error: Binary download failed, b2 doesnt work as expected."
-        exit 3
-    fi
-
-    b2 clear-account > /dev/null 2>&1
-    b2 authorize-account "$user" "$raw_password"> /dev/null 2>&1
-    b2 ls --long "$host" "$user" > /dev/null 2>&1
-
-    if [ $? -ne 0 ]; then
-        check_result "$E_CONNECT" "b2 failed to verify connection"
-    fi
+	# Download b2 binary
+	if [ ! -f "$b2cli" ]; then
+		if [ "$arch" = 'aarch64' ] || [ "$arch" = 'arm64' ]; then
+			echo "Error: B2 binary for arm64 must be downloaded manually."
+			exit 3
+		else
+			wget -O $b2cli $b2lnk > /dev/null 2>&1
+			chmod +x $b2cli > /dev/null 2>&1
+		fi
+		if [ ! -f "$b2cli" ]; then
+			echo "Error: Binary download failed, b2 doesnt work as expected."
+			exit 3
+		fi
+	fi
+
+	# Validate b2 binary
+	b2version="$(b2 version)"
+	if [[ ! "$b2version" =~ "b2 command line tool" ]]; then
+		echo "Error: Binary download failed, b2 doesnt work as expected."
+		exit 3
+	fi
+
+	b2 clear-account > /dev/null 2>&1
+	b2 authorize-account "$user" "$raw_password" > /dev/null 2>&1
+	b2 ls --long "$host" "$user" > /dev/null 2>&1
+
+	if [ $? -ne 0 ]; then
+		check_result "$E_CONNECT" "b2 failed to verify connection"
+	fi
 fi
 
 if [ "$type" = 'rclone' ]; then
-    curl -s https://rclone.org/install.sh | bash /dev/null > /dev/null 2>&1
-    # Verify account exists
-    if [ ! -z "$(cat /root/.config/rclone/rclone.conf | grep "\[$host\]")" ]; then
-        echo "test" > /tmp/hestia-backup.txt
-        # Try to upload a single file
-        if [ -z "$path" ]; then
-            rclone copy /tmp/hestia-backup $host:/hestia-backup.txt
-            rclone delete $host:/hestia-backup.txt
-        else
-            rclone copy /tmp/hestia-backup $host:$path/hestia-backup.txt
-            rclone delete $host:$path/hestia-backup.txt
-        fi
-    else
-        check_result "$E_CONNECT" "Rclone config does not exits"
-    fi
+	curl -s https://rclone.org/install.sh | bash /dev/null > /dev/null 2>&1
+	# Verify account exists
+	if [ ! -z "$(cat /root/.config/rclone/rclone.conf | grep "\[$host\]")" ]; then
+		echo "test" > /tmp/hestia-backup.txt
+		# Try to upload a single file
+		if [ -z "$path" ]; then
+			rclone copy /tmp/hestia-backup $host:/hestia-backup.txt
+			rclone delete $host:/hestia-backup.txt
+		else
+			rclone copy /tmp/hestia-backup $host:$path/hestia-backup.txt
+			rclone delete $host:$path/hestia-backup.txt
+		fi
+	else
+		check_result "$E_CONNECT" "Rclone config does not exits"
+	fi
 fi
 
 # Adding backup host
-if [ $type == 'ftp' ] || [ $type = 'sftp' ] ; then
-    new_timestamp
-    str="HOST='$host'\nUSERNAME='$user'\nPASSWORD='$password'\nPRIVATEKEY='$privatekey'"
-    str="$str\nBPATH='$path'\nPORT='$port'\nTIME='$time'\nDATE='$date'"
-    echo -e "$str" > $HESTIA/conf/$type.backup.conf
-    chmod 660 $HESTIA/conf/$type.backup.conf
+if [ $type == 'ftp' ] || [ $type = 'sftp' ]; then
+	new_timestamp
+	str="HOST='$host'\nUSERNAME='$user'\nPASSWORD='$password'\nPRIVATEKEY='$privatekey'"
+	str="$str\nBPATH='$path'\nPORT='$port'\nTIME='$time'\nDATE='$date'"
+	echo -e "$str" > $HESTIA/conf/$type.backup.conf
+	chmod 660 $HESTIA/conf/$type.backup.conf
 elif [ $type == 'b2' ]; then
-    new_timestamp
-    str="BUCKET='$host'\nB2_KEYID='$user'\nB2_KEY='$raw_password'"
-    str="$str\nTIME='$time'\nDATE='$date'"
-    echo -e "$str" > $HESTIA/conf/$type.backup.conf
-    chmod 660 $HESTIA/conf/$type.backup.conf
+	new_timestamp
+	str="BUCKET='$host'\nB2_KEYID='$user'\nB2_KEY='$raw_password'"
+	str="$str\nTIME='$time'\nDATE='$date'"
+	echo -e "$str" > $HESTIA/conf/$type.backup.conf
+	chmod 660 $HESTIA/conf/$type.backup.conf
 elif [ $type == "rclone" ]; then
-    new_timestamp
-    str="HOST='$host'\nBPATH='$path'"
-    str="$str\nTIME='$time'\nDATE='$date'"
-    echo -e "$str" > $HESTIA/conf/$type.backup.conf
+	new_timestamp
+	str="HOST='$host'\nBPATH='$path'"
+	str="$str\nTIME='$time'\nDATE='$date'"
+	echo -e "$str" > $HESTIA/conf/$type.backup.conf
 fi
 
 #----------------------------------------------------------#
@@ -327,14 +328,14 @@ fi
 
 # Update hestia.conf
 if [ -z "$(grep BACKUP_SYSTEM $HESTIA/conf/hestia.conf)" ]; then
-    echo "BACKUP_SYSTEM='$type'" >> $HESTIA/conf/hestia.conf
+	echo "BACKUP_SYSTEM='$type'" >> $HESTIA/conf/hestia.conf
 else
-    bckp=$(echo "$BACKUP_SYSTEM,$type" |\
-        sed "s/,/\n/g"|\
-        sort -r -u |\
-        sed "/^$/d"|\
-        sed ':a;N;$!ba;s/\n/,/g')
-    sed -i "s/BACKUP_SYSTEM=.*/BACKUP_SYSTEM='$bckp'/g" $HESTIA/conf/hestia.conf
+	bckp=$(echo "$BACKUP_SYSTEM,$type" \
+		| sed "s/,/\n/g" \
+		| sort -r -u \
+		| sed "/^$/d" \
+		| sed ':a;N;$!ba;s/\n/,/g')
+	sed -i "s/BACKUP_SYSTEM=.*/BACKUP_SYSTEM='$bckp'/g" $HESTIA/conf/hestia.conf
 fi
 
 # Logging

+ 16 - 16
bin/v-add-cron-hestia-autoupdate

@@ -31,7 +31,7 @@ get_next_cronjob
 check_cron_apt=$(grep 'v-update-sys-hestia-all' $USER_DATA/cron.conf)
 check_cron_git=$(grep 'v-update-sys-hestia-git' $USER_DATA/cron.conf)
 if [ -n "$check_cron_apt" ] || [ -n "$check_cron_git" ]; then
-    exit
+	exit
 fi
 
 # Perform verification if read-only mode is enabled
@@ -43,26 +43,26 @@ check_hestia_demo_mode
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Define time somewhere at night
 if [ -z "$mode" ] || [ "$mode" = "apt" ]; then
-    min=$(generate_password '012345' '2')
-    hour=$(generate_password '1234567' '1')
-    day='*'
-    month='*'
-    wday='*'
-    command='sudo /usr/local/hestia/bin/v-update-sys-hestia-all'
+	min=$(generate_password '012345' '2')
+	hour=$(generate_password '1234567' '1')
+	day='*'
+	month='*'
+	wday='*'
+	command='sudo /usr/local/hestia/bin/v-update-sys-hestia-all'
 fi
 
 if [ "$mode" = "git" ]; then
-    min='0'
-    hour='0'
-    day='*'
-    month='*'
-    wday='*'
-    command='sudo /usr/local/hestia/bin/v-update-sys-hestia-git'
+	min='0'
+	hour='0'
+	day='*'
+	month='*'
+	wday='*'
+	command='sudo /usr/local/hestia/bin/v-update-sys-hestia-git'
 fi
 
 # Concatenating cron string
@@ -90,7 +90,7 @@ increase_user_value "$user" '$U_CRON_JOBS'
 
 # Restarting cron
 $BIN/v-restart-cron
-check_result $? "Cron restart failed" >/dev/null
+check_result $? "Cron restart failed" > /dev/null
 
 # Logging
 $BIN/v-log-action "system" "Info" "Updates" "Automatic updates enabled."

+ 4 - 4
bin/v-add-cron-job

@@ -18,7 +18,7 @@ hour=$3
 day=$4
 month=$5
 wday=$6
-command=$(echo $7 |sed "s/'/%quote%/g")
+command=$(echo $7 | sed "s/'/%quote%/g")
 job=$8
 restart=$9
 
@@ -56,8 +56,8 @@ check_hestia_demo_mode
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Concatenating cron string
 str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
@@ -84,7 +84,7 @@ increase_user_value $user '$U_CRON_JOBS'
 
 # Restarting cron
 $BIN/v-restart-cron "$restart"
-check_result $? "Cron restart failed" >/dev/null
+check_result $? "Cron restart failed" > /dev/null
 
 # Logging
 $BIN/v-log-action "$user" "Info" "Cron Jobs" "Cron job added (ID: $job, Command: $command)"

+ 1 - 1
bin/v-add-cron-letsencrypt-job

@@ -33,7 +33,7 @@ check_hestia_demo_mode
 cmd="sudo $HESTIA/bin/v-update-sys-queue letsencrypt"
 check_cron=$(grep "$cmd" $HESTIA/data/users/admin/cron.conf 2> /dev/null)
 if [ -z "$check_cron" ] && [ -n "$CRON_SYSTEM" ]; then
-    $BIN/v-add-cron-job admin '*/5' '*' '*' '*' '*' "$cmd"
+	$BIN/v-add-cron-job admin '*/5' '*' '*' '*' '*' "$cmd"
 fi
 
 #----------------------------------------------------------#

+ 1 - 1
bin/v-add-cron-reports

@@ -51,7 +51,7 @@ sync_cron_jobs
 
 # Restart cron
 $BIN/v-restart-cron
-check_result $? "Cron restart failed" >/dev/null
+check_result $? "Cron restart failed" > /dev/null
 
 # Logging
 $BIN/v-log-action "$user" "Info" "Cron Jobs" "Cron job notifications and reporting enabled."

+ 1 - 1
bin/v-add-cron-restart-job

@@ -33,7 +33,7 @@ check_hestia_demo_mode
 cmd="sudo $HESTIA/bin/v-update-sys-queue restart"
 check_cron=$(grep "$cmd" $HESTIA/data/users/admin/cron.conf 2> /dev/null)
 if [ -z "$check_cron" ] && [ -n "$CRON_SYSTEM" ]; then
-    $BIN/v-add-cron-job admin '*' '*' '*' '*' '*' "$cmd"
+	$BIN/v-add-cron-job admin '*' '*' '*' '*' '*' "$cmd"
 fi
 
 #----------------------------------------------------------#

+ 16 - 15
bin/v-add-database

@@ -20,11 +20,12 @@
 user=$1
 database="$user"_"$2"
 dbuser="$user"_"$3"
-password=$4; HIDE=4
+password=$4
+HIDE=4
 type=${5-mysql}
 host=$6
 charset=${7-UTF8}
-charset=$(echo "$charset" |tr '[:lower:]' '[:upper:]')
+charset=$(echo "$charset" | tr '[:lower:]' '[:upper:]')
 
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -37,8 +38,8 @@ source $HESTIA/func/db.sh
 source_conf "$HESTIA/conf/hestia.conf"
 
 if [ "$type" = "pgsql" ]; then
-   database=$(echo "$user"_"$2" | tr '[:upper:]' '[:lower:]');
-   dbuser=$(echo "$user"_"$3" | tr '[:upper:]' '[:lower:]');
+	database=$(echo "$user"_"$2" | tr '[:upper:]' '[:lower:]')
+	dbuser=$(echo "$user"_"$3" | tr '[:upper:]' '[:lower:]')
 fi
 
 #----------------------------------------------------------#
@@ -61,13 +62,13 @@ is_package_full 'DATABASES'
 is_password_valid
 
 if [ "$type" = "pgsql" ]; then
-   exclude="-"
-    if [[ "$dbuser" =~ $exclude ]]; then
-        check_result "$E_INVALID" "invalid database user format"
-    fi
-    if [[ "$database" =~ $exclude ]]; then
-      check_result "$E_INVALID" "invalid database format"
-    fi
+	exclude="-"
+	if [[ "$dbuser" =~ $exclude ]]; then
+		check_result "$E_INVALID" "invalid database user format"
+	fi
+	if [[ "$database" =~ $exclude ]]; then
+		check_result "$E_INVALID" "invalid database format"
+	fi
 fi
 
 dbpass="$password"
@@ -81,8 +82,8 @@ check_hestia_demo_mode
 
 # Switching on db type
 case $type in
-    mysql) add_mysql_database ;;
-    pgsql) add_pgsql_database ;;
+	mysql) add_mysql_database ;;
+	pgsql) add_pgsql_database ;;
 esac
 
 #----------------------------------------------------------#
@@ -91,8 +92,8 @@ esac
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Adding db to db conf
 str="DB='$database' DBUSER='$dbuser' MD5='$md5' HOST='$host' TYPE='$type'"

+ 47 - 42
bin/v-add-database-host

@@ -18,7 +18,8 @@
 type=$1
 host=$2
 dbuser=$3
-password=$4; HIDE=4
+password=$4
+HIDE=4
 max_db=${5-500}
 charsets=${6}
 template=${7}
@@ -35,32 +36,32 @@ source $HESTIA/func/db.sh
 source_conf "$HESTIA/conf/hestia.conf"
 
 is_mysql_host_alive() {
-    mycnf=$(mktemp)
-    echo "[client]">$mycnf
-    echo "host='$host'" >> $mycnf
-    echo "user='$dbuser'" >> $mycnf
-    echo "password='$password'" >> $mycnf
-    echo "port='$port'" >> $mycnf
-
-    chmod 600 $mycnf
-    mysql --defaults-file=$mycnf -e 'SELECT VERSION()' >/dev/null 2>&1
-    rm $mycnf
-
-    if [ "$?" -ne '0' ]; then
-        echo "Error: MySQL connection to $host failed"
-        log_event "$E_CONNECT" "$ARGUMENTS"
-        exit "$E_CONNECT"
-    fi
+	mycnf=$(mktemp)
+	echo "[client]" > $mycnf
+	echo "host='$host'" >> $mycnf
+	echo "user='$dbuser'" >> $mycnf
+	echo "password='$password'" >> $mycnf
+	echo "port='$port'" >> $mycnf
+
+	chmod 600 $mycnf
+	mysql --defaults-file=$mycnf -e 'SELECT VERSION()' > /dev/null 2>&1
+	rm $mycnf
+
+	if [ "$?" -ne '0' ]; then
+		echo "Error: MySQL connection to $host failed"
+		log_event "$E_CONNECT" "$ARGUMENTS"
+		exit "$E_CONNECT"
+	fi
 }
 
 is_pgsql_host_alive() {
-    export PGPASSWORD="$dbpass"
-    psql -h $host -U $dbuser -p $port -c "SELECT VERSION()" > /dev/null 2>&1
-    if [ "$?" -ne '0' ]; then
-        echo "Error: PostgreSQL connection to $host failed"
-        log_event "$E_CONNECT" "$ARGUMENTS"
-        exit "$E_CONNECT"
-    fi
+	export PGPASSWORD="$dbpass"
+	psql -h $host -U $dbuser -p $port -c "SELECT VERSION()" > /dev/null 2>&1
+	if [ "$?" -ne '0' ]; then
+		echo "Error: PostgreSQL connection to $host failed"
+		log_event "$E_CONNECT" "$ARGUMENTS"
+		exit "$E_CONNECT"
+	fi
 }
 
 #----------------------------------------------------------#
@@ -83,8 +84,8 @@ is_password_valid
 dbpass="$password"
 
 case $type in
-    mysql) is_mysql_host_alive ;;
-    pgsql) is_pgsql_host_alive ;;
+	mysql) is_mysql_host_alive ;;
+	pgsql) is_pgsql_host_alive ;;
 esac
 
 # Perform verification if read-only mode is enabled
@@ -96,18 +97,22 @@ check_hestia_demo_mode
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Concatenating db host string
 case $type in
-    mysql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
-           str="$str CHARSETS='$charsets' MAX_DB='$max_db' U_SYS_USERS=''";
-           str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$time' DATE='$date' PORT='$port'";;
-    pgsql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
-           str="$str CHARSETS='$charsets' TPL='$template' MAX_DB='$max_db'";
-           str="$str U_SYS_USERS='' U_DB_BASES='0' SUSPENDED='no'";
-           str="$str TIME='$time' DATE='$date' PORT='$port'";;
+	mysql)
+		str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'"
+		str="$str CHARSETS='$charsets' MAX_DB='$max_db' U_SYS_USERS=''"
+		str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$time' DATE='$date' PORT='$port'"
+		;;
+	pgsql)
+		str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'"
+		str="$str CHARSETS='$charsets' TPL='$template' MAX_DB='$max_db'"
+		str="$str U_SYS_USERS='' U_DB_BASES='0' SUSPENDED='no'"
+		str="$str TIME='$time' DATE='$date' PORT='$port'"
+		;;
 esac
 
 #----------------------------------------------------------#
@@ -120,14 +125,14 @@ chmod 660 $HESTIA/conf/$type.conf
 
 # Updating hestia.conf
 if [ -z "$(grep DB_SYSTEM $HESTIA/conf/hestia.conf)" ]; then
-    echo "DB_SYSTEM='$type'" >> $HESTIA/conf/hestia.conf
+	echo "DB_SYSTEM='$type'" >> $HESTIA/conf/hestia.conf
 else
-    db=$(echo "$DB_SYSTEM,$type" |\
-        sed "s/,/\n/g"|\
-        sort -r -u |\
-        sed "/^$/d"|\
-        sed ':a;N;$!ba;s/\n/,/g')
-    sed -i "s/DB_SYSTEM=.*/DB_SYSTEM='$db'/g" $HESTIA/conf/hestia.conf
+	db=$(echo "$DB_SYSTEM,$type" \
+		| sed "s/,/\n/g" \
+		| sort -r -u \
+		| sed "/^$/d" \
+		| sed ':a;N;$!ba;s/\n/,/g')
+	sed -i "s/DB_SYSTEM=.*/DB_SYSTEM='$db'/g" $HESTIA/conf/hestia.conf
 fi
 
 # Logging

+ 8 - 8
bin/v-add-database-temp-user

@@ -20,7 +20,7 @@ host=$4
 ttl=$5
 
 if [ "$ttl" == '' ]; then
-    ttl=60
+	ttl=60
 fi
 
 # Includes
@@ -58,17 +58,17 @@ check_hestia_demo_mode
 get_database_values
 
 #generate password and unique user
-dbpass=$(generate_password);
-dbuser="hestia_sso_$(generate_password)";
+dbpass=$(generate_password)
+dbuser="hestia_sso_$(generate_password)"
 
 add_mysql_database_temp_user
 if [ $? -ne 0 ]; then
-    echo "Error: Unable to create temp user"
-    exit 2
-fi;
+	echo "Error: Unable to create temp user"
+	exit 2
+fi
 
 if [[ "$ttl" -gt 0 ]]; then
-    echo "$BIN/v-delete-database-temp-user $user $database $dbuser mysql $host" | at "now +${ttl} minute" > /dev/null 2>&1
+	echo "$BIN/v-delete-database-temp-user $user $database $dbuser mysql $host" | at "now +${ttl} minute" > /dev/null 2>&1
 fi
 echo '{
     "login": {
@@ -84,4 +84,4 @@ echo '{
 # Logging
 $BIN/v-log-action "$user" "Info" "Databases" "Granted user $dbuser access to database $database."
 log_event "$OK" "$ARGUMENTS"
-exit
+exit

+ 58 - 58
bin/v-add-dns-domain

@@ -56,25 +56,25 @@ is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
 is_object_valid 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
 
-if [ "$($BIN/v-list-dns-domain $user $domain_utf plain |cut -f 1) " != "$domain" ]; then
-    is_domain_new 'dns' "$domain_utf"
+if [ "$($BIN/v-list-dns-domain $user $domain_utf plain | cut -f 1) " != "$domain" ]; then
+	is_domain_new 'dns' "$domain_utf"
 fi
-if [ "$($BIN/v-list-dns-domain $user $domain_idn plain |cut -f 1) " != "$domain" ]; then
-    is_domain_new 'dns' "$domain_idn"
+if [ "$($BIN/v-list-dns-domain $user $domain_idn plain | cut -f 1) " != "$domain" ]; then
+	is_domain_new 'dns' "$domain_idn"
 else
-    is_domain_new 'dns' "$domain"
+	is_domain_new 'dns' "$domain"
 fi
 if [ -z "$(is_ip_format_valid $domain)" ]; then
-    echo "Error: Invalid domain format. IP address detected as input."
-    exit 1
+	echo "Error: Invalid domain format. IP address detected as input."
+	exit 1
 fi
 
 if [ -n "$restart" ]; then
-    is_format_valid 'restart'
+	is_format_valid 'restart'
 fi
 
 if [ -n "$dnssec" ]; then
-    is_boolean_format_valid "$dnssec" 'dnssec'
+	is_boolean_format_valid "$dnssec" 'dnssec'
 fi
 
 is_package_full 'DNS_DOMAINS'
@@ -84,36 +84,36 @@ is_dns_template_valid "$template"
 is_base_domain_owner "$domain"
 
 if [ -n "$ns1" ]; then
-    ns1=$(echo $4 |sed -e 's/\.*$//g' -e 's/^\.*//g')
-    is_format_valid 'ns1'
+	ns1=$(echo $4 | sed -e 's/\.*$//g' -e 's/^\.*//g')
+	is_format_valid 'ns1'
 fi
 if [ -n "$ns2" ]; then
-    ns2=$(echo $5 |sed -e 's/\.*$//g' -e 's/^\.*//g')
-    is_format_valid 'ns2'
+	ns2=$(echo $5 | sed -e 's/\.*$//g' -e 's/^\.*//g')
+	is_format_valid 'ns2'
 fi
 if [ -n "$ns3" ]; then
-    ns3=$(echo $6 |sed -e 's/\.*$//g' -e 's/^\.*//g')
-    is_format_valid 'ns3'
+	ns3=$(echo $6 | sed -e 's/\.*$//g' -e 's/^\.*//g')
+	is_format_valid 'ns3'
 fi
 if [ -n "$ns4" ]; then
-    ns4=$(echo $7 |sed -e 's/\.*$//g' -e 's/^\.*//g')
-    is_format_valid 'ns4'
+	ns4=$(echo $7 | sed -e 's/\.*$//g' -e 's/^\.*//g')
+	is_format_valid 'ns4'
 fi
 if [ -n "$ns5" ]; then
-    ns5=$(echo $8 |sed -e 's/\.*$//g' -e 's/^\.*//g')
-    is_format_valid 'ns5'
+	ns5=$(echo $8 | sed -e 's/\.*$//g' -e 's/^\.*//g')
+	is_format_valid 'ns5'
 fi
 if [ -n "$ns6" ]; then
-    ns6=$(echo $9 |sed -e 's/\.*$//g' -e 's/^\.*//g')
-    is_format_valid 'ns6'
+	ns6=$(echo $9 | sed -e 's/\.*$//g' -e 's/^\.*//g')
+	is_format_valid 'ns6'
 fi
 if [ -n "$ns7" ]; then
-    ns7=$(echo ${10} |sed -e 's/\.*$//g' -e 's/^\.*//g')
-    is_format_valid 'ns7'
+	ns7=$(echo ${10} | sed -e 's/\.*$//g' -e 's/^\.*//g')
+	is_format_valid 'ns7'
 fi
 if [ -n "$ns8" ]; then
-    ns8=$(echo ${11} |sed -e 's/\.*$//g' -e 's/^\.*//g')
-    is_format_valid 'ns8'
+	ns8=$(echo ${11} | sed -e 's/\.*$//g' -e 's/^\.*//g')
+	is_format_valid 'ns8'
 fi
 
 # Perform verification if read-only mode is enabled
@@ -125,12 +125,12 @@ check_hestia_demo_mode
 
 # Defining NS variables
 if [ -z $ns2 ]; then
-    i=1
-    ns=$(get_user_value '$NS')
-    for nameserver in ${ns//,/ };do
-        eval ns$i=$nameserver
-        (( ++i))
-    done
+	i=1
+	ns=$(get_user_value '$NS')
+	for nameserver in ${ns//,/ }; do
+		eval ns$i=$nameserver
+		((++i))
+	done
 fi
 soa="$ns1"
 exp=$(date +%F -d "+ 1 year")
@@ -142,50 +142,50 @@ template_data=$(cat "$DNSTPL/$template.tpl")
 
 # Deleting unused nameservers
 if [ -z "$ns3" ]; then
-    template_data=$(echo "$template_data" |grep -v %ns3%)
+	template_data=$(echo "$template_data" | grep -v %ns3%)
 fi
 if [ -z "$ns4" ]; then
-    template_data=$(echo "$template_data" |grep -v %ns4%)
+	template_data=$(echo "$template_data" | grep -v %ns4%)
 fi
 if [ -z "$ns5" ]; then
-    template_data=$(echo "$template_data" |grep -v %ns5%)
+	template_data=$(echo "$template_data" | grep -v %ns5%)
 fi
 if [ -z "$ns6" ]; then
-    template_data=$(echo "$template_data" |grep -v %ns6%)
+	template_data=$(echo "$template_data" | grep -v %ns6%)
 fi
 if [ -z "$ns7" ]; then
-    template_data=$(echo "$template_data" |grep -v %ns7%)
+	template_data=$(echo "$template_data" | grep -v %ns7%)
 fi
 if [ -z "$ns8" ]; then
-    template_data=$(echo "$template_data" |grep -v %ns8%)
+	template_data=$(echo "$template_data" | grep -v %ns8%)
 fi
 if [ -z "$dnssec" ]; then
-    dnssec="no"
+	dnssec="no"
 fi
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Adding dns zone to the user config
-echo "$template_data" |\
-    sed -e "s/%ip%/$ip/g" \
-        -e "s/%domain_idn%/$domain_idn/g" \
-        -e "s/%domain%/$domain/g" \
-        -e "s/%ns1%/$ns1/g" \
-        -e "s/%ns2%/$ns2/g" \
-        -e "s/%ns3%/$ns3/g" \
-        -e "s/%ns4%/$ns4/g" \
-        -e "s/%ns5%/$ns5/g" \
-        -e "s/%ns6%/$ns6/g" \
-        -e "s/%ns7%/$ns7/g" \
-        -e "s/%ns8%/$ns8/g" \
-        -e "s/%time%/$time/g" \
-        -e "s/%date%/$date/g" > $USER_DATA/dns/$domain.conf
+echo "$template_data" \
+	| sed -e "s/%ip%/$ip/g" \
+		-e "s/%domain_idn%/$domain_idn/g" \
+		-e "s/%domain%/$domain/g" \
+		-e "s/%ns1%/$ns1/g" \
+		-e "s/%ns2%/$ns2/g" \
+		-e "s/%ns3%/$ns3/g" \
+		-e "s/%ns4%/$ns4/g" \
+		-e "s/%ns5%/$ns5/g" \
+		-e "s/%ns6%/$ns6/g" \
+		-e "s/%ns7%/$ns7/g" \
+		-e "s/%ns8%/$ns8/g" \
+		-e "s/%time%/$time/g" \
+		-e "s/%date%/$date/g" > $USER_DATA/dns/$domain.conf
 
 chmod 660 $USER_DATA/dns/$domain.conf
-records="$(wc -l $USER_DATA/dns/$domain.conf |cut -f 1 -d ' ')"
+records="$(wc -l $USER_DATA/dns/$domain.conf | cut -f 1 -d ' ')"
 
 # Adding dns.conf record
 dns_rec="DOMAIN='$domain' IP='$ip' TPL='$template' TTL='$ttl' EXP='$exp'"
@@ -198,9 +198,9 @@ chmod 660 $USER_DATA/dns.conf
 rebuild_dns_domain_conf
 
 # Updating dns-cluster queue
-if [ "$DNS_CLUSTER"  = "yes" ]; then
-    cmd="$BIN/v-add-remote-dns-domain $user $domain yes"
-    echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
+if [ "$DNS_CLUSTER" = "yes" ]; then
+	cmd="$BIN/v-add-remote-dns-domain $user $domain yes"
+	echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
 fi
 
 #----------------------------------------------------------#

+ 12 - 12
bin/v-add-dns-on-web-alias

@@ -36,7 +36,7 @@ is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
 is_object_valid 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
 if [ -e "$USER_DATA/dns/$alias.conf" ]; then
-    exit
+	exit
 fi
 
 # Perform verification if read-only mode is enabled
@@ -50,15 +50,15 @@ check_hestia_demo_mode
 log_event "$OK" "$ARGUMENTS"
 
 # Define additional vars
-sub_domain=$(echo "$alias" |awk -F '.' '{print $1}')
-top_domain=$(echo "$alias" |sed -e "s/^$sub_domain.//")
-domain_lvl=$(echo "$alias" |grep -o "\." |wc -l)
+sub_domain=$(echo "$alias" | awk -F '.' '{print $1}')
+top_domain=$(echo "$alias" | sed -e "s/^$sub_domain.//")
+domain_lvl=$(echo "$alias" | grep -o "\." | wc -l)
 
 # Adding second level domain
 if [ "$domain_lvl" -eq 1 ] || [ "${#top_domain}" -le '6' ]; then
-    $BIN/v-add-dns-domain \
-        "$user" "$alias" "$ip" '' '' '' '' '' '' '' '' "$restart" >> /dev/null
-    exit
+	$BIN/v-add-dns-domain \
+		"$user" "$alias" "$ip" '' '' '' '' '' '' '' '' "$restart" >> /dev/null
+	exit
 fi
 
 # Adding top-level domain and then its sub
@@ -66,20 +66,20 @@ $BIN/v-add-dns-domain "$user" "$top_domain" "$ip" '' '' '' '' '' '' '' '' "$rest
 
 # Checking top-level domain
 if [ ! -e "$USER_DATA/dns/$top_domain.conf" ]; then
-    exit
+	exit
 fi
 
 # Checking subdomain record
 if [ "$sub_domain" == '*' ]; then
-    check_record=$(grep -w "RECORD='\*'" $USER_DATA/dns/$top_domain.conf)
+	check_record=$(grep -w "RECORD='\*'" $USER_DATA/dns/$top_domain.conf)
 else
-    check_record=$(grep -w "RECORD='$sub_domain'" $USER_DATA/dns/$top_domain.conf)
+	check_record=$(grep -w "RECORD='$sub_domain'" $USER_DATA/dns/$top_domain.conf)
 fi
 
 # Adding subdomain record
 if [ -z "$check_record" ]; then
-    $BIN/v-add-dns-record \
-        "$user" "$top_domain" "$sub_domain" A "$ip" '' '' "$restart" >> /dev/null
+	$BIN/v-add-dns-record \
+		"$user" "$top_domain" "$sub_domain" A "$ip" '' '' "$restart" >> /dev/null
 fi
 
 #----------------------------------------------------------#

+ 32 - 32
bin/v-add-dns-record

@@ -17,9 +17,9 @@
 user=$1
 domain=$2
 domain_idn=$2
-record=$(idn2 --quiet -d "$3" )
+record=$(idn2 --quiet -d "$3")
 record=$(echo "$record" | tr '[:upper:]' '[:lower:]')
-rtype=$(echo "$4"| tr '[:lower:]' '[:upper:]')
+rtype=$(echo "$4" | tr '[:lower:]' '[:upper:]')
 dvalue=$5
 priority=$6
 id=$7
@@ -28,7 +28,7 @@ ttl=$9
 quiet=${10}
 
 if [ -z "$priority" ]; then
-    priority=10
+	priority=10
 fi
 
 # Includes
@@ -45,20 +45,20 @@ source_conf "$HESTIA/conf/hestia.conf"
 
 # Null priority for none MX/SRV records
 if [ "$rtype" != 'MX' ] && [ "$rtype" != 'SRV' ]; then
-    priority=''
+	priority=''
 fi
 
 # Add trailing dot at the end of NS/CNAME/MX/PTR/SRV record
 if [[ $rtype =~ ^NS|CNAME|MX|PTR|SRV ]]; then
-    trailing_dot=$(echo $dvalue | grep "\.$")
-    if [ -z "$trailing_dot" ]; then
-        dvalue="$dvalue."
-    fi
+	trailing_dot=$(echo $dvalue | grep "\.$")
+	if [ -z "$trailing_dot" ]; then
+		dvalue="$dvalue."
+	fi
 fi
 
 if [[ $rtype =~ ^NS|CNAME|MX|PTR|SRV ]]; then
-    dvalue=$(idn2 --quiet  "$dvalue" )
-    record=$(idn2 --quiet  "$record" )
+	dvalue=$(idn2 --quiet "$dvalue")
+	record=$(idn2 --quiet "$record")
 fi
 
 # Cleanup quotes on dvalue
@@ -69,17 +69,17 @@ fi
 #   will be enclosed in double quotes if containing spaces or semicolons
 
 if [ "$rtype" != "CAA" ]; then
-    dvalue=${dvalue//\"/}
-    # Add support for DS key
-    if [ "$rtype" != "DNSKEY" ] && [ "$rtype" != "DS" ] ; then
-        if [ "$rtype" != 'SRV' ] && [[ "$dvalue" =~ [\;[:space:]] ]]; then
-            dvalue='"'"$dvalue"'"'
-        fi
-    fi
+	dvalue=${dvalue//\"/}
+	# Add support for DS key
+	if [ "$rtype" != "DNSKEY" ] && [ "$rtype" != "DS" ]; then
+		if [ "$rtype" != 'SRV' ] && [[ "$dvalue" =~ [\;[:space:]] ]]; then
+			dvalue='"'"$dvalue"'"'
+		fi
+	fi
 fi
 
 if [ "$record" = "@" ] && [ "$rtype" = "CNAME" ]; then
-    check_result $E_INVALID "CNAME on root is not allowed"
+	check_result $E_INVALID "CNAME on root is not allowed"
 fi
 
 # Additional argument formatting
@@ -106,7 +106,7 @@ is_dns_fqnd "$rtype" "$dvalue"
 is_dns_nameserver_valid "$domain" "$rtype" "$dvalue"
 is_format_valid 'ttl'
 if [ -n "$restart" ]; then
-    is_format_valid 'restart'
+	is_format_valid 'restart'
 fi
 
 # Perform verification if read-only mode is enabled
@@ -118,15 +118,15 @@ check_hestia_demo_mode
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Adding record
 zone="$USER_DATA/dns/$domain.conf"
 dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
 dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date'"
 [ -n "$ttl" ] && dns_rec="$dns_rec TTL='$ttl'"
-echo "$dns_rec" >> $zone;
+echo "$dns_rec" >> $zone
 chmod 660 $zone
 
 # Sorting records
@@ -134,18 +134,18 @@ sort_dns_records
 
 # Updating zone
 if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
-    # Do full rebuild due DNS SEC
-    rebuild_dns_domain_conf
+	# Do full rebuild due DNS SEC
+	rebuild_dns_domain_conf
 fi
 
 # Updating dns-cluster queue
-if [ "$DNS_CLUSTER"  = "yes" ]; then
-    # Check for first sync
-    dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
-    if [ -z "$dlock" ]; then
-        cmd="$BIN/v-add-remote-dns-record $user $domain $id"
-        echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
-    fi
+if [ "$DNS_CLUSTER" = "yes" ]; then
+	# Check for first sync
+	dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
+	if [ -z "$dlock" ]; then
+		cmd="$BIN/v-add-remote-dns-record $user $domain $id"
+		echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
+	fi
 fi
 
 #----------------------------------------------------------#
@@ -163,7 +163,7 @@ check_result $? "$E_RESTART" 'dns failed to restart'
 
 # Logging
 if [ "$quiet" != "yes" ]; then
-    $BIN/v-log-action "$user" "Info" "DNS" "Added DNS record (Type: $rtype, Value: $record, Domain: $domain)."
+	$BIN/v-log-action "$user" "Info" "DNS" "Added DNS record (Type: $rtype, Value: $record, Domain: $domain)."
 fi
 log_event "$OK" "$ARGUMENTS"
 

+ 12 - 12
bin/v-add-domain

@@ -31,8 +31,8 @@ source_conf "$HESTIA/conf/hestia.conf"
 #----------------------------------------------------------#
 check_args '2' "$#" 'USER DOMAIN [IP] [RESTART]'
 is_format_valid 'user' 'domain' 'restart'
-if [ -n "$ip" ] ; then
-    is_format_valid 'ip'
+if [ -n "$ip" ]; then
+	is_format_valid 'ip'
 fi
 is_object_valid 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
@@ -46,28 +46,28 @@ check_hestia_demo_mode
 
 # Get ip if it wasn't defined
 if [ -z "$ip" ]; then
-    get_user_ip
-    if [ -z "$ip" ]; then
-        check_result "$E_NOTEXIST" "no available IP address"
-    fi
+	get_user_ip
+	if [ -z "$ip" ]; then
+		check_result "$E_NOTEXIST" "no available IP address"
+	fi
 fi
 
 # Working on web domain
 if [ -n "$WEB_SYSTEM" ]; then
-    $BIN/v-add-web-domain "$user" "$domain" "$ip" 'no'
-    check_result $? "can't add web domain" >/dev/null
+	$BIN/v-add-web-domain "$user" "$domain" "$ip" 'no'
+	check_result $? "can't add web domain" > /dev/null
 fi
 
 # Working on DNS domain
 if [ -n "$DNS_SYSTEM" ]; then
-    $BIN/v-add-dns-domain "$user" "$domain" "$ip" "" "" "" "" "" "" "" "" "no"
-    check_result $? "can't add dns domain" >/dev/null
+	$BIN/v-add-dns-domain "$user" "$domain" "$ip" "" "" "" "" "" "" "" "" "no"
+	check_result $? "can't add dns domain" > /dev/null
 fi
 
 # Working on mail domain
 if [ -n "$MAIL_SYSTEM" ]; then
-    $BIN/v-add-mail-domain $user $domain 'no'
-    check_result $? "can't add mail domain" >/dev/null
+	$BIN/v-add-mail-domain $user $domain 'no'
+	check_result $? "can't add mail domain" > /dev/null
 fi
 
 # Restarting services

+ 12 - 13
bin/v-add-fastcgi-cache

@@ -38,13 +38,13 @@ is_object_valid 'web' 'DOMAIN' "$domain"
 is_object_unsuspended 'web' 'DOMAIN' "$domain"
 
 if ! [[ "$duration" =~ ^[0-9].*[s|m|d]$ ]]; then
-   echo "Invalid duration";
-   exit 2;
+	echo "Invalid duration"
+	exit 2
 fi
 
 if [[ "$duration" =~ ^[0].*[s|m|d]$ ]]; then
-   echo "Invalid duration";
-   exit 2;
+	echo "Invalid duration"
+	exit 2
 fi
 
 # Perform verification if read-only mode is enabled
@@ -59,8 +59,8 @@ parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
 
 # Check that nginx is not in proxy mode
 if [ "$WEB_SYSTEM" != 'nginx' ]; then
-    echo "Error: nginx is in proxy mode"
-    exit "$E_NOTEXIST"
+	echo "Error: nginx is in proxy mode"
+	exit "$E_NOTEXIST"
 fi
 
 fastcgi="$HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.fastcgi_cache.conf"
@@ -76,7 +76,6 @@ cat << EOF > $fastcgi
     set $no_cache 0;
 EOF
 
-
 chown root:$user $fastcgi
 chmod 640 $fastcgi
 
@@ -84,11 +83,11 @@ str="fastcgi_cache_path /var/cache/nginx/micro/$domain levels=1:2"
 str="$str keys_zone=$domain:10m max_size=512m inactive=30m use_temp_path=off;"
 conf='/etc/nginx/conf.d/fastcgi_cache_pool.conf'
 if [ -f "$conf" ]; then
-    if [ -z "$(grep "=${domain}:" $conf)" ]; then
-        echo "$str" >> $conf
-    fi
+	if [ -z "$(grep "=${domain}:" $conf)" ]; then
+		echo "$str" >> $conf
+	fi
 else
-    echo "$str" >> $conf
+	echo "$str" >> $conf
 fi
 
 mkdir -p /var/cache/nginx/micro/$domain
@@ -98,10 +97,10 @@ mkdir -p /var/cache/nginx/micro/$domain
 #----------------------------------------------------------#
 
 if [ -z "$FASTCGI_CACHE" ]; then
-    add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_CACHE' 'ALIAS'
+	add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_CACHE' 'ALIAS'
 fi
 if [ -z "$FASTCGI_DURATION" ]; then
-    add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_DURATION' 'ALIAS'
+	add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_DURATION' 'ALIAS'
 fi
 
 # Set FastCGI cache flag to enabled

+ 10 - 11
bin/v-add-firewall-ban

@@ -12,7 +12,7 @@
 
 # Argument definition
 ip=$1
-chain=$(echo $2|tr '[:lower:]' '[:upper:]')
+chain=$(echo $2 | tr '[:lower:]' '[:upper:]')
 
 # Defining absolute path for iptables and modprobe
 iptables="/sbin/iptables"
@@ -35,7 +35,6 @@ check_args '2' "$#" 'IP CHAIN'
 is_format_valid 'ip' 'chain'
 is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
 
-
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode
 
@@ -48,21 +47,21 @@ heal_iptables_links
 
 # Checking server ip
 if [ -e "$HESTIA/data/ips/$ip" ] || [ "$ip" = '127.0.0.1' ]; then
-    exit
+	exit
 fi
 
 # Checking ip exclusions
 excludes="$HESTIA/data/firewall/excludes.conf"
-check_excludes=$(grep "^$ip$" $excludes 2>/dev/null)
-if  [ -n "$check_excludes" ]; then
-    exit
+check_excludes=$(grep "^$ip$" $excludes 2> /dev/null)
+if [ -n "$check_excludes" ]; then
+	exit
 fi
 
 # Checking ip in banlist
 conf="$HESTIA/data/firewall/banlist.conf"
-check_ip=$(grep "IP='$ip' CHAIN='$chain'" $conf 2>/dev/null)
+check_ip=$(grep "IP='$ip' CHAIN='$chain'" $conf 2> /dev/null)
 if [ -n "$check_ip" ]; then
-    exit
+	exit
 fi
 
 # Adding chain
@@ -70,13 +69,13 @@ $BIN/v-add-firewall-chain $chain
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Adding ip to banlist
 echo "IP='$ip' CHAIN='$chain' TIME='$time' DATE='$date'" >> $conf
 $iptables -I fail2ban-$chain 1 -s $ip \
-    -j REJECT --reject-with icmp-port-unreachable 2>/dev/null
+	-j REJECT --reject-with icmp-port-unreachable 2> /dev/null
 
 # Changing permissions
 chmod 660 $conf

+ 51 - 29
bin/v-add-firewall-chain

@@ -15,7 +15,7 @@ chain=$(echo $1 | tr '[:lower:]' '[:upper:]')
 port=$2
 port_ext=$2
 protocol=${4-TCP}
-protocol=$(echo $protocol|tr '[:lower:]' '[:upper:]')
+protocol=$(echo $protocol | tr '[:lower:]' '[:upper:]')
 
 # Defining absolute path to iptables
 iptables="/sbin/iptables"
@@ -33,7 +33,7 @@ source_conf "$HESTIA/conf/hestia.conf"
 # Get hestia port by reading nginx.conf
 hestiaport=$(grep 'listen' $HESTIA/nginx/conf/nginx.conf | awk '{print $2}' | sed "s|;||")
 if [ -z "$hestiaport" ]; then
-    hestiaport=8083
+	hestiaport=8083
 fi
 
 #----------------------------------------------------------#
@@ -56,42 +56,64 @@ heal_iptables_links
 
 # Checking known chains
 case $chain in
-    SSH)        # Get ssh port by reading ssh config file.
-                sshport=$(grep '^Port ' /etc/ssh/sshd_config | head -1 | cut -d ' ' -f 2)
-                if [ -z "$sshport" ]; then
-                    sshport=22
-                fi
-                port=$sshport;
-                protocol=TCP ;;
-    FTP)        port=21; protocol=TCP  ;;
-    MAIL)       port='25,465,587,110,995,143,993'; protocol=TCP  ;;
-    DNS)        port=53; protocol=UDP  ;;
-    WEB)        port='80,443'; protocol=TCP  ;;
-    DB)         port='3306,5432'; protocol=TCP  ;;
-    HESTIA)     port=$hestiaport; protocol=TCP  ;;
-    RECIDIVE)   port='1:65535'; protocol=TCP  ;;
-    *)          check_args '2' "$#" 'CHAIN PORT' ;;
+	SSH) # Get ssh port by reading ssh config file.
+		sshport=$(grep '^Port ' /etc/ssh/sshd_config | head -1 | cut -d ' ' -f 2)
+		if [ -z "$sshport" ]; then
+			sshport=22
+		fi
+		port=$sshport
+		protocol=TCP
+		;;
+	FTP)
+		port=21
+		protocol=TCP
+		;;
+	MAIL)
+		port='25,465,587,110,995,143,993'
+		protocol=TCP
+		;;
+	DNS)
+		port=53
+		protocol=UDP
+		;;
+	WEB)
+		port='80,443'
+		protocol=TCP
+		;;
+	DB)
+		port='3306,5432'
+		protocol=TCP
+		;;
+	HESTIA)
+		port=$hestiaport
+		protocol=TCP
+		;;
+	RECIDIVE)
+		port='1:65535'
+		protocol=TCP
+		;;
+	*) check_args '2' "$#" 'CHAIN PORT' ;;
 esac
 
 # Adding chain
-$iptables -N fail2ban-$chain 2>/dev/null
+$iptables -N fail2ban-$chain 2> /dev/null
 if [ $? -eq 0 ]; then
-    $iptables -A fail2ban-$chain -j RETURN
-
-    # Adding multiport module
-    if [[ "$port" =~ ,|-|: ]] ; then
-        port_str="-m multiport --dports $port"
-    else
-        port_str="--dport $port"
-    fi
-    $iptables -I INPUT -p $protocol $port_str -j fail2ban-$chain
+	$iptables -A fail2ban-$chain -j RETURN
+
+	# Adding multiport module
+	if [[ "$port" =~ ,|-|: ]]; then
+		port_str="-m multiport --dports $port"
+	else
+		port_str="--dport $port"
+	fi
+	$iptables -I INPUT -p $protocol $port_str -j fail2ban-$chain
 fi
 
 # Preserving chain
 chains=$HESTIA/data/firewall/chains.conf
-check_chain=$(grep "CHAIN='$chain'" $chains 2>/dev/null)
+check_chain=$(grep "CHAIN='$chain'" $chains 2> /dev/null)
 if [ -z "$check_chain" ]; then
-    echo "CHAIN='$chain' PORT='$port' PROTOCOL='$protocol'" >> $chains
+	echo "CHAIN='$chain' PORT='$port' PROTOCOL='$protocol'" >> $chains
 fi
 
 # Changing permissions

+ 65 - 66
bin/v-add-firewall-ipset

@@ -44,40 +44,40 @@ IPSET_PATH="$HESTIA/data/firewall/ipset"
 
 # Ensure ipset is installed
 if [ -z "$IPSET_BIN" ]; then
-    if [ -f '/etc/redhat-release' ]; then
-        dnf install -q -y ipset > /dev/null
-    else
-        apt-get --quiet --yes install ipset > /dev/null
-    fi
-    check_result $? "Installing ipset package"
-
-    IPSET_BIN="$(which ipset)"
-    check_result $? "ipset binary not found"
+	if [ -f '/etc/redhat-release' ]; then
+		dnf install -q -y ipset > /dev/null
+	else
+		apt-get --quiet --yes install ipset > /dev/null
+	fi
+	check_result $? "Installing ipset package"
+
+	IPSET_BIN="$(which ipset)"
+	check_result $? "ipset binary not found"
 fi
 
 # Ensure ipset configuration path and master file exist before attempting to parse
 mkdir -p "$IPSET_PATH"
 if [ ! -f "$HESTIA/data/firewall/ipset.conf" ]; then
-    touch $HESTIA/data/firewall/ipset.conf
+	touch $HESTIA/data/firewall/ipset.conf
 fi
 
 if [ -z "$data_source" ]; then
-    if [ ! -f "${IPSET_PATH}.conf" ] || [[ ! $(grep "LISTNAME='$ip_name'" "${IPSET_PATH}.conf") ]]; then
-        check_args '2' "$#" 'NAME SOURCE [IPVERSION] [AUTOUPDATE] [FORCE]'
-    fi
+	if [ ! -f "${IPSET_PATH}.conf" ] || [[ ! $(grep "LISTNAME='$ip_name'" "${IPSET_PATH}.conf") ]]; then
+		check_args '2' "$#" 'NAME SOURCE [IPVERSION] [AUTOUPDATE] [FORCE]'
+	fi
 
-    data_source="$(get_object_value "$ipset_hstobject" 'LISTNAME' "$ip_name" '$SOURCE')"
-    ip_version="$(get_object_value "$ipset_hstobject" 'LISTNAME' "$ip_name" '$IP_VERSION')"
+	data_source="$(get_object_value "$ipset_hstobject" 'LISTNAME' "$ip_name" '$SOURCE')"
+	ip_version="$(get_object_value "$ipset_hstobject" 'LISTNAME' "$ip_name" '$IP_VERSION')"
 else
-    is_object_new "$ipset_hstobject" 'LISTNAME' "$ip_name"
+	is_object_new "$ipset_hstobject" 'LISTNAME' "$ip_name"
 fi
 
 if [ "$ip_version" != "v4" ] && [ "$ip_version" != "v6" ]; then
-    check_result "$E_INVALID" "invalid ip version, valid: (v4|v6)"
+	check_result "$E_INVALID" "invalid ip version, valid: (v4|v6)"
 fi
 
 if ! echo "$data_source" | egrep -q '^(https?|script|file):'; then
-    check_result "$E_INVALID" "invalid ipset source, valid: (http[s]://|script:|file:)"
+	check_result "$E_INVALID" "invalid ipset source, valid: (http[s]://|script:|file:)"
 fi
 
 IPSET_FILE="${ip_name}.${ip_version}"
@@ -90,54 +90,54 @@ IPSET_MIN_SIZE=10
 # Generate ip lists file if missing or when forced
 if [ ! -f "${IPSET_PATH}/${IPSET_FILE}.iplist" ] || [ "$force" = "yes" ]; then
 
-    iplist_tempfile=$(mktemp)
+	iplist_tempfile=$(mktemp)
 
-    if [[ "$data_source" =~ ^https?:// ]]; then
+	if [[ "$data_source" =~ ^https?:// ]]; then
 
-        wget --tries=3 --timeout=15 --read-timeout=15 --waitretry=3 --no-dns-cache --quiet "$data_source" -O "$iplist_tempfile"
-        check_result $? "Downloading ip list"
+		wget --tries=3 --timeout=15 --read-timeout=15 --waitretry=3 --no-dns-cache --quiet "$data_source" -O "$iplist_tempfile"
+		check_result $? "Downloading ip list"
 
-        # Advanced: execute script with the same basename for aditional pre-processing
-        # ex:
-        if [ -x "${IPSET_PATH}/${IPSET_FILE}.sh" ]; then
-            preprocess_output="$(cat "$iplist_tempfile" | setpriv --clear-groups --reuid nobody --regid nogroup -- ${IPSET_PATH}/${IPSET_FILE}.sh "$ip_name" "$iplist_tempfile")"
-            check_result $? "Preprocessing script failed (${IPSET_FILE}.sh)"
-            [[ "$preprocess_output" ]] && echo "$preprocess_output" > "$iplist_tempfile"
-        fi
+		# Advanced: execute script with the same basename for aditional pre-processing
+		# ex:
+		if [ -x "${IPSET_PATH}/${IPSET_FILE}.sh" ]; then
+			preprocess_output="$(cat "$iplist_tempfile" | setpriv --clear-groups --reuid nobody --regid nogroup -- ${IPSET_PATH}/${IPSET_FILE}.sh "$ip_name" "$iplist_tempfile")"
+			check_result $? "Preprocessing script failed (${IPSET_FILE}.sh)"
+			[[ "$preprocess_output" ]] && echo "$preprocess_output" > "$iplist_tempfile"
+		fi
 
-    elif [[ "$data_source" =~ ^script:/ ]]; then
+	elif [[ "$data_source" =~ ^script:/ ]]; then
 
-        # Generate the ip list file trough a external script
-        # ex: compiling a ip list from multiple sources on demand
+		# Generate the ip list file trough a external script
+		# ex: compiling a ip list from multiple sources on demand
 
-        if [ -x "${data_source#script:}" ]; then
+		if [ -x "${data_source#script:}" ]; then
 
-            setpriv --clear-groups --reuid nobody --regid nogroup -- ${data_source#script:} "$ip_name" > "$iplist_tempfile"
-            check_result $? "Running custom ip list update script"
+			setpriv --clear-groups --reuid nobody --regid nogroup -- ${data_source#script:} "$ip_name" > "$iplist_tempfile"
+			check_result $? "Running custom ip list update script"
 
-        fi
+		fi
 
-    elif [[ "$data_source" =~ ^file:/ ]]; then
+	elif [[ "$data_source" =~ ^file:/ ]]; then
 
-        # Use a external ip-list file managed by other apps
-        # ex: Using a ip list that is continously updated
+		# Use a external ip-list file managed by other apps
+		# ex: Using a ip list that is continously updated
 
-        [ -f "${data_source#file:}" ] && cp -f "${data_source#file:}" "$iplist_tempfile"
+		[ -f "${data_source#file:}" ] && cp -f "${data_source#file:}" "$iplist_tempfile"
 
-    fi
+	fi
 
-    # Cleanup ip list
-    sed -r -i -e 's/[;#].*$//' -e 's/[ \t]*$//' -e '/^$/d' "$iplist_tempfile"
-    if [[ $ip_version == 'v4' ]]; then
-        sed -i -r -n -e '/^((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])/p' "$iplist_tempfile"
-    elif [[ $ip_version == 'v6' ]]; then
-        sed -i -r -n -e '/^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}/p' "$iplist_tempfile"
-    fi
+	# Cleanup ip list
+	sed -r -i -e 's/[;#].*$//' -e 's/[ \t]*$//' -e '/^$/d' "$iplist_tempfile"
+	if [[ $ip_version == 'v4' ]]; then
+		sed -i -r -n -e '/^((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])/p' "$iplist_tempfile"
+	elif [[ $ip_version == 'v6' ]]; then
+		sed -i -r -n -e '/^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}/p' "$iplist_tempfile"
+	fi
 
-    # Validate iplist file size
-    iplist_size=$(sed -r -e '/^#|^$/d' "$iplist_tempfile" | wc -l)
-    [[ "$iplist_size" -le "$IPSET_MIN_SIZE" ]] && check_result "$E_INVALID" "iplist file too small (<${IPSET_MIN_SIZE}), ignoring"
-    mv -f "$iplist_tempfile" "${IPSET_PATH}/${IPSET_FILE}.iplist"
+	# Validate iplist file size
+	iplist_size=$(sed -r -e '/^#|^$/d' "$iplist_tempfile" | wc -l)
+	[[ "$iplist_size" -le "$IPSET_MIN_SIZE" ]] && check_result "$E_INVALID" "iplist file too small (<${IPSET_MIN_SIZE}), ignoring"
+	mv -f "$iplist_tempfile" "${IPSET_PATH}/${IPSET_FILE}.iplist"
 
 fi
 
@@ -150,31 +150,30 @@ $IPSET_BIN -quiet destroy "${ip_name}-tmp"
 $IPSET_BIN create "${ip_name}-tmp" -exist hash:net family $inet_ver maxelem 1048576
 $IPSET_BIN flush "${ip_name}-tmp"
 
-sed -rn -e '/^#|^$/d'  -e "s/^(.*)/add ${ip_name}-tmp \\1/p" "${IPSET_PATH}/${IPSET_FILE}.iplist" | $IPSET_BIN -quiet restore
+sed -rn -e '/^#|^$/d' -e "s/^(.*)/add ${ip_name}-tmp \\1/p" "${IPSET_PATH}/${IPSET_FILE}.iplist" | $IPSET_BIN -quiet restore
 check_result $? "Populating ipset table"
 
 $IPSET_BIN swap "${ip_name}-tmp" "${ip_name}"
 $IPSET_BIN -quiet destroy "${ip_name}-tmp"
 
-
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 if [ ! -f "${IPSET_PATH}.conf" ] || [ -z "$(get_object_value "$ipset_hstobject" 'LISTNAME' "$ip_name" '$LISTNAME')" ]; then
 
-    # Concatenating rule
-    str="LISTNAME='$ip_name' IP_VERSION='$ip_version' SOURCE='$data_source'"
-    str="$str AUTOUPDATE='$autoupdate' SUSPENDED='no'"
-    str="$str TIME='$time' DATE='$date'"
-    echo "$str" >> $HESTIA/data/firewall/ipset.conf
+	# Concatenating rule
+	str="LISTNAME='$ip_name' IP_VERSION='$ip_version' SOURCE='$data_source'"
+	str="$str AUTOUPDATE='$autoupdate' SUSPENDED='no'"
+	str="$str TIME='$time' DATE='$date'"
+	echo "$str" >> $HESTIA/data/firewall/ipset.conf
 
 elif [ "$force" = "yes" ]; then
 
-    # update iplist last regen time
-    update_object_value "$ipset_hstobject" 'LISTNAME' "$ip_name" '$TIME' "$time"
-    update_object_value "$ipset_hstobject" 'LISTNAME' "$ip_name" '$DATE' "$date"
+	# update iplist last regen time
+	update_object_value "$ipset_hstobject" 'LISTNAME' "$ip_name" '$TIME' "$time"
+	update_object_value "$ipset_hstobject" 'LISTNAME' "$ip_name" '$DATE' "$date"
 
 fi
 
@@ -184,8 +183,8 @@ chmod 660 "${IPSET_PATH}/${IPSET_FILE}.iplist"
 
 # Install ipset daily cron updater
 if ! grep --silent --no-messages "v-update-firewall-ipset" $HESTIA/data/queue/daily.pipe; then
-    cmd="$BIN/v-update-firewall-ipset yes"
-    echo "$cmd" >> $HESTIA/data/queue/daily.pipe
+	cmd="$BIN/v-update-firewall-ipset yes"
+	echo "$cmd" >> $HESTIA/data/queue/daily.pipe
 fi
 
 #----------------------------------------------------------#

+ 19 - 20
bin/v-add-firewall-rule

@@ -11,11 +11,11 @@
 #----------------------------------------------------------#
 
 # Argument definition
-action=$(echo $1|tr '[:lower:]' '[:upper:]')
+action=$(echo $1 | tr '[:lower:]' '[:upper:]')
 ip=$2
 port_ext=$3
 protocol=${4-TCP}
-protocol=$(echo $protocol|tr '[:lower:]' '[:upper:]')
+protocol=$(echo $protocol | tr '[:lower:]' '[:upper:]')
 comment=$5
 rule=$6
 
@@ -29,18 +29,18 @@ source_conf "$HESTIA/conf/hestia.conf"
 
 # Get next firewall rule id
 get_next_fw_rule() {
-    if [ -z "$rule" ]; then
-        curr_str=$(grep "RULE=" $HESTIA/data/firewall/rules.conf |\
-         cut -f 2 -d \' | sort -n | tail -n1)
-        rule="$((curr_str +1))"
-    fi
+	if [ -z "$rule" ]; then
+		curr_str=$(grep "RULE=" $HESTIA/data/firewall/rules.conf \
+			| cut -f 2 -d \' | sort -n | tail -n1)
+		rule="$((curr_str + 1))"
+	fi
 }
 
 sort_fw_rules() {
-    cat $HESTIA/data/firewall/rules.conf |\
-        sort -n -k 2 -t \' > $HESTIA/data/firewall/rules.conf.tmp
-    mv -f $HESTIA/data/firewall/rules.conf.tmp \
-        $HESTIA/data/firewall/rules.conf
+	cat $HESTIA/data/firewall/rules.conf \
+		| sort -n -k 2 -t \' > $HESTIA/data/firewall/rules.conf.tmp
+	mv -f $HESTIA/data/firewall/rules.conf.tmp \
+		$HESTIA/data/firewall/rules.conf
 }
 
 #----------------------------------------------------------#
@@ -54,14 +54,14 @@ get_next_fw_rule
 is_format_valid 'rule'
 is_object_new '../../data/firewall/rules' 'RULE' "$rule"
 if [ -n "$comment" ]; then
-    is_format_valid 'comment'
+	is_format_valid 'comment'
 fi
 if [[ "$ip" =~ ^ipset: ]]; then
-    ipset_name="${ip#ipset:}"
-    $BIN/v-list-firewall-ipset plain | grep "^$ipset_name\s" >/dev/null
-    check_result $? 'ipset object not found' "$E_NOTEXIST"
+	ipset_name="${ip#ipset:}"
+	$BIN/v-list-firewall-ipset plain | grep "^$ipset_name\s" > /dev/null
+	check_result $? 'ipset object not found' "$E_NOTEXIST"
 else
-    is_format_valid 'ip'
+	is_format_valid 'ip'
 fi
 
 # Perform verification if read-only mode is enabled
@@ -73,8 +73,8 @@ check_hestia_demo_mode
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Concatenating rule
 str="RULE='$rule' ACTION='$action' PROTOCOL='$protocol' PORT='$port_ext'"
@@ -93,14 +93,13 @@ sort_fw_rules
 # Updating system firewall
 $BIN/v-update-firewall
 
-
 #----------------------------------------------------------#
 #                       Hestia                             #
 #----------------------------------------------------------#
 
 # Fix missing port value in log if zero
 if [ -z "$port" ]; then
-    port="0"
+	port="0"
 fi
 
 # Logging

+ 29 - 29
bin/v-add-fs-archive

@@ -31,55 +31,55 @@ is_object_valid 'user' 'USER' "$user"
 check_hestia_demo_mode
 
 # Checking user homedir
-homedir=$(grep "^$user:" /etc/passwd |cut -f 6 -d :)
+homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
 if [ -z "$homedir" ]; then
-    echo "Error: user home directory doesn't exist"
-    exit 12
+	echo "Error: user home directory doesn't exist"
+	exit 12
 fi
 
 # Checking archive
 if [ -e "$archive" ]; then
-    echo "Error: archive already exist $archive"
-    exit 1
+	echo "Error: archive already exist $archive"
+	exit 1
 fi
 
 # Checking source path
 IFS=$'\n'
 i=1
 for src in $*; do
-    if [ "$i" -gt 2 ]; then
-        rpath=$(readlink -f "$src")
-        if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
-            echo "Error: invalid source path $src"
-            exit 1
-        fi
-    fi
-    ((i++))
+	if [ "$i" -gt 2 ]; then
+		rpath=$(readlink -f "$src")
+		if [ -z "$(echo $rpath | egrep "^/tmp|^$homedir")" ]; then
+			echo "Error: invalid source path $src"
+			exit 1
+		fi
+	fi
+	((i++))
 done
 
 i=1
 for src in $*; do
-    if [ "$i" -gt 2 ]; then
-        # Deleting leading home path
-        src=$(echo "$src"| sed -e "s|/home/$user/||")
+	if [ "$i" -gt 2 ]; then
+		# Deleting leading home path
+		src=$(echo "$src" | sed -e "s|/home/$user/||")
 
-        # Creating tar.gz archive
-        user_exec tar -rf "${archive/.gz/}" -C /home/$user $src >/dev/null 2>&1
-        if [ "$?" -ne 0 ]; then
-            echo "Error: archive $archive was not created"
-            exit 3
-        fi
-    fi
-    ((i++))
+		# Creating tar.gz archive
+		user_exec tar -rf "${archive/.gz/}" -C /home/$user $src > /dev/null 2>&1
+		if [ "$?" -ne 0 ]; then
+			echo "Error: archive $archive was not created"
+			exit 3
+		fi
+	fi
+	((i++))
 done
 
 # Checking gzip
 if [[ "$archive" =~ \.gz$ ]]; then
-    user_exec gzip "${archive/.gz/}" >/dev/null 2>&1
-    if [ "$?" -ne 0 ]; then
-        echo "Error: archive $archive was not gziped"
-        exit 3
-    fi
+	user_exec gzip "${archive/.gz/}" > /dev/null 2>&1
+	if [ "$?" -ne 0 ]; then
+		echo "Error: archive $archive was not gziped"
+		exit 3
+	fi
 fi
 
 exit

+ 8 - 8
bin/v-add-fs-directory

@@ -33,22 +33,22 @@ check_hestia_demo_mode
 # Checking user homedir
 homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
 if [ -z "$homedir" ]; then
-    echo "Error: user home directory doesn't exist"
-    exit 12
+	echo "Error: user home directory doesn't exist"
+	exit 12
 fi
 
 # Checking destination path
 rpath=$(readlink -f "$dst_dir")
-if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
-    echo "Error: invalid destination path $dst_dir"
-    exit 2
+if [ -z "$(echo $rpath | egrep "^/tmp|^$homedir")" ]; then
+	echo "Error: invalid destination path $dst_dir"
+	exit 2
 fi
 
 # Adding directory
-user_exec mkdir -p "$dst_dir" >/dev/null 2>&1
+user_exec mkdir -p "$dst_dir" > /dev/null 2>&1
 if [ $? -ne 0 ]; then
-    echo "Error: directory $dst_dir was not created"
-    exit 3
+	echo "Error: directory $dst_dir was not created"
+	exit 3
 fi
 
 # Exiting

+ 8 - 8
bin/v-add-fs-file

@@ -33,22 +33,22 @@ check_hestia_demo_mode
 # Checking user homedir
 homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
 if [ -z $homedir ]; then
-    echo "Error: user home directory doesn't exist"
-    exit 12
+	echo "Error: user home directory doesn't exist"
+	exit 12
 fi
 
 # Checking destination path
 rpath=$(readlink -f "$dst_file")
-if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
-    echo "Error: invalid destination path $dst_file"
-    exit 2
+if [ -z "$(echo $rpath | egrep "^/tmp|^$homedir")" ]; then
+	echo "Error: invalid destination path $dst_file"
+	exit 2
 fi
 
 # Creating file
-user_exec touch "$dst_file" >/dev/null 2>&1
+user_exec touch "$dst_file" > /dev/null 2>&1
 if [ $? -ne 0 ]; then
-    echo "Error: file $dst_file was not created"
-    exit 3
+	echo "Error: file $dst_file was not created"
+	exit 3
 fi
 
 # Exiting

+ 378 - 381
bin/v-add-letsencrypt-domain

@@ -15,7 +15,7 @@
 user=$1
 domain=$2
 aliases=$3
-mail=${4// }
+mail=${4// /}
 
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -31,36 +31,36 @@ source_conf "$HESTIA/conf/hestia.conf"
 LE_API='https://acme-v02.api.letsencrypt.org'
 
 if [[ "$LE_STAGING" = 'yes' ]]; then
-    LE_API='https://acme-staging-v02.api.letsencrypt.org'
+	LE_API='https://acme-staging-v02.api.letsencrypt.org'
 fi
 
 # encode base64
 encode_base64() {
-    cat |base64 |tr '+/' '-_' |tr -d '\r\n='
+	cat | base64 | tr '+/' '-_' | tr -d '\r\n='
 }
 
 # Let's Encrypt v2 curl function
 query_le_v2() {
-    protected='{"nonce": "'$3'",'
-    protected=''$protected' "url": "'$1'",'
-    protected=''$protected' "alg": "RS256", "kid": "'$KID'"}'
-    content="Content-Type: application/jose+json"
-
-    payload_=$(echo -n "$2" |encode_base64)
-    protected_=$(echo -n "$protected" |encode_base64)
-    signature_=$(printf "%s" "$protected_.$payload_" |\
-        openssl dgst -sha256 -binary -sign $USER_DATA/ssl/user.key |\
-        encode_base64)
-
-    post_data='{"protected":"'"$protected_"'",'
-    post_data=$post_data'"payload":"'"$payload_"'",'
-    post_data=$post_data'"signature":"'"$signature_"'"}'
-
-    # Save http response to file passed as "$4" arg or print to stdout if not provided
-    # http response headers are always sent to stdout
-    local save_to_file=${4:-"/dev/stdout"}
-    curl --location --insecure --retry 5 --retry-connrefused --silent --dump-header /dev/stdout --data "$post_data" "$1" --header "$content" --output "$save_to_file"
-    debug_log "API call" "exit status: $?"
+	protected='{"nonce": "'$3'",'
+	protected=''$protected' "url": "'$1'",'
+	protected=''$protected' "alg": "RS256", "kid": "'$KID'"}'
+	content="Content-Type: application/jose+json"
+
+	payload_=$(echo -n "$2" | encode_base64)
+	protected_=$(echo -n "$protected" | encode_base64)
+	signature_=$(printf "%s" "$protected_.$payload_" \
+		| openssl dgst -sha256 -binary -sign $USER_DATA/ssl/user.key \
+		| encode_base64)
+
+	post_data='{"protected":"'"$protected_"'",'
+	post_data=$post_data'"payload":"'"$payload_"'",'
+	post_data=$post_data'"signature":"'"$signature_"'"}'
+
+	# Save http response to file passed as "$4" arg or print to stdout if not provided
+	# http response headers are always sent to stdout
+	local save_to_file=${4:-"/dev/stdout"}
+	curl --location --insecure --retry 5 --retry-connrefused --silent --dump-header /dev/stdout --data "$post_data" "$1" --header "$content" --output "$save_to_file"
+	debug_log "API call" "exit status: $?"
 }
 
 #----------------------------------------------------------#
@@ -72,41 +72,39 @@ is_format_valid 'user' 'domain' 'aliases'
 is_object_valid 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
 if [ -n "$mail" ]; then
-    is_boolean_format_valid "$mail" 'mail'
+	is_boolean_format_valid "$mail" 'mail'
 fi
 
 # Set DNS CAA record retrieval commands
 if [ -n "$DNS_SYSTEM" ]; then
-    dns_domain=$($BIN/v-list-dns-domains "$user" | grep "$domain" | cut -d' ' -f1)
-    caa_record=$($BIN/v-list-dns-records "$user" "$domain" | grep -i "CAA" | grep -i "letsencrypt.org" | cut -d' ' -f1 )
+	dns_domain=$($BIN/v-list-dns-domains "$user" | grep "$domain" | cut -d' ' -f1)
+	caa_record=$($BIN/v-list-dns-records "$user" "$domain" | grep -i "CAA" | grep -i "letsencrypt.org" | cut -d' ' -f1)
 fi
 
 if [ -z "$mail" ] || [ "$mail" = 'no' ]; then
-    mail=''
-    is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
-    is_object_valid 'web' 'DOMAIN' "$domain"
-    is_object_unsuspended 'web' 'DOMAIN' "$domain"
-    get_domain_values 'web'
-    # check if alias is the letsencrypt wildcard domain, if not, make the normal checks
-    if [[ "$aliases" != "*.$domain" ]]; then
-        for alias in $(echo "$aliases" |tr ',' '\n' |sort -u); do
-            check_alias="$(echo $ALIAS |tr ',' '\n' |grep ^$alias$)"
-            if [ -z "$check_alias" ]; then
-                check_result "$E_NOTEXIST" "domain alias $alias doesn't exist"
-            fi
-        done
-    fi;
+	mail=''
+	is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
+	is_object_valid 'web' 'DOMAIN' "$domain"
+	is_object_unsuspended 'web' 'DOMAIN' "$domain"
+	get_domain_values 'web'
+	# check if alias is the letsencrypt wildcard domain, if not, make the normal checks
+	if [[ "$aliases" != "*.$domain" ]]; then
+		for alias in $(echo "$aliases" | tr ',' '\n' | sort -u); do
+			check_alias="$(echo $ALIAS | tr ',' '\n' | grep ^$alias$)"
+			if [ -z "$check_alias" ]; then
+				check_result "$E_NOTEXIST" "domain alias $alias doesn't exist"
+			fi
+		done
+	fi
 else
-    is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
-    is_object_valid 'mail' 'DOMAIN' "$domain"
-    is_object_unsuspended 'mail' 'DOMAIN' "$domain"
+	is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
+	is_object_valid 'mail' 'DOMAIN' "$domain"
+	is_object_unsuspended 'mail' 'DOMAIN' "$domain"
 fi
 
-
-
 # Dump debug info
 debug_log() {
-    echo -e "\n==[${1}]==\n${2}\n" >> "$log_file"
+	echo -e "\n==[${1}]==\n${2}\n" >> "$log_file"
 }
 
 # Perform verification if read-only mode is enabled
@@ -118,25 +116,25 @@ check_hestia_demo_mode
 
 # Generate correct variables for mail domain SSL certificates
 if [ -n "$mail" ]; then
-    root_domain=$domain
-    domain="mail.$root_domain"
-    webmail=$(get_object_value "mail" "DOMAIN" "$root_domain" '$WEBMAIL');
-    if [ -n "$webmail" ]; then
-        aliases="$WEBMAIL_ALIAS.$root_domain"
-    fi
+	root_domain=$domain
+	domain="mail.$root_domain"
+	webmail=$(get_object_value "mail" "DOMAIN" "$root_domain" '$WEBMAIL')
+	if [ -n "$webmail" ]; then
+		aliases="$WEBMAIL_ALIAS.$root_domain"
+	fi
 else
-    parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
-
-    domain_redirect="$REDIRECT"
-    if [[ -n "$domain_redirect"  ]] ; then
-        domain_redirect_code="$REDIRECT_CODE"
-        $BIN/v-delete-web-domain-redirect $user $domain
-    fi
-
-    domain_forcessl="$SSL_FORCE"
-    if [[ "$domain_forcessl" == 'yes' ]] ; then
-        $BIN/v-delete-web-domain-ssl-force $user $domain
-    fi
+	parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
+
+	domain_redirect="$REDIRECT"
+	if [[ -n "$domain_redirect" ]]; then
+		domain_redirect_code="$REDIRECT_CODE"
+		$BIN/v-delete-web-domain-redirect $user $domain
+	fi
+
+	domain_forcessl="$SSL_FORCE"
+	if [[ "$domain_forcessl" == 'yes' ]]; then
+		$BIN/v-delete-web-domain-ssl-force $user $domain
+	fi
 fi
 
 log_file="/var/log/hestia/LE-${user}-${domain}.log"
@@ -153,11 +151,11 @@ domain: ${domain}
 
 # Registering LetsEncrypt user account
 $BIN/v-add-letsencrypt-user $user
-if [ "$?" -ne 0  ]; then
-    touch $HESTIA/data/queue/letsencrypt.pipe
-    sed -i "/ $domain /d" $HESTIA/data/queue/letsencrypt.pipe
-    send_notice "LETSENCRYPT" "Account registration failed ($user)"
-    check_result "$E_CONNECT" "LE account registration ($user)" > /dev/null
+if [ "$?" -ne 0 ]; then
+	touch $HESTIA/data/queue/letsencrypt.pipe
+	sed -i "/ $domain /d" $HESTIA/data/queue/letsencrypt.pipe
+	send_notice "LETSENCRYPT" "Account registration failed ($user)"
+	check_result "$E_CONNECT" "LE account registration ($user)" > /dev/null
 fi
 
 # Parsing LetsEncrypt account data
@@ -165,13 +163,13 @@ source $USER_DATA/ssl/le.conf
 
 # Checking wildcard alias
 if [ "$aliases" = "*.$domain" ]; then
-    wildcard='yes'
-    proto="dns-01"
-    if [ ! -e "$HESTIA/data/users/$user/dns/$domain.conf" ]; then
-        check_result "$E_NOTEXIST" "DNS domain $domain doesn't exist"
-    fi
+	wildcard='yes'
+	proto="dns-01"
+	if [ ! -e "$HESTIA/data/users/$user/dns/$domain.conf" ]; then
+		check_result "$E_NOTEXIST" "DNS domain $domain doesn't exist"
+	fi
 else
-    proto="http-01"
+	proto="http-01"
 fi
 
 echo -e "
@@ -182,285 +180,285 @@ echo -e "
 
 # Check if dns records exist for requested domain/aliases
 if [ "$proto" = "http-01" ]; then
-    for identifier in $(echo $domain,$aliases |tr ',' '\n' |sort -u); do
-        if [[ "$identifier" = *[![:ascii:]]* ]]; then
-            identifier=$(idn2 --quiet $identifier)
-        fi
-        if ! nslookup "${identifier}" > /dev/null 2>&1 ; then
-            # Attempt against Cloudflare DNS
-            if ! nslookup "${identifier}" 1.1.1.1 > /dev/null 2>&1 ; then
-                check_result "$E_NOTEXIST" "DNS record for $identifier doesn't exist"
-            fi
-        fi
-    done
+	for identifier in $(echo $domain,$aliases | tr ',' '\n' | sort -u); do
+		if [[ "$identifier" = *[![:ascii:]]* ]]; then
+			identifier=$(idn2 --quiet $identifier)
+		fi
+		if ! nslookup "${identifier}" > /dev/null 2>&1; then
+			# Attempt against Cloudflare DNS
+			if ! nslookup "${identifier}" 1.1.1.1 > /dev/null 2>&1; then
+				check_result "$E_NOTEXIST" "DNS record for $identifier doesn't exist"
+			fi
+		fi
+	done
 fi
 
 # Ensure DNS CAA record exists for Let's Encrypt before requesting certificate
 if [ -n "$DNS_SYSTEM" ]; then
-    # Check for DNS zone
-    if [ "$dns_domain" = "$domain" ]; then
-        # Replace DNS domain CAA records with Let's Encrypt values
-        if [ -z "$caa_record" ]; then
-            $BIN/v-add-dns-record "$user" "$domain" '@' 'CAA' '0 issue "letsencrypt.org"'
-        else
-            $BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
-            $BIN/v-add-dns-record "$user" "$domain" '@' 'CAA' '0 issue "letsencrypt.org"'
-        fi
-    fi
+	# Check for DNS zone
+	if [ "$dns_domain" = "$domain" ]; then
+		# Replace DNS domain CAA records with Let's Encrypt values
+		if [ -z "$caa_record" ]; then
+			$BIN/v-add-dns-record "$user" "$domain" '@' 'CAA' '0 issue "letsencrypt.org"'
+		else
+			$BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
+			$BIN/v-add-dns-record "$user" "$domain" '@' 'CAA' '0 issue "letsencrypt.org"'
+		fi
+	fi
 fi
 
 # Requesting nonce / STEP 1
 answer=$(curl -s -I "$LE_API/directory")
-nonce=$(echo "$answer" |grep -i nonce |cut -f2 -d \ |tr -d '\r\n')
-status=$(echo "$answer"|grep HTTP/ |tail -n1 |cut -f 2 -d ' ')
+nonce=$(echo "$answer" | grep -i nonce | cut -f2 -d \  | tr -d '\r\n')
+status=$(echo "$answer" | grep HTTP/ | tail -n1 | cut -f 2 -d ' ')
 
 debug_log "Step 1" "- status: ${status}\n- nonce: ${nonce}\n- answer: ${answer}"
 
 if [[ "$status" -ne 200 ]]; then
-    # Delete DNS CAA record
-    if [ -n "$DNS_SYSTEM" ]; then
-        if [ "$dns_domain" = "$domain" ]; then
-            if [ -n "$caa_record" ]; then
-                $BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
-            fi
-        fi
-    fi
-    check_result "$E_CONNECT" "Let's Encrypt nonce request status $status ($domain)"
+	# Delete DNS CAA record
+	if [ -n "$DNS_SYSTEM" ]; then
+		if [ "$dns_domain" = "$domain" ]; then
+			if [ -n "$caa_record" ]; then
+				$BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
+			fi
+		fi
+	fi
+	check_result "$E_CONNECT" "Let's Encrypt nonce request status $status ($domain)"
 fi
 
 # Placing new order / STEP 2
 url="$LE_API/acme/new-order"
 payload='{"identifiers":['
-for identifier in $(echo $domain,$aliases |tr ',' '\n' |sort -u); do
-    if [[ "$identifier" = *[![:ascii:]]* ]]; then
-        identifier=$(idn2 --quiet $identifier)
-    fi
-    payload=$payload'{"type":"dns","value":"'$identifier'"},'
+for identifier in $(echo $domain,$aliases | tr ',' '\n' | sort -u); do
+	if [[ "$identifier" = *[![:ascii:]]* ]]; then
+		identifier=$(idn2 --quiet $identifier)
+	fi
+	payload=$payload'{"type":"dns","value":"'$identifier'"},'
 done
-payload=$(echo "$payload"|sed "s/,$//")
+payload=$(echo "$payload" | sed "s/,$//")
 payload=$payload']}'
 answer=$(query_le_v2 "$url" "$payload" "$nonce")
-nonce=$(echo "$answer" |grep -i nonce |cut -f2 -d \ |tr -d '\r\n')
-authz=$(echo "$answer" |grep "acme/authz" |cut -f2 -d '"')
-finalize=$(echo "$answer" |grep 'finalize":' |cut -f4 -d '"')
-status=$(echo "$answer" |grep HTTP/ |tail -n1 |cut -f2 -d ' ')
+nonce=$(echo "$answer" | grep -i nonce | cut -f2 -d \  | tr -d '\r\n')
+authz=$(echo "$answer" | grep "acme/authz" | cut -f2 -d '"')
+finalize=$(echo "$answer" | grep 'finalize":' | cut -f4 -d '"')
+status=$(echo "$answer" | grep HTTP/ | tail -n1 | cut -f2 -d ' ')
 
 debug_log "Step 2" "- status: ${status}\n- nonce: ${nonce}\n- authz: ${authz}\n- finalize: ${finalize}\n- payload: ${payload}\n- answer: ${answer}"
 
 if [[ "$status" -ne 201 ]]; then
-    # Delete DNS CAA record
-    if [ -n "$DNS_SYSTEM" ]; then
-        if [ "$dns_domain" = "$domain" ]; then
-            if [ -n "$caa_record" ]; then
-                $BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
-            fi
-        fi
-    fi
-    check_result $E_CONNECT "Let's Encrypt new auth status $status ($domain)"
+	# Delete DNS CAA record
+	if [ -n "$DNS_SYSTEM" ]; then
+		if [ "$dns_domain" = "$domain" ]; then
+			if [ -n "$caa_record" ]; then
+				$BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
+			fi
+		fi
+	fi
+	check_result $E_CONNECT "Let's Encrypt new auth status $status ($domain)"
 fi
 
 # Requesting authorization token / STEP 3
 for auth in $authz; do
-    payload=''
-    answer=$(query_le_v2 "$auth" "$payload" "$nonce")
-    url=$(echo "$answer" |grep -A3 $proto |grep -m1 url |cut -f 4 -d \")
-    token=$(echo "$answer" |grep -A3 $proto |grep token |cut -f 4 -d \")
-    nonce=$(echo "$answer" |grep -i nonce |cut -f2 -d \ |tr -d '\r\n')
-    status=$(echo "$answer"|grep HTTP/ |tail -n1 |cut -f 2 -d ' ')
-
-    debug_log "Step 3" "- status: ${status}\n- nonce: ${nonce}\n- url: ${url}\n- token: ${token}\n- answer: ${answer}"
-
-    if [[ "$status" -ne 200 ]]; then
-        # Delete DNS CAA record
-        if [ -n "$DNS_SYSTEM" ]; then
-            dns_domain=$($BIN/v-list-dns-domains "$user" | grep "$domain" | cut -d' ' -f1)
-            caa_record=$($BIN/v-list-dns-records "$user" "$domain" | grep -i "letsencrypt" | cut -d' ' -f1)
-
-            if [ "$dns_domain" = "$domain" ]; then
-                if [ -n "$caa_record" ]; then
-                    $BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
-                fi
-            fi
-        fi
-        check_result "$E_CONNECT" "Let's Encrypt acme/authz bad status $status ($domain)"
-    fi
-
-    # Accepting challenge / STEP 4
-    if [ "$wildcard" = 'yes'  ]; then
-        record=$(printf "%s" "$token.$THUMB" |\
-            openssl dgst -sha256 -binary |encode_base64)
-        old_records=$($BIN/v-list-dns-records "$user" "$domain" plain|grep 'TXT')
-        old_records=$(echo "$old_records" |grep _acme-challenge |cut -f 1)
-        for old_record in $old_records; do
-            $BIN/v-delete-dns-record "$user" "$domain" "$old_record"
-        done
-        $BIN/v-add-dns-record "$user" "$domain" "_acme-challenge" "TXT" "$record"
-        check_result $? "DNS _acme-challenge record wasn't created ($domain)"
-    else
-        if [ -z "$mail" ]; then
-            if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
-                conf="$HOMEDIR/$user/conf/web/$domain/nginx.conf_letsencrypt"
-                sconf="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_letsencrypt"
-                echo 'location ~ "^/\.well-known/acme-challenge/([-_A-Za-z0-9]+)$" {' \
-                    > $conf
-                echo '    default_type text/plain;' >> $conf
-                echo '    return 200 "$1.'$THUMB'";' >> $conf
-                echo '}' >> $conf
-                if [ ! -e "$sconf" ]; then
-                    ln -s "$conf" "$sconf"
-                fi
-                if [ -n "$PROXY_SYSTEM" ]; then
-                    $BIN/v-restart-proxy
-                    check_result $? "Proxy restart failed" > /dev/null
-                fi
-            else
-                # Get root directory from configuration
-                domain_config="$HOMEDIR/$user/conf/web/$domain"
-                if [ -f "$domain_config/apache2.conf" ]; then
-                    well_known="$(cat $domain_config/apache2.conf | egrep \
-                                '^\s+DocumentRoot'| awk '{split($0, a, " "); \
+	payload=''
+	answer=$(query_le_v2 "$auth" "$payload" "$nonce")
+	url=$(echo "$answer" | grep -A3 $proto | grep -m1 url | cut -f 4 -d \")
+	token=$(echo "$answer" | grep -A3 $proto | grep token | cut -f 4 -d \")
+	nonce=$(echo "$answer" | grep -i nonce | cut -f2 -d \  | tr -d '\r\n')
+	status=$(echo "$answer" | grep HTTP/ | tail -n1 | cut -f 2 -d ' ')
+
+	debug_log "Step 3" "- status: ${status}\n- nonce: ${nonce}\n- url: ${url}\n- token: ${token}\n- answer: ${answer}"
+
+	if [[ "$status" -ne 200 ]]; then
+		# Delete DNS CAA record
+		if [ -n "$DNS_SYSTEM" ]; then
+			dns_domain=$($BIN/v-list-dns-domains "$user" | grep "$domain" | cut -d' ' -f1)
+			caa_record=$($BIN/v-list-dns-records "$user" "$domain" | grep -i "letsencrypt" | cut -d' ' -f1)
+
+			if [ "$dns_domain" = "$domain" ]; then
+				if [ -n "$caa_record" ]; then
+					$BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
+				fi
+			fi
+		fi
+		check_result "$E_CONNECT" "Let's Encrypt acme/authz bad status $status ($domain)"
+	fi
+
+	# Accepting challenge / STEP 4
+	if [ "$wildcard" = 'yes' ]; then
+		record=$(printf "%s" "$token.$THUMB" \
+			| openssl dgst -sha256 -binary | encode_base64)
+		old_records=$($BIN/v-list-dns-records "$user" "$domain" plain | grep 'TXT')
+		old_records=$(echo "$old_records" | grep _acme-challenge | cut -f 1)
+		for old_record in $old_records; do
+			$BIN/v-delete-dns-record "$user" "$domain" "$old_record"
+		done
+		$BIN/v-add-dns-record "$user" "$domain" "_acme-challenge" "TXT" "$record"
+		check_result $? "DNS _acme-challenge record wasn't created ($domain)"
+	else
+		if [ -z "$mail" ]; then
+			if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
+				conf="$HOMEDIR/$user/conf/web/$domain/nginx.conf_letsencrypt"
+				sconf="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_letsencrypt"
+				echo 'location ~ "^/\.well-known/acme-challenge/([-_A-Za-z0-9]+)$" {' \
+					> $conf
+				echo '    default_type text/plain;' >> $conf
+				echo '    return 200 "$1.'$THUMB'";' >> $conf
+				echo '}' >> $conf
+				if [ ! -e "$sconf" ]; then
+					ln -s "$conf" "$sconf"
+				fi
+				if [ -n "$PROXY_SYSTEM" ]; then
+					$BIN/v-restart-proxy
+					check_result $? "Proxy restart failed" > /dev/null
+				fi
+			else
+				# Get root directory from configuration
+				domain_config="$HOMEDIR/$user/conf/web/$domain"
+				if [ -f "$domain_config/apache2.conf" ]; then
+					well_known="$(cat $domain_config/apache2.conf | egrep \
+						'^\s+DocumentRoot' | awk '{split($0, a, " "); \
                                 print a[2]}')/.well-known"
-                else
-                    well_known="$(cat $domain_config/nginx.conf | egrep '^\s+root'| \
-                                awk '{split($0, a, " "); print a[2]}' | \
-                                sed 's/;$//')/.well-known"
-                fi
-                acme_challenge="$well_known/acme-challenge"
-                mkdir -p $acme_challenge
-                echo "$token.$THUMB" > $acme_challenge/$token
-                chown -R $user:$user $well_known
-            fi
-        else
-            if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
-                conf="$HOMEDIR/$user/conf/mail/$root_domain/nginx.conf_letsencrypt"
-                sconf="$HOMEDIR/$user/conf/mail/$root_domain/nginx.ssl.conf_letsencrypt"
-                echo 'location ~ "^/\.well-known/acme-challenge/([-_A-Za-z0-9]+)$" {' \
-                    > $conf
-                echo '    default_type text/plain;' >> $conf
-                echo '    return 200 "$1.'$THUMB'";' >> $conf
-                echo '}' >> $conf
-                if [ ! -e "$sconf" ]; then
-                    ln -s "$conf" "$sconf"
-                fi
-                if [ -n "$PROXY_SYSTEM" ]; then
-                    $BIN/v-restart-proxy
-                    check_result $? "Proxy restart failed" > /dev/null
-                fi
-            else
-                get_object_value 'mail' 'DOMAIN' "$root_domain" "WEBMAIL"
-                if [ -n "$WEBMAIL" ]; then
-                    well_known="/var/lib/$WEBMAIL/.well-known"
-                    acme_challenge="$well_known/acme-challenge"
-                    mkdir -p $acme_challenge
-                    echo "$token.$THUMB" > $acme_challenge/$token
-                    chown -R $user:$user $well_known
-                fi
-            fi
-        fi
-        if [ "$WEB_SYSTEM" = 'nginx' ]; then
-            $BIN/v-restart-web
-            check_result $? "Web restart failed" > /dev/null
-        fi
-    fi
-
-    if [ "$DNS_CLUSTER" = "yes" ]; then
-        $BIN/v-update-sys-queue dns-cluster
-    fi
-
-    # Requesting ACME validation / STEP 5
-    validation_check=$(echo "$answer" |grep '"valid"')
-    if [[ -n "$validation_check" ]]; then
-        validation='valid'
-    else
-        validation='pending'
-        sleep 5
-    fi
-
-    # Doing pol check on status
-    i=1
-    while [ "$validation" = 'pending' ]; do
-        payload='{}'
-        answer=$(query_le_v2 "$url" "$payload" "$nonce")
-        validation=$(echo "$answer"|grep -A1 $proto |tail -n1|cut -f4 -d \")
-        nonce=$(echo "$answer" |grep -i nonce |cut -f2 -d \ |tr -d '\r\n')
-        status=$(echo "$answer"|grep HTTP/ |tail -n1 |cut -f 2 -d ' ')
-        details=$(echo "$answer"| grep detail | cut -f 1 -d ',' | cut -f 2-4 -d ':' | cut -f 2 -d '"')
-
-        debug_log "Step 5" "- status: ${status}\n- url: ${url}\n- nonce: ${nonce}\n- validation: ${validation}\n- details: ${details}\n- answer: ${answer}"
-
-        if [[ "$status" -ne 200 ]]; then
-            # Delete DNS CAA record
-            if [ -n "$DNS_SYSTEM" ]; then
-                dns_domain=$($BIN/v-list-dns-domains "$user" | grep "$domain" | cut -d' ' -f1)
-                caa_record=$($BIN/v-list-dns-records "$user" "$domain" | grep -i "letsencrypt" | cut -d' ' -f1)
-
-                if [ "$dns_domain" = "$domain" ]; then
-                    if [ -n "$caa_record" ]; then
-                        $BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
-                    fi
-                fi
-            fi
-            # Download debug info from LE server
-            result=$(wget -qO- $url)
-            debug_log "Debug information Step 5"  "$result"
-            details=$(echo $result | jq '.error.detail' )
-            error_code=$(echo $result | jq '.error.status' )
-
-            debug_log "Abort Step 5" "=> Wrong status"
-            check_result "$E_CONNECT" "Let's Encrypt validation status $status ($domain). Details: $error_code:$details"
-        fi
-
-        i=$((i + 1))
-        if [ "$i" -gt 10 ]; then
-            # Delete DNS CAA record
-            if [ -n "$DNS_SYSTEM" ]; then
-                dns_domain=$($BIN/v-list-dns-domains "$user" | grep "$domain" | cut -d' ' -f1)
-                caa_record=$($BIN/v-list-dns-records "$user" "$domain" | grep -i "letsencrypt" | cut -d' ' -f1)
-
-                if [ "$dns_domain" = "$domain" ]; then
-                    if [ -n "$caa_record" ]; then
-                        $BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
-                    fi
-                fi
-            fi
-            debug_log "Abort Step 5" "=> Too many validation retries"
-            check_result "$E_CONNECT" "Let's Encrypt domain validation timeout ($domain)"
-        fi
-        sleep $((i*2))
-    done
-    if [ "$validation" = 'invalid' ]; then
-        # Delete DNS CAA record
-        if [ -n "$DNS_SYSTEM" ]; then
-            dns_domain=$($BIN/v-list-dns-domains "$user" | grep "$domain" | cut -d' ' -f1)
-            caa_record=$($BIN/v-list-dns-records "$user" "$domain" | grep -i "letsencrypt" | cut -d' ' -f1)
-
-            if [ "$dns_domain" = "$domain" ]; then
-                if [ -n "$caa_record" ]; then
-                    $BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
-                fi
-            fi
-        fi
-        check_result "$E_CONNECT" "Let's Encrypt domain verification failed ($domain)"
-    fi
+				else
+					well_known="$(cat $domain_config/nginx.conf | egrep '^\s+root' \
+						| awk '{split($0, a, " "); print a[2]}' \
+						| sed 's/;$//')/.well-known"
+				fi
+				acme_challenge="$well_known/acme-challenge"
+				mkdir -p $acme_challenge
+				echo "$token.$THUMB" > $acme_challenge/$token
+				chown -R $user:$user $well_known
+			fi
+		else
+			if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
+				conf="$HOMEDIR/$user/conf/mail/$root_domain/nginx.conf_letsencrypt"
+				sconf="$HOMEDIR/$user/conf/mail/$root_domain/nginx.ssl.conf_letsencrypt"
+				echo 'location ~ "^/\.well-known/acme-challenge/([-_A-Za-z0-9]+)$" {' \
+					> $conf
+				echo '    default_type text/plain;' >> $conf
+				echo '    return 200 "$1.'$THUMB'";' >> $conf
+				echo '}' >> $conf
+				if [ ! -e "$sconf" ]; then
+					ln -s "$conf" "$sconf"
+				fi
+				if [ -n "$PROXY_SYSTEM" ]; then
+					$BIN/v-restart-proxy
+					check_result $? "Proxy restart failed" > /dev/null
+				fi
+			else
+				get_object_value 'mail' 'DOMAIN' "$root_domain" "WEBMAIL"
+				if [ -n "$WEBMAIL" ]; then
+					well_known="/var/lib/$WEBMAIL/.well-known"
+					acme_challenge="$well_known/acme-challenge"
+					mkdir -p $acme_challenge
+					echo "$token.$THUMB" > $acme_challenge/$token
+					chown -R $user:$user $well_known
+				fi
+			fi
+		fi
+		if [ "$WEB_SYSTEM" = 'nginx' ]; then
+			$BIN/v-restart-web
+			check_result $? "Web restart failed" > /dev/null
+		fi
+	fi
+
+	if [ "$DNS_CLUSTER" = "yes" ]; then
+		$BIN/v-update-sys-queue dns-cluster
+	fi
+
+	# Requesting ACME validation / STEP 5
+	validation_check=$(echo "$answer" | grep '"valid"')
+	if [[ -n "$validation_check" ]]; then
+		validation='valid'
+	else
+		validation='pending'
+		sleep 5
+	fi
+
+	# Doing pol check on status
+	i=1
+	while [ "$validation" = 'pending' ]; do
+		payload='{}'
+		answer=$(query_le_v2 "$url" "$payload" "$nonce")
+		validation=$(echo "$answer" | grep -A1 $proto | tail -n1 | cut -f4 -d \")
+		nonce=$(echo "$answer" | grep -i nonce | cut -f2 -d \  | tr -d '\r\n')
+		status=$(echo "$answer" | grep HTTP/ | tail -n1 | cut -f 2 -d ' ')
+		details=$(echo "$answer" | grep detail | cut -f 1 -d ',' | cut -f 2-4 -d ':' | cut -f 2 -d '"')
+
+		debug_log "Step 5" "- status: ${status}\n- url: ${url}\n- nonce: ${nonce}\n- validation: ${validation}\n- details: ${details}\n- answer: ${answer}"
+
+		if [[ "$status" -ne 200 ]]; then
+			# Delete DNS CAA record
+			if [ -n "$DNS_SYSTEM" ]; then
+				dns_domain=$($BIN/v-list-dns-domains "$user" | grep "$domain" | cut -d' ' -f1)
+				caa_record=$($BIN/v-list-dns-records "$user" "$domain" | grep -i "letsencrypt" | cut -d' ' -f1)
+
+				if [ "$dns_domain" = "$domain" ]; then
+					if [ -n "$caa_record" ]; then
+						$BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
+					fi
+				fi
+			fi
+			# Download debug info from LE server
+			result=$(wget -qO- $url)
+			debug_log "Debug information Step 5" "$result"
+			details=$(echo $result | jq '.error.detail')
+			error_code=$(echo $result | jq '.error.status')
+
+			debug_log "Abort Step 5" "=> Wrong status"
+			check_result "$E_CONNECT" "Let's Encrypt validation status $status ($domain). Details: $error_code:$details"
+		fi
+
+		i=$((i + 1))
+		if [ "$i" -gt 10 ]; then
+			# Delete DNS CAA record
+			if [ -n "$DNS_SYSTEM" ]; then
+				dns_domain=$($BIN/v-list-dns-domains "$user" | grep "$domain" | cut -d' ' -f1)
+				caa_record=$($BIN/v-list-dns-records "$user" "$domain" | grep -i "letsencrypt" | cut -d' ' -f1)
+
+				if [ "$dns_domain" = "$domain" ]; then
+					if [ -n "$caa_record" ]; then
+						$BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
+					fi
+				fi
+			fi
+			debug_log "Abort Step 5" "=> Too many validation retries"
+			check_result "$E_CONNECT" "Let's Encrypt domain validation timeout ($domain)"
+		fi
+		sleep $((i * 2))
+	done
+	if [ "$validation" = 'invalid' ]; then
+		# Delete DNS CAA record
+		if [ -n "$DNS_SYSTEM" ]; then
+			dns_domain=$($BIN/v-list-dns-domains "$user" | grep "$domain" | cut -d' ' -f1)
+			caa_record=$($BIN/v-list-dns-records "$user" "$domain" | grep -i "letsencrypt" | cut -d' ' -f1)
+
+			if [ "$dns_domain" = "$domain" ]; then
+				if [ -n "$caa_record" ]; then
+					$BIN/v-delete-dns-record "$user" "$domain" "$caa_record"
+				fi
+			fi
+		fi
+		check_result "$E_CONNECT" "Let's Encrypt domain verification failed ($domain)"
+	fi
 done
 
 # Generating new ssl certificate
-ssl_dir=$($BIN/v-generate-ssl-cert "$domain" "info@$domain" "US" "California"\
-    "San Francisco" "Hestia" "IT" "$aliases" |tail -n1 |awk '{print $2}')
+ssl_dir=$($BIN/v-generate-ssl-cert "$domain" "info@$domain" "US" "California" \
+	"San Francisco" "Hestia" "IT" "$aliases" | tail -n1 | awk '{print $2}')
 
 # Sending CSR to finalize order / STEP 6
-csr=$(openssl req -in $ssl_dir/$domain.csr -outform DER |encode_base64)
+csr=$(openssl req -in $ssl_dir/$domain.csr -outform DER | encode_base64)
 payload='{"csr":"'$csr'"}'
 answer=$(query_le_v2 "$finalize" "$payload" "$nonce")
-nonce=$(echo "$answer" |grep -i nonce |cut -f2 -d \ |tr -d '\r\n')
-status=$(echo "$answer"|grep HTTP/ |tail -n1 |cut -f 2 -d ' ')
-certificate=$(echo "$answer"|grep 'certificate":' |cut -f4 -d '"')
+nonce=$(echo "$answer" | grep -i nonce | cut -f2 -d \  | tr -d '\r\n')
+status=$(echo "$answer" | grep HTTP/ | tail -n1 | cut -f 2 -d ' ')
+certificate=$(echo "$answer" | grep 'certificate":' | cut -f4 -d '"')
 
 debug_log "Step 6" "- status: ${status}\n- nonce: ${nonce}\n- payload: ${payload}\n- certificate: ${certificate}\n- answer: ${answer}"
 
 if [[ "$status" -ne 200 ]]; then
-    [ -d "$ssl_dir" ] && rm -rf "$ssl_dir"
-    check_result "$E_CONNECT" "Let's Encrypt finalize bad status $status ($domain)"
+	[ -d "$ssl_dir" ] && rm -rf "$ssl_dir"
+	check_result "$E_CONNECT" "Let's Encrypt finalize bad status $status ($domain)"
 fi
 
 # Downloading signed certificate / STEP 7
@@ -469,124 +467,123 @@ retry=0
 
 while [[ $status != 200 && $retry -lt 3 ]]; do
 
-    answer=$(query_le_v2 "$certificate" "" "$nonce" "$ssl_dir/$domain.pem")
-    status=$(echo "$answer"|grep HTTP/ |tail -n1 |cut -f 2 -d ' ')
+	answer=$(query_le_v2 "$certificate" "" "$nonce" "$ssl_dir/$domain.pem")
+	status=$(echo "$answer" | grep HTTP/ | tail -n1 | cut -f 2 -d ' ')
 
-    debug_log "Step 7" "- status: ${status}\n- retry: ${retry}\n- answer: ${answer}"
+	debug_log "Step 7" "- status: ${status}\n- retry: ${retry}\n- answer: ${answer}"
 
-    if [[ $status != 200 ]]; then
-        retry=$((retry + 1))
-        sleep $((retry * 2))    # Sleep for 2s, 4s, 6s, 8s
-    fi
+	if [[ $status != 200 ]]; then
+		retry=$((retry + 1))
+		sleep $((retry * 2)) # Sleep for 2s, 4s, 6s, 8s
+	fi
 
 done
 
 # Fallback on depreciated download method for certs (unauthenticated GET)
 if [[ $status != 200 ]]; then
-    answer=$(curl  --insecure --retry 5 --retry-connrefused --silent --dump-header /dev/stdout "$certificate" --output "$ssl_dir/$domain.pem")
-    status=$(echo "$answer"|grep HTTP/ |tail -n1 |cut -f 2 -d ' ')
+	answer=$(curl --insecure --retry 5 --retry-connrefused --silent --dump-header /dev/stdout "$certificate" --output "$ssl_dir/$domain.pem")
+	status=$(echo "$answer" | grep HTTP/ | tail -n1 | cut -f 2 -d ' ')
 
-    debug_log "Step 7 - Fallback" "- status: ${status}\n- answer: ${answer}"
+	debug_log "Step 7 - Fallback" "- status: ${status}\n- answer: ${answer}"
 fi
 
 debug_log "CERT DIR" "$(ls -las "$ssl_dir/")"
 debug_log "CERT PEM" "$(cat "$ssl_dir/$domain.pem")"
 
-
 if [[ "$status" -ne 200 ]]; then
-    [ -d "$ssl_dir" ] && rm -rf "$ssl_dir"
-    check_result "$E_NOTEXIST" "Let's Encrypt downloading signed cert failed status:$status ($domain)"
+	[ -d "$ssl_dir" ] && rm -rf "$ssl_dir"
+	check_result "$E_NOTEXIST" "Let's Encrypt downloading signed cert failed status:$status ($domain)"
 fi
 
 # Splitting up downloaded pem
-crt_end=$(grep -n 'END CERTIFICATE' $ssl_dir/$domain.pem |head -n1 |cut -f1 -d:)
+crt_end=$(grep -n 'END CERTIFICATE' $ssl_dir/$domain.pem | head -n1 | cut -f1 -d:)
 head -n $crt_end $ssl_dir/$domain.pem > $ssl_dir/$domain.crt
 
-pem_lines=$(wc -l $ssl_dir/$domain.pem |cut -f 1 -d ' ')
-ca_end=$(grep -n  'BEGIN CERTIFICATE' $ssl_dir/$domain.pem |tail -n1 |cut -f 1 -d :)
-ca_end=$(( pem_lines - crt_end + 1 ))
+pem_lines=$(wc -l $ssl_dir/$domain.pem | cut -f 1 -d ' ')
+ca_end=$(grep -n 'BEGIN CERTIFICATE' $ssl_dir/$domain.pem | tail -n1 | cut -f 1 -d :)
+ca_end=$((pem_lines - crt_end + 1))
 tail -n $ca_end $ssl_dir/$domain.pem > $ssl_dir/$domain.ca
 
 debug_log "CERT CRT" "$(cat "$ssl_dir/$domain.crt")"
 debug_log "CERT CA-1" "$(cat "$ssl_dir/$domain.ca")"
 # Temporary fix for double "END CERTIFICATE"
 if [[ $(head -n 1 $ssl_dir/$domain.ca) = "-----END CERTIFICATE-----" ]]; then
-    sed -i '1,2d' $ssl_dir/$domain.ca
+	sed -i '1,2d' $ssl_dir/$domain.ca
 fi
 debug_log "CERT CA-2" "$(cat "$ssl_dir/$domain.ca")"
 
 # Rename certs for mail
 if [ -n "$mail" ]; then
-    mv $ssl_dir/$domain.ca $ssl_dir/$root_domain.ca
-    mv $ssl_dir/$domain.crt $ssl_dir/$root_domain.crt
-    mv $ssl_dir/$domain.csr $ssl_dir/$root_domain.csr
-    mv $ssl_dir/$domain.key $ssl_dir/$root_domain.key
-    mv $ssl_dir/$domain.pem $ssl_dir/$root_domain.pem
+	mv $ssl_dir/$domain.ca $ssl_dir/$root_domain.ca
+	mv $ssl_dir/$domain.crt $ssl_dir/$root_domain.crt
+	mv $ssl_dir/$domain.csr $ssl_dir/$root_domain.csr
+	mv $ssl_dir/$domain.key $ssl_dir/$root_domain.key
+	mv $ssl_dir/$domain.pem $ssl_dir/$root_domain.pem
 fi
 
 # Adding SSL
 if [ -z "$mail" ]; then
-    ssl_home="$(get_object_value 'web' 'DOMAIN' "$domain" '$SSL_HOME')"
-    ssl_enabled="$(get_object_value 'web' 'DOMAIN' "$domain" '$SSL')"
-    if [ "$ssl_enabled" = "yes" ]; then
-        $BIN/v-update-web-domain-ssl "$user" "$domain" "$ssl_dir" "updatessl"
-    else
-        $BIN/v-add-web-domain-ssl "$user" "$domain" "$ssl_dir" "$ssl_home" "updatessl"
-    fi
- else
- # TODO replace with v-update-mail-domain-ssl if ssl is enabled
-    ssl_enabled="$(get_object_value 'mail' 'DOMAIN' "$root_domain" '$SSL')"
-    if [ "$ssl_enabled" = "yes" ]; then
-        $BIN/v-update-mail-domain-ssl "$user" "$root_domain" "$ssl_dir" "updatessl"
-    else
-        $BIN/v-add-mail-domain-ssl "$user" "$root_domain" "$ssl_dir" "updatessl"
-    fi
+	ssl_home="$(get_object_value 'web' 'DOMAIN' "$domain" '$SSL_HOME')"
+	ssl_enabled="$(get_object_value 'web' 'DOMAIN' "$domain" '$SSL')"
+	if [ "$ssl_enabled" = "yes" ]; then
+		$BIN/v-update-web-domain-ssl "$user" "$domain" "$ssl_dir" "updatessl"
+	else
+		$BIN/v-add-web-domain-ssl "$user" "$domain" "$ssl_dir" "$ssl_home" "updatessl"
+	fi
+else
+	# TODO replace with v-update-mail-domain-ssl if ssl is enabled
+	ssl_enabled="$(get_object_value 'mail' 'DOMAIN' "$root_domain" '$SSL')"
+	if [ "$ssl_enabled" = "yes" ]; then
+		$BIN/v-update-mail-domain-ssl "$user" "$root_domain" "$ssl_dir" "updatessl"
+	else
+		$BIN/v-add-mail-domain-ssl "$user" "$root_domain" "$ssl_dir" "updatessl"
+	fi
 fi
 
 if [ "$?" -ne '0' ]; then
-    [ -d "$ssl_dir" ] && rm -rf "$ssl_dir"
-    touch $HESTIA/data/queue/letsencrypt.pipe
-    sed -i "/ $domain /d" $HESTIA/data/queue/letsencrypt.pipe
-    send_notice 'LETSENCRYPT' "$domain certificate installation failed ($domain)"
-    check_result $? "SSL install" > /dev/null
+	[ -d "$ssl_dir" ] && rm -rf "$ssl_dir"
+	touch $HESTIA/data/queue/letsencrypt.pipe
+	sed -i "/ $domain /d" $HESTIA/data/queue/letsencrypt.pipe
+	send_notice 'LETSENCRYPT' "$domain certificate installation failed ($domain)"
+	check_result $? "SSL install" > /dev/null
 fi
 
 # Adding LE autorenew cronjob
 if [ -z "$(grep v-update-lets $HESTIA/data/users/admin/cron.conf)" ]; then
-    min=$(generate_password '012345' '2')
-    hour=$(generate_password '1234567' '1')
-    cmd="sudo $BIN/v-update-letsencrypt-ssl"
-    $BIN/v-add-cron-job admin "$min" "$hour" '*' '*' '*' "$cmd" > /dev/null
+	min=$(generate_password '012345' '2')
+	hour=$(generate_password '1234567' '1')
+	cmd="sudo $BIN/v-update-letsencrypt-ssl"
+	$BIN/v-add-cron-job admin "$min" "$hour" '*' '*' '*' "$cmd" > /dev/null
 fi
 
 # Updating letsencrypt key
 if [ -z "$mail" ]; then
-    if [ -z "$LETSENCRYPT" ]; then
-        add_object_key "web" 'DOMAIN' "$domain" 'LETSENCRYPT' 'FTP_USER'
-        add_object_key "web" 'DOMAIN' "$domain" 'LETSENCRYPT_FAIL_COUNT' 'LETSENCRYPT'
-    fi
-    update_object_value 'web' 'DOMAIN' "$domain" '$LETSENCRYPT' 'yes'
-    update_object_value 'web' 'DOMAIN' "$domain" '$LETSENCRYPT_FAIL_COUNT' "0"
-
-    if [[ "$domain_forcessl" == 'yes' ]] ; then
-        $BIN/v-add-web-domain-ssl-force $user $domain
-    fi
-    if [[ -n "$domain_redirect" ]] ; then
-        $BIN/v-add-web-domain-redirect $user $domain $domain_redirect $domain_redirect_code
-    fi
+	if [ -z "$LETSENCRYPT" ]; then
+		add_object_key "web" 'DOMAIN' "$domain" 'LETSENCRYPT' 'FTP_USER'
+		add_object_key "web" 'DOMAIN' "$domain" 'LETSENCRYPT_FAIL_COUNT' 'LETSENCRYPT'
+	fi
+	update_object_value 'web' 'DOMAIN' "$domain" '$LETSENCRYPT' 'yes'
+	update_object_value 'web' 'DOMAIN' "$domain" '$LETSENCRYPT_FAIL_COUNT' "0"
+
+	if [[ "$domain_forcessl" == 'yes' ]]; then
+		$BIN/v-add-web-domain-ssl-force $user $domain
+	fi
+	if [[ -n "$domain_redirect" ]]; then
+		$BIN/v-add-web-domain-redirect $user $domain $domain_redirect $domain_redirect_code
+	fi
 
 else
-    if [ -z "$LETSENCRYPT" ]; then
-        add_object_key "mail" 'DOMAIN' "$root_domain" 'LETSENCRYPT'
-        add_object_key "mail" 'DOMAIN' "$root_domain" 'LETSENCRYPT_FAIL_COUNT' 'LETSENCRYPT'
-    fi
-    update_object_value 'mail' 'DOMAIN' "$root_domain" '$LETSENCRYPT' 'yes'
-    update_object_value 'mail' 'DOMAIN' "$root_domain" '$LETSENCRYPT_FAIL_COUNT' "0"
+	if [ -z "$LETSENCRYPT" ]; then
+		add_object_key "mail" 'DOMAIN' "$root_domain" 'LETSENCRYPT'
+		add_object_key "mail" 'DOMAIN' "$root_domain" 'LETSENCRYPT_FAIL_COUNT' 'LETSENCRYPT'
+	fi
+	update_object_value 'mail' 'DOMAIN' "$root_domain" '$LETSENCRYPT' 'yes'
+	update_object_value 'mail' 'DOMAIN' "$root_domain" '$LETSENCRYPT_FAIL_COUNT' "0"
 fi
 
 # Remove challenge folder if exist
 if [ -n "$well_known" ]; then
-    rm -fr $well_known
+	rm -fr $well_known
 fi
 
 # Remove temporary SSL folder

+ 18 - 18
bin/v-add-letsencrypt-host

@@ -25,9 +25,9 @@ source_conf "$HESTIA/conf/hestia.conf"
 check_hestia_demo_mode
 
 # Argument definition
-domain=$(hostname -f);
+domain=$(hostname -f)
 if [ -z $domain ]; then
-    domain=$HOSTNAME;
+	domain=$HOSTNAME
 fi
 user="$($HESTIA/bin/v-search-domain-owner "$domain" web)"
 [[ -z "$user" ]] && user="admin"
@@ -48,9 +48,9 @@ is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
 #----------------------------------------------------------#
 
 # Check if hostname already exists as domain
-if [ "$($BIN/v-list-web-domain $user $domain plain |cut -f 1)" != "$domain" ]; then
-    # Create web domain for hostname
-    $BIN/v-add-web-domain "$user" "$domain"
+if [ "$($BIN/v-list-web-domain $user $domain plain | cut -f 1)" != "$domain" ]; then
+	# Create web domain for hostname
+	$BIN/v-add-web-domain "$user" "$domain"
 fi
 
 # Validate web domain
@@ -65,23 +65,23 @@ parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
 add_ssl="yes"
 
 if [ "$SSL" = "yes" ]; then
-    # Valildate SSL Certificate
-    if [ -e "$USER_DATA/ssl/$domain.ca" ]; then
-        if openssl verify -CAfile <(openssl x509 -in $USER_DATA/ssl/$domain.ca) $USER_DATA/ssl/$domain.pem | grep -q "$domain.pem: OK"; then
-            add_ssl="no"
-        fi
-    else
-        if openssl verify $USER_DATA/ssl/$domain.pem | grep -q "$domain.pem: OK"; then
-            add_ssl="no"
-        fi
-    fi
+	# Valildate SSL Certificate
+	if [ -e "$USER_DATA/ssl/$domain.ca" ]; then
+		if openssl verify -CAfile <(openssl x509 -in $USER_DATA/ssl/$domain.ca) $USER_DATA/ssl/$domain.pem | grep -q "$domain.pem: OK"; then
+			add_ssl="no"
+		fi
+	else
+		if openssl verify $USER_DATA/ssl/$domain.pem | grep -q "$domain.pem: OK"; then
+			add_ssl="no"
+		fi
+	fi
 fi
 
 # Add let's encrypt ssl if needed
 if [ "$add_ssl" = "yes" ]; then
-    # Add let's encrypt ssl
-    $BIN/v-add-letsencrypt-domain "$user" "$domain"
-    check_result $? "Let's Encrypt SSL creation failed"  "$E_UPDATE"
+	# Add let's encrypt ssl
+	$BIN/v-add-letsencrypt-domain "$user" "$domain"
+	check_result $? "Let's Encrypt SSL creation failed" "$E_UPDATE"
 fi
 
 # Add certificate to backend

+ 42 - 43
bin/v-add-letsencrypt-user

@@ -25,32 +25,32 @@ source_conf "$HESTIA/conf/hestia.conf"
 LE_API='https://acme-v02.api.letsencrypt.org'
 
 if [[ "$LE_STAGING" = 'yes' ]]; then
-    LE_API='https://acme-staging-v02.api.letsencrypt.org'
+	LE_API='https://acme-staging-v02.api.letsencrypt.org'
 fi
 
 # encode base64
 encode_base64() {
-    cat |base64 |tr '+/' '-_' |tr -d '\r\n='
+	cat | base64 | tr '+/' '-_' | tr -d '\r\n='
 }
 
 # Let's Encrypt v2 curl function
 query_le_v2() {
-    protected='{"nonce": "'$3'",'
-    protected=''$protected' "url": "'$1'",'
-    protected=''$protected' "alg": "RS256", "jwk": '$jwk'}'
-    content="Content-Type: application/jose+json"
-
-    payload_=$(echo -n "$2" |encode_base64)
-    protected_=$(echo -n "$protected" |encode_base64)
-    signature_=$(printf "%s" "$protected_.$payload_" |\
-        openssl dgst -sha256 -binary -sign $USER_DATA/ssl/user.key |\
-        encode_base64)
-
-    post_data='{"protected":"'"$protected_"'",'
-    post_data=$post_data'"payload":"'"$payload_"'",'
-    post_data=$post_data'"signature":"'"$signature_"'"}'
-
-    curl -s -i -d "$post_data" "$1" -H "$content"
+	protected='{"nonce": "'$3'",'
+	protected=''$protected' "url": "'$1'",'
+	protected=''$protected' "alg": "RS256", "jwk": '$jwk'}'
+	content="Content-Type: application/jose+json"
+
+	payload_=$(echo -n "$2" | encode_base64)
+	protected_=$(echo -n "$protected" | encode_base64)
+	signature_=$(printf "%s" "$protected_.$payload_" \
+		| openssl dgst -sha256 -binary -sign $USER_DATA/ssl/user.key \
+		| encode_base64)
+
+	post_data='{"protected":"'"$protected_"'",'
+	post_data=$post_data'"payload":"'"$payload_"'",'
+	post_data=$post_data'"signature":"'"$signature_"'"}'
+
+	curl -s -i -d "$post_data" "$1" -H "$content"
 }
 
 #----------------------------------------------------------#
@@ -61,10 +61,10 @@ check_args '1' "$#" 'USER'
 is_format_valid 'user'
 is_object_valid 'user' 'USER' "$user"
 if [ -e "$USER_DATA/ssl/le.conf" ]; then
-    source "$USER_DATA/ssl/le.conf"
+	source "$USER_DATA/ssl/le.conf"
 fi
 if [ -n "$KID" ]; then
-    exit
+	exit
 fi
 
 # Perform verification if read-only mode is enabled
@@ -76,7 +76,7 @@ check_hestia_demo_mode
 
 # Defining user email
 if [[ -z "$EMAIL" ]]; then
-    EMAIL=$(get_user_value '$CONTACT')
+	EMAIL=$(get_user_value '$CONTACT')
 fi
 
 # Defining user agreement
@@ -85,21 +85,21 @@ agreement=''
 # Generating user key
 KEY="$USER_DATA/ssl/user.key"
 if [ ! -e "$KEY" ]; then
-    openssl genrsa -out "$KEY" 4096 >/dev/null 2>&1
-    chmod 600 $KEY
+	openssl genrsa -out "$KEY" 4096 > /dev/null 2>&1
+	chmod 600 $KEY
 fi
 
 # Defining key exponent
 if [ -z "$EXPONENT" ]; then
-    EXPONENT=$(openssl pkey -inform pem -in "$KEY" -noout -text_pub |\
-        grep Exponent: |cut -f 2 -d '(' |cut -f 1 -d ')' |sed -e 's/x//' |\
-        xxd -r -p |encode_base64)
+	EXPONENT=$(openssl pkey -inform pem -in "$KEY" -noout -text_pub \
+		| grep Exponent: | cut -f 2 -d '(' | cut -f 1 -d ')' | sed -e 's/x//' \
+		| xxd -r -p | encode_base64)
 fi
 
 # Defining key modulus
 if [ -z "$MODULUS" ]; then
-    MODULUS=$(openssl rsa -in "$KEY" -modulus -noout |\
-        sed -e 's/^Modulus=//' |xxd -r -p |encode_base64)
+	MODULUS=$(openssl rsa -in "$KEY" -modulus -noout \
+		| sed -e 's/^Modulus=//' | xxd -r -p | encode_base64)
 fi
 
 # Defining JWK
@@ -107,23 +107,22 @@ jwk='{"e":"'$EXPONENT'","kty":"RSA","n":"'"$MODULUS"'"}'
 
 # Defining key thumbnail
 if [ -z "$THUMB" ]; then
-    THUMB="$(echo -n "$jwk" |openssl dgst -sha256 -binary |encode_base64)"
+	THUMB="$(echo -n "$jwk" | openssl dgst -sha256 -binary | encode_base64)"
 fi
 
-
 # Requesting ACME nonce
-nonce=$(curl -s -I "$LE_API/directory" |grep -i nonce |cut -f2 -d\ |tr -d '\r\n')
+nonce=$(curl -s -I "$LE_API/directory" | grep -i nonce | cut -f2 -d\  | tr -d '\r\n')
 
 # Creating ACME account
 url="$LE_API/acme/new-acct"
 payload='{"termsOfServiceAgreed": true}'
 answer=$(query_le_v2 "$url" "$payload" "$nonce")
-kid=$(echo "$answer" |grep -i location: |cut -f2 -d ' '|tr -d '\r')
+kid=$(echo "$answer" | grep -i location: | cut -f2 -d ' ' | tr -d '\r')
 
 # Checking answer status
-status=$(echo "$answer" |grep HTTP/ |tail -n1 |cut -f2 -d ' ')
+status=$(echo "$answer" | grep HTTP/ | tail -n1 | cut -f2 -d ' ')
 if [[ "${status:0:2}" -ne "20" ]]; then
-    check_result "$E_CONNECT" "Let's Encrypt acc registration failed $status"
+	check_result "$E_CONNECT" "Let's Encrypt acc registration failed $status"
 fi
 
 #----------------------------------------------------------#
@@ -132,18 +131,18 @@ fi
 
 # Adding le.conf
 if [ ! -e "$USER_DATA/ssl/le.conf" ]; then
-    echo "EXPONENT='$EXPONENT'" > $USER_DATA/ssl/le.conf
-    echo "MODULUS='$MODULUS'" >> $USER_DATA/ssl/le.conf
-    echo "THUMB='$THUMB'" >> $USER_DATA/ssl/le.conf
-    echo "EMAIL='$EMAIL'" >> $USER_DATA/ssl/le.conf
-    echo "KID='$kid'" >> $USER_DATA/ssl/le.conf
-    chmod 660  $USER_DATA/ssl/le.conf
+	echo "EXPONENT='$EXPONENT'" > $USER_DATA/ssl/le.conf
+	echo "MODULUS='$MODULUS'" >> $USER_DATA/ssl/le.conf
+	echo "THUMB='$THUMB'" >> $USER_DATA/ssl/le.conf
+	echo "EMAIL='$EMAIL'" >> $USER_DATA/ssl/le.conf
+	echo "KID='$kid'" >> $USER_DATA/ssl/le.conf
+	chmod 660 $USER_DATA/ssl/le.conf
 else
-    sed -i '/^KID=/d' $USER_DATA/ssl/le.conf
-    echo "KID='$kid'" >> $USER_DATA/ssl/le.conf
+	sed -i '/^KID=/d' $USER_DATA/ssl/le.conf
+	echo "KID='$kid'" >> $USER_DATA/ssl/le.conf
 fi
 
 # Logging
 log_event "$OK" "$ARGUMENTS"
 
-exit
+exit

+ 31 - 33
bin/v-add-mail-account

@@ -15,7 +15,8 @@ user=$1
 domain=$2
 domain_idn=$2
 account=$3
-password=$4; HIDE=4
+password=$4
+HIDE=4
 quota=${5-unlimited}
 
 # Includes
@@ -32,13 +33,12 @@ source_conf "$HESTIA/conf/hestia.conf"
 
 # Additional argument formatting
 if [[ "$account" =~ [[:upper:]] ]]; then
-    account=$(echo "$account" |tr '[:upper:]' '[:lower:]')
+	account=$(echo "$account" | tr '[:upper:]' '[:lower:]')
 fi
 
 format_domain
 format_domain_idn
 
-
 #----------------------------------------------------------#
 #                    Verifications                         #
 #----------------------------------------------------------#
@@ -46,7 +46,7 @@ format_domain_idn
 check_args '4' "$#" 'USER DOMAIN ACCOUNT PASSWORD [QUOTA]'
 is_format_valid 'user' 'domain' 'account'
 if [ "$quota" != 'unlimited' ]; then
-    is_format_valid 'quota'
+	is_format_valid 'quota'
 fi
 is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
 is_object_valid 'user' 'USER' "$user"
@@ -60,7 +60,6 @@ is_password_valid
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode
 
-
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
@@ -68,33 +67,32 @@ check_hestia_demo_mode
 # Generating hashed password
 
 if [ -n "$(doveadm pw -l | grep BLF-CRYPT)" ]; then
-    set +H # disable ! style history substitution
-    md5="$(doveadm pw -s BLF-CRYPT -p "$password")"
+	set +H # disable ! style history substitution
+	md5="$(doveadm pw -s BLF-CRYPT -p "$password")"
 elif [ -n "$(doveadm pw -l | grep ARGON2ID)" ]; then
-    # Fall back on Argon2id if bcrypt is not available
-    set +H # disable ! style history substitution
-    md5="$(doveadm pw -s ARGON2ID -p "$password")"
+	# Fall back on Argon2id if bcrypt is not available
+	set +H # disable ! style history substitution
+	md5="$(doveadm pw -s ARGON2ID -p "$password")"
 else
-    # Fall back on MD5 if neither bcrypt nor argon2id is available
-    salt=$(generate_password "$PW_MATRIX" "8")
-    md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)"
+	# Fall back on MD5 if neither bcrypt nor argon2id is available
+	salt=$(generate_password "$PW_MATRIX" "8")
+	md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<< $password)"
 fi
 # Adding account info into password file
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    if [ "$quota" = 'unlimited' ]; then
-        quota='0'
-    fi
-    str="$account:$md5:$user:mail::$HOMEDIR/$user:${quota}:userdb_quota_rule=*:storage=${quota}M"
-    echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
-    userstr="$account:$account:$user:mail:$HOMEDIR/$user"
-    echo $userstr >> $HOMEDIR/$user/conf/mail/$domain/accounts
+	if [ "$quota" = 'unlimited' ]; then
+		quota='0'
+	fi
+	str="$account:$md5:$user:mail::$HOMEDIR/$user:${quota}:userdb_quota_rule=*:storage=${quota}M"
+	echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
+	userstr="$account:$account:$user:mail:$HOMEDIR/$user"
+	echo $userstr >> $HOMEDIR/$user/conf/mail/$domain/accounts
 fi
 
 # Create mail account folder (mailbox)
- mkdir $HOMEDIR/$user/mail/$domain/$account
- chown $user:mail $HOMEDIR/$user/mail/$domain/$account
- chmod 700 $HOMEDIR/$user/mail/$domain/$account
-
+mkdir $HOMEDIR/$user/mail/$domain/$account
+chown $user:mail $HOMEDIR/$user/mail/$domain/$account
+chmod 700 $HOMEDIR/$user/mail/$domain/$account
 
 #----------------------------------------------------------#
 #                       Hestia                             #
@@ -102,11 +100,11 @@ fi
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 if [[ "$quota" -eq '0' ]]; then
-    quota='unlimited'
+	quota='unlimited'
 fi
 
 str="ACCOUNT='$account' ALIAS='' AUTOREPLY='no' FWD='' FWD_ONLY=''"
@@ -117,16 +115,16 @@ chmod 660 $USER_DATA/mail/$domain.conf
 
 syshealth_repair_mail_account_config
 
-touch $HOMEDIR/$user/conf/mail/$domain/limits;
+touch $HOMEDIR/$user/conf/mail/$domain/limits
 
 user_rate_limit=$(get_object_value 'mail' 'DOMAIN' "$domain" '$RATE_LIMIT')
 if [ -n "$user_rate_limit" ]; then
-    sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/limits
-    echo "$account@$domain_idn:$user_rate_limit" >> $HOMEDIR/$user/conf/mail/$domain/limits
+	sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/limits
+	echo "$account@$domain_idn:$user_rate_limit" >> $HOMEDIR/$user/conf/mail/$domain/limits
 else
-    system=$(cat /etc/exim4/limit.conf)
-    sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/limits
-    echo "$account@$domain_idn:$system" >> $HOMEDIR/$user/conf/mail/$domain/limits
+	system=$(cat /etc/exim4/limit.conf)
+	sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/limits
+	echo "$account@$domain_idn:$system" >> $HOMEDIR/$user/conf/mail/$domain/limits
 fi
 
 # Increase mail accounts counter

+ 5 - 5
bin/v-add-mail-account-alias

@@ -56,8 +56,8 @@ check_hestia_demo_mode
 
 # Adding exim alias
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    str="$malias@$domain_idn:$account@$domain_idn"
-    echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/aliases
+	str="$malias@$domain_idn:$account@$domain_idn"
+	echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/aliases
 fi
 
 #----------------------------------------------------------#
@@ -67,11 +67,11 @@ fi
 # Adding hestia alias
 aliases=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS')
 if [ -z "$aliases" ]; then
-    aliases="$malias"
+	aliases="$malias"
 else
-    aliases="$aliases,$malias"
+	aliases="$aliases,$malias"
 fi
-update_object_value "mail/$domain" 'ACCOUNT' "$account"  '$ALIAS' "$aliases"
+update_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS' "$aliases"
 
 # Logging
 $BIN/v-log-action "$user" "Info" "Mail" "Added alias $malias to mail account $account@$domain."

+ 6 - 6
bin/v-add-mail-account-autoreply

@@ -29,9 +29,9 @@ source_conf "$HESTIA/conf/hestia.conf"
 
 # Define mail user
 if [ "$MAIL_SYSTEM" = 'exim4' ]; then
-    MAIL_USER=Debian-exim
+	MAIL_USER=Debian-exim
 else
-    MAIL_USER=exim
+	MAIL_USER=exim
 fi
 
 # Additional argument formatting
@@ -63,10 +63,10 @@ check_hestia_demo_mode
 
 # Adding exim autoreply
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    msg="$HOMEDIR/$user/conf/mail/$domain/autoreply.$account.msg"
-    echo -e "$autoreply" > $msg
-    chown $MAIL_USER:mail $msg
-    chmod 660 $msg
+	msg="$HOMEDIR/$user/conf/mail/$domain/autoreply.$account.msg"
+	echo -e "$autoreply" > $msg
+	chown $MAIL_USER:mail $msg
+	chmod 660 $msg
 fi
 
 #----------------------------------------------------------#

+ 10 - 10
bin/v-add-mail-account-forward

@@ -37,8 +37,8 @@ format_domain_idn
 
 check_args '4' "$#" 'USER DOMAIN ACCOUNT FORWARD'
 is_format_valid 'user' 'domain' 'account'
-if [ "$email_forward"  != ':blackhole:' ]; then
-    is_format_valid 'email_forward'
+if [ "$email_forward" != ':blackhole:' ]; then
+	is_format_valid 'email_forward'
 fi
 is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
 is_object_valid 'user' 'USER' "$user"
@@ -49,9 +49,9 @@ is_object_valid "mail/$domain" 'ACCOUNT' "$account"
 is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
 fwd=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD')
 if [ -n "$(echo $fwd | grep -w "$email_forward")" ]; then
-    echo "Error: forward $email_forward exists"
-    log_event "$E_EXISTS" "$ARGUMENTS"
-    exit $E_EXISTS
+	echo "Error: forward $email_forward exists"
+	log_event "$E_EXISTS" "$ARGUMENTS"
+	exit $E_EXISTS
 fi
 
 # Perform verification if read-only mode is enabled
@@ -63,15 +63,15 @@ check_hestia_demo_mode
 
 # Define fwd string
 if [ -z "$fwd" ]; then
-    fwd="$email_forward"
+	fwd="$email_forward"
 else
-    fwd="$fwd,$email_forward"
+	fwd="$fwd,$email_forward"
 fi
 
 # Adding forward to exim
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/aliases
-    echo "$account@$domain_idn:$fwd" >> $HOMEDIR/$user/conf/mail/$domain/aliases
+	sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/aliases
+	echo "$account@$domain_idn:$fwd" >> $HOMEDIR/$user/conf/mail/$domain/aliases
 fi
 
 #----------------------------------------------------------#
@@ -79,7 +79,7 @@ fi
 #----------------------------------------------------------#
 
 # Updating config
-update_object_value "mail/$domain" 'ACCOUNT' "$account"  '$FWD' "$fwd"
+update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD' "$fwd"
 
 # Logging
 $BIN/v-log-action "$user" "Warning" "Mail" "Mail forwarding on mail account $account@$domain enabled (send to: $email_forward)."

+ 8 - 9
bin/v-add-mail-account-fwd-only

@@ -28,9 +28,9 @@ source_conf "$HESTIA/conf/hestia.conf"
 
 # Define mail user
 if [ "$MAIL_SYSTEM" = 'exim4' ]; then
-    MAIL_USER=Debian-exim
+	MAIL_USER=Debian-exim
 else
-    MAIL_USER=exim
+	MAIL_USER=exim
 fi
 
 # Additional argument formatting
@@ -53,9 +53,9 @@ is_object_valid "mail/$domain" 'ACCOUNT' "$account"
 is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
 fwd=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD')
 if [ -z "$fwd" ]; then
-    echo "Error: forward doesn't exist"
-    log_event "$E_NOTEXIST" "$ARGUMENTS"
-    exit "$E_NOTEXIST"
+	echo "Error: forward doesn't exist"
+	log_event "$E_NOTEXIST" "$ARGUMENTS"
+	exit "$E_NOTEXIST"
 fi
 
 # Perform verification if read-only mode is enabled
@@ -67,18 +67,17 @@ check_hestia_demo_mode
 
 # Adding account to fwd_only
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    echo "$account" >> $HOMEDIR/$user/conf/mail/$domain/fwd_only
-    chown -R $MAIL_USER:mail $HOMEDIR/$user/conf/mail/$domain/fwd_only
+	echo "$account" >> $HOMEDIR/$user/conf/mail/$domain/fwd_only
+	chown -R $MAIL_USER:mail $HOMEDIR/$user/conf/mail/$domain/fwd_only
 fi
 
-
 #----------------------------------------------------------#
 #                       Hestia                             #
 #----------------------------------------------------------#
 
 # Updating config
 add_object_key "mail/$domain" 'ACCOUNT' "$account" 'FWD_ONLY' 'MD5'
-update_object_value "mail/$domain" 'ACCOUNT' "$account"  '$FWD_ONLY' "yes"
+update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD_ONLY' "yes"
 
 # Logging
 $BIN/v-log-action "$user" "Warning" "Mail" "Forward-only flag enabled on mail account $account@$domain."

+ 82 - 82
bin/v-add-mail-domain

@@ -36,9 +36,9 @@ source_conf "$HESTIA/conf/hestia.conf"
 
 # Define mail user
 if [ "$MAIL_SYSTEM" = 'exim4' ]; then
-    MAIL_USER=Debian-exim
+	MAIL_USER=Debian-exim
 else
-    MAIL_USER=exim
+	MAIL_USER=exim
 fi
 
 # Additional argument formatting
@@ -56,17 +56,17 @@ is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
 is_object_valid 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
 
-if [ "$($BIN/v-list-mail-domain $user $domain_utf plain |cut -f 1) " != "$domain" ]; then
-    is_domain_new 'mail' "$domain_utf"
+if [ "$($BIN/v-list-mail-domain $user $domain_utf plain | cut -f 1) " != "$domain" ]; then
+	is_domain_new 'mail' "$domain_utf"
 fi
-if [ "$($BIN/v-list-mail-domain $user $domain_idn plain |cut -f 1) " != "$domain" ]; then
-    is_domain_new 'mail' "$domain_idn"
+if [ "$($BIN/v-list-mail-domain $user $domain_idn plain | cut -f 1) " != "$domain" ]; then
+	is_domain_new 'mail' "$domain_idn"
 else
-    is_domain_new 'mail' "$domain"
+	is_domain_new 'mail' "$domain"
 fi
 if [ -z "$(is_ip_format_valid $domain)" ]; then
-    echo "Error: Invalid domain format. IP address detected as input."
-    exit 1
+	echo "Error: Invalid domain format. IP address detected as input."
+	exit 1
 fi
 
 is_package_full 'MAIL_DOMAINS'
@@ -85,10 +85,10 @@ source_conf "$USER_DATA/user.conf"
 # Inherit web domain local ip address
 domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
 if [ ! -z "$domain_ip" ]; then
-    local_ip=$(get_real_ip "$domain_ip")
-    is_ip_valid "$local_ip" "$user"
+	local_ip=$(get_real_ip "$domain_ip")
+	is_ip_valid "$local_ip" "$user"
 else
-    get_user_ip
+	get_user_ip
 fi
 
 # Generating timestamp
@@ -105,9 +105,9 @@ syshealth_repair_mail_config
 
 # Generating DKIM keys
 if [ "$dkim" = 'yes' ]; then
-    openssl genrsa -out $USER_DATA/mail/$domain.pem $dkim_size &>/dev/null
-    openssl rsa -pubout -in $USER_DATA/mail/$domain.pem \
-        -out $USER_DATA/mail/$domain.pub &>/dev/null
+	openssl genrsa -out $USER_DATA/mail/$domain.pem $dkim_size &> /dev/null
+	openssl rsa -pubout -in $USER_DATA/mail/$domain.pem \
+		-out $USER_DATA/mail/$domain.pub &> /dev/null
 fi
 
 # Set permissions
@@ -116,78 +116,78 @@ chmod 660 $USER_DATA/mail.conf
 
 # Building exim configs
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    mkdir $HOMEDIR/$user/conf/mail/$domain
-    mkdir $HOMEDIR/$user/mail/$domain_idn
-    touch $HOMEDIR/$user/conf/mail/$domain/aliases
-    touch $HOMEDIR/$user/conf/mail/$domain/passwd
-    touch $HOMEDIR/$user/conf/mail/$domain/fwd_only
-    touch $HOMEDIR/$user/conf/mail/$domain/accounts
-    ln -s $HOMEDIR/$user/conf/mail/$domain \
-        /etc/$MAIL_SYSTEM/domains/$domain_idn
-
-    # Seeting outgoing ip address
-    if [ -n "$local_ip" ]; then
-        echo "$local_ip" > $HOMEDIR/$user/conf/mail/$domain/ip
-    fi
-
-    if [ -n "$ANTISPAM_SYSTEM" ]; then
-        # Adding antispam protection
-        if [ "$antispam" = 'yes' ]; then
-            touch "$HOMEDIR/$user/conf/mail/$domain/antispam"
-        fi
-        if [ "$reject" = 'yes' ]; then
-            touch "$HOMEDIR/$user/conf/mail/$domain/reject_spam"
-        fi
-    fi
-
-    if [ -n "$ANTIVIRUS_SYSTEM" ]; then
-        # Adding antivirus protection
-        if [ "$antivirus" = 'yes' ]; then
-            touch "$HOMEDIR/$user/conf/mail/$domain/antivirus"
-        fi
-    fi
-
-    # Adding dkim support
-    if [ "$dkim" = 'yes' ]; then
-        cp -f $USER_DATA/mail/$domain.pem \
-            $HOMEDIR/$user/conf/mail/$domain/dkim.pem
-    fi
-
-    # Set permission
-    chmod 771 $HOMEDIR/$user/conf/mail/$domain
-    chmod 660 $HOMEDIR/$user/conf/mail/$domain/*
-    chmod 771 /etc/$MAIL_SYSTEM/domains/$domain_idn
-    chmod 770 $HOMEDIR/$user/mail/$domain_idn
-
-    # Set ownership
-    chown -R $MAIL_USER:mail $HOMEDIR/$user/conf/mail/$domain
-    if [ "$IMAP_SYSTEM" = 'dovecot' ]; then
-        chown -R dovecot:mail $HOMEDIR/$user/conf/mail/$domain/passwd
-    fi
-    chown $MAIL_USER:mail $HOMEDIR/$user/conf/mail/$domain/accounts
-    chown $user:mail $HOMEDIR/$user/mail/$domain_idn
+	mkdir $HOMEDIR/$user/conf/mail/$domain
+	mkdir $HOMEDIR/$user/mail/$domain_idn
+	touch $HOMEDIR/$user/conf/mail/$domain/aliases
+	touch $HOMEDIR/$user/conf/mail/$domain/passwd
+	touch $HOMEDIR/$user/conf/mail/$domain/fwd_only
+	touch $HOMEDIR/$user/conf/mail/$domain/accounts
+	ln -s $HOMEDIR/$user/conf/mail/$domain \
+		/etc/$MAIL_SYSTEM/domains/$domain_idn
+
+	# Seeting outgoing ip address
+	if [ -n "$local_ip" ]; then
+		echo "$local_ip" > $HOMEDIR/$user/conf/mail/$domain/ip
+	fi
+
+	if [ -n "$ANTISPAM_SYSTEM" ]; then
+		# Adding antispam protection
+		if [ "$antispam" = 'yes' ]; then
+			touch "$HOMEDIR/$user/conf/mail/$domain/antispam"
+		fi
+		if [ "$reject" = 'yes' ]; then
+			touch "$HOMEDIR/$user/conf/mail/$domain/reject_spam"
+		fi
+	fi
+
+	if [ -n "$ANTIVIRUS_SYSTEM" ]; then
+		# Adding antivirus protection
+		if [ "$antivirus" = 'yes' ]; then
+			touch "$HOMEDIR/$user/conf/mail/$domain/antivirus"
+		fi
+	fi
+
+	# Adding dkim support
+	if [ "$dkim" = 'yes' ]; then
+		cp -f $USER_DATA/mail/$domain.pem \
+			$HOMEDIR/$user/conf/mail/$domain/dkim.pem
+	fi
+
+	# Set permission
+	chmod 771 $HOMEDIR/$user/conf/mail/$domain
+	chmod 660 $HOMEDIR/$user/conf/mail/$domain/*
+	chmod 771 /etc/$MAIL_SYSTEM/domains/$domain_idn
+	chmod 770 $HOMEDIR/$user/mail/$domain_idn
+
+	# Set ownership
+	chown -R $MAIL_USER:mail $HOMEDIR/$user/conf/mail/$domain
+	if [ "$IMAP_SYSTEM" = 'dovecot' ]; then
+		chown -R dovecot:mail $HOMEDIR/$user/conf/mail/$domain/passwd
+	fi
+	chown $MAIL_USER:mail $HOMEDIR/$user/conf/mail/$domain/accounts
+	chown $user:mail $HOMEDIR/$user/mail/$domain_idn
 fi
 
 # Adding dkim dns records
 if [ -n "$DNS_SYSTEM" ] && [ "$dkim" = 'yes' ]; then
-    check_dns_domain=$(is_object_valid 'dns' 'DOMAIN' "$domain")
-    if [ "$?" -eq 0 ]; then
-        p=$(cat $USER_DATA/mail/$domain.pub|grep -v ' KEY---'|tr -d '\n')
-        record='_domainkey'
-        policy="\"t=y; o=~;\""
-        $BIN/v-add-dns-record "$user" "$domain" "$record" TXT "$policy" '' '' 'no' '' 'yes'
-
-        record='mail._domainkey'
-        selector="\"v=DKIM1\; k=rsa\; p=$p\""
-        $BIN/v-add-dns-record "$user" "$domain" "$record" TXT "$selector" '' '' 'yes' '' 'yes'
-    fi
+	check_dns_domain=$(is_object_valid 'dns' 'DOMAIN' "$domain")
+	if [ "$?" -eq 0 ]; then
+		p=$(cat $USER_DATA/mail/$domain.pub | grep -v ' KEY---' | tr -d '\n')
+		record='_domainkey'
+		policy="\"t=y; o=~;\""
+		$BIN/v-add-dns-record "$user" "$domain" "$record" TXT "$policy" '' '' 'no' '' 'yes'
+
+		record='mail._domainkey'
+		selector="\"v=DKIM1\; k=rsa\; p=$p\""
+		$BIN/v-add-dns-record "$user" "$domain" "$record" TXT "$selector" '' '' 'yes' '' 'yes'
+	fi
 fi
 
 # Add webmail configuration to mail domain
 if [ -n "$WEB_SYSTEM" ] || [ -n "$PROXY_SYSTEM" ]; then
-    if [ -n "$IMAP_SYSTEM" ]; then
-        $BIN/v-add-mail-domain-webmail "$user" "$domain" '' 'no'
-    fi
+	if [ -n "$IMAP_SYSTEM" ]; then
+		$BIN/v-add-mail-domain-webmail "$user" "$domain" '' 'no'
+	fi
 fi
 
 #----------------------------------------------------------#
@@ -198,16 +198,16 @@ fi
 increase_user_value "$user" '$U_MAIL_DOMAINS'
 
 if [ "$dkim" = 'yes' ]; then
-    increase_user_value "$user" '$U_MAIL_DKIM'
+	increase_user_value "$user" '$U_MAIL_DKIM'
 fi
 
 # Restarting web server
 $BIN/v-restart-web "$restart"
-check_result $? "Web restart failed" >/dev/null
+check_result $? "Web restart failed" > /dev/null
 
 # Restarting proxy server
 $BIN/v-restart-proxy "$restart"
-check_result $? "Proxy restart failed" >/dev/null
+check_result $? "Proxy restart failed" > /dev/null
 
 # Logging
 $BIN/v-log-action "$user" "Info" "Mail" "Added new mail domain ($domain)."

+ 1 - 1
bin/v-add-mail-domain-antispam

@@ -52,7 +52,7 @@ check_hestia_demo_mode
 
 # Adding antispam flag
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    touch $HOMEDIR/$user/conf/mail/$domain/antispam
+	touch $HOMEDIR/$user/conf/mail/$domain/antispam
 fi
 
 #----------------------------------------------------------#

+ 1 - 1
bin/v-add-mail-domain-antivirus

@@ -52,7 +52,7 @@ check_hestia_demo_mode
 
 # Adding antivirus flag
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    touch $HOMEDIR/$user/conf/mail/$domain/antivirus
+	touch $HOMEDIR/$user/conf/mail/$domain/antivirus
 fi
 
 #----------------------------------------------------------#

+ 2 - 2
bin/v-add-mail-domain-catchall

@@ -52,8 +52,8 @@ check_hestia_demo_mode
 
 # Adding catchall alias
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    sed -i "/*@$domain_idn:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
-    echo "*@$domain_idn:$email" >> $HOMEDIR/$user/conf/mail/$domain/aliases
+	sed -i "/*@$domain_idn:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
+	echo "*@$domain_idn:$email" >> $HOMEDIR/$user/conf/mail/$domain/aliases
 fi
 
 #----------------------------------------------------------#

+ 15 - 15
bin/v-add-mail-domain-dkim

@@ -28,9 +28,9 @@ source_conf "$HESTIA/conf/hestia.conf"
 
 # Define mail user
 if [ "$MAIL_SYSTEM" = 'exim4' ]; then
-    MAIL_USER=Debian-exim
+	MAIL_USER=Debian-exim
 else
-    MAIL_USER=exim
+	MAIL_USER=exim
 fi
 
 # Additional argument formatting
@@ -59,28 +59,28 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 
 # Generating dkim
-openssl genrsa -out $USER_DATA/mail/$domain.pem $dkim_size &>/dev/null
+openssl genrsa -out $USER_DATA/mail/$domain.pem $dkim_size &> /dev/null
 openssl rsa -pubout -in $USER_DATA/mail/$domain.pem \
-    -out $USER_DATA/mail/$domain.pub &>/dev/null
+	-out $USER_DATA/mail/$domain.pub &> /dev/null
 chmod 660 $USER_DATA/mail/$domain.*
 
 # Adding dkim keys
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    cp $USER_DATA/mail/$domain.pem $HOMEDIR/$user/conf/mail/$domain/dkim.pem
-    chown $MAIL_USER:mail $HOMEDIR/$user/conf/mail/$domain/dkim.pem
-    chmod 660 $HOMEDIR/$user/conf/mail/$domain/dkim.pem
+	cp $USER_DATA/mail/$domain.pem $HOMEDIR/$user/conf/mail/$domain/dkim.pem
+	chown $MAIL_USER:mail $HOMEDIR/$user/conf/mail/$domain/dkim.pem
+	chmod 660 $HOMEDIR/$user/conf/mail/$domain/dkim.pem
 fi
 
 # Adding dns records
 if [ -n "$DNS_SYSTEM" ] && [ -e "$USER_DATA/dns/$domain.conf" ]; then
-    p=$(cat $USER_DATA/mail/$domain.pub |grep -v ' KEY---' |tr -d '\n')
-    record="_domainkey"
-    policy="\"t=y\; o=~\;\""
-    $BIN/v-add-dns-record "$user" "$domain" "$record" TXT "$policy" '' '' 'no' '' 'yes'
-
-    record="mail._domainkey"
-    selector="\"v=DKIM1\; k=rsa\; p=$p\""
-    $BIN/v-add-dns-record "$user" "$domain" "$record" TXT "$selector" '' '' 'yes' '' 'yes'
+	p=$(cat $USER_DATA/mail/$domain.pub | grep -v ' KEY---' | tr -d '\n')
+	record="_domainkey"
+	policy="\"t=y\; o=~\;\""
+	$BIN/v-add-dns-record "$user" "$domain" "$record" TXT "$policy" '' '' 'no' '' 'yes'
+
+	record="mail._domainkey"
+	selector="\"v=DKIM1\; k=rsa\; p=$p\""
+	$BIN/v-add-dns-record "$user" "$domain" "$record" TXT "$selector" '' '' 'yes' '' 'yes'
 fi
 
 #----------------------------------------------------------#

+ 2 - 6
bin/v-add-mail-domain-reject

@@ -7,7 +7,6 @@
 #
 # The function enables clamav scan for incoming emails.
 
-
 #----------------------------------------------------------#
 #                    Variable&Function                     #
 #----------------------------------------------------------#
@@ -32,7 +31,6 @@ format_domain
 format_domain_idn
 # TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
 
-
 #----------------------------------------------------------#
 #                    Verifications                         #
 #----------------------------------------------------------#
@@ -49,18 +47,16 @@ is_object_value_empty 'mail' 'DOMAIN' "$domain" '$REJECT'
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode
 
-
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
 # Adding antivirus flag
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    # Reject spam > 10 when enabled
-    touch $HOMEDIR/$user/conf/mail/$domain/reject_spam
+	# Reject spam > 10 when enabled
+	touch $HOMEDIR/$user/conf/mail/$domain/reject_spam
 fi
 
-
 #----------------------------------------------------------#
 #                       Hestia                             #
 #----------------------------------------------------------#

+ 6 - 6
bin/v-add-mail-domain-smtp-relay

@@ -48,7 +48,7 @@ check_hestia_demo_mode
 #                       Action                             #
 #----------------------------------------------------------#
 
-cat >/etc/exim4/domains/${domain}/smtp_relay.conf << EOL
+cat > /etc/exim4/domains/${domain}/smtp_relay.conf << EOL
 host:$host
 port:$port
 user:$username
@@ -61,11 +61,11 @@ EOL
 
 # Adding smtp relay values in config
 if [ -z "$U_SMTP_RELAY" ]; then
-    add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY' 'ACCOUNTS'
-    add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_HOST' 'ACCOUNTS'
-    add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_PORT' 'ACCOUNTS'
-    add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_USERNAME' 'ACCOUNTS'
-    add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_PASSWORD' 'ACCOUNTS'
+	add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY' 'ACCOUNTS'
+	add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_HOST' 'ACCOUNTS'
+	add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_PORT' 'ACCOUNTS'
+	add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_USERNAME' 'ACCOUNTS'
+	add_object_key 'mail' 'DOMAIN' "$domain" 'U_SMTP_RELAY_PASSWORD' 'ACCOUNTS'
 fi
 
 update_object_value 'mail' 'DOMAIN' "$domain" '$U_SMTP_RELAY' 'true'

+ 29 - 29
bin/v-add-mail-domain-ssl

@@ -19,13 +19,13 @@ restart="$4"
 
 # Additional argument formatting
 if [[ "$domain" =~ [[:upper:]] ]]; then
-    domain=$(echo "$domain" |tr '[:upper:]' '[:lower:]')
+	domain=$(echo "$domain" | tr '[:upper:]' '[:lower:]')
 fi
 if [[ "$domain" =~ ^www\..* ]]; then
-    domain=$(echo "$domain" |sed -e "s/^www.//")
+	domain=$(echo "$domain" | sed -e "s/^www.//")
 fi
 if [[ "$domain" =~ .*\.$ ]]; then
-    domain=$(echo "$domain" |sed -e "s/\.$//")
+	domain=$(echo "$domain" | sed -e "s/\.$//")
 fi
 
 domain_idn=$(idn2 --quiet "$domain")
@@ -64,7 +64,7 @@ is_web_domain_cert_valid
 check_hestia_demo_mode
 
 if [ -n "$restart" ]; then
-    is_format_valid "$restart"
+	is_format_valid "$restart"
 fi
 #----------------------------------------------------------#
 #                       Action                             #
@@ -73,41 +73,41 @@ fi
 # Inherit web domain local ip address
 domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
 if [ -n "$domain_ip" ]; then
-    local_ip=$(get_real_ip "$domain_ip")
-    is_ip_valid "$local_ip" "$user"
+	local_ip=$(get_real_ip "$domain_ip")
+	is_ip_valid "$local_ip" "$user"
 else
-    get_user_ip
+	get_user_ip
 fi
 
 # Call routine to add SSL configuration to mail domain
 add_mail_ssl_config
 
 if [ "$WEBMAIL" == "roundcube" ]; then
-    WEBMAIL_TEMPLATE="default"
-    if [ -n "$PROXY_SYSTEM" ]; then
-        PROXY_TEMPLATE="default"
-    fi
-    # Add webmail configuration to mail domain
-    WEBMAIL_TEMPLATE="default"
-    if [ "$WEB_SYSTEM" = "nginx" ]; then
-        WEBMAIL_TEMPLATE="web_system"
-    fi
+	WEBMAIL_TEMPLATE="default"
+	if [ -n "$PROXY_SYSTEM" ]; then
+		PROXY_TEMPLATE="default"
+	fi
+	# Add webmail configuration to mail domain
+	WEBMAIL_TEMPLATE="default"
+	if [ "$WEB_SYSTEM" = "nginx" ]; then
+		WEBMAIL_TEMPLATE="web_system"
+	fi
 elif [ "$WEBMAIL" == "rainloop" ]; then
-    WEBMAIL_TEMPLATE="rainloop"
-    if [ -n "$PROXY_SYSTEM" ]; then
-        PROXY_TEMPLATE="default_rainloop"
-    fi
+	WEBMAIL_TEMPLATE="rainloop"
+	if [ -n "$PROXY_SYSTEM" ]; then
+		PROXY_TEMPLATE="default_rainloop"
+	fi
 else
-    WEBMAIL_TEMPLATE="disabled"
-    if [ -n "$PROXY_SYSTEM" ]; then
-        PROXY_TEMPLATE="default_disabled"
-    fi
+	WEBMAIL_TEMPLATE="disabled"
+	if [ -n "$PROXY_SYSTEM" ]; then
+		PROXY_TEMPLATE="default_disabled"
+	fi
 fi
 
 add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.stpl"
 
 if [ -n "$PROXY_SYSTEM" ]; then
-    add_webmail_config "$PROXY_SYSTEM" "${PROXY_TEMPLATE}.stpl"
+	add_webmail_config "$PROXY_SYSTEM" "${PROXY_TEMPLATE}.stpl"
 fi
 
 # Increase value for domain
@@ -122,18 +122,18 @@ update_object_value 'mail' 'DOMAIN' "$domain" '$SSL' "yes"
 
 # Restarting mail server
 $BIN/v-restart-mail "$restart"
-check_result $? "Mail restart failed" >/dev/null
+check_result $? "Mail restart failed" > /dev/null
 
 # Restarting web server
 $BIN/v-restart-web "$restart"
-check_result $? "Web restart failed" >/dev/null
+check_result $? "Web restart failed" > /dev/null
 
 # Restarting proxy server
 $BIN/v-restart-proxy "$restart"
-check_result $? "Proxy restart failed" >/dev/null
+check_result $? "Proxy restart failed" > /dev/null
 
 # Logging
 $BIN/v-log-action "$user" "Info" "Mail" "SSL enabled (Domain: $domain)."
 log_event "$OK" "$ARGUMENTS"
 
-exit
+exit

+ 87 - 87
bin/v-add-mail-domain-webmail

@@ -20,18 +20,18 @@ restart="$4"
 quiet=$5
 
 if [ -z "$restart" ]; then
-    restart="yes"
+	restart="yes"
 fi
 
 # Additional argument formatting
 if [[ "$domain" =~ [[:upper:]] ]]; then
-    domain=$(echo "$domain" |tr '[:upper:]' '[:lower:]')
+	domain=$(echo "$domain" | tr '[:upper:]' '[:lower:]')
 fi
 if [[ "$domain" =~ ^www\..* ]]; then
-    domain=$(echo "$domain" |sed -e "s/^www.//")
+	domain=$(echo "$domain" | sed -e "s/^www.//")
 fi
 if [[ "$domain" =~ .*\.$ ]]; then
-    domain=$(echo "$domain" |sed -e "s/\.$//")
+	domain=$(echo "$domain" | sed -e "s/\.$//")
 fi
 
 # Includes
@@ -55,9 +55,9 @@ format_domain_idn
 #----------------------------------------------------------#
 
 if [ -z "$webmail" ]; then
-    for client in ${WEBMAIL_SYSTEM//,/ };do
-        webmail="$client"
-    done
+	for client in ${WEBMAIL_SYSTEM//,/ }; do
+		webmail="$client"
+	done
 fi
 
 check_args '2' "$#" 'USER DOMAIN [WEBMAIL] [RESTART]'
@@ -80,89 +80,89 @@ check_hestia_demo_mode
 # Inherit web domain local ip address
 domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
 if [ -n "$domain_ip" ]; then
-    local_ip=$(get_real_ip "$domain_ip")
-    is_ip_valid "$local_ip" "$user"
-
-    ip=$local_ip
-    nat_ip=$(get_ip_value '$NAT')
-    if [ -n "$nat_ip" ]; then
-        ip=$nat_ip
-    fi
+	local_ip=$(get_real_ip "$domain_ip")
+	is_ip_valid "$local_ip" "$user"
+
+	ip=$local_ip
+	nat_ip=$(get_ip_value '$NAT')
+	if [ -n "$nat_ip" ]; then
+		ip=$nat_ip
+	fi
 else
-    get_user_ip
+	get_user_ip
 fi
 
 # Verify that webmail alias variable exists and create it if it does not
 if [ -z "$WEBMAIL_ALIAS" ]; then
-    $BIN/v-change-sys-config-value 'WEBMAIL_ALIAS' "webmail"
+	$BIN/v-change-sys-config-value 'WEBMAIL_ALIAS' "webmail"
 else
-    # Ensure DNS record exists if Hestia is hosting DNS zones
-    if [ -n "$DNS_SYSTEM" ]; then
-        dns_domain=$($BIN/v-list-dns-domains $user | grep $domain | cut -d' ' -f1)
-        webmail_record=$($BIN/v-list-dns-records $user $domain | grep -i " $WEBMAIL_ALIAS " | cut -d' ' -f1)
-        if [ "$dns_domain" = "$domain" ]; then
-            if [ "$WEBMAIL_ALIAS" != "mail" ]; then
-                #Prevent mail.domain.com to be cycled
-                if [ -z "$webmail_record" ]; then
-                    if [ "$quiet" = "yes" ]; then
-                        $BIN/v-add-dns-record "$user" "$domain" "$WEBMAIL_ALIAS" A "$ip" '' '' "$restart" '' 'yes'
-                    else
-                        $BIN/v-add-dns-record "$user" "$domain" "$WEBMAIL_ALIAS" A "$ip" '' '' "$restart" '' 'yes'
-                    fi
-                else
-                    if [ "$quiet" = "yes" ]; then
-                        $BIN/v-delete-dns-record "$user" "$domain" "$webmail_record" "$restart" 'yes'
-                        $BIN/v-add-dns-record "$user" "$domain" "$WEBMAIL_ALIAS" A "$ip" '' '' "$restart" '' 'yes'
-                    else
-                        $BIN/v-delete-dns-record "$user" "$domain" "$webmail_record" "$restart" 'yes'
-                        $BIN/v-add-dns-record "$user" "$domain" "$WEBMAIL_ALIAS" A "$ip" '' '' "$restart" '' 'yes'
-                    fi
-                fi
-            fi
-        fi
-    fi
-
-    if [ "$webmail" == "roundcube" ]; then
-        WEBMAIL_TEMPLATE="default"
-        if [ -n "$PROXY_SYSTEM" ]; then
-            PROXY_TEMPLATE="default"
-        fi
-        # Add webmail configuration to mail domain
-        WEBMAIL_TEMPLATE="default"
-        if [ "$WEB_SYSTEM" = "nginx" ]; then
-            WEBMAIL_TEMPLATE="web_system"
-        fi
-    elif [ "$webmail" == "rainloop" ]; then
-        WEBMAIL_TEMPLATE="rainloop"
-        if [ -n "$PROXY_SYSTEM" ]; then
-            PROXY_TEMPLATE="default_rainloop"
-        fi
-    else
-        WEBMAIL_TEMPLATE="disabled"
-        if [ -n "$PROXY_SYSTEM" ]; then
-            PROXY_TEMPLATE="default_disabled"
-        fi
-    fi
-
-    add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.tpl"
-
-    if [ -n "$PROXY_SYSTEM" ]; then
-        add_webmail_config "$PROXY_SYSTEM" "${PROXY_TEMPLATE}.tpl"
-    fi
-
-    # Enable SSL for webmail if available
-    if [ -f $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.crt ] || [ "$SSL" = 'yes' ]; then
-        add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.stpl"
-
-        if [ -n "$PROXY_SYSTEM" ]; then
-            add_webmail_config "$PROXY_SYSTEM" "${PROXY_TEMPLATE}.stpl"
-        fi
-    fi
+	# Ensure DNS record exists if Hestia is hosting DNS zones
+	if [ -n "$DNS_SYSTEM" ]; then
+		dns_domain=$($BIN/v-list-dns-domains $user | grep $domain | cut -d' ' -f1)
+		webmail_record=$($BIN/v-list-dns-records $user $domain | grep -i " $WEBMAIL_ALIAS " | cut -d' ' -f1)
+		if [ "$dns_domain" = "$domain" ]; then
+			if [ "$WEBMAIL_ALIAS" != "mail" ]; then
+				#Prevent mail.domain.com to be cycled
+				if [ -z "$webmail_record" ]; then
+					if [ "$quiet" = "yes" ]; then
+						$BIN/v-add-dns-record "$user" "$domain" "$WEBMAIL_ALIAS" A "$ip" '' '' "$restart" '' 'yes'
+					else
+						$BIN/v-add-dns-record "$user" "$domain" "$WEBMAIL_ALIAS" A "$ip" '' '' "$restart" '' 'yes'
+					fi
+				else
+					if [ "$quiet" = "yes" ]; then
+						$BIN/v-delete-dns-record "$user" "$domain" "$webmail_record" "$restart" 'yes'
+						$BIN/v-add-dns-record "$user" "$domain" "$WEBMAIL_ALIAS" A "$ip" '' '' "$restart" '' 'yes'
+					else
+						$BIN/v-delete-dns-record "$user" "$domain" "$webmail_record" "$restart" 'yes'
+						$BIN/v-add-dns-record "$user" "$domain" "$WEBMAIL_ALIAS" A "$ip" '' '' "$restart" '' 'yes'
+					fi
+				fi
+			fi
+		fi
+	fi
+
+	if [ "$webmail" == "roundcube" ]; then
+		WEBMAIL_TEMPLATE="default"
+		if [ -n "$PROXY_SYSTEM" ]; then
+			PROXY_TEMPLATE="default"
+		fi
+		# Add webmail configuration to mail domain
+		WEBMAIL_TEMPLATE="default"
+		if [ "$WEB_SYSTEM" = "nginx" ]; then
+			WEBMAIL_TEMPLATE="web_system"
+		fi
+	elif [ "$webmail" == "rainloop" ]; then
+		WEBMAIL_TEMPLATE="rainloop"
+		if [ -n "$PROXY_SYSTEM" ]; then
+			PROXY_TEMPLATE="default_rainloop"
+		fi
+	else
+		WEBMAIL_TEMPLATE="disabled"
+		if [ -n "$PROXY_SYSTEM" ]; then
+			PROXY_TEMPLATE="default_disabled"
+		fi
+	fi
+
+	add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.tpl"
+
+	if [ -n "$PROXY_SYSTEM" ]; then
+		add_webmail_config "$PROXY_SYSTEM" "${PROXY_TEMPLATE}.tpl"
+	fi
+
+	# Enable SSL for webmail if available
+	if [ -f $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.crt ] || [ "$SSL" = 'yes' ]; then
+		add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.stpl"
+
+		if [ -n "$PROXY_SYSTEM" ]; then
+			add_webmail_config "$PROXY_SYSTEM" "${PROXY_TEMPLATE}.stpl"
+		fi
+	fi
 fi
 
 WEBMAIL=$(get_object_value 'web' 'DOMAIN' "$domain" "$WEBMAIL")
 if [ -z "$WEBMAIL" ]; then
-    add_object_key 'mail' 'DOMAIN' "$domain" 'WEBMAIL' 'SSL'
+	add_object_key 'mail' 'DOMAIN' "$domain" 'WEBMAIL' 'SSL'
 fi
 
 # Set SSL as enabled in configuration
@@ -173,18 +173,18 @@ update_object_value 'mail' 'DOMAIN' "$domain" '$WEBMAIL' "$webmail"
 #----------------------------------------------------------#
 
 if [ "$restart" = 'yes' ]; then
-    # Restarting web server
-    $BIN/v-restart-web "$restart"
-    check_result $? "Web restart failed" >/dev/null
+	# Restarting web server
+	$BIN/v-restart-web "$restart"
+	check_result $? "Web restart failed" > /dev/null
 
-    $BIN/v-restart-proxy "$restart"
-    check_result $? "Proxy restart failed" >/dev/null
+	$BIN/v-restart-proxy "$restart"
+	check_result $? "Proxy restart failed" > /dev/null
 fi
 
 # Logging
 if [ "$quiet" != 'yes' ]; then
-    $BIN/v-log-action "$user" "Info" "Mail" "Webmail access enabled (Domain: $domain)."
+	$BIN/v-log-action "$user" "Info" "Mail" "Webmail access enabled (Domain: $domain)."
 fi
 log_event "$OK" "$ARGUMENTS"
 
-exit
+exit

+ 41 - 42
bin/v-add-remote-dns-domain

@@ -15,7 +15,6 @@ user=$1
 domain=$2
 flush=$3
 
-
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
 source /etc/hestiacp/hestia.conf
@@ -33,7 +32,7 @@ source_conf "$HESTIA/conf/hestia.conf"
 check_args '2' "$#" 'USER DOMAIN [FLUSH]'
 is_format_valid 'user' 'domain'
 if [ -n "$flush" ]; then
-    is_type_valid "records yes no" "$flush"
+	is_type_valid "records yes no" "$flush"
 fi
 is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
 is_procces_running
@@ -47,63 +46,63 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 
 # Parsing domain record
-str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf 2>/dev/null)
+str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf 2> /dev/null)
 if [ -z "$str" ]; then
-    pipe="$HESTIA/data/queue/dns-cluster.pipe"
-    queue_str=$(grep -n "$SCRIPT $1 $2 " $pipe |cut -f1 -d: |head -n1)
-    if [ -n "$queue_str" ]; then
-        sed -i "$queue_str d"  $pipe
-    fi
-    exit
+	pipe="$HESTIA/data/queue/dns-cluster.pipe"
+	queue_str=$(grep -n "$SCRIPT $1 $2 " $pipe | cut -f1 -d: | head -n1)
+	if [ -n "$queue_str" ]; then
+		sed -i "$queue_str d" $pipe
+	fi
+	exit
 fi
 if [ "$DNS_CLUSTER_SYSTEM" = "zone" ]; then
-    str=$(echo "$str" | sed "s/SLAVE='no'/SLAVE='yes'/g");
-    str=$(echo "$str" | sed "s/SLAVE=''/SLAVE='yes'/g");
-    ip=$($BIN/v-list-sys-ips plain | cut -f1 | head -n1);
-    str=$(echo "$str" | sed "s/MASTER=''/MASTER='$ip'/g");
+	str=$(echo "$str" | sed "s/SLAVE='no'/SLAVE='yes'/g")
+	str=$(echo "$str" | sed "s/SLAVE=''/SLAVE='yes'/g")
+	ip=$($BIN/v-list-sys-ips plain | cut -f1 | head -n1)
+	str=$(echo "$str" | sed "s/MASTER=''/MASTER='$ip'/g")
 fi
 
 IFS=$'\n'
 for cluster in $(grep "SUSPENDED='no'" $HESTIA/conf/dns-cluster.conf); do
-    # Reset user, password and hash vars
-    clear_dns_cluster_settings
+	# Reset user, password and hash vars
+	clear_dns_cluster_settings
 
-    # Parsing remote dns host parameters
-    parse_object_kv_list "$cluster"
+	# Parsing remote dns host parameters
+	parse_object_kv_list "$cluster"
 
-    # Parsing domain parameters
-    parse_object_kv_list "$str"
+	# Parsing domain parameters
+	parse_object_kv_list "$str"
 
-    if [ "$DNS_CLUSTER_SYSTEM" = "zone" ]; then
-        # Syncing domain data
-        cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME $flush 'no'
-        check_result $? "$HOST connection failed" "$E_CONNECT"
+	if [ "$DNS_CLUSTER_SYSTEM" = "zone" ]; then
+		# Syncing domain data
+		cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME $flush 'no'
+		check_result $? "$HOST connection failed" "$E_CONNECT"
 
-        cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
-        check_result $? "$HOST connection failed" "$E_CONNECT"
+		cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
+		check_result $? "$HOST connection failed" "$E_CONNECT"
 
-    else
-        # Syncing domain data
-        cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME $flush 'no'
-        check_result $? "$HOST connection failed" "$E_CONNECT"
+	else
+		# Syncing domain data
+		cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME $flush 'no'
+		check_result $? "$HOST connection failed" "$E_CONNECT"
 
-        # Syncing domain records
-        tmp_file="/tmp/vst-sync.$DOMAIN"
-        cluster_file $USER_DATA/dns/$DOMAIN.conf $tmp_file
-        check_result $? "$HOST connection failed" "$E_CONNECT"
+		# Syncing domain records
+		tmp_file="/tmp/vst-sync.$DOMAIN"
+		cluster_file $USER_DATA/dns/$DOMAIN.conf $tmp_file
+		check_result $? "$HOST connection failed" "$E_CONNECT"
 
-        # Inserting synced records
-        cluster_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp_file 'no'
-        check_result $? "$HOST connection failed" "$E_CONNECT"
+		# Inserting synced records
+		cluster_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp_file 'no'
+		check_result $? "$HOST connection failed" "$E_CONNECT"
 
-        # Rebuilding dns zone
-        cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
-        check_result $? "$HOST connection failed" "$E_CONNECT"
-    fi
+		# Rebuilding dns zone
+		cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
+		check_result $? "$HOST connection failed" "$E_CONNECT"
+	fi
 done
 
 if [ "$DNS_CLUSTER_SYSTEM" = "zone" ]; then
-    rndc notify $domain  > /dev/null 2>&1
+	rndc notify $domain > /dev/null 2>&1
 fi
 #----------------------------------------------------------#
 #                       Hestia                             #
@@ -114,7 +113,7 @@ rm -f $tmpfile
 pipe="$HESTIA/data/queue/dns-cluster.pipe"
 str=$(grep -n "$SCRIPT $1 $2 " $pipe | cut -f1 -d: | head -n1)
 if [ -n "$str" ]; then
-    sed -i "$str d"  $pipe
+	sed -i "$str d" $pipe
 fi
 
 exit

+ 22 - 21
bin/v-add-remote-dns-host

@@ -23,7 +23,8 @@ user=$3
 USER=$user
 hash=$user
 HASH=$user
-password=$4; HIDE=4
+password=$4
+HIDE=4
 PASSWORD=$password
 type=${5}
 TYPE="$type"
@@ -45,17 +46,17 @@ source_conf "$HESTIA/conf/hestia.conf"
 #----------------------------------------------------------#
 
 if [ -z "$type" ]; then
-    type='api'
-    TYPE="$type"
+	type='api'
+	TYPE="$type"
 fi
 
 args_usage='HOST PORT USER [PASSWORD] [TYPE] [DNS_USER]'
 check_args '3' "$#" "$args_usage"
 is_format_valid 'host' 'port' 'dns_user'
 if [ -z "$password" ]; then
-    is_format_valid 'hash'
+	is_format_valid 'hash'
 else
-    is_format_valid 'user'
+	is_format_valid 'user'
 fi
 is_type_valid "api ssh" "$type"
 is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
@@ -72,19 +73,19 @@ check_hestia_demo_mode
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 if [ -z "$password" ]; then
-    # Concatentating dns host string
-    str="HOST='$host' PORT='$port' HASH='$hash'"
-    str="$str DNS_USER='$dns_user' TYPE='$type' SUSPENDED='no'"
-    str="$str TIME='$time' DATE='$date'"
+	# Concatentating dns host string
+	str="HOST='$host' PORT='$port' HASH='$hash'"
+	str="$str DNS_USER='$dns_user' TYPE='$type' SUSPENDED='no'"
+	str="$str TIME='$time' DATE='$date'"
 else
-    # Concatentating dns host string
-    str="HOST='$host' PORT='$port' USER='$user' PASSWORD='$password'"
-    str="$str DNS_USER='$dns_user' TYPE='$type' SUSPENDED='no'"
-    str="$str TIME='$time' DATE='$date'"
+	# Concatentating dns host string
+	str="HOST='$host' PORT='$port' USER='$user' PASSWORD='$password'"
+	str="$str DNS_USER='$dns_user' TYPE='$type' SUSPENDED='no'"
+	str="$str TIME='$time' DATE='$date'"
 fi
 
 # Adding host to dns-cluster.conf
@@ -93,9 +94,9 @@ chmod 660 $HESTIA/conf/dns-cluster.conf
 
 # Enabling DNS_CLUSTER
 if [ -z "$(grep DNS_CLUSTER= $HESTIA/conf/hestia.conf)" ]; then
-    sed -i "s/^STATS_/DNS_CLUSTER='yes'\nSTATS_/g" $HESTIA/conf/hestia.conf
+	sed -i "s/^STATS_/DNS_CLUSTER='yes'\nSTATS_/g" $HESTIA/conf/hestia.conf
 else
-    sed -i "s/DNS_CLUSTER=.*/DNS_CLUSTER='yes'/g" $HESTIA/conf/hestia.conf
+	sed -i "s/DNS_CLUSTER=.*/DNS_CLUSTER='yes'/g" $HESTIA/conf/hestia.conf
 fi
 
 # Enabling remote dns-cluster queue
@@ -104,9 +105,9 @@ check_result $? "$HOST connection failed" "$E_CONNECT"
 
 # Loop trough domains to generate new serial
 for dns_user in $($BIN/v-list-sys-users plain); do
-    for dns_domain in $($BIN/v-list-dns-domains $dns_user plain | cut -f1); do
-        $BIN/v-rebuild-dns-domain $dns_user $dns_domain "no" "yes"
-    done
+	for dns_domain in $($BIN/v-list-dns-domains $dns_user plain | cut -f1); do
+		$BIN/v-rebuild-dns-domain $dns_user $dns_domain "no" "yes"
+	done
 done
 
 # Syncing all domains
@@ -121,7 +122,7 @@ check_result $? "$HOST sync failed" "$E_CONNECT"
 cmd="sudo $HESTIA/bin/v-update-sys-queue dns-cluster"
 check_cron=$(grep "$cmd" $HESTIA/data/users/admin/cron.conf 2> /dev/null)
 if [ -z "$check_cron" ] && [ ! -z "$CRON_SYSTEM" ]; then
-    $BIN/v-add-cron-job admin '*/5' '*' '*' '*' '*' "$cmd"
+	$BIN/v-add-cron-job admin '*/5' '*' '*' '*' '*' "$cmd"
 fi
 
 # Logging

+ 27 - 28
bin/v-add-remote-dns-record

@@ -47,43 +47,42 @@ check_hestia_demo_mode
 # Parsing record
 str=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf)
 if [ -z "$str" ]; then
-    pipe="$HESTIA/data/queue/dns-cluster.pipe"
-    queue_str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
-    if [ -n "$queue_str" ]; then
-        sed -i "$queue_str d"  $pipe
-    fi
-    exit
+	pipe="$HESTIA/data/queue/dns-cluster.pipe"
+	queue_str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
+	if [ -n "$queue_str" ]; then
+		sed -i "$queue_str d" $pipe
+	fi
+	exit
 fi
 # $DNS_CLUSTER_SYSTEM = "zone" doesn't need to be uopdated
 
 if [ "$DNS_CLUSTER_SYSTEM" != "zone" ]; then
-    IFS=$'\n'
-    for cluster in $(grep "SUSPENDED='no'" $HESTIA/conf/dns-cluster.conf); do
+	IFS=$'\n'
+	for cluster in $(grep "SUSPENDED='no'" $HESTIA/conf/dns-cluster.conf); do
 
-        # Reset user, password and hash vars
-        clear_dns_cluster_settings
+		# Reset user, password and hash vars
+		clear_dns_cluster_settings
 
-        # Parsing remote host parameters
-        parse_object_kv_list "$cluster"
+		# Parsing remote host parameters
+		parse_object_kv_list "$cluster"
 
-        # Syncing serial
-        str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
-        # Parsing domain parameters
-        parse_object_kv_list "$str"
+		# Syncing serial
+		str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
+		# Parsing domain parameters
+		parse_object_kv_list "$str"
 
+		cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'domain' 'no'
+		check_result $? "$HOST connection failed (soa sync)" "$E_CONNECT"
 
-        cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'domain' 'no'
-        check_result $? "$HOST connection failed (soa sync)" "$E_CONNECT"
+		# Syncing record
+		str=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf | sed 's/"/\\"/g')
+		cluster_cmd v-insert-dns-record $DNS_USER $domain "$str" 'no'
+		check_result $? "$HOST connection failed (record sync)" "$E_CONNECT"
 
-        # Syncing record
-        str=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf | sed 's/"/\\"/g')
-        cluster_cmd v-insert-dns-record $DNS_USER $domain "$str" 'no'
-        check_result $? "$HOST connection failed (record sync)" "$E_CONNECT"
-
-        # Rebuilding dns zone
-        cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
-        check_result $? "$HOST connection failed (rebuild)" "$E_CONNECT"
-    done
+		# Rebuilding dns zone
+		cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
+		check_result $? "$HOST connection failed (rebuild)" "$E_CONNECT"
+	done
 fi
 #----------------------------------------------------------#
 #                       Hestia                             #
@@ -93,7 +92,7 @@ fi
 pipe="$HESTIA/data/queue/dns-cluster.pipe"
 str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
 if [ -n "$str" ]; then
-    sed -i "$str d"  $pipe
+	sed -i "$str d" $pipe
 fi
 
 exit

+ 3 - 3
bin/v-add-sys-api-ip

@@ -35,9 +35,9 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 
 if [ "$API_ALLOWED_IP" != "" ]; then
-    $BIN/v-change-sys-config-value 'API_ALLOWED_IP' "$API_ALLOWED_IP,$ip46"
+	$BIN/v-change-sys-config-value 'API_ALLOWED_IP' "$API_ALLOWED_IP,$ip46"
 else
-    $BIN/v-change-sys-config-value 'API_ALLOWED_IP' "$ip46"
+	$BIN/v-change-sys-config-value 'API_ALLOWED_IP' "$ip46"
 fi
 
 #----------------------------------------------------------#
@@ -46,4 +46,4 @@ fi
 
 # Logging
 $BIN/v-log-action "system" "Warning" "System" "Added new IP address added to Allowed IP API (IP: $ip46)"
-log_event "$OK" "$ARGUMENTS"
+log_event "$OK" "$ARGUMENTS"

+ 23 - 23
bin/v-add-sys-dependencies

@@ -30,27 +30,27 @@ COMPOSER_BIN="$HOMEDIR/$user/.composer/composer"
 
 # Checking root permissions
 if [ "x$(id -u)" != 'x0' ]; then
-    echo "ERROR: v-add-sys-dependencies can be run executed only by root user"
-    exit 10
+	echo "ERROR: v-add-sys-dependencies can be run executed only by root user"
+	exit 10
 fi
 
 # Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
 if [ -z "$HESTIA" ]; then
-    HESTIA="/usr/local/hestia"
+	HESTIA="/usr/local/hestia"
 fi
 
 if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
-    echo "ERROR: Environment variables not present, installation aborted."
-    exit 2
+	echo "ERROR: Environment variables not present, installation aborted."
+	exit 2
 fi
 
 # Ensure that Composer is installed for the user before continuing as it is a dependency of the PHPMailer.
 if [ ! -f "$COMPOSER_BIN" ]; then
-    $BIN/v-add-user-composer "$user"
-    if [ $? -ne 0 ]; then
-        $BIN/v-add-user-notification admin 'Composer installation failed!' '<b>Hestia will not work without Composer.</b><br><br>Please try running the installer manually from a shell session:<br>v-add-sys-phpmailer<br><br>If this continues, open an issue report on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
-        exit 1
-    fi
+	$BIN/v-add-user-composer "$user"
+	if [ $? -ne 0 ]; then
+		$BIN/v-add-user-notification admin 'Composer installation failed!' '<b>Hestia will not work without Composer.</b><br><br>Please try running the installer manually from a shell session:<br>v-add-sys-phpmailer<br><br>If this continues, open an issue report on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
+		exit 1
+	fi
 fi
 
 # Perform verification if read-only mode is enabled
@@ -65,24 +65,24 @@ rm --recursive --force ${PM_INSTALL_DIR}/vendor
 mkdir -p ${PM_INSTALL_DIR}/vendor
 chown $user: -R ${PM_INSTALL_DIR}/vendor
 
-openssl_installed=$(/usr/local/hestia/php/bin/php -m | grep openssl);
-if [ -z "$openssl_installed"  ]; then
-    COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php $COMPOSER_BIN --quiet --no-dev install
+openssl_installed=$(/usr/local/hestia/php/bin/php -m | grep openssl)
+if [ -z "$openssl_installed" ]; then
+	COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php $COMPOSER_BIN --quiet --no-dev install
 else
-    COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/local/hestia/php/bin/php $COMPOSER_BIN --quiet --no-dev install
+	COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/local/hestia/php/bin/php $COMPOSER_BIN --quiet --no-dev install
 fi
 
 # Check if installation was successful, if not abort script and throw error message notification and clean-up
 if [ $? -ne 0 ]; then
-    echo "ERROR: PHPMailer installation failed!"
-    echo "Please report this to our development team:"
-    echo "https://github.com/hestiacp/hestiacp/issues"
-    $BIN/v-add-user-notification admin 'Hestia PHP dependencies installation failed!' 'Please report this to our development team on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
-    # Installation failed, clean up files
-    rm --recursive --force ${PM_INSTALL_DIR}/vendor
-    $BIN/v-change-sys-config-value 'USE_SERVER_SMTP' 'n'
-    $BIN/v-log-action "system" "Error" "Plugins" "PHP dependencies installation failed"
-    exit 1
+	echo "ERROR: PHPMailer installation failed!"
+	echo "Please report this to our development team:"
+	echo "https://github.com/hestiacp/hestiacp/issues"
+	$BIN/v-add-user-notification admin 'Hestia PHP dependencies installation failed!' 'Please report this to our development team on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
+	# Installation failed, clean up files
+	rm --recursive --force ${PM_INSTALL_DIR}/vendor
+	$BIN/v-change-sys-config-value 'USE_SERVER_SMTP' 'n'
+	$BIN/v-log-action "system" "Error" "Plugins" "PHP dependencies installation failed"
+	exit 1
 fi
 
 # Set permissions

+ 23 - 23
bin/v-add-sys-filemanager

@@ -33,27 +33,27 @@ COMPOSER_BIN="$HOMEDIR/$user/.composer/composer"
 
 # Checking root permissions
 if [ "x$(id -u)" != 'x0' ]; then
-    echo "ERROR: v-add-sys-filemanager can be run executed only by root user"
-    exit 10
+	echo "ERROR: v-add-sys-filemanager can be run executed only by root user"
+	exit 10
 fi
 
 # Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
 if [ -z "$HESTIA" ]; then
-    HESTIA="/usr/local/hestia"
+	HESTIA="/usr/local/hestia"
 fi
 
 if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
-    echo "ERROR: Environment variables not present, installation aborted."
-    exit 2
+	echo "ERROR: Environment variables not present, installation aborted."
+	exit 2
 fi
 
 # Ensure that Composer is installed for the user before continuing as it is a dependency of the File Manager.
 if [ ! -f "$COMPOSER_BIN" ]; then
-    $BIN/v-add-user-composer "$user"
-    if [ $? -ne 0 ]; then
-        $BIN/v-add-user-notification admin 'Composer installation failed!' '<b>The File Manager will not work without Composer.</b><br><br>Please try running the installer manually from a shell session:<br>v-add-sys-filemanager<br><br>If this continues, open an issue report on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
-        exit 1
-    fi
+	$BIN/v-add-user-composer "$user"
+	if [ $? -ne 0 ]; then
+		$BIN/v-add-user-notification admin 'Composer installation failed!' '<b>The File Manager will not work without Composer.</b><br><br>Please try running the installer manually from a shell session:<br>v-add-sys-filemanager<br><br>If this continues, open an issue report on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
+		exit 1
+	fi
 fi
 
 # Perform verification if read-only mode is enabled
@@ -63,7 +63,7 @@ check_hestia_demo_mode
 #                       Action                             #
 #----------------------------------------------------------#
 
-openssl_installed=$(/usr/local/hestia/php/bin/php -m | grep openssl);
+openssl_installed=$(/usr/local/hestia/php/bin/php -m | grep openssl)
 
 rm --recursive --force "$FM_INSTALL_DIR"
 mkdir -p "$FM_INSTALL_DIR"
@@ -80,23 +80,23 @@ cp --recursive --force ${HESTIA_INSTALL_DIR}/filemanager/filegator/* "${FM_INSTA
 
 chown $user: -R "${FM_INSTALL_DIR}"
 
-if [ -z "$openssl_installed"  ]; then
-    COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php $COMPOSER_BIN --quiet --no-dev install
+if [ -z "$openssl_installed" ]; then
+	COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php $COMPOSER_BIN --quiet --no-dev install
 else
-    COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/local/hestia/php/bin/php $COMPOSER_BIN --quiet --no-dev install
+	COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/local/hestia/php/bin/php $COMPOSER_BIN --quiet --no-dev install
 fi
 
 # Check if installation was successful, if not abort script and throw error message notification and clean-up
 if [ $? -ne 0 ]; then
-    echo "ERROR: File Manager installation failed!"
-    echo "Please report this to our development team:"
-    echo "https://github.com/hestiacp/hestiacp/issues"
-    $BIN/v-add-user-notification admin 'File Manager installation failed!' 'Please report this to our development team on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
-    # Installation failed, clean up files
-    rm --recursive --force ${FM_INSTALL_DIR}
-    $BIN/v-change-sys-config-value 'FILE_MANAGER' 'false'
-    $BIN/v-log-action "system" "Error" "Plugins" "File Manager installation failed (Version: $fm_v)."
-    exit 1
+	echo "ERROR: File Manager installation failed!"
+	echo "Please report this to our development team:"
+	echo "https://github.com/hestiacp/hestiacp/issues"
+	$BIN/v-add-user-notification admin 'File Manager installation failed!' 'Please report this to our development team on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
+	# Installation failed, clean up files
+	rm --recursive --force ${FM_INSTALL_DIR}
+	$BIN/v-change-sys-config-value 'FILE_MANAGER' 'false'
+	$BIN/v-log-action "system" "Error" "Plugins" "File Manager installation failed (Version: $fm_v)."
+	exit 1
 fi
 
 # Add configuration file

+ 3 - 3
bin/v-add-sys-firewall

@@ -23,7 +23,7 @@ source_conf "$HESTIA/conf/hestia.conf"
 #----------------------------------------------------------#
 
 if [ "$FIREWALL_SYSTEM" = 'iptables' ]; then
-    exit
+	exit
 fi
 
 # Perform verification if read-only mode is enabled
@@ -34,8 +34,8 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 
 # Adding default ruleset
-if [ -z "$(ls -A $HESTIA/data/firewall 2>/dev/null)" ]; then
-    cp -rf $HESTIA_INSTALL_DIR/firewall $HESTIA/data/
+if [ -z "$(ls -A $HESTIA/data/firewall 2> /dev/null)" ]; then
+	cp -rf $HESTIA_INSTALL_DIR/firewall $HESTIA/data/
 fi
 
 # Updating FIREWAL_SYSTEM value

+ 113 - 113
bin/v-add-sys-ip

@@ -48,14 +48,14 @@ is_format_valid 'ip' 'netmask' 'iface' 'user' 'ip_status'
 is_ip_free
 is_object_valid 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-if [ -n "$ip_name" ] ; then
-    is_format_valid 'ip_name'
+if [ -n "$ip_name" ]; then
+	is_format_valid 'ip_name'
 fi
-if [ -n "$nat_ip" ] ; then
-    is_format_valid 'nat_ip'
+if [ -n "$nat_ip" ]; then
+	is_format_valid 'nat_ip'
 fi
 if [ "$user" != "admin" ]; then
-    ip_status="dedicated"
+	ip_status="dedicated"
 fi
 
 # Perform verification if read-only mode is enabled
@@ -70,51 +70,51 @@ broadcast=$(get_broadcast $ip $netmask)
 
 sys_ip_check=$(/sbin/ip addr | grep "$ip")
 if [ -z "$sys_ip_check" ]; then
-    # Adding sys ip
-    /sbin/ip addr add $ip/$cidr dev $iface \
-        broadcast $broadcast label $iface
-
-    # Check if netplan is in use and generate configuration file
-    if [ ! -z $(which netplan) ]; then
-        if  [ ! -z "$(netplan generate --mapping "$iface" | grep networkd)" ]; then
-            netplan=1
-        else
-            netplan=0
-        fi
-    else
-        netplan=0
-    fi
-
-    if [ "$netplan" == "1" ]; then
-        if [ -f "/etc/netplan/60-hestia.yaml" ]; then
-            sys_ip="        - $ip/$cidr"
-        else
-            sys_ip="# Added by hestia, please do not edit the file manually!"
-            sys_ip="$sys_ip\nnetwork:"
-            sys_ip="$sys_ip\n  version: 2"
-            sys_ip="$sys_ip\n  renderer: networkd"
-            sys_ip="$sys_ip\n  ethernets:"
-            sys_ip="$sys_ip\n    $iface:"
-            sys_ip="$sys_ip\n      addresses:"
-            sys_ip="$sys_ip\n        - $ip/$cidr"
-        fi
-        IFS='%'
-        echo -e $sys_ip >> /etc/netplan/60-hestia.yaml
-        unset IFS
-    else
-        sys_ip="\n# Added by Hestia Control Panel"
-        sys_ip="$sys_ip\nauto $iface"
-        sys_ip="$sys_ip\niface $iface inet static"
-        sys_ip="$sys_ip\naddress $ip"
-        sys_ip="$sys_ip\nnetmask $netmask"
-        echo -e $sys_ip >> /etc/network/interfaces
-    fi
+	# Adding sys ip
+	/sbin/ip addr add $ip/$cidr dev $iface \
+		broadcast $broadcast label $iface
+
+	# Check if netplan is in use and generate configuration file
+	if [ ! -z $(which netplan) ]; then
+		if [ ! -z "$(netplan generate --mapping "$iface" | grep networkd)" ]; then
+			netplan=1
+		else
+			netplan=0
+		fi
+	else
+		netplan=0
+	fi
+
+	if [ "$netplan" == "1" ]; then
+		if [ -f "/etc/netplan/60-hestia.yaml" ]; then
+			sys_ip="        - $ip/$cidr"
+		else
+			sys_ip="# Added by hestia, please do not edit the file manually!"
+			sys_ip="$sys_ip\nnetwork:"
+			sys_ip="$sys_ip\n  version: 2"
+			sys_ip="$sys_ip\n  renderer: networkd"
+			sys_ip="$sys_ip\n  ethernets:"
+			sys_ip="$sys_ip\n    $iface:"
+			sys_ip="$sys_ip\n      addresses:"
+			sys_ip="$sys_ip\n        - $ip/$cidr"
+		fi
+		IFS='%'
+		echo -e $sys_ip >> /etc/netplan/60-hestia.yaml
+		unset IFS
+	else
+		sys_ip="\n# Added by Hestia Control Panel"
+		sys_ip="$sys_ip\nauto $iface"
+		sys_ip="$sys_ip\niface $iface inet static"
+		sys_ip="$sys_ip\naddress $ip"
+		sys_ip="$sys_ip\nnetmask $netmask"
+		echo -e $sys_ip >> /etc/network/interfaces
+	fi
 fi
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Adding hestia ip
 echo "OWNER='$user'
@@ -131,64 +131,64 @@ chmod 660 $HESTIA/data/ips/$ip
 
 # WEB support
 if [ ! -z "$WEB_SYSTEM" ]; then
-    web_conf="/etc/$WEB_SYSTEM/conf.d/$ip.conf"
-    rm -f $web_conf
-
-    if [ "$WEB_SYSTEM" = 'httpd' ] || [ "$WEB_SYSTEM" = 'apache2' ]; then
-        if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then
-            echo "NameVirtualHost $ip:$WEB_PORT" >  $web_conf
-        fi
-        echo "Listen $ip:$WEB_PORT" >> $web_conf
-        cat $HESTIA_INSTALL_DIR/apache2/unassigned.conf >> $web_conf
-        sed -i 's/directIP/'$ip'/g' $web_conf
-        sed -i 's/directPORT/'$WEB_PORT'/g' $web_conf
-
-    elif [ "$WEB_SYSTEM" = 'nginx' ]; then
-        cp -f $HESTIA_INSTALL_DIR/nginx/unassigned.inc $web_conf
-        sed -i 's/directIP/'$ip'/g' $web_conf
-    fi
-
-    if [ "$WEB_SSL" = 'mod_ssl' ]; then
-        if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then
-            sed -i "1s/^/NameVirtualHost $ip:$WEB_SSL_PORT\n/" $web_conf
-        fi
-        sed -i "1s/^/Listen $ip:$WEB_SSL_PORT\n/" $web_conf
-        sed -i 's/directSSLPORT/'$WEB_SSL_PORT'/g' $web_conf
-    fi
+	web_conf="/etc/$WEB_SYSTEM/conf.d/$ip.conf"
+	rm -f $web_conf
+
+	if [ "$WEB_SYSTEM" = 'httpd' ] || [ "$WEB_SYSTEM" = 'apache2' ]; then
+		if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then
+			echo "NameVirtualHost $ip:$WEB_PORT" > $web_conf
+		fi
+		echo "Listen $ip:$WEB_PORT" >> $web_conf
+		cat $HESTIA_INSTALL_DIR/apache2/unassigned.conf >> $web_conf
+		sed -i 's/directIP/'$ip'/g' $web_conf
+		sed -i 's/directPORT/'$WEB_PORT'/g' $web_conf
+
+	elif [ "$WEB_SYSTEM" = 'nginx' ]; then
+		cp -f $HESTIA_INSTALL_DIR/nginx/unassigned.inc $web_conf
+		sed -i 's/directIP/'$ip'/g' $web_conf
+	fi
+
+	if [ "$WEB_SSL" = 'mod_ssl' ]; then
+		if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then
+			sed -i "1s/^/NameVirtualHost $ip:$WEB_SSL_PORT\n/" $web_conf
+		fi
+		sed -i "1s/^/Listen $ip:$WEB_SSL_PORT\n/" $web_conf
+		sed -i 's/directSSLPORT/'$WEB_SSL_PORT'/g' $web_conf
+	fi
 fi
 
 # Proxy support
 if [ -n "$PROXY_SYSTEM" ]; then
-    cat $WEBTPL/$PROXY_SYSTEM/proxy_ip.tpl |\
-        sed -e "s/%ip%/$ip/g" \
-            -e "s/%web_port%/$WEB_PORT/g" \
-            -e "s/%proxy_port%/$PROXY_PORT/g" \
-            -e "s/%proxy_ssl_port%/$PROXY_SSL_PORT/g" \
-        > /etc/$PROXY_SYSTEM/conf.d/$ip.conf
-
-    # mod_extract_forwarded
-    fw_conf="/etc/$WEB_SYSTEM/conf.d/mod_extract_forwarded.conf"
-    if [ -e "$fw_conf" ]; then
-        ips=$(grep 'MEFaccept ' $fw_conf | grep -v '#' | head -n1)
-        sed -i "s/$ips/$ips $ip/g" $fw_conf
-    fi
-
-    # mod_rpaf
-    rpaf_conf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
-    if [ -e "$rpaf_conf" ]; then
-        rpaf_str=$(grep RPAFproxy_ips $rpaf_conf)
-        [ -z "$rpaf_str" ] && sed -i 's|</IfModule>|RPAFproxy_ips\n</IfModule>|' $rpaf_conf && rpaf_str='RPAFproxy_ips'
-        rpaf_str="$rpaf_str $ip"
-        sed -i "s/.*RPAFproxy_ips.*/$rpaf_str/" $rpaf_conf
-    fi
-
-    #mod_remoteip
-    remoteip_conf="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
-    if [ -e "$remoteip_conf" ]; then
-        if [ $( grep -ic "$ip" $remoteip_conf ) -eq 0 ]; then
-            sed -i "s/<\/IfModule>/RemoteIPInternalProxy $ip\n<\/IfModule>/g" $remoteip_conf
-        fi
-    fi
+	cat $WEBTPL/$PROXY_SYSTEM/proxy_ip.tpl \
+		| sed -e "s/%ip%/$ip/g" \
+			-e "s/%web_port%/$WEB_PORT/g" \
+			-e "s/%proxy_port%/$PROXY_PORT/g" \
+			-e "s/%proxy_ssl_port%/$PROXY_SSL_PORT/g" \
+			> /etc/$PROXY_SYSTEM/conf.d/$ip.conf
+
+	# mod_extract_forwarded
+	fw_conf="/etc/$WEB_SYSTEM/conf.d/mod_extract_forwarded.conf"
+	if [ -e "$fw_conf" ]; then
+		ips=$(grep 'MEFaccept ' $fw_conf | grep -v '#' | head -n1)
+		sed -i "s/$ips/$ips $ip/g" $fw_conf
+	fi
+
+	# mod_rpaf
+	rpaf_conf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
+	if [ -e "$rpaf_conf" ]; then
+		rpaf_str=$(grep RPAFproxy_ips $rpaf_conf)
+		[ -z "$rpaf_str" ] && sed -i 's|</IfModule>|RPAFproxy_ips\n</IfModule>|' $rpaf_conf && rpaf_str='RPAFproxy_ips'
+		rpaf_str="$rpaf_str $ip"
+		sed -i "s/.*RPAFproxy_ips.*/$rpaf_str/" $rpaf_conf
+	fi
+
+	#mod_remoteip
+	remoteip_conf="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
+	if [ -e "$remoteip_conf" ]; then
+		if [ $(grep -ic "$ip" $remoteip_conf) -eq 0 ]; then
+			sed -i "s/<\/IfModule>/RemoteIPInternalProxy $ip\n<\/IfModule>/g" $remoteip_conf
+		fi
+	fi
 fi
 
 #----------------------------------------------------------#
@@ -198,31 +198,31 @@ fi
 # Updating user counters
 increase_user_value "$user" '$IP_OWNED'
 if [ "$user" = 'admin' ]; then
-    if [ "$ip_status" = 'shared' ]; then
-        for hestia_user in $($HESTIA/bin/v-list-sys-users plain); do
-            increase_user_value "$hestia_user" '$IP_AVAIL'
-        done
-    else
-        increase_user_value 'admin' '$IP_AVAIL'
-    fi
+	if [ "$ip_status" = 'shared' ]; then
+		for hestia_user in $($HESTIA/bin/v-list-sys-users plain); do
+			increase_user_value "$hestia_user" '$IP_AVAIL'
+		done
+	else
+		increase_user_value 'admin' '$IP_AVAIL'
+	fi
 else
-    increase_user_value "$user" '$IP_AVAIL'
-    increase_user_value 'admin' '$IP_AVAIL'
+	increase_user_value "$user" '$IP_AVAIL'
+	increase_user_value 'admin' '$IP_AVAIL'
 fi
 
 # Restarting web server
 $BIN/v-restart-web
-check_result $? "Web restart failed" >/dev/null
+check_result $? "Web restart failed" > /dev/null
 
 # Restarting proxy server
 if [ -n "$PROXY_SYSTEM" ]; then
-    $BIN/v-restart-proxy
-    check_result $? "Proxy restart failed" >/dev/null
+	$BIN/v-restart-proxy
+	check_result $? "Proxy restart failed" > /dev/null
 fi
 
 # Restarting firewall
 if [ -n "$FIREWALL_SYSTEM" ]; then
-    $BIN/v-update-firewall
+	$BIN/v-update-firewall
 fi
 
 # Logging

+ 23 - 23
bin/v-add-sys-pma-sso

@@ -32,28 +32,28 @@ check_hestia_demo_mode
 
 # Checking root permissions
 if [ "x$(id -u)" != 'x0' ]; then
-    echo "Error: Script can be run executed only by root"
-    exit 10
+	echo "Error: Script can be run executed only by root"
+	exit 10
 fi
 
-if [ -n "$PHPMYADMIN_KEY" ] && [ "$PHPMYADMIN_KEY" != "" ] ; then
-    echo "Error: SSO has been installed before to reenable it please run v-delete-sys-pma-sso first"
-    exit 1;
+if [ -n "$PHPMYADMIN_KEY" ] && [ "$PHPMYADMIN_KEY" != "" ]; then
+	echo "Error: SSO has been installed before to reenable it please run v-delete-sys-pma-sso first"
+	exit 1
 fi
 
 if [ -f "/usr/share/phpmyadmin/hestia-sso.php" ]; then
-    echo "Error: hestia-sso.php is already installed"
-    exit 2
+	echo "Error: hestia-sso.php is already installed"
+	exit 2
 fi
 
 if [ -f "/usr/local/hesta/web/api/index.php" ]; then
-    echo "Error: API script not installed"
-    exit 2
+	echo "Error: API script not installed"
+	exit 2
 fi
 
 if [ "API_SYSTEM" = "0" ]; then
-    echo "Error: API is not enabled"
-    exit 2
+	echo "Error: API is not enabled"
+	exit 2
 fi
 
 #----------------------------------------------------------#
@@ -61,8 +61,8 @@ fi
 #----------------------------------------------------------#
 
 # Generate the keys to secure everything
-phpmyadminkey=$(generate_password);
-apikey=$($BIN/v-add-access-key 'admin' 'phpmyadmin-sso' 'phpMyAdmin' 'plain');
+phpmyadminkey=$(generate_password)
+apikey=$($BIN/v-add-access-key 'admin' 'phpmyadmin-sso' 'phpMyAdmin' 'plain')
 
 # copy config dir to /usr/share/phpmyadmin/
 cp -f $HESTIA_INSTALL_DIR/phpmyadmin/hestia-sso.php $PMA_INSTALL/hestia-sso.php
@@ -89,18 +89,18 @@ if(isset(\$_GET['hestia_token']) || isset(\$_COOKIE['SignonSession'])){
 ?>" >> $PMA_CONFIG/hestia-sso.inc.php
 
 file=$(cat $PMA_CONFIG/config.inc.php)
-if ! [[  "$file" =~ hestia-sso.inc.php ]]; then
-    if [[ $file =~ "//Add Hestia SSO code here" ]]; then
-        sed -i "s|//Add Hestia SSO code here|//Add Hestia SSO code here\n     include ('$PMA_CONFIG/hestia-sso.inc.php');|g" $PMA_CONFIG/config.inc.php
-    else
-        echo "include ('$PMA_CONFIG/hestia-sso.inc.php');" >> $PMA_CONFIG/config.inc.php
-    fi
+if ! [[ "$file" =~ hestia-sso.inc.php ]]; then
+	if [[ $file =~ "//Add Hestia SSO code here" ]]; then
+		sed -i "s|//Add Hestia SSO code here|//Add Hestia SSO code here\n     include ('$PMA_CONFIG/hestia-sso.inc.php');|g" $PMA_CONFIG/config.inc.php
+	else
+		echo "include ('$PMA_CONFIG/hestia-sso.inc.php');" >> $PMA_CONFIG/config.inc.php
+	fi
 fi
 
 $BIN/v-change-sys-config-value 'PHPMYADMIN_KEY' "$phpmyadminkey"
 
-if [  -z "$(echo $API_ALLOWED_IP | grep 127.0.0.1)"  ]; then
-    $BIN/v-add-sys-api-ip "127.0.0.1"
+if [ -z "$(echo $API_ALLOWED_IP | grep 127.0.0.1)" ]; then
+	$BIN/v-add-sys-api-ip "127.0.0.1"
 fi
 
 #----------------------------------------------------------#
@@ -108,7 +108,7 @@ fi
 #----------------------------------------------------------#
 
 if [ "$MODE" != "quiet" ]; then
-    echo "PMA Hestia-SSO plugin has been succesfully installed"
+	echo "PMA Hestia-SSO plugin has been succesfully installed"
 fi
 $BIN/v-log-action "system" "Info" "Plugins" "phpMyAdmin Single Sign-On has been enabled."
-log_event "$OK" "$ARGUMENTS"
+log_event "$OK" "$ARGUMENTS"

+ 25 - 25
bin/v-add-sys-quota

@@ -22,26 +22,26 @@ source_conf "$HESTIA/conf/hestia.conf"
 #----------------------------------------------------------#
 
 # Ensure that quota kernel modules are installed
-kernel_module_check=$(find /lib/modules/`uname -r` -type f -name '*quota_v*.ko*' | egrep '.*' && [ $? -eq 0 ])
+kernel_module_check=$(find /lib/modules/$(uname -r) -type f -name '*quota_v*.ko*' | egrep '.*' && [ $? -eq 0 ])
 if [ -z "$kernel_module_check" ]; then
-    # Install kernel modules for quota support.
-    # Requires reboot to activate updated kernel.
-    echo "Installing required kernel modules for quota support..."
-    reboot_req="Y"
-    apt-get -qq install linux-image-extra-virtual -y
-    check_result $? "kernel module installation failed" "$E_UPDATE"
+	# Install kernel modules for quota support.
+	# Requires reboot to activate updated kernel.
+	echo "Installing required kernel modules for quota support..."
+	reboot_req="Y"
+	apt-get -qq install linux-image-extra-virtual -y
+	check_result $? "kernel module installation failed" "$E_UPDATE"
 fi
 
 # Checking quota package
-quota=$(which --skip-alias --skip-functions quota 2>/dev/null)
+quota=$(which --skip-alias --skip-functions quota 2> /dev/null)
 if [ $? -ne 0 ]; then
-    if [ -f "/etc/redhat-release" ]; then
-        dnf -y install quota >/dev/null 2>&1
-    else
-        export DEBIAN_FRONTEND=noninteractive
-        apt-get -y install quota >/dev/null 2>&1
-    fi
-    check_result $? "quota package installation failed" "$E_UPDATE"
+	if [ -f "/etc/redhat-release" ]; then
+		dnf -y install quota > /dev/null 2>&1
+	else
+		export DEBIAN_FRONTEND=noninteractive
+		apt-get -y install quota > /dev/null 2>&1
+	fi
+	check_result $? "quota package installation failed" "$E_UPDATE"
 fi
 
 # Perform verification if read-only mode is enabled
@@ -57,15 +57,15 @@ lnr=$(cat -n /etc/fstab | grep -v "#" | awk '{print $1,$3}' | grep "$mnt$" | cut
 opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
 fnd='usrquota\|grpquota\|usrjquota=aquota.user\|grpjquota=aquota.group\|jqfmt=vfsv0'
 if [ $(echo $opt | tr ',' '\n' | grep -x $fnd | wc -l) -ne 5 ]; then
-    old=$(echo $(echo $opt | tr ',' '\n' | grep -v 'usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt=') | tr ' ' ',')
-    new='usrquota,grpquota,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0'
-    sed -i "$lnr s/$opt/$old,$new/" /etc/fstab
-    mount -o remount "$mnt"
+	old=$(echo $(echo $opt | tr ',' '\n' | grep -v 'usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt=') | tr ' ' ',')
+	new='usrquota,grpquota,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0'
+	sed -i "$lnr s/$opt/$old,$new/" /etc/fstab
+	mount -o remount "$mnt"
 fi
 
 # Adding v2 group and user quota index
 if [ ! -e "$mnt/aquota.user" ] || [ ! -e "$mnt/aquota.group" ]; then
-    quotacheck -avcugm >/dev/null 2>&1
+	quotacheck -avcugm > /dev/null 2>&1
 fi
 
 # Adding quotacheck on reboot
@@ -78,20 +78,20 @@ chmod a+x /etc/cron.daily/quotacheck
 
 # Enabling group and user quota
 if [ -n "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is off')" ]; then
-    quotaon -v $mnt
-    check_result $? "quota can't be enabled in $mnt" "$E_DISK"
+	quotaon -v $mnt
+	check_result $? "quota can't be enabled in $mnt" "$E_DISK"
 fi
 
 # Updating hestia.conf value
 if [ -z "$(grep DISK_QUOTA $HESTIA/conf/hestia.conf)" ]; then
-    echo "DISK_QUOTA='yes'" >> $HESTIA/conf/hestia.conf
+	echo "DISK_QUOTA='yes'" >> $HESTIA/conf/hestia.conf
 else
-    sed -i "s/DISK_QUOTA=.*/DISK_QUOTA='yes'/g" $HESTIA/conf/hestia.conf
+	sed -i "s/DISK_QUOTA=.*/DISK_QUOTA='yes'/g" $HESTIA/conf/hestia.conf
 fi
 
 # Rebuilding user quota
 for user in $($HESTIA/bin/v-list-sys-users plain); do
-    $BIN/v-update-user-quota "$user"
+	$BIN/v-update-user-quota "$user"
 done
 
 #----------------------------------------------------------#

+ 91 - 92
bin/v-add-sys-rainloop

@@ -40,29 +40,29 @@ RL_LOG="/var/log/rainloop"
 
 # Checking root permissions
 if [ "x$(id -u)" != 'x0' ]; then
-    echo "ERROR: v-add-sys-rainloop can only be executed by the root user"
-    exit 10
+	echo "ERROR: v-add-sys-rainloop can only be executed by the root user"
+	exit 10
 fi
 
 # Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
 if [ -z "$HESTIA" ]; then
-    HESTIA="/usr/local/hestia"
+	HESTIA="/usr/local/hestia"
 fi
 
 if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
-    echo "ERROR: Environment variables not present, installation aborted."
-    exit 2
+	echo "ERROR: Environment variables not present, installation aborted."
+	exit 2
 fi
 
 # Get current version
 if [ -f "/var/lib/rainloop/data/VERSION" ]; then
-    version=$(cat $RL_INSTALL_DIR/data/VERSION);
-    if [ "$version" == "$rl_v" ]; then
-        echo "Error: Installed version ($version) is equal to the available version ($rl_v)"
-        exit 2;
-    else
-        UPDATE="yes"
-    fi
+	version=$(cat $RL_INSTALL_DIR/data/VERSION)
+	if [ "$version" == "$rl_v" ]; then
+		echo "Error: Installed version ($version) is equal to the available version ($rl_v)"
+		exit 2
+	else
+		UPDATE="yes"
+	fi
 fi
 
 # Perform verification if read-only mode is enabled
@@ -73,97 +73,96 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 
 if [ "$UPDATE" == "no" ]; then
-    rm -f -r $RL_INSTALL_DIR
-    rm -f -r $RL_CONFIG_DIR
+	rm -f -r $RL_INSTALL_DIR
+	rm -f -r $RL_CONFIG_DIR
 
-    mkdir $RL_INSTALL_DIR
-    mkdir $RL_CONFIG_DIR
+	mkdir $RL_INSTALL_DIR
+	mkdir $RL_CONFIG_DIR
 
-    cd "$RL_INSTALL_DIR"
-    [ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RL_URL" --retry-connrefused --quiet -O "${RL_INSTALL_DIR}/${RL_FILE}"
+	cd "$RL_INSTALL_DIR"
+	[ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RL_URL" --retry-connrefused --quiet -O "${RL_INSTALL_DIR}/${RL_FILE}"
 
-    key=$(openssl rand -hex 4);
+	key=$(openssl rand -hex 4)
 
-    admin_account="admin_$key"
-    admin_password=$(generate_password)
-    r=$(generate_password)
+	admin_account="admin_$key"
+	admin_password=$(generate_password)
+	r=$(generate_password)
 
-    echo "Username: admin_$key" > ~/.rainloop
-    echo "Password: $admin_password" >> ~/.rainloop
-    echo "Secret key: admin_$key" >> ~/.rainloop
+	echo "Username: admin_$key" > ~/.rainloop
+	echo "Password: $admin_password" >> ~/.rainloop
+	echo "Secret key: admin_$key" >> ~/.rainloop
 
-    unzip -q ${RL_INSTALL_DIR}/${RL_FILE}
+	unzip -q ${RL_INSTALL_DIR}/${RL_FILE}
 
-    mv ./data $RL_CONFIG_DIR/
-    ln -s $RL_CONFIG_DIR/data/ ./data
+	mv ./data $RL_CONFIG_DIR/
+	ln -s $RL_CONFIG_DIR/data/ ./data
 
-    SALT=$(openssl rand -base64 64)
-    cp ./data/VERSION ./data/INSTALLED
-    echo "<?php //$SALT" >  ./data/SALT.php
-    echo "Forbidden" >  ./data/index.php
-    echo "Forbidden" >  ./data/index.html
+	SALT=$(openssl rand -base64 64)
+	cp ./data/VERSION ./data/INSTALLED
+	echo "<?php //$SALT" > ./data/SALT.php
+	echo "Forbidden" > ./data/index.php
+	echo "Forbidden" > ./data/index.html
 
-    # Create database
-    mysql -e "CREATE DATABASE rainloop"
-    # Mysql available on system
-    r=$(generate_password)
-    mysql -e "GRANT ALL ON rainloop.*
+	# Create database
+	mysql -e "CREATE DATABASE rainloop"
+	# Mysql available on system
+	r=$(generate_password)
+	mysql -e "GRANT ALL ON rainloop.*
      TO rainloop@localhost IDENTIFIED BY '$r'"
 
-    mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/configs
-    php -f $HESTIA_INSTALL_DIR/rainloop/change_password.php "admin_$key" "$admin_password" "$r"
-    mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/domains
-    cp -f $HESTIA_INSTALL_DIR/rainloop/default.ini $RL_CONFIG_DIR/data/_data_/_default_/domains
-    mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/plugins
-    cp -f -r $HESTIA_INSTALL_DIR/rainloop/plugins/hestia-change-password/ $RL_CONFIG_DIR/data/_data_/_default_/plugins
-    mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header
-    # Download add-x-originating-ip-header from rainloop github
-    wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/index.php https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/index.php
-    wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/VERSION https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/VERSION
-    wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/README https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/README
-    wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/LICENSE https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/LICENSE
-
-    cp -f $HESTIA_INSTALL_DIR/rainloop/plugins/plugin-add-x-originating-ip-header.ini $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-add-x-originating-ip-header.ini
-    cp -f $HESTIA_INSTALL_DIR/rainloop/plugins/plugin-hestia-change-password.ini $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
-
-    sed -i "s/%hostname%/$(hostname)/g" $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
-    sed -i "s/%port%/$BACKEND_PORT/g" $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
-
-
-    chown -R  www-data:www-data ./data
-    chown -R  www-data:www-data $RL_CONFIG_DIR/
-
-    rm  ${RL_INSTALL_DIR}/${RL_FILE}
-    # Add robots.txt
-    echo "User-agent: *" > $RL_INSTALL_DIR/robots.txt
-    echo "Disallow: /" >> $RL_INSTALL_DIR/robots.txt
-
-    # Updating hestia.conf
-    if [ -z "$(grep WEBMAIL_SYSTEM $HESTIA/conf/hestia.conf)" ]; then
-        $BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' 'rainloop'
-    else
-        if [  -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'rainloop')" ]; then
-           if [ -n "$WEBMAIL_SYSTEM" ]; then
-               $BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "rainloop,$WEBMAIL_SYSTEM"
-           else
-               $BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "rainloop"
-           fi
-        fi
-    fi
+	mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/configs
+	php -f $HESTIA_INSTALL_DIR/rainloop/change_password.php "admin_$key" "$admin_password" "$r"
+	mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/domains
+	cp -f $HESTIA_INSTALL_DIR/rainloop/default.ini $RL_CONFIG_DIR/data/_data_/_default_/domains
+	mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/plugins
+	cp -f -r $HESTIA_INSTALL_DIR/rainloop/plugins/hestia-change-password/ $RL_CONFIG_DIR/data/_data_/_default_/plugins
+	mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header
+	# Download add-x-originating-ip-header from rainloop github
+	wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/index.php https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/index.php
+	wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/VERSION https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/VERSION
+	wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/README https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/README
+	wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/LICENSE https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/LICENSE
+
+	cp -f $HESTIA_INSTALL_DIR/rainloop/plugins/plugin-add-x-originating-ip-header.ini $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-add-x-originating-ip-header.ini
+	cp -f $HESTIA_INSTALL_DIR/rainloop/plugins/plugin-hestia-change-password.ini $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
+
+	sed -i "s/%hostname%/$(hostname)/g" $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
+	sed -i "s/%port%/$BACKEND_PORT/g" $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
+
+	chown -R www-data:www-data ./data
+	chown -R www-data:www-data $RL_CONFIG_DIR/
+
+	rm ${RL_INSTALL_DIR}/${RL_FILE}
+	# Add robots.txt
+	echo "User-agent: *" > $RL_INSTALL_DIR/robots.txt
+	echo "Disallow: /" >> $RL_INSTALL_DIR/robots.txt
+
+	# Updating hestia.conf
+	if [ -z "$(grep WEBMAIL_SYSTEM $HESTIA/conf/hestia.conf)" ]; then
+		$BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' 'rainloop'
+	else
+		if [ -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'rainloop')" ]; then
+			if [ -n "$WEBMAIL_SYSTEM" ]; then
+				$BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "rainloop,$WEBMAIL_SYSTEM"
+			else
+				$BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "rainloop"
+			fi
+		fi
+	fi
 
 else
-   [ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RL_URL" --quiet -O "${RL_INSTALL_DIR}/${RL_FILE}"
-   version=$(cat $RL_INSTALL_DIR/data/VERSION);
-
-   unzip -q -j rainloop-latest.zip "data/VERSION" -d $RL_INSTALL_DIR/
-   version_source=$(cat $RL_INSTALL_DIR/VERSION);
-
-   # Check version inside .zip file in case hestia didn't update yet
-   if [ "$version" != "$version_source" ]; then
-       unzip -q ${RL_INSTALL_DIR}/${RL_FILE}
-       rm $RL_INSTALL_DIR/$RL_FILE
-    fi
-    rm ${RL_INSTALL_DIR}/VERSION
+	[ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RL_URL" --quiet -O "${RL_INSTALL_DIR}/${RL_FILE}"
+	version=$(cat $RL_INSTALL_DIR/data/VERSION)
+
+	unzip -q -j rainloop-latest.zip "data/VERSION" -d $RL_INSTALL_DIR/
+	version_source=$(cat $RL_INSTALL_DIR/VERSION)
+
+	# Check version inside .zip file in case hestia didn't update yet
+	if [ "$version" != "$version_source" ]; then
+		unzip -q ${RL_INSTALL_DIR}/${RL_FILE}
+		rm $RL_INSTALL_DIR/$RL_FILE
+	fi
+	rm ${RL_INSTALL_DIR}/VERSION
 fi
 
 #----------------------------------------------------------#
@@ -171,8 +170,8 @@ fi
 #----------------------------------------------------------#
 
 if [ "$UPDATE" = "yes" ]; then
-    $BIN/v-log-action "system" "Info" "Plugins" "Rainloop updated (Version: $version)."
+	$BIN/v-log-action "system" "Info" "Plugins" "Rainloop updated (Version: $version)."
 else
-    $BIN/v-log-action "system" "Info" "Plugins" "Rainloop enabled (Version: $version)."
+	$BIN/v-log-action "system" "Info" "Plugins" "Rainloop enabled (Version: $version)."
 fi
 log_event "$OK" "$ARGUMENTS"

+ 133 - 133
bin/v-add-sys-roundcube

@@ -38,39 +38,39 @@ RC_LOG="/var/log/roundcube"
 
 # Checking root permissions
 if [ "x$(id -u)" != 'x0' ]; then
-    echo "ERROR: v-add-sys-roundcube can be run executed only by root user"
-    exit 10
+	echo "ERROR: v-add-sys-roundcube can be run executed only by root user"
+	exit 10
 fi
 
 # Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
 if [ -z "$HESTIA" ]; then
-    HESTIA="/usr/local/hestia"
+	HESTIA="/usr/local/hestia"
 fi
 
 if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_COMMON_DIR" ]; then
-    echo "ERROR: Environment variables not present, installation aborted."
-    exit 2
+	echo "ERROR: Environment variables not present, installation aborted."
+	exit 2
 fi
 
 if [ -z "$(echo "$DB_SYSTEM" | grep -w 'mysql')" ]; then
-    echo "ERROR: Mysql not available. Installation aborted"
-    exit 2
+	echo "ERROR: Mysql not available. Installation aborted"
+	exit 2
 fi
 
 if [ -d "/usr/share/roundcube" ]; then
-    echo "ERROR: Install done from apt source, unable to continue"
-    exit 2;
+	echo "ERROR: Install done from apt source, unable to continue"
+	exit 2
 fi
 
 # Get current version
 if [ -f "/var/lib/roundcube/index.php" ]; then
-    version=$(cat $RC_INSTALL_DIR/index.php | grep -o -E '[0-9].[0-9].[0-9]+' | head -1);
-    if [ "$version" == "$rc_v" ]; then
-        echo "Error: Installed version ($version) is equal to the available version ($rc_v)"
-        exit 2;
-    else
-        UPDATE="yes"
-    fi
+	version=$(cat $RC_INSTALL_DIR/index.php | grep -o -E '[0-9].[0-9].[0-9]+' | head -1)
+	if [ "$version" == "$rc_v" ]; then
+		echo "Error: Installed version ($version) is equal to the available version ($rc_v)"
+		exit 2
+	else
+		UPDATE="yes"
+	fi
 fi
 
 # Perform verification if read-only mode is enabled
@@ -81,122 +81,122 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 
 if [ "$UPDATE" == "no" ]; then
-    rm  -f -r $RC_INSTALL_DIR
-    rm  -f -r $RC_CONFIG_DIR
-
-    mkdir -p $RC_INSTALL_DIR/
-    mkdir -p $RC_CONFIG_DIR/
-
-    cd "$RC_INSTALL_DIR"
-    [ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RC_URL" --retry-connrefused --quiet -O "${RC_INSTALL_DIR}/${RC_FILE}"
-
-    tar xzf $RC_FILE
-    cp -rT $RC_EXTRACT $RC_INSTALL_DIR
-
-    # Delete old config folder
-    cp $RC_INSTALL_DIR/config/defaults.inc.php $RC_CONFIG_DIR/defaults.inc.php
-    rm -f -r $RC_INSTALL_DIR/config/
-    ln -s $RC_CONFIG_DIR/ ./config
-    # Replace with Hestia config
-    cp -f $HESTIA_COMMON_DIR/roundcube/main.inc.php $RC_CONFIG_DIR/config.inc.php
-    cp -f $HESTIA_COMMON_DIR/roundcube/mimetypes.php $RC_CONFIG_DIR/mimetypes.php
-    chmod 644 $RC_CONFIG_DIR/*.php
-
-    cp -f $HESTIA_COMMON_DIR/roundcube/hestia.php $RC_INSTALL_DIR/plugins/password/drivers/
-    mkdir -p $RC_CONFIG_DIR/plugins/password
-    mkdir -p $RC_CONFIG_DIR/plugins/newmail_notifier
-    mkdir -p $RC_CONFIG_DIR/plugins/zipdownload
-
-    # Allow changes to the respective config / Create symlinks to /etc/roundcube/
-    cp -f $HESTIA_COMMON_DIR/roundcube/config.inc.php $RC_CONFIG_DIR/plugins/password/config.inc.php
-    ln -s $RC_CONFIG_DIR/plugins/password/config.inc.php ./plugins/password/config.inc.php
-    cp -f $HESTIA_COMMON_DIR/roundcube/plugins/config_newmail_notifier.inc.php $RC_CONFIG_DIR/plugins/newmail_notifier/config.inc.php
-    ln -s $RC_CONFIG_DIR/plugins/newmail_notifier/config.inc.php ./plugins/newmail_notifier/config.inc.php
-    cp -f $HESTIA_COMMON_DIR/roundcube/plugins/config_zipdownload.inc.php $RC_CONFIG_DIR/plugins/zipdownload/config.inc.php
-    ln -s $RC_CONFIG_DIR/plugins/zipdownload/config.inc.php ./plugins/zipdownload/config.inc.php
-
-    # Set up correct permissions roundcube
-    chown -R root:www-data $RC_CONFIG_DIR/
-    chmod 751 -R $RC_CONFIG_DIR
-    chmod 644 $RC_CONFIG_DIR/config.inc.php
-    chmod 644 $RC_CONFIG_DIR/plugins/password/config.inc.php
-    chmod 644 $RC_CONFIG_DIR/plugins/newmail_notifier/config.inc.php
-    chmod 644 $RC_CONFIG_DIR/plugins/zipdownload/config.inc.php
-
-    # Add robots.txt
-    echo "User-agent: *" > /var/lib/roundcube/robots.txt
-    echo "Disallow: /" >> /var/lib/roundcube/robots.txt
-
-    chown -R root:www-data $RC_INSTALL_DIR
-
-    # Log file
-    if [ ! -d  $RC_LOG ];then
-        mkdir $RC_LOG
-    fi
-    chown www-data:www-data $RC_LOG
-    chmod 751 $RC_LOG
-
-    if [ ! -z "$(echo "$DB_SYSTEM" | grep -E 'mysql|pgsql')" ]; then
-        host='localhost'
-        database='roundcube'
-        dbuser="$database"
-        dbpass=$(generate_password)
-        charset='UTF8'
-        sed -i "s/%password%/$dbpass/g" $RC_CONFIG_DIR/config.inc.php
-
-        if [ ! -z "$(echo "$DB_SYSTEM" | grep -w 'mysql')" ]; then
-            add_mysql_database
-            mysql_query "USE $database; $(< /var/lib/roundcube/SQL/mysql.initial.sql)"
-        else
-            add_pgsql_database
-            psql_query "USE $database; $(< /var/lib/roundcube/SQL/postgres.initial.sql)"
-        fi
-    fi
-
-    # TODO: Add support for PostgreSQL
-
-    rcDesKey="$(openssl rand -base64 30 | tr -d "/" | cut -c1-24)"
-    sed -i "s/%des_key%/$rcDesKey/g" $RC_CONFIG_DIR/config.inc.php
-    # Update server hostname in password change plugin
-    sed -i "s/localhost/$(hostname)/g" $RC_CONFIG_DIR/plugins/password/config.inc.php
-
-    # Clean up
-    rm -f -r $RC_INSTALL_DIR/installer;
-    rm -f -r $RC_INSTALL_DIR/$RC_FILE;
-    rm -f -r $RC_INSTALL_DIR/$RC_EXTRACT;
-
-    # Updating hestia.conf
-    if [ -z "$(grep WEBMAIL_SYSTEM $HESTIA/conf/hestia.conf)" ]; then
-        $BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' 'roundcube'
-    else
-        if [  -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'roundcube')" ]; then
-           if [ ! -z "$WEBMAIL_SYSTEM" ]; then
-               $BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "roundcube,$WEBMAIL_SYSTEM"
-           else
-               $BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "roundcube"
-           fi
-        fi
-    fi
-
-    phpenmod mcrypt > /dev/null 2>&1
+	rm -f -r $RC_INSTALL_DIR
+	rm -f -r $RC_CONFIG_DIR
+
+	mkdir -p $RC_INSTALL_DIR/
+	mkdir -p $RC_CONFIG_DIR/
+
+	cd "$RC_INSTALL_DIR"
+	[ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RC_URL" --retry-connrefused --quiet -O "${RC_INSTALL_DIR}/${RC_FILE}"
+
+	tar xzf $RC_FILE
+	cp -rT $RC_EXTRACT $RC_INSTALL_DIR
+
+	# Delete old config folder
+	cp $RC_INSTALL_DIR/config/defaults.inc.php $RC_CONFIG_DIR/defaults.inc.php
+	rm -f -r $RC_INSTALL_DIR/config/
+	ln -s $RC_CONFIG_DIR/ ./config
+	# Replace with Hestia config
+	cp -f $HESTIA_COMMON_DIR/roundcube/main.inc.php $RC_CONFIG_DIR/config.inc.php
+	cp -f $HESTIA_COMMON_DIR/roundcube/mimetypes.php $RC_CONFIG_DIR/mimetypes.php
+	chmod 644 $RC_CONFIG_DIR/*.php
+
+	cp -f $HESTIA_COMMON_DIR/roundcube/hestia.php $RC_INSTALL_DIR/plugins/password/drivers/
+	mkdir -p $RC_CONFIG_DIR/plugins/password
+	mkdir -p $RC_CONFIG_DIR/plugins/newmail_notifier
+	mkdir -p $RC_CONFIG_DIR/plugins/zipdownload
+
+	# Allow changes to the respective config / Create symlinks to /etc/roundcube/
+	cp -f $HESTIA_COMMON_DIR/roundcube/config.inc.php $RC_CONFIG_DIR/plugins/password/config.inc.php
+	ln -s $RC_CONFIG_DIR/plugins/password/config.inc.php ./plugins/password/config.inc.php
+	cp -f $HESTIA_COMMON_DIR/roundcube/plugins/config_newmail_notifier.inc.php $RC_CONFIG_DIR/plugins/newmail_notifier/config.inc.php
+	ln -s $RC_CONFIG_DIR/plugins/newmail_notifier/config.inc.php ./plugins/newmail_notifier/config.inc.php
+	cp -f $HESTIA_COMMON_DIR/roundcube/plugins/config_zipdownload.inc.php $RC_CONFIG_DIR/plugins/zipdownload/config.inc.php
+	ln -s $RC_CONFIG_DIR/plugins/zipdownload/config.inc.php ./plugins/zipdownload/config.inc.php
+
+	# Set up correct permissions roundcube
+	chown -R root:www-data $RC_CONFIG_DIR/
+	chmod 751 -R $RC_CONFIG_DIR
+	chmod 644 $RC_CONFIG_DIR/config.inc.php
+	chmod 644 $RC_CONFIG_DIR/plugins/password/config.inc.php
+	chmod 644 $RC_CONFIG_DIR/plugins/newmail_notifier/config.inc.php
+	chmod 644 $RC_CONFIG_DIR/plugins/zipdownload/config.inc.php
+
+	# Add robots.txt
+	echo "User-agent: *" > /var/lib/roundcube/robots.txt
+	echo "Disallow: /" >> /var/lib/roundcube/robots.txt
+
+	chown -R root:www-data $RC_INSTALL_DIR
+
+	# Log file
+	if [ ! -d $RC_LOG ]; then
+		mkdir $RC_LOG
+	fi
+	chown www-data:www-data $RC_LOG
+	chmod 751 $RC_LOG
+
+	if [ ! -z "$(echo "$DB_SYSTEM" | grep -E 'mysql|pgsql')" ]; then
+		host='localhost'
+		database='roundcube'
+		dbuser="$database"
+		dbpass=$(generate_password)
+		charset='UTF8'
+		sed -i "s/%password%/$dbpass/g" $RC_CONFIG_DIR/config.inc.php
+
+		if [ ! -z "$(echo "$DB_SYSTEM" | grep -w 'mysql')" ]; then
+			add_mysql_database
+			mysql_query "USE $database; $(< /var/lib/roundcube/SQL/mysql.initial.sql)"
+		else
+			add_pgsql_database
+			psql_query "USE $database; $(< /var/lib/roundcube/SQL/postgres.initial.sql)"
+		fi
+	fi
+
+	# TODO: Add support for PostgreSQL
+
+	rcDesKey="$(openssl rand -base64 30 | tr -d "/" | cut -c1-24)"
+	sed -i "s/%des_key%/$rcDesKey/g" $RC_CONFIG_DIR/config.inc.php
+	# Update server hostname in password change plugin
+	sed -i "s/localhost/$(hostname)/g" $RC_CONFIG_DIR/plugins/password/config.inc.php
+
+	# Clean up
+	rm -f -r $RC_INSTALL_DIR/installer
+	rm -f -r $RC_INSTALL_DIR/$RC_FILE
+	rm -f -r $RC_INSTALL_DIR/$RC_EXTRACT
+
+	# Updating hestia.conf
+	if [ -z "$(grep WEBMAIL_SYSTEM $HESTIA/conf/hestia.conf)" ]; then
+		$BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' 'roundcube'
+	else
+		if [ -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'roundcube')" ]; then
+			if [ ! -z "$WEBMAIL_SYSTEM" ]; then
+				$BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "roundcube,$WEBMAIL_SYSTEM"
+			else
+				$BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "roundcube"
+			fi
+		fi
+	fi
+
+	phpenmod mcrypt > /dev/null 2>&1
 else
-    cd "$RC_INSTALL_DIR"
-    [ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RC_URL" --quiet -O "${RC_INSTALL_DIR}/${RC_FILE}"
-
-    tar xzf $RC_FILE
-
-    # Run Roundcube upgrade script
-    $RC_INSTALL_DIR/$RC_EXTRACT/bin/installto.sh -y $RC_INSTALL_DIR > /dev/null 2>&1
-    $RC_INSTALL_DIR/bin/update.sh --version "$version" > /dev/null 2>&1
-    $RC_INSTALL_DIR/bin/indexcontacts.sh > /dev/null 2>&1
-    chown -R root:www-data $RC_INSTALL_DIR
-
-    #clean up the mess
-    if [ -d "$RC_INSTALL_DIR/installer" ]; then
-        rm -f -r $RC_INSTALL_DIR/installer
-    fi
-    rm -f -r $RC_INSTALL_DIR/$RC_FILE
-    rm -f -r $RC_INSTALL_DIR/$RC_EXTRACT
+	cd "$RC_INSTALL_DIR"
+	[ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RC_URL" --quiet -O "${RC_INSTALL_DIR}/${RC_FILE}"
+
+	tar xzf $RC_FILE
+
+	# Run Roundcube upgrade script
+	$RC_INSTALL_DIR/$RC_EXTRACT/bin/installto.sh -y $RC_INSTALL_DIR > /dev/null 2>&1
+	$RC_INSTALL_DIR/bin/update.sh --version "$version" > /dev/null 2>&1
+	$RC_INSTALL_DIR/bin/indexcontacts.sh > /dev/null 2>&1
+	chown -R root:www-data $RC_INSTALL_DIR
+
+	#clean up the mess
+	if [ -d "$RC_INSTALL_DIR/installer" ]; then
+		rm -f -r $RC_INSTALL_DIR/installer
+	fi
+	rm -f -r $RC_INSTALL_DIR/$RC_FILE
+	rm -f -r $RC_INSTALL_DIR/$RC_EXTRACT
 fi
 
 #----------------------------------------------------------#
@@ -204,8 +204,8 @@ fi
 #----------------------------------------------------------#
 
 if [ "$UPDATE" = "yes" ]; then
-    $BIN/v-log-action "system" "Info" "Plugins" "Roundcube updated (Version: $version)."
+	$BIN/v-log-action "system" "Info" "Plugins" "Roundcube updated (Version: $version)."
 else
-    $BIN/v-log-action "system" "Info" "Plugins" "Roundcube enabled (Version: $version)."
+	$BIN/v-log-action "system" "Info" "Plugins" "Roundcube enabled (Version: $version)."
 fi
 log_event "$OK" "$ARGUMENTS"

+ 28 - 28
bin/v-add-sys-sftp-jail

@@ -33,60 +33,60 @@ check_hestia_demo_mode
 
 # Checking sshd directives
 config='/etc/ssh/sshd_config'
-sftp_n=$(grep -n "Subsystem.*sftp" $config |grep -v internal |grep -v ":#")
+sftp_n=$(grep -n "Subsystem.*sftp" $config | grep -v internal | grep -v ":#")
 sftp_i=$(grep -n "^# Hestia SFTP Chroot" $config)
 
 # Disabling normal sftp
 if [ -n "$sftp_n" ]; then
-    fline=$(echo $sftp_n |cut -f 1 -d :)
-    sed -i "${fline}s/Subsystem.*sftp/#Subsystem sftp/" $config
-    restart='yes'
+	fline=$(echo $sftp_n | cut -f 1 -d :)
+	sed -i "${fline}s/Subsystem.*sftp/#Subsystem sftp/" $config
+	restart='yes'
 fi
 
 # Enabling jailed sftp
 if [ -z "$sftp_i" ]; then
-    echo " " >> $config
-    echo "# Hestia SFTP Chroot" >> $config
-    echo "Match User sftp_dummy99" >> $config
-    echo "ChrootDirectory %h" >> $config
-    echo "    X11Forwarding no" >> $config
-    echo "    AllowTCPForwarding no" >> $config
-    echo "    ForceCommand internal-sftp" >> $config
-    restart='yes'
+	echo " " >> $config
+	echo "# Hestia SFTP Chroot" >> $config
+	echo "Match User sftp_dummy99" >> $config
+	echo "ChrootDirectory %h" >> $config
+	echo "    X11Forwarding no" >> $config
+	echo "    AllowTCPForwarding no" >> $config
+	echo "    ForceCommand internal-sftp" >> $config
+	restart='yes'
 fi
 
 # Validating opensshd config
 if [ "$restart" = 'yes' ]; then
-    subj="OpenSSH restart failed"
-    email=$(grep CONTACT $HESTIA/data/users/admin/user.conf |cut -f 2 -d \')
-    /usr/sbin/sshd -t >/dev/null 2>&1
-    if [ "$?" -ne 0 ]; then
-        mail_text="OpenSSH can not be restarted. Please check config:
+	subj="OpenSSH restart failed"
+	email=$(grep CONTACT $HESTIA/data/users/admin/user.conf | cut -f 2 -d \')
+	/usr/sbin/sshd -t > /dev/null 2>&1
+	if [ "$?" -ne 0 ]; then
+		mail_text="OpenSSH can not be restarted. Please check config:
             \n\n$(/usr/sbin/sshd -t)"
-        echo -e "$mail_text" |$SENDMAIL -s "$subj" $email
-    else
-        service ssh restart >/dev/null 2>&1
-    fi
+		echo -e "$mail_text" | $SENDMAIL -s "$subj" $email
+	else
+		service ssh restart > /dev/null 2>&1
+	fi
 fi
 
 # Checking users
 shells="rssh|nologin"
-for user in $(grep "$HOMEDIR" /etc/passwd |egrep "$shells" |cut -f 1 -d:); do
-    # Include all users v-add-user-sftp-jail will handle it
-    $BIN/v-add-user-sftp-jail "$user" "no"
+for user in $(grep "$HOMEDIR" /etc/passwd | egrep "$shells" | cut -f 1 -d:); do
+	# Include all users v-add-user-sftp-jail will handle it
+	$BIN/v-add-user-sftp-jail "$user" "no"
 done
 
 # Restart ssh service
 if [ "$restart" = 'no' ]; then
-    # Skip restart of SSH daemon
-    echo "" > /dev/null 2>&1
+	# Skip restart of SSH daemon
+	echo "" > /dev/null 2>&1
 else
-    service ssh restart > /dev/null 2>&1
+	service ssh restart > /dev/null 2>&1
 fi
 
 # Add v-add-sys-sftp-jail to startup
 if [ ! -e "/etc/cron.d/hestia-sftp" ]; then
-    echo "@reboot root sleep 60 && /usr/local/hestia/bin/v-add-sys-sftp-jail > /dev/null" > /etc/cron.d/hestia-sftp
+	echo "@reboot root sleep 60 && /usr/local/hestia/bin/v-add-sys-sftp-jail > /dev/null" > /etc/cron.d/hestia-sftp
 fi
 
 #----------------------------------------------------------#

+ 1 - 1
bin/v-add-sys-smtp-relay

@@ -46,7 +46,7 @@ change_sys_value 'SMTP_RELAY_HOST' "$host"
 change_sys_value 'SMTP_RELAY_PORT' "$port"
 change_sys_value 'SMTP_RELAY_USER' "$username"
 
-cat >/etc/exim4/smtp_relay.conf << EOL
+cat > /etc/exim4/smtp_relay.conf << EOL
 host:$host
 port:$port
 user:$username

+ 86 - 86
bin/v-add-user

@@ -12,13 +12,14 @@
 
 # Argument definition
 user=$1
-password=$2; HIDE=2
+password=$2
+HIDE=2
 email=$3
 package=${4-default}
 name=$5
 # Last name has been added for backward compatibility with WHMCS / Blesta VestaCP Plugins
 if [ -n "$6" ]; then
-    name="$name $6";
+	name="$name $6"
 fi
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -28,20 +29,19 @@ source $HESTIA/func/main.sh
 # load config file
 source_conf "$HESTIA/conf/hestia.conf"
 
-
 is_user_free() {
-    # these names may cause issues with MariaDB/MySQL database names and should be reserved:
-    # sudo has been added due to Privilege escalation as sudo group has always sudo permission
-    check_sysuser=$(php -r '$reserved_names=array("aria", "aria_log", "mysql", "mysql_upgrade", "ib", "ib_buffer",
- "ddl", "ddl_recovery", "performance", "sudo"); if(in_array(strtolower($argv[1]), $reserved_names, true)){echo implode(", ", $reserved_names);}' "$user" );
-    if [ -n "$check_sysuser" ]; then
-        check_result "$E_INVALID" "The user name '$user' is reserved and cannot be used. List of reserved names: $check_sysuser"
-        return
-    fi
-    check_sysuser=$(cut -f 1 -d : /etc/passwd | grep "^$user$" )
-    if [ -n "$check_sysuser" ] || [ -e "$USER_DATA" ]; then
-        check_result "$E_EXISTS" "user $user exists"
-    fi
+	# these names may cause issues with MariaDB/MySQL database names and should be reserved:
+	# sudo has been added due to Privilege escalation as sudo group has always sudo permission
+	check_sysuser=$(php -r '$reserved_names=array("aria", "aria_log", "mysql", "mysql_upgrade", "ib", "ib_buffer",
+ "ddl", "ddl_recovery", "performance", "sudo"); if(in_array(strtolower($argv[1]), $reserved_names, true)){echo implode(", ", $reserved_names);}' "$user")
+	if [ -n "$check_sysuser" ]; then
+		check_result "$E_INVALID" "The user name '$user' is reserved and cannot be used. List of reserved names: $check_sysuser"
+		return
+	fi
+	check_sysuser=$(cut -f 1 -d : /etc/passwd | grep "^$user$")
+	if [ -n "$check_sysuser" ] || [ -e "$USER_DATA" ]; then
+		check_result "$E_EXISTS" "user $user exists"
+	fi
 }
 
 #----------------------------------------------------------#
@@ -51,7 +51,7 @@ is_user_free() {
 check_args '3' "$#" 'USER PASSWORD EMAIL [PACKAGE] [NAME] '
 is_format_valid 'user' 'email' 'package'
 if [ -n "$name" ]; then
-    is_format_valid 'name'
+	is_format_valid 'name'
 fi
 
 is_user_free "$user"
@@ -66,11 +66,11 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 
 # Parsing package data
-pkg_data=$(cat $HESTIA/data/packages/$package.pkg |egrep -v "TIME|DATE")
+pkg_data=$(cat $HESTIA/data/packages/$package.pkg | egrep -v "TIME|DATE")
 
 # Checking shell
 shell_conf=$(echo "$pkg_data" | grep 'SHELL' | cut -f 2 -d \')
-shell=$(grep -w "$shell_conf" /etc/shells |head -n1)
+shell=$(grep -w "$shell_conf" /etc/shells | head -n1)
 
 # Adding user
 /usr/sbin/useradd "$user" -s "$shell" -c "$email" -m -d "$HOMEDIR/$user" -U
@@ -80,23 +80,23 @@ check_result $? "user creation failed" "$E_INVALID"
 echo "$user:$password" | /usr/sbin/chpasswd
 
 if [ $? -ne 0 ]; then
-    # Delete user on failure
-    /usr/sbin/deluser "$user" > /dev/null 2>&1
-    echo "Error: Password not accepted due to PAM restrictions"
-    exit 2
+	# Delete user on failure
+	/usr/sbin/deluser "$user" > /dev/null 2>&1
+	echo "Error: Password not accepted due to PAM restrictions"
+	exit 2
 fi
 
 # Add a general group for normal users created by Hestia
 if [ -z "$(grep ^hestia-users: /etc/group)" ]; then
-    groupadd --system "hestia-users"
+	groupadd --system "hestia-users"
 fi
 
 # Add membership to hestia-users group to non-admin users
 if [ "$user" = "admin" ]; then
-    setfacl -m "g:admin:r-x" "$HOMEDIR/$user"
+	setfacl -m "g:admin:r-x" "$HOMEDIR/$user"
 else
-    usermod -a -G "hestia-users" "$user"
-    setfacl -m "u:$user:r-x" "$HOMEDIR/$user"
+	usermod -a -G "hestia-users" "$user"
+	setfacl -m "u:$user:r-x" "$HOMEDIR/$user"
 fi
 setfacl -m "g:hestia-users:---" "$HOMEDIR/$user"
 
@@ -104,105 +104,105 @@ setfacl -m "g:hestia-users:---" "$HOMEDIR/$user"
 mkdir $HOMEDIR/$user/conf
 
 if [ -n "$WEB_SYSTEM" ]; then
-    mkdir $HOMEDIR/$user/conf/web $HOMEDIR/$user/web $HOMEDIR/$user/tmp
-    chmod 751 $HOMEDIR/$user/conf/web
-    chmod 700 $HOMEDIR/$user/tmp
-    chown $user:$user $HOMEDIR/$user/web $HOMEDIR/$user/tmp
+	mkdir $HOMEDIR/$user/conf/web $HOMEDIR/$user/web $HOMEDIR/$user/tmp
+	chmod 751 $HOMEDIR/$user/conf/web
+	chmod 700 $HOMEDIR/$user/tmp
+	chown $user:$user $HOMEDIR/$user/web $HOMEDIR/$user/tmp
 fi
 
 if [ -n "$MAIL_SYSTEM" ]; then
-    mkdir $HOMEDIR/$user/conf/mail $HOMEDIR/$user/mail
-    chmod 751 $HOMEDIR/$user/mail
-    chmod 755 $HOMEDIR/$user/conf/mail
+	mkdir $HOMEDIR/$user/conf/mail $HOMEDIR/$user/mail
+	chmod 751 $HOMEDIR/$user/mail
+	chmod 755 $HOMEDIR/$user/conf/mail
 fi
 
 if [ -n "$DNS_SYSTEM" ]; then
-    if [ "$DNS_SYSTEM" = 'named' ]; then
-        dns_group='named'
-    else
-        dns_group='bind'
-    fi
-    mkdir $HOMEDIR/$user/conf/dns
-    chmod 771 $HOMEDIR/$user/conf/dns
-    chown root:$dns_group $HOMEDIR/$user/conf/dns
+	if [ "$DNS_SYSTEM" = 'named' ]; then
+		dns_group='named'
+	else
+		dns_group='bind'
+	fi
+	mkdir $HOMEDIR/$user/conf/dns
+	chmod 771 $HOMEDIR/$user/conf/dns
+	chown root:$dns_group $HOMEDIR/$user/conf/dns
 fi
 
 # Create default writeable folders
 mkdir $HOMEDIR/$user/.config \
-      $HOMEDIR/$user/.cache \
-      $HOMEDIR/$user/.local \
-      $HOMEDIR/$user/.composer \
-      $HOMEDIR/$user/.vscode-server \
-      $HOMEDIR/$user/.ssh \
-      $HOMEDIR/$user/.npm
+	$HOMEDIR/$user/.cache \
+	$HOMEDIR/$user/.local \
+	$HOMEDIR/$user/.composer \
+	$HOMEDIR/$user/.vscode-server \
+	$HOMEDIR/$user/.ssh \
+	$HOMEDIR/$user/.npm
 
 chown $user:$user \
-      $HOMEDIR/$user/.config \
-      $HOMEDIR/$user/.cache \
-      $HOMEDIR/$user/.local \
-      $HOMEDIR/$user/.composer \
-      $HOMEDIR/$user/.vscode-server \
-      $HOMEDIR/$user/.ssh \
-      $HOMEDIR/$user/.npm
+	$HOMEDIR/$user/.config \
+	$HOMEDIR/$user/.cache \
+	$HOMEDIR/$user/.local \
+	$HOMEDIR/$user/.composer \
+	$HOMEDIR/$user/.vscode-server \
+	$HOMEDIR/$user/.ssh \
+	$HOMEDIR/$user/.npm
 
 # Set permissions
 chmod a+x $HOMEDIR/$user
 chattr +i $HOMEDIR/$user/conf > /dev/null 2>&1
 
 # Adding user dir
-mkdir -p  $USER_DATA/ssl $USER_DATA/dns $USER_DATA/mail
+mkdir -p $USER_DATA/ssl $USER_DATA/dns $USER_DATA/mail
 
 # Creating configuration files and pipes
 touch $USER_DATA/backup.conf \
-    $USER_DATA/history.log \
-    $USER_DATA/stats.log \
-    $USER_DATA/web.conf \
-    $USER_DATA/dns.conf \
-    $USER_DATA/mail.conf \
-    $USER_DATA/db.conf \
-    $USER_DATA/cron.conf
+	$USER_DATA/history.log \
+	$USER_DATA/stats.log \
+	$USER_DATA/web.conf \
+	$USER_DATA/dns.conf \
+	$USER_DATA/mail.conf \
+	$USER_DATA/db.conf \
+	$USER_DATA/cron.conf
 
 chmod 770 $USER_DATA \
-    $USER_DATA/ssl \
-    $USER_DATA/dns \
-    $USER_DATA/mail
+	$USER_DATA/ssl \
+	$USER_DATA/dns \
+	$USER_DATA/mail
 
 chmod 660 $USER_DATA/backup.conf \
-    $USER_DATA/history.log \
-    $USER_DATA/stats.log \
-    $USER_DATA/web.conf \
-    $USER_DATA/dns.conf \
-    $USER_DATA/mail.conf \
-    $USER_DATA/db.conf \
-    $USER_DATA/cron.conf
+	$USER_DATA/history.log \
+	$USER_DATA/stats.log \
+	$USER_DATA/web.conf \
+	$USER_DATA/dns.conf \
+	$USER_DATA/mail.conf \
+	$USER_DATA/db.conf \
+	$USER_DATA/cron.conf
 
 # Updating queue pipes
 echo "$BIN/v-update-user-disk $user" >> $HESTIA/data/queue/disk.pipe
 if [ -n "$WEB_SYSTEM" ]; then
-    echo "$BIN/v-update-web-domains-traff $user" \
-        >> $HESTIA/data/queue/traffic.pipe
-    echo "$BIN/v-update-web-domains-disk $user" >> $HESTIA/data/queue/disk.pipe
+	echo "$BIN/v-update-web-domains-traff $user" \
+		>> $HESTIA/data/queue/traffic.pipe
+	echo "$BIN/v-update-web-domains-disk $user" >> $HESTIA/data/queue/disk.pipe
 fi
 if [ -n "$MAIL_SYSTEM" ]; then
-    echo "$BIN/v-update-mail-domains-disk $user" >> $HESTIA/data/queue/disk.pipe
+	echo "$BIN/v-update-mail-domains-disk $user" >> $HESTIA/data/queue/disk.pipe
 fi
 
 if [ -n "$DB_SYSTEM" ]; then
-    echo "$BIN/v-update-databases-disk $user" >> $HESTIA/data/queue/disk.pipe
+	echo "$BIN/v-update-databases-disk $user" >> $HESTIA/data/queue/disk.pipe
 fi
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Filling user config
 if [ "$user" != 'admin' ]; then
-    ip_avail=$($BIN/v-list-user-ips admin plain |grep -w shared|wc -l)
-    u_users=0
+	ip_avail=$($BIN/v-list-user-ips admin plain | grep -w shared | wc -l)
+	u_users=0
 else
-    ip_avail=0
-    u_users=1
+	ip_avail=0
+	u_users=1
 fi
 
 echo "NAME='$name'
@@ -257,17 +257,17 @@ chmod 660 $USER_DATA/user.conf
 
 # Updating quota
 if [ "$DISK_QUOTA" = 'yes' ]; then
-    $BIN/v-update-user-quota "$user"
+	$BIN/v-update-user-quota "$user"
 fi
 
 # Updating admin counter
 if [ "$user" != 'admin' ]; then
-    increase_user_value 'admin' '$U_USERS'
+	increase_user_value 'admin' '$U_USERS'
 fi
 
 # Run template trigger
 if [ -x "$HESTIA/data/packages/$package.sh" ]; then
-    $HESTIA/data/packages/$package.sh "$user" "$email" "$name"
+	$HESTIA/data/packages/$package.sh "$user" "$email" "$name"
 fi
 
 # Adding jailed sftp env

+ 2 - 2
bin/v-add-user-2fa

@@ -41,8 +41,8 @@ source $USER_DATA/user.conf
 
 # Check if 2FA is already enabled
 if [ -n "$TWOFA" ]; then
-    echo "Error: 2FA already enabled"
-    exit "$E_EXISTS"
+	echo "Error: 2FA already enabled"
+	exit "$E_EXISTS"
 fi
 
 # Get secret and qr code from 2fa libary

+ 5 - 5
bin/v-add-user-composer

@@ -16,7 +16,7 @@ user=$1
 version=${2-2}
 
 if [ -z "$HESTIA" ]; then
-    HESTIA="/usr/local/hestia"
+	HESTIA="/usr/local/hestia"
 fi
 
 # Includes
@@ -50,8 +50,8 @@ COMPOSER_DIR="$HOMEDIR/$user/.composer"
 COMPOSER_BIN="$COMPOSER_DIR/composer"
 
 if [ -f "$COMPOSER_BIN" ]; then
-    echo "Composer already available"
-    exit
+	echo "Composer already available"
+	exit
 fi
 
 [ -z "$(readlink -m "$COMPOSER_DIR" | egrep "^$HOMEDIR/$user/")" ] && check_result "$E_FORBIDEN" "Path outside of user homedir (Composer dir)"
@@ -75,8 +75,8 @@ user_exec wget --tries=3 --timeout=15 --read-timeout=15 --waitretry=3 --no-dns-c
 check_result $? "Download composer installer"
 
 if [[ "$signature" != $(sha384sum "$COMPOSER_SETUP_FILE" | cut -f 1 -d " ") ]]; then
-    rm -f "$COMPOSER_SETUP_FILE"
-    check_result "$E_INVALID" "Composer signature does not match"
+	rm -f "$COMPOSER_SETUP_FILE"
+	check_result "$E_INVALID" "Composer signature does not match"
 fi
 
 COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php "$COMPOSER_SETUP_FILE" --quiet "--$version" --install-dir="$COMPOSER_DIR" --filename=composer

+ 14 - 14
bin/v-add-user-notification

@@ -10,8 +10,8 @@
 
 # Argument definition
 user=$1
-topic=$(echo $2 |sed "s/'/%quote%/g")
-notice=$(echo $3 |sed "s/'/%quote%/g")
+topic=$(echo $2 | sed "s/'/%quote%/g")
+notice=$(echo $3 | sed "s/'/%quote%/g")
 type=$4
 
 # Includes
@@ -39,21 +39,21 @@ check_hestia_demo_mode
 
 # Defining notification id
 if [ -e "$USER_DATA/notifications.conf" ]; then
-    nid=$(grep "NID=" $USER_DATA/notifications.conf |cut -f 2 -d \')
-    nid=$(echo "$nid" |sort -n |tail -n1)
-    if [ -n "$nid" ]; then
-        nid="$((nid +1))"
-    else
-        nid=1
-    fi
+	nid=$(grep "NID=" $USER_DATA/notifications.conf | cut -f 2 -d \')
+	nid=$(echo "$nid" | sort -n | tail -n1)
+	if [ -n "$nid" ]; then
+		nid="$((nid + 1))"
+	else
+		nid=1
+	fi
 else
-    nid=1
+	nid=1
 fi
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Concatenating string
 str="NID='$nid' TOPIC='$topic' NOTICE='$notice' TYPE='$type'"
@@ -71,9 +71,9 @@ chmod 660 $USER_DATA/notifications.conf
 
 # Updating notification counter
 if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
-    sed -i "s/^TIME/NOTIFICATIONS='yes'\nTIME/g" $USER_DATA/user.conf
+	sed -i "s/^TIME/NOTIFICATIONS='yes'\nTIME/g" $USER_DATA/user.conf
 else
-    update_user_value "$user" '$NOTIFICATIONS' "yes"
+	update_user_value "$user" '$NOTIFICATIONS' "yes"
 fi
 
 exit

+ 65 - 66
bin/v-add-user-package

@@ -24,66 +24,65 @@ source $HESTIA/func/domain.sh
 source_conf "$HESTIA/conf/hestia.conf"
 
 is_package_consistent() {
-    source_conf "$tmpfile"
-    if [ "$WEB_DOMAINS" != 'unlimited' ]; then
-        is_int_format_valid "$WEB_DOMAINS" 'WEB_DOMAINS'
-    fi
-    if [ "$WEB_ALIASES" != 'unlimited' ]; then
-        is_int_format_valid "$WEB_ALIASES" 'WEB_ALIASES'
-    fi
-    if [ "$DNS_DOMAINS" != 'unlimited' ]; then
-        is_int_format_valid "$DNS_DOMAINS" 'DNS_DOMAINS'
-    fi
-    if [ "$DNS_RECORDS" != 'unlimited' ]; then
-        is_int_format_valid "$DNS_RECORDS" 'DNS_RECORDS'
-    fi
-    if [ "$MAIL_DOMAINS" != 'unlimited' ]; then
-        is_int_format_valid "$MAIL_DOMAINS" 'MAIL_DOMAINS'
-    fi
-    if [ "$MAIL_ACCOUNTS" != 'unlimited' ]; then
-        is_int_format_valid "$MAIL_ACCOUNTS" 'MAIL_ACCOUNTS'
-    fi
-    if [ "$DATABASES" != 'unlimited' ]; then
-        is_int_format_valid "$DATABASES" 'DATABASES'
-    fi
-    if [ "$CRON_JOBS" != 'unlimited' ]; then
-        is_int_format_valid "$CRON_JOBS" 'CRON_JOBS'
-    fi
-
-    is_int_format_valid "$RATE_LIMIT" 'RATE_LIMIT'
-
-    if [ "$DISK_QUOTA" != 'unlimited' ]; then
-        is_int_format_valid "$DISK_QUOTA" 'DISK_QUOTA'
-    fi
-    if [ "$BANDWIDTH" != 'unlimited' ]; then
-        is_int_format_valid "$BANDWIDTH" 'BANDWIDTH'
-    fi
-    if [ "$BACKUPS" != 'unlimited' ]; then
-        is_int_format_valid "$BACKUPS" 'BACKUPS'
-    fi
-    if [ -n "$WEB_TEMPLATE" ]; then
-        is_web_template_valid "$WEB_TEMPLATE"
-    fi
-    if [ -n "$BACKEND_TEMPLATE" ]; then
-        is_backend_template_valid "$BACKEND_TEMPLATE"
-    fi
-    if [ -n "$PROXY_TEMPLATE" ]; then
-        is_proxy_template_valid "$PROXY_TEMPLATE"
-    fi
-    if [ -n "$DNS_TEMPLATE" ]; then
-        is_dns_template_valid "$DNS_TEMPLATE"
-    fi
-    if [ -n "$NS" ]; then
-        IFS=',' read -r -a nameservers <<< "$NS"
-        i=1;
-        for ns in "${nameservers[@]}"
-        do
-            is_domain_format_valid "$ns" "ns$i"
-            i=$((i+1))
-        done
-    fi
-
-    is_format_valid_shell "$SHELL"
+	source_conf "$tmpfile"
+	if [ "$WEB_DOMAINS" != 'unlimited' ]; then
+		is_int_format_valid "$WEB_DOMAINS" 'WEB_DOMAINS'
+	fi
+	if [ "$WEB_ALIASES" != 'unlimited' ]; then
+		is_int_format_valid "$WEB_ALIASES" 'WEB_ALIASES'
+	fi
+	if [ "$DNS_DOMAINS" != 'unlimited' ]; then
+		is_int_format_valid "$DNS_DOMAINS" 'DNS_DOMAINS'
+	fi
+	if [ "$DNS_RECORDS" != 'unlimited' ]; then
+		is_int_format_valid "$DNS_RECORDS" 'DNS_RECORDS'
+	fi
+	if [ "$MAIL_DOMAINS" != 'unlimited' ]; then
+		is_int_format_valid "$MAIL_DOMAINS" 'MAIL_DOMAINS'
+	fi
+	if [ "$MAIL_ACCOUNTS" != 'unlimited' ]; then
+		is_int_format_valid "$MAIL_ACCOUNTS" 'MAIL_ACCOUNTS'
+	fi
+	if [ "$DATABASES" != 'unlimited' ]; then
+		is_int_format_valid "$DATABASES" 'DATABASES'
+	fi
+	if [ "$CRON_JOBS" != 'unlimited' ]; then
+		is_int_format_valid "$CRON_JOBS" 'CRON_JOBS'
+	fi
+
+	is_int_format_valid "$RATE_LIMIT" 'RATE_LIMIT'
+
+	if [ "$DISK_QUOTA" != 'unlimited' ]; then
+		is_int_format_valid "$DISK_QUOTA" 'DISK_QUOTA'
+	fi
+	if [ "$BANDWIDTH" != 'unlimited' ]; then
+		is_int_format_valid "$BANDWIDTH" 'BANDWIDTH'
+	fi
+	if [ "$BACKUPS" != 'unlimited' ]; then
+		is_int_format_valid "$BACKUPS" 'BACKUPS'
+	fi
+	if [ -n "$WEB_TEMPLATE" ]; then
+		is_web_template_valid "$WEB_TEMPLATE"
+	fi
+	if [ -n "$BACKEND_TEMPLATE" ]; then
+		is_backend_template_valid "$BACKEND_TEMPLATE"
+	fi
+	if [ -n "$PROXY_TEMPLATE" ]; then
+		is_proxy_template_valid "$PROXY_TEMPLATE"
+	fi
+	if [ -n "$DNS_TEMPLATE" ]; then
+		is_dns_template_valid "$DNS_TEMPLATE"
+	fi
+	if [ -n "$NS" ]; then
+		IFS=',' read -r -a nameservers <<< "$NS"
+		i=1
+		for ns in "${nameservers[@]}"; do
+			is_domain_format_valid "$ns" "ns$i"
+			i=$((i + 1))
+		done
+	fi
+
+	is_format_valid_shell "$SHELL"
 }
 
 #----------------------------------------------------------#
@@ -93,14 +92,14 @@ is_package_consistent() {
 check_args '2' "$#" 'PKG_DIR PACKAGE' 'rewrite'
 is_format_valid 'package'
 if [ "$rewrite" != 'yes' ]; then
-    is_package_new "$package"
+	is_package_new "$package"
 else
-    is_package_valid "$package"
+	is_package_valid "$package"
 fi
 
 if [ ! -f "$tmpfile" ]; then
-    echo "$tmpfile does not exists"
-    exit "$E_NOTEXIST";
+	echo "$tmpfile does not exists"
+	exit "$E_NOTEXIST"
 fi
 
 is_package_consistent
@@ -121,9 +120,9 @@ chmod 644 "$HESTIA/data/packages/$package.pkg"
 
 # Logging
 if [ "$rewrite" != 'yes' ]; then
-    $BIN/v-log-action "system" "Info" "Packages" "Package added (Name: $package)."
+	$BIN/v-log-action "system" "Info" "Packages" "Package added (Name: $package)."
 else
-    $BIN/v-log-action "system" "Info" "Packages" "Package limits updated (Name: $package)."
+	$BIN/v-log-action "system" "Info" "Packages" "Package limits updated (Name: $package)."
 fi
 log_event "$OK" "$ARGUMENTS"
 

+ 19 - 15
bin/v-add-user-sftp-jail

@@ -30,14 +30,14 @@ check_args '1' "$#" 'USER'
 is_format_valid 'user'
 check=$(is_object_valid 'user' 'USER' "$user")
 if [ $? -ne 0 ]; then
-    user_str=$(grep "^$user:" /etc/passwd |egrep "rssh|nologin")
-    #try to detect "owner" of the ftp_user if not found dont set it up
-    user_owner=$(echo $user_str | cut -f6 -d : | cut -f3 -d / )
-    is_object_valid 'user' 'USER' "$user_owner"
+	user_str=$(grep "^$user:" /etc/passwd | egrep "rssh|nologin")
+	#try to detect "owner" of the ftp_user if not found dont set it up
+	user_owner=$(echo $user_str | cut -f6 -d : | cut -f3 -d /)
+	is_object_valid 'user' 'USER' "$user_owner"
 fi
-user_str=$(grep "^$user:" /etc/passwd |egrep "rssh|nologin")
+user_str=$(grep "^$user:" /etc/passwd | egrep "rssh|nologin")
 if [ -z "$user_str" ]; then
-    exit
+	exit
 fi
 
 # Get current users and split into array
@@ -47,10 +47,10 @@ IFS=',' read -r -a users <<< "$ssh_users"
 # Check if jail exist
 match_string="$ssh_users,"
 if [[ "$match_string" =~ ,$user, ]]; then
-    if [[ -d /home/$user && -z "$(find /home/$user -user root -print -prune -o -prune)" ]]; then
-       chown root:root /home/$user
-    fi
-    exit;
+	if [[ -d /home/$user && -z "$(find /home/$user -user root -print -prune -o -prune)" ]]; then
+		chown root:root /home/$user
+	fi
+	exit
 fi
 
 # Perform verification if read-only mode is enabled
@@ -64,12 +64,16 @@ check_hestia_demo_mode
 users+=($user)
 
 # Write new user list to config
-users=$(IFS=',';echo "${users[*]// /|}";IFS=$' \t\n')
+users=$(
+	IFS=','
+	echo "${users[*]// /|}"
+	IFS=$' \t\n'
+)
 sed -i "s/$ssh_users/$users/g" /etc/ssh/sshd_config
 
 # Set home folder permission to root
 if [ -d "/home/$user" ]; then
-    chown root:root /home/$user
+	chown root:root /home/$user
 fi
 
 #----------------------------------------------------------#
@@ -78,10 +82,10 @@ fi
 
 # Restart ssh service
 if [ "$restart" = 'no' ]; then
-    # Skip restart of SSH daemon
-    echo "" > /dev/null 2>&1
+	# Skip restart of SSH daemon
+	echo "" > /dev/null 2>&1
 else
-    service ssh restart > /dev/null 2>&1
+	service ssh restart > /dev/null 2>&1
 fi
 
 # Logging

+ 21 - 21
bin/v-add-user-sftp-key

@@ -39,33 +39,33 @@ PRVKEY_FILE="$HOMEDIR/$user/.ssh/hst-filemanager-key"
 PUBKEY_FILE="$HOMEDIR/$user/.ssh/hst-filemanager-key.pub"
 AUTHKEY_FILE="$HOMEDIR/$user/.ssh/authorized_keys"
 
-[ -z "$(readlink -f "$PRVKEY_FILE"  | egrep "^$HOMEDIR/$user/.ssh/")" ] && check_result "$E_FORBIDEN" "Invalid private key file path"
-[ -z "$(readlink -f "$PUBKEY_FILE"  | egrep "^$HOMEDIR/$user/.ssh/")" ] && check_result "$E_FORBIDEN" "Invalid public key file path"
+[ -z "$(readlink -f "$PRVKEY_FILE" | egrep "^$HOMEDIR/$user/.ssh/")" ] && check_result "$E_FORBIDEN" "Invalid private key file path"
+[ -z "$(readlink -f "$PUBKEY_FILE" | egrep "^$HOMEDIR/$user/.ssh/")" ] && check_result "$E_FORBIDEN" "Invalid public key file path"
 [ -z "$(readlink -f "$AUTHKEY_FILE" | egrep "^$HOMEDIR/$user/.ssh/")" ] && check_result "$E_FORBIDEN" "Invalid authorized keys path"
 
 if [ ! -f "${PRVKEY_FILE}" ]; then
-    ssh-keygen -q -b 1024 -t rsa -f "${PRVKEY_FILE}" -N ""
-    rm "${PUBKEY_FILE}"
-    new_privkey=true
+	ssh-keygen -q -b 1024 -t rsa -f "${PRVKEY_FILE}" -N ""
+	rm "${PUBKEY_FILE}"
+	new_privkey=true
 fi
 
 if [ ! -f "${AUTHKEY_FILE}" ] || [ "$new_privkey" = true ]; then
-    pubkey_str="$(ssh-keygen -y -f ${PRVKEY_FILE})"
-    pubkey_desc="filemanager.ssh.key"
-
-    if grep --quiet --no-messages -F "$pubkey_desc" "${AUTHKEY_FILE}"; then
-        sed -i "/filemanager\.ssh\.key\$/d" "${AUTHKEY_FILE}"
-    fi
-
-    # make sure authorized_keys is ending with EOL
-    [ -f "${AUTHKEY_FILE}" ] && sed -i '$a\' "${AUTHKEY_FILE}"
-
-    expire=0
-    if [[ "$ttl" -gt 0 ]]; then
-        expire=$(date +%s -d "+${ttl} min")
-        echo "rm ${PRVKEY_FILE}" | at "now +${ttl} minute" > /dev/null 2>&1
-    fi
-    echo "from=\"127.0.0.1\",command=\"internal-sftp\",restrict ${pubkey_str} TS:${expire} ${pubkey_desc}" >> "${AUTHKEY_FILE}"
+	pubkey_str="$(ssh-keygen -y -f ${PRVKEY_FILE})"
+	pubkey_desc="filemanager.ssh.key"
+
+	if grep --quiet --no-messages -F "$pubkey_desc" "${AUTHKEY_FILE}"; then
+		sed -i "/filemanager\.ssh\.key\$/d" "${AUTHKEY_FILE}"
+	fi
+
+	# make sure authorized_keys is ending with EOL
+	[ -f "${AUTHKEY_FILE}" ] && sed -i '$a\' "${AUTHKEY_FILE}"
+
+	expire=0
+	if [[ "$ttl" -gt 0 ]]; then
+		expire=$(date +%s -d "+${ttl} min")
+		echo "rm ${PRVKEY_FILE}" | at "now +${ttl} minute" > /dev/null 2>&1
+	fi
+	echo "from=\"127.0.0.1\",command=\"internal-sftp\",restrict ${pubkey_str} TS:${expire} ${pubkey_desc}" >> "${AUTHKEY_FILE}"
 fi
 
 #

+ 2 - 2
bin/v-add-user-ssh-key

@@ -47,13 +47,13 @@ AUTHKEY_FILE="$HOMEDIR/$user/.ssh/authorized_keys"
 
 # Check if file exits
 if [ ! -f "$AUTHKEY_FILE" ]; then
-    v-add-fs-file "$user" "${AUTHKEY_FILE}"
+	v-add-fs-file "$user" "${AUTHKEY_FILE}"
 fi
 
 [ -z "$key" ] && check_result "$E_NOTEXIST" "Empty ssh public key"
 
 if ! echo "$key" | ssh-keygen -l -f - > /dev/null 2>&1; then
-    check_result "$E_PARSING" "Validating user private key"
+	check_result "$E_PARSING" "Validating user private key"
 fi
 
 # Make sure authorized_keys ends with EOL

+ 3 - 3
bin/v-add-user-wp-cli

@@ -14,7 +14,7 @@
 user=$1
 
 if [ -z "$HESTIA" ]; then
-    HESTIA="/usr/local/hestia"
+	HESTIA="/usr/local/hestia"
 fi
 
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -44,8 +44,8 @@ WPCLI_DIR="/home/$user/.wp-cli"
 WPCLI_BIN="$WPCLI_DIR/wp"
 
 if [ -f "$WPCLI_DIR" ]; then
-    echo "WP-CLI already available"
-    exit
+	echo "WP-CLI already available"
+	exit
 fi
 
 [ -z "$(readlink -m "$WPCLI_DIR" | egrep "^$HOMEDIR/$user/")" ] && check_result "$E_FORBIDEN" "Path outside of user homedir (WP Cli dir)"

+ 70 - 70
bin/v-add-web-domain

@@ -20,7 +20,7 @@ user=$1
 domain=$2
 domain_idn=$2
 ip=$3
-restart=$4      # will be moved to the end soon
+restart=$4 # will be moved to the end soon
 aliases=$5
 proxy_ext=$6
 
@@ -56,21 +56,21 @@ is_object_unsuspended 'user' 'USER' "$user"
 is_package_full 'WEB_DOMAINS'
 
 if [ "$aliases" != "none" ]; then
-    ALIAS="$aliases"
-    is_package_full 'WEB_ALIASES'
+	ALIAS="$aliases"
+	is_package_full 'WEB_ALIASES'
 fi
 
-if [ "$($BIN/v-list-web-domain $user $domain_utf plain |cut -f 1) " != "$domain" ]; then
-    is_domain_new 'web' "$domain_utf,$aliases"
+if [ "$($BIN/v-list-web-domain $user $domain_utf plain | cut -f 1) " != "$domain" ]; then
+	is_domain_new 'web' "$domain_utf,$aliases"
 fi
-if [ "$($BIN/v-list-web-domain $user $domain_idn plain |cut -f 1) " != "$domain" ]; then
-    is_domain_new 'web' "$domain_idn,$aliases"
+if [ "$($BIN/v-list-web-domain $user $domain_idn plain | cut -f 1) " != "$domain" ]; then
+	is_domain_new 'web' "$domain_idn,$aliases"
 else
-    is_domain_new 'web' "$domain,$aliases"
+	is_domain_new 'web' "$domain,$aliases"
 fi
 if [ -z "$(is_ip_format_valid $domain)" ]; then
-    echo "Error: Invalid domain format. IP address detected as input."
-    exit 1
+	echo "Error: Invalid domain format. IP address detected as input."
+	exit 1
 fi
 
 is_dir_symlink "$HOMEDIR/$user/web"
@@ -79,9 +79,9 @@ is_dir_symlink "$HOMEDIR/$user/web/$domain"
 is_base_domain_owner "$domain,$aliases"
 
 if [ -n "$ip" ]; then
-    is_ip_valid "$ip" "$user"
+	is_ip_valid "$ip" "$user"
 else
-    get_user_ip
+	get_user_ip
 fi
 
 # Perform verification if read-only mode is enabled
@@ -107,15 +107,15 @@ $BIN/v-add-fs-directory "$user" "$HOMEDIR/$user/web/$domain/logs"
 
 # Creating domain logs
 touch /var/log/$WEB_SYSTEM/domains/$domain.bytes \
-      /var/log/$WEB_SYSTEM/domains/$domain.log \
-      /var/log/$WEB_SYSTEM/domains/$domain.error.log
+	/var/log/$WEB_SYSTEM/domains/$domain.log \
+	/var/log/$WEB_SYSTEM/domains/$domain.error.log
 ln -f -s /var/log/$WEB_SYSTEM/domains/$domain.*log \
-    $HOMEDIR/$user/web/$domain/logs/
+	$HOMEDIR/$user/web/$domain/logs/
 
 # Adding domain skeleton
-user_exec cp -r $WEBTPL/skel/* "$HOMEDIR/$user/web/$domain/" >/dev/null 2>&1
+user_exec cp -r $WEBTPL/skel/* "$HOMEDIR/$user/web/$domain/" > /dev/null 2>&1
 for file in $(find "$HOMEDIR/$user/web/$domain/" -type f); do
-    sed -i "s/%domain%/$domain/g" $file
+	sed -i "s/%domain%/$domain/g" $file
 done
 
 # Changing file owner & permission
@@ -130,54 +130,54 @@ chown --no-dereference $user:www-data $HOMEDIR/$user/web/$domain/public_*html
 
 # Adding PHP-FPM backend
 if [ -n "$WEB_BACKEND" ]; then
-    if [ -z "$BACKEND_TEMPLATE" ]; then
-        BACKEND_TEMPLATE='default'
-        if [ -z "$(grep BACKEND_TEMPLATE $USER_DATA/user.conf)" ]; then
-            sed -i "s/^DNS_TEMPL/BACKEND_TEMPLATE='default'\nDNS_TEMPL/g" \
-                $USER_DATA/user.conf
-        else
-            update_user_value "$user" '$BACKEND_TEMPLATE' "default"
-        fi
-    fi
-    export BACKEND="$BACKEND_TEMPLATE"
-    $BIN/v-add-web-domain-backend "$user" "$domain" "$BACKEND_TEMPLATE" "$restart"
-    check_result $? "Backend error" >/dev/null
+	if [ -z "$BACKEND_TEMPLATE" ]; then
+		BACKEND_TEMPLATE='default'
+		if [ -z "$(grep BACKEND_TEMPLATE $USER_DATA/user.conf)" ]; then
+			sed -i "s/^DNS_TEMPL/BACKEND_TEMPLATE='default'\nDNS_TEMPL/g" \
+				$USER_DATA/user.conf
+		else
+			update_user_value "$user" '$BACKEND_TEMPLATE' "default"
+		fi
+	fi
+	export BACKEND="$BACKEND_TEMPLATE"
+	$BIN/v-add-web-domain-backend "$user" "$domain" "$BACKEND_TEMPLATE" "$restart"
+	check_result $? "Backend error" > /dev/null
 fi
 
 # Preparing domain aliases
 if [ "$aliases" = 'none' ]; then
-    ALIAS=''
+	ALIAS=''
 else
-    ALIAS="www.$domain"
-    if [ -z "$aliases" ]; then
-        # Check and skip www alias for subdomains.
-        IFS='.' read -r -a domain_elements <<< "$domain"
-        if [ "${#domain_elements[@]}" -gt 2 ]; then
-            is_valid_2_part_extension $domain
-            if [ $? -ne 0 ]; then
-                ALIAS=""
-            else
-                ALIAS="www.$domain"
-            fi
-        else
-            ALIAS="www.$domain"
-        fi
-    else
-        ALIAS="$aliases"
-    fi
-
-    ip_alias=$(get_ip_alias "$domain")
-    if [ -n "$ip_alias" ]; then
-        ALIAS="$ALIAS,$ip_alias"
-    fi
+	ALIAS="www.$domain"
+	if [ -z "$aliases" ]; then
+		# Check and skip www alias for subdomains.
+		IFS='.' read -r -a domain_elements <<< "$domain"
+		if [ "${#domain_elements[@]}" -gt 2 ]; then
+			is_valid_2_part_extension $domain
+			if [ $? -ne 0 ]; then
+				ALIAS=""
+			else
+				ALIAS="www.$domain"
+			fi
+		else
+			ALIAS="www.$domain"
+		fi
+	else
+		ALIAS="$aliases"
+	fi
+
+	ip_alias=$(get_ip_alias "$domain")
+	if [ -n "$ip_alias" ]; then
+		ALIAS="$ALIAS,$ip_alias"
+	fi
 fi
 
 # Preparing domain variables
 prepare_web_domain_values
 
 if [ -z "$WEB_TEMPLATE" ]; then
-    WEB_TEMPLATE='default'
-    update_user_value "$user" '$WEB_TEMPLATE' "default"
+	WEB_TEMPLATE='default'
+	update_user_value "$user" '$WEB_TEMPLATE' "default"
 fi
 
 # Adding web server config
@@ -185,18 +185,18 @@ add_web_config "$WEB_SYSTEM" "$WEB_TEMPLATE.tpl"
 
 # Adding proxy config
 if [ -n "$PROXY_SYSTEM" ]; then
-    PROXY_EXT="$proxy_ext"
-    if [ -z "$proxy_ext" ]; then
-        PROXY_EXT="jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls"
-        PROXY_EXT="$PROXY_EXT,exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp"
-        PROXY_EXT="$PROXY_EXT,rtf,js,mp3,avi,mpeg,flv,html,htm"
-    fi
-    if [ -z "$PROXY_TEMPLATE" ]; then
-        PROXY_TEMPLATE='default'
-        update_user_value "$user" '$PROXY_TEMPLATE' "default"
-    fi
-
-    add_web_config "$PROXY_SYSTEM" "$PROXY_TEMPLATE.tpl"
+	PROXY_EXT="$proxy_ext"
+	if [ -z "$proxy_ext" ]; then
+		PROXY_EXT="jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls"
+		PROXY_EXT="$PROXY_EXT,exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp"
+		PROXY_EXT="$PROXY_EXT,rtf,js,mp3,avi,mpeg,flv,html,htm"
+	fi
+	if [ -z "$PROXY_TEMPLATE" ]; then
+		PROXY_TEMPLATE='default'
+		update_user_value "$user" '$PROXY_TEMPLATE' "default"
+	fi
+
+	add_web_config "$PROXY_SYSTEM" "$PROXY_TEMPLATE.tpl"
 fi
 
 #----------------------------------------------------------#
@@ -210,8 +210,8 @@ increase_user_value "$user" '$U_WEB_ALIASES' "$alias_number"
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Adding domain in web.conf
 echo "DOMAIN='$domain' IP='$ip' IP6='' CUSTOM_DOCROOT='' ALIAS='$ALIAS' TPL='$WEB_TEMPLATE'\
@@ -224,11 +224,11 @@ syshealth_repair_web_config
 
 # Restarting web server
 $BIN/v-restart-web "$restart"
-check_result $? "Web restart failed" >/dev/null
+check_result $? "Web restart failed" > /dev/null
 
 # Restarting proxy server
 $BIN/v-restart-proxy "$restart"
-check_result $? "Proxy restart failed" >/dev/null
+check_result $? "Proxy restart failed" > /dev/null
 
 # Logging
 $BIN/v-log-action "$user" "Info" "Web" "Added new web domain (Name: $domain)."

+ 14 - 14
bin/v-add-web-domain-alias

@@ -41,7 +41,7 @@ format_aliases
 #----------------------------------------------------------#
 
 if [ -z "$aliases" ]; then
-    check_result "$E_INVALID" "Invalid alias format: empty"
+	check_result "$E_INVALID" "Invalid alias format: empty"
 fi
 
 check_args '3' "$#" 'USER DOMAIN ALIASES [RESTART]'
@@ -66,9 +66,9 @@ get_domain_values 'web'
 # Preparing domain values for the template substitution
 local_ip=$(get_real_ip $IP)
 if [ -z "$ALIAS" ]; then
-    ALIAS="$aliases"
+	ALIAS="$aliases"
 else
-    ALIAS="$ALIAS,$aliases"
+	ALIAS="$ALIAS,$aliases"
 fi
 prepare_web_domain_values
 
@@ -78,18 +78,18 @@ is_package_full 'WEB_ALIASES'
 del_web_config "$WEB_SYSTEM" "$TPL.tpl"
 add_web_config "$WEB_SYSTEM" "$TPL.tpl"
 if [ "$SSL" = 'yes' ]; then
-    del_web_config "$WEB_SYSTEM" "$TPL.stpl"
-    add_web_config "$WEB_SYSTEM" "$TPL.stpl"
+	del_web_config "$WEB_SYSTEM" "$TPL.stpl"
+	add_web_config "$WEB_SYSTEM" "$TPL.stpl"
 fi
 
 # Rebuilding proxy configuration
-if [ -n  "$PROXY_SYSTEM" ] && [ -n "$PROXY" ]; then
-    del_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
-    add_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
-    if [ "$SSL" = 'yes' ]; then
-        del_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
-        add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
-    fi
+if [ -n "$PROXY_SYSTEM" ] && [ -n "$PROXY" ]; then
+	del_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
+	add_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
+	if [ "$SSL" = 'yes' ]; then
+		del_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
+		add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
+	fi
 fi
 
 #----------------------------------------------------------#
@@ -102,11 +102,11 @@ increase_user_value "$user" '$U_WEB_ALIASES'
 
 # Restarting web server
 $BIN/v-restart-web "$restart"
-check_result $? "Web restart failed" >/dev/null
+check_result $? "Web restart failed" > /dev/null
 
 # Restarting proxy server
 $BIN/v-restart-proxy "$restart"
-check_result $? "Proxy restart failed" >/dev/null
+check_result $? "Proxy restart failed" > /dev/null
 
 $BIN/v-log-action "$user" "Info" "Web" "Added new web domain alias (Alias: $aliases, Domain: $domain)."
 log_event "$OK" "$ARGUMENTS"

+ 1 - 1
bin/v-add-web-domain-allow-users

@@ -59,7 +59,7 @@ parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
 #----------------------------------------------------------#
 
 if [ -z "$ALLOW_USERS" ]; then
-    add_object_key "web" 'DOMAIN' "$domain" 'ALLOW_USERS' 'TIME'
+	add_object_key "web" 'DOMAIN' "$domain" 'ALLOW_USERS' 'TIME'
 fi
 
 # Adding new alias

+ 20 - 21
bin/v-add-web-domain-backend

@@ -49,38 +49,37 @@ check_hestia_demo_mode
 prepare_web_backend
 get_domain_values 'web'
 
-if [[ -n "$BACKEND" && "$BACKEND" != "$template" ]];then
-    check_result "$E_EXISTS" "Pool already exists"
+if [[ -n "$BACKEND" && "$BACKEND" != "$template" ]]; then
+	check_result "$E_EXISTS" "Pool already exists"
 fi
 
 # Allocating backend port
 backend_port=9000
-ports=$(grep -v '^;' $pool/* 2>/dev/null |grep listen |grep -o :[0-9].*)
-ports=$(echo "$ports" |sed "s/://" |sort -n)
+ports=$(grep -v '^;' $pool/* 2> /dev/null | grep listen | grep -o :[0-9].*)
+ports=$(echo "$ports" | sed "s/://" | sort -n)
 for port in $ports; do
-    if [ "$backend_port" -eq "$port" ]; then
-        backend_port=$((backend_port + 1))
-    fi
+	if [ "$backend_port" -eq "$port" ]; then
+		backend_port=$((backend_port + 1))
+	fi
 done
 
 # Adding backend config
-cat $WEBTPL/$WEB_BACKEND/$template.tpl |\
-    sed -e "s|%backend_port%|$backend_port|" \
-        -e "s|%user%|$user|g"\
-        -e "s|%domain%|$domain|g"\
-        -e "s|%backend%|$backend_type|g"\
-        -e "s|%backend_version%|$backend_version|g" > $pool/$backend_type.conf
-
+cat $WEBTPL/$WEB_BACKEND/$template.tpl \
+	| sed -e "s|%backend_port%|$backend_port|" \
+		-e "s|%user%|$user|g" \
+		-e "s|%domain%|$domain|g" \
+		-e "s|%backend%|$backend_type|g" \
+		-e "s|%backend_version%|$backend_version|g" > $pool/$backend_type.conf
 
 # Set correct document root path
 if [ -n "$CUSTOM_DOCROOT" ]; then
-    docroot="$CUSTOM_DOCROOT"
-    if [ -n "$CUSTOM_PHPROOT" ]; then
-        docroot="$CUSTOM_PHPROOT"
-    fi
-    sed -i "s|/home\/$user\/web\/$domain\/public_html|$docroot|g"  $pool/$backend_type.conf
+	docroot="$CUSTOM_DOCROOT"
+	if [ -n "$CUSTOM_PHPROOT" ]; then
+		docroot="$CUSTOM_PHPROOT"
+	fi
+	sed -i "s|/home\/$user\/web\/$domain\/public_html|$docroot|g" $pool/$backend_type.conf
 else
-    docroot="$HOMEDIR/$user/web/$domain/public_html/"
+	docroot="$HOMEDIR/$user/web/$domain/public_html/"
 fi
 
 #----------------------------------------------------------#
@@ -89,7 +88,7 @@ fi
 
 # Restart backend server
 $BIN/v-restart-web-backend "$restart" "$backend_version"
-check_result $? "Web backend restart failed" >/dev/null
+check_result $? "Web backend restart failed" > /dev/null
 
 # Logging
 $BIN/v-log-action "$user" "Info" "Web" "Web domain configuration applied (Domain: $domain, Backend: $WEB_BACKEND)."

+ 33 - 32
bin/v-add-web-domain-ftp

@@ -15,7 +15,8 @@ user=$1
 domain=$2
 domain_idn=$2
 ftp_user=${1}_${3}
-password=$4; HIDE=4
+password=$4
+HIDE=4
 ftp_path=$5
 
 # Includes
@@ -46,9 +47,9 @@ is_object_valid 'web' 'DOMAIN' "$domain"
 is_object_unsuspended 'web' 'DOMAIN' "$domain"
 check_ftp_user=$(grep "^$ftp_user:" /etc/passwd)
 if [ -n "$check_ftp_user" ] && [ "$FTP_USER" != "$ftp_user" ]; then
-    echo "Error: ftp user $ftp_user already exists"
-    log_event "$E_EXISTS" "$ARGUMENTS"
-    exit "$E_EXISTS"
+	echo "Error: ftp user $ftp_user already exists"
+	log_event "$E_EXISTS" "$ARGUMENTS"
+	exit "$E_EXISTS"
 fi
 is_password_valid
 
@@ -65,44 +66,44 @@ get_domain_values 'web'
 # Defining ftp user shell
 shell=$(which nologin)
 if [ -n "$FTP_SHELL" ]; then
-    shell=$FTP_SHELL
+	shell=$FTP_SHELL
 fi
 
 # Defining path
 if [ -z "$ftp_path" ]; then
-    ftp_path_a="$HOMEDIR/$user/web/$domain"
+	ftp_path_a="$HOMEDIR/$user/web/$domain"
 else
-    # Validating absolute path
-    ftp_path_a=$(readlink -f "$HOMEDIR/$user/web/$domain/$ftp_path")
-    if [ -z "$(echo $ftp_path_a |grep $HOMEDIR/$user/web/$domain)" ]; then
-        echo "Error: absolute path $ftp_path_a is invalid"
-        log_event "$E_INVALID" "$ARGUMENTS"
-        exit "$E_INVALID"
-    fi
-    # Creating ftp user home directory
-    if [ ! -e "$ftp_path_a" ]; then
-        $BIN/v-add-fs-directory "$user" "$ftp_path_a"
-        chown $user:$user "$ftp_path_a"
-        chmod 751 "$ftp_path_a"
-    fi
+	# Validating absolute path
+	ftp_path_a=$(readlink -f "$HOMEDIR/$user/web/$domain/$ftp_path")
+	if [ -z "$(echo $ftp_path_a | grep $HOMEDIR/$user/web/$domain)" ]; then
+		echo "Error: absolute path $ftp_path_a is invalid"
+		log_event "$E_INVALID" "$ARGUMENTS"
+		exit "$E_INVALID"
+	fi
+	# Creating ftp user home directory
+	if [ ! -e "$ftp_path_a" ]; then
+		$BIN/v-add-fs-directory "$user" "$ftp_path_a"
+		chown $user:$user "$ftp_path_a"
+		chmod 751 "$ftp_path_a"
+	fi
 fi
 
 # Adding ftp user
 /usr/sbin/useradd $ftp_user \
-    -s $shell \
-    -o -u $(id -u $user) \
-    -g $(id -g $user) \
-    -G hestia-users \
-    -M -d "$ftp_path_a"  > /dev/null 2>&1
+	-s $shell \
+	-o -u $(id -u $user) \
+	-g $(id -g $user) \
+	-G hestia-users \
+	-M -d "$ftp_path_a" > /dev/null 2>&1
 
 # Set ftp user password
 echo "$ftp_user:$password" | /usr/sbin/chpasswd
 
 if [ $? -ne 0 ]; then
-    # Delete user on failure again
-    /usr/sbin/deluser "$ftp_user"  > /dev/null 2>&1
-    echo "Error: Password not accepted due to PAM restrictions"
-    exit 2
+	# Delete user on failure again
+	/usr/sbin/deluser "$ftp_user" > /dev/null 2>&1
+	echo "Error: Password not accepted due to PAM restrictions"
+	exit 2
 fi
 
 ftp_md5=$(awk -v user=$ftp_user -F : 'user == $1 {print $2}' /etc/shadow)
@@ -115,13 +116,13 @@ $BIN/v-add-user-sftp-jail "$ftp_user"
 #----------------------------------------------------------#
 
 # Transforming absolute path to relative
-ftp_path_r=$(echo $ftp_path_a |sed "s%$HOMEDIR/$user/web/$domain%%")
+ftp_path_r=$(echo $ftp_path_a | sed "s%$HOMEDIR/$user/web/$domain%%")
 
 # Concatenating ftp variables
 if [ ! -z "$FTP_USER" ]; then
-    ftp_user="$FTP_USER:$ftp_user"
-    ftp_md5="$FTP_MD5:$ftp_md5"
-    ftp_path="$FTP_PATH:$ftp_path_r"
+	ftp_user="$FTP_USER:$ftp_user"
+	ftp_md5="$FTP_MD5:$ftp_md5"
+	ftp_path="$FTP_PATH:$ftp_path_r"
 fi
 
 # Adding new key into web.conf

+ 38 - 37
bin/v-add-web-domain-httpauth

@@ -14,7 +14,8 @@
 user=$1
 domain=$2
 auth_user=$3
-password=$4; HIDE=4
+password=$4
+HIDE=4
 restart=${5-yes}
 
 # Includes
@@ -48,10 +49,10 @@ is_object_unsuspended 'web' 'DOMAIN' "$domain"
 is_password_valid
 get_domain_values 'web'
 is_user_format_valid "$auth_user" "Auth user"
-if [ -n "$(echo "$AUTH_USER" |tr : '\n' |grep ^$auth_user$)" ]; then
-    echo "Error: auth user $auth_user already exists"
-    log_event "$E_EXISTS" "$ARGUMENTS"
-    exit "$E_EXISTS"
+if [ -n "$(echo "$AUTH_USER" | tr : '\n' | grep ^$auth_user$)" ]; then
+	echo "Error: auth user $auth_user already exists"
+	log_event "$E_EXISTS" "$ARGUMENTS"
+	exit "$E_EXISTS"
 fi
 
 #----------------------------------------------------------#
@@ -59,29 +60,29 @@ fi
 #----------------------------------------------------------#
 
 # Adding htaccess password protection
-    if [ "$WEB_SYSTEM" = "nginx" ] || [ "$PROXY_SYSTEM" = "nginx" ]; then
-        htaccess="$HOMEDIR/$user/conf/web/$domain/nginx.conf_htaccess"
-        shtaccess="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_htaccess"
-        if [ ! -f "$htaccess" ]; then
-            echo "auth_basic  \"$domain password access\";" > $htaccess
-            echo "auth_basic_user_file    $htpasswd;" >> $htaccess
-            ln -s $htaccess $shtaccess
-            restart_required='yes'
-        fi
-    else
-        htaccess="$HOMEDIR/$user/conf/web/$domain/apache2.conf_htaccess"
-        shtaccess="$HOMEDIR/$user/conf/web/$domain/apache2.ssl.conf_htaccess"
-        if [ ! -f "$htaccess" ]; then
-            echo "<Directory $docroot>" > $htaccess
-            echo "    AuthUserFile $htpasswd" >> $htaccess
-            echo "    AuthName \"$domain access\"" >> $htaccess
-            echo "    AuthType Basic" >> $htaccess
-            echo "    Require valid-user" >> $htaccess
-            echo "</Directory>" >> $htaccess
-            ln -s $htaccess $shtaccess
-            restart_required='yes'
-        fi
-    fi
+if [ "$WEB_SYSTEM" = "nginx" ] || [ "$PROXY_SYSTEM" = "nginx" ]; then
+	htaccess="$HOMEDIR/$user/conf/web/$domain/nginx.conf_htaccess"
+	shtaccess="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_htaccess"
+	if [ ! -f "$htaccess" ]; then
+		echo "auth_basic  \"$domain password access\";" > $htaccess
+		echo "auth_basic_user_file    $htpasswd;" >> $htaccess
+		ln -s $htaccess $shtaccess
+		restart_required='yes'
+	fi
+else
+	htaccess="$HOMEDIR/$user/conf/web/$domain/apache2.conf_htaccess"
+	shtaccess="$HOMEDIR/$user/conf/web/$domain/apache2.ssl.conf_htaccess"
+	if [ ! -f "$htaccess" ]; then
+		echo "<Directory $docroot>" > $htaccess
+		echo "    AuthUserFile $htpasswd" >> $htaccess
+		echo "    AuthName \"$domain access\"" >> $htaccess
+		echo "    AuthType Basic" >> $htaccess
+		echo "    Require valid-user" >> $htaccess
+		echo "</Directory>" >> $htaccess
+		ln -s $htaccess $shtaccess
+		restart_required='yes'
+	fi
+fi
 
 # Adding httpasswd user
 auth_hash=$($BIN/v-generate-password-hash htpasswd htpasswd $password)
@@ -93,10 +94,10 @@ echo "$auth_user:$auth_hash" >> $htpasswd
 
 # Restarting web server
 if [ "$restart" != 'no' ] && [ "$restart_required" = 'yes' ]; then
-    $BIN/v-restart-web
-    if [ -n "$PROXY_SYSTEM" ]; then
-        $BIN/v-restart-proxy
-    fi
+	$BIN/v-restart-web
+	if [ -n "$PROXY_SYSTEM" ]; then
+		$BIN/v-restart-proxy
+	fi
 fi
 
 #----------------------------------------------------------#
@@ -105,12 +106,12 @@ fi
 
 # Preparing web.conf keys
 if [ -n "$AUTH_USER" ]; then
-    auth_user="$AUTH_USER:$auth_user"
-    auth_hash="$AUTH_HASH:$auth_hash"
+	auth_user="$AUTH_USER:$auth_user"
+	auth_hash="$AUTH_HASH:$auth_hash"
 else
-    # Adding new key into web.conf
-    add_object_key "web" 'DOMAIN' "$domain" 'AUTH_USER' 'U_DISK'
-    add_object_key "web" 'DOMAIN' "$domain" 'AUTH_HASH' 'U_DISK'
+	# Adding new key into web.conf
+	add_object_key "web" 'DOMAIN' "$domain" 'AUTH_USER' 'U_DISK'
+	add_object_key "web" 'DOMAIN' "$domain" 'AUTH_HASH' 'U_DISK'
 fi
 
 # Updating config

+ 3 - 3
bin/v-add-web-domain-proxy

@@ -45,7 +45,7 @@ is_object_valid 'web' 'DOMAIN' "$domain"
 is_object_unsuspended 'web' 'DOMAIN' "$domain"
 is_object_value_empty 'web' 'DOMAIN' "$domain" '$PROXY'
 if [ -z $template ]; then
-    template=$(get_user_value '$PROXY_TEMPLATE')
+	template=$(get_user_value '$PROXY_TEMPLATE')
 fi
 is_proxy_template_valid $template
 
@@ -67,7 +67,7 @@ add_web_config "$PROXY_SYSTEM" "$template.tpl"
 
 # Adding proxy for ssl
 if [ "$SSL" = 'yes' ]; then
-    add_web_config "$PROXY_SYSTEM" "$template.stpl"
+	add_web_config "$PROXY_SYSTEM" "$template.stpl"
 fi
 
 #----------------------------------------------------------#
@@ -80,7 +80,7 @@ update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions"
 
 # Restarting web server
 $BIN/v-restart-proxy "$restart"
-check_result $? "Proxy restart failed" >/dev/null
+check_result $? "Proxy restart failed" > /dev/null
 
 $BIN/v-log-action "$user" "Info" "Web" "Proxy enabled (Domain: $domain)."
 log_event "$OK" "$ARGUMENTS"

+ 35 - 35
bin/v-add-web-domain-redirect

@@ -44,20 +44,20 @@ is_object_unsuspended 'web' 'DOMAIN' "$domain"
 
 idn_redirect=$(idn2 --quiet $3)
 if [ $? == 0 ]; then
-    redirect=$idn_redirect;
+	redirect=$idn_redirect
 fi
 
 if [[ "$3" =~ http://|https:// ]]; then
-    scheme=1
-    isValidUrl=$(php -r '$url=$argv[1]; $url=filter_var($url,FILTER_VALIDATE_URL); echo $url;' "$redirect")
-    if  [ -z "$isValidUrl" ]; then
-        check_result $E_INVALID "Invalid redirect"
-    fi
+	scheme=1
+	isValidUrl=$(php -r '$url=$argv[1]; $url=filter_var($url,FILTER_VALIDATE_URL); echo $url;' "$redirect")
+	if [ -z "$isValidUrl" ]; then
+		check_result $E_INVALID "Invalid redirect"
+	fi
 else
-    isValidUrl=$(php -r '$url=$argv[1]; $url=filter_var($url,FILTER_VALIDATE_URL); echo $url;' "http://$redirect")
-    if  [ -z "$isValidUrl" ]; then
-        check_result $E_INVALID "Invalid redirect"
-    fi
+	isValidUrl=$(php -r '$url=$argv[1]; $url=filter_var($url,FILTER_VALIDATE_URL); echo $url;' "http://$redirect")
+	if [ -z "$isValidUrl" ]; then
+		check_result $E_INVALID "Invalid redirect"
+	fi
 fi
 
 # Perform verification if read-only mode is enabled
@@ -69,28 +69,28 @@ check_hestia_demo_mode
 
 # Check if proxy is active
 if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
-    conf="$HOMEDIR/$user/conf/web/$domain/nginx.conf_redirect"
-    sconf="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_redirect"
+	conf="$HOMEDIR/$user/conf/web/$domain/nginx.conf_redirect"
+	sconf="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_redirect"
 fi
 # Insert redirect commands
 if [ -n "$PROXY_SYSTEM" ] || [ "$WEB_SYSTEM" = 'nginx' ]; then
-    if [ "$scheme" = 1 ]; then
-        echo "   return $code $redirect\$request_uri;" > $conf
-        if [ ! -e "$sconf" ]; then
-            ln -s "$conf" "$sconf"
-        fi
-    else
-        echo "if (\$host != \"$redirect\") {" > $conf
-        echo "   return $code \$scheme://$redirect\$request_uri;" >> $conf
-        echo "}" >> $conf
-
-        if [ ! -e "$sconf" ]; then
-            ln -s "$conf" "$sconf"
-        fi
-    fi
+	if [ "$scheme" = 1 ]; then
+		echo "   return $code $redirect\$request_uri;" > $conf
+		if [ ! -e "$sconf" ]; then
+			ln -s "$conf" "$sconf"
+		fi
+	else
+		echo "if (\$host != \"$redirect\") {" > $conf
+		echo "   return $code \$scheme://$redirect\$request_uri;" >> $conf
+		echo "}" >> $conf
+
+		if [ ! -e "$sconf" ]; then
+			ln -s "$conf" "$sconf"
+		fi
+	fi
 else
-    echo "Non supported please use .htaccess instead"
-    exit 2;
+	echo "Non supported please use .htaccess instead"
+	exit 2
 fi
 
 #----------------------------------------------------------#
@@ -99,8 +99,8 @@ fi
 
 # Update object keys
 if [ -z "$REDIRECT" ]; then
-    add_object_key "web" 'DOMAIN' "$domain" 'REDIRECT' 'U_DISK'
-    add_object_key "web" 'DOMAIN' "$domain" 'REDIRECT_CODE' 'U_DISK'
+	add_object_key "web" 'DOMAIN' "$domain" 'REDIRECT' 'U_DISK'
+	add_object_key "web" 'DOMAIN' "$domain" 'REDIRECT_CODE' 'U_DISK'
 fi
 
 # Update values for domain
@@ -108,12 +108,12 @@ update_object_value 'web' 'DOMAIN' "$domain" '$REDIRECT' "$redirect"
 update_object_value 'web' 'DOMAIN' "$domain" '$REDIRECT_CODE' "$code"
 
 if [ "$restart" = "yes" ]; then
-    # Restarting web server
-    $BIN/v-restart-web "$restart"
-    check_result $? "Web restart failed" >/dev/null
+	# Restarting web server
+	$BIN/v-restart-web "$restart"
+	check_result $? "Web restart failed" > /dev/null
 
-    $BIN/v-restart-proxy "$restart"
-    check_result $? "Proxy restart failed" >/dev/null
+	$BIN/v-restart-proxy "$restart"
+	check_result $? "Proxy restart failed" > /dev/null
 fi
 
 # Logging

+ 15 - 15
bin/v-add-web-domain-ssl

@@ -68,15 +68,15 @@ cp -f $ssl_dir/$domain.crt $USER_DATA/ssl/$domain.crt
 cp -f $ssl_dir/$domain.key $USER_DATA/ssl/$domain.key
 cp -f $ssl_dir/$domain.crt $USER_DATA/ssl/$domain.pem
 if [ -e "$ssl_dir/$domain.ca" ]; then
-    cp -f $ssl_dir/$domain.ca $USER_DATA/ssl/$domain.ca
-    echo >> $USER_DATA/ssl/$domain.pem
-    cat $USER_DATA/ssl/$domain.ca >> $USER_DATA/ssl/$domain.pem
+	cp -f $ssl_dir/$domain.ca $USER_DATA/ssl/$domain.ca
+	echo >> $USER_DATA/ssl/$domain.pem
+	cat $USER_DATA/ssl/$domain.ca >> $USER_DATA/ssl/$domain.pem
 fi
 chmod 660 $USER_DATA/ssl/$domain.*
 
 # Ensure SSL directory exists
 if [ ! -d "$HOMEDIR/$user/conf/web/$domain/ssl" ]; then
-    mkdir -p $HOMEDIR/$user/conf/web/$domain/ssl/
+	mkdir -p $HOMEDIR/$user/conf/web/$domain/ssl/
 fi
 
 # Adding certificate to user dir
@@ -84,12 +84,12 @@ cp -f $USER_DATA/ssl/$domain.crt $HOMEDIR/$user/conf/web/$domain/ssl/$domain.crt
 cp -f $USER_DATA/ssl/$domain.key $HOMEDIR/$user/conf/web/$domain/ssl/$domain.key
 cp -f $USER_DATA/ssl/$domain.pem $HOMEDIR/$user/conf/web/$domain/ssl/$domain.pem
 if [ -e "$USER_DATA/ssl/$domain.ca" ]; then
-    cp -f $USER_DATA/ssl/$domain.ca $HOMEDIR/$user/conf/web/$domain/ssl/$domain.ca
+	cp -f $USER_DATA/ssl/$domain.ca $HOMEDIR/$user/conf/web/$domain/ssl/$domain.ca
 fi
 
 if [ "$SSL_FORCE" == "yes" ]; then
-    # Enabling SSL redirection on demand
-    $BIN/v-add-web-domain-ssl-force "$user" "$domain"
+	# Enabling SSL redirection on demand
+	$BIN/v-add-web-domain-ssl-force "$user" "$domain"
 fi
 # Parsing domain values
 get_domain_values 'web'
@@ -104,7 +104,7 @@ add_web_config "$WEB_SYSTEM" "$TPL.stpl"
 
 # Checking proxy config
 if [ -n "$PROXY_SYSTEM" ] && [ -n "$PROXY" ]; then
-    add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
+	add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
 fi
 
 #----------------------------------------------------------#
@@ -120,20 +120,20 @@ update_object_value 'web' 'DOMAIN' "$domain" '$SSL' "yes"
 
 # Restarting web server
 $BIN/v-restart-web "$restart"
-check_result $? "Web restart failed" >/dev/null
+check_result $? "Web restart failed" > /dev/null
 
 $BIN/v-restart-proxy "$restart"
-check_result $? "Proxy restart failed" >/dev/null
+check_result $? "Proxy restart failed" > /dev/null
 
 if [ -n "$UPDATE_HOSTNAME_SSL" ] && [ "$UPDATE_HOSTNAME_SSL" = "yes" ]; then
-    hostname=$(hostname -f)
-    if [ "$hostname" = "$domain" ]; then
-        $BIN/v-update-host-certificate "$user" "$domain"
-    fi
+	hostname=$(hostname -f)
+	if [ "$hostname" = "$domain" ]; then
+		$BIN/v-update-host-certificate "$user" "$domain"
+	fi
 fi
 
 if [ -n "$UPDATE_SSL_SCRIPT" ]; then
-    eval "$UPDATE_SSL_SCRIPT $user $domain"
+	eval "$UPDATE_SSL_SCRIPT $user $domain"
 fi
 
 # Logging

+ 10 - 11
bin/v-add-web-domain-ssl-force

@@ -16,7 +16,6 @@ domain=$2
 restart="$3"
 quiet="$4"
 
-
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
 source /etc/hestiacp/hestia.conf
@@ -48,23 +47,23 @@ parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
 
 # Check if SSL is enabled
 if [ "$SSL" != 'yes' ]; then
-    echo "Error: SSL is not enabled"
-    exit "$E_NOTEXIST"
+	echo "Error: SSL is not enabled"
+	exit "$E_NOTEXIST"
 fi
 
 # Check if proxy is active
-if [ -n  "$PROXY_SYSTEM" ]; then
-    forcessl="$HOMEDIR/$user/conf/web/$domain/$PROXY_SYSTEM.forcessl.conf"
+if [ -n "$PROXY_SYSTEM" ]; then
+	forcessl="$HOMEDIR/$user/conf/web/$domain/$PROXY_SYSTEM.forcessl.conf"
 else
-    forcessl="$HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.forcessl.conf"
+	forcessl="$HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.forcessl.conf"
 fi
 
 # Insert redirect commands
 if [ -n "$PROXY_SYSTEM" ] || [ "$WEB_SYSTEM" = 'nginx' ]; then
-    echo 'return 301 https://$host$request_uri;' > $forcessl
+	echo 'return 301 https://$host$request_uri;' > $forcessl
 else
-    echo 'RewriteEngine On' > $forcessl
-    echo 'RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]' >> $forcessl
+	echo 'RewriteEngine On' > $forcessl
+	echo 'RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]' >> $forcessl
 fi
 
 chown root:$user $forcessl
@@ -75,7 +74,7 @@ chmod 640 $forcessl
 #----------------------------------------------------------#
 
 if [ -z "$SSL_FORCE" ]; then
-    add_object_key "web" 'DOMAIN' "$domain" 'SSL_FORCE' 'SSL_HOME'
+	add_object_key "web" 'DOMAIN' "$domain" 'SSL_FORCE' 'SSL_HOME'
 fi
 
 # Set forcessl flag to enabled
@@ -91,7 +90,7 @@ check_result $? "Proxy restart failed" > /dev/null
 
 # Logging
 if [ "$quiet" != "yes" ]; then
-    $BIN/v-log-action "$user" "Info" "Web" "Automatic HTTPS redirection enabled (Domain: $domain)."
+	$BIN/v-log-action "$user" "Info" "Web" "Automatic HTTPS redirection enabled (Domain: $domain)."
 fi
 log_event "$OK" "$ARGUMENTS"
 

+ 6 - 6
bin/v-add-web-domain-ssl-hsts

@@ -45,15 +45,15 @@ parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
 
 # Check if SSL is enabled
 if [ "$SSL" != 'yes' ]; then
-    echo "Error: SSL is not enabled"
-    exit "$E_NOTEXIST"
+	echo "Error: SSL is not enabled"
+	exit "$E_NOTEXIST"
 fi
 
 # Check for Apache/Nginx or Nginx/PHP-FPM configuration
 if [ -z "$PROXY_SYSTEM" ]; then
-    hstsconf="$HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.hsts.conf"
+	hstsconf="$HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.hsts.conf"
 else
-    hstsconf="$HOMEDIR/$user/conf/web/$domain/$PROXY_SYSTEM.hsts.conf"
+	hstsconf="$HOMEDIR/$user/conf/web/$domain/$PROXY_SYSTEM.hsts.conf"
 fi
 
 echo 'add_header Strict-Transport-Security "max-age=15768000;" always;' > $hstsconf
@@ -66,7 +66,7 @@ chmod 640 $hstsconf
 #----------------------------------------------------------#
 
 if [ -z "$SSL_HSTS" ]; then
-    add_object_key "web" 'DOMAIN' "$domain" 'SSL_HSTS' 'SSL_FORCE'
+	add_object_key "web" 'DOMAIN' "$domain" 'SSL_HSTS' 'SSL_FORCE'
 fi
 
 # Set forcessl flag to enabled
@@ -82,7 +82,7 @@ check_result $? "Proxy restart failed" > /dev/null
 
 # Logging
 if [ "$quiet" != "yes" ]; then
-    $BIN/v-log-action "$user" "Info" "Web" "HTTP Strict Transport Security (HSTS) enabled (Domain: $domain)."
+	$BIN/v-log-action "$user" "Info" "Web" "HTTP Strict Transport Security (HSTS) enabled (Domain: $domain)."
 fi
 log_event "$OK" "$ARGUMENTS"
 

+ 6 - 6
bin/v-add-web-domain-ssl-preset

@@ -45,13 +45,13 @@ check_hestia_demo_mode
 # Load domain data
 parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
 
-if [  "$ssl" = "yes" ]; then
-    if [ -z "$SSL_FORCE" ]; then
-    add_object_key "web" 'DOMAIN' "$domain" 'SSL_FORCE' 'SSL_HOME'
-    fi
+if [ "$ssl" = "yes" ]; then
+	if [ -z "$SSL_FORCE" ]; then
+		add_object_key "web" 'DOMAIN' "$domain" 'SSL_FORCE' 'SSL_HOME'
+	fi
 
-    # Set forcessl flag to enabled
-    update_object_value 'web' 'DOMAIN' "$domain" '$SSL_FORCE' 'yes'
+	# Set forcessl flag to enabled
+	update_object_value 'web' 'DOMAIN' "$domain" '$SSL_FORCE' 'yes'
 fi
 
 # Logging

+ 22 - 23
bin/v-add-web-domain-stats

@@ -61,32 +61,32 @@ get_domain_values 'web'
 prepare_web_domain_values
 
 if [ -z "${aliases//,/ }" ]; then
-    stats_alias="localhost"
+	stats_alias="localhost"
 else
-    stats_alias=${aliases_idn//,/ }
+	stats_alias=${aliases_idn//,/ }
 fi
 
-cat $WEBTPL/$type/$type.tpl |\
-    sed -e "s|%ip%|$ip|g" \
-        -e "s|%web_port%|$WEB_PORT|g" \
-        -e "s|%web_system%|$WEB_SYSTEM|g" \
-        -e "s|%web_ssl_port%|$WEB_SSL_PORT|g" \
-        -e "s|%rgroups%|$WEB_RGROUPs|g" \
-        -e "s|%proxy_system%|$PROXY_SYSTEM|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%|$HOMEDIR|g" \
-        -e "s|%alias%|$stats_alias|g" \
-        -e "s|%alias_idn%|$stats_alias|g" \
-    > $HOMEDIR/$user/conf/web/$domain/$type.conf
+cat $WEBTPL/$type/$type.tpl \
+	| sed -e "s|%ip%|$ip|g" \
+		-e "s|%web_port%|$WEB_PORT|g" \
+		-e "s|%web_system%|$WEB_SYSTEM|g" \
+		-e "s|%web_ssl_port%|$WEB_SSL_PORT|g" \
+		-e "s|%rgroups%|$WEB_RGROUPs|g" \
+		-e "s|%proxy_system%|$PROXY_SYSTEM|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%|$HOMEDIR|g" \
+		-e "s|%alias%|$stats_alias|g" \
+		-e "s|%alias_idn%|$stats_alias|g" \
+		> $HOMEDIR/$user/conf/web/$domain/$type.conf
 
 if [ "$type" == 'awstats' ]; then
-    rm -f /etc/awstats/$type.$domain_idn.conf
-    ln -s $HOMEDIR/$user/conf/web/$domain/$type.conf \
-        /etc/awstats/$type.$domain_idn.conf
+	rm -f /etc/awstats/$type.$domain_idn.conf
+	ln -s $HOMEDIR/$user/conf/web/$domain/$type.conf \
+		/etc/awstats/$type.$domain_idn.conf
 fi
 
 #----------------------------------------------------------#
@@ -94,8 +94,7 @@ fi
 #----------------------------------------------------------#
 
 # Schedule statistic processing
-echo "$BIN/v-update-web-domain-stat $user $domain" >> \
-    $HESTIA/data/queue/webstats.pipe
+echo "$BIN/v-update-web-domain-stat $user $domain" >> $HESTIA/data/queue/webstats.pipe
 
 # Update config
 update_object_value 'web' 'DOMAIN' "$domain" '$STATS' "$type"

+ 10 - 9
bin/v-add-web-domain-stats-user

@@ -14,7 +14,8 @@
 user=$1
 domain=$2
 stats_user=$3
-password=$4; HIDE=4
+password=$4
+HIDE=4
 restart=$5
 
 # Includes
@@ -53,13 +54,13 @@ conf_dir="$HOMEDIR/$user/conf/web"
 
 # Adding htaccess file
 if [ "$WEB_SYSTEM" = 'nginx' ]; then
-    echo "auth_basic \"Web Statistics\";" > $stats_dir/auth.conf
-    echo "auth_basic_user_file $stats_dir/.htpasswd;" >> $stats_dir/auth.conf
+	echo "auth_basic \"Web Statistics\";" > $stats_dir/auth.conf
+	echo "auth_basic_user_file $stats_dir/.htpasswd;" >> $stats_dir/auth.conf
 else
-    echo "AuthUserFile $stats_dir/.htpasswd" > $stats_dir/.htaccess
-    echo "AuthName \"Web Statistics\"" >> $stats_dir/.htaccess
-    echo "AuthType Basic" >> $stats_dir/.htaccess
-    echo "Require valid-user" >> $stats_dir/.htaccess
+	echo "AuthUserFile $stats_dir/.htpasswd" > $stats_dir/.htaccess
+	echo "AuthName \"Web Statistics\"" >> $stats_dir/.htaccess
+	echo "AuthType Basic" >> $stats_dir/.htaccess
+	echo "Require valid-user" >> $stats_dir/.htaccess
 fi
 
 # Generating htaccess user and password
@@ -77,8 +78,8 @@ update_object_value 'web' 'DOMAIN' "$domain" '$STATS_CRYPT' "$stats_pass"
 
 # Restarting web server
 if [ "$WEB_SYSTEM" = 'nginx' ]; then
-    $BIN/v-restart-web "$restart"
-    check_result $? "Web restart failed" >/dev/null
+	$BIN/v-restart-web "$restart"
+	check_result $? "Web restart failed" > /dev/null
 fi
 
 # Logging

+ 38 - 38
bin/v-add-web-php

@@ -28,7 +28,7 @@ source_conf "$HESTIA/install/upgrade/upgrade.conf"
 check_args '1' "$#" 'VERSION'
 
 if [ -z "$WEB_BACKEND" ]; then
-    echo "Multiple php versions are not supported for modphp"
+	echo "Multiple php versions are not supported for modphp"
 fi
 
 # Set file locations
@@ -36,21 +36,21 @@ php_fpm="/etc/init.d/php$version-fpm"
 
 # Verify php version format
 if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
-    echo "The specified PHP version format is invalid, it should look like [0-9].[0-9]."
-    echo "Example: 7.0, 7.4, 8.0"
-    exit "$E_INVALID";
+	echo "The specified PHP version format is invalid, it should look like [0-9].[0-9]."
+	echo "Example: 7.0, 7.4, 8.0"
+	exit "$E_INVALID"
 fi
 
 # Check if php version already exists
 if [ -f "$php_fpm" ] && [ -f "$HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl" ]; then
-    echo "ERROR: Specified PHP version is already installed."
-    exit "$E_INVALID";
+	echo "ERROR: Specified PHP version is already installed."
+	exit "$E_INVALID"
 fi
 
 # Check if php version is supported
-if  [[ ! "$multiphp_v" =~ $version ]]; then
-    echo "ERROR: Specified PHP version is not supported or does not exist."
-    exit "$E_INVALID";
+if [[ ! "$multiphp_v" =~ $version ]]; then
+	echo "ERROR: Specified PHP version is not supported or does not exist."
+	exit "$E_INVALID";
 fi
 
 # Perform verification if read-only mode is enabled
@@ -66,30 +66,30 @@ mph="php$version-common php$version-mbstring php$version-bcmath php$version-cli
      php$version-pspell php$version-imagick php$version-pgsql php$version-imap php$version-ldap"
 
 # Check is version is 7.1 or below to add mcrypt
-if [[ `echo "$version 7.2" | awk '{print ($1 < $2)}'` == 1 ]]; then
-    mph="$mph php$version-mcrypt"
+if [[ $(echo "$version 7.2" | awk '{print ($1 < $2)}') == 1 ]]; then
+	mph="$mph php$version-mcrypt"
 fi
 
 # Check if version is 8.0 or higher and drop php json.
 if [[ ${version:0:1} == "8" ]]; then
-    mph=$(echo "$mph" | sed -e "s/php$version-json//")
+	mph=$(echo "$mph" | sed -e "s/php$version-json//")
 fi
 
-if ! echo "$DB_SYSTEM" | grep -w 'mysql' >/dev/null; then
-    mph=$(echo "$mph" | sed -e "s/php$version-mysql//")
+if ! echo "$DB_SYSTEM" | grep -w 'mysql' > /dev/null; then
+	mph=$(echo "$mph" | sed -e "s/php$version-mysql//")
 fi
 
-if ! echo "$DB_SYSTEM" | grep -w 'pgsql' >/dev/null; then
-    mph=$(echo "$mph" | sed -e "s/php$version-pgsql//")
+if ! echo "$DB_SYSTEM" | grep -w 'pgsql' > /dev/null; then
+	mph=$(echo "$mph" | sed -e "s/php$version-pgsql//")
 fi
 
 # Install php packages
 if [ -f '/etc/redhat-release' ]; then
-    dnf makecache -q
-    dnf install -q -y $mph > /dev/null 2>&1 &
+	dnf makecache -q
+	dnf install -q -y $mph > /dev/null 2>&1 &
 else
-    apt-get -qq update
-    apt-get -y -qq -o Dpkg::Options::="--force-confold" install $mph > /dev/null 2>&1 &
+	apt-get -qq update
+	apt-get -y -qq -o Dpkg::Options::="--force-confold" install $mph > /dev/null 2>&1 &
 fi
 BACK_PID=$!
 
@@ -97,9 +97,9 @@ BACK_PID=$!
 echo "Installing PHP-$version, please wait..."
 spinner="/-\|"
 spin_i=1
-while kill -0 $BACK_PID > /dev/null 2>&1 ; do
-    printf "\b${spinner:spin_i++%${#spinner}:1}"
-    sleep 0.5
+while kill -0 $BACK_PID > /dev/null 2>&1; do
+	printf "\b${spinner:spin_i++%${#spinner}:1}"
+	sleep 0.5
 done
 
 # Do a blank echo to get the \n back
@@ -107,28 +107,28 @@ echo
 
 # Check if installation was successful
 if [ ! -f "$php_fpm" ]; then
-    echo "ERROR: Installation failed, please run the following command manually for debugging:"
-    if [ -f '/etc/redhat-release' ]; then
-        echo "dnf install $mph"
-    else
-        echo "apt-get install $mph"
-    fi
+	echo "ERROR: Installation failed, please run the following command manually for debugging:"
+	if [ -f '/etc/redhat-release' ]; then
+		echo "dnf install $mph"
+	else
+		echo "apt-get install $mph"
+	fi
 fi
 
 # Check if required modules for apache2 are enabled
 if [ "$WEB_SYSTEM" = "apache2" ]; then
-    if ! a2query -q -m proxy_fcgi; then
-        a2enmod -q proxy_fcgi
-    fi
-    if ! a2query -q -m setenvif; then
-        a2enmod -q setenvif
-    fi
-    $BIN/v-restart-web "yes"
+	if ! a2query -q -m proxy_fcgi; then
+		a2enmod -q proxy_fcgi
+	fi
+	if ! a2query -q -m setenvif; then
+		a2enmod -q setenvif
+	fi
+	$BIN/v-restart-web "yes"
 fi
 
 # Configure fpm
 update-rc.d php$version-fpm defaults > /dev/null 2>&1
-v_tpl=${version//.}
+v_tpl=${version//./}
 rm -f /etc/php/$version/fpm/pool.d/*
 cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf /etc/php/$version/fpm/pool.d/
 sed -i "s/9999/99$v_tpl/g" /etc/php/$version/fpm/pool.d/dummy.conf
@@ -142,7 +142,7 @@ sed -i "s/max_execution_time = 30/max_execution_time = 60/g" /etc/php/$version/f
 
 # Install backend template
 cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl \
-    $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
+	$HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
 
 #----------------------------------------------------------#
 #                       Hestia                             #

Fișier diff suprimat deoarece este prea mare
+ 580 - 586
bin/v-backup-user


+ 16 - 16
bin/v-backup-users

@@ -29,24 +29,24 @@ check_hestia_demo_mode
 mysqlrepair --all-databases --check --auto-repair > /dev/null 2>&1
 
 if [ -z "$BACKUP_SYSTEM" ]; then
-    exit
+	exit
 fi
 for user in $($HESTIA/bin/v-list-sys-users plain); do
-    check_suspend=$(grep "SUSPENDED='no'" $HESTIA/data/users/$user/user.conf)
-    log=$HESTIA/log/backup.log
-    if [ ! -f "$HESTIA/data/users/$user/user.conf" ]; then
-        continue;
-    fi
-    check_backup_conditions
-    check_suspend=$(grep "SUSPENDED='no'" $HESTIA/data/users/$user/user.conf)
-    log=$HESTIA/log/backup.log
-    if [ -n "$check_suspend" ]; then
-        echo -e "================================" >> $log
-        echo -e "$user" >> $log
-        echo -e "--------------------------------\n" >> $log
-        nice -n 19 ionice -c2 -n7 $BIN/v-backup-user $user >> $log 2>&1
-        echo -e "\n--------------------------------\n\n" >> $log
-    fi
+	check_suspend=$(grep "SUSPENDED='no'" $HESTIA/data/users/$user/user.conf)
+	log=$HESTIA/log/backup.log
+	if [ ! -f "$HESTIA/data/users/$user/user.conf" ]; then
+		continue
+	fi
+	check_backup_conditions
+	check_suspend=$(grep "SUSPENDED='no'" $HESTIA/data/users/$user/user.conf)
+	log=$HESTIA/log/backup.log
+	if [ -n "$check_suspend" ]; then
+		echo -e "================================" >> $log
+		echo -e "$user" >> $log
+		echo -e "--------------------------------\n" >> $log
+		nice -n 19 ionice -c2 -n7 $BIN/v-backup-user $user >> $log 2>&1
+		echo -e "\n--------------------------------\n\n" >> $log
+	fi
 done
 
 #----------------------------------------------------------#

+ 3 - 3
bin/v-change-cron-job

@@ -50,8 +50,8 @@ check_hestia_demo_mode
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Concatenating cron string
 command=$(echo $command | sed -e "s/'/%quote%/g")
@@ -76,7 +76,7 @@ sync_cron_jobs
 
 # Restarting crond
 $BIN/v-restart-cron
-check_result $? "Cron restart failed" >/dev/null
+check_result $? "Cron restart failed" > /dev/null
 
 # Logging
 $BIN/v-log-action "$user" "Info" "Cron Jobs" "Cron job updated (Job: $job, Command: $command)."

+ 16 - 13
bin/v-change-database-host-password

@@ -14,7 +14,8 @@
 type=$1
 host=$2
 dbuser=$3
-password=$4; HIDE=4
+password=$4
+HIDE=4
 
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -44,21 +45,23 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 
 # Define email
-email=$(grep CONTACT $HESTIA/data/users/admin/user.conf |cut -f2 -d \')
+email=$(grep CONTACT $HESTIA/data/users/admin/user.conf | cut -f2 -d \')
 subj="v-change-database-host-password $*"
 
 case $type in
-    mysql)    mysql_connect "$host";
-              query="USE mysql; UPDATE user SET"
-              query="$query password=PASSWORD('$dbpass')"
-              query="$query WHERE User='$dbuser';"
-              query="$query FLUSH PRIVILEGES;"
-              mysql_query "$query" ;
-              if [ "$dbuser" == "root" ]; then
-                 echo -e "[client]\npassword='$dbpass'\n" > /root/.my.cnf
-                 chmod 600 /root/.my.cnf
-              fi;;
-    pgsql)    echo "TBD" >/dev/null;;
+	mysql)
+		mysql_connect "$host"
+		query="USE mysql; UPDATE user SET"
+		query="$query password=PASSWORD('$dbpass')"
+		query="$query WHERE User='$dbuser';"
+		query="$query FLUSH PRIVILEGES;"
+		mysql_query "$query"
+		if [ "$dbuser" == "root" ]; then
+			echo -e "[client]\npassword='$dbpass'\n" > /root/.my.cnf
+			chmod 600 /root/.my.cnf
+		fi
+		;;
+	pgsql) echo "TBD" > /dev/null ;;
 esac
 
 update_object_value "../../conf/$type" 'HOST' "$host" '$USER' "$dbuser"

+ 16 - 17
bin/v-change-database-owner

@@ -14,7 +14,6 @@
 database=$1
 user=$2
 
-
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
 source /etc/hestiacp/hestia.conf
@@ -40,39 +39,39 @@ is_object_unsuspended 'user' 'USER' "$user"
 # Check owner existance
 owner=$(echo $database | cut -f 1 -d '_')
 if [ ! -d "$HESTIA/data/users/$owner" ]; then
-    echo "Error: database owner doesn't exist"
-    log_event "$E_NOTEXIST" "$ARGUMENTS"
-    exit "$E_NOTEXIST"
+	echo "Error: database owner doesn't exist"
+	log_event "$E_NOTEXIST" "$ARGUMENTS"
+	exit "$E_NOTEXIST"
 fi
 
 # Check if owner is the same as the dst user
 if [ "$owner" = "$user" ]; then
-    exit
+	exit
 fi
 
 # Check db existance
 db_data=$(grep "DB='$database'" $HESTIA/data/users/$owner/db.conf)
 if [ -z "$db_data" ]; then
-    echo "Error: database $database doesn't exist"
-    log_event "$E_NOTEXIST" "$ARGUMENTS"
-    exit "$E_NOTEXIST"
+	echo "Error: database $database doesn't exist"
+	log_event "$E_NOTEXIST" "$ARGUMENTS"
+	exit "$E_NOTEXIST"
 fi
 
 parse_object_kv_list "$db_data"
 #Fix issue #1084 with "Upper case not allowed with PGSQL"
 if [ "$TYPE" == "pgsql" ]; then
-   usersmall=$(echo "$user" | tr '[:upper:]' '[:lower:]');
+	usersmall=$(echo "$user" | tr '[:upper:]' '[:lower:]')
 else
-   usersmall=$user
+	usersmall=$user
 fi
 
 # Check if database name is uniqe
 new_db=$(echo $database | sed "s/^${owner}_/${usersmall}_/")
 check_db=$(grep "DB='$new_db'" $HESTIA/data/users/$user/db.conf)
 if [ -n "$check_db" ]; then
-    echo "Error: $new_db database exists"
-    log_event "$E_EXISTS" "$ARGUMENTS"
-    exit "$E_EXISTS"
+	echo "Error: $new_db database exists"
+	log_event "$E_EXISTS" "$ARGUMENTS"
+	exit "$E_EXISTS"
 fi
 
 # Perform verification if read-only mode is enabled
@@ -92,8 +91,8 @@ $BIN/v-suspend-database $owner $database > /dev/null 2>&1
 dump="$tmpdir/$database.$TYPE.sql"
 grants="$tmpdir/$database.$TYPE.$DBUSER"
 case $TYPE in
-    mysql) dump_mysql_database ;;
-    pgsql) dump_pgsql_database ;;
+	mysql) dump_mysql_database ;;
+	pgsql) dump_pgsql_database ;;
 esac
 
 # Import configuration
@@ -109,8 +108,8 @@ $BIN/v-rebuild-databases "$user"
 
 # Import dump
 case $TYPE in
-    mysql) import_mysql_database "$dump" ;;
-    pgsql) import_pgsql_database "$dump" ;;
+	mysql) import_mysql_database "$dump" ;;
+	pgsql) import_pgsql_database "$dump" ;;
 esac
 
 # Deleting tmpdir

+ 4 - 3
bin/v-change-database-password

@@ -14,7 +14,8 @@
 # Argument definition
 user=$1
 database=$2
-password=$3; HIDE=3
+password=$3
+HIDE=3
 
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -50,8 +51,8 @@ check_hestia_demo_mode
 get_database_values
 
 case $TYPE in
-    mysql) change_mysql_password ;;
-    pgsql) change_pgsql_password ;;
+	mysql) change_mysql_password ;;
+	pgsql) change_pgsql_password ;;
 esac
 
 #----------------------------------------------------------#

+ 20 - 19
bin/v-change-database-user

@@ -14,7 +14,8 @@
 user=$1
 database=$2
 dbuser="$user"_"$3"
-password=$4; HIDE=4
+password=$4
+HIDE=4
 
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -52,7 +53,7 @@ check_hestia_demo_mode
 # Compare old and new user
 old_dbuser=$(get_object_value 'db' 'DB' "$database" '$DBUSER')
 if [ "$old_dbuser" = "$dbuser" ]; then
-    exit
+	exit
 fi
 
 # Set new dbuser
@@ -63,37 +64,37 @@ get_database_values
 
 #Fix issue #1084 with "Upper case not allowed with PGSQL"
 if [ "$TYPE" = "pgsql" ]; then
-   dbuser=$(echo $dbuser | tr '[:upper:]' '[:lower:]');
-   exclude="-"
-    if [[ "$dbuser" =~ $exclude ]]; then
-        check_result "$E_INVALID" "invalid database user format"
-    fi
+	dbuser=$(echo $dbuser | tr '[:upper:]' '[:lower:]')
+	exclude="-"
+	if [[ "$dbuser" =~ $exclude ]]; then
+		check_result "$E_INVALID" "invalid database user format"
+	fi
 fi
 
 # Rebuild database
 case $TYPE in
-    mysql) rebuild_mysql_database ;;
-    pgsql) rebuild_pgsql_database ;;
+	mysql) rebuild_mysql_database ;;
+	pgsql) rebuild_pgsql_database ;;
 esac
 
 # Change password
 if [ -n "$dbpass" ]; then
-    case $TYPE in
-        mysql) change_mysql_password ;;
-        pgsql) change_pgsql_password ;;
-    esac
+	case $TYPE in
+		mysql) change_mysql_password ;;
+		pgsql) change_pgsql_password ;;
+	esac
 
-    # Update config value
-    update_object_value 'db' 'DB' "$database" '$MD5' "$md5"
+	# Update config value
+	update_object_value 'db' 'DB' "$database" '$MD5' "$md5"
 fi
 
 # Remove old user
 check_old_dbuser=$(grep "DBUSER='$old_dbuser'" $USER_DATA/db.conf)
 if [ -z "$check_old_dbuser" ]; then
-    case $TYPE in
-        mysql) delete_mysql_user ;;
-        pgsql) delete_pgsql_user ;;
-    esac
+	case $TYPE in
+		mysql) delete_mysql_user ;;
+		pgsql) delete_pgsql_user ;;
+	esac
 fi
 
 #----------------------------------------------------------#

+ 14 - 14
bin/v-change-dns-domain-dnssec

@@ -45,7 +45,7 @@ is_object_valid 'dns' 'DOMAIN' "$domain"
 is_object_unsuspended 'dns' 'DOMAIN' "$domain"
 
 if [ -n "$status" ]; then
-    is_boolean_format_valid "$status" 'status'
+	is_boolean_format_valid "$status" 'status'
 fi
 
 # Perform verification if read-only mode is enabled
@@ -56,7 +56,7 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 
 if [ -f "$HESTIA/data/queue/dns-cluster.pipe" ]; then
-    bash $HESTIA/data/queue/dns-cluster.pipe
+	bash $HESTIA/data/queue/dns-cluster.pipe
 fi
 
 syshealth_repair_dns_config
@@ -69,21 +69,21 @@ update_object_value 'dns' 'DOMAIN' "$domain" '$DNSSEC' "$status"
 rebuild_dns_domain_conf
 
 if [ $status = "no" ]; then
-    update_object_value 'dns' 'DOMAIN' "$domain" '$KEY' ""
-    # Delete existing keys
-    rm -fr  $HOMEDIR/$user/conf/dns/$domain.db.*
-    rm -fr /var/cache/bind/K$domain_idn.*
-    rm -fr $USER_DATA/keys/K$domain_idn.*
+	update_object_value 'dns' 'DOMAIN' "$domain" '$KEY' ""
+	# Delete existing keys
+	rm -fr $HOMEDIR/$user/conf/dns/$domain.db.*
+	rm -fr /var/cache/bind/K$domain_idn.*
+	rm -fr $USER_DATA/keys/K$domain_idn.*
 fi
 
 # Updating dns-cluster queue
-if [ "$DNS_CLUSTER"  = "yes" ]; then
-    # Check for first sync
-    dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
-    if [ -z "$dlock" ]; then
-        cmd="$BIN/v-add-remote-dns-domain $user $domain yes"
-        echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
-    fi
+if [ "$DNS_CLUSTER" = "yes" ]; then
+	# Check for first sync
+	dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
+	if [ -z "$dlock" ]; then
+		cmd="$BIN/v-add-remote-dns-domain $user $domain yes"
+		echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
+	fi
 fi
 
 #----------------------------------------------------------#

+ 7 - 7
bin/v-change-dns-domain-exp

@@ -53,13 +53,13 @@ check_hestia_demo_mode
 update_object_value 'dns' 'DOMAIN' "$domain" '$EXP' "$exp"
 
 # Updating dns-cluster queue
-if [ "$DNS_CLUSTER"  = "yes" ]; then
-    # Check for first sync
-    dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
-    if [ -z "$dlock" ]; then
-        cmd="$BIN/v-change-remote-dns-domain-exp $user $domain $exp"
-        echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
-    fi
+if [ "$DNS_CLUSTER" = "yes" ]; then
+	# Check for first sync
+	dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
+	if [ -z "$dlock" ]; then
+		cmd="$BIN/v-change-remote-dns-domain-exp $user $domain $exp"
+		echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
+	fi
 fi
 
 #----------------------------------------------------------#

+ 9 - 9
bin/v-change-dns-domain-ip

@@ -65,17 +65,17 @@ sed -i "s/$old/$ip/g" $USER_DATA/dns/$domain.conf
 
 # Updating zone
 if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
-    rebuild_dns_domain_conf
+	rebuild_dns_domain_conf
 fi
 
 # Updating dns-cluster queue
-if [ "$DNS_CLUSTER"  = "yes" ]; then
-    # Check for first sync
-    dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
-    if [ -z "$dlock" ]; then
-        cmd="$BIN/v-add-remote-dns-domain $user $domain domain yes"
-        echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
-    fi
+if [ "$DNS_CLUSTER" = "yes" ]; then
+	# Check for first sync
+	dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
+	if [ -z "$dlock" ]; then
+		cmd="$BIN/v-add-remote-dns-domain $user $domain domain yes"
+		echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
+	fi
 fi
 
 #----------------------------------------------------------#
@@ -84,7 +84,7 @@ fi
 
 # Restarting named
 $BIN/v-restart-dns "$restart"
-check_result $? "DNS restart failed" >/dev/null
+check_result $? "DNS restart failed" > /dev/null
 
 # Logging
 $BIN/v-log-action "$user" "Info" "DNS" "IP address for DNS domain changed (IP: $ip, Domain: $domain)."

+ 9 - 9
bin/v-change-dns-domain-soa

@@ -59,17 +59,17 @@ update_object_value 'dns' 'DOMAIN' "$domain" '$SOA' "$soa"
 
 # Updating zone
 if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
-    rebuild_dns_domain_conf
+	rebuild_dns_domain_conf
 fi
 
 # Updating dns-cluster queue
-if [ "$DNS_CLUSTER"  = "yes" ]; then
-    # Check for first sync
-    dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
-    if [ -z "$dlock" ]; then
-        cmd="$BIN/v-change-remote-dns-domain-soa $user $domain $soa"
-        echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
-    fi
+if [ "$DNS_CLUSTER" = "yes" ]; then
+	# Check for first sync
+	dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
+	if [ -z "$dlock" ]; then
+		cmd="$BIN/v-change-remote-dns-domain-soa $user $domain $soa"
+		echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
+	fi
 fi
 
 #----------------------------------------------------------#
@@ -78,7 +78,7 @@ fi
 
 # Restarting named
 $BIN/v-restart-dns "$restart"
-check_result $? "DNS restart failed" >/dev/null
+check_result $? "DNS restart failed" > /dev/null
 
 # Logging
 $BIN/v-log-action "$user" "Info" "DNS" "SOA record for DNS domain changed (SOA: $soa, Domain: $domain)."

+ 52 - 52
bin/v-change-dns-domain-tpl

@@ -59,9 +59,9 @@ check_hestia_demo_mode
 get_domain_values 'dns'
 i=1
 ns=$(get_user_value '$NS')
-for nameserver in ${ns//,/ };do
-    eval ns$i=$nameserver
-    (( ++i))
+for nameserver in ${ns//,/ }; do
+	eval ns$i=$nameserver
+	((++i))
 done
 
 # Reading template
@@ -69,81 +69,81 @@ template_data=$(cat "$DNSTPL/$template.tpl")
 
 # Deleting unused nameservers
 if [ -z "$ns3" ]; then
-    template_data=$(echo "$template_data" |grep -v %ns3%)
+	template_data=$(echo "$template_data" | grep -v %ns3%)
 fi
 if [ -z "$ns4" ]; then
-    template_data=$(echo "$template_data" |grep -v %ns4%)
+	template_data=$(echo "$template_data" | grep -v %ns4%)
 fi
 if [ -z "$ns5" ]; then
-    template_data=$(echo "$template_data" |grep -v %ns5%)
+	template_data=$(echo "$template_data" | grep -v %ns5%)
 fi
 if [ -z "$ns6" ]; then
-    template_data=$(echo "$template_data" |grep -v %ns6%)
+	template_data=$(echo "$template_data" | grep -v %ns6%)
 fi
 if [ -z "$ns7" ]; then
-    template_data=$(echo "$template_data" |grep -v %ns7%)
+	template_data=$(echo "$template_data" | grep -v %ns7%)
 fi
 if [ -z "$ns8" ]; then
-    template_data=$(echo "$template_data" |grep -v %ns8%)
+	template_data=$(echo "$template_data" | grep -v %ns8%)
 fi
 
 # Changing tpl
-echo "$template_data" |\
-    sed -e "s/%ip%/$IP/g" \
-        -e "s/%domain_idn%/$domain_idn/g" \
-        -e "s/%domain%/$domain/g" \
-        -e "s/%ns1%/$ns1/g" \
-        -e "s/%ns2%/$ns2/g" \
-        -e "s/%ns3%/$ns3/g" \
-        -e "s/%ns4%/$ns4/g" \
-        -e "s/%ns5%/$ns5/g" \
-        -e "s/%ns6%/$ns6/g" \
-        -e "s/%ns7%/$ns7/g" \
-        -e "s/%ns8%/$ns8/g" \
-        -e "s/%time%/$TIME/g" \
-        -e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf
-records="$(wc -l $USER_DATA/dns/$domain.conf |cut -f 1 -d ' ')"
+echo "$template_data" \
+	| sed -e "s/%ip%/$IP/g" \
+		-e "s/%domain_idn%/$domain_idn/g" \
+		-e "s/%domain%/$domain/g" \
+		-e "s/%ns1%/$ns1/g" \
+		-e "s/%ns2%/$ns2/g" \
+		-e "s/%ns3%/$ns3/g" \
+		-e "s/%ns4%/$ns4/g" \
+		-e "s/%ns5%/$ns5/g" \
+		-e "s/%ns6%/$ns6/g" \
+		-e "s/%ns7%/$ns7/g" \
+		-e "s/%ns8%/$ns8/g" \
+		-e "s/%time%/$TIME/g" \
+		-e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf
+records="$(wc -l $USER_DATA/dns/$domain.conf | cut -f 1 -d ' ')"
 
 # Refresh DKIM records in DNS if signing key exists for domain
 if [ "$template" = "default" ] || [ "$template" = "child-ns" ]; then
-    if [ -n "$MAIL_SYSTEM" ] && [ -f "$HOMEDIR/$user/conf/mail/$domain/dkim.pem" ]; then
-        check_dns_domain=$(is_object_valid 'dns' 'DOMAIN' "$domain")
-        if [ "$?" -eq 0 ]; then
-            p=$(cat "$USER_DATA/mail/$domain.pub" |grep -v ' KEY---'|tr -d '\n')
-            record='_domainkey'
-            policy="\"t=y; o=~;\""
-            $BIN/v-add-dns-record "$user" "$domain" "$record" TXT "$policy" '' '' 'no'
-
-            record='mail._domainkey'
-            selector="\"v=DKIM1\; k=rsa\; p=$p\""
-            $BIN/v-add-dns-record "$user" "$domain" "$record" TXT "$selector"
-        fi
-    fi
+	if [ -n "$MAIL_SYSTEM" ] && [ -f "$HOMEDIR/$user/conf/mail/$domain/dkim.pem" ]; then
+		check_dns_domain=$(is_object_valid 'dns' 'DOMAIN' "$domain")
+		if [ "$?" -eq 0 ]; then
+			p=$(cat "$USER_DATA/mail/$domain.pub" | grep -v ' KEY---' | tr -d '\n')
+			record='_domainkey'
+			policy="\"t=y; o=~;\""
+			$BIN/v-add-dns-record "$user" "$domain" "$record" TXT "$policy" '' '' 'no'
+
+			record='mail._domainkey'
+			selector="\"v=DKIM1\; k=rsa\; p=$p\""
+			$BIN/v-add-dns-record "$user" "$domain" "$record" TXT "$selector"
+		fi
+	fi
 fi
 
 # Set correct domain name formatting for Office 365/Microsoft 365 MX records
 if [ "$template" = "office365" ]; then
-    check_dns_domain=$(is_object_valid 'dns' 'DOMAIN' "$domain")
-    if [ "$?" -eq 0 ]; then
-        record='@'
-        formatted_domain=$(echo "$domain" | sed 's/\./-/g')
-        $BIN/v-add-dns-record "$user" "$domain" "$record" MX "${formatted_domain}.mail.protection.outlook.com." '0' '' "$restart"
-    fi
+	check_dns_domain=$(is_object_valid 'dns' 'DOMAIN' "$domain")
+	if [ "$?" -eq 0 ]; then
+		record='@'
+		formatted_domain=$(echo "$domain" | sed 's/\./-/g')
+		$BIN/v-add-dns-record "$user" "$domain" "$record" MX "${formatted_domain}.mail.protection.outlook.com." '0' '' "$restart"
+	fi
 fi
 
 # Updating zone
 if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
-    rebuild_dns_domain_conf
+	rebuild_dns_domain_conf
 fi
 
 # Updating dns-cluster queue
-if [ "$DNS_CLUSTER"  = "yes" ]; then
-    # Check for first sync
-    dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
-    if [ -z "$dlock" ]; then
-        cmd="$BIN/v-add-remote-dns-domain $user $domain domain"
-        echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
-    fi
+if [ "$DNS_CLUSTER" = "yes" ]; then
+	# Check for first sync
+	dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
+	if [ -z "$dlock" ]; then
+		cmd="$BIN/v-add-remote-dns-domain $user $domain domain"
+		echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
+	fi
 fi
 
 #----------------------------------------------------------#
@@ -161,7 +161,7 @@ $BIN/v-update-user-counters "$user"
 
 # Restarting named
 $BIN/v-restart-dns "$restart"
-check_result $? "DNS restart failed" >/dev/null
+check_result $? "DNS restart failed" > /dev/null
 
 # Logging
 $BIN/v-log-action "system" "Info" "DNS" "Template for DNS domain changed (Template: $template, Domain: $domain)."

+ 9 - 9
bin/v-change-dns-domain-ttl

@@ -58,17 +58,17 @@ update_object_value 'dns' 'DOMAIN' "$domain" '$TTL' "$ttl"
 
 # Updating zone
 if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
-    rebuild_dns_domain_conf
+	rebuild_dns_domain_conf
 fi
 
 # Updating dns-cluster queue
-if [ "$DNS_CLUSTER"  = "yes" ]; then
-    # Check for first sync
-    dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
-    if [ -z "$dlock" ]; then
-        cmd="$BIN/v-change-remote-dns-domain-ttl $user $domain $ttl"
-        echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
-    fi
+if [ "$DNS_CLUSTER" = "yes" ]; then
+	# Check for first sync
+	dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
+	if [ -z "$dlock" ]; then
+		cmd="$BIN/v-change-remote-dns-domain-ttl $user $domain $ttl"
+		echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
+	fi
 fi
 
 #----------------------------------------------------------#
@@ -77,7 +77,7 @@ fi
 
 # Restarting named
 $BIN/v-restart-dns "$restart"
-check_result $? "DNS restart failed" >/dev/null
+check_result $? "DNS restart failed" > /dev/null
 
 # Logging
 $BIN/v-log-action "$user" "Info" "DNS" "TTL for DNS domain changed (TTL: $ttl, Domain: $domain)."

+ 28 - 29
bin/v-change-dns-record

@@ -61,7 +61,7 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 
 if [ "$record" = "@" ] && [ "$rtype" = "CNAME" ]; then
-    check_result $E_INVALID "CNAME on root is not allowed"
+	check_result $E_INVALID "CNAME on root is not allowed"
 fi
 
 # Make sure the variable for the optional parameter TTL is empty before parsing
@@ -73,40 +73,39 @@ line=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf)
 parse_object_kv_list "$line"
 
 if [ -z "$rtype" ]; then
-    rtype=$TYPE
+	rtype=$TYPE
 fi
 
 if [ -z "$priority" ]; then
-    priority=$PRIORITY
+	priority=$PRIORITY
 fi
 
 # Null priority for none MX/SRV records
 if [ "$rtype" != 'MX' ] && [ "$rtype" != 'SRV' ]; then
-    priority=''
+	priority=''
 fi
 
 # Add trailing dot at the end of NS/CNAME/MX/PTR/SRV record
 if [[ $rtype =~ NS|CNAME|MX|PTR|SRV ]]; then
-    trailing_dot=$(echo "$dvalue" | grep "\.$")
-    if [ -z "$trailing_dot" ]; then
-        dvalue="$dvalue."
-    fi
+	trailing_dot=$(echo "$dvalue" | grep "\.$")
+	if [ -z "$trailing_dot" ]; then
+		dvalue="$dvalue."
+	fi
 fi
 
 if [[ $rtype =~ NS|CNAME|MX|PTR|SRV ]]; then
-    dvalue=$(idn2  --quiet  "$dvalue" )
-    record=$(idn2  --quiet  "$record" )
+	dvalue=$(idn2 --quiet "$dvalue")
+	record=$(idn2 --quiet "$record")
 fi
 
 if [ "$rtype" != "CAA" ]; then
-    dvalue=${dvalue//\"/}
+	dvalue=${dvalue//\"/}
 
-    if [ "$rtype" != 'SRV' ] && [[ "$dvalue" =~ [\;[:space:]] ]]; then
-        dvalue='"'"$dvalue"'"'
-    fi
+	if [ "$rtype" != 'SRV' ] && [[ "$dvalue" =~ [\;[:space:]] ]]; then
+		dvalue='"'"$dvalue"'"'
+	fi
 fi
 
-
 #RTYPE wasn't checked make sure to do it now correctly
 is_format_valid 'user' 'domain' 'id' 'record' 'rtype' 'dvalue'
 
@@ -115,15 +114,15 @@ is_dns_fqnd "$TYPE" "$dvalue"
 is_dns_nameserver_valid "$domain" "$TYPE" "$dvalue"
 
 if [[ "$RECORD" == "$record" ]] && [[ "$TYPE" == "$rtype" ]] && [[ "$PRIORITY" -eq "$priority" ]] \
-        && [[ "$VALUE" == "$dvalue" ]] && [[ "$SUSPENDED" == 'no' ]] && [[ "$TTL" -eq "$ttl" ]]; then
-    echo "No pending changes in DNS entry."
-    exit "$E_EXISTS"
+	&& [[ "$VALUE" == "$dvalue" ]] && [[ "$SUSPENDED" == 'no' ]] && [[ "$TTL" -eq "$ttl" ]]; then
+	echo "No pending changes in DNS entry."
+	exit "$E_EXISTS"
 fi
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Adding record
 dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
@@ -139,17 +138,17 @@ sort_dns_records
 
 # Updating zone
 if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
-    rebuild_dns_domain_conf
+	rebuild_dns_domain_conf
 fi
 
 # Updating dns-cluster queue
-if [ "$DNS_CLUSTER"  = "yes" ]; then
-    # Check for first sync
-    dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
-    if [ -z "$dlock" ]; then
-        cmd="$BIN/v-add-remote-dns-domain $user $domain records"
-        echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
-    fi
+if [ "$DNS_CLUSTER" = "yes" ]; then
+	# Check for first sync
+	dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
+	if [ -z "$dlock" ]; then
+		cmd="$BIN/v-add-remote-dns-domain $user $domain records"
+		echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
+	fi
 fi
 
 #----------------------------------------------------------#
@@ -158,7 +157,7 @@ fi
 
 # Restarting named
 $BIN/v-restart-dns "$restart"
-check_result $? "DNS restart failed" >/dev/null
+check_result $? "DNS restart failed" > /dev/null
 
 # Logging
 $BIN/v-log-action "$user" "Info" "DNS" "DNS record value changed (Type: $rtype, Record: $record, Value: $dvalue, Domain: $domain)."

+ 9 - 9
bin/v-change-dns-record-id

@@ -64,17 +64,17 @@ sort_dns_records
 
 # Updating zone
 if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
-    rebuild_dns_domain_conf
+	rebuild_dns_domain_conf
 fi
 
 # Updating dns-cluster queue
-if [ "$DNS_CLUSTER"  = "yes" ]; then
-    # Check for first sync
-    dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
-    if [ -z "$dlock" ]; then
-        cmd="$BIN/v-add-remote-dns-domain $user $domain records"
-        echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
-    fi
+if [ "$DNS_CLUSTER" = "yes" ]; then
+	# Check for first sync
+	dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
+	if [ -z "$dlock" ]; then
+		cmd="$BIN/v-add-remote-dns-domain $user $domain records"
+		echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
+	fi
 fi
 
 #----------------------------------------------------------#
@@ -83,7 +83,7 @@ fi
 
 # Restarting named
 $BIN/v-restart-dns "$restart"
-check_result $? "DNS restart failed" >/dev/null
+check_result $? "DNS restart failed" > /dev/null
 
 # Logging
 log_event "$OK" "$ARGUMENTS"

+ 231 - 231
bin/v-change-domain-owner

@@ -34,11 +34,11 @@ is_object_valid 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
 owner=$($BIN/v-search-domain-owner "$domain")
 if [ -z "$owner" ]; then
-    check_result "$E_NOTEXIST" "domain $domain doesn't exist"
+	check_result "$E_NOTEXIST" "domain $domain doesn't exist"
 fi
 if [ "$owner" = "$user" ]; then
-    echo "ERROR: $domain is already owned by $user."
-    exit
+	echo "ERROR: $domain is already owned by $user."
+	exit
 fi
 
 # Perform verification if read-only mode is enabled
@@ -53,234 +53,234 @@ echo "Moving $domain from $owner to $user, please wait..."
 # WEB domain
 web_data=$(grep "DOMAIN='$domain'" $HESTIA/data/users/$owner/web.conf)
 if [ -n "$web_data" ]; then
-    echo "[*] Moving web domain..."
-    $BIN/v-suspend-web-domain "$owner" "$domain" >> /dev/null 2>&1
-    parse_object_kv_list "$web_data"
-
-    if [ -n "$CUSTOM_DOCROOT" ]; then
-        if [ -z $(echo $CUSTOM_DOCROOT | grep -i "/home/$owner/web/$domain") ]; then
-            docdomain=$(echo "$CUSTOM_DOCROOT" | cut -d'/' -f5)
-            $BIN/v-list-web-domain $user $docdomain > /dev/null
-            if [ "$?" != 0 ]; then
-                echo "Error: Target domain doesn't belong to the new user";
-                exit $E_NOTEXIST;
-            fi
-            new_docroot=$(echo $CUSTOM_DOCROOT | sed "s/\/home\/$owner/\/home\/$user/");
-            new_php_docroot=$(echo $CUSTOM_PHPROOT | sed "s/\/home\/$owner/\/home\/$user/");
-
-        else
-            new_docroot=$(echo $CUSTOM_DOCROOT | sed "s/\/home\/$owner/\/home\/$user/");
-            new_php_docroot=$(echo $CUSTOM_PHPROOT | sed "s/\/home\/$owner/\/home\/$user/");
-        fi
-    fi
-
-    if [ -z "$(echo $(get_user_ips) | grep $IP)" ]; then
-        echo "[*] IP dedicated to $owner select new ip adress..."
-        get_user_ip
-    fi
-    old_ip=$IP;
-    new_ip=$ip;
-    echo $ip;
-
-    # Change IP
-    if [ -n "$ip" ]; then
-        web_data=$(echo "$web_data" | sed "s/IP='$IP'/IP='$ip'/")
-    fi
-    if [ -n "$new_docroot" ]; then
-        web_data=$(echo "$web_data" | sed "s|CUSTOM_DOCROOT='$CUSTOM_DOCROOT'|CUSTOM_DOCROOT='$new_docroot'|")
-        web_data=$(echo "$web_data" | sed "s|CUSTOM_PHPROOT='$CUSTOM_PHPROOT'|CUSTOM_PHPROOT='$new_php_docroot'|")
-    fi
-    web_data=$(echo "$web_data" | sed "s/SUSPENDED='no'/SUSPENDED='yes'/")
-
-    # Check SSL
-    if [ "$SSL" = 'yes' ]; then
-        ssl_crt=$HESTIA/data/users/$owner/ssl/$domain.crt
-        ssl_key=$HESTIA/data/users/$owner/ssl/$domain.key
-        ssl_ca=$HESTIA/data/users/$owner/ssl/$domain.ca
-        ssl_pem=$HESTIA/data/users/$owner/ssl/$domain.pem
-        mv $ssl_crt $HESTIA/data/users/$user/ssl/
-        mv $ssl_key $HESTIA/data/users/$user/ssl/
-        mv $ssl_ca $HESTIA/data/users/$user/ssl/ >> /dev/null 2>&1
-        mv $ssl_pem $HESTIA/data/users/$user/ssl/ >> /dev/null 2>&1
-        rm -f $HOMEDIR/$owner/conf/web/ssl.$domain.*
-    fi
-
-    # Check ftp user account
-    if [ -n "$FTP_USER" ]; then
-        /usr/sbin/userdel -f  "$FTP_USER" >> /dev/null 2>&1
-        old_str="FTP_USER='$FTP_USER'"
-        new_str=$(echo "$old_str" | sed "s/${owner}_/${user}_/")
-        web_data=$(echo "$web_data" | sed "s/$old_str/$new_str/")
-    fi
-
-    # Move config
-    sed -i "/DOMAIN='$domain'/d" $HESTIA/data/users/$owner/web.conf
-    echo "$web_data" >> $HESTIA/data/users/$user/web.conf
-
-    # Move data
-    mv $HOMEDIR/$owner/web/$domain $HOMEDIR/$user/web/
-
-    # Change ownership
-    find "$HOMEDIR/$user/web/$domain" -user "$owner" \
-        -exec chown -h $user:$user {} \;
-
-    # Rebuild config
-    $BIN/v-unsuspend-web-domain "$user" "$domain" no >> /dev/null 2>&1
-    $BIN/v-rebuild-web-domains "$owner" no
-    $BIN/v-rebuild-web-domains "$user"
-
-    # Cleanup old config
-    rm -rf "$HOMEDIR/$owner/conf/web/$domain/"
+	echo "[*] Moving web domain..."
+	$BIN/v-suspend-web-domain "$owner" "$domain" >> /dev/null 2>&1
+	parse_object_kv_list "$web_data"
+
+	if [ -n "$CUSTOM_DOCROOT" ]; then
+		if [ -z $(echo $CUSTOM_DOCROOT | grep -i "/home/$owner/web/$domain") ]; then
+			docdomain=$(echo "$CUSTOM_DOCROOT" | cut -d'/' -f5)
+			$BIN/v-list-web-domain $user $docdomain > /dev/null
+			if [ "$?" != 0 ]; then
+				echo "Error: Target domain doesn't belong to the new user"
+				exit $E_NOTEXIST
+			fi
+			new_docroot=$(echo $CUSTOM_DOCROOT | sed "s/\/home\/$owner/\/home\/$user/")
+			new_php_docroot=$(echo $CUSTOM_PHPROOT | sed "s/\/home\/$owner/\/home\/$user/")
+
+		else
+			new_docroot=$(echo $CUSTOM_DOCROOT | sed "s/\/home\/$owner/\/home\/$user/")
+			new_php_docroot=$(echo $CUSTOM_PHPROOT | sed "s/\/home\/$owner/\/home\/$user/")
+		fi
+	fi
+
+	if [ -z "$(echo $(get_user_ips) | grep $IP)" ]; then
+		echo "[*] IP dedicated to $owner select new ip adress..."
+		get_user_ip
+	fi
+	old_ip=$IP
+	new_ip=$ip
+	echo $ip
+
+	# Change IP
+	if [ -n "$ip" ]; then
+		web_data=$(echo "$web_data" | sed "s/IP='$IP'/IP='$ip'/")
+	fi
+	if [ -n "$new_docroot" ]; then
+		web_data=$(echo "$web_data" | sed "s|CUSTOM_DOCROOT='$CUSTOM_DOCROOT'|CUSTOM_DOCROOT='$new_docroot'|")
+		web_data=$(echo "$web_data" | sed "s|CUSTOM_PHPROOT='$CUSTOM_PHPROOT'|CUSTOM_PHPROOT='$new_php_docroot'|")
+	fi
+	web_data=$(echo "$web_data" | sed "s/SUSPENDED='no'/SUSPENDED='yes'/")
+
+	# Check SSL
+	if [ "$SSL" = 'yes' ]; then
+		ssl_crt=$HESTIA/data/users/$owner/ssl/$domain.crt
+		ssl_key=$HESTIA/data/users/$owner/ssl/$domain.key
+		ssl_ca=$HESTIA/data/users/$owner/ssl/$domain.ca
+		ssl_pem=$HESTIA/data/users/$owner/ssl/$domain.pem
+		mv $ssl_crt $HESTIA/data/users/$user/ssl/
+		mv $ssl_key $HESTIA/data/users/$user/ssl/
+		mv $ssl_ca $HESTIA/data/users/$user/ssl/ >> /dev/null 2>&1
+		mv $ssl_pem $HESTIA/data/users/$user/ssl/ >> /dev/null 2>&1
+		rm -f $HOMEDIR/$owner/conf/web/ssl.$domain.*
+	fi
+
+	# Check ftp user account
+	if [ -n "$FTP_USER" ]; then
+		/usr/sbin/userdel -f "$FTP_USER" >> /dev/null 2>&1
+		old_str="FTP_USER='$FTP_USER'"
+		new_str=$(echo "$old_str" | sed "s/${owner}_/${user}_/")
+		web_data=$(echo "$web_data" | sed "s/$old_str/$new_str/")
+	fi
+
+	# Move config
+	sed -i "/DOMAIN='$domain'/d" $HESTIA/data/users/$owner/web.conf
+	echo "$web_data" >> $HESTIA/data/users/$user/web.conf
+
+	# Move data
+	mv $HOMEDIR/$owner/web/$domain $HOMEDIR/$user/web/
+
+	# Change ownership
+	find "$HOMEDIR/$user/web/$domain" -user "$owner" \
+		-exec chown -h $user:$user {} \;
+
+	# Rebuild config
+	$BIN/v-unsuspend-web-domain "$user" "$domain" no >> /dev/null 2>&1
+	$BIN/v-rebuild-web-domains "$owner" no
+	$BIN/v-rebuild-web-domains "$user"
+
+	# Cleanup old config
+	rm -rf "$HOMEDIR/$owner/conf/web/$domain/"
 fi
 
 # DNS domain
 dns_data=$(grep "DOMAIN='$domain'" $HESTIA/data/users/$owner/dns.conf)
 if [ -n "$dns_data" ]; then
-    echo "[*] Moving DNS zone and records..."
-    parse_object_kv_list "$dns_data"
-
-    # Change IP
-    if [ -n "$ip" ]; then
-        dns_data=$(echo "$dns_data" | sed "s/IP='$IP'/IP='$ip'/")
-        sed -i "s/$IP/$ip/g" $HESTIA/data/users/$owner/dns/$domain.conf
-    fi
-
-    # Move config
-    sed -i "/DOMAIN='$domain'/d" $HESTIA/data/users/$owner/dns.conf
-    echo "$dns_data" >> $HESTIA/data/users/$user/dns.conf
-
-    # Move dns records
-    mv $HESTIA/data/users/$owner/dns/$domain.conf \
-        $HESTIA/data/users/$user/dns/
-
-    # Rebuild config
-    $BIN/v-unsuspend-dns-domain "$user" "$domain" no >> /dev/null 2>&1
-    $BIN/v-rebuild-dns-domains "$owner" no
-    $BIN/v-rebuild-dns-domains "$user"
-
-    # Cleanup old config
-    rm -f $HOMEDIR/$owner/conf/dns/$domain.db
-
-    # Resync dns cluster
-    if [ "$DNS_CLUSTER"  = "yes" ]; then
-        $BIN/v-sync-dns-cluster
-    fi
+	echo "[*] Moving DNS zone and records..."
+	parse_object_kv_list "$dns_data"
+
+	# Change IP
+	if [ -n "$ip" ]; then
+		dns_data=$(echo "$dns_data" | sed "s/IP='$IP'/IP='$ip'/")
+		sed -i "s/$IP/$ip/g" $HESTIA/data/users/$owner/dns/$domain.conf
+	fi
+
+	# Move config
+	sed -i "/DOMAIN='$domain'/d" $HESTIA/data/users/$owner/dns.conf
+	echo "$dns_data" >> $HESTIA/data/users/$user/dns.conf
+
+	# Move dns records
+	mv $HESTIA/data/users/$owner/dns/$domain.conf \
+		$HESTIA/data/users/$user/dns/
+
+	# Rebuild config
+	$BIN/v-unsuspend-dns-domain "$user" "$domain" no >> /dev/null 2>&1
+	$BIN/v-rebuild-dns-domains "$owner" no
+	$BIN/v-rebuild-dns-domains "$user"
+
+	# Cleanup old config
+	rm -f $HOMEDIR/$owner/conf/dns/$domain.db
+
+	# Resync dns cluster
+	if [ "$DNS_CLUSTER" = "yes" ]; then
+		$BIN/v-sync-dns-cluster
+	fi
 fi
 
 # MAIL domain
 mail_data=$(grep "DOMAIN='$domain'" $HESTIA/data/users/$owner/mail.conf)
 if [ -n "$mail_data" ]; then
-    $BIN/v-suspend-mail-domain "$owner" "$domain" >> /dev/null 2>&1
-    echo "[*] Moving mail domain and accounts..."
-
-    parse_object_kv_list "$mail_data"
-
-    # Ensure mail configuration directory exists for receiving user
-    if [ ! -e "$HOMEDIR/$user/conf/mail/$domain/" ]; then
-        mkdir -p $HOMEDIR/$user/conf/mail/$domain/
-    fi
-
-    # Move config
-    sed -i "/DOMAIN='$domain'/d" $HESTIA/data/users/$owner/mail.conf
-    mail_data=$(echo "$mail_data" | sed "s/SUSPENDED='no'/SUSPENDED='yes'/")
-    echo "$mail_data" >> $HESTIA/data/users/$user/mail.conf
-    mv -f $HESTIA/data/users/$owner/mail/$domain.conf \
-        $HESTIA/data/users/$user/mail/
-
-    # Move DKIM
-    if [ -e "$HESTIA/data/users/$owner/mail/$domain.pem" ]; then
-        mv -f $HESTIA/data/users/$owner/mail/$domain.pem \
-            $HESTIA/data/users/$user/mail/
-        mv -f $HESTIA/data/users/$owner/mail/$domain.pub \
-            $HESTIA/data/users/$user/mail/
-    fi
-
-    # Move SSL certificates
-    if [ "$SSL" = 'yes' ]; then
-         # Ensure that SSL directory exists and move certificates
-        mkdir -p $HESTIA/data/users/$user/ssl/
-        mkdir -p $HOMEDIR/$user/conf/mail/$domain/ssl/
-
-        ssl_crt=$HESTIA/data/users/$owner/ssl/mail.$domain.crt
-        ssl_key=$HESTIA/data/users/$owner/ssl/mail.$domain.key
-        ssl_ca=$HESTIA/data/users/$owner/ssl/mail.$domain.ca
-        ssl_pem=$HESTIA/data/users/$owner/ssl/mail.$domain.pem
-        mv $ssl_crt $HESTIA/data/users/$user/ssl/
-        mv $ssl_key $HESTIA/data/users/$user/ssl/
-        mv $ssl_ca $HESTIA/data/users/$user/ssl/ >> /dev/null 2>&1
-        mv $ssl_pem $HESTIA/data/users/$user/ssl/ >> /dev/null 2>&1
-
-        # Add certificate to user home directory
-        cp -f $HESTIA/data/users/$user/ssl/mail.$domain.crt $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.crt
-        cp -f $HESTIA/data/users/$user/ssl/mail.$domain.key $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key
-        cp -f $HESTIA/data/users/$user/ssl/mail.$domain.pem $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem
-        if [ -e "$HESTIA/data/users/$user/ssl/mail.$domain.ca" ]; then
-            cp -f $HESTIA/data/users/$user/ssl/mail.$domain.ca $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.ca
-        fi
-
-        # Add domain SSL configuration to dovecot
-        if [ -f "/etc/dovecot/conf.d/domains/$domain.conf" ]; then
-            rm -f /etc/dovecot/conf.d/domains/$domain.conf
-        fi
-
-        echo "" >> /etc/dovecot/conf.d/domains/$domain.conf
-        echo "local_name mail.$domain {" >> /etc/dovecot/conf.d/domains/$domain.conf
-        echo "  ssl_cert = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem" >> /etc/dovecot/conf.d/domains/$domain.conf
-        echo "  ssl_key = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key" >> /etc/dovecot/conf.d/domains/$domain.conf
-        echo "}" >> /etc/dovecot/conf.d/domains/$domain.conf
-
-        # Add domain SSL configuration to exim4
-        # Cleanup symlinks
-        find /usr/local/hestia/ssl/mail -xtype l -delete
-
-        ln -s -f $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem /usr/local/hestia/ssl/mail/mail.$domain.crt
-        ln -s -f $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key /usr/local/hestia/ssl/mail/mail.$domain.key
-
-        # Set correct permissions on certificates
-        chmod 750 $HOMEDIR/$user/conf/mail/$domain/ssl
-        chown -R $MAIL_USER:mail $HOMEDIR/$user/conf/mail/$domain/ssl
-        chmod 0644 $HOMEDIR/$user/conf/mail/$domain/ssl/*
-        chown -h $user:mail $HOMEDIR/$user/conf/mail/$domain/ssl/*
-        chmod -R 0644 /usr/local/hestia/ssl/mail/*
-        chown -h $user:mail /usr/local/hestia/ssl/mail/*
-    fi
-
-    # Move data
-    mv $HOMEDIR/$owner/mail/$domain $HOMEDIR/$user/mail/
-
-    # Change ownership
-    find $HOMEDIR/$user/mail/$domain -user $owner \
-        -exec chown -h $user {} \;
-
-    # 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
-    # Chowning mail conf files to exim user
-    if [ -d "$HOMEDIR/$user/conf/mail/$domain" ]; then
-        find $HOMEDIR/$user/conf/mail/$domain -user root \
-            -exec chown $exim_user {} \;
-    fi
-
-    # Remove old mail directory from original owner
-    if [ -e "$HOMEDIR/$owner/mail/$domain" ]; then
-        rm -rf "$HOMEDIR/$owner/mail/$domain"
-    fi
-
-    # Remove old mail configuration directory from original owner
-    if [ -e "$HOMEDIR/$owner/conf/mail/$domain" ]; then
-        rm -rf "$HOMEDIR/$owner/conf/mail/$domain"
-    fi
-    if [ -e "$HESTIA/data/users/$owner/mail/$domain.conf" ]; then
-        rm -f "$HESTIA/data/users/$owner/mail/$domain.conf"
-    fi
-
-    # Rebuild config
-    $BIN/v-unsuspend-mail-domain "$user" "$domain" no
-    $BIN/v-rebuild-mail-domains "$owner" no
-    $BIN/v-rebuild-mail-domains "$user"
+	$BIN/v-suspend-mail-domain "$owner" "$domain" >> /dev/null 2>&1
+	echo "[*] Moving mail domain and accounts..."
+
+	parse_object_kv_list "$mail_data"
+
+	# Ensure mail configuration directory exists for receiving user
+	if [ ! -e "$HOMEDIR/$user/conf/mail/$domain/" ]; then
+		mkdir -p $HOMEDIR/$user/conf/mail/$domain/
+	fi
+
+	# Move config
+	sed -i "/DOMAIN='$domain'/d" $HESTIA/data/users/$owner/mail.conf
+	mail_data=$(echo "$mail_data" | sed "s/SUSPENDED='no'/SUSPENDED='yes'/")
+	echo "$mail_data" >> $HESTIA/data/users/$user/mail.conf
+	mv -f $HESTIA/data/users/$owner/mail/$domain.conf \
+		$HESTIA/data/users/$user/mail/
+
+	# Move DKIM
+	if [ -e "$HESTIA/data/users/$owner/mail/$domain.pem" ]; then
+		mv -f $HESTIA/data/users/$owner/mail/$domain.pem \
+			$HESTIA/data/users/$user/mail/
+		mv -f $HESTIA/data/users/$owner/mail/$domain.pub \
+			$HESTIA/data/users/$user/mail/
+	fi
+
+	# Move SSL certificates
+	if [ "$SSL" = 'yes' ]; then
+		# Ensure that SSL directory exists and move certificates
+		mkdir -p $HESTIA/data/users/$user/ssl/
+		mkdir -p $HOMEDIR/$user/conf/mail/$domain/ssl/
+
+		ssl_crt=$HESTIA/data/users/$owner/ssl/mail.$domain.crt
+		ssl_key=$HESTIA/data/users/$owner/ssl/mail.$domain.key
+		ssl_ca=$HESTIA/data/users/$owner/ssl/mail.$domain.ca
+		ssl_pem=$HESTIA/data/users/$owner/ssl/mail.$domain.pem
+		mv $ssl_crt $HESTIA/data/users/$user/ssl/
+		mv $ssl_key $HESTIA/data/users/$user/ssl/
+		mv $ssl_ca $HESTIA/data/users/$user/ssl/ >> /dev/null 2>&1
+		mv $ssl_pem $HESTIA/data/users/$user/ssl/ >> /dev/null 2>&1
+
+		# Add certificate to user home directory
+		cp -f $HESTIA/data/users/$user/ssl/mail.$domain.crt $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.crt
+		cp -f $HESTIA/data/users/$user/ssl/mail.$domain.key $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key
+		cp -f $HESTIA/data/users/$user/ssl/mail.$domain.pem $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem
+		if [ -e "$HESTIA/data/users/$user/ssl/mail.$domain.ca" ]; then
+			cp -f $HESTIA/data/users/$user/ssl/mail.$domain.ca $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.ca
+		fi
+
+		# Add domain SSL configuration to dovecot
+		if [ -f "/etc/dovecot/conf.d/domains/$domain.conf" ]; then
+			rm -f /etc/dovecot/conf.d/domains/$domain.conf
+		fi
+
+		echo "" >> /etc/dovecot/conf.d/domains/$domain.conf
+		echo "local_name mail.$domain {" >> /etc/dovecot/conf.d/domains/$domain.conf
+		echo "  ssl_cert = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem" >> /etc/dovecot/conf.d/domains/$domain.conf
+		echo "  ssl_key = <$HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key" >> /etc/dovecot/conf.d/domains/$domain.conf
+		echo "}" >> /etc/dovecot/conf.d/domains/$domain.conf
+
+		# Add domain SSL configuration to exim4
+		# Cleanup symlinks
+		find /usr/local/hestia/ssl/mail -xtype l -delete
+
+		ln -s -f $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.pem /usr/local/hestia/ssl/mail/mail.$domain.crt
+		ln -s -f $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.key /usr/local/hestia/ssl/mail/mail.$domain.key
+
+		# Set correct permissions on certificates
+		chmod 750 $HOMEDIR/$user/conf/mail/$domain/ssl
+		chown -R $MAIL_USER:mail $HOMEDIR/$user/conf/mail/$domain/ssl
+		chmod 0644 $HOMEDIR/$user/conf/mail/$domain/ssl/*
+		chown -h $user:mail $HOMEDIR/$user/conf/mail/$domain/ssl/*
+		chmod -R 0644 /usr/local/hestia/ssl/mail/*
+		chown -h $user:mail /usr/local/hestia/ssl/mail/*
+	fi
+
+	# Move data
+	mv $HOMEDIR/$owner/mail/$domain $HOMEDIR/$user/mail/
+
+	# Change ownership
+	find $HOMEDIR/$user/mail/$domain -user $owner \
+		-exec chown -h $user {} \;
+
+	# 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
+	# Chowning mail conf files to exim user
+	if [ -d "$HOMEDIR/$user/conf/mail/$domain" ]; then
+		find $HOMEDIR/$user/conf/mail/$domain -user root \
+			-exec chown $exim_user {} \;
+	fi
+
+	# Remove old mail directory from original owner
+	if [ -e "$HOMEDIR/$owner/mail/$domain" ]; then
+		rm -rf "$HOMEDIR/$owner/mail/$domain"
+	fi
+
+	# Remove old mail configuration directory from original owner
+	if [ -e "$HOMEDIR/$owner/conf/mail/$domain" ]; then
+		rm -rf "$HOMEDIR/$owner/conf/mail/$domain"
+	fi
+	if [ -e "$HESTIA/data/users/$owner/mail/$domain.conf" ]; then
+		rm -f "$HESTIA/data/users/$owner/mail/$domain.conf"
+	fi
+
+	# Rebuild config
+	$BIN/v-unsuspend-mail-domain "$user" "$domain" no
+	$BIN/v-rebuild-mail-domains "$owner" no
+	$BIN/v-rebuild-mail-domains "$user"
 fi
 
 # Update counters
@@ -289,19 +289,19 @@ $BIN/v-update-user-counters "$user"
 
 # Mail domains currently don't have the IP variable set see #2306
 if [ -n "$old_ip" ]; then
-    # Recalculate ip usage
-    if [ -n "$ip" ]; then
-        decrease_ip_value $old_ip $owner
-        increase_ip_value $new_ip
-    else
-        # recalculate ip
-        decrease_ip_value $old_ip $owner
-        increase_ip_value $old_ip
-    fi
+	# Recalculate ip usage
+	if [ -n "$ip" ]; then
+		decrease_ip_value $old_ip $owner
+		increase_ip_value $new_ip
+	else
+		# recalculate ip
+		decrease_ip_value $old_ip $owner
+		increase_ip_value $old_ip
+	fi
 fi
 # Send notification to panel
 if [ -n "$web_data" ] || [ -n "$dns_data" ] || [ -n "$mail_data" ]; then
-    $HESTIA/bin/v-add-user-notification "$user" "$domain has been added to your account" ''
+	$HESTIA/bin/v-add-user-notification "$user" "$domain has been added to your account" ''
 fi
 
 #----------------------------------------------------------#

+ 13 - 13
bin/v-change-firewall-rule

@@ -13,11 +13,11 @@
 
 # Argument definition
 rule=$1
-action=$(echo $2|tr '[:lower:]' '[:upper:]')
+action=$(echo $2 | tr '[:lower:]' '[:upper:]')
 ip=$3
 port_ext=$4
 protocol=${5-TCP}
-protocol=$(echo $protocol|tr '[:lower:]' '[:upper:]')
+protocol=$(echo $protocol | tr '[:lower:]' '[:upper:]')
 comment=$6
 
 # Includes
@@ -30,10 +30,10 @@ source_conf "$HESTIA/conf/hestia.conf"
 
 # Sort function
 sort_fw_rules() {
-    cat $HESTIA/data/firewall/rules.conf |\
-        sort -n -k 2 -t \' > $HESTIA/data/firewall/rules.conf.tmp
-    mv -f $HESTIA/data/firewall/rules.conf.tmp \
-        $HESTIA/data/firewall/rules.conf
+	cat $HESTIA/data/firewall/rules.conf \
+		| sort -n -k 2 -t \' > $HESTIA/data/firewall/rules.conf.tmp
+	mv -f $HESTIA/data/firewall/rules.conf.tmp \
+		$HESTIA/data/firewall/rules.conf
 }
 
 #----------------------------------------------------------#
@@ -43,17 +43,17 @@ sort_fw_rules() {
 check_args '4' "$#" 'RULE ACTION IP PORT [PROTOCOL] [COMMENT]'
 is_format_valid 'rule' 'action' 'protocol' 'port_ext'
 if [ ! -z "$comment" ]; then
-    is_format_valid 'comment'
+	is_format_valid 'comment'
 fi
 is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
 is_object_valid '../../data/firewall/rules' 'RULE' "$rule"
 
 if [[ "$ip" =~ ^ipset: ]]; then
-    ipset_name="${ip#ipset:}"
-    $BIN/v-list-firewall-ipset plain | grep "^$ipset_name\s" >/dev/null
-    check_result $? 'ipset object not found' "$E_NOTEXIST"
+	ipset_name="${ip#ipset:}"
+	$BIN/v-list-firewall-ipset plain | grep "^$ipset_name\s" > /dev/null
+	check_result $? 'ipset object not found' "$E_NOTEXIST"
 else
-    is_format_valid 'ip'
+	is_format_valid 'ip'
 fi
 
 # Perform verification if read-only mode is enabled
@@ -65,8 +65,8 @@ check_hestia_demo_mode
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
+time=$(echo "$time_n_date" | cut -f 1 -d \ )
+date=$(echo "$time_n_date" | cut -f 2 -d \ )
 
 # Concatenating firewall rule
 str="RULE='$rule' ACTION='$action' PROTOCOL='$protocol' PORT='$port_ext'"

+ 11 - 11
bin/v-change-fs-file-permission

@@ -32,31 +32,31 @@ check_hestia_demo_mode
 # Checking user homedir
 homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
 if [ -z "$homedir" ]; then
-    echo "Error: user home directory doesn't exist"
-    exit 12
+	echo "Error: user home directory doesn't exist"
+	exit 12
 fi
 
 # Checking source file
 if [ ! -f "$src_file" ]; then
-    echo "Error: source file doesn't exist $src_file"
-    exit 3
+	echo "Error: source file doesn't exist $src_file"
+	exit 3
 fi
 
 # Checking source path
 rpath=$(readlink -f "$src_file")
-if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
-    echo "Error: invalid source path $src_file"
-    exit 2
+if [ -z "$(echo $rpath | egrep "^/tmp|^$homedir")" ]; then
+	echo "Error: invalid source path $src_file"
+	exit 2
 fi
 
 # Changing file permissions
-user_exec chmod -R $permissions "$src_file" >/dev/null 2>&1
+user_exec chmod -R $permissions "$src_file" > /dev/null 2>&1
 if [ $? -ne 0 ]; then
-    echo "Error: access permission on $src_file was not changed"
-    exit 3
+	echo "Error: access permission on $src_file was not changed"
+	exit 3
 fi
 
 $BIN/v-log-action "system" "Info" "System" "File system permissions changed (User: $user, File: $src_file, Permissions: $permissions)."
 
 # Exiting
-exit
+exit

+ 17 - 16
bin/v-change-mail-account-password

@@ -15,7 +15,8 @@ user=$1
 domain=$2
 domain_idn=$2
 account=$3
-password=$4; HIDE=4
+password=$4
+HIDE=4
 
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -57,26 +58,26 @@ check_hestia_demo_mode
 
 # Generating hashed password
 if [ -n "$(doveadm pw -l | grep BLF-CRYPT)" ]; then
-    set +H # disable ! style history substitution
-    md5="$(doveadm pw -s BLF-CRYPT -p "$password")"
+	set +H # disable ! style history substitution
+	md5="$(doveadm pw -s BLF-CRYPT -p "$password")"
 elif [ -n "$(doveadm pw -l | grep ARGON2ID)" ]; then
-    # Fall back on Argon2id if bcrypt is not available
-    set +H # disable ! style history substitution
-    md5="$(doveadm pw -s ARGON2ID -p "$password")"
+	# Fall back on Argon2id if bcrypt is not available
+	set +H # disable ! style history substitution
+	md5="$(doveadm pw -s ARGON2ID -p "$password")"
 else
-    # Fall back on MD5 if neither bcrypt nor argon2id is available
-    salt=$(generate_password "$PW_MATRIX" "8")
-    md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)"
+	# Fall back on MD5 if neither bcrypt nor argon2id is available
+	salt=$(generate_password "$PW_MATRIX" "8")
+	md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<< $password)"
 fi
 
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    quota=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$QUOTA')
-    if [ "$quota" = 'unlimited' ]; then
-        quota=0
-    fi
-    sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
-    str="$account:$md5:$user:mail::$HOMEDIR/$user:${quota}:userdb_quota_rule=*:storage=${quota}M"
-    echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/passwd
+	quota=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$QUOTA')
+	if [ "$quota" = 'unlimited' ]; then
+		quota=0
+	fi
+	sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
+	str="$account:$md5:$user:mail::$HOMEDIR/$user:${quota}:userdb_quota_rule=*:storage=${quota}M"
+	echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/passwd
 fi
 
 #----------------------------------------------------------#

+ 8 - 8
bin/v-change-mail-account-quota

@@ -39,7 +39,7 @@ format_domain_idn
 check_args '4' "$#" 'USER DOMAIN ACCOUNT QUOTA'
 is_format_valid 'user' 'domain' 'account'
 if [ "$quota" != 'unlimited' ]; then
-    is_format_valid 'quota'
+	is_format_valid 'quota'
 fi
 is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
 is_object_valid 'user' 'USER' "$user"
@@ -58,12 +58,12 @@ check_hestia_demo_mode
 
 md5=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$MD5')
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    if [ "$quota" = 'unlimited' ]; then
-        quota=0
-    fi
-    sed -i "/^$account:/d" "$HOMEDIR/$user/conf/mail/$domain/passwd"
-    str="$account:$md5:$user:mail::$HOMEDIR/$user:${quota}:userdb_quota_rule=*:storage=${quota}M"
-    echo "$str" >> "$HOMEDIR/$user/conf/mail/$domain/passwd"
+	if [ "$quota" = 'unlimited' ]; then
+		quota=0
+	fi
+	sed -i "/^$account:/d" "$HOMEDIR/$user/conf/mail/$domain/passwd"
+	str="$account:$md5:$user:mail::$HOMEDIR/$user:${quota}:userdb_quota_rule=*:storage=${quota}M"
+	echo "$str" >> "$HOMEDIR/$user/conf/mail/$domain/passwd"
 fi
 
 #----------------------------------------------------------#
@@ -71,7 +71,7 @@ fi
 #----------------------------------------------------------#
 
 if [[ "$quota" -eq 0 ]]; then
-    quota='unlimited'
+	quota='unlimited'
 fi
 
 # Update quota

+ 17 - 17
bin/v-change-mail-account-rate-limit

@@ -41,7 +41,7 @@ format_domain_idn
 check_args '4' "$#" 'USER DOMAIN ACCOUNT RATE'
 is_format_valid 'user' 'domain' 'account'
 if [ "$rate" != 'system' ]; then
-    is_format_valid 'rate'
+	is_format_valid 'rate'
 fi
 is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
 is_object_valid 'user' 'USER' "$user"
@@ -60,20 +60,20 @@ check_hestia_demo_mode
 
 md5=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$MD5')
 if [[ "$MAIL_SYSTEM" =~ exim ]]; then
-    if [ "$rate" = "system" ]; then
-        user_rate_limit=$(get_object_value 'mail' 'DOMAIN' "$domain" '$RATE_LIMIT');
-        if [ -n "$user_rate_limit" ]; then
-            sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/limits
-            echo "$account@$domain_idn:$user_rate_limit" >> $HOMEDIR/$user/conf/mail/$domain/limits
-        else
-            system=$(cat /etc/exim4/limit.conf)
-            sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/limits
-            echo "$account@$domain_idn:$system" >> $HOMEDIR/$user/conf/mail/$domain/limits
-        fi
-    else
-        sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/limits
-        echo "$account@$domain_idn:$rate" >> $HOMEDIR/$user/conf/mail/$domain/limits
-    fi
+	if [ "$rate" = "system" ]; then
+		user_rate_limit=$(get_object_value 'mail' 'DOMAIN' "$domain" '$RATE_LIMIT')
+		if [ -n "$user_rate_limit" ]; then
+			sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/limits
+			echo "$account@$domain_idn:$user_rate_limit" >> $HOMEDIR/$user/conf/mail/$domain/limits
+		else
+			system=$(cat /etc/exim4/limit.conf)
+			sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/limits
+			echo "$account@$domain_idn:$system" >> $HOMEDIR/$user/conf/mail/$domain/limits
+		fi
+	else
+		sed -i "/^$account@$domain_idn:/ d" $HOMEDIR/$user/conf/mail/$domain/limits
+		echo "$account@$domain_idn:$rate" >> $HOMEDIR/$user/conf/mail/$domain/limits
+	fi
 fi
 
 #----------------------------------------------------------#
@@ -81,7 +81,7 @@ fi
 #----------------------------------------------------------#
 
 if [[ "$rate" = "system" ]]; then
-    rate=''
+	rate=''
 fi
 
 syshealth_repair_mail_account_config
@@ -93,4 +93,4 @@ update_object_value "mail/$domain" 'ACCOUNT' "$account" '$RATE_LIMIT' "$rate"
 $BIN/v-log-action "$user" "Info" "Mail" "Mail account rate limit changed (Rate: $rate, Account: $account@$domain)."
 log_event "$OK" "$ARGUMENTS"
 
-exit
+exit

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff