Skip to content

Commit 42afe55

Browse files
committed
dns add dns record page
1 parent 276df05 commit 42afe55

File tree

8 files changed

+154
-25
lines changed

8 files changed

+154
-25
lines changed

bin/v_add_dns_domain_record

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: add dns domain record
3-
# options: user domain record type value [id] [priority]
3+
# options: user domain record type value [priority] [id]
44
#
55
# The call is used for adding new DNS record. Complex records of TXT, MX and
66
# 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:]')
2222
rtype=$(echo "$4"| tr '[:lower:]' '[:upper:]')
2323
dvalue=$(idn -t --quiet -u "$5" )
2424
dvalue=$(echo $dvalue | tr '[:upper:]' '[:lower:]')
25-
id=$6
26-
priority=$7
25+
priority=$6
26+
id=$7
27+
2728

2829
# Includes
2930
source $VESTA/conf/vesta.conf
@@ -35,7 +36,7 @@ source $VESTA/func/domain.sh
3536
# Verifications #
3637
#----------------------------------------------------------#
3738

38-
check_args '5' "$#" 'user domain record type value [id] [priority]'
39+
check_args '5' "$#" 'user domain record type value [priority] [id]'
3940
validate_format 'user' 'domain' 'record' 'rtype' 'dvalue'
4041
is_system_enabled "$DNS_SYSTEM"
4142
is_object_valid 'user' 'USER' "$user"
@@ -52,7 +53,7 @@ is_object_free "dns/$domain" 'ID' "$id"
5253
# Action #
5354
#----------------------------------------------------------#
5455

55-
if [ "$rtype" != 'MX' ] || [ "$rtype" != 'SRV' ]; then
56+
if [ "$rtype" != 'MX' ] && [ "$rtype" != 'SRV' ]; then
5657
priority=''
5758
fi
5859

bin/v_change_dns_domain_record

Lines changed: 2 additions & 2 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 record type value id [priority]
3+
# options: user domain id record type value [priority]
44
#
55
# The function for changing DNS record.
66

@@ -32,7 +32,7 @@ source $VESTA/func/domain.sh
3232
# Verifications #
3333
#----------------------------------------------------------#
3434

35-
check_args '6' "$#" 'user domain record type value id [priority]'
35+
check_args '6' "$#" 'user domain record type id value [priority]'
3636
validate_format 'user' 'domain' 'record' 'rtype' 'dvalue' 'id'
3737
is_system_enabled "$DNS_SYSTEM"
3838
is_object_valid 'user' 'USER' "$user"

web/add/dns/index.php

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
header("Location: /list/dns/");
2121
}
2222

23-
// Action
23+
// DNS Domain
2424
if (!empty($_POST['ok'])) {
2525
// Check input
2626
if (empty($_POST['v_domain'])) $errors[] = 'domain';
@@ -67,22 +67,78 @@
6767
}
6868
}
6969

70-
exec (VESTA_CMD."v_list_dns_templates json", $output, $return_var);
71-
$templates = json_decode(implode('', $output), true);
72-
unset($output);
7370

