Browse Source

Merge branch 'staging/features' into main

Kristan Kenney 5 years ago
parent
commit
044657d962

+ 18 - 8
bin/v-add-database-host

@@ -18,9 +18,10 @@ type=$1
 host=$2
 host=$2
 dbuser=$3
 dbuser=$3
 password=$4; HIDE=4
 password=$4; HIDE=4
-max_db=${6-500}
-charsets=${7-UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8}
-template=${8-template1}
+max_db=${5-500}
+charsets=${6}
+template=${7}
+port=${8}
 
 
 # Includes
 # Includes
 source $HESTIA/func/main.sh
 source $HESTIA/func/main.sh
@@ -33,6 +34,8 @@ is_mysql_host_alive() {
     echo "host='$HOST'" >> $mycnf
     echo "host='$HOST'" >> $mycnf
     echo "user='$USER'" >> $mycnf
     echo "user='$USER'" >> $mycnf
     echo "password='$PASSWORD'" >> $mycnf
     echo "password='$PASSWORD'" >> $mycnf
+    echo "port='$PORT'" >> $mycnf
+    
     chmod 600 $mycnf
     chmod 600 $mycnf
     mysql --defaults-file=$mycnf -e 'SELECT VERSION()' >/dev/null 2>&1
     mysql --defaults-file=$mycnf -e 'SELECT VERSION()' >/dev/null 2>&1
     rm $mycnf
     rm $mycnf
@@ -45,7 +48,7 @@ is_mysql_host_alive() {
 
 
 is_pgsql_host_alive() {
 is_pgsql_host_alive() {
     export PGPASSWORD="$dbpass"
     export PGPASSWORD="$dbpass"
-    psql -h $host -U $dbuser -c "SELECT VERSION()" > /dev/null 2>&1
+    psql -h $host -U $dbuser -p $port -c "SELECT VERSION()" > /dev/null 2>&1
     if [ '0' -ne "$?" ]; then
     if [ '0' -ne "$?" ]; then
         echo "Error: PostgreSQL connection to $host failed"
         echo "Error: PostgreSQL connection to $host failed"
         log_event "$E_CONNECT" "$ARGUMENTS"
         log_event "$E_CONNECT" "$ARGUMENTS"
@@ -58,14 +61,21 @@ is_pgsql_host_alive() {
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-args_usage='TYPE HOST DBUSER DBPASS [MAX_DB] [CHARSETS] [TPL]'
+args_usage='TYPE HOST DBUSER DBPASS [MAX_DB] [CHARSETS] [TPL] [PORT]'
 check_args '4' "$#" "$args_usage"
 check_args '4' "$#" "$args_usage"
-is_format_valid 'host' 'dbuser' 'max_db' 'charsets' 'template'
+
+if [ -z $charsets ]; then charsets="UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8"; fi
+if [ -z $template ]; then template="template1"; fi
+
+database_set_default_ports
+
+is_format_valid 'host' 'dbuser' 'max_db' 'charsets' 'template' 'port'
 #is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
 #is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
 #is_type_valid "$DB_SYSTEM" "$type"
 #is_type_valid "$DB_SYSTEM" "$type"
 is_dbhost_new
 is_dbhost_new
 is_password_valid
 is_password_valid
 dbpass="$password"
 dbpass="$password"
+
 case $type in
 case $type in
     mysql) is_mysql_host_alive ;;
     mysql) is_mysql_host_alive ;;
     pgsql) is_pgsql_host_alive ;;
     pgsql) is_pgsql_host_alive ;;
@@ -85,11 +95,11 @@ date=$(echo "$time_n_date" |cut -f 2 -d \ )
 case $type in
 case $type in
     mysql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
     mysql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
            str="$str CHARSETS='$charsets' MAX_DB='$max_db' U_SYS_USERS=''";
            str="$str CHARSETS='$charsets' MAX_DB='$max_db' U_SYS_USERS=''";
-           str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$time' DATE='$date'";;
+           str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$time' DATE='$date' PORT='$port'";;
     pgsql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
     pgsql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
            str="$str CHARSETS='$charsets' TPL='$template' MAX_DB='$max_db'";
            str="$str CHARSETS='$charsets' TPL='$template' MAX_DB='$max_db'";
            str="$str U_SYS_USERS='' U_DB_BASES='0' SUSPENDED='no'";
            str="$str U_SYS_USERS='' U_DB_BASES='0' SUSPENDED='no'";
-           str="$str TIME='$time' DATE='$date'";;
+           str="$str TIME='$time' DATE='$date' PORT='$port'";;
 esac
 esac
 
 
 
 

+ 0 - 125
bin/v-add-user-favourites

@@ -1,125 +0,0 @@
-#!/bin/bash
-# info: adding user favourites
-# options: USER SYSTEM OBJECT
-#
-# The function adds object to users favourites
-
-
-#----------------------------------------------------------#
-#                    Variable&Function                     #
-#----------------------------------------------------------#
-
-# Argument definition
-user=$1
-system=$(echo "$2" |tr '[:lower:]' '[:upper:]')
-object=$3
-email=$3
-id=$3
-
-# Includes
-source $HESTIA/func/main.sh
-source $HESTIA/conf/hestia.conf
-
-
-#----------------------------------------------------------#
-#                    Verifications                         #
-#----------------------------------------------------------#
-
-check_args '3' "$#" 'USER SYSTEM OBJECT'
-is_format_valid 'user' 'system'
-case $system in 
-    MAIL_ACC)   is_format_valid 'email' ;;
-    CRON)       is_format_valid 'id' ;;
-    DNS_REC)    is_format_valid 'id' ;;
-    *)          is_format_valid 'object'
-esac
-is_object_valid 'user' 'USER' "$user"
-is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking system
-case $system in
-    USER)       check='ok' ;;
-    WEB)        check='ok' ;;
-    DNS)        check='ok' ;;
-    DNS_REC)    check='ok' ;;
-    MAIL)       check='ok' ;;
-    MAIL_ACC)   check='ok' ;;
-    DB)         check='ok' ;;
-    CRON)       check='ok' ;;
-    BACKUP)     check='ok' ;;
-    IP)         check='ok' ;;
-    PACKAGE)    check='ok' ;;
-    FIREWALL)   check='ok' ;;
-    *)      check_args '2' '0' 'USER SYSTEM OBJECT'
-esac
-
-
-#----------------------------------------------------------#
-#                       Action                             #
-#----------------------------------------------------------#
-
-# Flushing vars
-USER=''
-WEB=''
-DNS=''
-DNS_REC=''
-MAIL=''
-MAIL_ACC=''
-DB=''
-CRON=''
-BACKUP=''
-IP=''
-PACKAGE=''
-FIREWALL=''
-
-# Creating config just in case
-touch $USER_DATA/favourites.conf
-
-# Reading current values
-source $USER_DATA/favourites.conf
-
-# Assigning current system value
-eval value=\$$system
-
-# Checking if object is new
-check_fav=$(echo "$value" |tr ',' '\n'| grep "^$object$")
-if [ ! -z "$check_fav" ]; then
-    exit 0
-fi
-
-# Adding object to favorites
-if [ -z "$value" ]; then
-    value="$object"
-else
-    value="$value,$object"
-fi
-
-# Updating sytem
-eval $system=$value
-
-# Updating user favorites
-echo "USER='$USER'
-WEB='$WEB'
-DNS='$DNS'
-DNS_REC='$DNS_REC'
-MAIL='$MAIL'
-MAIL_ACC='$MAIL_ACC'
-DB='$DB'
-CRON='$CRON'
-BACKUP='$BACKUP'
-IP='$IP'
-PACKAGE='$PACKAGE'
-FIREWALL='$FIREWALL'" > $USER_DATA/favourites.conf
-
-# Changing file permission
-chmod 640 $USER_DATA/favourites.conf
-
-#----------------------------------------------------------#
-#                       Hestia                             #
-#----------------------------------------------------------#
-
-# Logging
-log_history "added starred $object in $system listing"
-log_event "$OK" "$ARGUMENTS"
-
-exit

