forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
138 lines (120 loc) · 4.96 KB
/
index.php
File metadata and controls
138 lines (120 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?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') {
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);
}
}
}
// DNS Record
if (!empty($_POST['ok_rec'])) {
// Check input
if (empty($_POST['v_domain'])) $errors[] = 'domain';
if (empty($_POST['v_rec'])) $errors[] = 'record';
if (empty($_POST['v_type'])) $errors[] = 'type';
if (empty($_POST['v_val'])) $errors[] = 'value';
// Protect input
$v_domain = escapeshellarg($_POST['v_domain']);
$v_rec = escapeshellarg($_POST['v_rec']);
$v_type = escapeshellarg($_POST['v_type']);
$v_val = escapeshellarg($_POST['v_val']);
$v_priority = escapeshellarg($_POST['v_priority']);
// 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 Record
exec (VESTA_CMD."v_add_dns_domain_record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority, $output, $return_var);
$v_type = $_POST['v_type'];
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: record <b>".$_POST[v_rec]."</b> has been created successfully.";
unset($v_domain);
unset($v_rec);
unset($v_val);
unset($v_priority);
}
}
}
if ((empty($_GET['domain'])) && (empty($_POST['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']);
} else {
$v_domain = $_GET['domain'];
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_dns_rec.html');
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns_rec.html');
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
}
}
// Footer
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');