Skip to content

Commit e05dca6

Browse files
committed
refactoring: log_event(), is_format_valid()
1 parent 6e0ef66 commit e05dca6

File tree

211 files changed

+754
-1089
lines changed

Some content is hidden

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

211 files changed

+754
-1089
lines changed

bin/v-acknowledge-user-notification

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ source $VESTA/conf/vesta.conf
2323
#----------------------------------------------------------#
2424

2525
check_args '2' "$#" 'USER NOTIFICATION'
26-
validate_format 'user' 'nid'
26+
is_format_valid 'user' 'nid'
2727
is_object_valid 'user' 'USER' "$user"
2828

2929

@@ -61,6 +61,6 @@ if [ "$notice" = 'no' ]; then
6161
fi
6262

6363
# Logging
64-
log_event "$OK" "$EVENT"
64+
log_event "$OK" "$ARGUMENTS"
6565

6666
exit

bin/v-activate-vesta-license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ if [ "$module" = 'SFTPJAIL' ]; then
6262
fi
6363

6464
# Logging
65-
log_event "$OK" "$EVENT"
65+
log_event "$OK" "$ARGUMENTS"
6666

6767
exit

bin/v-add-backup-host

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ EOF
9494

9595
if [ "$type" != 'local' ];then
9696
check_args '4' "$#" "TYPE HOST USERNAME PASSWORD [PATH] [PORT]"
97-
validate_format 'host'
97+
is_format_valid 'host'
9898
is_password_valid
9999
if [ "$type" = 'sftp' ]; then
100100
which expect >/dev/null 2>&1
@@ -117,7 +117,7 @@ if [ "$type" = 'ftp' ]; then
117117
grep -i -e failed -e error -e "can't" -e "not conn" -e "incorrect")
118118
if [ ! -z "$ferror" ]; then
119119
echo "Error: can't login to ftp $user@$host"
120-
log_event "$E_CONNECT" "$EVENT"
120+
log_event "$E_CONNECT" "$ARGUMENTS"
121121
exit $E_CONNECT
122122
fi
123123

@@ -129,7 +129,7 @@ if [ "$type" = 'ftp' ]; then
129129
echo "$ftp_result"
130130
rm -rf $tmpdir
131131
echo "Error: can't create $ftmpdir folder on the ftp"
132-
log_event "$E_FTP" "$EVENT"
132+
log_event "$E_FTP" "$ARGUMENTS"
133133
exit $E_FTP
134134
fi
135135
fi
@@ -145,21 +145,20 @@ if [ "$type" = 'sftp' ]; then
145145
$E_CONNECT) echo "Error: can't login to sftp $user@$host";;
146146
$E_FTP) echo "Error: can't create temp folder on the sftp host";;
147147
esac
148-
log_event "$rc" "$EVENT"
148+
log_event "$rc" "$ARGUMENTS"
149149
exit "$rc"
150150
fi
151151
fi
152152

153153

154154
# Adding backup host
155155
if [ $type != 'local' ]; then
156-
echo "HOST='$host'
157-
USERNAME='$user'
158-
PASSWORD='$password'
159-
BPATH='$path'
160-
PORT='$port'
161-
TIME='$TIME'
162-
DATE='$DATE'" > $VESTA/conf/$type.backup.conf
156+
time_n_date=$(date +'%T %F')
157+
time=$(echo "$time_n_date" |cut -f 1 -d \ )
158+
date=$(echo "$time_n_date" |cut -f 2 -d \ )
159+
str="HOST='$host'\nUSERNAME='$user'\nPASSWORD='$password'"
160+
str="$str\nBPATH='$path'\nPORT='$port'\nTIME='$time'\nDATE='$date'"
161+
echo -e "$str" > $VESTA/conf/$type.backup.conf
163162
chmod 660 $VESTA/conf/$type.backup.conf
164163
fi
165164

@@ -181,6 +180,6 @@ else
181180
fi
182181

183182
# Logging
184-
log_event "$OK" "$EVENT"
183+
log_event "$OK" "$ARGUMENTS"
185184

186185
exit

bin/v-add-cron-job

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,28 @@ A7="$command"
3434
#----------------------------------------------------------#
3535

