From b998c725003e7462b80207295328888ef564a4a8 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Thu, 8 Mar 2012 23:37:03 +0200 Subject: [PATCH] Refactoring stage II --- bin/v_add_cron_job | 2 +- bin/v_add_cron_report | 2 +- bin/v_add_db_base | 2 +- bin/v_add_dns_domain | 41 +++---- bin/v_add_dns_domain_record | 67 ++++-------- bin/v_add_mail_account | 2 +- bin/v_add_mail_account_alias | 2 +- bin/v_add_mail_account_autoreply | 6 +- bin/v_add_mail_domain | 2 +- bin/v_add_mail_domain_antispam | 2 +- bin/v_add_mail_domain_antivirus | 2 +- bin/v_add_mail_domain_cactchall | 2 +- bin/v_add_mail_domain_dkim | 2 +- bin/v_add_web_domain | 2 +- bin/v_add_web_domain_alias | 2 +- bin/v_add_web_domain_cgi | 2 +- bin/v_add_web_domain_elog | 2 +- bin/v_add_web_domain_nginx | 2 +- bin/v_add_web_domain_ssl | 2 +- bin/v_add_web_domain_stat | 2 +- bin/v_add_web_domain_stat_auth | 2 +- bin/v_change_cron_job | 2 +- bin/v_change_db_password | 2 +- bin/v_change_dns_domain_exp | 32 ++---- bin/v_change_dns_domain_ip | 35 ++---- bin/v_change_dns_domain_record | 64 +++++------ bin/v_change_dns_domain_soa | 33 ++---- bin/v_change_dns_domain_tpl | 51 ++++----- bin/v_change_dns_domain_ttl | 32 ++---- bin/v_change_mail_domain_cactchall | 2 +- bin/v_change_sys_ip_owner | 2 +- bin/v_change_user_contact | 2 +- bin/v_change_user_name | 2 +- bin/v_change_user_ns | 2 +- bin/v_change_user_password | 2 +- bin/v_change_user_shell | 2 +- bin/v_change_web_domain_ip | 2 +- bin/v_change_web_domain_sslcert | 2 +- bin/v_change_web_domain_sslhome | 2 +- bin/v_change_web_domain_tpl | 2 +- bin/v_delete_cron_job | 4 +- bin/v_delete_cron_reports | 2 +- bin/v_delete_db_base | 2 +- bin/v_delete_dns_domain | 50 +++------ bin/v_delete_dns_domain_record | 35 ++---- bin/v_delete_dns_domains | 36 ++---- bin/v_delete_mail_domain | 2 +- bin/v_delete_mail_domain_antispam | 2 +- bin/v_delete_mail_domain_antivirus | 2 +- bin/v_delete_mail_domain_cactchall | 2 +- bin/v_delete_mail_domain_dkim | 2 +- bin/v_delete_user | 2 +- bin/v_delete_user_ips | 2 +- bin/v_delete_web_domain | 2 +- bin/v_delete_web_domain_alias | 2 +- bin/v_delete_web_domain_cgi | 2 +- bin/v_delete_web_domain_elog | 2 +- bin/v_delete_web_domain_nginx | 2 +- bin/v_delete_web_domain_ssl | 2 +- bin/v_delete_web_domain_stat | 2 +- bin/v_delete_web_domain_stat_auth | 2 +- bin/v_get_dns_domain_value | 23 +--- bin/v_get_user_value | 2 +- bin/v_get_web_domain_value | 2 +- bin/v_list_dns_domain | 15 +-- bin/v_list_dns_domain_records | 43 +------- bin/v_list_dns_domains | 13 +-- bin/v_list_dns_template | 56 +++------- bin/v_list_dns_templates | 14 +-- bin/v_list_user | 28 +---- bin/v_rebuild_dns_domains | 47 +++----- bin/v_rebuild_mail_domains | 2 +- bin/v_rebuild_web_domains | 2 +- bin/v_restart_dns | 2 +- bin/v_suspend_cron_job | 4 +- bin/v_suspend_dns_domain | 40 +++---- bin/v_suspend_dns_domains | 24 +--- bin/v_suspend_mail_domain | 2 +- bin/v_suspend_user | 2 +- bin/v_unsuspend_cron_job | 2 +- bin/v_unsuspend_dns_domain | 36 ++---- bin/v_unsuspend_dns_domains | 31 +----- bin/v_unsuspend_mail_domain | 2 +- data/templates/dns/default.tpl | 18 +-- data/templates/dns/gmail.tpl | 28 ++--- func/domain.sh | 170 ++++++++--------------------- func/shared.sh | 106 ++++++++---------- test/test_json_listing.sh | 22 ++-- 88 files changed, 422 insertions(+), 896 deletions(-) diff --git a/bin/v_add_cron_job b/bin/v_add_cron_job index 776071877..0d765978f 100755 --- a/bin/v_add_cron_job +++ b/bin/v_add_cron_job @@ -33,7 +33,7 @@ check_args '7' "$#" 'user min hour day month wday command [job]' validate_format 'user' 'min' 'hour' 'day' 'month' 'wday' 'command' is_system_enabled $CRON_SYSTEM is_object_valid 'user' 'USER' "$user" -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" is_package_full 'CRON_JOBS' get_next_cronjob validate_format 'job' diff --git a/bin/v_add_cron_report b/bin/v_add_cron_report index f77b1c899..68ea3f6d4 100755 --- a/bin/v_add_cron_report +++ b/bin/v_add_cron_report @@ -26,7 +26,7 @@ check_args '1' "$#" 'user' validate_format 'user' is_system_enabled "$CRON_SYSTEM" is_object_valid 'user' 'USER' "$user" -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# diff --git a/bin/v_add_db_base b/bin/v_add_db_base index d0846c26a..34aa50d3b 100755 --- a/bin/v_add_db_base +++ b/bin/v_add_db_base @@ -40,7 +40,7 @@ validate_format 'user' 'database' 'db_user' 'db_password' 'encoding' is_system_enabled 'DB_SYSTEM' is_type_valid "$DB_SYSTEM" "$type" is_object_valid 'user' 'USER' "$user" -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" is_object_free 'db' 'DB' "$database" get_next_dbhost is_object_valid "$type" 'DBHOST' "$host" diff --git a/bin/v_add_dns_domain b/bin/v_add_dns_domain index 34c44ca8a..90b299979 100755 --- a/bin/v_add_dns_domain +++ b/bin/v_add_dns_domain @@ -25,7 +25,7 @@ exp=${5-$next_year} soa=$6 ttl=${7-14400} -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -35,30 +35,16 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain ip [template] [exp] [soa] [ttl]' - -# Checking argument format validate_format 'user' 'domain' 'ip' 'template' 'exp' 'ttl' - -# Checking dns system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active -is_object_suspended 'user' 'USER' "$user" - -# Checking domain +is_object_unsuspended 'user' 'USER' "$user" is_domain_new 'dns' - -# Checking package is_package_full 'DNS_DOMAINS' - -# Checking template is_dns_template_valid + #----------------------------------------------------------# # Action # #----------------------------------------------------------# @@ -68,9 +54,10 @@ i=1 ns=$(get_user_value '$NS') for nameserver in ${ns//,/ };do eval ns$i=$nameserver - i=$((i + 1)) + (( ++i)) done +# Define soa if [ -z "$soa" ]; then soa="$ns1" fi @@ -88,13 +75,16 @@ cat $DNSTPL/$template.tpl |\ -e "s/%ns6%/$ns6/g" \ -e "s/%ns7%/$ns7/g" \ -e "s/%ns8%/$ns8/g" \ - -e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain - -records="$(wc -l $USER_DATA/dns/$domain)" + -e "s/%time%/$TIME/g" \ + -e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf +chmod 660 $USER_DATA/dns/$domain.conf +records="$(wc -l $USER_DATA/dns/$domain.conf |cut -f 1 -d ' ')" # Adding dns.conf record dns_rec="DOMAIN='$domain' IP='$ip' TPL='$template' TTL='$ttl' EXP='$exp'" -dns_rec="$dns_rec SOA='$soa' RECORDS='$records' SUSPENDED='no' DATE='$DATE'" +dns_rec="$dns_rec SOA='$soa' RECORDS='$records' SUSPENDED='no' TIME='$TIME'" +dns_rec="$dns_rec DATE='$DATE'" + echo "$dns_rec" >> $USER_DATA/dns.conf chmod 660 $USER_DATA/dns.conf @@ -104,7 +94,6 @@ named="$named \"$HOMEDIR/$user/conf/dns/$domain.db\";};" echo "$named" >> /etc/named.conf # Updating domain dns zone -conf="$HOMEDIR/$user/conf/dns/$domain.db" update_domain_zone chmod 640 $conf @@ -119,11 +108,11 @@ chown root:named $conf increase_user_value "$user" '$U_DNS_DOMAINS' increase_user_value "$user" '$U_DNS_RECORDS' "$records" -# Adding task to the vesta pipe +# Restart named $BIN/v_restart_dns # Logging -log_history "$EVENT" "v_delete_dns_domain $user $domain" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_add_dns_domain_record b/bin/v_add_dns_domain_record index 88757deb6..5369f1408 100755 --- a/bin/v_add_dns_domain_record +++ b/bin/v_add_dns_domain_record @@ -1,6 +1,6 @@ #!/bin/bash # info: add dns domain record -# options: user domain record type value [id] +# options: user domain record type value [id] [priority] # # The call is used for adding new DNS record. Complex records of TXT, MX and # 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:]') dvalue=$(idn -t --quiet -u "$5" ) dvalue=$(echo $dvalue | tr '[:upper:]' '[:lower:]') id=$6 +priority=$7 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -34,59 +35,37 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number -check_args '5' "$#" 'user domain record type value [id]' - -# Checking argument format +check_args '5' "$#" 'user domain record type value [id] [priority]' validate_format 'user' 'domain' 'record' 'rtype' 'dvalue' - -# Checking web system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active -is_object_suspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' - -# Checking domain is active -is_domain_suspended 'dns' - -# Checking package +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'dns' 'DOMAIN' "$domain" +is_object_unsuspended 'dns' 'DOMAIN' "$domain" is_package_full 'DNS_RECORDS' - -# Defining if emtpy -if [ -z "$id"] ; then - id=$(get_next_dns_record) -fi - -# Checking id format +get_next_dnsrecord validate_format 'id' - -# Checking id -is_dns_record_free +is_object_free "dns/$domain" 'ID' "$id" #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Defining zone path -zone="$USER_DATA/dns/$domain" +if [ "$rtype" != 'MX' ] || [ "$rtype" != 'SRV' ]; then + priority='' +fi # Adding record -dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' VALUE='$dvalue'" -dns_rec="$dns_rec SUSPENDED='no' DATE='$DATE'" -echo "$dns_rec" >> $zone +zone="$USER_DATA/dns/$domain.conf" +dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'" +dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$TIME' DATE='$DATE'" +echo "$dns_rec" >> $zone # Sorting records sort_dns_records # Updating zone -conf="$HOMEDIR/$user/conf/dns/$domain.db" update_domain_zone @@ -94,18 +73,16 @@ update_domain_zone # Vesta # #----------------------------------------------------------# -# Updating dns domain values -records="$(wc -l $USER_DATA/dns/$domain)" -update_domain_value 'dns' '$RECORDS' "$records" - -# Updating user counters +# Upddate counters +records="$(wc -l $USER_DATA/dns/$domain.conf | cut -f1 -d ' ')" +update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records" increase_user_value "$user" '$U_DNS_RECORDS' -# Adding task to the vesta pipe +# Restart named $BIN/v_restart_dns # Logging -log_history "$EVENT" "v_delete_dns_domain_record $user $domain $id" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_add_mail_account b/bin/v_add_mail_account index f3be8a6ab..79dea41d4 100755 --- a/bin/v_add_mail_account +++ b/bin/v_add_mail_account @@ -41,7 +41,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_valid 'mail' diff --git a/bin/v_add_mail_account_alias b/bin/v_add_mail_account_alias index 385d8b19e..c8f2f3311 100755 --- a/bin/v_add_mail_account_alias +++ b/bin/v_add_mail_account_alias @@ -40,7 +40,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_valid 'mail' diff --git a/bin/v_add_mail_account_autoreply b/bin/v_add_mail_account_autoreply index 3cba3eec0..ca2c1c63b 100755 --- a/bin/v_add_mail_account_autoreply +++ b/bin/v_add_mail_account_autoreply @@ -30,11 +30,11 @@ check_args '4' "$#" 'user domain account alias' validate_format 'user' 'domain' 'account' 'malias' is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" is_object_valid 'mail' 'DOMAIN' "$domain" -is_object_suspended 'mail' 'DOMAIN' "$domain" +is_object_unsuspended 'mail' 'DOMAIN' "$domain" is_object_valid "mail/$domain" 'ACCOUNT' "$account" -is_object_suspended "mail/$domain" 'ACCOUNT' "$account" +is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account" is_key_empty "mail/$domain" '' '$AUTOREPLY' exit diff --git a/bin/v_add_mail_domain b/bin/v_add_mail_domain index 44dd82c43..9149c6c91 100755 --- a/bin/v_add_mail_domain +++ b/bin/v_add_mail_domain @@ -42,7 +42,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_new 'mail' diff --git a/bin/v_add_mail_domain_antispam b/bin/v_add_mail_domain_antispam index 5912e3bdf..1ed832419 100755 --- a/bin/v_add_mail_domain_antispam +++ b/bin/v_add_mail_domain_antispam @@ -38,7 +38,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_valid 'mail' diff --git a/bin/v_add_mail_domain_antivirus b/bin/v_add_mail_domain_antivirus index 4d9a1b2a9..7e0790640 100755 --- a/bin/v_add_mail_domain_antivirus +++ b/bin/v_add_mail_domain_antivirus @@ -38,7 +38,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_valid 'mail' diff --git a/bin/v_add_mail_domain_cactchall b/bin/v_add_mail_domain_cactchall index bead73266..d9f71ff3e 100755 --- a/bin/v_add_mail_domain_cactchall +++ b/bin/v_add_mail_domain_cactchall @@ -39,7 +39,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_valid 'mail' diff --git a/bin/v_add_mail_domain_dkim b/bin/v_add_mail_domain_dkim index e3886a5e9..a5fbb9420 100755 --- a/bin/v_add_mail_domain_dkim +++ b/bin/v_add_mail_domain_dkim @@ -39,7 +39,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_valid 'mail' diff --git a/bin/v_add_web_domain b/bin/v_add_web_domain index ef5a6bdc4..2413400fd 100755 --- a/bin/v_add_web_domain +++ b/bin/v_add_web_domain @@ -46,7 +46,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_new 'dns' diff --git a/bin/v_add_web_domain_alias b/bin/v_add_web_domain_alias index dddd747d1..78fdbdaa5 100755 --- a/bin/v_add_web_domain_alias +++ b/bin/v_add_web_domain_alias @@ -42,7 +42,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_add_web_domain_cgi b/bin/v_add_web_domain_cgi index f154fc51d..ab04a362c 100755 --- a/bin/v_add_web_domain_cgi +++ b/bin/v_add_web_domain_cgi @@ -40,7 +40,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_add_web_domain_elog b/bin/v_add_web_domain_elog index a9822b06d..3ce44db3d 100755 --- a/bin/v_add_web_domain_elog +++ b/bin/v_add_web_domain_elog @@ -38,7 +38,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_add_web_domain_nginx b/bin/v_add_web_domain_nginx index d599c51f5..afb9c5207 100755 --- a/bin/v_add_web_domain_nginx +++ b/bin/v_add_web_domain_nginx @@ -42,7 +42,7 @@ is_system_enabled 'proxy' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_add_web_domain_ssl b/bin/v_add_web_domain_ssl index bd4c9a3a2..594f22bbe 100755 --- a/bin/v_add_web_domain_ssl +++ b/bin/v_add_web_domain_ssl @@ -45,7 +45,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_add_web_domain_stat b/bin/v_add_web_domain_stat index 65cc5837a..89bc944ff 100755 --- a/bin/v_add_web_domain_stat +++ b/bin/v_add_web_domain_stat @@ -42,7 +42,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_add_web_domain_stat_auth b/bin/v_add_web_domain_stat_auth index 7728eef7d..b8d589378 100755 --- a/bin/v_add_web_domain_stat_auth +++ b/bin/v_add_web_domain_stat_auth @@ -38,7 +38,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_change_cron_job b/bin/v_change_cron_job index 0b7b909ad..c25783dd5 100755 --- a/bin/v_change_cron_job +++ b/bin/v_change_cron_job @@ -33,7 +33,7 @@ check_args '7' "$#" 'user job min hour day month wday command' validate_format 'user' 'job' 'min' 'hour' 'day' 'month' 'wday' 'command' is_system_enabled $CRON_SYSTEM is_object_valid 'user' 'USER' "$user" -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" is_object_valid 'cron' 'JOB' "$job" diff --git a/bin/v_change_db_password b/bin/v_change_db_password index 6f7594448..47199df52 100755 --- a/bin/v_change_db_password +++ b/bin/v_change_db_password @@ -38,7 +38,7 @@ is_system_enabled 'DB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking db existance is_db_valid diff --git a/bin/v_change_dns_domain_exp b/bin/v_change_dns_domain_exp index e32e4808a..e28275d02 100755 --- a/bin/v_change_dns_domain_exp +++ b/bin/v_change_dns_domain_exp @@ -16,47 +16,31 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") exp=$3 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh -source $VESTA/func/domain.sh #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain exp' - -# Checking argument format validate_format 'user' 'domain' 'exp' - -# Checking web system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active -is_object_suspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' - -# Checking domain is not suspened -is_domain_suspended 'dns' +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'dns' 'DOMAIN' "$domain" +is_object_unsuspended 'dns' 'DOMAIN' "$domain" #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Get old expiriation date -old_exp=$(get_domain_value 'dns' '$EXP') - # Changing exp -update_domain_value 'dns' '$EXP' "$exp" +update_object_value 'dns' 'DOMAIN' "$domain" '$EXP' "$exp" + #----------------------------------------------------------# @@ -64,7 +48,7 @@ update_domain_value 'dns' '$EXP' "$exp" #----------------------------------------------------------# # Logging -log_history "$EVENT" "$SCRIPT $user $domain $old_exp" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_change_dns_domain_ip b/bin/v_change_dns_domain_ip index c450fecff..a712d6262 100755 --- a/bin/v_change_dns_domain_ip +++ b/bin/v_change_dns_domain_ip @@ -15,49 +15,34 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") ip=$3 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh + #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain ip' - -# Checking argument format validate_format 'user' 'domain' 'ip' - -# Checking web system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active -is_object_suspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' - -# Checking domain is not suspened -is_domain_suspended 'dns' +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'dns' 'DOMAIN' "$domain" +is_object_unsuspended 'dns' 'DOMAIN' "$domain" #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Get old ip -old_ip=$(get_domain_value 'dns' '$IP') - # Changing ip -update_domain_value 'dns' '$IP' "$ip" +update_object_value 'dns' 'DOMAIN' "$domain" '$IP' "$ip" # Changing records -sed -i "s/$old_ip/$ip/g" $USER_DATA/dns/$domain +sed -i "s/$old_ip/$ip/g" $USER_DATA/dns/$domain.conf # Updating zone update_domain_zone @@ -67,11 +52,11 @@ update_domain_zone # Vesta # #----------------------------------------------------------# -# Adding task to the vesta pipe +# Restart named $BIN/v_restart_dns # Logging -log_history "$EVENT" "$SCRIPT $user $domain $old_ip" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_change_dns_domain_record b/bin/v_change_dns_domain_record index c7cd1c383..e79d7a588 100755 --- a/bin/v_change_dns_domain_record +++ b/bin/v_change_dns_domain_record @@ -1,6 +1,6 @@ #!/bin/bash # info: change dns domain record -# options: user domain id record type value +# options: user domain record type value id [priority] # # The function for changing DNS record. @@ -12,13 +12,17 @@ # Argument defenition user=$1 domain=$(idn -t --quiet -u "$2" ) +domain=$(echo $domain | tr '[:upper:]' '[:lower:]') domain_idn=$(idn -t --quiet -a "$domain") -id=$3 -record=$(idn -t --quiet -u "$4" ) -rtype=$(echo "$5"| tr '[:lower:]' '[:upper:]') -value=$(idn -t --quiet -u "$6" ) +record=$(idn -t --quiet -u "$3" ) +record=$(echo $record | tr '[:upper:]' '[:lower:]') +rtype=$(echo "$4"| tr '[:lower:]' '[:upper:]') +dvalue=$(idn -t --quiet -u "$5" ) +dvalue=$(echo $dvalue | tr '[:upper:]' '[:lower:]') +id=$6 +priority=$7 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -28,47 +32,31 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number -check_args '5' "$#" 'user domain id record type value' - -# Checking argument format -validate_format 'user' 'domain' 'id' 'record' 'rtype' - -# Checking web system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +check_args '6' "$#" 'user domain record type value id [priority]' +validate_format 'user' 'domain' 'record' 'rtype' 'dvalue' 'id' +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'dns' 'DOMAIN' "$domain" +is_object_unsuspended 'dns' 'DOMAIN' "$domain" +is_object_valid "dns/$domain" 'ID' "$id" -# Checking user is active -is_object_suspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' - -# Checking domain is not suspened -is_domain_suspended 'dns' - -# Checking record valid -is_dns_record_valid #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Defining zone path -zone="$USER_DATA/dns/$domain" - -# Deleting old record -rm_string=$(grep -n "^ID='$id'" $zone|cut -d : -f 1) -if [ ! -z "$rm_string" ]; then - sed -i "$rm_string d" $zone +if [ "$rtype" != 'MX' ] || [ "$rtype" != 'SRV' ]; then + priority='' fi +# Deleting old record +sed -i "/^ID='$id'/d" $USER_DATA/dns/$domain.conf + # Adding record -dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' VALUE='$value'" -dns_rec="$dns_rec SUSPENDED='no' DATE='$DATE'" -echo "$dns_rec" >> $zone +dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'" +dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$TIME' DATE='$DATE'" +echo "$dns_rec" >> $USER_DATA/dns/$domain.conf # Sorting records sort_dns_records @@ -81,7 +69,7 @@ update_domain_zone # Vesta # #----------------------------------------------------------# -# Adding task to the vesta pipe +# Restart named $BIN/v_restart_dns # Logging diff --git a/bin/v_change_dns_domain_soa b/bin/v_change_dns_domain_soa index 17be8de87..bc07f29b0 100755 --- a/bin/v_change_dns_domain_soa +++ b/bin/v_change_dns_domain_soa @@ -16,46 +16,31 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") soa=$3 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh + #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain soa' - -# Checking argument format validate_format 'user' 'domain' 'soa' - -# Checking web system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active -is_object_suspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' - -# Checking domain is not suspened -is_domain_suspended 'dns' +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'dns' 'DOMAIN' "$domain" +is_object_unsuspended 'dns' 'DOMAIN' "$domain" #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Get old soa -old_soa=$(get_domain_value 'dns' '$SOA') - # Changing soa -update_domain_value 'dns' '$SOA' "$soa" +update_object_value 'dns' 'DOMAIN' "$domain" '$SOA' "$soa" # Updating zone update_domain_zone @@ -65,11 +50,11 @@ update_domain_zone # Vesta # #----------------------------------------------------------# -# Adding task to the vesta pipe +# Restart named $BIN/v_restart_dns # Logging -log_history "$EVENT" "$SCRIPT $user $domain $old_soa" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_change_dns_domain_tpl b/bin/v_change_dns_domain_tpl index 011f002ea..43f6ce811 100755 --- a/bin/v_change_dns_domain_tpl +++ b/bin/v_change_dns_domain_tpl @@ -17,7 +17,7 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") template=$3 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -27,28 +27,13 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain template' - -# Checking argument format validate_format 'user' 'domain' 'template' - -# Checking web system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active -is_object_suspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' - -# Checking domain is not suspened -is_domain_suspended 'dns' - -# Checking template +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'dns' 'DOMAIN' "$domain" +is_object_unsuspended 'dns' 'DOMAIN' "$domain" is_dns_template_valid @@ -56,14 +41,20 @@ is_dns_template_valid # Action # #----------------------------------------------------------# -# Get vals -old_tpl=$(get_domain_value 'dns' '$TPL') -ip=$(get_domain_value 'dns' '$IP') -ns1=$(get_user_value '$NS1') -ns2=$(get_user_value '$NS2') +# Defining variables +ip=$(get_object_value 'dns' 'DOMAIN' "$domain" '$IP') + +i=1 +ns=$(get_user_value '$NS') +for nameserver in ${ns//,/ };do + eval ns$i=$nameserver + (( ++i)) +done # Changing tpl -update_domain_value 'dns' '$TPL' "$template" +update_object_value 'dns' 'DOMAIN' "$domain" '$TPL' "$template" + +# Adding zone to dns dir cat $DNSTPL/$template.tpl |\ sed -e "s/%ip%/$ip/g" \ -e "s/%domain_idn%/$domain_idn/g" \ @@ -76,10 +67,10 @@ cat $DNSTPL/$template.tpl |\ -e "s/%ns6%/$ns6/g" \ -e "s/%ns7%/$ns7/g" \ -e "s/%ns8%/$ns8/g" \ - -e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain + -e "s/%time%/$TIME/g" \ + -e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf # Updating zone -conf="$HOMEDIR/$user/conf/dns/$domain.db" update_domain_zone @@ -87,11 +78,11 @@ update_domain_zone # Vesta # #----------------------------------------------------------# -# Adding task to the vesta pipe +# Restart named $BIN/v_restart_dns # Logging -log_history "$EVENT" "$SCRIPT $user $domain $old_tpl" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_change_dns_domain_ttl b/bin/v_change_dns_domain_ttl index e14b1343b..cb7a610d8 100755 --- a/bin/v_change_dns_domain_ttl +++ b/bin/v_change_dns_domain_ttl @@ -15,7 +15,7 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") ttl=$3 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -25,37 +25,21 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain ttl' - -# Checking argument format validate_format 'user' 'domain' 'ttl' - -# Checking web system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active -is_object_suspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' - -# Checking domain is not suspened -is_domain_suspended 'dns' +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'dns' 'DOMAIN' "$domain" +is_object_unsuspended 'dns' 'DOMAIN' "$domain" #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Get old ttl -old_ttl=$(get_domain_value 'dns' '$TTL') - # Changing ttl -update_domain_value 'dns' '$TTL' "$ttl" +update_object_value 'dns' 'DOMAIN' "$domain" '$TTL' "$ttl" # Updating zone update_domain_zone @@ -65,11 +49,11 @@ update_domain_zone # Vesta # #----------------------------------------------------------# -# Adding task to the vesta pipe +# Restart named $BIN/v_restart_dns # Logging -log_history "$EVENT" "$SCRIPT $user $domain $old_ttl" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_change_mail_domain_cactchall b/bin/v_change_mail_domain_cactchall index 48b0e5414..9d7beda90 100755 --- a/bin/v_change_mail_domain_cactchall +++ b/bin/v_change_mail_domain_cactchall @@ -39,7 +39,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_valid 'mail' diff --git a/bin/v_change_sys_ip_owner b/bin/v_change_sys_ip_owner index f276c4dfb..f8eb6269f 100755 --- a/bin/v_change_sys_ip_owner +++ b/bin/v_change_sys_ip_owner @@ -33,7 +33,7 @@ validate_format 'ip' 'user' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking system ip is_sys_ip_valid diff --git a/bin/v_change_user_contact b/bin/v_change_user_contact index 2ea9ec771..5a835ae5e 100755 --- a/bin/v_change_user_contact +++ b/bin/v_change_user_contact @@ -32,7 +32,7 @@ validate_format 'user' 'email' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# diff --git a/bin/v_change_user_name b/bin/v_change_user_name index 182963958..edd16368c 100755 --- a/bin/v_change_user_name +++ b/bin/v_change_user_name @@ -33,7 +33,7 @@ validate_format 'user' 'fname' 'lname' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# diff --git a/bin/v_change_user_ns b/bin/v_change_user_ns index dd65ad307..f1d5e36af 100755 --- a/bin/v_change_user_ns +++ b/bin/v_change_user_ns @@ -62,7 +62,7 @@ fi is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# diff --git a/bin/v_change_user_password b/bin/v_change_user_password index 9fad79e5a..214c29c3f 100755 --- a/bin/v_change_user_password +++ b/bin/v_change_user_password @@ -32,7 +32,7 @@ validate_format 'user' 'password' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# diff --git a/bin/v_change_user_shell b/bin/v_change_user_shell index d1c1c3ca0..9051e71d7 100755 --- a/bin/v_change_user_shell +++ b/bin/v_change_user_shell @@ -32,7 +32,7 @@ validate_format 'user' 'shell' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# diff --git a/bin/v_change_web_domain_ip b/bin/v_change_web_domain_ip index 0163d9f70..e138816f6 100755 --- a/bin/v_change_web_domain_ip +++ b/bin/v_change_web_domain_ip @@ -40,7 +40,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_change_web_domain_sslcert b/bin/v_change_web_domain_sslcert index 1cdb0db33..974c4b20a 100755 --- a/bin/v_change_web_domain_sslcert +++ b/bin/v_change_web_domain_sslcert @@ -39,7 +39,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_change_web_domain_sslhome b/bin/v_change_web_domain_sslhome index b5e4f7987..ae2b393c5 100755 --- a/bin/v_change_web_domain_sslhome +++ b/bin/v_change_web_domain_sslhome @@ -34,7 +34,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_change_web_domain_tpl b/bin/v_change_web_domain_tpl index 6a5b20dec..2c753bdd0 100755 --- a/bin/v_change_web_domain_tpl +++ b/bin/v_change_web_domain_tpl @@ -39,7 +39,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_delete_cron_job b/bin/v_delete_cron_job index 79c4e7591..6f8c6ab14 100755 --- a/bin/v_delete_cron_job +++ b/bin/v_delete_cron_job @@ -26,9 +26,9 @@ check_args '2' "$#" 'user job' validate_format 'user' 'job' is_system_enabled "$CRON_SYSTEM" is_object_valid 'user' 'USER' "$user" -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" is_object_valid 'cron' 'JOB' "$job" -is_object_suspended 'cron' 'JOB' "$job" +is_object_unsuspended 'cron' 'JOB' "$job" #----------------------------------------------------------# diff --git a/bin/v_delete_cron_reports b/bin/v_delete_cron_reports index 03b923679..a18a09bf5 100755 --- a/bin/v_delete_cron_reports +++ b/bin/v_delete_cron_reports @@ -26,7 +26,7 @@ check_args '1' "$#" 'user' validate_format 'user' is_system_enabled "$CRON_SYSTEM" is_object_valid 'user' 'USER' "$user" -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# diff --git a/bin/v_delete_db_base b/bin/v_delete_db_base index 3df8a40ad..ebaf747a9 100755 --- a/bin/v_delete_db_base +++ b/bin/v_delete_db_base @@ -37,7 +37,7 @@ is_system_enabled 'DB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking db existance is_db_valid diff --git a/bin/v_delete_dns_domain b/bin/v_delete_dns_domain index 5eaea5b0c..670a22780 100755 --- a/bin/v_delete_dns_domain +++ b/bin/v_delete_dns_domain @@ -13,9 +13,9 @@ # Argument defenition user=$1 domain=$(idn -t --quiet -u "$2" ) -named_conf=/etc/named.conf +restart="$3" -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -25,43 +25,24 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'user domain' - -# Checking argument format validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active -is_object_suspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'dns' 'DOMAIN' "$domain" +is_object_unsuspended 'dns' 'DOMAIN' "$domain" #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Get domain values -tpl_name=$(get_domain_value 'dns' '$TPL') -old_ip=$(get_domain_value 'dns' '$IP') -records=$(wc -l $USER_DATA/dns/$domain|cut -f 1 -d ' ') +records=$(wc -l $USER_DATA/dns/$domain.conf | cut -f 1 -d ' ') # Deleting domain in named.conf -rm_string=$(grep -n /conf/dns/$domain.db $named_conf |cut -d : -f 1) -if [ ! -z "$rm_string" ]; then - sed -i "$rm_string d" $named_conf -fi - -if [ -e "$HOMEDIR/$user/conf/dns/$domain.db" ]; then - rm -f $HOMEDIR/$user/conf/dns/$domain.db -fi +sed -i "/\/$domain.db\"/d" /etc/named.conf +rm -f $HOMEDIR/$user/conf/dns/$domain.db #----------------------------------------------------------# @@ -69,18 +50,21 @@ fi #----------------------------------------------------------# # Deleting domain -sed -i "/DOMAIN='$domain'/ d" $USER_DATA/dns.conf -rm -f $USER_DATA/dns/$domain +sed -i "/DOMAIN='$domain'/d" $USER_DATA/dns.conf +rm -f $USER_DATA/dns/$domain.conf # Decreasing domain value decrease_user_value "$user" '$U_DNS_DOMAINS' decrease_user_value "$user" '$U_DNS_RECORDS' "$records" -# Adding task to the vesta pipe -$BIN/v_restart_dns +# Restart named +if [ "$restart" != 'no' ]; then + $BIN/v_restart_dns +fi + # Logging -log_history "$EVENT" "v_add_dns_domain $user $domain $old_ip $tpl_name" +log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/bin/v_delete_dns_domain_record b/bin/v_delete_dns_domain_record index 54b820945..bb3606869 100755 --- a/bin/v_delete_dns_domain_record +++ b/bin/v_delete_dns_domain_record @@ -15,7 +15,7 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") id=$3 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh @@ -25,26 +25,13 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '3' "$#" 'user domain id' - -# Checking argument format validate_format 'user' 'domain' 'id' - -# Checking user is_object_valid 'user' 'USER' "$user" - -# Checking user is active -is_object_suspended 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' - -# Checking domain is not suspened -is_domain_suspended 'dns' - -# Checking record valid -is_dns_record_valid +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'dns' 'DOMAIN' "$domain" +is_object_unsuspended 'dns' 'DOMAIN' "$domain" +is_object_valid "dns/$domain" 'ID' "$id" #----------------------------------------------------------# @@ -52,17 +39,9 @@ is_dns_record_valid #----------------------------------------------------------# # Deleting record -conf="$USER_DATA/dns/$domain" -rm_string=$(grep -n "^ID='$id'" $conf|cut -d : -f 1) -if [ ! -z "$rm_string" ]; then - sed -i "$rm_string d" $conf -fi - -# Sorting records -sort_dns_records +sed -i "/^ID='$id'/d" $USER_DATA/dns/$domain.conf # Updating zone -conf="$HOMEDIR/$user/conf/dns/$domain.db" update_domain_zone @@ -70,7 +49,7 @@ update_domain_zone # Vesta # #----------------------------------------------------------# -# Adding task to the vesta pipe +# Restart named $BIN/v_restart_dns # Logging diff --git a/bin/v_delete_dns_domains b/bin/v_delete_dns_domains index 544d6c2ac..ca1cd9410 100755 --- a/bin/v_delete_dns_domains +++ b/bin/v_delete_dns_domains @@ -12,26 +12,18 @@ # Argument defenition user=$1 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh -source $VESTA/func/domain.sh #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '1' "$#" 'user' - -# Checking argument format validate_format 'user' - -# Checking web system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" @@ -39,26 +31,9 @@ is_object_valid 'user' 'USER' "$user" # Action # #----------------------------------------------------------# -# Defining config -conf="$USER_DATA/dns.conf" - -# Defining fileds to select -field='$DOMAIN' - -# Defining search string -search_string="SUSPENDED='no'" - -# Parsing domain list -domains=$(dom_clear_search) - # Starting delete loop -for domain in $domains; do - $BIN/v_delete_dns_domain "$user" "$domain" - rv="$?" - if [ "$rv" -ne '0' ]; then - log_event 'debug' "$rv $EVENT" - exit $rv - fi +for domain in $(search_objects 'dns' 'SUSPENDED' "no" 'DOMAIN'); do + $BIN/v_delete_dns_domain "$user" "$domain" 'no' done @@ -66,6 +41,9 @@ done # Vesta # #----------------------------------------------------------# +# Restart named +$BIN/v_restart_dns + # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_delete_mail_domain b/bin/v_delete_mail_domain index 9c7f3abb2..e75a69af8 100755 --- a/bin/v_delete_mail_domain +++ b/bin/v_delete_mail_domain @@ -37,7 +37,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'mail' diff --git a/bin/v_delete_mail_domain_antispam b/bin/v_delete_mail_domain_antispam index 0e63353bc..57a8dc5f8 100755 --- a/bin/v_delete_mail_domain_antispam +++ b/bin/v_delete_mail_domain_antispam @@ -38,7 +38,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_valid 'mail' diff --git a/bin/v_delete_mail_domain_antivirus b/bin/v_delete_mail_domain_antivirus index 85c7c5506..c2413ce5f 100755 --- a/bin/v_delete_mail_domain_antivirus +++ b/bin/v_delete_mail_domain_antivirus @@ -38,7 +38,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_valid 'mail' diff --git a/bin/v_delete_mail_domain_cactchall b/bin/v_delete_mail_domain_cactchall index 2277d6016..668700717 100755 --- a/bin/v_delete_mail_domain_cactchall +++ b/bin/v_delete_mail_domain_cactchall @@ -38,7 +38,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_valid 'mail' diff --git a/bin/v_delete_mail_domain_dkim b/bin/v_delete_mail_domain_dkim index 49d1353c8..cae1bbfa2 100755 --- a/bin/v_delete_mail_domain_dkim +++ b/bin/v_delete_mail_domain_dkim @@ -37,7 +37,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_valid 'mail' diff --git a/bin/v_delete_user b/bin/v_delete_user index 11c0e5207..f38441941 100755 --- a/bin/v_delete_user +++ b/bin/v_delete_user @@ -35,7 +35,7 @@ validate_format 'user' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking user admin if [ "$user" = 'admin' ]; then diff --git a/bin/v_delete_user_ips b/bin/v_delete_user_ips index 86a6563e8..acc528a3f 100755 --- a/bin/v_delete_user_ips +++ b/bin/v_delete_user_ips @@ -32,7 +32,7 @@ validate_format 'user' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking user vesta if [ "$user" = 'admin' ]; then diff --git a/bin/v_delete_web_domain b/bin/v_delete_web_domain index ba32675c3..6ddb25c65 100755 --- a/bin/v_delete_web_domain +++ b/bin/v_delete_web_domain @@ -41,7 +41,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_delete_web_domain_alias b/bin/v_delete_web_domain_alias index f161405ea..83872d493 100755 --- a/bin/v_delete_web_domain_alias +++ b/bin/v_delete_web_domain_alias @@ -40,7 +40,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_delete_web_domain_cgi b/bin/v_delete_web_domain_cgi index 38d66532b..252127cd2 100755 --- a/bin/v_delete_web_domain_cgi +++ b/bin/v_delete_web_domain_cgi @@ -40,7 +40,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_delete_web_domain_elog b/bin/v_delete_web_domain_elog index f3666f080..8e081c924 100755 --- a/bin/v_delete_web_domain_elog +++ b/bin/v_delete_web_domain_elog @@ -39,7 +39,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_delete_web_domain_nginx b/bin/v_delete_web_domain_nginx index 4a311dc83..596d8a028 100755 --- a/bin/v_delete_web_domain_nginx +++ b/bin/v_delete_web_domain_nginx @@ -37,7 +37,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_delete_web_domain_ssl b/bin/v_delete_web_domain_ssl index ef1f68dbc..7222bd74e 100755 --- a/bin/v_delete_web_domain_ssl +++ b/bin/v_delete_web_domain_ssl @@ -37,7 +37,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_delete_web_domain_stat b/bin/v_delete_web_domain_stat index 95c2c4d7b..c7804c943 100755 --- a/bin/v_delete_web_domain_stat +++ b/bin/v_delete_web_domain_stat @@ -37,7 +37,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_delete_web_domain_stat_auth b/bin/v_delete_web_domain_stat_auth index 6f3bb1e5c..368c1859b 100755 --- a/bin/v_delete_web_domain_stat_auth +++ b/bin/v_delete_web_domain_stat_auth @@ -40,7 +40,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_get_dns_domain_value b/bin/v_get_dns_domain_value index 89843f953..90b0b4636 100755 --- a/bin/v_get_dns_domain_value +++ b/bin/v_get_dns_domain_value @@ -15,41 +15,26 @@ domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") key=$(echo "$3"| tr '[:lower:]' '[:upper:]'|sed -e "s/^/$/") -# Importing variables -source $VESTA/conf/vesta.conf +# Includes source $VESTA/func/shared.sh -source $VESTA/func/domain.sh #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# -# Checking args check_args '3' "$#" 'user domain key' - -# Checking argument format validate_format 'user' 'domain' - -# Checking user is_object_valid 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' - -# Checking domain is not suspened -is_domain_suspended 'dns' +is_object_valid 'dns' 'DOMAIN' "$domain" #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Checking key -value=$(get_domain_value 'dns' "$key") - -# Printing value -echo "$value" +# Print +get_object_value 'dns' 'DOMAIN' "$domain" "$key" #----------------------------------------------------------# diff --git a/bin/v_get_user_value b/bin/v_get_user_value index 628b6acd2..48d42a775 100755 --- a/bin/v_get_user_value +++ b/bin/v_get_user_value @@ -32,7 +32,7 @@ validate_format 'user' is_object_valid 'user' 'USER' "$user" # Checking domain is not suspened -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# diff --git a/bin/v_get_web_domain_value b/bin/v_get_web_domain_value index 2065fe82a..168e4d75c 100755 --- a/bin/v_get_web_domain_value +++ b/bin/v_get_web_domain_value @@ -37,7 +37,7 @@ validate_format 'user' 'domain' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain exist is_domain_valid 'web' diff --git a/bin/v_list_dns_domain b/bin/v_list_dns_domain index ad640268e..0a2a2763d 100755 --- a/bin/v_list_dns_domain +++ b/bin/v_list_dns_domain @@ -15,7 +15,7 @@ user=$1 domain=$2 format=${3-shell} -# Importing variables +# Includes source $VESTA/func/shared.sh # Json function @@ -76,25 +76,18 @@ shell_list_domain() { # Verifications # #----------------------------------------------------------# -# Checking args check_args '2' "$#" 'user domain [format]' - -# Checking user is_object_valid 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' +is_object_valid 'dns' 'DOMAIN' "$domain" #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Defining config +# Defining config and fields to select conf=$USER_DATA/dns.conf - -# Defining fileds to select -fields='$DOMAIN $IP $TPL $TTL $EXP $SOA $RECORDS $SUSPENDED $DATE' +fields='$DOMAIN $IP $TPL $TTL $EXP $SOA $RECORDS $SUSPENDED $TIME $DATE' # Listing domains case $format in diff --git a/bin/v_list_dns_domain_records b/bin/v_list_dns_domain_records index 130b747f9..c322fcc2f 100755 --- a/bin/v_list_dns_domain_records +++ b/bin/v_list_dns_domain_records @@ -14,26 +14,16 @@ user=$1 domain=$2 format=${3-shell} -# Importing variables +# Includes source $VESTA/func/shared.sh # Json func json_list_dns() { - # Print top bracket echo '{' - - # Count fields fileds_count=$(echo $fields| wc -w ) - - # Reading file line by line while read line; do - # New delimeter IFS=$'\n' - - # Assing key=value pair eval $line - - # Closing bracket if there already was output if [ -n "$data" ]; then echo -e ' },' fi @@ -42,13 +32,10 @@ json_list_dns() { for field in $fields; do eval value=\"$field\" value=$(echo "$value" | sed -e 's/"/\\"/g' -e "s/%quote%/'/g") - if [ $i -eq 1 ]; then - # Printing parrent (( ++i)) echo -e "\t\"$value\": {" else - # Printing child if [ $i -lt $fileds_count ]; then (( ++i)) echo -e "\t\t\"${field//$/}\": \"${value//,/, }\"," @@ -59,13 +46,9 @@ json_list_dns() { fi done done < $conf - - # Closing bracket if there was output if [ -n "$data" ]; then echo -e ' }' fi - - # Printing bottom bracket echo -e '}' } @@ -73,22 +56,15 @@ json_list_dns() { shell_list_dns() { if [ -z "$nohead" ] ; then - # Print brief info echo "${fields//$/}" for a in $fields; do echo -e "------ \c" done echo fi - - # Reading file line by line while read line ; do - # New delimeter IFS=$'\n' - # Assing key=value pair eval $line - - # Print result eval echo "$fields" | sed -e "s/%quote%/'/g" done < $conf } @@ -98,28 +74,19 @@ shell_list_dns() { # Verifications # #----------------------------------------------------------# -# Checking args check_args '2' "$#" 'user domain [format]' - -# Checking argument format validate_format 'user' 'domain' - -# Checking user is_object_valid 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' +is_object_valid 'dns' 'DOMAIN' "$domain" #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Defining config -conf=$USER_DATA/dns/$domain - -# Defining fileds to select -fields='$ID $RECORD $TYPE $VALUE $SUSPENDED $DATE' +# Defining config and fields +conf=$USER_DATA/dns/$domain.conf +fields='$ID $RECORD $TYPE $PRIORITY $VALUE $SUSPENDED $TIME $DATE' # Listing domains case $format in diff --git a/bin/v_list_dns_domains b/bin/v_list_dns_domains index 8248a8a18..b28b2cf10 100755 --- a/bin/v_list_dns_domains +++ b/bin/v_list_dns_domains @@ -13,7 +13,7 @@ user=$1 format=${2-shell} -# Importing variables +# Includes source $VESTA/func/shared.sh @@ -21,13 +21,8 @@ source $VESTA/func/shared.sh # Verifications # #----------------------------------------------------------# -# Checking args check_args '1' "$#" 'user [format]' - -# Checking argument format validate_format 'user' - -# Checking user is_object_valid 'user' 'USER' "$user" @@ -35,11 +30,9 @@ is_object_valid 'user' 'USER' "$user" # Action # #----------------------------------------------------------# -# Defining config +# Defining config and fields conf=$USER_DATA/dns.conf - -# Defining fileds to select -fields='$DOMAIN $IP $TPL $TTL $EXP $SOA $RECORDS $SUSPENDED $DATE' +fields='$DOMAIN $IP $TPL $TTL $EXP $SOA $RECORDS $SUSPENDED $TIME $DATE' # Listing domains case $format in diff --git a/bin/v_list_dns_template b/bin/v_list_dns_template index 4aab92b6f..c1c33cd5d 100755 --- a/bin/v_list_dns_template +++ b/bin/v_list_dns_template @@ -13,41 +13,17 @@ template=$1 format=${2-shell} -# Importing variables +# Includes source $VESTA/func/shared.sh source $VESTA/func/domain.sh - -#----------------------------------------------------------# -# Verifications # -#----------------------------------------------------------# - -# Checking args -check_args '1' "$#" 'template [format]' - -# Checking argument format -validate_format 'template' - -# Checking template -is_dns_template_valid - # Json func json_list_dns() { - # Print top bracket echo '{' - - # Count fields fileds_count=$(echo $fields| wc -w ) - - # Reading file line by line while read line; do - # New delimeter IFS=$'\n' - - # Assing key=value pair eval $line - - # Closing bracket if there already was output if [ -n "$data" ]; then echo -e ' },' fi @@ -56,13 +32,10 @@ json_list_dns() { for field in $fields; do eval value=\"$field\" value=$(echo "$value" | sed -e 's/"/\\"/g' -e "s/%quote%/'/g") - if [ $i -eq 1 ]; then - # Printing parrent (( ++i)) echo -e "\t\"$value\": {" else - # Printing child if [ $i -lt $fileds_count ]; then (( ++i)) echo -e "\t\t\"${field//$/}\": \"${value//,/, }\"," @@ -73,21 +46,15 @@ json_list_dns() { fi done done < $conf - - # Closing bracket if there was output if [ -n "$data" ]; then echo -e ' }' fi - - # Printing bottom bracket echo -e '}' } # Shell function shell_list_dns() { - if [ -z "$nohead" ] ; then - # Print brief info echo "${fields//$/}" for a in $fields; do echo -e "------ \c" @@ -95,28 +62,31 @@ shell_list_dns() { echo fi - # Reading file line by line while read line ; do - # Assing key=value pair eval $line - - # Print result eval echo "$fields" | sed -e "s/%quote%/'/g" done < $conf } +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '1' "$#" 'template [format]' +validate_format 'template' +is_dns_template_valid + + #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Defining config +# Defining config and fields conf=$DNSTPL/$template.tpl +fields='$RECORD $TYPE $PRIORITY $VALUE' -# Defining fileds to select -fields='$RECORD $TYPE $VALUE' - -# Listing domains +# Listing templates case $format in json) json_list_dns ;; plain) nohead=1; shell_list_dns ;; diff --git a/bin/v_list_dns_templates b/bin/v_list_dns_templates index c3767033b..f231d7b76 100755 --- a/bin/v_list_dns_templates +++ b/bin/v_list_dns_templates @@ -12,35 +12,25 @@ # Argument defenition format=${1-shell} -# Importing variables +# Includes source $VESTA/func/shared.sh # Json function json_list_dnstpl() { - # Print top bracket echo '{' - - # Count fields for template in $(ls $DNSTPL/| grep '.descr'); do - # Closing bracket if there already was output if [ -n "$data" ]; then echo -e ' },' fi - tpl_descr=$(cat $DNSTPL/$template |grep '#'|tr -d '\n') tpl_name="${template//.descr/}" echo -e "\t\"$tpl_name\": {" echo -e "\t\t\"DESCR\": \"${tpl_descr//# /}\"" - data=1 done - - # Closing bracket if there was output if [ -n "$data" ]; then echo -e ' }' fi - - # Printing bottom bracket echo -e '}' } @@ -49,8 +39,6 @@ shell_list_dnstpl() { for template in $(ls $DNSTPL/| grep '.descr'); do tpl_name="${template//.descr/}" tpl_descr=$(cat $DNSTPL/$template |grep '#') - - # Print result if [ -z "$nohead" ] ; then echo "----------" fi diff --git a/bin/v_list_user b/bin/v_list_user index a22a32351..910ea6fce 100755 --- a/bin/v_list_user +++ b/bin/v_list_user @@ -9,29 +9,22 @@ # Variable&Function # #----------------------------------------------------------# +# Includes +source $VESTA/func/shared.sh + # Argument defenition user=$1 USER="$user" format=${2-shell} -# Importing variables -source $VESTA/func/shared.sh - # Json function json_list_user() { i=1 fileds_count=$(echo "$fields" | wc -w) - source $V_USERS/$USER/user.conf - - # Print top bracket + source $VESTA/data/users/$user/user.conf echo '{' - - # Starting output loop for field in $fields; do - # Parsing key=value eval value=$field - - # Checking first field if [ "$i" -eq 1 ]; then echo -e "\t\"$value\": {" else @@ -41,22 +34,17 @@ json_list_user() { echo -e "\t\t\"${field//$/}\": \"${value//,/, }\"," fi fi - # Updating iterator (( ++i)) done - - # If there was any output if [ -n "$value" ]; then echo -e ' }' fi - # Printing bottom json bracket echo -e "}" } # Shell function shell_list_user() { - source $V_USERS/$USER/user.conf - + source $VESTA/data/users/$user/user.conf for field in $fields; do eval key="$field" echo "${field//$/}: $key " @@ -68,13 +56,8 @@ shell_list_user() { # Verifications # #----------------------------------------------------------# -# Checking args check_args '1' "$#" 'user [format]' - -# Checking argument format validate_format 'user' - -# Checking user is_object_valid 'user' 'USER' "$user" @@ -101,7 +84,6 @@ case $format in json) json_list_user ;; plain) nohead=1; shell_list_user ;; shell) shell_list_user | column -t ;; - *) check_args '1' '0' 'user [format]' ;; esac diff --git a/bin/v_rebuild_dns_domains b/bin/v_rebuild_dns_domains index d1097517f..e495f8518 100755 --- a/bin/v_rebuild_dns_domains +++ b/bin/v_rebuild_dns_domains @@ -12,31 +12,21 @@ # Argument defenition user=$1 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/domain.sh -source $VESTA/func/ip.sh #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '1' "$#" 'user' - -# Checking argument format validate_format 'user' - -# Checking dns system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# @@ -53,17 +43,9 @@ if [ ! -d "$USER_DATA/dns" ]; then mkdir $USER_DATA/dns fi -# Defining config +# Defining config and fie conf="$USER_DATA/dns.conf" -# Defining search string -search_string="DOMAIN" - -# Defining fileds to select -field='$DOMAIN' - -# Parsing unsuspeneded domains -domains=$(dom_clear_search) # Defining user name servers ns=$(get_user_value '$NS') @@ -74,14 +56,13 @@ for nameserver in ${ns//,/ };do done # Starting loop -for domain in $domains; do - +for domain in $(search_objects 'dns' 'DOMAIN' "*" 'DOMAIN'); do # Defining variables get_domain_values 'dns' domain_idn=$(idn -t --quiet -a "$domain") # Checking zone file - if [ ! -e "$USER_DATA/dns/$domain" ]; then + if [ ! -e "$USER_DATA/dns/$domain.conf" ]; then cat $DNSTPL/$TPL.tpl |\ sed -e "s/%ip%/$IP/g" \ -e "s/%domain_idn%/$domain_idn/g" \ @@ -94,22 +75,22 @@ for domain in $domains; do -e "s/%ns6%/$ns6/g" \ -e "s/%ns7%/$ns7/g" \ -e "s/%ns8%/$ns8/g" \ - -e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain + -e "s/%time%/$TIME/g" \ + -e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf fi # Sorting records sort_dns_records # Updating zone - conf="$HOMEDIR/$user/conf/dns/$domain.db" update_domain_zone - chmod 640 $conf - chown root:named $conf + # Set file permissions + chmod 640 $HOMEDIR/$user/conf/dns/$domain.db + chown root:named $HOMEDIR/$user/conf/dns/$domain.db # Bind config check nconf='/etc/named.conf' - if [ "$SUSPENDED" = 'yes' ]; then rm_string=$(grep -n /etc/namedb/$domain.db $nconf | cut -d : -f 1) if [ ! -z "$rm_string" ]; then @@ -124,9 +105,9 @@ for domain in $domains; do fi fi user_domains=$((user_domains + 1)) - records=$(wc -l $USER_DATA/dns/$domain | cut -f 1 -d ' ') + records=$(wc -l $USER_DATA/dns/$domain.conf | cut -f 1 -d ' ') user_records=$((user_records + records)) - update_domain_value 'dns' '$RECORDS' "$records" + update_object_value 'dns' 'DOMAIN' "$domain" '$RECORDS' "$records" done @@ -139,7 +120,7 @@ update_user_value "$user" '$U_DNS_DOMAINS' "$user_domains" update_user_value "$user" '$U_DNS_RECORDS' "$user_records" update_user_value "$user" '$SUSPENDED_DNS' "$suspended_dns" -# Adding task to the vesta pipe +# Restart named $BIN/v_restart_dns # Logging diff --git a/bin/v_rebuild_mail_domains b/bin/v_rebuild_mail_domains index 53882c82f..226c1d048 100755 --- a/bin/v_rebuild_mail_domains +++ b/bin/v_rebuild_mail_domains @@ -35,7 +35,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# diff --git a/bin/v_rebuild_web_domains b/bin/v_rebuild_web_domains index e8ca878d4..56979381d 100755 --- a/bin/v_rebuild_web_domains +++ b/bin/v_rebuild_web_domains @@ -37,7 +37,7 @@ is_system_enabled 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# diff --git a/bin/v_restart_dns b/bin/v_restart_dns index e79599b7a..ecd345d05 100755 --- a/bin/v_restart_dns +++ b/bin/v_restart_dns @@ -9,7 +9,7 @@ # Variable&Function # #----------------------------------------------------------# -# Importing variables +# Includes source /etc/profile.d/vesta.sh source $VESTA/conf/vesta.conf diff --git a/bin/v_suspend_cron_job b/bin/v_suspend_cron_job index 688f32179..e7f04faa4 100755 --- a/bin/v_suspend_cron_job +++ b/bin/v_suspend_cron_job @@ -24,10 +24,10 @@ source $VESTA/func/shared.sh #----------------------------------------------------------# check_args '2' "$#" 'user job [restart]' -validate_format 'user' 'job' 'rstart' +validate_format 'user' 'job' is_object_valid 'user' 'USER' "$user" is_object_valid 'cron' 'JOB' "$job" -is_object_suspended 'cron' 'JOB' "$job" +is_object_unsuspended 'cron' 'JOB' "$job" #----------------------------------------------------------# diff --git a/bin/v_suspend_dns_domain b/bin/v_suspend_dns_domain index 6f1d2442e..50b66735a 100755 --- a/bin/v_suspend_dns_domain +++ b/bin/v_suspend_dns_domain @@ -1,6 +1,6 @@ #!/bin/bash # info: suspend dns domain -# options: user domain +# options: user domain [restart] # # The function suspends a certain user's domain. @@ -13,47 +13,31 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") +restart="$3" # Importing variables source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh -source $VESTA/func/domain.sh #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# -# Checking arg number -check_args '2' "$#" 'user domain' - -# Checking argument format +check_args '2' "$#" 'user domain [restart]' validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' - -# Checking domain is not suspened -is_domain_suspended 'dns' +is_object_valid 'dns' 'DOMAIN' "$domain" +is_object_unsuspended 'dns' 'DOMAIN' "$domain" #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Defining config -conf="/etc/named.conf" - -rm_string=$(grep -n /etc/namedb/$domain.db $conf|cut -d : -f 1) -if [ ! -z "$rm_string" ]; then - sed -i "$rm_string d" $conf -fi +# Deleting domain from named.conf +sed -i "/\/$domain.db\"/d" /etc/named.conf #----------------------------------------------------------# @@ -61,11 +45,13 @@ fi #----------------------------------------------------------# # Adding suspend in config -update_domain_value 'dns' '$SUSPENDED' 'yes' +update_object_value 'dns' 'DOMAIN' "$domain" '$SUSPENDED' 'yes' increase_user_value "$user" '$SUSPENDED_DNS' -# Adding task to the vesta pipe -$BIN/v_restart_dns +# Restart named +if [ "$restart" != 'no' ]; then + $BIN/v_restart_dns +fi # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_suspend_dns_domains b/bin/v_suspend_dns_domains index 8361ef751..8c177ca18 100755 --- a/bin/v_suspend_dns_domains +++ b/bin/v_suspend_dns_domains @@ -12,26 +12,18 @@ # Argument defenition user=$1 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh -source $VESTA/func/domain.sh #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '1' "$#" 'user' - -# Checking argument format validate_format 'user' - -# Checking dns system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" @@ -39,17 +31,9 @@ is_object_valid 'user' 'USER' "$user" # Action # #----------------------------------------------------------# -# Defining config -conf="$USER_DATA/dns.conf" - -# Defining fileds to select -field='$DOMAIN' -search_string="SUSPENDED='no'" -domains=$(dom_clear_search) - # Starting suspend loop -for domain in $domains; do - $BIN/v_suspend_dns_domain "$user" "$domain" +for domain in $(search_objects 'dns' 'SUSPENDED' "no" 'DOMAIN'); do + $BIN/v_suspend_dns_domain "$user" "$domain" 'no' done diff --git a/bin/v_suspend_mail_domain b/bin/v_suspend_mail_domain index 4dffe7a41..1fbd2af29 100755 --- a/bin/v_suspend_mail_domain +++ b/bin/v_suspend_mail_domain @@ -38,7 +38,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_valid 'mail' diff --git a/bin/v_suspend_user b/bin/v_suspend_user index 95870ea0a..ec3921a03 100755 --- a/bin/v_suspend_user +++ b/bin/v_suspend_user @@ -31,7 +31,7 @@ validate_format 'user' is_object_valid 'user' 'USER' "$user" # Checking user status -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking user admin if [ "$user" = 'admin' ]; then diff --git a/bin/v_unsuspend_cron_job b/bin/v_unsuspend_cron_job index d5a2db37b..796170365 100755 --- a/bin/v_unsuspend_cron_job +++ b/bin/v_unsuspend_cron_job @@ -27,7 +27,7 @@ check_args '2' "$#" 'user job [restart]' validate_format 'user' 'job' 'restart' is_object_valid 'user' 'USER' "$user" is_object_valid 'cron' 'JOB' "$job" -is_object_unsuspended 'cron' 'JOB' "$job" +is_object_suspended 'cron' 'JOB' "$job" #----------------------------------------------------------# diff --git a/bin/v_unsuspend_dns_domain b/bin/v_unsuspend_dns_domain index fe791ccfa..66705014b 100755 --- a/bin/v_unsuspend_dns_domain +++ b/bin/v_unsuspend_dns_domain @@ -13,57 +13,45 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") +restart="$3" -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh -source $VESTA/func/domain.sh #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'user domain' - -# Checking argument format validate_format 'user' 'domain' - -# Checking web system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" - -# Checking domain exist -is_domain_valid 'dns' - -# Check domain is suspened -is_domain_unsuspended 'dns' +is_object_valid 'dns' 'DOMAIN' "$domain" +is_object_suspended 'dns' 'DOMAIN' "$domain" #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Defining config -conf="/etc/named.conf" - # Adding zone in named.conf -nmd_rec="zone \"$domain\" { type master; file \"/etc/namedb/$domain.db\"; };" -echo "$nmd_rec" >> $conf +echo "zone \"$domain\" { type master; file \"/etc/namedb/$domain.db\"; };" \ + >> /etc/named.conf #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# # Unsuspending domain in config -update_domain_value 'dns' '$SUSPENDED' 'no' +update_object_value 'dns' 'DOMAIN' "$domain" '$SUSPENDED' 'no' decrease_user_value "$user" '$SUSPENDED_DNS' -# Adding task to the vesta pipe -$BIN/v_restart_dns +# Restart named +if [ "$restart" != 'no' ]; then + $BIN/v_restart_dns +fi # Logging log_event "$OK" "$EVENT" diff --git a/bin/v_unsuspend_dns_domains b/bin/v_unsuspend_dns_domains index 3b45fef10..90320f5e3 100755 --- a/bin/v_unsuspend_dns_domains +++ b/bin/v_unsuspend_dns_domains @@ -12,26 +12,18 @@ # Argument defenition user=$1 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh -source $VESTA/func/domain.sh #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '1' "$#" 'user' - -# Checking argument format validate_format 'user' - -# Checking dns system is enabled -is_system_enabled 'DNS_SYSTEM' - -# Checking user +is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" @@ -39,22 +31,9 @@ is_object_valid 'user' 'USER' "$user" # Action # #----------------------------------------------------------# -# Defining config -conf="$USER_DATA/dns.conf" - -# Defining fileds to select -field='$DOMAIN' - -# Defining search string -search_string="SUSPENDED='yes'" - -# Parsing suspeneded domains -domains=$(dom_clear_search) - - # Starting unsuspend loop -for domain in $domains; do - $BIN/v_unsuspend_dns_domain "$user" "$domain" +for domain in $(search_objects 'dns' 'SUSPENDED' "yes" 'DOMAIN'); do + $BIN/v_unsuspend_dns_domain "$user" "$domain" 'no' done @@ -62,7 +41,7 @@ done # Vesta # #----------------------------------------------------------# -# Adding task to the vesta pipe +# Restart named $BIN/v_restart_dns # Logging diff --git a/bin/v_unsuspend_mail_domain b/bin/v_unsuspend_mail_domain index d6ee683da..3e99cbaf5 100755 --- a/bin/v_unsuspend_mail_domain +++ b/bin/v_unsuspend_mail_domain @@ -38,7 +38,7 @@ is_system_enabled 'MAIL_SYSTEM' is_object_valid 'user' 'USER' "$user" # Checking user is active -is_object_suspended 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" # Checking domain is_domain_valid 'mail' diff --git a/data/templates/dns/default.tpl b/data/templates/dns/default.tpl index 00d9517d5..e25c4c885 100644 --- a/data/templates/dns/default.tpl +++ b/data/templates/dns/default.tpl @@ -1,9 +1,9 @@ -ID='1' RECORD='@' TYPE='NS' VALUE='%ns1%.' SUSPEND='no' DATE='%date%' -ID='2' RECORD='@' TYPE='NS' VALUE='%ns2%.' SUSPEND='no' DATE='%date%' -ID='3' RECORD='@' TYPE='A' VALUE='%ip%' SUSPEND='no' DATE='%date%' -ID='4' RECORD='mail' TYPE='A' VALUE='%ip%' SUSPEND='no' DATE='%date%' -ID='5' RECORD='www' TYPE='A' VALUE='%ip%' SUSPEND='no' DATE='%date%' -ID='6' RECORD='pop' TYPE='A' VALUE='%ip%' SUSPEND='no' DATE='%date%' -ID='7' RECORD='ftp' TYPE='A' VALUE='%ip%' SUSPEND='no' DATE='%date%' -ID='8' RECORD='@' TYPE='MX' VALUE='10 mail' SUSPEND='no' DATE='%date%' -ID='9' RECORD='@' TYPE='TXT' VALUE='"v=spf1 a mx ip4:%ip% ?all"' SUSPEND='no' DATE='%date%' +ID='1' RECORD='@' TYPE='NS' PRIORITY='' VALUE='%ns1%.' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='2' RECORD='@' TYPE='NS' PRIORITY='' VALUE='%ns2%.' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='3' RECORD='@' TYPE='A' PRIORITY='' VALUE='%ip%' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='4' RECORD='mail' TYPE='A' PRIORITY='' VALUE='%ip%' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='5' RECORD='www' TYPE='A' PRIORITY='' VALUE='%ip%' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='6' RECORD='pop' TYPE='A' PRIORITY='' VALUE='%ip%' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='7' RECORD='ftp' TYPE='A' PRIORITY='' VALUE='%ip%' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='8' RECORD='@' TYPE='MX' PRIORITY='10' VALUE='mail' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='9' RECORD='@' TYPE='TXT' PRIORITY='' VALUE='"v=spf1 a mx ip4:%ip% ?all"' SUSPEND='no' TIME='%time%' DATE='%date%' diff --git a/data/templates/dns/gmail.tpl b/data/templates/dns/gmail.tpl index e0e353493..052bf6d67 100644 --- a/data/templates/dns/gmail.tpl +++ b/data/templates/dns/gmail.tpl @@ -1,14 +1,14 @@ -ID='1' RECORD='@' TYPE='NS' VALUE='%ns1%.' SUSPEND='no' DATE='%date%' -ID='2' RECORD='@' TYPE='NS' VALUE='%ns2%.' SUSPEND='no' DATE='%date%' -ID='3' RECORD='@' TYPE='A' VALUE='%ip%' SUSPEND='no' DATE='%date%' -ID='4' RECORD='ftp' TYPE='A' VALUE='%ip%' SUSPEND='no' DATE='%date%' -ID='5' RECORD='localhost' TYPE='A' VALUE='127.0.0.1' SUSPEND='no' DATE='%date%' -ID='6' RECORD='mail' TYPE='CNAME' VALUE='ghs.google.com.' SUSPEND='no' DATE='%date%' -ID='7' RECORD='pop' TYPE='A' VALUE='%ip%' SUSPEND='no' DATE='%date%' -ID='8' RECORD='www' TYPE='A' VALUE='%ip%' SUSPEND='no' DATE='%date%' -ID='9' RECORD='@' TYPE='MX' VALUE='1 ASPMX.L.GOOGLE.COM.' SUSPEND='no' DATE='%date%' -ID='10' RECORD='@' TYPE='MX' VALUE='5 ALT1.ASPMX.L.GOOGLE.COM.' SUSPEND='no' DATE='%date%' -ID='11' RECORD='@' TYPE='MX' VALUE='5 ALT2.ASPMX.L.GOOGLE.COM.' SUSPEND='no' DATE='%date%' -ID='12' RECORD='@' TYPE='MX' VALUE='10 ASPMX2.GOOGLEMAIL.COM.' SUSPEND='no' DATE='%date%' -ID='13' RECORD='@' TYPE='MX' VALUE='10 ASPMX3.GOOGLEMAIL.COM.' SUSPEND='no' DATE='%date%' -ID='14' RECORD='@' TYPE='TXT' VALUE='"v=spf1 a mx ip4:%ip% ?all"' SUSPEND='no' DATE='%date%' +ID='1' RECORD='@' TYPE='NS' PRIORITY='' VALUE='%ns1%.' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='2' RECORD='@' TYPE='NS' PRIORITY='' VALUE='%ns2%.' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='3' RECORD='@' TYPE='A' PRIORITY='' VALUE='%ip%' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='4' RECORD='ftp' TYPE='A' PRIORITY='' VALUE='%ip%' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='5' RECORD='localhost' TYPE='A' PRIORITY='' VALUE='127.0.0.1' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='6' RECORD='mail' TYPE='CNAME' PRIORITY='' VALUE='ghs.google.com.' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='7' RECORD='pop' TYPE='A' PRIORITY='' VALUE='%ip%' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='8' RECORD='www' TYPE='A' PRIORITY='' VALUE='%ip%' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='9' RECORD='@' TYPE='MX' PRIORITY='1' VALUE='ASPMX.L.GOOGLE.COM.' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='10' RECORD='@' TYPE='MX' PRIORITY='5' VALUE='ALT1.ASPMX.L.GOOGLE.COM.' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='11' RECORD='@' TYPE='MX' PRIORITY='5' VALUE='ALT2.ASPMX.L.GOOGLE.COM.' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='12' RECORD='@' TYPE='MX' PRIORITY='10' VALUE='ASPMX2.GOOGLEMAIL.COM.' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='13' RECORD='@' TYPE='MX' PRIORITY='10' VALUE='ASPMX3.GOOGLEMAIL.COM.' SUSPEND='no' TIME='%time%' DATE='%date%' +ID='14' RECORD='@' TYPE='TXT' PRIORITY='' VALUE='"v=spf1 a mx ip4:%ip% ?all"' SUSPEND='no' TIME='%time%' DATE='%date%' diff --git a/func/domain.sh b/func/domain.sh index 1a7aa33a3..007172477 100644 --- a/func/domain.sh +++ b/func/domain.sh @@ -1,3 +1,39 @@ +# Web template check +is_apache_template_valid() { + c=$(echo "$templates" | grep -w "$template") + t="$WEBTPL/apache_$template.tpl" + d="$WEBTPL/apache_$template.descr" + s="$WEBTPL/apache_$template.stpl" + if [ -z "$c" ] || [ ! -e $t ] || [ ! -e $d ] || [ ! -e $s ]; then + echo "Error: $template not found" + log_event "$E_NOTEXIST" "$EVENT" + exit $E_NOTEXIST + fi +} + +# Nginx template check +is_nginx_template_valid() { + t="$WEBTPL/ngingx_vhost_$template.tpl" + d="$WEBTPL/ngingx_vhost_$template.descr" + s="$WEBTPL/ngingx_vhost_$template.stpl" + if [ ! -e $t ] || [ ! -e $d ] || [ ! -e $s ]; then + echo "Error: $template not found" + log_event "$E_NOTEXIST" "$EVENT" + exit $E_NOTEXIST + fi +} + +# DNS template check +is_dns_template_valid() { + tpl="$DNSTPL/$template.tpl" + descr="$DNSTPL/$template.descr" + if [ ! -e $tpl ] || [ ! -e $descr ]; then + echo "Error: template not found" + log_event "$E_NOTEXIST" "$EVENT" + exit $E_NOTEXIST + fi +} + # Checking domain existance is_domain_new() { config_type="$1" @@ -20,38 +56,12 @@ is_domain_new() { fi } -is_domain_suspended() { - config_type="$1" - # Parsing domain values - check_domain=$(grep "DOMAIN='$domain'" $USER_DATA/$config_type.conf|\ - grep "SUSPENDED='yes'") - - # Checking result - if [ ! -z "$check_domain" ]; then - echo "Error: domain $domain is suspended" - log_event 'debug' "$E_SUSPENDED $EVENT" - exit $E_SUSPENDED - fi -} - -is_domain_unsuspended() { - config_type="$1" - # Parsing domain values - check_domain=$(grep "DOMAIN='$domain'" $USER_DATA/$config_type.conf|\ - grep "SUSPENDED='no'") - - # Checking result - if [ ! -z "$check_domain" ]; then - echo "Error: domain unsuspended" - log_event 'debug' "$E_UNSUSPENDED $EVENT" - exit $E_UNSUSPENDED - fi -} - +# Update domain zone update_domain_zone() { # Definigng variables + conf="$HOMEDIR/$user/conf/dns/$domain.db" line=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf) - fields='$RECORD\t$TTL\tIN\t$TYPE\t$VALUE' + fields='$RECORD\t$TTL\tIN\t$TYPE\t$PRIORITY\t$VALUE' # Checking serial if [ -e $conf ]; then @@ -99,34 +109,21 @@ update_domain_zone() { # Converting utf records to ascii RECORD=$(idn --quiet -a -t "$RECORD") - #VALUE=$(idn --quiet -a -t "$VALUE") eval echo -e "\"$fields\""|sed -e "s/%quote%/'/g" >> $conf - done < $USER_DATA/dns/$domain + done < $USER_DATA/dns/$domain.conf } -get_next_dns_record() { - # Parsing config - curr_str=$(grep "ID=" $USER_DATA/dns/$domain|cut -f 2 -d \'|\ - sort -n|tail -n1) - - # Print result - echo "$((curr_str +1))" -} - -is_dns_record_free() { - # Checking record id - check_id=$(grep "ID='$id'" $USER_DATA/dns/$domain) - - if [ ! -z "$check_id" ]; then - echo "Error: ID exist" - log_event 'debug' "$E_EXISTS $EVENT" - exit $E_EXISTS +get_next_dnsrecord(){ + if [ -z "$id" ]; then + curr_str=$(grep "ID=" $USER_DATA/dns/$domain.conf | cut -f 2 -d \' |\ + sort -n|tail -n1) + id="$((curr_str +1))" fi } sort_dns_records() { # Defining conf - conf="$USER_DATA/dns/$domain" + conf="$USER_DATA/dns/$domain.conf" cat $conf |sort -n -k 2 -t \' >$conf.tmp mv -f $conf.tmp $conf } @@ -231,86 +228,13 @@ replace_web_config() { sed -i "$top_line,$bottom_line s/$clean_old/$clean_new/" $conf } -get_domain_value() { - conf_type="$1" - key="$2" - default_str="DOMAIN='$domain'" - search_str="${3-DOMAIN=$search_str}" - - # Parsing config - string=$(grep "$search_str" $USER_DATA/$conf_type.conf ) - - # Parsing key=value - eval $string - - # Self reference - eval value="$key" - - # Print value - echo "$value" -} - +# Get domain values get_domain_values() { - # Defining domain parameters for line in $(grep "DOMAIN='$domain'" $USER_DATA/$1.conf); do - # Assing key=value eval $line done } -update_domain_value() { - conf_type="$1" - key="$2" - value="$3" - default_str="DOMAIN='$domain'" - search_str=${4-$default_str} - - # Defining conf - conf="$USER_DATA/$conf_type.conf" - - # Parsing conf - domain_str=$(grep -n "$search_str" $conf) - str_number=$(echo $domain_str | cut -f 1 -d ':') - str=$(echo $domain_str | cut -f 2 -d ':') - - # Reading key=values - eval $str - - # Defining clean key - c_key=$(echo "${key//$/}") - - eval old="${key}" - - # Escaping slashes - old=$(echo "$old" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g') - new=$(echo "$value" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g') - - # Updating conf - sed -i "$str_number s/$c_key='${old//\*/\\*}'/$c_key='${new//\*/\\*}'/g"\ - $conf -} - -is_domain_key_empty() { - conf_type="$1" - key="$2" - - # Parsing domains - string=$( grep "DOMAIN='$domain'" $USER_DATA/$conf_type.conf ) - - # Parsing key=value - eval $string - - # Self reference - eval value="$key" - - # Checkng key - if [ ! -z "$value" ] && [ "$value" != 'no' ]; then - echo "Error: ${key//$} is not empty = $value" - log_event 'debug' "$E_EXISTS $EVENT" - exit $E_EXISTS - fi -} - is_web_domain_cert_valid() { # Checking file existance diff --git a/func/shared.sh b/func/shared.sh index fa9abc55b..06dcf3948 100644 --- a/func/shared.sh +++ b/func/shared.sh @@ -51,7 +51,7 @@ log_history() { # Argument list checker check_args() { if [ "$1" -gt "$2" ]; then - echo "Error: bad args" + echo "Error: not enought arguments" echo "Usage: $SCRIPT $3" log_event "$E_ARGS" "$EVENT" exit $E_ARGS @@ -75,14 +75,13 @@ is_package_full() { awk -F "ALIAS='" '{print $2}' | cut -f 1 -d \' | tr ',' '\n' |\ wc -l );; DNS_DOMAINS) used=$(wc -l $USER_DATA/dns.conf |cut -f1 -d \ );; - DNS_RECORDS) used=$(wc -l $USER_DATA/dns/$domain |cut -f1 -d \ );; + DNS_RECORDS) used=$(wc -l $USER_DATA/dns/$domain.conf |cut -f1 -d \ );; MAIL_DOMAINS) used=$(wc -l $USER_DATA/mail.conf |cut -f1 -d \ );; - MAIL_ACCOUNTS) used=$(wc -l $USER_DATA/mail/$domain |\ + MAIL_ACCOUNTS) used=$(wc -l $USER_DATA/mail/$domain.conf |\ cut -f1 -d \ );; DATABASES) used=$(wc -l $USER_DATA/db.conf |cut -f1 -d \ );; CRON_JOBS) used=$(wc -l $USER_DATA/cron.conf |cut -f1 -d \ );; esac - limit=$(grep "^$1=" $USER_DATA/user.conf | cut -f 2 -d \' ) if [ "$used" -ge "$limit" ]; then echo "Error: Upgrade package" @@ -102,42 +101,6 @@ gen_password() { echo "$pass" } -# Web template check -is_apache_template_valid() { - c=$(echo "$templates" | grep -w "$template") - t="$WEBTPL/apache_$template.tpl" - d="$WEBTPL/apache_$template.descr" - s="$WEBTPL/apache_$template.stpl" - if [ -z "$c" ] || [ ! -e $t ] || [ ! -e $d ] || [ ! -e $s ]; then - echo "Error: $template not found" - log_event "$E_NOTEXIST" "$EVENT" - exit $E_NOTEXIST - fi -} - -# Nginx template check -is_nginx_template_valid() { - t="$WEBTPL/ngingx_vhost_$template.tpl" - d="$WEBTPL/ngingx_vhost_$template.descr" - s="$WEBTPL/ngingx_vhost_$template.stpl" - if [ ! -e $t ] || [ ! -e $d ] || [ ! -e $s ]; then - echo "Error: $template not found" - log_event "$E_NOTEXIST" "$EVENT" - exit $E_NOTEXIST - fi -} - -# DNS template check -is_dns_template_valid() { - tpl="$DNSTPL/$template.tpl" - descr="$DNSTPL/$template.descr" - if [ ! -e $tpl ] || [ ! -e $descr ]; then - echo "Error: template not found" - log_event "$E_NOTEXIST" "$EVENT" - exit $E_NOTEXIST - fi -} - # Package existance check is_package_valid() { if [ ! -e "$VESTA/data/packages/$package.pkg" ]; then @@ -176,7 +139,7 @@ is_object_free() { object=$(grep "$2='$3'" $USER_DATA/$1.conf) fi if [ ! -z "$object" ]; then - echo "Error: $3 exists" + echo "Error: $2 with value $3 exists" log_event "$E_EXISTS" "$EVENT" exit $E_EXISTS fi @@ -209,7 +172,7 @@ is_object_suspended() { else spnd=$(grep "$2='$3'" $USER_DATA/$1.conf|grep "SUSPENDED='yes'") fi - if [ ! -z "$spnd" ]; then + if [ -z "$spnd" ]; then echo "Error: $3 is suspended" log_event "$E_SUSPENDED" "$EVENT" exit $E_SUSPENDED @@ -223,13 +186,21 @@ is_object_unsuspended() { else spnd=$(grep "$2='$3'" $USER_DATA/$1.conf|grep "SUSPENDED='yes'") fi - if [ -z "$spnd" ]; then + if [ ! -z "$spnd" ]; then echo "Error: $3 is not suspended" log_event "$E_UNSUSPENDED" "$EVENT" exit $E_UNSUSPENDED fi } +# Get object value +get_object_value() { + object=$(grep "$2='$3'" $USER_DATA/$1.conf) + eval "$object" + eval object_val="$4" + echo "$object_val" +} + # Update object value update_object_value() { row=$(grep -n "$2='$3'" $USER_DATA/$1.conf) @@ -256,7 +227,7 @@ search_objects() { # Get user value get_user_value() { - grep "^$1=" $USER_DATA/user.conf| cut -f 2 -d \' + grep "^${1//$/}=" $USER_DATA/user.conf| cut -f 2 -d \' } # Update user value in user.conf @@ -514,7 +485,7 @@ validate_format_email() { # Username validate_format_username() { if ! [[ "$1" =~ ^[0-Z]+(\.[0-Z]+)?$ ]] || [[ "${#1}" -gt 28 ]]; then - echo "Error: usernmae $1 is not valid" + echo "Error: $2 $1 is not valid" log_event "$E_INVALID" "$EVENT" exit $E_INVALID fi @@ -593,10 +564,10 @@ validate_format_mhdmw() { } # Nginx static extention or DNS record -validate_format_extentions() { - exclude="[!|@|#|$|^|&|(|)|+|=|{|}|:|<|>|?|/|\|\"|'|;|%| ]" +validate_format_common() { + exclude="[!|#|$|^|&|(|)|+|=|{|}|:|<|>|?|/|\|\"|'|;|%| ]" if [[ "$1" =~ $exclude ]] || [ 200 -le ${#1} ]; then - echo "Error: extention $1 is not valid" + echo "Error: $2 $1 is not valid" log_event "$E_INVALID" "$EVENT" exit $E_INVALID fi @@ -616,6 +587,11 @@ validate_format_dvalue() { if [ "$rtype" = 'NS' ]; then validate_format_domain "$1" fi + if [ "$rtype" = 'MX' ]; then + validate_format_domain "$1" + validate_format_int "$priority" + fi + } # Date @@ -630,13 +606,19 @@ validate_format_date() { # Format validation controller validate_format(){ for arg_name in $*; do - eval arg=\$$argument_name - case $var in - account) validate_format_username "$arg" ;; + eval arg=\$$arg_name + if [ -z "$arg" ]; then + echo "Error: argument $arg_name is not valid (empty)" + log_event "$E_INVALID" "$EVENT" + exit $E_INVALID + fi + + case $arg_name in + account) validate_format_username "$arg" "$arg_name" ;; antispam) validate_format_boolean "$arg" ;; antivirus) validate_format_boolean "$arg" ;; auth_pass) validate_format_password "$arg" ;; - auth_user) validate_format_username "$arg" ;; + auth_user) validate_format_username "$arg" "$arg_name" ;; backup) validate_format_date "$arg" ;; database) validate_format_database "$arg" ;; day) validate_format_mhdmw "$arg" $arg_name ;; @@ -648,11 +630,11 @@ validate_format(){ dom_alias) validate_format_domain "$arg" ;; dvalue) validate_format_dvalue "$arg";; email) validate_format_email "$arg" ;; - encoding) validate_format_username "$arg" ;; + encoding) validate_format_username "$arg" "$arg_name" ;; exp) validate_format_date "$arg" ;; - extentions) validate_format_extentions "$arg" ;; - fname) validate_format_username "$arg" ;; - host) validate_format_username "$arg" ;; + extentions) validate_format_common "$arg" 'extentions' ;; + fname) validate_format_username "$arg" "$arg_name" ;; + host) validate_format_username "$arg" "$arg_name" ;; hour) validate_format_mhdmw "$arg" $arg_name ;; id) validate_format_int "$arg" ;; interface) validate_format_interface "$arg" ;; @@ -660,9 +642,9 @@ validate_format(){ ip_name) validate_format_domain "$arg" ;; ip_status) validate_format_ip_status "$arg" ;; job) validate_format_int "$arg" ;; - key) validate_format_username "$arg" ;; - lname) validate_format_username "$arg" ;; - malias) validate_format_username "$arg" ;; + key) validate_format_username "$arg" "$arg_name" ;; + lname) validate_format_username "$arg" "$arg_name" ;; + malias) validate_format_username "$arg" "$arg_name" ;; mask) validate_format_ip "$arg" ;; max_db) validate_format_int "$arg" ;; min) validate_format_mhdmw "$arg" $arg_name ;; @@ -675,16 +657,16 @@ validate_format(){ ns6) validate_format_domain "$arg" ;; ns7) validate_format_domain "$arg" ;; ns8) validate_format_domain "$arg" ;; - package) validate_format_username "$arg" ;; + package) validate_format_username "$arg" "$arg_name" ;; password) validate_format_password "$arg" ;; port) validate_format_int "$arg" ;; quota) validate_format_int "$arg" ;; restart) validate_format_boolean "$arg" ;; - record) validate_format_extentions "$arg" ;; + record) validate_format_common "$arg" 'record';; rtype) validate_format_dns_type "$arg" ;; shell) validate_format_shell "$arg" ;; soa) validate_format_domain "$arg" ;; - template) validate_format_username "$arg" ;; + template) validate_format_username "$arg" "$arg_name" ;; ttl) validate_format_int "$arg" ;; url) validate_format_url "$arg" ;; user) validate_format_username "$arg" ;; diff --git a/test/test_json_listing.sh b/test/test_json_listing.sh index 03875672a..8002037ab 100755 --- a/test/test_json_listing.sh +++ b/test/test_json_listing.sh @@ -5,27 +5,27 @@ source /etc/profile.d/vesta.sh V_BIN="$VESTA/bin" V_TEST="$VESTA/test" -commands='v_list_cron_jobs vesta json -v_list_db_bases vesta json -v_list_db_base vesta vesta_read json +commands='v_list_cron_jobs admin json +v_list_db_bases admin json +v_list_db_base admin admin_read json v_list_db_host mysql localhost json v_list_db_hosts mysql json -v_list_dns_domains vesta json +v_list_dns_domains admin json v_list_dns_templates json v_list_sys_config json v_list_sys_interfaces json v_list_sys_ips json v_list_sys_rrd json -v_list_user vesta json +v_list_user admin json v_list_user_backups vesta json -v_list_user_ips vesta json -v_list_user_ns vesta json +v_list_user_ips admin json +v_list_user_ns admin json v_list_user_packages json v_list_users json -v_list_web_domains vesta json -v_list_web_domain vesta default.vesta.domain json -v_list_web_templates vesta json -v_list_web_templates_nginx vesta json' +v_list_web_domains admin json +v_list_web_domain admin default.vesta.domain json +v_list_web_templates admin json +v_list_web_templates_nginx admin json' IFS=$'\n' for cmd in $commands; do