From 530fc3b63d8cf9078b2e6b9c7c2fbe89d7dc80b5 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Wed, 25 Jul 2012 10:43:25 +0300 Subject: [PATCH] add dns zones when editing webaliases --- bin/v_add_dns_on_web_alias | 50 +++++++++++--------- bin/v_delete_dns_on_web_alias | 80 ++++++++++++++++++++++++++++++++ bin/v_update_mail_domains_disk | 1 - web/add/web/index.php | 30 ++++++++---- web/edit/web/index.php | 15 +++--- web/templates/admin/add_web.html | 10 ++-- 6 files changed, 142 insertions(+), 44 deletions(-) create mode 100755 bin/v_delete_dns_on_web_alias diff --git a/bin/v_add_dns_on_web_alias b/bin/v_add_dns_on_web_alias index ccefb2565..8fd171e2f 100755 --- a/bin/v_add_dns_on_web_alias +++ b/bin/v_add_dns_on_web_alias @@ -1,5 +1,5 @@ #!/bin/bash -# info: add dns domain or dns record based on web domain alias +# info: add dns domain or dns record based on web domain alias restart # options: user domain # # The function adds dns domain or dns record based on web domain alias. @@ -11,8 +11,13 @@ # Argument defenition user=$1 -domain=$(echo $domain | sed -e 's/\.*$//g' -e 's/^\.*//g') +domain=$(echo $2 | sed -e 's/\.*$//g' -e 's/^\.*//g') domain_idn=$(idn -t --quiet -a "$domain") +dom_alias=$(idn -t --quiet -u "$3" ) +dom_alias=$(echo $dom_alias | sed -e 's/\.*$//g' -e 's/^\.*//g') +dom_alias=$(echo $dom_alias | tr '[:upper:]' '[:lower:]') +dom_alias_idn=$(idn -t --quiet -a "$dom_alias" ) +restart="$4" # Includes source $VESTA/conf/vesta.conf @@ -24,7 +29,7 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -check_args '2' "$#" 'user domain' +check_args '3' "$#" 'user domain alias' validate_format 'user' 'domain' is_system_enabled "$WEB_SYSTEM" is_system_enabled "$DNS_SYSTEM" @@ -41,34 +46,35 @@ is_object_unsuspended 'web' 'DOMAIN' "$domain" # Parsing domain values get_domain_values 'web' -OLD_IFS=$IFS -IFS=',' -for web_alias in $ALIAS; do - # Check if parent dns domain exist - sub_domain=$(echo $web_alias | cut -f1 -d .) - pr_domain=$(echo $web_alias | sed -e "s/^$sub_domain.//" ) - check_parent=$(grep "DOMAIN='$pr_domain'" $USER_DATA/dns.conf) - if [ -z "$check_parent" ]; then - check_dom=$(grep "DOMAIN='$web_alias'" $USER_DATA/dns.conf) - if [ -z "$check_dom" ]; then - $BIN/v_add_dns_domain $user $web_alias $IP - fi +# Check if it a simple domain +if [ $(echo -e "${dom_alias//\./\n}" | wc -l) -le 2 ]; then + if [ ! -e "$USER_DATA/dns/$dom_alias.conf" ]; then + $BIN/v_add_dns_domain $user $dom_alias $IP '' '' '' '' '' $restart + fi +else + # Check subdomain + sub=$(echo "$dom_alias" | cut -f1 -d . -s) + dom=$(echo "$dom_alias" | sed -e "s/^$sub.//" ) + if [ ! -e "$USER_DATA/dns/$dom.conf" ]; then + $BIN/v_add_dns_domain $user $dom $IP '' '' '' '' '' $restart + $BIN/v_add_dns_domain_record $user $dom "$sub" A $IP '' '' $restart else - check_rec=$(grep "RECORD='$sub_domain'" $USER_DATA/dns/$pr_domain.conf) - if [ -z "$check_rec" ]; then - $BIN/v_add_dns_domain_record $user $pr_domain $sub_domain A $IP + if [ "$sub" == '*' ]; then + rec=$(grep -w "RECORD='\*'" $USER_DATA/dns/$dom.conf) + else + rec=$(grep -w "RECORD='$sub'" $USER_DATA/dns/$dom.conf) + fi + if [ -z "$rec" ]; then + $BIN/v_add_dns_domain_record $user $dom "$sub" A $IP '' '' $restart fi fi -done +fi #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# -# Restart web server -$BIN/v_restart_dns "$EVENT" - # Logging log_history "$EVENT" log_event "$OK" "$EVENT" diff --git a/bin/v_delete_dns_on_web_alias b/bin/v_delete_dns_on_web_alias new file mode 100755 index 000000000..ded43f5f6 --- /dev/null +++ b/bin/v_delete_dns_on_web_alias @@ -0,0 +1,80 @@ +#!/bin/bash +# info: delete dns domain or dns record based on web domain alias +# options: user domain +# +# The function deletes dns domain or dns record based on web domain alias. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=$1 +domain=$(echo $2 | sed -e 's/\.*$//g' -e 's/^\.*//g') +domain_idn=$(idn -t --quiet -a "$domain") +dom_alias=$(idn -t --quiet -u "$3" ) +dom_alias=$(echo $dom_alias | sed -e 's/\.*$//g' -e 's/^\.*//g') +dom_alias=$(echo $dom_alias | tr '[:upper:]' '[:lower:]') +dom_alias_idn=$(idn -t --quiet -a "$dom_alias" ) +restart="$4" + +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/main.sh +source $VESTA/func/domain.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '3' "$#" 'user domain alias' +validate_format 'user' 'domain' +is_system_enabled "$WEB_SYSTEM" +is_system_enabled "$DNS_SYSTEM" +is_object_valid 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Parsing domain values +get_domain_values 'web' + +# Check if it a simple domain +if [ $(echo -e "${dom_alias//\./\n}" | wc -l) -le 2 ]; then + if [ -e "$USER_DATA/dns/$dom_alias.conf" ]; then + $BIN/v_delete_dns_domain $user $dom_alias $IP $restart + fi +else + # Check subdomain + sub=$(echo "$dom_alias" | cut -f1 -d . -s) + root=$(echo "$dom_alias" | sed -e "s/^$sub.//" ) + if [ -e "$USER_DATA/dns/$root.conf" ]; then + if [ "$sub" == '*' ]; then + rec=$(grep -w "RECORD='\*'" $USER_DATA/dns/$root.conf) + else + rec=$(grep -w "RECORD='$sub'" $USER_DATA/dns/$root.conf) + fi + if [ ! -z "$rec" ]; then + eval "$rec" + $BIN/v_delete_dns_domain_record $user "$root" "$ID" + fi + fi +fi + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Logging +log_history "$EVENT" +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v_update_mail_domains_disk b/bin/v_update_mail_domains_disk index 8533f8031..d2c835c73 100755 --- a/bin/v_update_mail_domains_disk +++ b/bin/v_update_mail_domains_disk @@ -58,7 +58,6 @@ done recalc_user_disk_usage # Logging -log_history "$EVENT" log_event "$OK" "$EVENT" exit diff --git a/web/add/web/index.php b/web/add/web/index.php index 27fcbf2f6..29cc8fdcd 100644 --- a/web/add/web/index.php +++ b/web/add/web/index.php @@ -100,15 +100,15 @@ top_panel($user,$TAB); } } unset($output); - } - if (($_POST['v_dns'] == 'on') && (empty($_SESSION['error_msg']))) { - exec (VESTA_CMD."v_add_dns_on_web_alias ".$user." ".$v_domain." 'no'", $output, $return_var); - if ($return_var != 0) { - $error = implode('
', $output); - if (empty($error)) $error = 'Error: vesta did not return any output.'; - $_SESSION['error_msg'] = $error; + if (($_POST['v_dns'] == 'on') && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_add_dns_on_web_alias ".$user." ".$v_domain." ".$alias." 'no'", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); } - unset($output); } } @@ -182,6 +182,16 @@ top_panel($user,$TAB); unset($output); } + if (($_POST['v_dns'] == 'on') && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_restart_dns", $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } + unset($output); + } + if (empty($_SESSION['error_msg'])) { exec (VESTA_CMD."v_restart_web", $output, $return_var); if ($return_var != 0) { @@ -205,6 +215,10 @@ top_panel($user,$TAB); $ips = json_decode(implode('', $output), true); unset($output); + exec (VESTA_CMD."v_get_user_value ".$user." 'TEMPLATE'", $output, $return_var); + $template = $output[0] ; + unset($output); + exec (VESTA_CMD."v_list_web_templates json", $output, $return_var); $templates = json_decode(implode('', $output), true); unset($output); diff --git a/web/edit/web/index.php b/web/edit/web/index.php index 16f053732..7328359c5 100644 --- a/web/edit/web/index.php +++ b/web/edit/web/index.php @@ -142,7 +142,7 @@ top_panel($user,$TAB); $v_aliases = str_replace(' ', "\n", $waliases); $result = array_diff($valiases, $aliases); foreach ($result as $alias) { - if (empty($_SESSION['error_msg'])) { + if ((empty($_SESSION['error_msg'])) && (!empty($alias))) { $restart_web = 'yes'; $v_template = escapeshellarg($_POST['v_template']); exec (VESTA_CMD."v_delete_web_domain_alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var); @@ -152,9 +152,9 @@ top_panel($user,$TAB); $_SESSION['error_msg'] = $error; } unset($output); - exec (VESTA_CMD."v_list_dns_domain ".$v_username." '".$alias."' json", $output, $return_var); - if ((empty($_SESSION['error_msg'])) && ($return_var == 0 )) { - exec (VESTA_CMD."v_delete_dns_domain ".$v_username." '".$alias."'", $output, $return_var); + + if (empty($_SESSION['error_msg'])) { + exec (VESTA_CMD."v_delete_dns_on_web_alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var); if ($return_var != 0) { $error = implode('
', $output); if (empty($error)) $error = 'Error: vesta did not return any output.'; @@ -168,7 +168,7 @@ top_panel($user,$TAB); $result = array_diff($aliases, $valiases); foreach ($result as $alias) { - if (empty($_SESSION['error_msg'])) { + if ((empty($_SESSION['error_msg'])) && (!empty($alias))) { $restart_web = 'yes'; $v_template = escapeshellarg($_POST['v_template']); exec (VESTA_CMD."v_add_web_domain_alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var); @@ -178,9 +178,8 @@ top_panel($user,$TAB); $_SESSION['error_msg'] = $error; } unset($output); - exec (VESTA_CMD."v_list_dns_domain ".$v_username." '".$alias."' json", $output, $return_var); - if ((empty($_SESSION['error_msg'])) && ($return_var == 0 )) { - exec (VESTA_CMD."v_add_dns_domain ".$v_username." '".$alias."' ".$v_ip, $output, $return_var); + if (empty($_SESSION['error_msg'])) { + exec (VESTA_CMD."v_add_dns_on_web_alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var); if ($return_var != 0) { $error = implode('
', $output); if (empty($error)) $error = 'Error: vesta did not return any output.'; diff --git a/web/templates/admin/add_web.html b/web/templates/admin/add_web.html index 10aabb411..688b8f937 100644 --- a/web/templates/admin/add_web.html +++ b/web/templates/admin/add_web.html @@ -41,7 +41,6 @@ DNS support > - Mail support > Advanced Options ⇢ @@ -52,14 +51,15 @@ Apache Template