3636
check_args '7' "$#" 'USER MIN HOUR DAY MONTH WDAY COMMAND [JOB] [RESTART]'
37-
validate_format 'user' 'min' 'hour' 'day' 'month' 'wday' 'command'
37+
is_format_valid 'user' 'min' 'hour' 'day' 'month' 'wday' 'command'
3838
is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
3939
is_object_valid 'user' 'USER' "$user"
4040
is_object_unsuspended 'user' 'USER' "$user"
4141
is_package_full 'CRON_JOBS'
4242
get_next_cronjob
43-
validate_format 'job'
43+
is_format_valid 'job'
4444
is_object_new 'cron' 'JOB' "$job"
4545

4646

4747
#----------------------------------------------------------#
4848
# Action #
4949
#----------------------------------------------------------#
5050

51+
# Generating timestamp
52+
time_n_date=$(date +'%T %F')
53+
time=$(echo "$time_n_date" |cut -f 1 -d \ )
54+
date=$(echo "$time_n_date" |cut -f 2 -d \ )
55+
5156
# Concatenating cron string
5257
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
53-
str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
58+
str="$str CMD='$command' SUSPENDED='no' TIME='$time' DATE='$date'"
5459

5560
# Adding to crontab
5661
echo "$str" >> $VESTA/data/users/$user/cron.conf
@@ -78,6 +83,6 @@ check_result $? "Cron restart failed" >/dev/null
7883

7984
# Logging
8085
log_history "added cron job $job"
81-
log_event "$OK" "$EVENT"
86+
log_event "$OK" "$ARGUMENTS"
8287

8388
exit

bin/v-add-cron-reports

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ source $VESTA/conf/vesta.conf
2323
#----------------------------------------------------------#
2424

2525
check_args '1' "$#" 'USER'
26-
validate_format 'user'
26+
is_format_valid 'user'
2727
is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
2828
is_object_valid 'user' 'USER' "$user"
2929
is_object_unsuspended 'user' 'USER' "$user"
@@ -50,6 +50,6 @@ check_result $? "Cron restart failed" >/dev/null
5050

5151
# Logging
5252
log_history "enabled cron reporting"
53-
log_event "$OK" "$EVENT"
53+
log_event "$OK" "$ARGUMENTS"
5454

5555
exit

bin/v-add-cron-restart-job

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ fi
3838
#----------------------------------------------------------#
3939

4040
# Logging
41-
log_event "$OK" "$EVENT"
41+
log_event "$OK" "$ARGUMENTS"
4242

4343
exit

bin/v-add-cron-vesta-autoupdate

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ fi
3434
# Action #
3535
#----------------------------------------------------------#
3636

37+
# Generating timestamp
38+
time_n_date=$(date +'%T %F')
39+
time=$(echo "$time_n_date" |cut -f 1 -d \ )
40+
date=$(echo "$time_n_date" |cut -f 2 -d \ )
41+
3742
# Define time somewhere at night
3843
min=$(gen_password '012345' '2')
3944
hour=$(gen_password '1234567' '1')
@@ -44,7 +49,7 @@ command='sudo /usr/local/vesta/bin/v-update-sys-vesta-all'
4449

4550
# Concatenating cron string
4651
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
47-
str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
52+
str="$str CMD='$command' SUSPENDED='no' TIME='$time' DATE='$date'"
4853

4954
# Adding to crontab
5055
echo "$str" >> $VESTA/data/users/$user/cron.conf
@@ -72,6 +77,6 @@ check_result $? "Cron restart failed" >/dev/null
7277

7378
# Logging
7479
log_history "added cron job $job"
75-
log_event "$OK" "$EVENT"
80+
log_event "$OK" "$ARGUMENTS"
7681

7782
exit

bin/v-add-database

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ source $VESTA/conf/vesta.conf
3636
#----------------------------------------------------------#
3737

3838
check_args '4' "$#" 'USER DATABASE DBUSER DBPASS [TYPE] [HOST] [CHARSET]'
39-
validate_format 'user' 'database' 'dbuser' 'charset'
39+
is_format_valid 'user' 'database' 'dbuser' 'charset'
4040
is_system_enabled "$DB_SYSTEM" '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_new 'db' 'DB' "$database"
4545
get_next_dbhost
46-
is_object_valid "../../../conf/$type" 'DBHOST' "$host"
46+
is_object_valid "../../../conf/$type" 'HOST' "$host"
4747
is_object_unsuspended "../../../conf/$type" 'DBHOST' "$host"
4848
#is_charset_valid
4949
is_package_full 'DATABASES'
@@ -66,14 +66,15 @@ esac
6666
# Vesta #
6767
#----------------------------------------------------------#
6868

