From fe71ef2f0877dca27149142bab4c0d78401cfacf Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Tue, 24 Jul 2012 22:04:27 +0300 Subject: [PATCH] improved dns nameservers section --- bin/v_add_dns_domain | 62 +++++++++++++++++++----------- bin/v_add_dns_domain_record | 4 +- bin/v_change_dns_domain_exp | 1 - bin/v_change_dns_domain_soa | 5 ++- bin/v_change_dns_domain_tpl | 4 -- bin/v_change_dns_domain_ttl | 5 ++- bin/v_change_user_ns | 26 ++----------- bin/v_get_user_value | 3 -- bin/v_rebuild_dns_domains | 4 -- func/main.sh | 4 -- web/add/dns/index.php | 57 ++++++++++++++++++++------- web/templates/admin/add_dns.html | 14 +++++-- web/templates/admin/edit_user.html | 4 +- web/templates/admin/list_db.html | 2 +- web/templates/admin/list_mail.html | 2 +- web/templates/user/add_dns.html | 25 +++++++++++- web/templates/user/edit_user.html | 2 +- web/templates/user/list_db.html | 2 +- web/templates/user/list_mail.html | 2 +- 19 files changed, 138 insertions(+), 90 deletions(-) diff --git a/bin/v_add_dns_domain b/bin/v_add_dns_domain index 955d16ea..8d15b8e8 100755 --- a/bin/v_add_dns_domain +++ b/bin/v_add_dns_domain @@ -1,6 +1,6 @@ #!/bin/bash # info: add dns domain -# options: user domain ip [template] [exp] [soa] [ttl] +# options: user domain ip [template] [ns1] [ns2] [ns3] [ns4] # # The function adds DNS zone with records defined in the template. If the exp # argument isn't stated, the expiration date value will be set to next year. @@ -21,10 +21,11 @@ domain=$(echo $domain | tr '[:upper:]' '[:lower:]') domain_idn=$(idn -t --quiet -a "$domain") ip=$3 template=$4 -next_year=$(date +%F -d "+ 1 year") -exp=${5-$next_year} -soa=$6 -ttl=${7-14400} +ns1=$5 +ns2=$6 +ns3=$7 +ns4=$8 +restart=$9 # Includes source $VESTA/conf/vesta.conf @@ -36,8 +37,8 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -check_args '3' "$#" 'user domain ip [template] [exp] [soa] [ttl]' -validate_format 'user' 'domain' 'ip' 'exp' 'ttl' +check_args '3' "$#" 'user domain ip [template] [ns1] [ns2] [ns3] [ns4]' +validate_format 'user' 'domain' 'ip' is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" is_object_unsuspended 'user' 'USER' "$user" @@ -51,23 +52,42 @@ else is_dns_template_valid fi +if [ ! -z "$ns1" ]; then + ns1=$(echo $5 | sed -e 's/\.*$//g' -e 's/^\.*//g') + validate_format 'ns1' +fi +if [ ! -z "$ns2" ]; then + ns2=$(echo $6 | sed -e 's/\.*$//g' -e 's/^\.*//g') + validate_format 'ns2' +fi + +if [ ! -z "$ns3" ]; then + ns3=$(echo $7 | sed -e 's/\.*$//g' -e 's/^\.*//g') + validate_format 'ns3' +fi +if [ ! -z "$ns4" ]; then + ns4=$(echo $8 | sed -e 's/\.*$//g' -e 's/^\.*//g') + validate_format 'ns4' +fi + #----------------------------------------------------------# # Action # #----------------------------------------------------------# # Defining variables -i=1 -ns=$(get_user_value '$NS') -for nameserver in ${ns//,/ };do - eval ns$i=$nameserver - (( ++i)) -done - -# Define soa -if [ -z "$soa" ]; then - soa="$ns1" +if [ -z $ns2 ]; then + i=1 + ns=$(get_user_value '$NS') + for nameserver in ${ns//,/ };do + eval ns$i=$nameserver + (( ++i)) + done fi +soa="$ns1" +exp=$(date +%F -d "+ 1 year") +ttl=14400 + # Adding zone to dns dir cat $DNSTPL/$template.tpl |\ @@ -78,10 +98,6 @@ cat $DNSTPL/$template.tpl |\ -e "s/%ns2%/$ns2/g" \ -e "s/%ns3%/$ns3/g" \ -e "s/%ns4%/$ns4/g" \ - -e "s/%ns5%/$ns5/g" \ - -e "s/%ns6%/$ns6/g" \ - -e "s/%ns7%/$ns7/g" \ - -e "s/%ns8%/$ns8/g" \ -e "s/%time%/$TIME/g" \ -e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf chmod 660 $USER_DATA/dns/$domain.conf @@ -116,7 +132,9 @@ increase_user_value "$user" '$U_DNS_DOMAINS' increase_user_value "$user" '$U_DNS_RECORDS' "$records" # Restart named -$BIN/v_restart_dns "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_dns "$EVENT" +fi # Logging log_history "$EVENT" diff --git a/bin/v_add_dns_domain_record b/bin/v_add_dns_domain_record index 0b0d975c..b4b3c972 100755 --- a/bin/v_add_dns_domain_record +++ b/bin/v_add_dns_domain_record @@ -18,10 +18,10 @@ domain=$(idn -t --quiet -u "$2" ) domain=$(echo $domain | tr '[:upper:]' '[:lower:]') domain_idn=$(idn -t --quiet -a "$domain") record=$(idn -t --quiet -u "$3" ) -record=$(echo $record | tr '[:upper:]' '[:lower:]') +record=$(echo "$record" | tr '[:upper:]' '[:lower:]') rtype=$(echo "$4"| tr '[:lower:]' '[:upper:]') dvalue=$(idn -t --quiet -u "$5" ) -dvalue=$(echo $dvalue | tr '[:upper:]' '[:lower:]') +dvalue=$(echo "$dvalue" | tr '[:upper:]' '[:lower:]') priority=$6 id=$7 diff --git a/bin/v_change_dns_domain_exp b/bin/v_change_dns_domain_exp index 35b5d451..070a2171 100755 --- a/bin/v_change_dns_domain_exp +++ b/bin/v_change_dns_domain_exp @@ -42,7 +42,6 @@ is_object_unsuspended 'dns' 'DOMAIN' "$domain" update_object_value 'dns' 'DOMAIN' "$domain" '$EXP' "$exp" - #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# diff --git a/bin/v_change_dns_domain_soa b/bin/v_change_dns_domain_soa index 2851756e..3eff0011 100755 --- a/bin/v_change_dns_domain_soa +++ b/bin/v_change_dns_domain_soa @@ -15,6 +15,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") soa=$(echo $3 | sed -e 's/\.*$//g' -e 's/^\.*//g') +restart=$4 # Includes source $VESTA/conf/vesta.conf @@ -51,7 +52,9 @@ update_domain_zone #----------------------------------------------------------# # Restart named -$BIN/v_restart_dns "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_dns "$EVENT" +fi # Logging log_history "$EVENT" diff --git a/bin/v_change_dns_domain_tpl b/bin/v_change_dns_domain_tpl index e57e2537..e80112b2 100755 --- a/bin/v_change_dns_domain_tpl +++ b/bin/v_change_dns_domain_tpl @@ -63,10 +63,6 @@ cat $DNSTPL/$template.tpl |\ -e "s/%ns2%/$ns2/g" \ -e "s/%ns3%/$ns3/g" \ -e "s/%ns4%/$ns4/g" \ - -e "s/%ns5%/$ns5/g" \ - -e "s/%ns6%/$ns6/g" \ - -e "s/%ns7%/$ns7/g" \ - -e "s/%ns8%/$ns8/g" \ -e "s/%time%/$TIME/g" \ -e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf diff --git a/bin/v_change_dns_domain_ttl b/bin/v_change_dns_domain_ttl index c324a9c2..73d8f45b 100755 --- a/bin/v_change_dns_domain_ttl +++ b/bin/v_change_dns_domain_ttl @@ -14,6 +14,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") ttl=$3 +restart=$4 # Includes source $VESTA/conf/vesta.conf @@ -50,7 +51,9 @@ update_domain_zone #----------------------------------------------------------# # Restart named -$BIN/v_restart_dns "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_dns "$EVENT" +fi # Logging log_history "$EVENT" diff --git a/bin/v_change_user_ns b/bin/v_change_user_ns index 91232140..131a4549 100755 --- a/bin/v_change_user_ns +++ b/bin/v_change_user_ns @@ -1,6 +1,6 @@ #!/bin/bash # info: change user nameservers -# options: user ns1 ns2 [ns3] [ns4] [ns5] [ns6] [ns7] [ns8] +# options: user ns1 ns2 [ns3] [ns4] # # The function for changing default nameservers for speciefic user. @@ -15,10 +15,6 @@ ns1=$(echo $2 | sed -e 's/\.*$//g' -e 's/^\.*//g') ns2=$(echo $3 | sed -e 's/\.*$//g' -e 's/^\.*//g') ns3=$4 ns4=$5 -ns5=$6 -ns6=$7 -ns7=$8 -ns8=$9 # Includes source $VESTA/conf/vesta.conf @@ -30,7 +26,7 @@ source $VESTA/func/main.sh #----------------------------------------------------------# # Checking args -check_args '3' "$#" 'user ns1 ns2 [ns3] [ns4] [ns5] [ns6] [ns7] [ns8]' +check_args '3' "$#" 'user ns1 ns2 [ns3] [ns4]' # Checking argument format validate_format 'user' 'ns1' 'ns2' @@ -42,22 +38,6 @@ if [ ! -z "$ns4" ]; then ns4=$(echo $5 | sed -e 's/\.*$//g' -e 's/^\.*//g') validate_format 'ns4' fi -if [ ! -z "$ns5" ]; then - ns5=$(echo $6 | sed -e 's/\.*$//g' -e 's/^\.*//g') - validate_format 'ns5' -fi -if [ ! -z "$ns6" ]; then - ns6=$(echo $7 | sed -e 's/\.*$//g' -e 's/^\.*//g') - validate_format 'ns6' -fi -if [ ! -z "$ns7" ]; then - ns7=$(echo $8 | sed -e 's/\.*$//g' -e 's/^\.*//g') - validate_format 'ns7' -fi -if [ ! -z "$ns8" ]; then - ns8=$(echo $9 | sed -e 's/\.*$//g' -e 's/^\.*//g') - validate_format 'ns8' -fi is_object_valid 'user' 'USER' "$user" is_object_unsuspended 'user' 'USER' "$user" @@ -68,7 +48,7 @@ is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# # Merging values -ns="$ns1,$ns2,$ns3,$ns4,$ns5,$ns6,$ns7,$ns8" +ns="$ns1,$ns2,$ns3,$ns4" ns=$(echo "$ns"|sed -e "s/,,//g" -e "s/,$//") # Changing ns values diff --git a/bin/v_get_user_value b/bin/v_get_user_value index 29224c91..d8c193fd 100755 --- a/bin/v_get_user_value +++ b/bin/v_get_user_value @@ -42,7 +42,4 @@ echo "$value" # Vesta # #----------------------------------------------------------# -# Logging -log_event "$OK" "$EVENT" - exit diff --git a/bin/v_rebuild_dns_domains b/bin/v_rebuild_dns_domains index d5e314f2..89fc598c 100755 --- a/bin/v_rebuild_dns_domains +++ b/bin/v_rebuild_dns_domains @@ -71,10 +71,6 @@ for domain in $(search_objects 'dns' 'DOMAIN' "*" 'DOMAIN'); do -e "s/%ns2%/$ns2/g" \ -e "s/%ns3%/$ns3/g" \ -e "s/%ns4%/$ns4/g" \ - -e "s/%ns5%/$ns5/g" \ - -e "s/%ns6%/$ns6/g" \ - -e "s/%ns7%/$ns7/g" \ - -e "s/%ns8%/$ns8/g" \ -e "s/%time%/$TIME/g" \ -e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf fi diff --git a/func/main.sh b/func/main.sh index 915cd482..5f691303 100755 --- a/func/main.sh +++ b/func/main.sh @@ -734,10 +734,6 @@ validate_format(){ ns2) validate_format_domain "$arg" ;; ns3) validate_format_domain "$arg" ;; ns4) validate_format_domain "$arg" ;; - ns5) validate_format_domain "$arg" ;; - ns6) validate_format_domain "$arg" ;; - ns7) validate_format_domain "$arg" ;; - ns8) validate_format_domain "$arg" ;; package) validate_format_username "$arg" "$arg_name" ;; password) validate_format_password "$arg" ;; port) validate_format_int "$arg" ;; diff --git a/web/add/dns/index.php b/web/add/dns/index.php index c333b23b..c1fa300b 100644 --- a/web/add/dns/index.php +++ b/web/add/dns/index.php @@ -18,9 +18,6 @@ top_panel($user,$TAB); // Check input if (empty($_POST['v_domain'])) $errors[] = 'domain'; if (empty($_POST['v_ip'])) $errors[] = 'ip'; - if (empty($_POST['v_exp'])) $errors[] = 'expiriation date'; - if (empty($_POST['v_soa'])) $errors[] = 'SOA'; - if (empty($_POST['v_ttl'])) $errors[] = 'TTL'; // Protect input $v_domain = preg_replace("/^www./i", "", $_POST['v_domain']); @@ -31,9 +28,10 @@ top_panel($user,$TAB); } else { $v_template = "''"; } - $v_exp = escapeshellarg($_POST['v_exp']); - $v_soa = escapeshellarg($_POST['v_soa']); - $v_ttl = escapeshellarg($_POST['v_ttl']); + if (!empty($_POST['v_ns1'])) $v_ns1 = escapeshellarg($_POST['v_ns1']); + if (!empty($_POST['v_ns2'])) $v_ns2 = escapeshellarg($_POST['v_ns2']); + if (!empty($_POST['v_ns3'])) $v_ns3 = escapeshellarg($_POST['v_ns3']); + if (!empty($_POST['v_ns4'])) $v_ns4 = escapeshellarg($_POST['v_ns4']); // Check for errors if (!empty($errors[0])) { @@ -48,7 +46,7 @@ top_panel($user,$TAB); } else { // Add DNS - exec (VESTA_CMD."v_add_dns_domain ".$user." ".$v_domain." ".$v_ip." ".$v_template." ".$v_exp." ".$v_soa." ".$v_ttl, $output, $return_var); + exec (VESTA_CMD."v_add_dns_domain ".$user." ".$v_domain." ".$v_ip." ".$v_template." ".$v_ns1." ".$v_ns2." ".$v_ns3." ".$ns4, $output, $return_var); if ($return_var != 0) { $error = implode('
', $output); if (empty($error)) $error = 'Error: vesta did not return any output.'; @@ -56,6 +54,30 @@ top_panel($user,$TAB); } unset($output); + // Change Expiriation date + if ((!empty($_POST['v_exp'])) && ($_POST['v_exp'] != date('Y-m-d', strtotime('+1 year')))) { + $v_exp = escapeshellarg($_POST['v_exp']); + exec (VESTA_CMD."v_change_dns_domain_exp ".$user." ".$v_domain." ".$v_exp, $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); + } + + // Change TTL + if ((!empty($_POST['v_ttl'])) && ($_POST['v_ttl'] != '14400')) { + $v_ttl = escapeshellarg($_POST['v_ttl']); + exec (VESTA_CMD."v_change_dns_domain_ttl ".$user." ".$v_domain." ".$v_ttl, $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'])) { $_SESSION['ok_msg'] = "OK: domain ".$_POST[v_domain]." has been created successfully."; unset($v_domain); @@ -111,17 +133,26 @@ top_panel($user,$TAB); if ((empty($_GET['domain'])) && (empty($_POST['domain']))) { + exec (VESTA_CMD."v_get_user_value ".$user." 'TEMPLATE'", $output, $return_var); + $template = $output[0] ; + unset($output); + exec (VESTA_CMD."v_list_dns_templates json", $output, $return_var); $templates = json_decode(implode('', $output), true); unset($output); - exec (VESTA_CMD."v_list_user_ns ".$user." json", $output, $return_var); - $soa = json_decode(implode('', $output), true); - $v_soa = $soa[0]; - unset($output); + if ((empty($v_ns1)) && (empty($v_ns2))) { + exec (VESTA_CMD."v_list_user_ns ".$user." json", $output, $return_var); + $nameservers = json_decode(implode('', $output), true); + $v_ns1 = $nameservers[0]; + $v_ns2 = $nameservers[1]; + $v_ns3 = $nameservers[2]; + $v_ns4 = $nameservers[3]; + unset($output); + } - $v_ttl = 14400; - $v_exp = date('Y-m-d', strtotime('+1 year')); + if (empty($v_ttl)) $v_ttl = 14400; + if (empty($v_exp)) $v_exp = date('Y-m-d', strtotime('+1 year')); if ($_SESSION['user'] == 'admin') { include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_dns.html'); diff --git a/web/templates/admin/add_dns.html b/web/templates/admin/add_dns.html index e19b6d7f..288f581f 100644 --- a/web/templates/admin/add_dns.html +++ b/web/templates/admin/add_dns.html @@ -35,22 +35,30 @@ Template Domain Expiriation SOA - TTL NameServers + diff --git a/web/templates/admin/edit_user.html b/web/templates/admin/edit_user.html index 450230ee..d3c64c27 100644 --- a/web/templates/admin/edit_user.html +++ b/web/templates/admin/edit_user.html @@ -49,7 +49,7 @@ document.v_edit_user.v_password.value = randomstring; Last Name Default Template: + Default Template - Name Servers + Default Name Servers $value) { ++$i; if ($data[$key]['SUSPENDED'] == 'yes') { diff --git a/web/templates/admin/list_mail.html b/web/templates/admin/list_mail.html index 39476ea8..178cf5be 100644 --- a/web/templates/admin/list_mail.html +++ b/web/templates/admin/list_mail.html @@ -2,7 +2,7 @@ $value) { ++$i; if ($data[$key]['SUSPENDED'] == 'yes') { diff --git a/web/templates/user/add_dns.html b/web/templates/user/add_dns.html index 22188d7b..288f581f 100644 --- a/web/templates/user/add_dns.html +++ b/web/templates/user/add_dns.html @@ -32,12 +32,33 @@ Advanced Options ⇢ + + - + +
Template
Domain Expiriation
SOA
TTL
NameServers
diff --git a/web/templates/user/edit_user.html b/web/templates/user/edit_user.html index ad24f38c..ad182634 100644 --- a/web/templates/user/edit_user.html +++ b/web/templates/user/edit_user.html @@ -32,7 +32,7 @@ document.v_edit_user.v_password.value = randomstring;
Email
Name Servers
Default Name Servers
$value) { ++$i; if ($data[$key]['SUSPENDED'] == 'yes') { diff --git a/web/templates/user/list_mail.html b/web/templates/user/list_mail.html index b2e327b3..9cce3c4d 100644 --- a/web/templates/user/list_mail.html +++ b/web/templates/user/list_mail.html @@ -1,7 +1,7 @@ $value) { ++$i; if ($data[$key]['SUSPENDED'] == 'yes') {