|
1 | 1 | <?php |
2 | | -error_reporting(NULL); |
| 2 | + |
| 3 | +error_reporting(null); |
3 | 4 | ob_start(); |
4 | 5 | $TAB = 'PACKAGE'; |
5 | 6 |
|
6 | 7 | // Main include |
7 | 8 | include($_SERVER['DOCUMENT_ROOT']."/inc/main.php"); |
8 | 9 |
|
9 | 10 | // Check user |
10 | | -if ($_SESSION['userContext'] != 'admin') { |
| 11 | +if ($_SESSION['userContext'] != 'admin') { |
11 | 12 | header("Location: /list/user"); |
12 | 13 | exit; |
13 | 14 | } |
|
22 | 23 | } |
23 | 24 |
|
24 | 25 | // 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 | + } |
27 | 32 | 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 | + } |
29 | 36 | } |
30 | 37 | 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 | + |
47 | 82 | // Check if name server entries are blank if DNS server is installed |
48 | 83 | 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 | + } |
51 | 90 | } |
52 | 91 | if (!empty($errors[0])) { |
53 | 92 | foreach ($errors as $i => $error) { |
54 | | - if ( $i == 0 ) { |
| 93 | + if ($i == 0) { |
55 | 94 | $error_msg = $error; |
56 | 95 | } else { |
57 | 96 | $error_msg = $error_msg.", ".$error; |
58 | 97 | } |
59 | 98 | } |
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); |
61 | 100 | } |
62 | 101 |
|
63 | 102 | // Protect input |
|
87 | 126 | $v_ns7 = trim($_POST['v_ns7'], '.'); |
88 | 127 | $v_ns8 = trim($_POST['v_ns8'], '.'); |
89 | 128 | $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 | + } |
96 | 147 | $v_ns = escapeshellarg($v_ns); |
97 | 148 | $v_time = escapeshellarg(date('H:i:s')); |
98 | 149 | $v_date = escapeshellarg(date('Y-m-d')); |
99 | 150 |
|
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 | | - |
108 | 151 | // Create package file |
109 | 152 | if (empty($_SESSION['error_msg'])) { |
110 | 153 | $pkg = "WEB_TEMPLATE=".$v_web_template."\n"; |
|
131 | 174 | $pkg .= "TIME=".$v_time."\n"; |
132 | 175 | $pkg .= "DATE=".$v_date."\n"; |
133 | 176 |
|
134 | | - $fp = fopen($tmpdir."/".$_POST['v_package'].".pkg", 'w'); |
| 177 | + $tmpfile = tempnam('/tmp/', 'hst_'); |
| 178 | + $fp = fopen($tmpfile, 'w'); |
135 | 179 | 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); |
143 | 182 | unset($output); |
144 | | - } |
145 | 183 |
|
146 | | - // Remove tmpdir |
147 | | - exec ('rm -rf '.$tmpdir, $output, $return_var); |
148 | | - unset($output); |
| 184 | + fclose($fp); |
| 185 | + } |
149 | 186 |
|
150 | 187 | // Flush field values on success |
151 | 188 | 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'])); |
153 | 190 | unset($v_package); |
154 | 191 | } |
155 | | - |
156 | 192 | } |
157 | 193 |
|
158 | 194 |
|
159 | 195 | // 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); |
161 | 197 | $web_templates = json_decode(implode('', $output), true); |
162 | 198 | unset($output); |
163 | 199 |
|
164 | 200 | // List web templates for backend |
165 | 201 | 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); |
167 | 203 | $backend_templates = json_decode(implode('', $output), true); |
168 | 204 | unset($output); |
169 | 205 | } |
170 | 206 |
|
171 | 207 | // List web templates for proxy |
172 | 208 | 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); |
174 | 210 | $proxy_templates = json_decode(implode('', $output), true); |
175 | 211 | unset($output); |
176 | 212 | } |
177 | 213 |
|
178 | 214 | // 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); |
180 | 216 | $dns_templates = json_decode(implode('', $output), true); |
181 | 217 | unset($output); |
182 | 218 |
|
183 | 219 | // 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); |
185 | 221 | $shells = json_decode(implode('', $output), true); |
186 | 222 | unset($output); |
187 | 223 |
|
188 | 224 | // 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 | +} |
207 | 279 |
|
208 | 280 | // Render page |
209 | 281 | render_page($user, $TAB, 'add_package'); |
|
0 commit comments