Skip to content

Commit 3371762

Browse files
committed
Refactoring stage III (db)
1 parent 4fa3013 commit 3371762

21 files changed

+500
-895
lines changed
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: add database
3-
# options: user db db_user db_password type [host] [encoding]
3+
# options: user database dbuser dbpass type [host] [charset]
44
#
55
# The function creates the database concatenating username and user_db.
66
# Supported yypes of databases you can get using v_list_sys_config script.
@@ -22,8 +22,8 @@ dbuser="$user"_"$3"
2222
dbpass=$4
2323
type=$5
2424
host=$6
25-
encoding=${7-UTF8}
26-
encoding=$(echo "$encoding" |tr '[:lower:]' '[:upper:]')
25+
charset=${7-UTF8}
26+
charset=$(echo "$charset" |tr '[:lower:]' '[:upper:]')
2727

2828
# Includes
2929
source $VESTA/conf/vesta.conf
@@ -35,16 +35,17 @@ source $VESTA/func/db.sh
3535
# Verifications #
3636
#----------------------------------------------------------#
3737

38-
check_args '5' "$#" 'user db dbuser dbpass type [host] [encoding]'
39-
validate_format 'user' 'database' 'dbuser' 'dbpass' 'encoding'
38+
check_args '5' "$#" 'user database dbuser dbpass type [host] [charset]'
39+
validate_format 'user' 'database' 'dbuser' 'dbpass' 'charset'
4040
is_system_enabled "$DB_SYSTEM"
4141
is_type_valid "$DB_SYSTEM" "$type"
4242
is_object_valid 'user' 'USER' "$user"
4343
is_object_unsuspended 'user' 'USER' "$user"
4444
is_object_free 'db' 'DB' "$database"
4545
get_next_dbhost
4646
is_object_valid "../../../conf/$type" 'HOST' "$host"
47-
is_db_encoding_valid
47+
is_object_unsuspended "../../../conf/$type" 'HOST' "$host"
48+
is_charset_valid
4849
is_package_full 'DATABASES'
4950

5051
#----------------------------------------------------------#
@@ -53,8 +54,8 @@ is_package_full 'DATABASES'
5354

5455
# Switching on db type
5556
case $type in
56-
mysql) create_db_mysql ;;
57-
pgsql) create_db_pgsql ;;
57+
mysql) add_mysql_database ;;
58+
pgsql) add_pgsql_database ;;
5859
esac
5960

6061

@@ -67,15 +68,15 @@ increase_dbhost_values
6768
increase_user_value "$user" '$U_DATABASES'
6869

6970
# Adding db to db conf
70-
v_str="DB='$database' USER='$dbuser' HOST='$host' TYPE='$type'"
71-
v_str="$v_str CHARSET='$encoding' U_DISK='0' SUSPENDED='no' TIME='$TIME'"
72-
v_str="$v_str DATE='$DATE'"
73-
echo "$v_str" >> $USER_DATA/db.conf
71+
str="DB='$database' DBUSER='$dbuser' HOST='$host' TYPE='$type'"
72+
str="$str CHARSET='$charset' U_DISK='0' SUSPENDED='no' TIME='$TIME'"
73+
str="$str DATE='$DATE'"
74+
echo "$str" >> $USER_DATA/db.conf
7475
chmod 660 $USER_DATA/db.conf
7576

7677
# Hiding password
7778
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
78-
EVENT="$EVENT ARGUMENTS='$user $database $dbuser ***** $type $host'"
79+
EVENT="$EVENT ARGUMENTS='$user $database $dbuser ***** $type $host $charset'"
7980

8081
# Logging
8182
log_history "$EVENT"
Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: add new database server
3-
# options: type host port db_user db_password [max_db] [tpl]
3+
# options: type host port dbuser dbpass [max_db] [charsets] [template]
44
#
55
# The function add new database server to the server pool. It supports local
66
# and remote database servers, which is useful for clusters. By adding a host
@@ -17,13 +17,13 @@
1717
type=$1
1818
host=$2
1919
port=$3
20-
db_user=$4
21-
db_password=$5
20+
dbuser=$4
21+
dbpass=$5
2222
max_db=${6-300}
23-
template=${7-template1}
23+
charsets=${7-UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8}
24+
template=${8-template1}
2425

25-
26-
# Importing variables
26+
# Includes
2727
source $VESTA/conf/vesta.conf
2828
source $VESTA/func/shared.sh
2929
source $VESTA/func/db.sh
@@ -33,24 +33,12 @@ source $VESTA/func/db.sh
3333
# Verifications #
3434
#----------------------------------------------------------#
3535

