From 42afe55adc316df85ffb337285da51dfeff06186 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Wed, 13 Jun 2012 16:08:49 +0300 Subject: [PATCH] dns add dns record page --- bin/v_add_dns_domain_record | 11 +-- bin/v_change_dns_domain_record | 4 +- web/add/dns/index.php | 84 +++++++++++++++++++---- web/list/dns/index.php | 2 +- web/templates/admin/add_dns_rec.html | 58 ++++++++++++++++ web/templates/admin/edit_dns.html | 1 - web/templates/admin/list_dns.html | 4 +- web/templates/admin/menu_add_dns_rec.html | 15 ++++ 8 files changed, 154 insertions(+), 25 deletions(-) create mode 100644 web/templates/admin/add_dns_rec.html create mode 100644 web/templates/admin/menu_add_dns_rec.html diff --git a/bin/v_add_dns_domain_record b/bin/v_add_dns_domain_record index 335ce867..0b0d975c 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] [priority] +# options: user domain record type value [priority] [id] # # 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 @@ -22,8 +22,9 @@ 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 +priority=$6 +id=$7 + # Includes source $VESTA/conf/vesta.conf @@ -35,7 +36,7 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -check_args '5' "$#" 'user domain record type value [id] [priority]' +check_args '5' "$#" 'user domain record type value [priority] [id]' validate_format 'user' 'domain' 'record' 'rtype' 'dvalue' is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" @@ -52,7 +53,7 @@ is_object_free "dns/$domain" 'ID' "$id" # Action # #----------------------------------------------------------# -if [ "$rtype" != 'MX' ] || [ "$rtype" != 'SRV' ]; then +if [ "$rtype" != 'MX' ] && [ "$rtype" != 'SRV' ]; then priority='' fi diff --git a/bin/v_change_dns_domain_record b/bin/v_change_dns_domain_record index 649f827e..88fc8281 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 record type value id [priority] +# options: user domain id record type value [priority] # # The function for changing DNS record. @@ -32,7 +32,7 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -check_args '6' "$#" 'user domain record type value id [priority]' +check_args '6' "$#" 'user domain record type id value [priority]' validate_format 'user' 'domain' 'record' 'rtype' 'dvalue' 'id' is_system_enabled "$DNS_SYSTEM" is_object_valid 'user' 'USER' "$user" diff --git a/web/add/dns/index.php b/web/add/dns/index.php index e40ad833..eed374c6 100644 --- a/web/add/dns/index.php +++ b/web/add/dns/index.php @@ -20,7 +20,7 @@ if ($_SESSION['user'] == 'admin') { header("Location: /list/dns/"); } - // Action + // DNS Domain if (!empty($_POST['ok'])) { // Check input if (empty($_POST['v_domain'])) $errors[] = 'domain'; @@ -67,22 +67,78 @@ if ($_SESSION['user'] == 'admin') { } } - 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); + // DNS Record + if (!empty($_POST['ok_rec'])) { + // Check input + if (empty($_POST['v_domain'])) $errors[] = 'domain'; + if (empty($_POST['v_rec'])) $errors[] = 'record'; + if (empty($_POST['v_type'])) $errors[] = 'type'; + if (empty($_POST['v_val'])) $errors[] = 'value'; - $v_ttl = 14400; - $v_exp = date('Y-m-d', strtotime('+1 year')); + // Protect input + $v_domain = escapeshellarg($_POST['v_domain']); + $v_rec = escapeshellarg($_POST['v_rec']); + $v_type = escapeshellarg($_POST['v_type']); + $v_val = escapeshellarg($_POST['v_val']); + $v_priority = escapeshellarg($_POST['v_priority']); - include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_dns.html'); - include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html'); - unset($_SESSION['error_msg']); - unset($_SESSION['ok_msg']); + // Check for errors + if (!empty($errors[0])) { + foreach ($errors as $i => $error) { + if ( $i == 0 ) { + $error_msg = $error; + } else { + $error_msg = $error_msg.", ".$error; + } + } + $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank."; + } else { + // Add DNS Record + exec (VESTA_CMD."v_add_dns_domain_record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority, $output, $return_var); + $v_type = $_POST['v_type']; + 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: record ".$_POST[v_rec]." has been created successfully."; + unset($v_domain); + unset($v_rec); + unset($v_val); + unset($v_priority); + } + } + } + + + if ((empty($_GET['domain'])) && (empty($_POST['domain']))) { + 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); + + $v_ttl = 14400; + $v_exp = date('Y-m-d', strtotime('+1 year')); + + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_dns.html'); + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html'); + unset($_SESSION['error_msg']); + unset($_SESSION['ok_msg']); + } else { + $v_domain = $_GET['domain']; + + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_dns_rec.html'); + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns_rec.html'); + unset($_SESSION['error_msg']); + unset($_SESSION['ok_msg']); + } } // Footer diff --git a/web/list/dns/index.php b/web/list/dns/index.php index a178796f..d1a698d0 100644 --- a/web/list/dns/index.php +++ b/web/list/dns/index.php @@ -27,7 +27,7 @@ if ($_SESSION['user'] == 'admin') { exec (VESTA_CMD."v_list_dns_domain_records '".$user."' '".$_GET['domain']."' 'json'", $output, $return_var); check_error($return_var); $data = json_decode(implode('', $output), true); - //$data = array_reverse($data); + $data = array_reverse($data); unset($output); include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_dns_rec.html'); include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_dns_rec.html'); diff --git a/web/templates/admin/add_dns_rec.html b/web/templates/admin/add_dns_rec.html new file mode 100644 index 00000000..918e3052 --- /dev/null +++ b/web/templates/admin/add_dns_rec.html @@ -0,0 +1,58 @@ + + + + + + + + +
+ + +
+
+ + +
+ + + + + + + + + +
Domain
Record
Type
Value
Priority (optional)
+ + +
+
diff --git a/web/templates/admin/edit_dns.html b/web/templates/admin/edit_dns.html index cbadefda..936f6a82 100644 --- a/web/templates/admin/edit_dns.html +++ b/web/templates/admin/edit_dns.html @@ -40,7 +40,6 @@ - diff --git a/web/templates/admin/list_dns.html b/web/templates/admin/list_dns.html index 4f92b75a..9b6aaff6 100644 --- a/web/templates/admin/list_dns.html +++ b/web/templates/admin/list_dns.html @@ -24,8 +24,8 @@ foreach ($data as $key => $value) { - - + + diff --git a/web/templates/admin/menu_add_dns_rec.html b/web/templates/admin/menu_add_dns_rec.html new file mode 100644 index 00000000..c89dac67 --- /dev/null +++ b/web/templates/admin/menu_add_dns_rec.html @@ -0,0 +1,15 @@ +
list records add record list records add record edit delete
+ + + +