Skip to content

Commit b962e03

Browse files
committed
Fix due to external control of filename or path
Also removal of /edit/file/index.php as is not used within Hestia
1 parent 2edde58 commit b962e03

File tree

4 files changed

+163
-215
lines changed

4 files changed

+163
-215
lines changed

bin/v-add-user-package

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: adding user package
3-
# options: PKG_DIR PACKAGE [REWRITE]
3+
# options: tmpfile PACKAGE [REWRITE]
44
# labels:
55
#
66
# The function adds new user package to the system.
@@ -11,7 +11,7 @@
1111
#----------------------------------------------------------#
1212

1313
# Argument definition
14-
pkg_dir=$1
14+
tmpfile=$1
1515
package=$2
1616
rewrite=$3
1717

@@ -31,7 +31,7 @@ is_package_new() {
3131
}
3232

3333
is_package_consistent() {
34-
source $pkg_dir/$package.pkg
34+
source $tmpfile
3535
if [ "$WEB_DOMAINS" != 'unlimited' ]; then
3636
is_int_format_valid $WEB_DOMAINS 'WEB_DOMAINS'
3737
fi
@@ -78,7 +78,12 @@ is_format_valid 'pkg_dir' 'package'
7878
if [ "$rewrite" != 'yes' ]; then
7979
is_package_new
8080
fi
81-
is_package_valid "$pkg_dir"
81+
82+
if [ ! -f "$tmpfile" ]; then
83+
echo "$tmpfile does not exists"
84+
exit $E_NOTEXIST;
85+
fi
86+
8287
is_package_consistent
8388

8489
# Perform verification if read-only mode is enabled
@@ -89,7 +94,7 @@ check_hestia_demo_mode
8994
# Action #
9095
#----------------------------------------------------------#
9196

92-
cp -f $pkg_dir/$package.pkg $HESTIA/data/packages/
97+
cp -f $tmpfile $HESTIA/data/packages/$package.pkg
9398
chmod 644 $HESTIA/data/packages/$package.pkg
9499

95100

install/upgrade/versions/1.4.13.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ if [ "$FIREWALL_SYSTEM" = "iptables" ]; then
4343
$BIN/v-delete-sys-firewall
4444
$BIN/v-add-sys-firewall
4545
fi
46+
47+
# Not used any more
48+
if [ -d "$HESTIA/web/edit/file/" ]; then
49+
rm -fr $HESTIA/web/edit/file/
50+
fi

web/add/package/index.php

Lines changed: 148 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
2-
error_reporting(NULL);
2+
3+
error_reporting(null);
34
ob_start();
45
$TAB = 'PACKAGE';
56

67
// Main include
78
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
89

910
// Check user
10-
if ($_SESSION['userContext'] != 'admin') {
11+
if ($_SESSION['userContext'] != 'admin') {
1112
header("Location: /list/user");
1213
exit;
1314
}
@@ -22,42 +23,80 @@
2223
}
2324

2425
// Check empty fields
25-
if (empty($_POST['v_package'])) $errors[] = _('package');
26-
if (empty($_POST['v_web_template'])) $errors[] = _('web template');
26+
if (empty($_POST['v_package'])) {
27+
$errors[] = _('package');
28+
}
29+
if (empty($_POST['v_web_template'])) {
30+
$errors[] = _('web template');
31+
}
2732
if (!empty($_SESSION['WEB_BACKEND'])) {
28-
if (empty($_POST['v_backend_template'])) $errors[] = _('backend template');
33+
if (empty($_POST['v_backend_template'])) {
34+
$errors[] = _('backend template');
35+
}
2936
}
3037
if (!empty($_SESSION['PROXY_SYSTEM'])) {
31-
if (empty($_POST['v_proxy_template'])) $errors[] = _('proxy template');
32-
}
33-
if (empty($_POST['v_dns_template'])) $errors[] = _('dns template');
34-
if (empty($_POST['v_shell'])) $errrors[] = _('shell');
35-
if (!isset($_POST['v_web_domains'])) $errors[] = _('web domains');
36-
if (!isset($_POST['v_web_aliases'])) $errors[] = _('web aliases');
37-
if (!isset($_POST['v_dns_domains'])) $errors[] = _('dns domains');
38-
if (!isset($_POST['v_dns_records'])) $errors[] = _('dns records');
39-
if (!isset($_POST['v_mail_domains'])) $errors[] = _('mail domains');
40-
if (!isset($_POST['v_mail_accounts'])) $errors[] = _('mail accounts');
41-
if (!isset($_POST['v_databases'])) $errors[] = _('databases');
42-
if (!isset($_POST['v_cron_jobs'])) $errors[] = _('cron jobs');
43-
if (!isset($_POST['v_backups'])) $errors[] = _('backups');
44-
if (!isset($_POST['v_disk_quota'])) $errors[] = _('quota');
45-
if (!isset($_POST['v_bandwidth'])) $errors[] = _('bandwidth');
46-
38+
if (empty($_POST['v_proxy_template'])) {
39+
$errors[] = _('proxy template');
40+
}
41+
}
42+
if (empty($_POST['v_dns_template'])) {
43+
$errors[] = _('dns template');
44+
}
45+
if (empty($_POST['v_shell'])) {
46+
$errrors[] = _('shell');
47+
}
48+
if (!isset($_POST['v_web_domains'])) {
49+
$errors[] = _('web domains');
50+
}
51+
if (!isset($_POST['v_web_aliases'])) {
52+
$errors[] = _('web aliases');
53+
}
54+
if (!isset($_POST['v_dns_domains'])) {
55+
$errors[] = _('dns domains');
56+
}
57+
if (!isset($_POST['v_dns_records'])) {
58+
$errors[] = _('dns records');
59+
}
60+
if (!isset($_POST['v_mail_domains'])) {
61+
$errors[] = _('mail domains');
62+
}
63+
if (!isset($_POST['v_mail_accounts'])) {
64+
$errors[] = _('mail accounts');
65+
}
66+
if (!isset($_POST['v_databases'])) {
67+
$errors[] = _('databases');
68+
}
69+
if (!isset($_POST['v_cron_jobs'])) {
70+
$errors[] = _('cron jobs');
71+
}
72+
if (!isset($_POST['v_backups'])) {
73+
$errors[] = _('backups');
74+
}
75+
if (!isset($_POST['v_disk_quota'])) {
76+
$errors[] = _('quota');
77+
}
78+
if (!isset($_POST['v_bandwidth'])) {
79+
$errors[] = _('bandwidth');
80+
}
81+
4782
// Check if name server entries are blank if DNS server is installed
4883
if ((isset($_SESSION['DNS_SYSTEM'])) && (!empty($_SESSION['DNS_SYSTEM']))) {
49-
if (empty($_POST['v_ns1'])) $errors[] = _('ns1');
50-
if (empty($_POST['v_ns2'])) $errors[] = _('ns2');
84+
if (empty($_POST['v_ns1'])) {
85+
$errors[] = _('ns1');
86+
}
87+
if (empty($_POST['v_ns2'])) {
88+
$errors[] = _('ns2');
89+
}
5190
}
5291
if (!empty($errors[0])) {
5392
foreach ($errors as $i => $error) {
54-
if ( $i == 0 ) {
93+
if ($i == 0) {
5594
$error_msg = $error;
5695
} else {
5796
$error_msg = $error_msg.", ".$error;
5897
}
5998
}
60-
$_SESSION['error_msg'] = sprintf(_('Field "%s" can not be blank.'),$error_msg);
99+
$_SESSION['error_msg'] = sprintf(_('Field "%s" can not be blank.'), $error_msg);
61100
}
62101

63102
// Protect input
@@ -87,24 +126,28 @@
87126
$v_ns7 = trim($_POST['v_ns7'], '.');
88127
$v_ns8 = trim($_POST['v_ns8'], '.');
89128
$v_ns = $v_ns1.",".$v_ns2;
90-
if (!empty($v_ns3)) $v_ns .= ",".$v_ns3;
91-
if (!empty($v_ns4)) $v_ns .= ",".$v_ns4;
92-
if (!empty($v_ns5)) $v_ns .= ",".$v_ns5;
93-
if (!empty($v_ns6)) $v_ns .= ",".$v_ns6;
94-
if (!empty($v_ns7)) $v_ns .= ",".$v_ns7;
95-
if (!empty($v_ns8)) $v_ns .= ",".$v_ns8;
129+
if (!empty($v_ns3)) {
130+
$v_ns .= ",".$v_ns3;
131+
}
132+
if (!empty($v_ns4)) {
133+
$v_ns .= ",".$v_ns4;
134+
}
135+
if (!empty($v_ns5)) {
136+
$v_ns .= ",".$v_ns5;
137+
}
138+
if (!empty($v_ns6)) {
139+
$v_ns .= ",".$v_ns6;
140+
}
141+
if (!empty($v_ns7)) {
142+
$v_ns .= ",".$v_ns7;
143+
}
144+
if (!empty($v_ns8)) {
145+
$v_ns .= ",".$v_ns8;
146+
}
96147
$v_ns = escapeshellarg($v_ns);
97148
$v_time = escapeshellarg(date('H:i:s'));
98149
$v_date = escapeshellarg(date('Y-m-d'));
99150

100-
// Create temporary dir
101-
if (empty($_SESSION['error_msg'])) {
102-
exec ('mktemp -d', $output, $return_var);
103-
$tmpdir = $output[0];
104-
check_return_code($return_var,$output);
105-
unset($output);
106-
}
107-
108151
// Create package file
109152
if (empty($_SESSION['error_msg'])) {
110153
$pkg = "WEB_TEMPLATE=".$v_web_template."\n";
@@ -131,79 +174,108 @@
131174
$pkg .= "TIME=".$v_time."\n";
132175
$pkg .= "DATE=".$v_date."\n";
133176

134-
$fp = fopen($tmpdir."/".$_POST['v_package'].".pkg", 'w');
177+
$tmpfile = tempnam('/tmp/', 'hst_');
178+
$fp = fopen($tmpfile, 'w');
135179
fwrite($fp, $pkg);
136-
fclose($fp);
137-
}
138-
139-
// Add new package
140-
if (empty($_SESSION['error_msg'])) {
141-
exec (HESTIA_CMD."v-add-user-package ".$tmpdir." ".$v_package, $output, $return_var);
142-
check_return_code($return_var,$output);
180+
exec(HESTIA_CMD."v-add-user-package ".$tmpfile." ".$v_package, $output, $return_var);
181+
check_return_code($return_var, $output);
143182
unset($output);
144-
}
145183

146-
// Remove tmpdir
147-
exec ('rm -rf '.$tmpdir, $output, $return_var);
148-
unset($output);
184+
fclose($fp);
185+
}
149186

