Skip to content

Commit 80b38fb

Browse files
authored
Fix error in add package if field is missing (hestiacp#3883)
1 parent 8d6b2a9 commit 80b38fb

File tree

1 file changed

+96
-96
lines changed

1 file changed

+96
-96
lines changed

web/add/package/index.php

Lines changed: 96 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,35 @@
1717
if (!empty($_POST["ok"])) {
1818
// Check token
1919
verify_csrf($_POST);
20-
20+
$errors = [];
2121
// Check empty fields
22-
if (empty($_POST["v_package"])) {
22+
if (!isset($_POST["v_package"])) {
2323
$errors[] = _("Package");
2424
}
25-
if (empty($_POST["v_web_template"])) {
25+
if (!isset($_POST["v_web_template"])) {
2626
$errors[] = _("Web Template");
2727
}
2828
if (!empty($_SESSION["WEB_BACKEND"])) {
29-
if (empty($_POST["v_backend_template"])) {
29+
if (!isset($_POST["v_backend_template"])) {
3030
$errors[] = _("Backend Template");
3131
}
3232
} else {
3333
# When modphp is enabled
3434
$_POST["v_backend_template"] = "";
3535
}
3636
if (!empty($_SESSION["PROXY_SYSTEM"])) {
37-
if (empty($_POST["v_proxy_template"])) {
37+
if (!isset($_POST["v_proxy_template"])) {
3838
$errors[] = _("Proxy Template");
3939
}
4040
} else {
4141
# when nginx only is enabled
4242
$_POST["v_proxy_template"] = "default";
4343
}
44-
if (empty($_POST["v_dns_template"])) {
44+
if (!isset($_POST["v_dns_template"])) {
4545
$errors[] = _("DNS Template");
4646
}
47-
if (empty($_POST["v_shell"])) {
48-
$errrors[] = _("Shell");
47+
if (!isset($_POST["v_shell"])) {
48+
$errors[] = _("Shell");
4949
}
5050
if (!isset($_POST["v_web_domains"])) {
5151
$errors[] = _("Web Domains");
@@ -101,99 +101,99 @@
101101
}
102102
}
103103
$_SESSION["error_msg"] = sprintf(_('Field "%s" can not be blank.'), $error_msg);
104-
}
105-
106-
// Protect input
107-
$v_package = quoteshellarg($_POST["v_package"]);
108-
$v_web_template = quoteshellarg($_POST["v_web_template"]);
109-
$v_backend_template = quoteshellarg($_POST["v_backend_template"]);
110-
$v_proxy_template = quoteshellarg($_POST["v_proxy_template"]);
111-
$v_dns_template = quoteshellarg($_POST["v_dns_template"]);
112-
$v_shell = quoteshellarg($_POST["v_shell"]);
113-
$v_web_domains = quoteshellarg($_POST["v_web_domains"]);
114-
$v_web_aliases = quoteshellarg($_POST["v_web_aliases"]);
115-
$v_dns_domains = quoteshellarg($_POST["v_dns_domains"]);
116-
$v_dns_records = quoteshellarg($_POST["v_dns_records"]);
117-
$v_mail_domains = quoteshellarg($_POST["v_mail_domains"]);
118-
$v_mail_accounts = quoteshellarg($_POST["v_mail_accounts"]);
119-
$v_databases = quoteshellarg($_POST["v_databases"]);
120-
$v_cron_jobs = quoteshellarg($_POST["v_cron_jobs"]);
121-
$v_backups = quoteshellarg($_POST["v_backups"]);
122-
$v_disk_quota = quoteshellarg($_POST["v_disk_quota"]);
123-
$v_bandwidth = quoteshellarg($_POST["v_bandwidth"]);
124-
$v_ratelimit = quoteshellarg($_POST["v_ratelimit"]);
125-
$v_ns1 = !empty($_POST["v_ns1"]) ? trim($_POST["v_ns1"], ".") : "";
126-
$v_ns2 = !empty($_POST["v_ns2"]) ? trim($_POST["v_ns2"], ".") : "";
127-
$v_ns3 = !empty($_POST["v_ns3"]) ? trim($_POST["v_ns3"], ".") : "";
128-
$v_ns4 = !empty($_POST["v_ns4"]) ? trim($_POST["v_ns4"], ".") : "";
129-
$v_ns5 = !empty($_POST["v_ns5"]) ? trim($_POST["v_ns5"], ".") : "";
130-
$v_ns6 = !empty($_POST["v_ns6"]) ? trim($_POST["v_ns6"], ".") : "";
131-
$v_ns7 = !empty($_POST["v_ns7"]) ? trim($_POST["v_ns7"], ".") : "";
132-
$v_ns8 = !empty($_POST["v_ns8"]) ? trim($_POST["v_ns8"], ".") : "";
133-
134-
$v_ns = $v_ns1 . "," . $v_ns2;
135-
if (!empty($v_ns3)) {
136-
$v_ns .= "," . $v_ns3;
137-
}
138-
if (!empty($v_ns4)) {
139-
$v_ns .= "," . $v_ns4;
140-
}
141-
if (!empty($v_ns5)) {
142-
$v_ns .= "," . $v_ns5;
143-
}
144-
if (!empty($v_ns6)) {
145-
$v_ns .= "," . $v_ns6;
146-
}
147-
if (!empty($v_ns7)) {
148-
$v_ns .= "," . $v_ns7;
149-
}
150-
if (!empty($v_ns8)) {
151-
$v_ns .= "," . $v_ns8;
152-
}
153-
$v_ns = quoteshellarg($v_ns);
154-
$v_time = quoteshellarg(date("H:i:s"));
155-
$v_date = quoteshellarg(date("Y-m-d"));
104+
} else {
105+
// Protect input
106+
$v_package = quoteshellarg($_POST["v_package"]);
107+
$v_web_template = quoteshellarg($_POST["v_web_template"]);
108+
$v_backend_template = quoteshellarg($_POST["v_backend_template"]);
109+
$v_proxy_template = quoteshellarg($_POST["v_proxy_template"]);
110+
$v_dns_template = quoteshellarg($_POST["v_dns_template"]);
111+
$v_shell = quoteshellarg($_POST["v_shell"]);
112+
$v_web_domains = quoteshellarg($_POST["v_web_domains"]);
113+
$v_web_aliases = quoteshellarg($_POST["v_web_aliases"]);
114+
$v_dns_domains = quoteshellarg($_POST["v_dns_domains"]);
115+
$v_dns_records = quoteshellarg($_POST["v_dns_records"]);
116+
$v_mail_domains = quoteshellarg($_POST["v_mail_domains"]);
117+
$v_mail_accounts = quoteshellarg($_POST["v_mail_accounts"]);
118+
$v_databases = quoteshellarg($_POST["v_databases"]);
119+
$v_cron_jobs = quoteshellarg($_POST["v_cron_jobs"]);
120+
$v_backups = quoteshellarg($_POST["v_backups"]);
121+
$v_disk_quota = quoteshellarg($_POST["v_disk_quota"]);
122+
$v_bandwidth = quoteshellarg($_POST["v_bandwidth"]);
123+
$v_ratelimit = quoteshellarg($_POST["v_ratelimit"]);
124+
$v_ns1 = !empty($_POST["v_ns1"]) ? trim($_POST["v_ns1"], ".") : "";
125+
$v_ns2 = !empty($_POST["v_ns2"]) ? trim($_POST["v_ns2"], ".") : "";
126+
$v_ns3 = !empty($_POST["v_ns3"]) ? trim($_POST["v_ns3"], ".") : "";
127+
$v_ns4 = !empty($_POST["v_ns4"]) ? trim($_POST["v_ns4"], ".") : "";
128+
$v_ns5 = !empty($_POST["v_ns5"]) ? trim($_POST["v_ns5"], ".") : "";
129+
$v_ns6 = !empty($_POST["v_ns6"]) ? trim($_POST["v_ns6"], ".") : "";
130+
$v_ns7 = !empty($_POST["v_ns7"]) ? trim($_POST["v_ns7"], ".") : "";
131+
$v_ns8 = !empty($_POST["v_ns8"]) ? trim($_POST["v_ns8"], ".") : "";
156132

157-
// Create package file
158-
if (empty($_SESSION["error_msg"])) {
159-
$pkg = "WEB_TEMPLATE=" . $v_web_template . "\n";
160-
if (!empty($_SESSION["WEB_BACKEND"])) {
161-
$pkg .= "BACKEND_TEMPLATE=" . $v_backend_template . "\n";
133+
$v_ns = $v_ns1 . "," . $v_ns2;
134+
if (!empty($v_ns3)) {
135+
$v_ns .= "," . $v_ns3;
136+
}
137+
if (!empty($v_ns4)) {
138+
$v_ns .= "," . $v_ns4;
139+
}
140+
if (!empty($v_ns5)) {
141+
$v_ns .= "," . $v_ns5;
142+
}
143+
if (!empty($v_ns6)) {
144+
$v_ns .= "," . $v_ns6;
145+
}
146+
if (!empty($v_ns7)) {
147+
$v_ns .= "," . $v_ns7;
162148
}
163-
if (!empty($_SESSION["PROXY_SYSTEM"])) {
164-
$pkg .= "PROXY_TEMPLATE=" . $v_proxy_template . "\n";
149+
if (!empty($v_ns8)) {
150+
$v_ns .= "," . $v_ns8;
165151
}
166-
$pkg .= "DNS_TEMPLATE=" . $v_dns_template . "\n";
167-
$pkg .= "WEB_DOMAINS=" . $v_web_domains . "\n";
168-
$pkg .= "WEB_ALIASES=" . $v_web_aliases . "\n";
169-
$pkg .= "DNS_DOMAINS=" . $v_dns_domains . "\n";
170-
$pkg .= "DNS_RECORDS=" . $v_dns_records . "\n";
171-
$pkg .= "MAIL_DOMAINS=" . $v_mail_domains . "\n";
172-
$pkg .= "MAIL_ACCOUNTS=" . $v_mail_accounts . "\n";
173-
$pkg .= "DATABASES=" . $v_databases . "\n";
174-
$pkg .= "CRON_JOBS=" . $v_cron_jobs . "\n";
175-
$pkg .= "DISK_QUOTA=" . $v_disk_quota . "\n";
176-
$pkg .= "BANDWIDTH=" . $v_bandwidth . "\n";
177-
$pkg .= "RATE_LIMIT=" . $v_ratelimit . "\n";
178-
$pkg .= "NS=" . $v_ns . "\n";
179-
$pkg .= "SHELL=" . $v_shell . "\n";
180-
$pkg .= "BACKUPS=" . $v_backups . "\n";
181-
$pkg .= "TIME=" . $v_time . "\n";
182-
$pkg .= "DATE=" . $v_date . "\n";
152+
$v_ns = quoteshellarg($v_ns);
153+
$v_time = quoteshellarg(date("H:i:s"));
154+
$v_date = quoteshellarg(date("Y-m-d"));
183155

184-
$tmpfile = tempnam("/tmp/", "hst_");
185-
$fp = fopen($tmpfile, "w");
186-
fwrite($fp, $pkg);
187-
exec(
188-
HESTIA_CMD . "v-add-user-package " . $tmpfile . " " . $v_package,
189-
$output,
190-
$return_var,
191-
);
192-
check_return_code($return_var, $output);
193-
unset($output);
156+
// Create package file
157+
if (empty($_SESSION["error_msg"])) {
158+
$pkg = "WEB_TEMPLATE=" . $v_web_template . "\n";
159+
if (!empty($_SESSION["WEB_BACKEND"])) {
160+
$pkg .= "BACKEND_TEMPLATE=" . $v_backend_template . "\n";
161+
}
162+
if (!empty($_SESSION["PROXY_SYSTEM"])) {
163+
$pkg .= "PROXY_TEMPLATE=" . $v_proxy_template . "\n";
164+
}
165+
$pkg .= "DNS_TEMPLATE=" . $v_dns_template . "\n";
166+
$pkg .= "WEB_DOMAINS=" . $v_web_domains . "\n";
167+
$pkg .= "WEB_ALIASES=" . $v_web_aliases . "\n";
168+
$pkg .= "DNS_DOMAINS=" . $v_dns_domains . "\n";
169+
$pkg .= "DNS_RECORDS=" . $v_dns_records . "\n";
170+
$pkg .= "MAIL_DOMAINS=" . $v_mail_domains . "\n";
171+
$pkg .= "MAIL_ACCOUNTS=" . $v_mail_accounts . "\n";
172+
$pkg .= "DATABASES=" . $v_databases . "\n";
173+
$pkg .= "CRON_JOBS=" . $v_cron_jobs . "\n";
174+
$pkg .= "DISK_QUOTA=" . $v_disk_quota . "\n";
175+
$pkg .= "BANDWIDTH=" . $v_bandwidth . "\n";
176+
$pkg .= "RATE_LIMIT=" . $v_ratelimit . "\n";
177+
$pkg .= "NS=" . $v_ns . "\n";
178+
$pkg .= "SHELL=" . $v_shell . "\n";
179+
$pkg .= "BACKUPS=" . $v_backups . "\n";
180+
$pkg .= "TIME=" . $v_time . "\n";
181+
$pkg .= "DATE=" . $v_date . "\n";
194182

195-
fclose($fp);
196-
unlink($tmpfile);
183+
$tmpfile = tempnam("/tmp/", "hst_");
184+
$fp = fopen($tmpfile, "w");
185+
fwrite($fp, $pkg);
186+
exec(
187+
HESTIA_CMD . "v-add-user-package " . $tmpfile . " " . $v_package,
188+
$output,
189+
$return_var,
190+
);
191+
check_return_code($return_var, $output);
192+
unset($output);
193+
194+
fclose($fp);
195+
unlink($tmpfile);
196+
}
197197
}
198198

199199
// Flush field values on success

0 commit comments

Comments
 (0)