36-
# Checking arg number
37-
args_usage='type host port db_user db_password [max_db] [tpl]'
36+
args_usage='type host port dbuser dbpass [max_db] [charsets] [tpl]'
3837
check_args '5' "$#" "$args_usage"
39-
40-
# Checking argument format
41-
validate_format 'host' 'port' 'db_user' 'db_password' 'max_db'
42-
validate_format 'template'
43-
44-
# Checking db system is enabled
45-
is_system_enabled 'DB_SYSTEM'
46-
47-
# Checking db type
38+
validate_format 'host' 'port' 'dbuser' 'dbpass' 'max_db' 'charsets' 'template'
39+
is_system_enabled "$DB_SYSTEM"
4840
is_type_valid "$DB_SYSTEM" "$type"
49-
50-
# Checking host existance
51-
is_db_host_new
52-
53-
# Checking host connection
41+
is_dbhost_new
5442
case $type in
5543
mysql) is_mysql_host_alive ;;
5644
pgsql) is_pgsql_host_alive ;;
@@ -63,26 +51,28 @@ esac
6351

6452
# Concatentating db host string
6553
case $type in
66-
mysql) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'";
67-
new_str="$new_str PORT='$port' MAX_DB='$max_db' U_SYS_USERS=''";
68-
new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$DATE'";;
69-
pgsql) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'";
70-
new_str="$new_str PORT='$port' TPL='$template'";
71-
new_str="$new_str MAX_DB='$max_db' U_SYS_USERS=''";
72-
new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$DATE'";;
54+
mysql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass' PORT='$port'";
55+
str="$str CHARSETS='$charsets' MAX_DB='$max_db' U_SYS_USERS='' ";
56+
str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$TIME' DATE='$DATE'";;
57+
pgsql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass' PORT='$port'";
58+
str="$str CHARSETS='$charsets' TPL='$template' MAX_DB='$max_db'";
59+
str="$str U_SYS_USERS='' U_DB_BASES='0' SUSPENDED='no'";
60+
str="$str TIME='$TIME' DATE='$DATE'";;
7361
esac
7462

7563
# Adding host to conf
76-
echo "$new_str" >> $VESTA/conf/$type.conf
64+
echo "$str" >> $VESTA/conf/$type.conf
7765
chmod 660 $VESTA/conf/$type.conf
7866

7967

8068
#----------------------------------------------------------#
8169
# Vesta #
8270
#----------------------------------------------------------#
8371

84-
# Hidding db pass
85-
EVENT=$(echo $EVENT | sed -e "s/$db_password/xxxxxx/g")
72+
# Hiding password
73+
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
74+
EVENT="$EVENT ARGUMENTS='$type $host $port $dbuser ****** $max_db $charsets"
75+
EVENT="$EVENT $tpl'"
8676

8777
# Logging
8878
log_event "$OK" "$EVENT"
Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
2-
# info: change database user password
3-
# options: user db_name db_password
2+
# info: change database password
3+
# options: user database dbpass
44
#
55
# The function for changing database user password to a database. It uses the
66
# full name of database as argument.
@@ -13,9 +13,9 @@
1313
# Argument defenition
1414
user=$1
1515
database=$2
16-
db_password=$3
16+
dbpass=$3
1717

18-
# Importing variables
18+
# Includes
1919
source $VESTA/conf/vesta.conf
2020
source $VESTA/func/shared.sh
2121
source $VESTA/func/db.sh
@@ -25,41 +25,24 @@ source $VESTA/func/db.sh
2525
# Verifications #
2626
#----------------------------------------------------------#
2727

28-
# Checking arg number
29-
check_args '3' "$#" 'user db_name db_password'
30-
31-
# Checking argument format
32-
validate_format 'user' 'database' 'db_password'
33-
34-
# Checking db system is enabled
35-
is_system_enabled 'DB_SYSTEM'
36-
37-
# Checking user
28+
check_args '3' "$#" 'user database dbpass'
29+
validate_format 'user' 'database' 'dbpass'
30+
is_system_enabled "$DB_SYSTEM"
3831
is_object_valid 'user' 'USER' "$user"
39-
40-
# Checking user is active
4132
is_object_unsuspended 'user' 'USER' "$user"
42-
43-
# Checking db existance
44-
is_db_valid
45-
46-
# Checking db is active
47-
is_db_suspended
33+
is_object_valid 'db' 'DB' "$database"
34+
is_object_unsuspended 'db' 'DB' "$database"
4835

4936

5037
#----------------------------------------------------------#
5138
# Action #
5239
#----------------------------------------------------------#
40+
# Get database values
41+
get_database_values
5342

