Skip to content

Commit fb40168

Browse files
committed
Refactoring stage V (user)
1 parent 3ba10cd commit fb40168

Some content is hidden

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

42 files changed

+225
-551
lines changed

bin/v_add_user

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ package=${4-default}
1717
fname=$5
1818
lname=$6
1919

20-
# Importing variables
20+
# Includes
2121
source $VESTA/conf/vesta.conf
2222
source $VESTA/func/shared.sh
2323

2424
is_user_free() {
25-
# Parsing domain values
2625
check_sysuser=$(cut -f 1 -d : /etc/passwd | grep -w "$user" )
27-
28-
# Checking result
2926
if [ ! -z "$check_sysuser" ] || [ -e "$USER_DATA" ]; then
3027
echo "Error: user $user exist"
3128
log_event "$E_EXISTS" "$EVENT"
@@ -38,16 +35,13 @@ is_user_free() {
3835
# Verifications #
3936
#----------------------------------------------------------#
4037

41-
# Checking arg number
4238
check_args '3' "$#" 'user password email [package] [fname] [lname]'
39+
validate_format 'user' 'password' 'email' 'package'
40+
if [ ! -z "$fname" ]; then
41+
validate_format 'fname' 'lname'
42+
fi
4343

44-
# Checking argument format
45-
validate_format 'user' 'password' 'email' 'package' 'fname' 'lname'
46-
47-
# Checking user
4844
is_user_free "$user"
49-
50-
# Checking package
5145
is_package_valid "$package"
5246

5347

@@ -75,7 +69,6 @@ echo "$password" | /usr/bin/passwd "$user" --stdin &>/dev/null
7569

7670
# Building directory tree
7771
mkdir $HOMEDIR/$user/conf
78-
chmod 751 $HOMEDIR/$user/conf/web
7972

8073
if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
8174
mkdir $HOMEDIR/$user/conf/web
@@ -206,6 +199,7 @@ U_MAIL_ACCOUNTS='0'
206199
U_DATABASES='0'
207200
U_CRON_JOBS='0'
208201
U_BACKUPS='0'
202+
TIME='$TIME'
209203
DATE='$DATE'" > $USER_DATA/user.conf
210204
chmod 660 $USER_DATA/user.conf
211205

@@ -215,7 +209,8 @@ if [ "$user" != 'admin' ]; then
215209
fi
216210

217211
# Hiding password
218-
EVENT="$DATE $SCRIPT $user ***** $email $package $fname $lname"
212+
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
213+
EVENT="$EVENT ARGUMENTS='$user ***** $email $package $fname $lname'"
219214

220215
# Logging
221216
log_event "$OK" "$EVENT"

bin/v_add_user_backup

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# Argument defenition
1313
user=$1
1414

15-
# Importing variables
15+
# Includes
1616
source $VESTA/conf/vesta.conf
1717
source $VESTA/func/shared.sh
1818

@@ -21,19 +21,10 @@ source $VESTA/func/shared.sh
2121
# Verifications #
2222
#----------------------------------------------------------#
2323

24-
# Checking arg number
2524
check_args '1' "$#" 'user'
26-
27-
# Checking argument format
2825
validate_format 'user'
29-
30-
# Checking backup system is enabled
31-
is_system_enabled 'BACKUP_SYSTEM'
32-
33-
# Checking user
26+
is_system_enabled "$BACKUP_SYSTEM"
3427
is_object_valid 'user' 'USER' "$user"
35-
36-
# Checking user backups
3728
is_backup_enabled
3829

3930

bin/v_add_web_domain_cgi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ user=$1
1717
domain=$(idn -t --quiet -u "$2" )
1818
domain_idn=$(idn -t --quiet -a "$domain")
1919

20-
# Importing variables
20+
# Includes
2121
source $VESTA/conf/vesta.conf
2222
source $VESTA/func/shared.sh
2323
source $VESTA/func/domain.sh
@@ -70,7 +70,7 @@ fi
7070
# Update config value
7171
update_object_value 'web' 'DOMAIN' "$domain" '$CGI' 'yes'
7272

73-
# Adding task to the vesta pipe
73+
# Restart web server
7474
$BIN/v_restart_web "$EVENT"
7575

7676
# Logging

bin/v_add_web_domain_nginx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ default_extentions="jpg,jpeg,gif,png,ico,css,zip,tgz,gz,rar,bz2,doc,xls,exe,\
1919
pdf,ppt,txt,tar,wav,bmp,rtf,js,mp3,avi,mpeg,html,htm"
2020
extentions=${4-$default_extentions}
2121

22-
# Importing variables
22+
# Includes
2323
source $VESTA/conf/vesta.conf
2424
source $VESTA/func/shared.sh
2525
source $VESTA/func/domain.sh
@@ -93,7 +93,7 @@ fi
9393
update_object_value 'web' 'DOMAIN' "$domain" '$NGINX' "$NGINX"
9494
update_object_value 'web' 'DOMAIN' "$domain" '$NGINX_EXT' "$extentions"
9595

96-
# Adding task to the vesta pipe
96+
# Restart web server
9797
$BIN/v_restart_web "$EVENT"
9898

9999
log_history "$EVENT"

bin/v_backup_user

Lines changed: 25 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# Argument defenition
1313
user=$1
1414

15-
# Importing variables
15+
# Includes
1616
source $VESTA/conf/vesta.conf
1717
source $VESTA/func/shared.sh
1818
source $VESTA/func/domain.sh
@@ -23,36 +23,23 @@ source $VESTA/func/db.sh
2323
# Verifications #
2424
#----------------------------------------------------------#
2525

26-
# Checking arg number
2726
check_args '1' "$#" 'user'
28-
29-
# Checking argument format
3027
validate_format 'user'
31-
32-
# Checking backup system is enabled
33-
is_system_enabled 'BACKUP_SYSTEM'
34-
35-
# Checking user
28+
is_system_enabled "$BACKUP_SYSTEM"
3629
is_object_valid 'user' 'USER' "$user"
37-
38-
# Checking user backups
30+
is_object_unsuspended 'user' 'USER' "$user"
3931
is_backup_enabled
40-
41-
# Checking load averages
4232
la=$(cat /proc/loadavg |cut -f 1 -d ' '|cut -f 1 -d '.')
4333
i=0
4434
while [ "$la" -ge "$BACKUP_LA_LIMIT" ]; do
4535
echo "$(date "+%F %T") Load Average $la"
4636
echo
47-
4837
sleep 60
49-
5038
if [ "$i" -ge "15" ]; then
5139
echo "Error: LA is too high"
52-
log_event 'debug' "$E_LA $EVENT"
40+
log_event "$E_LA" "$EVENT"
5341
exit $E_LA
5442
fi
55-
5643
(( ++i))
5744
done
5845

@@ -76,8 +63,6 @@ echo
7663
echo "1.0" > $tmpdir/backup_version
7764
echo "$VERSION" > $tmpdir/vesta_version
7865

79-
80-
8166
# Vesta
8267
echo "-- VESTA --"
8368
vst='yes'
@@ -103,7 +88,6 @@ if [ -e "$USER_DATA/backup.excludes" ]; then
10388
cp -r $USER_DATA/backup.excludes $tmpdir/vesta/
10489
fi
10590

106-
10791
echo
10892

10993
# PAM
@@ -139,13 +123,7 @@ then
139123

140124
# Parsing unsuspeneded domains
141125
conf="$USER_DATA/web.conf"
142-
field='$DOMAIN'
143-
search_string='DOMAIN='
144-
domains=$(dom_clear_search)
145-
domain_list=''
146-
147-
# Cleaning excludes
148-
for domain in $domains; do
126+
for domain in $(search_objects 'web' 'SUSPENDED' "*" 'DOMAIN'); do
149127
check_exl=$(echo "$WEB"|grep -w $domain)
150128
if [ -z "$check_exl" ]; then
151129
web_list="$web_list $domain"
@@ -163,8 +141,8 @@ then
163141

164142
# Packing data folders
165143
cd $HOMEDIR/$user/web/$domain
166-
tar -cf $tmpdir/web/$domain/$domain.tar \
167-
public_html public_shtml private document_errors cgi-bin stats
144+
domain_direcotries=$(ls |grep -v logs)
145+
tar -cf $tmpdir/web/$domain/$domain.tar $domain_direcotries
168146

169147
# Creating web.config
170148
cd $tmpdir/web/$domain/
@@ -233,13 +211,7 @@ then
233211
mkdir $tmpdir/dns/
234212

235213
# Parsing unsuspeneded domains
236-
conf="$USER_DATA/dns.conf"
237-
field='$DOMAIN'
238-
search_string='DOMAIN='
239-
domains=$(dom_clear_search)
240-
241-
# Cleaning excludes
242-
for domain in $domains; do
214+
for domain in $(search_objects 'dns' 'SUSPENDED' "*" 'DOMAIN'); do
243215
check_exl=$(echo "$DNS"|grep -w $domain)
244216
if [ -z "$check_exl" ]; then
245217
dns_list="$dns_list $domain"
@@ -258,8 +230,8 @@ then
258230
grep "DOMAIN='$domain'" $conf > dns.conf
259231

260232
# Backingup dns recods
261-
cp $USER_DATA/dns/$domain $domain
262-
cp $USER_DATA/conf/dns/$domain.db $domain.db
233+
cp $USER_DATA/dns/$domain.conf $domain.conf
234+
cp $HOMEDIR/$user/conf/dns/$domain.db $domain.db
263235
done
264236
echo
265237
fi
@@ -274,13 +246,7 @@ if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ] && [ "$DB" != '*' ]; then
274246
mkdir $tmpdir/db/
275247

276248
# Parsing unsuspeneded domains
277-
conf="$USER_DATA/db.conf"
278-
field='$DB'
279-
search_string='DB='
280-
dbs=$(dom_clear_search)
281-
282-
# Cleaning excludes
283-
for database in $dbs; do
249+
for database in $(search_objects 'db' 'SUSPENDED' "*" 'DB'); do
284250
check_exl=$(echo "$DB"|grep -w $database)
285251
if [ -z "$check_exl" ]; then
286252
db_list="$db_list $database"
@@ -289,23 +255,17 @@ if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ] && [ "$DB" != '*' ]; then
289255
db_list=$(echo "$db_list" | sed -e "s/ */\ /g" -e "s/^ //")
290256

