Skip to content

Commit a968f9b

Browse files
committed
edit dns record page
1 parent 42afe55 commit a968f9b

File tree

7 files changed

+223
-113
lines changed

7 files changed

+223
-113
lines changed

bin/v_change_dns_domain_record

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: change dns domain record
3-
# options: user domain id record type value [priority]
3+
# options: user domain id value [priority]
44
#
55
# The function for changing DNS record.
66

@@ -14,13 +14,10 @@ user=$1
1414
domain=$(idn -t --quiet -u "$2" )
1515
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
1616
domain_idn=$(idn -t --quiet -a "$domain")
17-
record=$(idn -t --quiet -u "$3" )
18-
record=$(echo $record | tr '[:upper:]' '[:lower:]')
19-
rtype=$(echo "$4"| tr '[:lower:]' '[:upper:]')
20-
dvalue=$(idn -t --quiet -u "$5" )
17+
id=$3
18+
dvalue=$(idn -t --quiet -u "$4" )
2119
dvalue=$(echo $dvalue | tr '[:upper:]' '[:lower:]')
22-
id=$6
23-
priority=$7
20+
priority=$5
2421

2522
# Includes
2623
source $VESTA/conf/vesta.conf
@@ -32,8 +29,8 @@ source $VESTA/func/domain.sh
3229
# Verifications #
3330
#----------------------------------------------------------#
3431

35-
check_args '6' "$#" 'user domain record type id value [priority]'
36-
validate_format 'user' 'domain' 'record' 'rtype' 'dvalue' 'id'
32+
check_args '4' "$#" 'user domain id value [priority]'
33+
validate_format 'user' 'domain' 'id' 'dvalue'
3734
is_system_enabled "$DNS_SYSTEM"
3835
is_object_valid 'user' 'USER' "$user"
3936
is_object_unsuspended 'user' 'USER' "$user"
@@ -46,15 +43,16 @@ is_object_valid "dns/$domain" 'ID' "$id"
4643
# Action #
4744
#----------------------------------------------------------#
4845

49-
if [ "$rtype" != 'MX' ] || [ "$rtype" != 'SRV' ]; then
46+
# Deleting old record
47+
line=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf)
48+
eval $line
49+
if [ "$TYPE" != 'MX' ] && [ "$TYPE" != 'SRV' ]; then
5050
priority=''
5151
fi
52-
53-
# Deleting old record
5452
sed -i "/^ID='$id'/d" $USER_DATA/dns/$domain.conf
5553

5654
# Adding record
57-
dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
55+
dns_rec="ID='$id' RECORD='$RECORD' TYPE='$TYPE' PRIORITY='$priority'"
5856
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
5957
echo "$dns_rec" >> $USER_DATA/dns/$domain.conf
6058

bin/v_list_dns_domain_records

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ is_object_valid 'dns' 'DOMAIN' "$domain"
8686

8787
# Defining config and fields
8888
conf=$USER_DATA/dns/$domain.conf
89-
fields='$ID $RECORD $TYPE $PRIORITY $VALUE $SUSPENDED $TIME $DATE'
89+
fields='$ID $RECORD $TYPE $PRIORITY $VALUE $ID $SUSPENDED $TIME $DATE'
9090

9191
# Listing domains
9292
case $format in

web/edit/dns/index.php

Lines changed: 157 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -26,119 +26,182 @@
2626
}
2727

