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:]')
2323dvalue=$( idn -t --quiet -u " $5 " )
2424dvalue=$( echo $dvalue | tr ' [:upper:]' ' [:lower:]' )
2525id=$6
26+ priority=$7
2627
27- # Importing variables
28+ # Includes
2829source $VESTA /conf/vesta.conf
2930source $VESTA /func/shared.sh
3031source $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]'
4139validate_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 "
4741is_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 "
5945is_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
6747validate_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
8666sort_dns_records
8767
8868# Updating zone
89- conf=" $HOMEDIR /$user /conf/dns/$domain .db"
9069update_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 "
10279increase_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 "
10986log_event " $OK " " $EVENT "
11087
11188exit
0 commit comments