Skip to content

Commit 83196f3

Browse files
committed
Refactoring stage I
1 parent 62e5d3d commit 83196f3

File tree

173 files changed

+3132
-3342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+3132
-3342
lines changed

bin/v_add_cron_job

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,62 +20,45 @@ wday=$6
2020
command=$7
2121
job=$8
2222

23-
# Importing variables
24-
source $VESTA/conf/vars.conf
25-
source $V_CONF/vesta.conf
26-
source $V_FUNC/shared.func
27-
source $V_FUNC/cron.func
23+
# Includes
24+
source $VESTA/conf/vesta.conf
25+
source $VESTA/func/shared.sh
2826

2927

3028
#----------------------------------------------------------#
3129
# Verifications #
3230
#----------------------------------------------------------#
3331

34-
# Checking arg number
3532
check_args '7' "$#" 'user min hour day month wday command [job]'
36-
37-
# Checking argument format
38-
format_validation 'user' 'min' 'hour' 'day' 'month' 'wday' 'command'
39-
40-
# Checking cron system
41-
is_system_enabled 'CRON_SYSTEM'
42-
43-
# Checking user
44-
is_user_valid
45-
46-
# Checking package
33+
validate_format 'user' 'min' 'hour' 'day' 'month' 'wday' 'command'
34+
is_system_enabled $CRON_SYSTEM
35+
is_object_valid 'user' 'USER' "$user"
36+
is_object_suspended 'user' 'USER' "$user"
4737
is_package_full 'CRON_JOBS'
48-
49-
# Get str position
50-
if [ -z "$job" ]; then
51-
job=$(get_next_cron_string)
52-
fi
53-
54-
# Checking id format
55-
format_validation 'job'
56-
57-
# Checking job id
58-
is_cron_job_free
38+
get_next_cronjob
39+
validate_format 'job'
40+
is_object_free 'cron' 'JOB' "$job"
5941

6042

6143
#----------------------------------------------------------#
6244
# Action #
6345
#----------------------------------------------------------#
6446

6547
# Concatenating cron string
66-
command=$(echo $command|sed -e "s/'/%quote%/g" -e "s/:/%dots%/g")
67-
v_str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month"
68-
v_str="$v_str' WDAY='$wday' CMD='$command' SUSPENDED='no' DATE='$V_DATE'"
48+
command=$(echo $command | sed -e "s/'/%quote%/g" -e "s/:/%dots%/g")
49+
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month WDAY='$wday'"
50+
str="$v_str' CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
6951

7052
# Adding to crontab
71-
echo "$v_str">>$V_USERS/$user/cron.conf
53+
echo "$str" >> $VESTA/data/users/$user/cron.conf
7254

73-
chmod 660 $V_USERS/$user/cron.conf
55+
# Chaning permissions
56+
chmod 660 $VESTA/data/users/$user/cron.conf
7457

75-
# Sorting jobs by id
58+
# Sort jobs by id number
7659
sort_cron_jobs
7760

78-
# Sync system cron with user
61+
# Sync cronjobs with system crond
7962
sync_cron_jobs
8063

8164

@@ -84,13 +67,13 @@ sync_cron_jobs
8467
#----------------------------------------------------------#
8568

8669
# Increasing cron value
87-
increase_user_value "$user" '$U_CRON_JOBS'
70+
increase_user_value $user '$U_CRON_JOBS'
8871

89-
# Adding task to the vesta pipe
90-
restart_schedule 'cron'
72+
# Restart crond
73+
$BIN/v_restart_cron
9174

9275
# Logging
93-
log_history "$V_EVENT" "v_delete_cron_job $user $job"
94-
log_event 'system' "$V_EVENT"
76+
log_history "$EVENT"
77+
log_event "$OK" "$EVENT"
9578

9679
exit
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# info: add user reports
2+
# info: add cron reports
33
# opions: user
44
#
55
# The script for enabling reports on cron tasks and administrative
@@ -13,36 +13,28 @@
1313
# Argument defenition
1414
user=$1
1515