+ 0 - 128
bin/v-delete-user-favourites

@@ -1,128 +0,0 @@
-#!/bin/bash
-# info: deleting user favourites
-# options: USER SYSTEM OBJECT
-#
-# The function deletes object from users favourites
-
-
-#----------------------------------------------------------#
-#                    Variable&Function                     #
-#----------------------------------------------------------#
-
-# Argument definition
-user=$1
-system=$(echo "$2" |tr '[:lower:]' '[:upper:]')
-object=$3
-email=$3
-id=$3
-
-# Includes
-source $HESTIA/func/main.sh
-source $HESTIA/conf/hestia.conf
-
-
-#----------------------------------------------------------#
-#                    Verifications                         #
-#----------------------------------------------------------#
-
-check_args '3' "$#" 'USER SYSTEM OBJECT'
-case $system in 
-    MAIL_ACC)   is_format_valid 'email' ;;
-    CRON)       is_format_valid 'id' ;;
-    DNS_REC)    is_format_valid 'id' ;;
-    *)          is_format_valid 'object'
-esac
-is_format_valid 'user'
-is_object_valid 'user' 'USER' "$user"
-is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking system
-case $system in
-    USER)       check='ok' ;;
-    WEB)        check='ok' ;;
-    DNS)        check='ok' ;;
-    DNS_REC)    check='ok' ;;
-    MAIL)       check='ok' ;;
-    MAIL_ACC)   check='ok' ;;
-    DB)         check='ok' ;;
-    CRON)       check='ok' ;;
-    BACKUP)     check='ok' ;;
-    IP)         check='ok' ;;
-    PACKAGE)    check='ok' ;;
-    FIREWALL)   check='ok' ;;
-    *)      check_args '2' '0' 'USER SYSTEM OBJECT'
-esac
-
-# Perform verification if read-only mode is enabled
-check_hestia_demo_mode
-
-
-#----------------------------------------------------------#
-#                       Action                             #
-#----------------------------------------------------------#
-
-# Flushing vars
-USER=''
-WEB=''
-DNS=''
-DNS_REC=''
-MAIL=''
-MAIL_ACC=''
-DB=''
-CRON=''
-BACKUP=''
-IP=''
-PACKAGE=''
-FIREWALL=''
-
-# Creating config just in case
-touch $USER_DATA/favourites.conf
-
-# Reading current values
-source $USER_DATA/favourites.conf
-
-# Assigning current system value
-eval value=\$$system
-
-# Checking if object is new
-check_fav=$(echo "$value" |tr ',' '\n'| grep "^$object$")
-if [ -z "$check_fav" ]; then
-    exit 0
-fi
-
-# Deleting object from favorites
-value=$(echo "$value" |\
-    sed -e "s/,/\n/g"|\
-    sed -e "s/^$object$//g"|\
-    sed -e "/^$/d"|\
-    sed -e ':a;N;$!ba;s/\n/,/g')
-
-# Updating sytem
-eval $system=$value
-
-# Updating user favorites
-echo "USER='$USER'
-WEB='$WEB'
-DNS='$DNS'
-DNS_REC='$DNS_REC'
-MAIL='$MAIL'
-MAIL_ACC='$MAIL_ACC'
-DB='$DB'
-CRON='$CRON'
-BACKUP='$BACKUP'
-IP='$IP'
-PACKAGE='$PACKAGE'
-FIREWALL='$FIREWALL'" > $USER_DATA/favourites.conf
-
-# Changing file permission
-chmod 640 $USER_DATA/favourites.conf
-
-#----------------------------------------------------------#
-#                       Hestia                             #
-#----------------------------------------------------------#
-
-# Logging
-log_history "deleted starred $object from $system listing"
-log_event "$OK" "$ARGUMENTS"
-
-exit

+ 8 - 3
bin/v-list-database-host

@@ -16,12 +16,14 @@ format=${3-shell}
 
 
 # Includes
 # Includes
 source $HESTIA/func/main.sh
 source $HESTIA/func/main.sh
