Serghey Rodin 13 лет назад
Родитель
Сommit
42afe55adc

+ 6 - 5
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
 

+ 2 - 2
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"

+ 70 - 14
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';
+
+        // 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']);
+
+        // 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('<br>', $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 <b>".$_POST[v_rec]."</b> has been created successfully.";
+                unset($v_domain);
+                unset($v_rec);
+                unset($v_val);
+                unset($v_priority);
+            }
+        }
+    }
+
 
-    $v_ttl = 14400;
-    $v_exp = date('Y-m-d', strtotime('+1 year'));
+    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);
 
-    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']);
+        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

+ 1 - 1
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');

+ 58 - 0
web/templates/admin/add_dns_rec.html

@@ -0,0 +1,58 @@
+<script language="javascript">
+  function elementHideShow(elementToHideOrShow)
+    {
+      var el = document.getElementById(elementToHideOrShow);
+      if (el.style.display == "block") {
+        el.style.display = "none";
+      } else {
+        el.style.display = "block";
+      }
+    }
+</script>
+
+
+<table class='data'>
+<tr class="data-add">
+    <td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
+        <table class="data-col1">
+            <tr><td style="padding: 18 0 4 18;"></td></tr>
+        </table>
+    </td>
+    <td class="data-dotted" width="830px" style="vertical-align:top;">
+        <table width="830px"><tr>
+            <td></td>
+        </tr></table>
+        <table class="data-col2" width="600px">
+            <form method="post" name="v_add_user">
+            <tr><td class="add-text" style="padding: 10 0 0 2px;">Domain</td></tr>
+            <tr><td><input type="text" size="20" class="add-input" name="v_domain" <?php echo "value=".$v_domain;  ?> disabled ><input type="hidden" name="v_domain" <?php echo "value=".$v_domain;  ?>></td></tr>
+            <tr><td class="add-text" style="padding: 10px 0 0 2px;">Record</td></tr>
+            <tr><td><input type="text" size="20" class="add-input" name="v_rec" <?php if (!empty($v_rec)) echo "value=".$v_rec; ?>></tr>
+            <tr><td class="add-text" style="padding: 10px 0 0 2px;">Type</td></tr>
+            <tr><td><select class="add-list" name="v_type">
+                    <option value="A" <?php if ($v_type == 'A') echo selected; ?>>A</option>
+                    <option value="AAAA" <?php if ($v_type == 'AAAA') echo selected; ?>>AAAA</option>
+                    <option value="NS" <?php if ($v_type == 'NS') echo selected; ?>>NS</option>
+                    <option value="CNAME" <?php if ($v_type == 'CNAME') echo selected; ?>>CNAME</option>
+                    <option value="MX" <?php if ($v_type == 'MX') echo selected; ?>>MX</option>
+                    <option value="TXT" <?php if ($v_type == 'TXT') echo selected; ?>>TXT</option>
+                    <option value="SRV" <?php if ($v_type == 'SRV') echo selected; ?>>SRV</option>
+                    <option value="DNSKEY" <?php if ($v_type == 'DNSKEY') echo selected; ?>>DNSKEY</option>
+                    <option value="KEY" <?php if ($v_type == 'KEY') echo selected; ?>>KEY</option>
+                    <option value="IPSECKEY" <?php if ($v_type == 'IPSECKEY') echo selected; ?>>IPSECKEY</option>
+                    <option value="PTR" <?php if ($v_type == 'PTR') echo selected; ?>>PTR</option>
+                    <option value="SPF" <?php if ($v_type == 'SPF') echo selected; ?>>SPF</option>
+                </select></td></tr>
+            <tr><td class="add-text" style="padding: 10px 0 0 2px;">Value</td></tr>
+            <tr><td><input type="text" size="20" class="add-input" name="v_val" <?php if (!empty($v_val)) echo "value=".$v_val; ?>></tr>
+            <tr><td class="add-text" style="padding: 10px 0 0 2px;">Priority <span style="padding:0 0 0 6px; font-size: 10pt; color:#555;">(optional)</span></td></tr>
+            <tr><td><input type="text" size="20" class="add-input" name="v_priority" <?php if (!empty($v_priority)) echo "value=".$v_priority; ?>></tr>
+
+            <tr><td style="padding: 24px 0 0 0;">
+                <input type="submit" name="ok_rec" value="OK" class="add-button"></form>
+                <input type="button" class="add-button" value="Cancel" onClick="location.href='/list/dns/<?php echo "?domain=".$v_domain;  ?>'">
+            </td></tr>
+        </table>
+    </td>
+</tr>
+</table>

+ 0 - 1
web/templates/admin/edit_dns.html

@@ -40,7 +40,6 @@
             <tr><td style="padding: 24px 0 0 0;">
                 <input type="submit" class="add-button" name="save" value="Save"></form>
                 <input type="button" class="add-button" value="Cancel" onClick="location.href='/list/dns/'">
-                <input type="button" class="add-button" value="Edit Records" onClick="location.href='/list/dns/'">
             </td></tr>
             </form>
         </table>

+ 2 - 2
web/templates/admin/list_dns.html

@@ -24,8 +24,8 @@ foreach ($data as $key => $value) {
     <td class="data-dotted" width="830px" style="vertical-align:top;">
         <table width="830px"><tr>
             <td></td>
-            <td class="data-controls" width="96px"><img src="/images/more.png" width="8px" height="8px"><a href="?domain=<?php echo $key ?>"> list records</a></td>
-            <td class="data-controls" width="92px"><img src="/images/add.png" width="8px" height="8px"><a href="?domain=<?php echo $key ?>"> add record</a></td>
+            <td class="data-controls" width="96px"><img src="/images/more.png" width="8px" height="8px"><a href="/list/dns/?domain=<?php echo $key ?>"> list records</a></td>
+            <td class="data-controls" width="92px"><img src="/images/add.png" width="8px" height="8px"><a href="/add/dns/?domain=<?php echo $key ?>"> add record</a></td>
             <td class="data-controls" width="50px"><img src="/images/edit.png" width="8px" height="8px"><a href="/edit/dns/?domain=<?php echo $key ?>"> edit</a></td>
             <td class="data-controls" width="80px"><img src="/images/suspend.png" width="7px" height="8px"><a href="#"> <?php echo $spnd_action ?></a></td>
             <td class="data-controls" width="70px"><img src="/images/delete.png" width="7px" height="7px"><a href="#"> delete</a></td>

+ 15 - 0
web/templates/admin/menu_add_dns_rec.html

@@ -0,0 +1,15 @@
+<table class="sub-menu">
+<tr>
+    <td style="padding: 10px 2px 28px 0;" ><a class="add-name"><b>Adding DNS Record</b></a>
+    <?php 
+        if (!empty($_SESSION['error_msg'])) {
+            echo "<a class=\"add-error\"> → ".$_SESSION['error_msg']."</a>";
+        } else {
+            if (!empty($_SESSION['ok_msg'])) {
+                echo "<a class=\"add-ok\"> → ".$_SESSION['ok_msg']."</a>";
+            }
+        }
+    ?>
+    </td>
+</tr>
+</table>