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
231 lines (201 loc) · 8 KB
/
index.php
File metadata and controls
231 lines (201 loc) · 8 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
$TAB = 'PACKAGE';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
// Check user
if ($_SESSION['user'] != 'admin') {
header("Location: /list/user");
exit;
}
// Check package argument
if (empty($_GET['package'])) {
header("Location: /list/package/");
exit;
}
$v_package = $_GET['package'];
// List package
v_exec('v-list-user-package', [$v_package, 'json'], false, $output);
$data = json_decode($output, true);
// Parse package
$v_web_template = $data[$v_package]['WEB_TEMPLATE'];
$v_backend_template = $data[$v_package]['BACKEND_TEMPLATE'];
$v_proxy_template = $data[$v_package]['PROXY_TEMPLATE'];
$v_dns_template = $data[$v_package]['DNS_TEMPLATE'];
$v_web_domains = $data[$v_package]['WEB_DOMAINS'];
$v_web_aliases = $data[$v_package]['WEB_ALIASES'];
$v_dns_domains = $data[$v_package]['DNS_DOMAINS'];
$v_dns_records = $data[$v_package]['DNS_RECORDS'];
$v_mail_domains = $data[$v_package]['MAIL_DOMAINS'];
$v_mail_accounts = $data[$v_package]['MAIL_ACCOUNTS'];
$v_databases = $data[$v_package]['DATABASES'];
$v_cron_jobs = $data[$v_package]['CRON_JOBS'];
$v_disk_quota = $data[$v_package]['DISK_QUOTA'];
$v_bandwidth = $data[$v_package]['BANDWIDTH'];
$v_shell = $data[$v_package]['SHELL'];
$v_ns = $data[$v_package]['NS'];
$nameservers = explode(', ', $v_ns);
$v_ns1 = $nameservers[0];
$v_ns2 = $nameservers[1];
$v_ns3 = $nameservers[2];
$v_ns4 = $nameservers[3];
$v_ns5 = $nameservers[4];
$v_ns6 = $nameservers[5];
$v_ns7 = $nameservers[6];
$v_ns8 = $nameservers[7];
$v_backups = $data[$v_package]['BACKUPS'];
$v_date = $data[$v_package]['DATE'];
$v_time = $data[$v_package]['TIME'];
$v_status = 'active';
// List web templates
v_exec('v-list-web-templates', ['json'], false, $output);
$web_templates = json_decode($output, true);
// List backend templates
if (!empty($_SESSION['WEB_BACKEND'])) {
v_exec('v-list-web-templates-backend', ['json'], false, $output);
$backend_templates = json_decode($output, true);
}
// List proxy templates
if (!empty($_SESSION['PROXY_SYSTEM'])) {
v_exec('v-list-web-templates-proxy', ['json'], false, $output);
$proxy_templates = json_decode($output, true);
}
// List dns templates
v_exec('v-list-dns-templates', ['json'], false, $output);
$dns_templates = json_decode($output, true);
// List shels
v_exec('v-list-sys-shells', ['json'], false, $output);
$shells = json_decode($output, true);
// Check POST request
if (!empty($_POST['save'])) {
// Check token
if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
header('location: /login/');
exit;
}
// Check empty fields
if (empty($_POST['v_package'])) $errors[] = __('package');
if (empty($_POST['v_web_template'])) $errors[] = __('web template');
if (!empty($_SESSION['WEB_BACKEND'])) {
if (empty($_POST['v_backend_template'])) $errors[] = __('backend template');
}
if (!empty($_SESSION['PROXY_SYSTEM'])) {
if (empty($_POST['v_proxy_template'])) $errors[] = __('proxy template');
}
if (empty($_POST['v_dns_template'])) $errors[] = __('dns template');
if (empty($_POST['v_shell'])) $errrors[] = __('shell');
if (!isset($_POST['v_web_domains'])) $errors[] = __('web domains');
if (!isset($_POST['v_web_aliases'])) $errors[] = __('web aliases');
if (!isset($_POST['v_dns_domains'])) $errors[] = __('dns domains');
if (!isset($_POST['v_dns_records'])) $errors[] = __('dns records');
if (!isset($_POST['v_mail_domains'])) $errors[] = __('mail domains');
if (!isset($_POST['v_mail_accounts'])) $errors[] = __('mail accounts');
if (!isset($_POST['v_databases'])) $errors[] = __('databases');
if (!isset($_POST['v_cron_jobs'])) $errors[] = __('cron jobs');
if (!isset($_POST['v_backups'])) $errors[] = __('backups');
if (!isset($_POST['v_disk_quota'])) $errors[] = __('quota');
if (!isset($_POST['v_bandwidth'])) $errors[] = __('bandwidth');
if (empty($_POST['v_ns1'])) $errors[] = __('ns1');
if (empty($_POST['v_ns2'])) $errors[] = __('ns2');
if (!empty($errors[0])) {
foreach ($errors as $i => $error) {
if ( $i == 0 ) {
$error_msg = $error;
} else {
$error_msg = $error_msg.", ".$error;
}
}
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
}
$v_package = $_POST['v_package'];
// Protect input
// TODO: Use array?
$v_web_template = escapeshellarg($_POST['v_web_template']);
if (!empty($_SESSION['WEB_BACKEND'])) {
$v_backend_template = escapeshellarg($_POST['v_backend_template']);
}
if (!empty($_SESSION['PROXY_SYSTEM'])) {
$v_proxy_template = escapeshellarg($_POST['v_proxy_template']);
}
$v_dns_template = escapeshellarg($_POST['v_dns_template']);
$v_shell = escapeshellarg($_POST['v_shell']);
$v_web_domains = escapeshellarg($_POST['v_web_domains']);
$v_web_aliases = escapeshellarg($_POST['v_web_aliases']);
$v_dns_domains = escapeshellarg($_POST['v_dns_domains']);
$v_dns_records = escapeshellarg($_POST['v_dns_records']);
$v_mail_domains = escapeshellarg($_POST['v_mail_domains']);
$v_mail_accounts = escapeshellarg($_POST['v_mail_accounts']);
$v_databases = escapeshellarg($_POST['v_databases']);
$v_cron_jobs = escapeshellarg($_POST['v_cron_jobs']);
$v_backups = escapeshellarg($_POST['v_backups']);
$v_disk_quota = escapeshellarg($_POST['v_disk_quota']);
$v_bandwidth = escapeshellarg($_POST['v_bandwidth']);
$v_ns1 = trim($_POST['v_ns1'], '.');
$v_ns2 = trim($_POST['v_ns2'], '.');
$v_ns3 = trim($_POST['v_ns3'], '.');
$v_ns4 = trim($_POST['v_ns4'], '.');
$v_ns5 = trim($_POST['v_ns5'], '.');
$v_ns6 = trim($_POST['v_ns6'], '.');
$v_ns7 = trim($_POST['v_ns7'], '.');
$v_ns8 = trim($_POST['v_ns8'], '.');
$v_ns = $v_ns1.",".$v_ns2;
if (!empty($v_ns3)) $v_ns .= ",".$v_ns3;
if (!empty($v_ns4)) $v_ns .= ",".$v_ns4;
if (!empty($v_ns5)) $v_ns .= ",".$v_ns5;
if (!empty($v_ns6)) $v_ns .= ",".$v_ns6;
if (!empty($v_ns7)) $v_ns .= ",".$v_ns7;
if (!empty($v_ns8)) $v_ns .= ",".$v_ns8;
$v_ns = escapeshellarg($v_ns);
$v_time = escapeshellarg(date('H:i:s'));
$v_date = escapeshellarg(date('Y-m-d'));
// Create temprorary directory
exec ('mktemp -d', $output, $return_var);
$tmpdir = $output[0];
unset($output);
// Save package file on a fs
$pkg = "WEB_TEMPLATE=".$v_web_template."\n";
$pkg .= "BACKEND_TEMPLATE=".$v_backend_template."\n";
$pkg .= "PROXY_TEMPLATE=".$v_proxy_template."\n";
$pkg .= "DNS_TEMPLATE=".$v_dns_template."\n";
$pkg .= "WEB_DOMAINS=".$v_web_domains."\n";
$pkg .= "WEB_ALIASES=".$v_web_aliases."\n";
$pkg .= "DNS_DOMAINS=".$v_dns_domains."\n";
$pkg .= "DNS_RECORDS=".$v_dns_records."\n";
$pkg .= "MAIL_DOMAINS=".$v_mail_domains."\n";
$pkg .= "MAIL_ACCOUNTS=".$v_mail_accounts."\n";
$pkg .= "DATABASES=".$v_databases."\n";
$pkg .= "CRON_JOBS=".$v_cron_jobs."\n";
$pkg .= "DISK_QUOTA=".$v_disk_quota."\n";
$pkg .= "BANDWIDTH=".$v_bandwidth."\n";
$pkg .= "NS=".$v_ns."\n";
$pkg .= "SHELL=".$v_shell."\n";
$pkg .= "BACKUPS=".$v_backups."\n";
$pkg .= "TIME=".$v_time."\n";
$pkg .= "DATE=".$v_date."\n";
$fp = fopen("$tmpdir/$v_package.pkg", 'w');
fwrite($fp, $pkg);
fclose($fp);
// Save changes
v_exec('v-add-user-package', [$tmpdir, $v_package, 'yes']);
// Remove temporary dir
safe_exec('rm', ['-rf', $tmpdir]);
// Propogate new package
v_exec('v-update-user-package', [$v_package, 'json']);
// Set success message
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = __('Changes has been saved.');
}
}
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Display body
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_package.html');
// Flush session messages
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);
// Footer
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');