2828
// Check domain
29-
$v_domain = escapeshellarg($_GET['domain']);
30-
exec (VESTA_CMD."v_list_dns_domain ".$user." ".$v_domain." json", $output, $return_var);
31-
if ($return_var != 0) {
32-
$error = implode('<br>', $output);
33-
if (empty($error)) $error = 'Error: vesta did not return any output.';
34-
$_SESSION['error_msg'] = $error;
35-
} else {
36-
$data = json_decode(implode('', $output), true);
37-
unset($output);
38-
39-
$v_username = $user;
40-
$v_domain = $_GET['domain'];
41-
$v_ip = $data[$v_domain]['IP'];
42-
$v_template = $data[$v_domain]['TPL'];
43-
$v_ttl = $data[$v_domain]['TTL'];
44-
$v_exp = $data[$v_domain]['EXP'];
45-
$v_soa = $data[$v_domain]['SOA'];
46-
$v_date = $data[$v_domain]['DATE'];
47-
$v_time = $data[$v_domain]['TIME'];
48-
49-
exec (VESTA_CMD."v_list_dns_templates json", $output, $return_var);
50-
$templates = json_decode(implode('', $output), true);
51-
unset($output);
52-
}
29+
if ((!empty($_GET['domain'])) && (empty($_GET['record_id']))) {
30+
$v_domain = escapeshellarg($_GET['domain']);
31+
exec (VESTA_CMD."v_list_dns_domain ".$user." ".$v_domain." json", $output, $return_var);
32+
if ($return_var != 0) {
33+
$error = implode('<br>', $output);
34+
if (empty($error)) $error = 'Error: vesta did not return any output.';
35+
$_SESSION['error_msg'] = $error;
36+
} else {
37+
$data = json_decode(implode('', $output), true);
38+
unset($output);
5339

54-
// Action
55-
if (!empty($_POST['save'])) {
56-
$v_domain = escapeshellarg($_POST['v_domain']);
57-
58-
// IP
59-
if (($v_ip != $_POST['v_ip']) && (empty($_SESSION['error_msg']))) {
60-
$v_ip = escapeshellarg($_POST['v_ip']);
61-
exec (VESTA_CMD."v_change_dns_domain_ip ".$v_username." ".$v_domain." ".$v_ip." 'no'", $output, $return_var);
62-
if ($return_var != 0) {
63-
$error = implode('<br>', $output);
64-
if (empty($error)) $error = 'Error: vesta did not return any output.';
65-
$_SESSION['error_msg'] = $error;
40+
$v_username = $user;
41+
$v_domain = $_GET['domain'];
42+
$v_ip = $data[$v_domain]['IP'];
43+
$v_template = $data[$v_domain]['TPL'];
44+
$v_ttl = $data[$v_domain]['TTL'];
45+
$v_exp = $data[$v_domain]['EXP'];
46+
$v_soa = $data[$v_domain]['SOA'];
47+
$v_date = $data[$v_domain]['DATE'];
48+
$v_time = $data[$v_domain]['TIME'];
49+
$v_suspended = $data[$v_domain]['SUSPENDED'];
50+
if ( $v_suspended == 'yes' ) {
51+
$v_status = 'suspended';
52+
} else {
53+
$v_status = 'active';
6654
}
67-
$restart_dns = 'yes';
55+
56+
exec (VESTA_CMD."v_list_dns_templates json", $output, $return_var);
57+
$templates = json_decode(implode('', $output), true);
6858
unset($output);
6959
}
7060

71-
// Template
72-
if (($v_template != $_POST['v_template']) && (empty($_SESSION['error_msg']))) {
73-
$v_template = escapeshellarg($_POST['v_template']);
74-
exec (VESTA_CMD."v_change_dns_domain_tpl ".$v_username." ".$v_domain." ".$v_template." 'no'", $output, $return_var);
75-
if ($return_var != 0) {
76-
$error = implode('<br>', $output);
77-
if (empty($error)) $error = 'Error: vesta did not return any output.';
78-
$_SESSION['error_msg'] = $error;
61+
// Action
62+
if (!empty($_POST['save'])) {
63+
$v_domain = escapeshellarg($_POST['v_domain']);
64+
65+
// IP
66+
if (($v_ip != $_POST['v_ip']) && (empty($_SESSION['error_msg']))) {
67+
$v_ip = escapeshellarg($_POST['v_ip']);
68+
exec (VESTA_CMD."v_change_dns_domain_ip ".$v_username." ".$v_domain." ".$v_ip." 'no'", $output, $return_var);
69+
if ($return_var != 0) {
70+
$error = implode('<br>', $output);
71+
if (empty($error)) $error = 'Error: vesta did not return any output.';
72+
$_SESSION['error_msg'] = $error;
73+
}
74+
$restart_dns = 'yes';
75+
unset($output);
7976
}
80-
unset($output);
81-
$restart_dns = 'yes';
82-
}
8377

84-
// SOA
85-
if (($v_soa != $_POST['v_soa']) && (empty($_SESSION['error_msg']))) {
86-
$v_soa = escapeshellarg($_POST['v_soa']);
87-
exec (VESTA_CMD."v_change_dns_domain_soa ".$v_username." ".$v_domain." ".$v_soa." 'no'", $output, $return_var);
88-
if ($return_var != 0) {
89-
$error = implode('<br>', $output);
90-
if (empty($error)) $error = 'Error: vesta did not return any output.';
91-
$_SESSION['error_msg'] = $error;
78+
// Template
79+
if (($v_template != $_POST['v_template']) && (empty($_SESSION['error_msg']))) {
80+
$v_template = escapeshellarg($_POST['v_template']);
81+
exec (VESTA_CMD."v_change_dns_domain_tpl ".$v_username." ".$v_domain." ".$v_template." 'no'", $output, $return_var);
82+
if ($return_var != 0) {
83+
$error = implode('<br>', $output);
84+
if (empty($error)) $error = 'Error: vesta did not return any output.';
85+
$_SESSION['error_msg'] = $error;
86+
}
87+
unset($output);
88+
$restart_dns = 'yes';
9289
}
93-
unset($output);
94-
$restart_dns = 'yes';
95-
}
9690

97-
// EXP
98-
if (($v_exp != $_POST['v_exp']) && (empty($_SESSION['error_msg']))) {
99-
$v_exp = escapeshellarg($_POST['v_exp']);
100-
exec (VESTA_CMD."v_change_dns_domain_exp ".$v_username." ".$v_domain." ".$v_exp." 'no'", $output, $return_var);
101-
if ($return_var != 0) {
102-
$error = implode('<br>', $output);
103-
if (empty($error)) $error = 'Error: vesta did not return any output.';
104-
$_SESSION['error_msg'] = $error;
91+
// SOA
92+
if (($v_soa != $_POST['v_soa']) && (empty($_SESSION['error_msg']))) {
93+
$v_soa = escapeshellarg($_POST['v_soa']);
94+
exec (VESTA_CMD."v_change_dns_domain_soa ".$v_username." ".$v_domain." ".$v_soa." 'no'", $output, $return_var);
95+
if ($return_var != 0) {
96+
$error = implode('<br>', $output);
97+
if (empty($error)) $error = 'Error: vesta did not return any output.';
98+
$_SESSION['error_msg'] = $error;
99+
}
100+
unset($output);
101+
$restart_dns = 'yes';
105102
}
106-
unset($output);
107-
$restart_dns = 'yes';
108-
}
109103

110-
// TTL
111-
if (($v_ttl != $_POST['v_ttl']) && (empty($_SESSION['error_msg']))) {
112-
$v_ttl = escapeshellarg($_POST['v_ttl']);
113-
exec (VESTA_CMD."v_change_dns_domain_ttl ".$v_username." ".$v_domain." ".$v_ttl." 'no'", $output, $return_var);
114-
if ($return_var != 0) {
115-
$error = implode('<br>', $output);
116-
if (empty($error)) $error = 'Error: vesta did not return any output.';
117-
$_SESSION['error_msg'] = $error;
104+
// EXP
105+
if (($v_exp != $_POST['v_exp']) && (empty($_SESSION['error_msg']))) {
106+
$v_exp = escapeshellarg($_POST['v_exp']);
107+
exec (VESTA_CMD."v_change_dns_domain_exp ".$v_username." ".$v_domain." ".$v_exp." 'no'", $output, $return_var);
108+
if ($return_var != 0) {
109+
$error = implode('<br>', $output);
110+
if (empty($error)) $error = 'Error: vesta did not return any output.';
111+
$_SESSION['error_msg'] = $error;
112+
}
113+
unset($output);
114+
$restart_dns = 'yes';
118115
}
116+
117+
// TTL
118+
if (($v_ttl != $_POST['v_ttl']) && (empty($_SESSION['error_msg']))) {
119+
$v_ttl = escapeshellarg($_POST['v_ttl']);
120+
exec (VESTA_CMD."v_change_dns_domain_ttl ".$v_username." ".$v_domain." ".$v_ttl." 'no'", $output, $return_var);
121+
if ($return_var != 0) {
122+
$error = implode('<br>', $output);
123+
if (empty($error)) $error = 'Error: vesta did not return any output.';
124+
$_SESSION['error_msg'] = $error;
125+
}
126+
unset($output);
127+
$restart_dns = 'yes';
128+
}
129+
130+
// Restart dns
131+
if (!empty($restart_dns) && (empty($_SESSION['error_msg']))) {
132+
exec (VESTA_CMD."v_restart_dns", $output, $return_var);
133+
if ($return_var != 0) {
134+
$error = implode('<br>', $output);
135+
if (empty($error)) $error = 'Error: vesta did not return any output.';
136+
$_SESSION['error_msg'] = $error;
137+
}
138+
}
139+
140+
if (empty($_SESSION['error_msg'])) {
141+
$_SESSION['ok_msg'] = "OK: changes has been saved.";
142+
}
143+
144+
}
145+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_dns.html');
146+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_dns.html');
147+
unset($_SESSION['error_msg']);
148+
unset($_SESSION['ok_msg']);
149+
} else {
150+
$v_domain = escapeshellarg($_GET['domain']);
151+
$v_record_id = escapeshellarg($_GET['record_id']);
152+
exec (VESTA_CMD."v_list_dns_domain_records ".$user." ".$v_domain." 'json'", $output, $return_var);
153+
if ($return_var != 0) {
154+
$error = implode('<br>', $output);
155+
if (empty($error)) $error = 'Error: vesta did not return any output.';
156+
$_SESSION['error_msg'] = $error;
157+
} else {
158+
$data = json_decode(implode('', $output), true);
119159
unset($output);
120-
$restart_dns = 'yes';
160+
$v_username = $user;
161+
$v_domain = $_GET['domain'];
162+
$v_record_id = $_GET['record_id'];
163+
$v_rec = $data[$v_record_id]['RECORD'];
164+
$v_type = $data[$v_record_id]['TYPE'];
165+
$v_val = $data[$v_record_id]['VALUE'];
166+
$v_priority = $data[$v_record_id]['PRIORITY'];
167+
$v_suspended = $data[$v_record_id]['SUSPENDED'];
168+
if ( $v_suspended == 'yes' ) {
169+
$v_status = 'suspended';
170+
} else {
171+
$v_status = 'active';
172+
}
173+
$v_date = $data[$v_record_id]['DATE'];
174+
$v_time = $data[$v_record_id]['TIME'];
121175
}
122176

123-
// Restart dns
124-
if (!empty($restart_dns) && (empty($_SESSION['error_msg']))) {
125-
exec (VESTA_CMD."v_restart_dns", $output, $return_var);
126-
if ($return_var != 0) {
127-
$error = implode('<br>', $output);
128-
if (empty($error)) $error = 'Error: vesta did not return any output.';
129-
$_SESSION['error_msg'] = $error;
177+
// Action
178+
if (!empty($_POST['save'])) {
179+
$v_domain = escapeshellarg($_POST['v_domain']);
180+
$v_record_id = escapeshellarg($_POST['v_record_id']);
181+
182+
if (($v_val != $_POST['v_val']) || ($v_priority != $_POST['v_priority']) && (empty($_SESSION['error_msg']))) {
183+
$v_val = escapeshellarg($_POST['v_val']);
184+
$v_priority = escapeshellarg($_POST['v_priority']);
185+
exec (VESTA_CMD."v_change_dns_domain_record ".$v_username." ".$v_domain." ".$v_record_id." ".$v_val." ".$v_priority, $output, $return_var);
186+
if ($return_var != 0) {
187+
$error = implode('<br>', $output);
188+
if (empty($error)) $error = 'Error: vesta did not return any output.';
189+
$_SESSION['error_msg'] = $error;
190+
}
191+
$restart_dns = 'yes';
192+
unset($output);
193+
}
194+
195+
if (empty($_SESSION['error_msg'])) {
196+
$_SESSION['ok_msg'] = "OK: changes has been saved.";
130197
}
131-
}
132198

133-
if (empty($_SESSION['error_msg'])) {
134-
$_SESSION['ok_msg'] = "OK: changes has been saved.";
135199
}
136-
200+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_dns_rec.html');
201+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_dns_rec.html');
202+
unset($_SESSION['error_msg']);
203+
unset($_SESSION['ok_msg']);
137204
}
138-
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_dns.html');
139-
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_dns.html');
140-
unset($_SESSION['error_msg']);
141-
unset($_SESSION['ok_msg']);
142205
}
143206

144207
// Footer
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<table class='data'>
2+
<tr class="data-add">
3+
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
4+
<table class="data-col1">
5+
<tr><td style="padding: 20px 0 4px 4px;"><a class="data-date" ?><?php echo date("d M Y", strtotime($v_date))?></a></td></tr>
6+
<tr><td style="padding: 0 0 6px 4px;"><a class="data-date" ?><?php echo $v_time?></a></td></tr>
7+
<tr><td style="padding: 0 0 0 24px;" class="data-<?php echo $v_status ?>"><b><?php echo $v_status ?></b></td></tr>
8+
</table>
9+
</td>
10+
<td class="data-dotted" width="830px" style="vertical-align:top;">
11+
<table width="830px"><tr>
12+
<td></td>
13+
</tr></table>
14+
<form method="post" name="v_edit_user">
15+
<table class="data-col2" width="830px">
16+
<tr><td class="add-text" style="padding: 10 0 0 2px;">Domain</td></tr>
17+
<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>
18+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Record</td></tr>
19+
<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>
20+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Type</td></tr>
21+
<tr><td><input type="text" size="20" class="add-input" name="v_type" <?php if (!empty($v_rec)) echo "value=".$v_type; ?> disabled></tr>
22+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Value</td></tr>
23+
<tr><td><input type="text" size="20" class="add-input" name="v_val" <?php if (!empty($v_val)) echo "value=".$v_val; ?>></tr>
24+
<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>
25+
<tr><td><input type="text" size="20" class="add-input" name="v_priority" <?php if (!empty($v_priority)) echo "value=".$v_priority; ?>></tr>
26+
27+
<tr><td style="padding: 24px 0 0 0;">
28+
<input type="submit" class="add-button" name="save" value="Save"></form>
29+
<input type="button" class="add-button" value="Cancel" onClick="location.href='/list/dns/<?php echo "?domain=".$_GET['domain']; ?>'">
30+
</td></tr>
31+
</form>
32+
</table>
33+
</td>
34+
</tr>
35+
</table>

web/templates/admin/list_dns_rec.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
<tr><td style="padding: 18 0 4 18;"><input type="checkbox" name="object" ></td></tr>
1919
<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>
2020
<tr><td class="data-<?php echo $status ?>"><b><?php echo $status ?></b></td></tr>
21-
2221
</table>
2322
</td>
2423
<td class="data-dotted" width="830px" style="vertical-align:top;">
2524
<table width="830px"><tr>
2625
<td></td>
27-
<td class="data-controls" width="50px"><img src="/images/edit.png" width="8px" height="8px"><a href="#"> edit</a></td>
28-
<td class="data-controls" width="80px"><img src="/images/suspend.png" width="7px" height="8px"><a href="#"> <?php echo $spnd_action ?></a></td>
29-
<td class="data-controls" width="70px"><img src="/images/delete.png" width="7px" height="7px"><a href="#"> delete</a></td>
26+
<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>
27+
<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>
28+
<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>
3029
</tr></table>
3130

3231
<table class="data-col5" width="780px">

0 commit comments

Comments
 (0)