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

+ 11 - 13
bin/v_change_dns_domain_record

@@ -1,6 +1,6 @@
 #!/bin/bash
 # info: change dns domain record
-# options: user domain id record type value [priority]
+# options: user domain id value [priority]
 #
 # The function for changing DNS record.
 
@@ -14,13 +14,10 @@ user=$1
 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:]')
-rtype=$(echo "$4"| tr '[:lower:]' '[:upper:]')
-dvalue=$(idn -t --quiet -u "$5" )
+id=$3
+dvalue=$(idn -t --quiet -u "$4" )
 dvalue=$(echo $dvalue | tr '[:upper:]' '[:lower:]')
-id=$6
-priority=$7
+priority=$5
 
 # Includes
 source $VESTA/conf/vesta.conf
@@ -32,8 +29,8 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-check_args '6' "$#" 'user domain record type id value [priority]'
-validate_format 'user' 'domain' 'record' 'rtype' 'dvalue' 'id'
+check_args '4' "$#" 'user domain id value [priority]'
+validate_format 'user' 'domain' 'id' 'dvalue'
 is_system_enabled "$DNS_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
@@ -46,15 +43,16 @@ is_object_valid "dns/$domain" 'ID' "$id"
 #                       Action                             #
 #----------------------------------------------------------#
 