74-
exec (VESTA_CMD."v_list_user_ns ".$user." json", $output, $return_var);
75-
$soa = json_decode(implode('', $output), true);
76-
$v_soa = $soa[0];
77-
unset($output);
71+
// DNS Record
72+
if (!empty($_POST['ok_rec'])) {
73+
// Check input
74+
if (empty($_POST['v_domain'])) $errors[] = 'domain';
75+
if (empty($_POST['v_rec'])) $errors[] = 'record';
76+
if (empty($_POST['v_type'])) $errors[] = 'type';
77+
if (empty($_POST['v_val'])) $errors[] = 'value';
78+
79+
// Protect input
80+
$v_domain = escapeshellarg($_POST['v_domain']);
81+
$v_rec = escapeshellarg($_POST['v_rec']);
82+
$v_type = escapeshellarg($_POST['v_type']);
83+
$v_val = escapeshellarg($_POST['v_val']);
84+
$v_priority = escapeshellarg($_POST['v_priority']);
85+
86+
// Check for errors
87+
if (!empty($errors[0])) {
88+
foreach ($errors as $i => $error) {
89+
if ( $i == 0 ) {
90+
$error_msg = $error;
91+
} else {
92+
$error_msg = $error_msg.", ".$error;
93+
}
94+
}
95+
$_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
96+
} else {
97+
// Add DNS Record
98+
exec (VESTA_CMD."v_add_dns_domain_record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority, $output, $return_var);
99+
$v_type = $_POST['v_type'];
100+
if ($return_var != 0) {
101+
$error = implode('<br>', $output);
102+
if (empty($error)) $error = 'Error: vesta did not return any output.';
103+
$_SESSION['error_msg'] = $error;
104+
}
105+
unset($output);
106+
if (empty($_SESSION['error_msg'])) {
107+
$_SESSION['ok_msg'] = "OK: record <b>".$_POST[v_rec]."</b> has been created successfully.";
108+
unset($v_domain);
109+
unset($v_rec);
110+
unset($v_val);
111+
unset($v_priority);
112+
}
113+
}
114+
}
115+
78116

79-
$v_ttl = 14400;
80-
$v_exp = date('Y-m-d', strtotime('+1 year'));
117+
if ((empty($_GET['domain'])) && (empty($_POST['domain']))) {
118+
exec (VESTA_CMD."v_list_dns_templates json", $output, $return_var);
119+
$templates = json_decode(implode('', $output), true);
120+
unset($output);
81121

82-
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_dns.html');
83-
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html');
84-
unset($_SESSION['error_msg']);
85-
unset($_SESSION['ok_msg']);
122+
exec (VESTA_CMD."v_list_user_ns ".$user." json", $output, $return_var);
123+
$soa = json_decode(implode('', $output), true);
124+
$v_soa = $soa[0];
125+
unset($output);
126+
127+
$v_ttl = 14400;
128+
$v_exp = date('Y-m-d', strtotime('+1 year'));
129+
130+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_dns.html');
131+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html');
132+
unset($_SESSION['error_msg']);
133+
unset($_SESSION['ok_msg']);
134+
} else {
135+
$v_domain = $_GET['domain'];
136+
137+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_dns_rec.html');
138+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns_rec.html');
139+
unset($_SESSION['error_msg']);
140+
unset($_SESSION['ok_msg']);
141+
}
86142
}
87143

88144
// Footer