291257
for database in $db_list; do
292-
type=$(get_db_value '$TYPE')
293-
host=$(get_db_value '$HOST')
294-
db_user=$(get_db_value '$USER')
295-
dump="$tmpdir/db/$database.$type.sql"
296-
grants="$tmpdir/db/$database.$type.$db_user"
297-
298-
echo -e "$(date "+%F %T") $database $type"
299-
300-
case $type in
301-
mysql) dump_db_mysql ;;
302-
pgsql) dump_db_pgsql ;;
258+
get_database_values
259+
dump="$tmpdir/db/$database.$TYPE.sql"
260+
grants="$tmpdir/db/$database.$TYPE.$DBUSER"
261+
echo -e "$(date "+%F %T") $database $TYPE"
262+
case $TYPE in
263+
mysql) dump_mysql_database ;;
264+
pgsql) dump_pgsql_database ;;
303265
esac
304-
305266
if [ ! -z "$BACKUP_GZIP" ]; then
306267
gzip -$BACKUP_GZIP $dump
307268
fi
308-
309269
done
310270
echo
311271
fi
@@ -333,6 +293,9 @@ size="$(du -shm $tmpdir | cut -f 1)"
333293

334294
# Get current time
335295
end_time=$(date '+%s')
296+
DATE=$(date +%F)
297+
TIME=$(date +%T)
298+
336299