+source $HESTIA/func/db.sh
 
 
 # JSON list function
 # JSON list function
 json_list() {
 json_list() {
     echo '{'
     echo '{'
     echo '    "'$HOST'": {
     echo '    "'$HOST'": {
         "HOST": "'$HOST'",
         "HOST": "'$HOST'",
+        "PORT": "'$PORT'",
         "TYPE": "'$type'",
         "TYPE": "'$type'",
         "CHARSETS": "'$CHARSETS'",
         "CHARSETS": "'$CHARSETS'",
         "MAX_DB": "'$MAX_DB'",
         "MAX_DB": "'$MAX_DB'",
@@ -38,6 +40,7 @@ json_list() {
 # SHELL list function
 # SHELL list function
 shell_list() {
 shell_list() {
     echo "HOST:           $HOST"
     echo "HOST:           $HOST"
+    echo "PORT:           $PORT"
     echo "TYPE:           $type"
     echo "TYPE:           $type"
     echo "CHARSETS:       $CHARSETS"
     echo "CHARSETS:       $CHARSETS"
     echo "MAX_DB:         $MAX_DB"
     echo "MAX_DB:         $MAX_DB"
@@ -51,15 +54,15 @@ shell_list() {
 
 
 # PLAIN list function
 # PLAIN list function
 plain_list() {
 plain_list() {
-    echo -ne "$HOST\t$type\t$CHARSETS\t$MAX_DB\t$U_SYS_USERS\t"
+    echo -ne "$HOST\t$PORT\t$type\t$CHARSETS\t$MAX_DB\t$U_SYS_USERS\t"
     echo -e "$U_DB_BASES\t$TPL\t$SUSPENDED\t$TIME\t$DATE"
     echo -e "$U_DB_BASES\t$TPL\t$SUSPENDED\t$TIME\t$DATE"
 }
 }
 
 
 # CSV list function
 # CSV list function
 csv_list() {
 csv_list() {
-    echo -n "HOST,TYPE,CHARSETS,MAX_DB,U_SYS_USERS,"
+    echo -n "HOST,PORT,TYPE,CHARSETS,MAX_DB,U_SYS_USERS,"
     echo "U_DB_BASES,TPL,SUSPENDED,TIME,DATE'"
     echo "U_DB_BASES,TPL,SUSPENDED,TIME,DATE'"
-    echo -n "$HOST,$type,\"$CHARSETS\",$MAX_DB,\"$U_SYS_USERS\","
+    echo -n "$HOST,$PORT,$type,\"$CHARSETS\",$MAX_DB,\"$U_SYS_USERS\","
     echo "$U_DB_BASES,$TPL,$SUSPENDED,$TIME,$DATE"
     echo "$U_DB_BASES,$TPL,$SUSPENDED,$TIME,$DATE"
 }
 }
 
 
@@ -81,6 +84,8 @@ is_format_valid 'host'
 is_type_format_valid "$type"
 is_type_format_valid "$type"
 is_object_valid "../../conf/$type" 'HOST' "$host"
 is_object_valid "../../conf/$type" 'HOST' "$host"
 
 
+# Set default port values if they don't exist in host configuration file
+database_set_default_ports
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Action                             #
 #                       Action                             #

+ 16 - 7
bin/v-list-database-hosts

@@ -14,6 +14,7 @@ format=${1-shell}
 
 
 # Includes
 # Includes
 source $HESTIA/func/main.sh
 source $HESTIA/func/main.sh
+source $HESTIA/func/db.sh
 source $HESTIA/conf/hestia.conf
 source $HESTIA/conf/hestia.conf
 
 
 # JSON list function
 # JSON list function
@@ -23,6 +24,8 @@ json_list() {
     objects=0
     objects=0
     for type in $(echo $DB_SYSTEM |sed -e 's/,/\n/'); do
     for type in $(echo $DB_SYSTEM |sed -e 's/,/\n/'); do
         if [ -e "$HESTIA/conf/$type.conf" ]; then
         if [ -e "$HESTIA/conf/$type.conf" ]; then
+            # Set default port values if they don't exist in database configuration file.
+            database_set_default_ports
             db_hosts=$(grep HOST $HESTIA/conf/$type.conf |wc -l)
             db_hosts=$(grep HOST $HESTIA/conf/$type.conf |wc -l)
             objects=$((objects + db_hosts))
             objects=$((objects + db_hosts))
         fi
         fi
@@ -35,6 +38,7 @@ json_list() {
                 parse_object_kv_list "$str"
                 parse_object_kv_list "$str"
         echo -n '    {
         echo -n '    {
         "HOST": "'$HOST'",
         "HOST": "'$HOST'",
+        "PORT": "'$PORT'",
         "TYPE": "'$type'",
         "TYPE": "'$type'",
         "CHARSETS": "'$CHARSETS'",
         "CHARSETS": "'$CHARSETS'",
         "MAX_DB": "'$MAX_DB'",
         "MAX_DB": "'$MAX_DB'",
@@ -60,13 +64,15 @@ json_list() {
 # SHELL list function
 # SHELL list function
 shell_list() {
 shell_list() {
     IFS=$'\n'
     IFS=$'\n'
-    echo "HOST   TYPE   MAX_DB   DB_USED   SPND   TIME   DATE"
-    echo "----   ----   ------   -------   ----   ----   ----"
+    echo "HOST   PORT   TYPE   MAX_DB   DB_USED   SPND   TIME   DATE"
+    echo "----   ----   ----   ------   -------   ----   ----   ----"
     for type in $(echo $DB_SYSTEM |sed -e 's/,/\n/'); do
     for type in $(echo $DB_SYSTEM |sed -e 's/,/\n/'); do
         if [ -e "$HESTIA/conf/$type.conf" ]; then
         if [ -e "$HESTIA/conf/$type.conf" ]; then
+            # Set default port values if they don't exist in database configuration file.
+            database_set_default_ports
             for str in $(cat $HESTIA/conf/$type.conf); do
             for str in $(cat $HESTIA/conf/$type.conf); do
                 parse_object_kv_list "$str"
                 parse_object_kv_list "$str"
-                echo "$HOST $type $MAX_DB $U_DB_BASES $SUSPENDED $TIME $DATE"
+                echo "$HOST $PORT $type $MAX_DB $U_DB_BASES $SUSPENDED $TIME $DATE"
             done
             done
         fi
         fi
     done
     done
@@ -77,9 +83,11 @@ plain_list() {
     IFS=$'\n'
     IFS=$'\n'
     for type in $(echo $DB_SYSTEM |sed -e 's/,/\n/'); do
     for type in $(echo $DB_SYSTEM |sed -e 's/,/\n/'); do
         if [ -e "$HESTIA/conf/$type.conf" ]; then
         if [ -e "$HESTIA/conf/$type.conf" ]; then
+            # Set default port values if they don't exist in database configuration file.
+            database_set_default_ports
             for str in $(cat $HESTIA/conf/$type.conf); do
             for str in $(cat $HESTIA/conf/$type.conf); do
                 parse_object_kv_list "$str"
                 parse_object_kv_list "$str"
-                echo -ne "$HOST\t$type\t$CHARSETS\t$MAX_DB\t$U_SYS_USERS\t"
+                echo -ne "$HOST\t$PORT\t$type\t$CHARSETS\t$MAX_DB\t$U_SYS_USERS\t"
                 echo -e "$U_DB_BASES\t$TPL\t$SUSPENDED\t$TIME\t$DATE"
                 echo -e "$U_DB_BASES\t$TPL\t$SUSPENDED\t$TIME\t$DATE"
             done
             done
         fi
         fi
@@ -89,13 +97,15 @@ plain_list() {
 # CSV list function
 # CSV list function
 csv_list() {
 csv_list() {
     IFS=$'\n'
     IFS=$'\n'
-    echo -n "HOST,TYPE,CHARSETS,MAX_DB,U_SYS_USERS,"
+    echo -n "HOST,PORT,TYPE,CHARSETS,MAX_DB,U_SYS_USERS,"
     echo "U_DB_BASES,TPL,SUSPENDED,TIME,DATE"
     echo "U_DB_BASES,TPL,SUSPENDED,TIME,DATE"
     for type in $(echo $DB_SYSTEM |sed -e 's/,/\n/'); do
     for type in $(echo $DB_SYSTEM |sed -e 's/,/\n/'); do
         if [ -e "$HESTIA/conf/$type.conf" ]; then
         if [ -e "$HESTIA/conf/$type.conf" ]; then
+            # Set default port values if they don't exist in database configuration file.
+            database_set_default_ports
             for str in $(cat $HESTIA/conf/$type.conf); do
             for str in $(cat $HESTIA/conf/$type.conf); do
                 parse_object_kv_list "$str"
                 parse_object_kv_list "$str"
-                echo -n "$HOST,$type,\"$CHARSETS\",$MAX_DB,\"$U_SYS_USERS\","
+                echo -n "$HOST,$PORT,$type,\"$CHARSETS\",$MAX_DB,\"$U_SYS_USERS\","
                 echo "$U_DB_BASES,$TPL,$SUSPENDED,$TIME,$DATE"
                 echo "$U_DB_BASES,$TPL,$SUSPENDED,$TIME,$DATE"
             done
             done
         fi
         fi
@@ -115,7 +125,6 @@ is_type_format_valid() {
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Action                             #
 #                       Action                             #
 #----------------------------------------------------------#
 #----------------------------------------------------------#

+ 0 - 117
bin/v-list-user-favourites

@@ -1,117 +0,0 @@
-#!/bin/bash
-# info: list user favourites
-# options: USER [FORMAT]
-#
-# The function for getting the list of favourite user objects
-
-
-#----------------------------------------------------------#
-#                    Variable&Function                     #
-#----------------------------------------------------------#
-
-# Argument definition
-user=$1
-format=${2-shell}
-
-# Includes
-source $HESTIA/func/main.sh
-
-# JSON list function
-json_list() {
-    echo '{'
-    echo '    "Favourites": {
-        "USER": "'$USER'",
-        "WEB": "'$WEB'",
-        "DNS": "'$DN'",
-        "DNS_REC": "'$DNS_REC'",
-        "MAIL": "'$MAIL'",
-        "MAIL_ACC": "'$MAIL_ACC'",
-        "DB": "'$DB'",
-        "CRON": "'$CRON'",
-        "BACKUP": "'$BACKUP'",
-        "IP": "'$IP'",
-        "PACKAGE": "'$PACKAGE'",
-        "FIREWALL": "'$FIREWALL'"
-        }'
-    echo '}'
-}
-
-# SHELL list function
-shell_list() {
-    echo "USER:           $USER"
-    echo "WEB:            $WEB"
-    echo "DNS:            $DNS"
-    echo "DNS RECORD:     $DNS_REC"
-    echo "MAIL:           $MAIL"
-    echo "MAIL USER:      $MAIL_ACC"
-    echo "DATABASE:       $DB"
-    echo "CRON:           $CRON"
-    echo "BACKUP:         $BACKUP"
-    echo "IP:             $IP"
-    echo "PACKAGE:        $PACKAGE"
-    echo "FIREWALL:       $FIREWALL"
-}
-
-# PLAIN list function
-plain_list() {
-    echo -ne "$USER\t$WEB\t$DNS\t$DNS_REC\t$MAIL\t$MAIL_ACC\t$DB\t$CRON\t"
-    echo -e "$BACKUP\t$IP\t$PACKAGE\t$FIREWALL"
-}
-
-# CSV list function
-csv_list() {
-    echo -n "USER,WEB,DNS,DNS_REC,MAIL,MAIL_ACC,DB,CRON,BACKUP,IP,"
-    echo "PACKAGE,FIREWALL"
-    echo -n "\"$USER\",\"$WEB\",\"$DNS\",\"$DNS_REC\",\"$MAIL\","
-    echo -n "\"$MAIL_ACC\",\"$DB\",\"$CRON\",\"$BACKUP\",\"$IP\","
-    echo "\"$PACKAGE\",\"$FIREWALL\""
-}
-
-
-#----------------------------------------------------------#
-#                    Verifications                         #
-#----------------------------------------------------------#
-
-# Checking args
-check_args '1' "$#" 'USER [FORMAT]'
-is_format_valid 'user'
-is_object_valid 'user' 'USER' "$user"
-
-
-#----------------------------------------------------------#
-#                       Action                             #
-#----------------------------------------------------------#
-
-# Flushing vars
-USER=''
-WEB=''
-DNS=''
-DNS_REC=''
-MAIL=''
-MAIL_ACC=''
-DB=''
-CRON=''
-BACKUP=''
-IP=''
-PACKAGE=''
-FIREWALL=''
-
-# Parsing user favourites
-if [ -e "$HESTIA/data/users/$user/favourites.conf" ]; then
-    source $HESTIA/data/users/$user/favourites.conf
-fi
-
-# Listing data
-case $format in
-    json)   json_list ;;
-    plain)  plain_list ;;
-    csv)    csv_list ;;
-    shell)  shell_list ;;
-esac
-
-
-#----------------------------------------------------------#
-#                       Hestia                             #
-#----------------------------------------------------------#
-
-exit

+ 62 - 0
bin/v-rebuild-all

@@ -0,0 +1,62 @@
+#!/bin/bash
+# info: rebuild all assets for a specified user
+# options: USER [RESTART]
+#
+# The function rebuilds all assets for a user account:
+# - Web domains
+# - DNS zones
+# - Mail domains
+# - Databases
+# - Cron Jobs
+# - User account configuration
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument definition
+user=$1
+restart=$2
+
+# Includes
+source $HESTIA/func/main.sh
+source $HESTIA/func/rebuild.sh
+source $HESTIA/conf/hestia.conf
+
+# Export sbin
+export PATH=$PATH:/usr/sbin
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+check_args '1' "$#" 'USER [RESTART]'
+is_format_valid 'user'
+is_object_valid 'user' 'USER' "$user"
+is_object_unsuspended 'user' 'USER' "$user"
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Rebuild loop
+for user in $($HESTIA/bin/v-list-sys-users plain); do
+    $BIN/v-rebuild-web-domains $user $restart
+    $BIN/v-rebuild-dns-domains $user $restart
+    $BIN/v-rebuild-mail-domains $user $restart
+    $BIN/v-rebuild-databases $user $restart
+    $BIN/v-rebuild-cron-jobs $user $restart
+    $BIN/v-rebuild-user $user $restart
+done
+
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+# Logging
+log_event "$OK" "$ARGUMENTS"
+
+exit

+ 34 - 3
func/db.sh

@@ -1,19 +1,48 @@
+# Global
+database_set_default_ports() {
+
+    # Set default ports for MySQL and PostgreSQL
+    mysql_default="3306"
+    pgsql_default="5432"
+
+    # Handle missing values for both $PORT and $port
+    # however don't override both at once or custom ports will be overridden.
+
+    if [ -z "$PORT" ]; then 
+        if [ "$type" = 'mysql' ]; then 
+            PORT="$mysql_default"
+        fi
+        if [ "$type" = 'pgsql' ]; then
+            PORT="$pgsql_default"
+        fi
+    fi
+    if [ -z "$port" ]; then 
+        if [ "$type" = 'mysql' ]; then 
+            port="$mysql_default"
+        fi
+        if [ "$type" = 'pgsql' ]; then
+            port="$pgsql_default"
+        fi
+    fi
+}
+
 # MySQL
 # MySQL
 mysql_connect() {
 mysql_connect() {
     host_str=$(grep "HOST='$1'" $HESTIA/conf/mysql.conf)
     host_str=$(grep "HOST='$1'" $HESTIA/conf/mysql.conf)
     parse_object_kv_list "$host_str"
     parse_object_kv_list "$host_str"
+    if [ -z $PORT ]; then PORT=3306; fi
     if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ]; then
     if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ]; then
         echo "Error: mysql config parsing failed"
         echo "Error: mysql config parsing failed"
         log_event "$E_PARSING" "$ARGUMENTS"
         log_event "$E_PARSING" "$ARGUMENTS"
         exit $E_PARSING
         exit $E_PARSING
     fi
     fi
-
     mycnf="$HESTIA/conf/.mysql.$HOST"
     mycnf="$HESTIA/conf/.mysql.$HOST"
     if [ ! -e "$mycnf" ]; then
     if [ ! -e "$mycnf" ]; then
         echo "[client]">$mycnf
         echo "[client]">$mycnf
         echo "host='$HOST'" >> $mycnf
         echo "host='$HOST'" >> $mycnf
         echo "user='$USER'" >> $mycnf
         echo "user='$USER'" >> $mycnf
         echo "password='$PASSWORD'" >> $mycnf
         echo "password='$PASSWORD'" >> $mycnf
+        echo "port='$PORT'" >> $mycnf
         chmod 600 $mycnf
         chmod 600 $mycnf
     else
     else
         mypw=$(grep password $mycnf|cut -f 2 -d \')
         mypw=$(grep password $mycnf|cut -f 2 -d \')
@@ -22,6 +51,7 @@ mysql_connect() {
             echo "host='$HOST'" >> $mycnf
             echo "host='$HOST'" >> $mycnf
             echo "user='$USER'" >> $mycnf
             echo "user='$USER'" >> $mycnf
             echo "password='$PASSWORD'" >> $mycnf
             echo "password='$PASSWORD'" >> $mycnf
+            echo "port='$PORT'" >> $mycnf
             chmod 660 $mycnf
             chmod 660 $mycnf
         fi
         fi
     fi
     fi
@@ -73,13 +103,14 @@ psql_connect() {
     host_str=$(grep "HOST='$1'" $HESTIA/conf/pgsql.conf)
     host_str=$(grep "HOST='$1'" $HESTIA/conf/pgsql.conf)
     parse_object_kv_list "$host_str"
     parse_object_kv_list "$host_str"
     export PGPASSWORD="$PASSWORD"
     export PGPASSWORD="$PASSWORD"
+    if [ -z $PORT ]; then PORT=5432; fi
     if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $TPL ]; then
     if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $TPL ]; then
         echo "Error: postgresql config parsing failed"
         echo "Error: postgresql config parsing failed"
         log_event "$E_PARSING" "$ARGUMENTS"
         log_event "$E_PARSING" "$ARGUMENTS"
         exit $E_PARSING
         exit $E_PARSING
     fi
     fi
-
-    psql -h $HOST -U $USER -c "SELECT VERSION()" > /dev/null 2>/tmp/e.psql
+    
+    psql -h $HOST -U $USER -p $PORT -c "SELECT VERSION()" > /dev/null 2>/tmp/e.psql
     if [ '0' -ne "$?" ]; then
     if [ '0' -ne "$?" ]; then
         if [ "$notify" != 'no' ]; then
         if [ "$notify" != 'no' ]; then
             echo -e "Can't connect to PostgreSQL $HOST\n$(cat /tmp/e.psql)" |\
             echo -e "Can't connect to PostgreSQL $HOST\n$(cat /tmp/e.psql)" |\

+ 0 - 23
web/add/favorite/index.php

@@ -1,23 +0,0 @@
-<?
-
-error_reporting(NULL);
-session_start();
-
-
-include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
-
-// Check token
-//    if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
-//        header('location: /login/');
-//        exit();
-//    }
-
-    // Protect input
-    $v_section = escapeshellarg($_REQUEST['v_section']);
-    $v_unit_id = escapeshellarg($_REQUEST['v_unit_id']);
-
-    $_SESSION['favourites'][strtoupper($_REQUEST['v_section'])][$_REQUEST['v_unit_id']] = 1;
-
-    exec (HESTIA_CMD."v-add-user-favourites ".$_SESSION['user']." ".$v_section." ".$v_unit_id, $output, $return_var);
-//    check_return_code($return_var,$output);
-?>

+ 1 - 1
web/bulk/db/index.php

@@ -17,7 +17,7 @@ $action = $_POST['action'];
 
 
 if ($_SESSION['user'] == 'admin') {
 if ($_SESSION['user'] == 'admin') {
     switch ($action) {
     switch ($action) {
-        case 'rebuild': $cmd='v-rebuild-web-domain';
+        case 'rebuild': $cmd='v-rebuild-database';
             break;
             break;
         case 'delete': $cmd='v-delete-database';
         case 'delete': $cmd='v-delete-database';
             break;
             break;

+ 1 - 1
web/bulk/user/index.php

@@ -25,7 +25,7 @@ if ($_SESSION['user'] == 'admin') {
             break;
             break;
         case 'update counters': $cmd='v-update-user-counters';
         case 'update counters': $cmd='v-update-user-counters';
             break;
             break;
-        case 'rebuild': $cmd='v-rebuild-user'; $restart = 'no';
+        case 'rebuild': $cmd='v-rebuild-all'; $restart = 'no';
             break;
             break;
         case 'rebuild web': $cmd='v-rebuild-web-domains'; $restart = 'no';
         case 'rebuild web': $cmd='v-rebuild-web-domains'; $restart = 'no';
             break;
             break;

+ 0 - 15
web/delete/favorite/index.php

@@ -1,15 +0,0 @@
-<?php
-
-    error_reporting(NULL);
-    session_start();
-
-    include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
-
-    unset($_SESSION['favourites'][strtoupper($_REQUEST['v_section'])][$_REQUEST['v_unit_id']]);
-
-    $v_section = escapeshellarg($_REQUEST['v_section']);
-    $v_unit_id = escapeshellarg($_REQUEST['v_unit_id']);
-
-    exec (HESTIA_CMD."v-delete-user-favourites ".$_SESSION['user']." ".$v_section." ".$v_unit_id, $output, $return_var);
-//    check_return_code($return_var,$output);
-?>

+ 21 - 2
web/edit/server/index.php

@@ -254,10 +254,29 @@ if (!empty($_POST['save'])) {
         }
         }
     }
     }
 
 
+   // Set File Manager support
+    if (empty($_SESSION['error_msg'])) {
+        if ((!empty($_POST['v_filemanager'])) && ($_SESSION['FILE_MANAGER'] != $_POST['v_filemanager'])) {
+            if ($_POST['v_filemanager'] == 'yes') {
+                $_POST['v_filemanager'] == 'true';
+                exec (HESTIA_CMD."v-add-sys-filemanager", $output, $return_var);
+                check_return_code($return_var,$output);
+                unset($output);
+                if (empty($_SESSION['error_msg'])) $_SESSION['FILE_MANAGER'] = 'yes';
+            } else {
+                $_POST['v_filemanager'] == 'false';
+                exec (HESTIA_CMD."v-delete-sys-filemanager", $output, $return_var);
+                check_return_code($return_var,$output);
+                unset($output);
+                if (empty($_SESSION['error_msg'])) $_SESSION['FILE_MANAGER'] = 'no';
+            }
+        }
+    }
+
     // Set disk_quota support
     // Set disk_quota support
     if (empty($_SESSION['error_msg'])) {
     if (empty($_SESSION['error_msg'])) {
         if ((!empty($_POST['v_quota'])) && ($_SESSION['DISK_QUOTA'] != $_POST['v_quota'])) {
         if ((!empty($_POST['v_quota'])) && ($_SESSION['DISK_QUOTA'] != $_POST['v_quota'])) {
-            if($_POST['v_quota'] == 'yes') {
+            if ($_POST['v_quota'] == 'yes') {
                 exec (HESTIA_CMD."v-add-sys-quota", $output, $return_var);
                 exec (HESTIA_CMD."v-add-sys-quota", $output, $return_var);
                 check_return_code($return_var,$output);
                 check_return_code($return_var,$output);
                 unset($output);
                 unset($output);
@@ -276,7 +295,7 @@ if (!empty($_POST['save'])) {
         if ($_SESSION['FIREWALL_SYSTEM'] == 'iptables') $v_firewall = 'yes';
         if ($_SESSION['FIREWALL_SYSTEM'] == 'iptables') $v_firewall = 'yes';
         if ($_SESSION['FIREWALL_SYSTEM'] != 'iptables') $v_firewall = 'no';
         if ($_SESSION['FIREWALL_SYSTEM'] != 'iptables') $v_firewall = 'no';
         if ((!empty($_POST['v_firewall'])) && ($v_firewall != $_POST['v_firewall'])) {
         if ((!empty($_POST['v_firewall'])) && ($v_firewall != $_POST['v_firewall'])) {
-            if($_POST['v_firewall'] == 'yes') {
+            if ($_POST['v_firewall'] == 'yes') {
                 exec (HESTIA_CMD."v-add-sys-firewall", $output, $return_var);
                 exec (HESTIA_CMD."v-add-sys-firewall", $output, $return_var);
                 check_return_code($return_var,$output);
                 check_return_code($return_var,$output);
                 unset($output);
                 unset($output);

+ 0 - 20
web/inc/main.php

@@ -103,26 +103,6 @@ if (isset($_SESSION['look']) && ( $_SESSION['look'] != 'admin' )) {
     $user = $_SESSION['look'];
     $user = $_SESSION['look'];
 }
 }
 
 
-function get_favourites(){
-    exec (HESTIA_CMD."v-list-user-favourites ".$_SESSION['user']." json", $output, $return_var);
-//    $data = json_decode(implode('', $output).'}', true);
-    $data = json_decode(implode('', $output), true);
-    $data = array_reverse($data,true);
-    $favourites = array();
-
-    foreach($data['Favourites'] as $key => $favourite){
-        $favourites[$key] = array();
-
-        $items = explode(',', $favourite);
-        foreach($items as $item){
-            if($item)
-                $favourites[$key][trim($item)] = 1;
-        }
-    }
-
-    $_SESSION['favourites'] = $favourites;
-}
-
 
 
 function check_error($return_var) {
 function check_error($return_var) {
     if ( $return_var > 0 ) {
     if ( $return_var > 0 ) {

+ 0 - 33
web/js/init.js

@@ -130,39 +130,6 @@ $(document).ready(function(){
                 }).appendTo(".l-center.units");
                 }).appendTo(".l-center.units");
               });
               });
 
 
-
-
-            // STARS
-
-              $('.l-unit .l-icon-star').click(function(){
-                var l_unit = $(this).parents('.l-unit');
-
-                if(l_unit.hasClass('l-unit--starred')){
-                  // removing star
-
-                  $.ajax({
-                    method: "POST",
-                    url: "/delete/favorite/index.php",
-                    data: { v_section: l_unit.attr('v_section'), v_unit_id: l_unit.attr('v_unit_id') }
-                  });
-
-                  l_unit.attr({'sort-star': 0});
-                  l_unit.removeClass('l-unit--starred');
-                }
-                else{
-                  $.ajax({
-                    method: "POST",
-                    url: "/add/favorite/index.php",
-                    data: { v_unit_id: l_unit.attr('v_unit_id'), v_section: l_unit.attr('v_section') }
-                  });
-
-                  l_unit.attr({'sort-star': 1});
-                  l_unit.addClass('l-unit--starred');
-                }
-              });
-
-
-
               // Shortcuts
               // Shortcuts
 
 
               shortcut.add("Ctrl+Enter", function(){
               shortcut.add("Ctrl+Enter", function(){

+ 0 - 24
web/list/favorites/index.php

@@ -1,24 +0,0 @@
-<?php
-error_reporting(NULL);
-    include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
-
-    echo '<br> Favorites: <br>';
-
-    // Data
-    exec (HESTIA_CMD."v-list-user-favourites ".$_SESSION['user']." json", $output, $return_var);
-
-
-//    print_r(implode('', $output));
-//    $json = '{ "Favourites": { "USER": "", "WEB": "bulletfarm.com", "DNS": "", "MAIL": "", "DB": "", "CRON": "", "BACKUP": "", "IP": "", "PACKAGE": "", "FIREWALL": ""}}';
-//    $data = json_decode($json, true);
-
-
-    $data = json_decode(implode('', $output).'}', true);
-    $data = array_reverse($data,true);
-
-    print_r($data);
-//    $data = array_reverse($data,true);
-
-//    $data = json_decode(implode('', $output), true);
-
-?>

+ 74 - 70
web/login/index.php

@@ -2,18 +2,18 @@
 
 
 define('NO_AUTH_REQUIRED',true);
 define('NO_AUTH_REQUIRED',true);
 
 
-
 // Main include
 // Main include
 include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
 include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
 
 
-
-$TAB = 'LOGIN';
+$TAB = 'login';
 
 
 // Logout
 // Logout
 if (isset($_GET['logout'])) {
 if (isset($_GET['logout'])) {
     session_destroy();
     session_destroy();
 }
 }
 
 
+
+
 // Login as someone else
 // Login as someone else
 if (isset($_SESSION['user'])) {
 if (isset($_SESSION['user'])) {
     if ($_SESSION['user'] == 'admin' && !empty($_GET['loginas'])) {
     if ($_SESSION['user'] == 'admin' && !empty($_GET['loginas'])) {
@@ -33,27 +33,25 @@ if (isset($_SESSION['user'])) {
     exit;
     exit;
 }
 }
 
 
-// Basic auth
-if (isset($_POST['user']) && isset($_POST['password'])) {
+function authenticate_user(){
     if(isset($_SESSION['token']) && isset($_POST['token']) && $_POST['token'] == $_SESSION['token']) {
     if(isset($_SESSION['token']) && isset($_POST['token']) && $_POST['token'] == $_SESSION['token']) {
-        $v_user = escapeshellarg($_POST['user']);
-        $v_ip = escapeshellarg($_SERVER['REMOTE_ADDR']);
-        if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])){
-            if(!empty($_SERVER['HTTP_CF_CONNECTING_IP'])){
-                $v_ip = escapeshellarg($_SERVER['HTTP_CF_CONNECTING_IP']);
-            }
+    $v_user = escapeshellarg($_POST['user']);
+    $v_ip = escapeshellarg($_SERVER['REMOTE_ADDR']);
+    if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])){
+        if(!empty($_SERVER['HTTP_CF_CONNECTING_IP'])){
+            $v_ip = escapeshellarg($_SERVER['HTTP_CF_CONNECTING_IP']);
         }
         }
-        if (isset($_POST['twofa'])) {
-            $v_twofa = escapeshellarg($_POST['twofa']);
-        }
-
-        // Get user's salt
-        $output = '';
-        exec (HESTIA_CMD."v-get-user-salt ".$v_user." ".$v_ip." json" , $output, $return_var);
-        $pam = json_decode(implode('', $output), true);
-        if ( $return_var > 0 ) {
-            sleep(5);
-            $ERROR = "<a class=\"error\">".__('Invalid username or password')."</a>";
+    } 
+     // Get user's salt
+    $output = '';
+    exec (HESTIA_CMD."v-get-user-salt ".$v_user." ".$v_ip." json" , $output, $return_var);
+    $pam = json_decode(implode('', $output), true);
+    if ( $return_var > 0 ) {
+        sleep(2);
+        unset($_POST['password']);
+        unset($_POST['user']);
+        $error = "<a class=\"error\">".__('Invalid username or password')."</a>";
+        return $error;
         } else {
         } else {
             $user = $_POST['user'];
             $user = $_POST['user'];
             $password = $_POST['password'];
             $password = $_POST['password'];
@@ -86,8 +84,10 @@ if (isset($_POST['user']) && isset($_POST['password'])) {
 
 
             // Check API answer
             // Check API answer
             if ( $return_var > 0 ) {
             if ( $return_var > 0 ) {
-                sleep(5);
-                $ERROR = "<a class=\"error\">".__('Invalid username or password')."</a>";
+                sleep(2);
+                unset($_POST['password']);
+                $error = "<a class=\"error\">".__('Invalid username or password')."</a>";
+                return $error;
             } else {
             } else {
 
 
                 // Make root admin user
                 // Make root admin user
@@ -99,64 +99,60 @@ if (isset($_POST['user']) && isset($_POST['password'])) {
 
 
                 // Check if 2FA is active
                 // Check if 2FA is active
                 if ($data[$_POST['user']]['TWOFA'] != '') {
                 if ($data[$_POST['user']]['TWOFA'] != '') {
-                    if (isset($v_twofa)){
-                        $v_twofa = str_replace(' ', '', $v_twofa);
+                   if (empty($_POST['twofa'])){
+                       return false;
+                   }else{
+                        $v_twofa = $_POST['twofa'];
                         exec(HESTIA_CMD ."v-check-user-2fa ".$v_user." ".$v_twofa, $output, $return_var);
                         exec(HESTIA_CMD ."v-check-user-2fa ".$v_user." ".$v_twofa, $output, $return_var);
                         unset($output);
                         unset($output);
                         if ( $return_var > 0 ) {
                         if ( $return_var > 0 ) {
-                            sleep(1);
-                            $ERROR = "<a class=\"error\">".__('Invalid or missing 2FA token')."</a>";
+                            sleep(2);
+                            $error = "<a class=\"error\">".__('Invalid or missing 2FA token')."</a>";
+                            return $error;
+                            unset($_POST['twofa']);
                         }
                         }
-                    } else {
-                        sleep(1);
-                        $ERROR = "<a class=\"error\">".__('Invalid or missing 2FA token')."</a>";
-                    }
+                   }
+                }
+                // Define session user
+                $_SESSION['user'] = key($data);
+                $v_user = $_SESSION['user'];
+
+                // Define language
+                $output = '';
+                exec (HESTIA_CMD."v-list-sys-languages json", $output, $return_var);
+                $languages = json_decode(implode('', $output), true);
+                if (in_array($data[$v_user]['LANGUAGE'], $languages)){
+                    $_SESSION['language'] = $data[$v_user]['LANGUAGE'];
+                } else {
+                    $_SESSION['language'] = 'en';
                 }
                 }
 
 
-                // Check if 2FA was successfully
-                if ( ! isset($v_twofa) || $ERROR == '' ) {
-                    // Define session user
-                    $_SESSION['user'] = key($data);
-                    $v_user = $_SESSION['user'];
-
-                    // Get user favorites
-                    get_favourites();
-
-                    // Define language
-                    $output = '';
-                    exec (HESTIA_CMD."v-list-sys-languages json", $output, $return_var);
-                    $languages = json_decode(implode('', $output), true);
-                    if (in_array($data[$v_user]['LANGUAGE'], $languages)){
-                        $_SESSION['language'] = $data[$v_user]['LANGUAGE'];
-                    } else {
-                        $_SESSION['language'] = 'en';
-                    }
-
-                    // Regenerate session id to prevent session fixation
-                    session_regenerate_id();
-
-                    // Redirect request to control panel interface
-                    if (!empty($_SESSION['request_uri'])) {
-                        header("Location: ".$_SESSION['request_uri']);
-                        unset($_SESSION['request_uri']);
-                        exit;
+                // Regenerate session id to prevent session fixation
+                session_regenerate_id();
+
+                // Redirect request to control panel interface
+                if (!empty($_SESSION['request_uri'])) {
+                    header("Location: ".$_SESSION['request_uri']);
+                    unset($_SESSION['request_uri']);
+                    exit;
+                } else {
+                    if ($v_user == 'admin') {
+                        header("Location: /list/user/");
                     } else {
                     } else {
-                        if ($v_user == 'admin') {
-                            header("Location: /list/user/");
-                        } else {
-                            header("Location: /list/web/");
-                        }
-                        exit;
+                        header("Location: /list/web/");
                     }
                     }
+                    exit;
                 }
                 }
             }
             }
         }
         }
-    } else {
-        sleep(1);
-        $ERROR = "<a class=\"error\">".__('Invalid or missing token')."</a>";
     }
     }
 }
 }
 
 
+if (!empty($_POST['user']) && !empty($_POST['password']) && !empty($_POST['twofa'])){
+    $error = authenticate_user(); 
+} else if (!empty($_POST['user']) && !empty($_POST['password'])) {
+    $error = authenticate_user();    
+}
 // Check system configuration
 // Check system configuration
 load_hestia_config();
 load_hestia_config();
 
 
@@ -180,7 +176,15 @@ if (empty($_SESSION['language'])) {
 
 
 // Generate CSRF token
 // Generate CSRF token
 $_SESSION['token'] = md5(uniqid(mt_rand(), true));
 $_SESSION['token'] = md5(uniqid(mt_rand(), true));
-
 require_once($_SERVER['DOCUMENT_ROOT'].'/inc/i18n/'.$_SESSION['language'].'.php');
 require_once($_SERVER['DOCUMENT_ROOT'].'/inc/i18n/'.$_SESSION['language'].'.php');
 require_once('../templates/header.html');
 require_once('../templates/header.html');
-require_once('../templates/login.html');
+if (empty($_POST['user'])) {
+    require_once('../templates/login.html');
+}else if (empty($_POST['password'])) {
+    require_once('../templates/login_1.html');
+}else if (empty($_POST['twofa'])) {
+    require_once('../templates/login_2.html');    
+} else {
+    require_once('../templates/login.html');
+}
+?>

+ 14 - 0
web/templates/admin/edit_server.html

@@ -820,6 +820,20 @@
                             <tr>
                             <tr>
                                 <td class="vst-text input-label step-left">
                                 <td class="vst-text input-label step-left">
                                     <table style="display:<?php if (empty($v_adv)) echo 'none';?> ;" id="hestia">
                                     <table style="display:<?php if (empty($v_adv)) echo 'none';?> ;" id="hestia">
+                                        <tr>
+                                            <td class="vst-text">
+                                                <?php print __('Fm');?>
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                            <td>
+                                                <select class="vst-list" name="v_filemanager">
+                                                    <option value='no'><?php print __('no'); ?></option>
+                                                    <option value='yes' <?php if($_SESSION['FILE_MANAGER'] == 'true') echo 'selected' ?> ><?php print __('yes'); ?></option>
+                                                </select>
+                                                <br><br>
+                                            </td>
+                                        </tr>
                                         <tr>
                                         <tr>
                                             <td class="vst-text">
                                             <td class="vst-text">
                                                 <?php print __('FileSystem Disk Quota');?>
                                                 <?php print __('FileSystem Disk Quota');?>

+ 8 - 55
web/templates/login.html

@@ -17,52 +17,22 @@
                                             </td>
                                             </td>
                                         </tr>
                                         </tr>
                                         <tr>
                                         <tr>
-                                            <td style="padding: 12px 0 0 2px;">
+                                            <td style="padding: 12px 0 5px 2px;">
                                                 <?php print __('Username');?>
                                                 <?php print __('Username');?>
                                             </td>
                                             </td>
                                         </tr>
                                         </tr>
                                         <tr>
                                         <tr>
                                             <td>
                                             <td>
-                                                <input tabindex="1" type="text" size="20px" style="width:240px;" name="user" class="vst-input">
+                                                <input tabindex="1" type="text" size="20px" style="width:240px;" name="user" class="vst-input" autofocus />
                                             </td>
                                             </td>
                                         </tr>
                                         </tr>
                                         <tr>
                                         <tr>
-                                            <td style="padding: 12px 0 0 2px;">
-                                                <?php print __('Password');?>
-                                                <div style="padding:0 6px 0px 14px; float:right;">
-                                                    <a tabindex="5" class="vst-advanced" href="/reset/">
-                                                        <?php print __('forgot password');?>
-                                                    </a>
-                                                </div>
+                                            <td height="10px">
                                             </td>
                                             </td>
                                         </tr>
                                         </tr>
                                         <tr>
                                         <tr>
-                                            <td>
-                                                <input tabindex="2" type="password" size="20px"  style="width:240px;" name="password" class="vst-input">
-                                            </td>
-                                        </tr>
-                                        <tr class="twofa" style="display:none;">
-                                            <td style="padding-top: 12px; padding-left:2px;">
-                                                <?php print __('2FA Token');?>
-                                                <div style="padding:0 6px 0px 14px; float:right;">
-                                                    <a tabindex="5" class="vst-advanced" href="/reset2fa/">
-                                                        <?php print __('Forgot token');?>
-                                                    </a>
-                                                </div>
-                                            </td>
-                                        </tr>
-                                        <tr class="twofa" style="display:none;">
-                                            <td>
-                                                <input tabindex="3" type="text" size="20px" style="width:240px;" name="twofa" class="vst-input">
-                                            </td>
-                                        </tr>
-                                        <tr>
-                                            <td height="28px">
-                                            </td>
-                                        </tr>
-                                        <tr>
-                                            <td style="padding: 0 0 12px 0;">
-                                                    <button tabindex="3" type="submit" class="button"><?php print __('Log in');?>&nbsp;&nbsp;&nbsp;<i class="fas fa-sign-in-alt"></i></button>
+                                            <td style="padding: 0 0 5px 0;">
+                                                <button tabindex="3" type="submit" class="button"><?php print __('Next');?>&nbsp;&nbsp;&nbsp;<i class="fas fa-sign-in-alt"></i></button>
                                             </td>
                                             </td>
                                         </tr>
                                         </tr>
                                     </table>
                                     </table>
@@ -72,7 +42,7 @@
                         <tr>
                         <tr>
                             <td colspan=2>
                             <td colspan=2>
                                 <div class="login-bottom">
                                 <div class="login-bottom">
-                                    <div style="height:20px"><?php if (isset($ERROR)) echo $ERROR ?></div>
+                                    <div style="height:20px"><?php if (isset($error)) echo $error ?></div>
                                 </div>
                                 </div>
                             </td>
                             </td>
                         </tr>
                         </tr>
@@ -80,23 +50,6 @@
                 </tr>
                 </tr>
             </table>
             </table>
         </center>
         </center>
-        <script type="text/javascript">
-            $(document).ready(function () {
-                $('#form_login').on('input', 'input[name="user"]', function() {
-                    var username = this.value;
-                    $.ajax({
-                        type: 'GET',
-                        url: '/inc/2fa/active.php?user=' + username,
-                        complete: function(xhr) {
-                            if(xhr.status == '200'){
-                                $('.twofa').show();
-                            }else if(xhr.status == '404'){
-                                $('.twofa').hide();
-                            }
-                        }
-                    });
-                });
-            });
-        </script>
+
     </body>
     </body>
-</html>
+</html>

+ 62 - 0
web/templates/login_1.html

@@ -0,0 +1,62 @@
+        <center>
+            <table class="login">
+                <tr>
+                    <td>
+                        <table>
+                            <tr>
+                                <td style="padding: 22px 30px 0 42px; height: 280px; width: 170px;">
+                                    <a href="/"><img border=0 src="/images/logo.png" alt="<?=__('Hestia Control Panel');?>" style="margin: 20px; margin-top: 64px;" /></a>
+                                </td>
+                                <td style="padding: 40px 60px 0 0;" class="animated fadeIn">
+                                    <form method="post" action="/login/" id="form_login">
+                                    <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
+                                    <input type="hidden" name="user" value="<?php echo $_POST['user']; ?>">
+                                    
+                                    <table class="login-box">
+                                        <tr>
+                                            <td style="padding: 12px 0 0 2px;" class="login-welcome">
+                                                <?php print __('Welcome');?> <?php echo $_POST['user']; ?>!
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                           <td style="padding: 12px 0 0 2px;">
+                                                <?php print __('Password');?>
+                                                <div style="padding:0 6px 0px 14px; float:right;">
+                                                    <a tabindex="5" class="vst-advanced" href="/reset/">
+                                                        <?php print __('forgot password');?>
+                                                    </a>
+                                                </div>
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                            <td>
+                                                <input tabindex="2" type="password" size="20px"  style="width:240px;" name="password" class="vst-input" autofocus />
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                            <td height="10px">
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                            <td style="padding: 0 0 5px 0;">
+                                                <button tabindex="3" type="submit" class="button"><?php print __('Login');?>&nbsp;&nbsp;&nbsp;<i class="fas fa-sign-in-alt"></i></button>&nbsp;&nbsp;
+                                                <input type="button" class="button cancel" value="<?php print __('Back');?>" onclick="location.href='/login/'">
+                                            </td>
+                                        </tr>
+                                    </table>
+                                </form>
+                            </td>
+                        </tr>
+                        <tr>
+                            <td colspan=2>
+                                <div class="login-bottom">
+                                    <div style="height:20px"><?php if (isset($ERROR)) echo $ERROR ?></div>
+                                </div>
+                            </td>
+                        </tr>
+                    </table>
+                </tr>
+            </table>
+        </center>
+    </body>
+</html>

+ 61 - 0
web/templates/login_2.html

@@ -0,0 +1,61 @@
+        <center>
+            <table class="login">
+                <tr>
+                    <td>
+                        <table>
+                            <tr>
+                                <td style="padding: 22px 30px 0 42px; height: 280px; width: 170px;">
+                                    <a href="/"><img border=0 src="/images/logo.png" alt="<?=__('Hestia Control Panel');?>" style="margin: 20px; margin-top: 64px;" /></a>
+                                </td>
+                                <td style="padding: 40px 60px 0 0;" class="animated fadeIn">
+                                    <form method="post" action="/login/" id="form_login">
+                                    <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
+                                    <input type="hidden" name="user" value="<?php echo $_POST['user']; ?>">
+                                    <input type="hidden" name="password" value="<?php echo $_POST['password']; ?>">
+                                    <table class="login-box">
+                                        <tr>
+                                            <td style="padding: 12px 0 0 2px;" class="login-welcome">
+                                                <?php print __('2 Factor Authentication');?>
+                                            </td>
+                                        </tr>
+                                        <tr class="twofa">
+                                            <td style="padding-top: 12px; padding-left:2px;">
+                                                <?php print __('2FA Token');?>
+                                                <div style="padding:0 6px 0px 14px; float:right;">
+                                                    <a tabindex="5" class="vst-advanced" href="/reset2fa/">
+                                                        <?php print __('Forgot token');?>
+                                                    </a>
+                                                </div>
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                            <td>
+                                                <input tabindex="2" type="" size="20px"  style="width:240px;" name="twofa" class="vst-input" autofocus />
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                            <td height="10px">
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                            <td style="padding: 0 0 5px 0;">
+                                                <button tabindex="3" type="submit" class="button"><?php print __('Login');?>&nbsp;&nbsp;&nbsp;<i class="fas fa-sign-in-alt"></i></button>
+                                            </td>
+                                        </tr>
+                                    </table>
+                                </form>
+                            </td>
+                        </tr>
+                        <tr>
+                            <td colspan=2>
+                                <div class="login-bottom">
+                                    <div style="height:20px"><?php if (isset($ERROR)) echo $ERROR ?></div>
+                                </div>
+                            </td>
+                        </tr>
+                    </table>
+                </tr>
+            </table>
+        </center>
+    </body>
+</html>

+ 2 - 2
web/templates/reset2fa.html

@@ -56,8 +56,8 @@
                                             </tr>
                                             </tr>
                                             <tr>
                                             <tr>
                                                 <td style="padding: 20px 0 12px 0;">
                                                 <td style="padding: 20px 0 12px 0;">
-                                                    <input type="button" class="button cancel" value="<?php print __('Back');?>" onclick="location.href='/login/'">&nbsp;&nbsp;
-                                                    <input tabindex="2" type="submit" value="<?php print __('Submit');?>" class="button">
+                                                    <input tabindex="2" type="submit" value="<?php print __('Submit');?>" class="button">&nbsp;&nbsp;
+                                                    <input type="button" class="button cancel" value="<?php print __('Back');?>" onclick="location.href='/login/'">
                                                 </td>
                                                 </td>
                                             </tr>
                                             </tr>
                                         </table>
                                         </table>

+ 2 - 2
web/templates/reset_1.html

@@ -42,8 +42,8 @@
                                             </tr>
                                             </tr>
                                             <tr>
                                             <tr>
                                                 <td style="padding: 20px 0 12px 0;">
                                                 <td style="padding: 20px 0 12px 0;">
-                                                    <input type="button" class="button cancel" value="<?php print __('Back');?>" onclick="location.href='/login/'">&nbsp;&nbsp;
-                                                    <input tabindex="2" type="submit" value="<?php print __('Submit');?>" class="button">
+                                                    <input tabindex="2" type="submit" value="<?php print __('Submit');?>" class="button">&nbsp;&nbsp;
+                                                    <input type="button" class="button cancel" value="<?php print __('Back');?>" onclick="location.href='/login/'">
                                                 </td>
                                                 </td>
                                             </tr>
                                             </tr>
                                         </table>
                                         </table>

+ 2 - 2
web/templates/reset_2.html

@@ -32,8 +32,8 @@
                                             </tr>
                                             </tr>
                                             <tr>
                                             <tr>
                                                 <td style="padding: 20px 0 12px 0;">
                                                 <td style="padding: 20px 0 12px 0;">
-                                                    <input type="button" class="button cancel" value="<?php print __('Back');?>" onclick="location.href='/reset/'">&nbsp;&nbsp;
-                                                    <input tabindex="2" type="submit" value="<?php print __('Confirm');?>" class="button">
+                                                    <input tabindex="2" type="submit" value="<?php print __('Confirm');?>" class="button">&nbsp;&nbsp;
+                                                    <input type="button" class="button cancel" value="<?php print __('Back');?>" onclick="location.href='/reset/'">
                                                 </td>
                                                 </td>
                                             </tr>
                                             </tr>
                                         </table>
                                         </table>

+ 2 - 2
web/templates/reset_3.html

@@ -40,8 +40,8 @@
                                             </tr>
                                             </tr>
                                             <tr>
                                             <tr>
                                                 <td style="padding: 20px 0 12px 0;">
                                                 <td style="padding: 20px 0 12px 0;">
-                                                    <input type="button" class="button cancel" value="<?php print __('Back');?>" onclick="location.href='/login/'">&nbsp;&nbsp;
-                                                    <input tabindex="3" type="submit" value="<?php print __('Reset');?>" class="button">
+                                                    <input tabindex="3" type="submit" value="<?php print __('Reset');?>" class="button">&nbsp;&nbsp;
+                                                    <input type="button" class="button cancel" value="<?php print __('Back');?>" onclick="location.href='/login/'">
                                                 </td>
                                                 </td>
                                             </tr>
                                             </tr>
                                         </table>
                                         </table>