150187
// Flush field values on success
151188
if (empty($_SESSION['error_msg'])) {
152-
$_SESSION['ok_msg'] = sprintf(_('PACKAGE_CREATED_OK'),htmlentities($_POST['v_package']),htmlentities($_POST['v_package']));
189+
$_SESSION['ok_msg'] = sprintf(_('PACKAGE_CREATED_OK'), htmlentities($_POST['v_package']), htmlentities($_POST['v_package']));
153190
unset($v_package);
154191
}
155-
156192
}
157193

158194

159195
// List web temmplates
160-
exec (HESTIA_CMD."v-list-web-templates json", $output, $return_var);
196+
exec(HESTIA_CMD."v-list-web-templates json", $output, $return_var);
161197
$web_templates = json_decode(implode('', $output), true);
162198
unset($output);
163199

164200
// List web templates for backend
165201
if (!empty($_SESSION['WEB_BACKEND'])) {
166-
exec (HESTIA_CMD."v-list-web-templates-backend json", $output, $return_var);
202+
exec(HESTIA_CMD."v-list-web-templates-backend json", $output, $return_var);
167203
$backend_templates = json_decode(implode('', $output), true);
168204
unset($output);
169205
}
170206

171207
// List web templates for proxy
172208
if (!empty($_SESSION['PROXY_SYSTEM'])) {
173-
exec (HESTIA_CMD."v-list-web-templates-proxy json", $output, $return_var);
209+
exec(HESTIA_CMD."v-list-web-templates-proxy json", $output, $return_var);
174210
$proxy_templates = json_decode(implode('', $output), true);
175211
unset($output);
176212
}
177213