web/list/dns/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
exec (VESTA_CMD."v_list_dns_domain_records '".$user."' '".$_GET['domain']."' 'json'", $output, $return_var);
2828
check_error($return_var);
2929
$data = json_decode(implode('', $output), true);
30-
//$data = array_reverse($data);
30+
$data = array_reverse($data);
3131
unset($output);
3232
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_dns_rec.html');
3333
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_dns_rec.html');
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<script language="javascript">
2+
function elementHideShow(elementToHideOrShow)
3+
{
4+
var el = document.getElementById(elementToHideOrShow);
5+
if (el.style.display == "block") {
6+
el.style.display = "none";
7+
} else {
8+
el.style.display = "block";
9+
}
10+
}
11+
</script>
12+
13+
14+
<table class='data'>
15+
<tr class="data-add">
16+
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
17+
<table class="data-col1">
18+
<tr><td style="padding: 18 0 4 18;"></td></tr>
19+
</table>
20+
</td>
21+
<td class="data-dotted" width="830px" style="vertical-align:top;">
22+
<table width="830px"><tr>
23+
<td></td>
24+
</tr></table>
25+
<table class="data-col2" width="600px">
26+
<form method="post" name="v_add_user">
27+
<tr><td class="add-text" style="padding: 10 0 0 2px;">Domain</td></tr>
28+
<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>
29+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Record</td></tr>
30+
<tr><td><input type="text" size="20" class="add-input" name="v_rec" <?php if (!empty($v_rec)) echo "value=".$v_rec; ?>></tr>
31+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Type</td></tr>
32+
<tr><td><select class="add-list" name="v_type">
33+
<option value="A" <?php if ($v_type == 'A') echo selected; ?>>A</option>
34+
<option value="AAAA" <?php if ($v_type == 'AAAA') echo selected; ?>>AAAA</option>
35+
<option value="NS" <?php if ($v_type == 'NS') echo selected; ?>>NS</option>
36+
<option value="CNAME" <?php if ($v_type == 'CNAME') echo selected; ?>>CNAME</option>
37+
<option value="MX" <?php if ($v_type == 'MX') echo selected; ?>>MX</option>
38+
<option value="TXT" <?php if ($v_type == 'TXT') echo selected; ?>>TXT</option>
39+
<option value="SRV" <?php if ($v_type == 'SRV') echo selected; ?>>SRV</option>
40+
<option value="DNSKEY" <?php if ($v_type == 'DNSKEY') echo selected; ?>>DNSKEY</option>
41+
<option value="KEY" <?php if ($v_type == 'KEY') echo selected; ?>>KEY</option>
42+
<option value="IPSECKEY" <?php if ($v_type == 'IPSECKEY') echo selected; ?>>IPSECKEY</option>
43+
<option value="PTR" <?php if ($v_type == 'PTR') echo selected; ?>>PTR</option>
44+
<option value="SPF" <?php if ($v_type == 'SPF') echo selected; ?>>SPF</option>
45+
</select></td></tr>
46+
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Value</td></tr>
47+
<tr><td><input type="text" size="20" class="add-input" name="v_val" <?php if (!empty($v_val)) echo "value=".$v_val; ?>></tr>
48+
<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>
49+
<tr><td><input type="text" size="20" class="add-input" name="v_priority" <?php if (!empty($v_priority)) echo "value=".$v_priority; ?>></tr>
50+
51+
<tr><td style="padding: 24px 0 0 0;">
52+
<input type="submit" name="ok_rec" value="OK" class="add-button"></form>
53+
<input type="button" class="add-button" value="Cancel" onClick="location.href='/list/dns/<?php echo "?domain=".$v_domain; ?>'">
54+
</td></tr>
55+
</table>
56+
</td>
57+
</tr>
58+
</table>

web/templates/admin/edit_dns.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
<tr><td style="padding: 24px 0 0 0;">
4141
<input type="submit" class="add-button" name="save" value="Save"></form>
4242
<input type="button" class="add-button" value="Cancel" onClick="location.href='/list/dns/'">
43-
<input type="button" class="add-button" value="Edit Records" onClick="location.href='/list/dns/'">
4443
</td></tr>
4544
</form>
4645
</table>

web/templates/admin/list_dns.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
<td class="data-dotted" width="830px" style="vertical-align:top;">
2525
<table width="830px"><tr>
2626
<td></td>
27-
<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>
28-
<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>
27+
<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>
28+
<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>
2929
<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>
3030
<td class="data-controls" width="80px"><img src="/images/suspend.png" width="7px" height="8px"><a href="#"> <?php echo $spnd_action ?></a></td>
3131
<td class="data-controls" width="70px"><img src="/images/delete.png" width="7px" height="7px"><a href="#"> delete</a></td>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<table class="sub-menu">
2+
<tr>
3+
<td style="padding: 10px 2px 28px 0;" ><a class="add-name"><b>Adding DNS Record</b></a>
4+
<?php
5+
if (!empty($_SESSION['error_msg'])) {
6+
echo "<a class=\"add-error\"> → ".$_SESSION['error_msg']."</a>";
7+
} else {
8+
if (!empty($_SESSION['ok_msg'])) {
9+
echo "<a class=\"add-ok\"> → ".$_SESSION['ok_msg']."</a>";
10+
}
11+
}
12+
?>
13+
</td>
14+
</tr>
15+
</table>

0 commit comments

Comments
 (0)