69-
# Update time and date
70-
DATE=$(date +%F)
71-
TIME=$(date +%T)
69+
# Generating timestamp
70+
time_n_date=$(date +'%T %F')
71+
time=$(echo "$time_n_date" |cut -f 1 -d \ )
72+
date=$(echo "$time_n_date" |cut -f 2 -d \ )
7273

7374
# Adding db to db conf
7475
str="DB='$database' DBUSER='$dbuser' MD5='$md5' HOST='$host' TYPE='$type'"
75-
str="$str CHARSET='$charset' U_DISK='0' SUSPENDED='no' TIME='$TIME'"
76-
str="$str DATE='$DATE'"
76+
str="$str CHARSET='$charset' U_DISK='0' SUSPENDED='no' TIME='$time'"
77+
str="$str DATE='$date'"
7778
echo "$str" >> $USER_DATA/db.conf
7879
chmod 660 $USER_DATA/db.conf
7980

@@ -83,6 +84,6 @@ increase_user_value "$user" '$U_DATABASES'
8384

8485
# Logging
8586
log_history "added $type database $database"
86-
log_event "$OK" "$EVENT"
87+
log_event "$OK" "$ARGUMENTS"
8788

8889
exit

bin/v-add-database-host

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ is_mysql_host_alive() {
3838
rm $mycnf
3939
if [ '0' -ne "$?" ]; then
4040
echo "Error: MySQL connection to $host failed"
41-
log_event "$E_CONNECT" "$EVENT"
41+
log_event "$E_CONNECT" "$ARGUMENTS"
4242
exit $E_CONNECT
4343
fi
4444
}
@@ -48,7 +48,7 @@ is_pgsql_host_alive() {
4848
psql -h $host -U $dbuser -c "SELECT VERSION()" > /dev/null 2>&1
4949
if [ '0' -ne "$?" ]; then
5050
echo "Error: PostgreSQL connection to $host failed"
51-
log_event "$E_CONNECT" "$EVENT"
51+
log_event "$E_CONNECT" "$ARGUMENTS"
5252
exit $E_CONNECT
5353
fi
5454
}
@@ -60,7 +60,7 @@ is_pgsql_host_alive() {
6060

6161
args_usage='TYPE HOST DBUSER DBPASS [MAX_DB] [CHARSETS] [TPL]'
6262
check_args '4' "$#" "$args_usage"
63-
validate_format 'host' 'dbuser' 'max_db' 'charsets' 'template'
63+
is_format_valid 'host' 'dbuser' 'max_db' 'charsets' 'template'
6464
#is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
6565
#is_type_valid "$DB_SYSTEM" "$type"
6666
is_dbhost_new
@@ -76,19 +76,23 @@ esac
7676
# Action #
7777
#----------------------------------------------------------#
7878

79+
# Generating timestamp
80+
time_n_date=$(date +'%T %F')
81+
time=$(echo "$time_n_date" |cut -f 1 -d \ )
82+
date=$(echo "$time_n_date" |cut -f 2 -d \ )
83+
7984
# Concatenating db host string
8085
case $type in
8186
mysql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
8287
str="$str CHARSETS='$charsets' MAX_DB='$max_db' U_SYS_USERS=''";
83-
str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$TIME' DATE='$DATE'";;
88+
str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$time' DATE='$date'";;
8489
pgsql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
8590
str="$str CHARSETS='$charsets' TPL='$template' MAX_DB='$max_db'";
8691
str="$str U_SYS_USERS='' U_DB_BASES='0' SUSPENDED='no'";
87-
str="$str TIME='$TIME' DATE='$DATE'";;
92+
str="$str TIME='$time' DATE='$date'";;
8893
esac
8994

9095

91-
9296
#----------------------------------------------------------#
9397
# Vesta #
9498
#----------------------------------------------------------#
@@ -110,6 +114,6 @@ else
110114
fi
111115

112116
# Logging
113-
log_event "$OK" "$EVENT"
117+
log_event "$OK" "$ARGUMENTS"
114118

115119
exit

bin/v-add-dns-domain

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ source $VESTA/conf/vesta.conf
4141
#----------------------------------------------------------#
4242

4343
check_args '3' "$#" 'USER DOMAIN IP [NS1] [NS2] [NS3] [..] [NS8] [RESTART]'
44-
validate_format 'user' 'domain' 'ip'
44+
is_format_valid 'user' 'domain' 'ip'
4545
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
4646
is_object_valid 'user' 'USER' "$user"
4747
is_object_unsuspended 'user' 'USER' "$user"
@@ -52,37 +52,37 @@ is_dns_template_valid
5252

5353
if [ ! -z "$ns1" ]; then
5454
ns1=$(echo $4 | sed -e 's/\.*$//g' -e 's/^\.*//g')
55-
validate_format 'ns1'
55+
is_format_valid 'ns1'
5656
fi
5757
if [ ! -z "$ns2" ]; then
5858
ns2=$(echo $5 | sed -e 's/\.*$//g' -e 's/^\.*//g')
59-
validate_format 'ns2'
59+
is_format_valid 'ns2'
6060
fi
6161

6262
if [ ! -z "$ns3" ]; then
6363
ns3=$(echo $6 | sed -e 's/\.*$//g' -e 's/^\.*//g')
64-
validate_format 'ns3'
64+
is_format_valid 'ns3'
6565
fi
6666
if [ ! -z "$ns4" ]; then
6767
ns4=$(echo $7 | sed -e 's/\.*$//g' -e 's/^\.*//g')
68-
validate_format 'ns4'
68+
is_format_valid 'ns4'
6969
fi
7070
if [ ! -z "$ns5" ]; then
7171
ns5=$(echo $8 | sed -e 's/\.*$//g' -e 's/^\.*//g')
72-
validate_format 'ns5'
72+
is_format_valid 'ns5'
7373
fi
7474
if [ ! -z "$ns6" ]; then
7575
ns6=$(echo $9 | sed -e 's/\.*$//g' -e 's/^\.*//g')
76-
validate_format 'ns6'
76+
is_format_valid 'ns6'
7777
fi
7878
if [ ! -z "$ns7" ]; then
7979
ns7=$(echo ${10} | sed -e 's/\.*$//g' -e 's/^\.*//g')
80-
validate_format 'ns7'
80+
is_format_valid 'ns7'
8181
fi
8282

8383
if [ ! -z "$ns8" ]; then
8484
ns8=$(echo ${11} | sed -e 's/\.*$//g' -e 's/^\.*//g')
85-
validate_format 'ns8'
85+
is_format_valid 'ns8'
8686
fi
8787

8888

@@ -127,6 +127,11 @@ if [ -z "$ns8" ]; then
127127
template_data=$(echo "$template_data" |grep -v %ns8%)
128128
fi
129129

130+
# Generating timestamp
131+
time_n_date=$(date +'%T %F')
132+
time=$(echo "$time_n_date" |cut -f 1 -d \ )
133+
date=$(echo "$time_n_date" |cut -f 2 -d \ )
134+
130135
# Adding dns zone to the user config
131136
echo "$template_data" |\
132137
sed -e "s/%ip%/$ip/g" \
@@ -140,16 +145,16 @@ echo "$template_data" |\
140145
-e "s/%ns6%/$ns6/g" \
141146
-e "s/%ns7%/$ns7/g" \
142147
-e "s/%ns8%/$ns8/g" \
143-
-e "s/%time%/$TIME/g" \
144-
-e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf
148+
-e "s/%time%/$time/g" \
149+
-e "s/%date%/$date/g" > $USER_DATA/dns/$domain.conf
145150

146151
chmod 660 $USER_DATA/dns/$domain.conf
147152
records="$(wc -l $USER_DATA/dns/$domain.conf |cut -f 1 -d ' ')"
148153

149154
# Adding dns.conf record
150155
dns_rec="DOMAIN='$domain' IP='$ip' TPL='$template' TTL='$ttl' EXP='$exp'"
151156
dns_rec="$dns_rec SOA='$soa' SERIAL='$serial' SRC='' RECORDS='$records'"
152-
dns_rec="$dns_rec SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
157+
dns_rec="$dns_rec SUSPENDED='no' TIME='$time' DATE='$date'"
153158

154159
echo "$dns_rec" >> $USER_DATA/dns.conf
155160
chmod 660 $USER_DATA/dns.conf
@@ -200,6 +205,6 @@ fi
200205

201206
# Logging
202207
log_history "added dns domain $domain"
203-
log_event "$OK" "$EVENT"
208+
log_event "$OK" "$ARGUMENTS"
204209

205210
exit

0 commit comments

Comments
 (0)