dns add domain page

This commit is contained in:
Serghey Rodin 2012-06-12 12:55:54 +03:00
commit 361f0ec7f3
5 changed files with 169 additions and 2 deletions

89
web/add/dns/index.php Normal file
View file

@ -0,0 +1,89 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
$TAB = 'DNS';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Are you admin?
if ($_SESSION['user'] == 'admin') {
// Cancel
if (!empty($_POST['cancel'])) {
header("Location: /list/dns/");
}
// Action
if (!empty($_POST['ok'])) {
// Check input
if (empty($_POST['v_domain'])) $errors[] = 'domain';
if (empty($_POST['v_ip'])) $errors[] = 'ip';
if (empty($_POST['v_template'])) $errors[] = 'template';
if (empty($_POST['v_exp'])) $errors[] = 'expiriation date';
if (empty($_POST['v_soa'])) $errors[] = 'SOA';
if (empty($_POST['v_ttl'])) $errors[] = 'TTL';
// Protect input
$v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
$v_domain = escapeshellarg($v_domain);
$v_ip = escapeshellarg($_POST['v_ip']);
$v_template = escapeshellarg($_POST['v_template']);
$v_exp = escapeshellarg($_POST['v_exp']);
$v_soa = escapeshellarg($_POST['v_soa']);
$v_ttl = escapeshellarg($_POST['v_ttl']);
// 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
exec (VESTA_CMD."v_add_dns_domain ".$user." ".$v_domain." ".$v_ip." ".$v_template." ".$v_exp." ".$v_soa." ".$v_ttl, $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);
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = "OK: domain <b>".$_POST[v_domain]."</b> has been created successfully.";
unset($v_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']);
}
// Footer
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');

View file

@ -17,6 +17,7 @@ if ($_SESSION['user'] == 'admin') {
exec (VESTA_CMD."v_list_users json", $output, $return_var);
check_error($return_var);
$data = json_decode(implode('', $output), true);
$data = array_reverse($data);
unset($output);
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_user.html');

View file

@ -0,0 +1,62 @@
<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 if (!empty($v_domain)) echo "value=".$v_domain; ?> ></td></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">IP address</td></tr>
<tr><td><input type="text" size="20" class="add-input" name="v_ip" <?php if (!empty($v_ip)) echo "value=".$v_ip; ?>></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Template</td></tr>
<tr><td><select class="add-list" name="v_template">
<?php
foreach ($templates as $key => $value) {
echo "\t\t\t\t<option value=\"".$key."\"";
if ((!empty($v_template)) && ( $key == $_POST['v_template'])){
echo ' selected' ;
}
echo ">".$key."</option>\n";
}
?>
</select></td></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;"><a href="javascript:elementHideShow('advtable');" class="add-advanced">Advanced Options ⇢</a></td></tr>
<tr><td class="add-text" style="padding: 9px 0 0 0px;">
<table style="display:<?php if (empty($v_adv)) echo 'none';?> ;" id="advtable">
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Domain Expiriation</td></tr>
<tr><td><input type="text" size="20" class="add-input" name="v_exp" <?php if (!empty($v_exp)) echo "value=".$v_exp; ?>></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">SOA</td></tr>
<tr><td><input type="text" size="20" class="add-input" name="v_soa" <?php if (!empty($v_soa)) echo "value=".$v_soa; ?>></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">TTL</td></tr>
<tr><td><input type="text" size="20" class="add-input" name="v_ttl" <?php if (!empty($v_ttl)) echo "value=".$v_ttl; ?>></tr>
</table>
</td></tr>
<tr><td style="padding: 24px 0 0 0;">
<input type="submit" name="ok" value="OK" class="add-button"></form>
<input type="button" class="add-button" value="Cancel" onClick="location.href='/list/dns/'">
</td></tr>
</table>
</td>
</tr>
</table>

View file

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

View file

@ -393,7 +393,7 @@ if (!empty($_SESSION['look'])) {
.aliases {
font-family: Arial;
font-size: 12pt;
color: #999999;
color: #99a7af;
padding: 0 0 0 8px;
}
@ -407,7 +407,7 @@ if (!empty($_SESSION['look'])) {
.fullname {
font-family: Arial;
font-size: 14pt;
color: #999999;
color: #99a7af;
padding: 0 0 0 8px;
}