Skip to content

Commit b998c72

Browse files
committed
Refactoring stage II
1 parent 83196f3 commit b998c72

File tree

88 files changed

+422
-896
lines changed

Some content is hidden

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

88 files changed

+422
-896
lines changed

bin/v_add_cron_job

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ check_args '7' "$#" 'user min hour day month wday command [job]'
3333
validate_format 'user' 'min' 'hour' 'day' 'month' 'wday' 'command'
3434
is_system_enabled $CRON_SYSTEM
3535
is_object_valid 'user' 'USER' "$user"
36-
is_object_suspended 'user' 'USER' "$user"
36+
is_object_unsuspended 'user' 'USER' "$user"
3737
is_package_full 'CRON_JOBS'
3838
get_next_cronjob
3939
validate_format 'job'

bin/v_add_cron_report

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ check_args '1' "$#" 'user'
2626
validate_format 'user'
2727
is_system_enabled "$CRON_SYSTEM"
2828
is_object_valid 'user' 'USER' "$user"
29-
is_object_suspended 'user' 'USER' "$user"
29+
is_object_unsuspended 'user' 'USER' "$user"
3030

3131

3232
#----------------------------------------------------------#

bin/v_add_db_base

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ validate_format 'user' 'database' 'db_user' 'db_password' 'encoding'
4040
is_system_enabled 'DB_SYSTEM'
4141
is_type_valid "$DB_SYSTEM" "$type"
4242
is_object_valid 'user' 'USER' "$user"
43-
is_object_suspended 'user' 'USER' "$user"
43+
is_object_unsuspended 'user' 'USER' "$user"
4444
is_object_free 'db' 'DB' "$database"
4545
get_next_dbhost
4646
is_object_valid "$type" 'DBHOST' "$host"

bin/v_add_dns_domain

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ exp=${5-$next_year}
2525
soa=$6
2626
ttl=${7-14400}
2727

28-
# Importing variables
28+
# Includes
2929
source $VESTA/conf/vesta.conf
3030
source $VESTA/func/shared.sh
3131
source $VESTA/func/domain.sh
@@ -35,30 +35,16 @@ source $VESTA/func/domain.sh
3535
# Verifications #
3636
#----------------------------------------------------------#
3737

38-
# Checking arg number
3938
check_args '3' "$#" 'user domain ip [template] [exp] [soa] [ttl]'
40-
41-
# Checking argument format
4239
validate_format 'user' 'domain' 'ip' 'template' 'exp' 'ttl'
43-
44-
# Checking dns system is enabled
45-
is_system_enabled 'DNS_SYSTEM'
46-
47-
# Checking user
40+
is_system_enabled "$DNS_SYSTEM"
4841
is_object_valid 'user' 'USER' "$user"
49-
50-
# Checking user is active
51-
is_object_suspended 'user' 'USER' "$user"
52-
53-
# Checking domain
42+
is_object_unsuspended 'user' 'USER' "$user"
5443
is_domain_new 'dns'
55-
56-
# Checking package
5744
is_package_full 'DNS_DOMAINS'
58-
59-
# Checking template
6045
is_dns_template_valid
6146

