|
| 1 | +<?php |
| 2 | +// Init |
| 3 | +error_reporting(NULL); |
| 4 | +ob_start(); |
| 5 | +session_start(); |
| 6 | +$TAB = 'DNS'; |
| 7 | +include($_SERVER['DOCUMENT_ROOT']."/inc/main.php"); |
| 8 | + |
| 9 | +// Header |
| 10 | +include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html'); |
| 11 | + |
| 12 | +// Panel |
| 13 | +top_panel($user,$TAB); |
| 14 | + |
| 15 | +// Are you admin? |
| 16 | +if ($_SESSION['user'] == 'admin') { |
| 17 | + |
| 18 | + // Cancel |
| 19 | + if (!empty($_POST['cancel'])) { |
| 20 | + header("Location: /list/dns/"); |
| 21 | + } |
| 22 | + |
| 23 | + // Action |
| 24 | + if (!empty($_POST['ok'])) { |
| 25 | + // Check input |
| 26 | + if (empty($_POST['v_domain'])) $errors[] = 'domain'; |
| 27 | + if (empty($_POST['v_ip'])) $errors[] = 'ip'; |
| 28 | + if (empty($_POST['v_template'])) $errors[] = 'template'; |
| 29 | + if (empty($_POST['v_exp'])) $errors[] = 'expiriation date'; |
| 30 | + if (empty($_POST['v_soa'])) $errors[] = 'SOA'; |
| 31 | + if (empty($_POST['v_ttl'])) $errors[] = 'TTL'; |
| 32 | + |
| 33 | + // Protect input |
| 34 | + $v_domain = preg_replace("/^www./i", "", $_POST['v_domain']); |
| 35 | + $v_domain = escapeshellarg($v_domain); |
| 36 | + $v_ip = escapeshellarg($_POST['v_ip']); |
| 37 | + $v_template = escapeshellarg($_POST['v_template']); |
| 38 | + $v_exp = escapeshellarg($_POST['v_exp']); |
| 39 | + $v_soa = escapeshellarg($_POST['v_soa']); |
| 40 | + $v_ttl = escapeshellarg($_POST['v_ttl']); |
| 41 | + |
| 42 | + // Check for errors |
| 43 | + if (!empty($errors[0])) { |
| 44 | + foreach ($errors as $i => $error) { |
| 45 | + if ( $i == 0 ) { |
| 46 | + $error_msg = $error; |
| 47 | + } else { |
| 48 | + $error_msg = $error_msg.", ".$error; |
| 49 | + } |
| 50 | + } |
| 51 | + $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank."; |
| 52 | + } else { |
| 53 | + |
| 54 | + // Add DNS |
| 55 | + exec (VESTA_CMD."v_add_dns_domain ".$user." ".$v_domain." ".$v_ip." ".$v_template." ".$v_exp." ".$v_soa." ".$v_ttl, $output, $return_var); |
| 56 | + if ($return_var != 0) { |
| 57 | + $error = implode('<br>', $output); |
| 58 | + if (empty($error)) $error = 'Error: vesta did not return any output.'; |
| 59 | + $_SESSION['error_msg'] = $error; |
| 60 | + } |
| 61 | + unset($output); |
| 62 | + |
| 63 | + if (empty($_SESSION['error_msg'])) { |
| 64 | + $_SESSION['ok_msg'] = "OK: domain <b>".$_POST[v_domain]."</b> has been created successfully."; |
| 65 | + unset($v_domain); |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + exec (VESTA_CMD."v_list_dns_templates json", $output, $return_var); |
| 71 | + $templates = json_decode(implode('', $output), true); |
| 72 | + unset($output); |
| 73 | + |
| 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); |
| 78 | + |
| 79 | + $v_ttl = 14400; |
| 80 | + $v_exp = date('Y-m-d', strtotime('+1 year')); |
| 81 | + |
| 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']); |
| 86 | +} |
| 87 | + |
| 88 | +// Footer |
| 89 | +include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html'); |
0 commit comments