16-
# Importing variables
17-
source $VESTA/conf/vars.conf
18-
source $V_CONF/vesta.conf
19-
source $V_FUNC/shared.func
20-
source $V_FUNC/cron.func
16+
# Includes
17+
source $VESTA/conf/vesta.conf
18+
source $VESTA/func/shared.sh
2119

2220

2321
#----------------------------------------------------------#
2422
# Verifications #
2523
#----------------------------------------------------------#
2624

27-
# Checking arg number
2825
check_args '1' "$#" 'user'
29-
30-
# Checking argument format
31-
format_validation 'user'
32-
33-
# Checking user
34-
is_user_valid
35-
36-
# Checking user is active
37-
is_user_suspended
26+
validate_format 'user'
27+
is_system_enabled "$CRON_SYSTEM"
28+
is_object_valid 'user' 'USER' "$user"
29+
is_object_suspended 'user' 'USER' "$user"
3830

3931

4032
#----------------------------------------------------------#
4133
# Action #
4234
#----------------------------------------------------------#
4335

4436
# Changing user report value
45-
update_user_value "$user" '$REPORTS' 'yes'
37+
update_user_value "$user" '$CRON_REPORTS' 'yes'
4638

4739
# Sync system cron with user
4840
sync_cron_jobs
@@ -52,11 +44,11 @@ sync_cron_jobs
5244
# Vesta #
5345
#----------------------------------------------------------#
5446

55-
# Adding task to the vesta pipe
56-
restart_schedule 'cron'
47+
# Restart crond
48+
$BIN/v_restart_cron
5749

5850
# Logging
59-
log_history "$V_EVENT" "v_delete_user_reports $user"
60-
log_event 'system' "$V_EVENT"
51+
log_history "$EVENT"
52+
log_event "$OK" "$EVENT"
6153

6254
exit

bin/v_add_db_base

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,26 @@ type=$5
2424
host=$6
2525
encoding=${7-UTF8}
2626
encoding=$(echo "$encoding" |tr '[:lower:]' '[:upper:]')
27+
2728
# Importing variables
28-
source $VESTA/conf/vars.conf
29-
source $V_CONF/vesta.conf
30-
source $V_FUNC/shared.func
31-
source $V_FUNC/db.func
29+
source $VESTA/conf/vesta.conf
30+
source $VESTA/func/shared.sh
31+
source $VESTA/func/db.sh
3232

3333

3434
#----------------------------------------------------------#
3535
# Verifications #
3636
#----------------------------------------------------------#
3737

38-
# Checking arg number
3938
check_args '5' "$#" 'user db db_user db_password type [host] [encoding]'
40-
41-
# Checking argument format
42-
format_validation 'user' 'database' 'db_user' 'db_password' 'encoding'
43-
44-
# Checking db system is enabled
39+
validate_format 'user' 'database' 'db_user' 'db_password' 'encoding'
4540
is_system_enabled 'DB_SYSTEM'
46-
47-
# Checking db type
48-
is_type_valid 'db' "$type"
49-
50-
# Checking user
51-
is_user_valid
52-
53-
# Checking user is active
54-
is_user_suspended
55-
56-
# Checking db existance
57-
is_db_new
58-
59-
# Checking db host
60-
if [ -z "$host" ]; then
61-
host=$(get_next_db_host)
62-
fi
63-
is_db_host_valid
64-
65-
# Checking package
41+
is_type_valid "$DB_SYSTEM" "$type"
42+
is_object_valid 'user' 'USER' "$user"
43+
is_object_suspended 'user' 'USER' "$user"
44+
is_object_free 'db' 'DB' "$database"
45+
get_next_dbhost
46+
is_object_valid "$type" 'DBHOST' "$host"
6647
is_package_full 'DATABASES'
6748

6849

@@ -81,24 +62,22 @@ esac
8162
# Vesta #
8263
#----------------------------------------------------------#
8364