-if [ "$rtype" != 'MX' ] || [ "$rtype" != 'SRV' ]; then
+# Deleting old record
+line=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf)
+eval $line
+if [ "$TYPE" != 'MX' ] && [ "$TYPE" != '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' PRIORITY='$priority'"
+dns_rec="ID='$id' RECORD='$RECORD' TYPE='$TYPE' PRIORITY='$priority'"
 dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
 echo "$dns_rec" >> $USER_DATA/dns/$domain.conf
 

+ 1 - 1
bin/v_list_dns_domain_records

@@ -86,7 +86,7 @@ is_object_valid 'dns' 'DOMAIN' "$domain"
 
 # Defining config and fields
 conf=$USER_DATA/dns/$domain.conf
-fields='$ID $RECORD $TYPE $PRIORITY $VALUE $SUSPENDED $TIME $DATE'
+fields='$ID $RECORD $TYPE $PRIORITY $VALUE $ID $SUSPENDED $TIME $DATE'
 
 # Listing domains
 case $format in 

+ 157 - 94
web/edit/dns/index.php

@@ -26,119 +26,182 @@ if ($_SESSION['user'] == 'admin') {
     }
 
     // Check domain
-    $v_domain = escapeshellarg($_GET['domain']);
-    exec (VESTA_CMD."v_list_dns_domain ".$user." ".$v_domain." json", $output, $return_var);
-    if ($return_var != 0) {
-        $error = implode('<br>', $output);
-        if (empty($error)) $error = 'Error: vesta did not return any output.';
-        $_SESSION['error_msg'] = $error;
-    } else {
-        $data = json_decode(implode('', $output), true);
-        unset($output);
-
-        $v_username = $user;
-        $v_domain = $_GET['domain'];
-        $v_ip = $data[$v_domain]['IP'];
-        $v_template = $data[$v_domain]['TPL'];
-        $v_ttl = $data[$v_domain]['TTL'];
-        $v_exp = $data[$v_domain]['EXP'];
-        $v_soa = $data[$v_domain]['SOA'];
-        $v_date = $data[$v_domain]['DATE'];
-        $v_time = $data[$v_domain]['TIME'];
-
-        exec (VESTA_CMD."v_list_dns_templates json", $output, $return_var);
-        $templates = json_decode(implode('', $output), true);
-        unset($output);
-    }
+    if ((!empty($_GET['domain'])) && (empty($_GET['record_id'])))  {
+        $v_domain = escapeshellarg($_GET['domain']);
+        exec (VESTA_CMD."v_list_dns_domain ".$user." ".$v_domain." json", $output, $return_var);
+        if ($return_var != 0) {
+            $error = implode('<br>', $output);
+            if (empty($error)) $error = 'Error: vesta did not return any output.';
+            $_SESSION['error_msg'] = $error;
+        } else {
+            $data = json_decode(implode('', $output), true);
+            unset($output);
 
-    // Action
-    if (!empty($_POST['save'])) {
-        $v_domain = escapeshellarg($_POST['v_domain']);
-
-        // IP
-        if (($v_ip != $_POST['v_ip']) && (empty($_SESSION['error_msg']))) {
-            $v_ip = escapeshellarg($_POST['v_ip']);
-            exec (VESTA_CMD."v_change_dns_domain_ip ".$v_username." ".$v_domain." ".$v_ip." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = 'Error: vesta did not return any output.';
-                $_SESSION['error_msg'] = $error;
+            $v_username = $user;
+            $v_domain = $_GET['domain'];
+            $v_ip = $data[$v_domain]['IP'];
+            $v_template = $data[$v_domain]['TPL'];
+            $v_ttl = $data[$v_domain]['TTL'];
+            $v_exp = $data[$v_domain]['EXP'];
+            $v_soa = $data[$v_domain]['SOA'];
+            $v_date = $data[$v_domain]['DATE'];
+            $v_time = $data[$v_domain]['TIME'];
+            $v_suspended = $data[$v_domain]['SUSPENDED'];
+            if ( $v_suspended == 'yes' ) {
+                $v_status =  'suspended';
+            } else {
+                $v_status =  'active';
             }
-            $restart_dns = 'yes';
+
+            exec (VESTA_CMD."v_list_dns_templates json", $output, $return_var);
+            $templates = json_decode(implode('', $output), true);
             unset($output);
         }
 
-        // Template
-        if (($v_template != $_POST['v_template']) && (empty($_SESSION['error_msg']))) {
-            $v_template = escapeshellarg($_POST['v_template']);
-            exec (VESTA_CMD."v_change_dns_domain_tpl ".$v_username." ".$v_domain." ".$v_template." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = 'Error: vesta did not return any output.';
-                $_SESSION['error_msg'] = $error;
+        // Action
+        if (!empty($_POST['save'])) {
+            $v_domain = escapeshellarg($_POST['v_domain']);
+
+            // IP
+            if (($v_ip != $_POST['v_ip']) && (empty($_SESSION['error_msg']))) {
+                $v_ip = escapeshellarg($_POST['v_ip']);
+                exec (VESTA_CMD."v_change_dns_domain_ip ".$v_username." ".$v_domain." ".$v_ip." 'no'", $output, $return_var);
+                if ($return_var != 0) {
+                    $error = implode('<br>', $output);
+                    if (empty($error)) $error = 'Error: vesta did not return any output.';
+                    $_SESSION['error_msg'] = $error;
+                }
+                $restart_dns = 'yes';
+                unset($output);
             }
-            unset($output);
-            $restart_dns = 'yes';
-        }
 
-        // SOA
-        if (($v_soa != $_POST['v_soa']) && (empty($_SESSION['error_msg']))) {
-            $v_soa = escapeshellarg($_POST['v_soa']);
-            exec (VESTA_CMD."v_change_dns_domain_soa ".$v_username." ".$v_domain." ".$v_soa." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = 'Error: vesta did not return any output.';
-                $_SESSION['error_msg'] = $error;
+            // Template
+            if (($v_template != $_POST['v_template']) && (empty($_SESSION['error_msg']))) {
+                $v_template = escapeshellarg($_POST['v_template']);
+                exec (VESTA_CMD."v_change_dns_domain_tpl ".$v_username." ".$v_domain." ".$v_template." 'no'", $output, $return_var);
+                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);
+                $restart_dns = 'yes';
             }
-            unset($output);
-            $restart_dns = 'yes';
-        }
 
-        // EXP
-        if (($v_exp != $_POST['v_exp']) && (empty($_SESSION['error_msg']))) {
-            $v_exp = escapeshellarg($_POST['v_exp']);
-            exec (VESTA_CMD."v_change_dns_domain_exp ".$v_username." ".$v_domain." ".$v_exp." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = 'Error: vesta did not return any output.';
-                $_SESSION['error_msg'] = $error;
+            // SOA
+            if (($v_soa != $_POST['v_soa']) && (empty($_SESSION['error_msg']))) {
+                $v_soa = escapeshellarg($_POST['v_soa']);
+                exec (VESTA_CMD."v_change_dns_domain_soa ".$v_username." ".$v_domain." ".$v_soa." 'no'", $output, $return_var);
+                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);
+                $restart_dns = 'yes';
             }
-            unset($output);
-            $restart_dns = 'yes';
-        }
 
-        // TTL
-        if (($v_ttl != $_POST['v_ttl']) && (empty($_SESSION['error_msg']))) {
-            $v_ttl = escapeshellarg($_POST['v_ttl']);
-            exec (VESTA_CMD."v_change_dns_domain_ttl ".$v_username." ".$v_domain." ".$v_ttl." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = 'Error: vesta did not return any output.';
-                $_SESSION['error_msg'] = $error;
+            // EXP
+            if (($v_exp != $_POST['v_exp']) && (empty($_SESSION['error_msg']))) {
+                $v_exp = escapeshellarg($_POST['v_exp']);
+                exec (VESTA_CMD."v_change_dns_domain_exp ".$v_username." ".$v_domain." ".$v_exp." 'no'", $output, $return_var);
+                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);
+                $restart_dns = 'yes';
             }
+
+            // TTL
+            if (($v_ttl != $_POST['v_ttl']) && (empty($_SESSION['error_msg']))) {
+                $v_ttl = escapeshellarg($_POST['v_ttl']);
+                exec (VESTA_CMD."v_change_dns_domain_ttl ".$v_username." ".$v_domain." ".$v_ttl." 'no'", $output, $return_var);
+                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);
+                $restart_dns = 'yes';
+            }
+    
+            // Restart dns
+            if (!empty($restart_dns) && (empty($_SESSION['error_msg']))) {
+                exec (VESTA_CMD."v_restart_dns", $output, $return_var);
+                if ($return_var != 0) {
+                    $error = implode('<br>', $output);
+                    if (empty($error)) $error = 'Error: vesta did not return any output.';
+                    $_SESSION['error_msg'] = $error;
+                }
+            }
+    
+            if (empty($_SESSION['error_msg'])) {
+                $_SESSION['ok_msg'] = "OK: changes has been saved.";
+            }
+
+        }
+        include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_dns.html');
+        include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_dns.html');
+        unset($_SESSION['error_msg']);
+        unset($_SESSION['ok_msg']);
+    } else {
+        $v_domain = escapeshellarg($_GET['domain']);
+        $v_record_id = escapeshellarg($_GET['record_id']);
+        exec (VESTA_CMD."v_list_dns_domain_records ".$user." ".$v_domain." 'json'", $output, $return_var);
+        if ($return_var != 0) {
+            $error = implode('<br>', $output);
+            if (empty($error)) $error = 'Error: vesta did not return any output.';
+            $_SESSION['error_msg'] = $error;
+        } else {
+            $data = json_decode(implode('', $output), true);
             unset($output);
-            $restart_dns = 'yes';
+            $v_username = $user;
+            $v_domain = $_GET['domain'];
+            $v_record_id = $_GET['record_id'];
+            $v_rec = $data[$v_record_id]['RECORD'];
+            $v_type = $data[$v_record_id]['TYPE'];
+            $v_val = $data[$v_record_id]['VALUE'];
+            $v_priority = $data[$v_record_id]['PRIORITY'];
+            $v_suspended = $data[$v_record_id]['SUSPENDED'];
+            if ( $v_suspended == 'yes' ) {
+                $v_status =  'suspended';
+            } else {
+                $v_status =  'active';
+            }
+            $v_date = $data[$v_record_id]['DATE'];
+            $v_time = $data[$v_record_id]['TIME'];
         }
 
-        // Restart dns
-        if (!empty($restart_dns) && (empty($_SESSION['error_msg']))) {
-            exec (VESTA_CMD."v_restart_dns", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = 'Error: vesta did not return any output.';
-                $_SESSION['error_msg'] = $error;
+        // Action
+        if (!empty($_POST['save'])) {
+            $v_domain = escapeshellarg($_POST['v_domain']);
+            $v_record_id = escapeshellarg($_POST['v_record_id']);
+
+            if (($v_val != $_POST['v_val']) || ($v_priority != $_POST['v_priority']) && (empty($_SESSION['error_msg']))) {
+                $v_val = escapeshellarg($_POST['v_val']);
+                $v_priority = escapeshellarg($_POST['v_priority']);
+                exec (VESTA_CMD."v_change_dns_domain_record ".$v_username." ".$v_domain." ".$v_record_id." ".$v_val." ".$v_priority, $output, $return_var);
+                if ($return_var != 0) {
+                    $error = implode('<br>', $output);
+                    if (empty($error)) $error = 'Error: vesta did not return any output.';
+                    $_SESSION['error_msg'] = $error;
+                }
+                $restart_dns = 'yes';
+                unset($output);
+            }
+    
+            if (empty($_SESSION['error_msg'])) {
+                $_SESSION['ok_msg'] = "OK: changes has been saved.";
             }
-        }
 
-        if (empty($_SESSION['error_msg'])) {
-            $_SESSION['ok_msg'] = "OK: changes has been saved.";
         }
-
+        include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_dns_rec.html');
+        include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_dns_rec.html');
+        unset($_SESSION['error_msg']);
+        unset($_SESSION['ok_msg']);
     }
-    include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_dns.html');
-    include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_dns.html');
-    unset($_SESSION['error_msg']);
-    unset($_SESSION['ok_msg']);
 }
 
 // Footer

+ 35 - 0
web/templates/admin/edit_dns_rec.html

@@ -0,0 +1,35 @@
+<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: 20px 0 4px 4px;"><a class="data-date" ?><?php echo date("d M Y", strtotime($v_date))?></a></td></tr>
+            <tr><td style="padding: 0 0 6px 4px;"><a class="data-date" ?><?php echo $v_time?></a></td></tr>
+            <tr><td style="padding: 0 0 0 24px;" class="data-<?php echo $v_status ?>"><b><?php echo $v_status ?></b></td></tr>
+        </table>
+    </td>
+    <td class="data-dotted" width="830px" style="vertical-align:top;">
+        <table width="830px"><tr>
+            <td></td>
+        </tr></table>
+        <form method="post" name="v_edit_user">
+        <table class="data-col2" width="830px">
+            <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; ?> disabled> <input type="hidden" name="v_record_id" <?php if (!empty($v_record_id)) echo "value=".$v_record_id; ?> ></tr>
+            <tr><td class="add-text" style="padding: 10px 0 0 2px;">Type</td></tr>
+            <tr><td><input type="text" size="20" class="add-input" name="v_type" <?php if (!empty($v_rec)) echo "value=".$v_type; ?> disabled></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" class="add-button" name="save" value="Save"></form>
+                <input type="button" class="add-button" value="Cancel" onClick="location.href='/list/dns/<?php echo "?domain=".$_GET['domain'];  ?>'">
+            </td></tr>
+            </form>
+        </table>
+    </td>
+</tr>
+</table>

+ 3 - 4
web/templates/admin/list_dns_rec.html

@@ -18,15 +18,14 @@ foreach ($data as $key => $value) {
             <tr><td style="padding: 18 0 4 18;"><input type="checkbox" name="object" ></td></tr>
             <tr><td><a class="data-date" title="<?php echo  $data[$key]['DATE']."  ".$data[$key]['TIME'] ?>"><?php echo date("d M Y", strtotime($data[$key]['DATE'])) ?></td></tr>
             <tr><td class="data-<?php echo $status ?>"><b><?php echo $status ?></b></td></tr>
-
         </table>
     </td>
     <td class="data-dotted" width="830px" style="vertical-align:top;">
         <table width="830px"><tr>
             <td></td>
-            <td class="data-controls" width="50px"><img src="/images/edit.png" width="8px" height="8px"><a href="#"> 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>
+            <td class="data-controls" width="50px"><img src="/images/edit.png" width="8px" height="8px"><a href="/edit/dns/?domain=<?php echo $_GET['domain'] ?>&record_id=<?php echo $data[$key]['ID'] ?>"> edit</a></td>
+            <td class="data-controls" width="80px"><img src="/images/suspend.png" width="7px" height="8px"><a href="/<?php echo $spnd_action ?>/dns/?domain=<?php echo $_GET['domain'] ?>&record_id=<?php echo $data[$key]['ID'] ?>"> <?php echo $spnd_action ?></a></td>
+            <td class="data-controls" width="70px"><img src="/images/delete.png" width="7px" height="7px"><a href="/delete/dns/?domain=<?php echo $_GET['domain'] ?>&record_id=<?php echo $data[$key]['ID'] ?>"> delete</a></td>
         </tr></table>
 
         <table class="data-col5" width="780px">

+ 1 - 1
web/templates/admin/menu_dns_rec.html

@@ -1,7 +1,7 @@
 <table class="sub-menu">
 <tr>
     <td width="142px" style="padding: 16px 0 16px 6px">
-    <button style="width:120px; padding: 2px 0px 2px 0px;" onclick="location.href='/add/dns/'">Add Record</button>
+    <button style="width:120px; padding: 2px 0px 2px 0px;" onclick="location.href='/add/dns/?domain=<?php echo $_GET['domain'] ?>'">Add Record</button>
     <td><a style="padding: 0 4px 0 12px" class="select-controls" href='javascript:checkedAll("vstobjects");'> toggle all </a>
     <select style="margin:0 0 0 0px">
         <option>apply to selected</option>

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

@@ -0,0 +1,15 @@
+<table class="sub-menu">
+<tr>
+    <td style="padding: 10px 2px 28px 0;" ><a class="add-name"><b>Editing 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>