178214
// List DNS templates
179-
exec (HESTIA_CMD."v-list-dns-templates json", $output, $return_var);
215+
exec(HESTIA_CMD."v-list-dns-templates json", $output, $return_var);
180216
$dns_templates = json_decode(implode('', $output), true);
181217
unset($output);
182218

183219
// List system shells
184-
exec (HESTIA_CMD."v-list-sys-shells json", $output, $return_var);
220+
exec(HESTIA_CMD."v-list-sys-shells json", $output, $return_var);
185221
$shells = json_decode(implode('', $output), true);
186222
unset($output);
187223

188224
// Set default values
189-
if (empty($v_web_template)) $v_web_template = 'default';
190-
if (empty($v_backend_template)) $v_backend_template = 'default';
191-
if (empty($v_proxy_template)) $v_proxy_template = 'default';
192-
if (empty($v_dns_template)) $v_dns_template = 'default';
193-
if (empty($v_shell)) $v_shell = 'nologin';
194-
if (empty($v_web_domains)) $v_web_domains = "'1'";
195-
if (empty($v_web_aliases)) $v_web_aliases = "'1'";
196-
if (empty($v_dns_domains)) $v_dns_domains = "'1'";
197-
if (empty($v_dns_records)) $v_dns_records = "'1'";
198-
if (empty($v_mail_domains)) $v_mail_domains = "'1'";
199-
if (empty($v_mail_accounts)) $v_mail_accounts = "'1'";
200-
if (empty($v_databases)) $v_databases = "'1'";
201-
if (empty($v_cron_jobs)) $v_cron_jobs = "'1'";
202-
if (empty($v_backups)) $v_backups = "'1'";
203-
if (empty($v_disk_quota)) $v_disk_quota = "'1000'";
204-
if (empty($v_bandwidth)) $v_bandwidth = "'1000'";
205-
if (empty($v_ns1)) $v_ns1 = 'ns1.example.ltd';
206-
if (empty($v_ns2)) $v_ns2 = 'ns2.example.ltd';
225+
if (empty($v_web_template)) {
226+
$v_web_template = 'default';
227+
}
228+
if (empty($v_backend_template)) {
229+
$v_backend_template = 'default';
230+
}
231+
if (empty($v_proxy_template)) {
232+
$v_proxy_template = 'default';
233+
}
234+
if (empty($v_dns_template)) {
235+
$v_dns_template = 'default';
236+
}
237+
if (empty($v_shell)) {
238+
$v_shell = 'nologin';
239+
}
240+
if (empty($v_web_domains)) {
241+
$v_web_domains = "'1'";
242+
}
243+
if (empty($v_web_aliases)) {
244+
$v_web_aliases = "'1'";
245+
}
246+
if (empty($v_dns_domains)) {
247+
$v_dns_domains = "'1'";
248+
}
249+
if (empty($v_dns_records)) {
250+
$v_dns_records = "'1'";
251+
}
252+
if (empty($v_mail_domains)) {
253+
$v_mail_domains = "'1'";
254+
}
255+
if (empty($v_mail_accounts)) {
256+
$v_mail_accounts = "'1'";
257+
}
258+
if (empty($v_databases)) {
259+
$v_databases = "'1'";
260+
}
261+
if (empty($v_cron_jobs)) {
262+
$v_cron_jobs = "'1'";
263+
}
264+
if (empty($v_backups)) {
265+
$v_backups = "'1'";
266+
}
267+
if (empty($v_disk_quota)) {
268+
$v_disk_quota = "'1000'";
269+
}
270+
if (empty($v_bandwidth)) {
271+
$v_bandwidth = "'1000'";
272+
}
273+
if (empty($v_ns1)) {
274+
$v_ns1 = 'ns1.example.ltd';
275+
}
276+
if (empty($v_ns2)) {
277+
$v_ns2 = 'ns2.example.ltd';
278+
}
207279

208280
// Render page
209281
render_page($user, $TAB, 'add_package');

0 commit comments

Comments
 (0)