337300
# Defining local storage function
338301
local_backup(){
@@ -349,7 +312,6 @@ local_backup(){
349312
# Checking retention
350313
backup_list=$(ls -lrt $BACKUP/ | awk '{print $9}' |grep "^$user\.")
351314
backups_count=$(echo "$backup_list" | wc -l)
352-
353315
if [ "$BACKUPS" -le "$backups_count" ]; then
354316
backups_rm_number=$((backups_count - BACKUPS))
355317
(( ++backups_rm_number))
@@ -367,7 +329,7 @@ local_backup(){
367329
disk_usage=$(df $BACKUP | awk '{print $5}'|tail -n1|cut -f 1 -d '%')
368330
if [ "$disk_usage" -ge "$BACKUP_DISK_LIMIT" ]; then
369331
echo "Error: Not enough disk space"
370-
log_event 'debug' "$E_DISK $EVENT"
332+
log_event "$E_DISK" "$EVENT"
371333
exit $E_DISK
372334
fi
373335

@@ -402,7 +364,7 @@ ftp_backup(){
402364
if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ] ||\
403365
[ -z "$BPATH" ]; then
404366
echo "Error: Parsing error"
405-
log_event 'debug' "$E_PARSING $EVENT"
367+
log_event "$E_PARSING" "$EVENT"
406368
exit $E_PARSING
407369
fi
408370

@@ -417,7 +379,7 @@ ftp_backup(){
417379
rm $ftmpdir"
418380
if [ ! -z "$(ftpc "$command")" ] ; then
419381
echo "Error: FTP error"
420-
log_event 'debug' "$E_FTP $EVENT"
382+
log_event "$E_FTP" "$EVENT"
421383
exit $E_FTP
422384
fi
423385

@@ -489,7 +451,7 @@ for backup_record in $deprecated; do
489451
done
490452

491453
# Concatenating string
492-
backup_str="DATE='$DATE' TIME='$current_time' RUNTIME='$run_time'"
454+
backup_str="DATE='$DATE' TIME='$TIME' RUNTIME='$run_time'"
493455
backup_str="$backup_str TYPE='$BACKUP_SYSTEM' SIZE='$size'"
494456
backup_str="$backup_str VESTA='$vst'"
495457
backup_str="$backup_str PAM='$pam'"

bin/v_backup_users

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# mostly by cron wich not read it by itself
1414
source /etc/profile.d/vesta.sh
1515

16-
# Importing variables
16+
# Includes
1717
source $VESTA/conf/vesta.conf
1818
source $VESTA/func/shared.sh
1919

@@ -22,11 +22,12 @@ source $VESTA/func/shared.sh
2222
# Action #
2323
#----------------------------------------------------------#
2424

25-
user_list=$(ls $V_USERS/)
26-
2725
# Updating user billing
28-
for user in $user_list; do
29-
$BIN/v_backup_user $user &>> $VESTA/logs/backup.log
26+
for user in $(ls $VESTA/data/users); do
27+
check_suspend=$(grep "SUSPENDED='no'" $VESTA/data/users/$user/user.conf)
28+
if [ ! -z "$check_suspend" ]; then
29+
$BIN/v_backup_user $user >> $VESTA/log/backup.log 2>&1
30+
fi
3031
done
3132

3233
#----------------------------------------------------------#

bin/v_change_sys_ip_owner

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ip=$1
1414
user=$2
1515

16-
# Importing variables
16+
# Includes
1717
source $VESTA/func/shared.sh
1818
source $VESTA/func/ip.sh
1919

0 commit comments

Comments
 (0)