84-
# Increasing db value
85-
increase_db_value
86-
87-
# Increasing domain value
65+
# Increasing counters
66+
increase_dbhost_values
8867
increase_user_value "$user" '$U_DATABASES'
8968

9069
# Adding db to db conf
9170
v_str="DB='$database' USER='$db_user' HOST='$host' TYPE='$type'"
92-
v_str="$v_str CHARSET='$encoding' U_DISK='0' SUSPENDED='no' DATE='$V_DATE'"
93-
echo "$v_str" >> $V_USERS/$user/db.conf
94-
chmod 660 $V_USERS/$user/db.conf
71+
v_str="$v_str CHARSET='$encoding' U_DISK='0' SUSPENDED='no' DATE='$DATE'"
72+
echo "$v_str" >> $USER_DATA/db.conf
73+
chmod 660 $USER_DATA/db.conf
9574

9675
# Hiding password
97-
V_EVENT="$V_DATE $V_SCRIPT $user $database $db_user ***** $type $host"
98-
V_EVENT="$V_EVENT $encoding"
76+
EVENT="$DATE $SCRIPT $user $database $db_user ***** $type $host"
77+
EVENT="$EVENT $encoding"
9978

10079
# Logging
101-
log_history "$V_EVENT" "v_delete_db_base $user $database"
102-
log_event 'system' "$V_EVENT"
80+
log_history "$EVENT" "v_delete_db_base $user $database"
81+
log_event "$OK" "$EVENT"
10382

10483
exit

bin/v_add_db_host

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ template=${7-template1}
2424

2525

2626
# Importing variables
27-
source $VESTA/conf/vars.conf
28-
source $V_CONF/vesta.conf
29-
source $V_FUNC/shared.func
30-
source $V_FUNC/db.func
27+
source $VESTA/conf/vesta.conf
28+
source $VESTA/func/shared.sh
29+
source $VESTA/func/db.sh
3130

3231

3332
#----------------------------------------------------------#
@@ -39,14 +38,14 @@ args_usage='type host port db_user db_password [max_db] [tpl]'
3938
check_args '5' "$#" "$args_usage"
4039

4140
# Checking argument format
42-
format_validation 'host' 'port' 'db_user' 'db_password' 'max_db'
43-
format_validation 'template'
41+
validate_format 'host' 'port' 'db_user' 'db_password' 'max_db'
42+
validate_format 'template'
4443

4544
# Checking db system is enabled
4645
is_system_enabled 'DB_SYSTEM'
4746

4847
# Checking db type
49-
is_type_valid 'db' "$type"
48+
is_type_valid "$DB_SYSTEM" "$type"
5049

5150
# Checking host existance
5251
is_db_host_new
@@ -66,26 +65,26 @@ esac
6665
case $type in
6766
mysql) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'";
6867
new_str="$new_str PORT='$port' MAX_DB='$max_db' U_SYS_USERS=''";
69-
new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$V_DATE'";;
68+
new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$DATE'";;
7069
pgsql) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'";
7170
new_str="$new_str PORT='$port' TPL='$template'";
7271
new_str="$new_str MAX_DB='$max_db' U_SYS_USERS=''";
73-
new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$V_DATE'";;
72+
new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$DATE'";;
7473
esac
7574

7675
# Adding host to conf
77-
echo "$new_str" >> $V_DB/$type.conf
78-
chmod 660 $V_DB/$type.conf
76+
echo "$new_str" >> $VESTA/conf/$type.conf
77+
chmod 660 $VESTA/conf/$type.conf
7978

8079

8180
#----------------------------------------------------------#
8281
# Vesta #
8382
#----------------------------------------------------------#
8483

8584
# Hidding db pass
86-
V_EVENT=$(echo $V_EVENT | sed -e "s/$db_password/xxxxxx/g")
85+
EVENT=$(echo $EVENT | sed -e "s/$db_password/xxxxxx/g")
8786

8887
# Logging
89-
log_event 'system' "$V_EVENT"
88+
log_event "$OK" "$EVENT"
9089

9190
exit

0 commit comments

Comments
 (0)