54-
# Define database variables
55-
db_user=$(get_db_value '$USER')
56-
host=$(get_db_value '$HOST')
57-
type=$(get_db_value '$TYPE')
58-
59-
# Switching on db type
60-
case $type in
61-
mysql) change_db_mysql_password ;;
62-
pgsql) change_db_pgsql_password ;;
43+
case $TYPE in
44+
mysql) change_mysql_password ;;
45+
pgsql) change_pgsql_password ;;
6346
esac
6447

6548

@@ -68,7 +51,8 @@ esac
6851
#----------------------------------------------------------#
6952

7053
# Hiding password
71-
EVENT="$DATE $SCRIPT $user $database *****"
54+
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
55+
EVENT="$EVENT ARGUMENTS='$user $database *****'"
7256

7357
# Logging
7458
log_event "$OK" "$EVENT"
Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
user=$1
1515
database=$2
1616

17-
# Importing variables
17+
# Includes
1818
source $VESTA/conf/vesta.conf
1919
source $VESTA/func/shared.sh
2020
source $VESTA/func/db.sh
@@ -24,57 +24,40 @@ source $VESTA/func/db.sh
2424
# Verifications #
2525
#----------------------------------------------------------#
2626

27-
# Checking arg number
28-
check_args '2' "$#" 'user db_name'
29-
30-
# Checking argument format
27+
check_args '2' "$#" 'user database'
3128
validate_format 'user' 'database'
32-
33-
# Checking db system is enabled
34-
is_system_enabled 'DB_SYSTEM'
35-
36-
# Checking user
29+
is_system_enabled "$DB_SYSTEM"
3730
is_object_valid 'user' 'USER' "$user"
38-
39-
# Checking user is active
4031
is_object_unsuspended 'user' 'USER' "$user"
41-
42-
# Checking db existance
43-
is_db_valid
44-
45-
# Checking db is active
46-
is_db_suspended
32+
is_object_valid 'db' 'DB' "$database"
33+
is_object_unsuspended 'db' 'DB' "$database"
4734

4835

4936
#----------------------------------------------------------#
5037
# Action #
5138
#----------------------------------------------------------#
5239

53-
# Get some variables we do not have now
54-
db_user=$(get_db_value '$USER')
55-
host=$(get_db_value '$HOST')
56-
type=$(get_db_value '$TYPE')
40+
# Get database values
41+
get_database_values
5742

5843
# Switching on db type
59-
case $type in
60-
mysql) del_db_mysql ;;
61-
pgsql) del_db_pgsql ;;
44+
case $TYPE in
45+
mysql) delete_mysql_database ;;
46+
pgsql) delete_pgsql_database ;;
6247
esac
6348

6449

6550
#----------------------------------------------------------#
6651
# Vesta #
6752
#----------------------------------------------------------#
6853

69-
# Decreasing db value
70-
decrease_db_value
54+
# Deleting database
55+
sed -i "/DB='$database' /d" $USER_DATA/db.conf
7156

72-
# Decreasing domain value
57+
# Decreasing counters
58+
decrease_dbhost_values
7359
decrease_user_value "$user" '$U_DATABASES'
7460

75-
# Deleting vesta db record
76-
del_db_vesta
77-
7861
# Logging
7962
log_event "$OK" "$EVENT"
8063

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# info: delete database serve
2+
# info: delete database server
33
# options: type host
44
#
55
# The function for deleting the database host from vesta configuration. It will
@@ -24,31 +24,19 @@ source $VESTA/func/db.sh
2424
# Verifications #
2525
#----------------------------------------------------------#
2626

27-
# Checking arg number
28-
check_args '2' "$#" 'type host'
29-
30-
# Checking argument format
31-
validate_format 'host'
32-
33-
# Checking db system is enabled
34-
is_system_enabled 'DB_SYSTEM'
35-
36-
# Checking db type
27+
check_args '2' "$#" "type host"
28+
validate_format 'type' 'host'
29+
is_system_enabled "$DB_SYSTEM"
3730
is_type_valid "$DB_SYSTEM" "$type"
38-
39-
# Checking host existance
40-
is_db_host_valid
41-
42-
# Checking db host users
43-
is_db_host_free
31+
is_object_valid "../../conf/$type" 'HOST' "$host"
32+
is_dbhost_free
4433

4534

4635
#----------------------------------------------------------#
4736
# Action #
4837
#----------------------------------------------------------#
49-
50-
# Deleting host from conf
51-
del_dbhost_vesta
38+
# Deleting server
39+
sed -i "/HOST='$host' /d" $VESTA/conf/$type.conf
5240

5341

5442
#----------------------------------------------------------#

0 commit comments

Comments
 (0)