@@ -18,9 +18,10 @@ type=$1
1818host=$2
1919dbuser=$3
2020password=$4 ; HIDE=4
21- max_db=${6-500}
22- charsets=${7-UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8}
23- template=${8-template1}
21+ max_db=${5-500}
22+ charsets=${6}
23+ template=${7}
24+ port=${8}
2425
2526# Includes
2627source $HESTIA /func/main.sh
@@ -33,6 +34,8 @@ is_mysql_host_alive() {
3334 echo " host='$HOST '" >> $mycnf
3435 echo " user='$USER '" >> $mycnf
3536 echo " password='$PASSWORD '" >> $mycnf
37+ echo " port='$PORT '" >> $mycnf
38+
3639 chmod 600 $mycnf
3740 mysql --defaults-file=$mycnf -e ' SELECT VERSION()' > /dev/null 2>&1
3841 rm $mycnf
@@ -45,7 +48,7 @@ is_mysql_host_alive() {
4548
4649is_pgsql_host_alive () {
4750 export PGPASSWORD=" $dbpass "
48- psql -h $host -U $dbuser -c " SELECT VERSION()" > /dev/null 2>&1
51+ psql -h $host -U $dbuser -p $port - c " SELECT VERSION()" > /dev/null 2>&1
4952 if [ ' 0' -ne " $? " ]; then
5053 echo " Error: PostgreSQL connection to $host failed"
5154 log_event " $E_CONNECT " " $ARGUMENTS "
@@ -58,14 +61,23 @@ is_pgsql_host_alive() {
5861# Verifications #
5962# ----------------------------------------------------------#
6063
61- args_usage=' TYPE HOST DBUSER DBPASS [MAX_DB] [CHARSETS] [TPL]'
64+ args_usage=' TYPE HOST DBUSER DBPASS [MAX_DB] [CHARSETS] [TPL] [PORT] '
6265check_args ' 4' " $# " " $args_usage "
63- is_format_valid ' host' ' dbuser' ' max_db' ' charsets' ' template'
66+
67+ if [ -z $charsets ]; then charsets=" UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8" ; fi
68+ if [ -z $template ]; then template=" template1" ; fi
69+ if [ -z $port ]; then
70+ if [ $type = ' mysql' ]; then port=" 3306" ; fi
71+ if [ $type = ' pgsql' ]; then port=" 5432" ; fi
72+ fi
73+
74+ is_format_valid ' host' ' dbuser' ' max_db' ' charsets' ' template' ' port'
6475# is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
6576# is_type_valid "$DB_SYSTEM" "$type"
6677is_dbhost_new
6778is_password_valid
6879dbpass=" $password "
80+
6981case $type in
7082 mysql) is_mysql_host_alive ;;
7183 pgsql) is_pgsql_host_alive ;;
@@ -85,11 +97,11 @@ date=$(echo "$time_n_date" |cut -f 2 -d \ )
8597case $type in
8698 mysql) str=" HOST='$host ' USER='$dbuser ' PASSWORD='$dbpass '" ;
8799 str=" $str CHARSETS='$charsets ' MAX_DB='$max_db ' U_SYS_USERS=''" ;
88- str=" $str U_DB_BASES='0' SUSPENDED='no' TIME='$time ' DATE='$date '" ;;
100+ str=" $str U_DB_BASES='0' SUSPENDED='no' TIME='$time ' DATE='$date ' PORT=' $port ' " ;;
89101 pgsql) str=" HOST='$host ' USER='$dbuser ' PASSWORD='$dbpass '" ;
90102 str=" $str CHARSETS='$charsets ' TPL='$template ' MAX_DB='$max_db '" ;
91103 str=" $str U_SYS_USERS='' U_DB_BASES='0' SUSPENDED='no'" ;
92- str=" $str TIME='$time ' DATE='$date '" ;;
104+ str=" $str TIME='$time ' DATE='$date ' PORT=' $port " ;;
93105esac
94106
95107
0 commit comments