47+
6248
#----------------------------------------------------------#
6349
# Action #
6450
#----------------------------------------------------------#
@@ -68,9 +54,10 @@ i=1
6854
ns=$(get_user_value '$NS')
6955
for nameserver in ${ns//,/ };do
7056
eval ns$i=$nameserver
71-
i=$((i + 1))
57+
(( ++i))
7258
done
7359

60+
# Define soa
7461
if [ -z "$soa" ]; then
7562
soa="$ns1"
7663
fi
@@ -88,13 +75,16 @@ cat $DNSTPL/$template.tpl |\
8875
-e "s/%ns6%/$ns6/g" \
8976
-e "s/%ns7%/$ns7/g" \
9077
-e "s/%ns8%/$ns8/g" \
91-
-e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain
92-
93-
records="$(wc -l $USER_DATA/dns/$domain)"
78+
-e "s/%time%/$TIME/g" \
79+
-e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf
80+
chmod 660 $USER_DATA/dns/$domain.conf
81+
records="$(wc -l $USER_DATA/dns/$domain.conf |cut -f 1 -d ' ')"
9482

9583
# Adding dns.conf record
9684
dns_rec="DOMAIN='$domain' IP='$ip' TPL='$template' TTL='$ttl' EXP='$exp'"
97-
dns_rec="$dns_rec SOA='$soa' RECORDS='$records' SUSPENDED='no' DATE='$DATE'"
85+
dns_rec="$dns_rec SOA='$soa' RECORDS='$records' SUSPENDED='no' TIME='$TIME'"
86+
dns_rec="$dns_rec DATE='$DATE'"
87+
9888
echo "$dns_rec" >> $USER_DATA/dns.conf
9989
chmod 660 $USER_DATA/dns.conf
10090

@@ -104,7 +94,6 @@ named="$named \"$HOMEDIR/$user/conf/dns/$domain.db\";};"
10494
echo "$named" >> /etc/named.conf
10595

10696
# Updating domain dns zone
107-
conf="$HOMEDIR/$user/conf/dns/$domain.db"
10897
update_domain_zone
10998

11099
chmod 640 $conf
@@ -119,11 +108,11 @@ chown root:named $conf
119108
increase_user_value "$user" '$U_DNS_DOMAINS'
120109
increase_user_value "$user" '$U_DNS_RECORDS' "$records"
121110

122-
# Adding task to the vesta pipe
111+
# Restart named
123112
$BIN/v_restart_dns
124113

125114
# Logging
126-
log_history "$EVENT" "v_delete_dns_domain $user $domain"
115+
log_history "$EVENT"
127116
log_event "$OK" "$EVENT"
128117

129118
exit

bin/v_add_dns_domain_record

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: add dns domain record
3-
# options: user domain record type value [id]
3+
# options: user domain record type value [id] [priority]
44
#
55
# The call is used for adding new DNS record. Complex records of TXT, MX and
66
# SRV types can be used by a filling in the 'value' argument. The function also
@@ -23,8 +23,9 @@ rtype=$(echo "$4"| tr '[:lower:]' '[:upper:]')
2323
dvalue=$(idn -t --quiet -u "$5" )
2424
dvalue=$(echo $dvalue | tr '[:upper:]' '[:lower:]')
2525
id=$6
26+
priority=$7
2627

27-
# Importing variables
28+
# Includes
2829
source $VESTA/conf/vesta.conf
2930
source $VESTA/func/shared.sh
3031
source $VESTA/func/domain.sh
@@ -34,78 +35,54 @@ source $VESTA/func/domain.sh
3435
# Verifications #
3536
#----------------------------------------------------------#
3637

37-
# Checking arg number
38-
check_args '5' "$#" 'user domain record type value [id]'
39-
40-
# Checking argument format
38+
check_args '5' "$#" 'user domain record type value [id] [priority]'
4139
validate_format 'user' 'domain' 'record' 'rtype' 'dvalue'
42-
43-
# Checking web system is enabled
44-
is_system_enabled 'DNS_SYSTEM'
45-
46-
# Checking user
40+
is_system_enabled "$DNS_SYSTEM"
4741
is_object_valid 'user' 'USER' "$user"
48-
49-
# Checking user is active
50-
is_object_suspended 'user' 'USER' "$user"
51-
52-
# Checking domain exist
53-
is_domain_valid 'dns'
54-
55-
# Checking domain is active
56-
is_domain_suspended 'dns'
57-
58-
# Checking package
42+
is_object_unsuspended 'user' 'USER' "$user"
43+
is_object_valid 'dns' 'DOMAIN' "$domain"
44+
is_object_unsuspended 'dns' 'DOMAIN' "$domain"
5945
is_package_full 'DNS_RECORDS'
60-
61-
# Defining if emtpy
62-
if [ -z "$id"] ; then
63-
id=$(get_next_dns_record)
64-
fi
65-
66-
# Checking id format
46+
get_next_dnsrecord
6747
validate_format 'id'
68-
69-
# Checking id
70-
is_dns_record_free
48+
is_object_free "dns/$domain" 'ID' "$id"
7149

7250

7351
#----------------------------------------------------------#
7452
# Action #
7553
#----------------------------------------------------------#
7654

77-
# Defining zone path
78-
zone="$USER_DATA/dns/$domain"
55+
if [ "$rtype" != 'MX' ] || [ "$rtype" != 'SRV' ]; then
56+
priority=''
57+
fi
7958

8059
# Adding record
81-
dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' VALUE='$dvalue'"
82-
dns_rec="$dns_rec SUSPENDED='no' DATE='$DATE'"
83-
echo "$dns_rec" >> $zone
60+
zone="$USER_DATA/dns/$domain.conf"
61+
dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
62+
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
63+
echo "$dns_rec" >> $zone
8464

8565
# Sorting records
8666
sort_dns_records
8767

8868
# Updating zone
89-
conf="$HOMEDIR/$user/conf/dns/$domain.db"
9069
update_domain_zone
9170

9271

9372
#----------------------------------------------------------#
9473
# Vesta #
9574
#----------------------------------------------------------#
9675

97-
# Updating dns domain values
98-
records="$(wc -l $USER_DATA/dns/$domain)"
99-
update_domain_value 'dns' '$RECORDS' "$records"
100-
101-
# Updating user counters
76+
# Upddate counters
77+
records="$(wc -l $USER_DATA/dns/$domain.conf | cut -f1 -d ' ')"
78+
update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records"
10279
increase_user_value "$user" '$U_DNS_RECORDS'
10380

104-
# Adding task to the vesta pipe
81+
# Restart named
10582
$BIN/v_restart_dns
10683

10784
# Logging
108-
log_history "$EVENT" "v_delete_dns_domain_record $user $domain $id"
85+
log_history "$EVENT"
10986
log_event "$OK" "$EVENT"
11087

11188
exit

bin/v_add_mail_account

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ is_system_enabled 'MAIL_SYSTEM'
4141
is_object_valid 'user' 'USER' "$user"
4242

4343
# Checking user is active
44-
is_object_suspended 'user' 'USER' "$user"
44+
is_object_unsuspended 'user' 'USER' "$user"
4545

4646
# Checking domain
4747
is_domain_valid 'mail'

bin/v_add_mail_account_alias

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ is_system_enabled 'MAIL_SYSTEM'
4040
is_object_valid 'user' 'USER' "$user"
4141

4242
# Checking user is active
43-
is_object_suspended 'user' 'USER' "$user"
43+
is_object_unsuspended 'user' 'USER' "$user"
4444

4545
# Checking domain
4646
is_domain_valid 'mail'

bin/v_add_mail_account_autoreply

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ check_args '4' "$#" 'user domain account alias'
3030
validate_format 'user' 'domain' 'account' 'malias'
3131
is_system_enabled 'MAIL_SYSTEM'
3232
is_object_valid 'user' 'USER' "$user"
33-
is_object_suspended 'user' 'USER' "$user"
33+
is_object_unsuspended 'user' 'USER' "$user"
3434
is_object_valid 'mail' 'DOMAIN' "$domain"
35-
is_object_suspended 'mail' 'DOMAIN' "$domain"
35+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
3636
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
37-
is_object_suspended "mail/$domain" 'ACCOUNT' "$account"
37+
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
3838
is_key_empty "mail/$domain" '' '$AUTOREPLY'
3939
exit
4040

bin/v_add_mail_domain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ is_system_enabled 'MAIL_SYSTEM'
4242
is_object_valid 'user' 'USER' "$user"
4343

4444
# Checking user is active
45-
is_object_suspended 'user' 'USER' "$user"
45+
is_object_unsuspended 'user' 'USER' "$user"
4646

4747
# Checking domain
4848
is_domain_new 'mail'

bin/v_add_mail_domain_antispam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ is_system_enabled 'MAIL_SYSTEM'
3838
is_object_valid 'user' 'USER' "$user"
3939

4040
# Checking user is active
41-
is_object_suspended 'user' 'USER' "$user"
41+
is_object_unsuspended 'user' 'USER' "$user"
4242

4343
# Checking domain
4444
is_domain_valid 'mail'

0 commit comments

Comments
 (0)