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
103 lines (91 loc) · 3.92 KB
/
index.php
File metadata and controls
103 lines (91 loc) · 3.92 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
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
$TAB = 'USER';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
if (empty($_SESSION['user'])) {
header("Location: /login/");
}
// 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_username'])) $errors[] = 'user';
if (empty($_POST['v_password'])) $errors[] = 'password';
if (empty($_POST['v_package'])) $errrors[] = 'package';
if (empty($_POST['v_email'])) $errors[] = 'email';
if (empty($_POST['v_fname'])) $errors[] = 'first name';
if (empty($_POST['v_lname'])) $errors[] = 'last name';
// Protect input
$v_username = escapeshellarg($_POST['v_username']);
$v_password = escapeshellarg($_POST['v_password']);
$v_package = escapeshellarg($_POST['v_package']);
$v_email = escapeshellarg($_POST['v_email']);
$v_fname = escapeshellarg($_POST['v_fname']);
$v_lname = escapeshellarg($_POST['v_lname']);
if (empty($_POST['v_notify'])) $v_notify = 'off';
// Validate email
if (!filter_var($_POST['v_email'], FILTER_VALIDATE_EMAIL)) {
$_SESSION['error_msg'] = 'Please enter valid email address.';
}
// 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.";
}
if (empty($_SESSION['error_msg'])) {
exec (VESTA_CMD."v-add-user ".$v_username." ".$v_password." ".$v_email." ".$v_package." ".$v_fname." ".$v_lname, $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;
} else {
if (empty($v_notify)) {
$to = $_POST['v_email'];
$subject = "Welcome to Vesta Control Panel";
$hostname = exec('hostname');
$from = "Vesta Control Panel <noreply@".$hostname.">";
if (!empty($_POST['v_fname'])) {
$mailtext = "Hello ".$_POST['v_fname']." ".$_POST['v_lname'].",\n";
} else {
$mailtext = "Hello,\n";
}
$mailtext .= "Your account has been created successfully and is ready to use.\n\n";
$mailtext .= "https://".$_SERVER['HTTP_HOST']."/login/\n";
$mailtext .= "username: ".$_POST['v_username']."\n";
$mailtext .= "password: ".$_POST['v_password']."\n\n";
$mailtext .= "--\nVesta Control Panel\n";
send_email($to, $subject, $mailtext, $from);
}
$_SESSION['ok_msg'] = "OK: user <a href='/edit/user/?user=".$_POST[v_username]."'><b>".$_POST[v_username]."</b></a> has been created successfully.";
unset($v_username);
unset($v_password);
unset($v_email);
unset($v_fname);
unset($v_lname);
}
unset($output);
}
}
exec (VESTA_CMD."v-list-user-packages json", $output, $return_var);
check_error($return_var);
$data = json_decode(implode('', $output), true);
unset($output);
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_user.html');
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
}
// Footer
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');