|
35 | 35 | $v_cgi = $data[$v_domain]['CGI']; |
36 | 36 | $v_elog = $data[$v_domain]['ELOG']; |
37 | 37 | $v_ssl = $data[$v_domain]['SSL']; |
38 | | -$v_letsencrypt = $data[$v_domain]['LETSENCRYPT']; |
39 | | -if ( $v_ssl == 'yes' && ($v_letsencrypt == 'no' || empty($v_letsencrypt))) { |
| 38 | +if (!empty($v_ssl)) { |
40 | 39 | exec (VESTA_CMD."v-list-web-domain-ssl ".$user." '".$v_domain."' json", $output, $return_var); |
41 | 40 | $ssl_str = json_decode(implode('', $output), true); |
42 | 41 | unset($output); |
|
51 | 50 | $v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY']; |
52 | 51 | $v_ssl_issuer = $ssl_str[$v_domain]['ISSUER']; |
53 | 52 | } |
| 53 | +$v_letsencrypt = $data[$v_domain]['LETSENCRYPT']; |
| 54 | +if (empty($v_letsencrypt)) $v_letsencrypt = 'no'; |
54 | 55 | $v_ssl_home = $data[$v_domain]['SSL_HOME']; |
55 | 56 | $v_backend_template = $data[$v_domain]['BACKEND']; |
56 | 57 | $v_proxy = $data[$v_domain]['PROXY']; |
|
214 | 215 |
|
215 | 216 | // Change backend template |
216 | 217 | if ((!empty($_SESSION['WEB_BACKEND'])) && ( $v_backend_template != $_POST['v_backend_template']) && ( $_SESSION['user'] == 'admin') && (empty($_SESSION['error_msg']))) { |
217 | | - $v_backend_template = $_POST['v_backend_template']; |
218 | | - exec (VESTA_CMD."v-change-web-domain-backend-tpl ".$v_username." ".$v_domain." ".escapeshellarg($v_backend_template), $output, $return_var); |
219 | | - check_return_code($return_var,$output); |
220 | | - unset($output); |
| 218 | + $v_backend_template = $_POST['v_backend_template']; |
| 219 | + exec (VESTA_CMD."v-change-web-domain-backend-tpl ".$v_username." ".$v_domain." ".escapeshellarg($v_backend_template), $output, $return_var); |
| 220 | + check_return_code($return_var,$output); |
| 221 | + unset($output); |
221 | 222 | } |
222 | 223 |
|
223 | 224 | // Delete proxy support |
|
264 | 265 | $restart_proxy = 'yes'; |
265 | 266 | } |
266 | 267 |
|
267 | | - // Disable Lets Encrypt support |
268 | | - |
269 | | - if (( $v_letsencrypt == 'yes' ) && (empty($_POST['v_letsencrypt'])) && (!empty($_POST['v_letsencrypt'])) && (empty($_SESSION['error_msg']))) { |
270 | | - exec (VESTA_CMD."v-delete-letsencrypt-domain ".$user." ".$v_domain." '' 'no'", $output, $return_var); |
| 268 | + // Delete Lets Encrypt support |
| 269 | + if (( $v_letsencrypt == 'yes' ) && (empty($_POST['v_letsencrypt'])) && (empty($_SESSION['error_msg']))) { |
| 270 | + exec (VESTA_CMD."v-delete-letsencrypt-domain ".$user." ".$v_domain." 'no'", $output, $return_var); |
271 | 271 | check_return_code($return_var,$output); |
272 | 272 | unset($output); |
273 | 273 | $v_letsencrypt = 'no'; |
| 274 | + $v_letsencrypt_deleted = 'yes'; |
| 275 | + $v_ssl = 'no'; |
274 | 276 | $restart_web = 'yes'; |
275 | 277 | $restart_proxy = 'yes'; |
276 | | - } |
277 | | - else{ |
278 | | - // Delete SSL certificate |
279 | | - if (( $v_ssl == 'yes' ) && (empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
280 | | - exec (VESTA_CMD."v-delete-web-domain-ssl ".$v_username." ".$v_domain." 'no'", $output, $return_var); |
281 | | - check_return_code($return_var,$output); |
282 | | - unset($output); |
283 | | - $v_ssl = 'no'; |
284 | | - $restart_web = 'yes'; |
285 | | - $restart_proxy = 'yes'; |
286 | | - } |
287 | | - } |
| 278 | + } |
| 279 | + |
| 280 | + // Delete SSL certificate |
| 281 | + if (( $v_ssl == 'yes' ) && (empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
| 282 | + exec (VESTA_CMD."v-delete-web-domain-ssl ".$v_username." ".$v_domain." 'no'", $output, $return_var); |
| 283 | + check_return_code($return_var,$output); |
| 284 | + unset($output); |
| 285 | + $v_ssl = 'no'; |
| 286 | + $restart_web = 'yes'; |
| 287 | + $restart_proxy = 'yes'; |
| 288 | + } |
288 | 289 |
|
289 | | - // Enable Lets Encrypt support |
290 | | - if (( $v_letsencrypt == 'no' || empty( $v_letsencrypt)) && (!empty($_POST['v_letsencrypt'])) && empty($_SESSION['error_msg'])) { |
291 | | - exec (VESTA_CMD."v-list-web-domain ".$user." ".$v_domain." json", $output, $return_var); |
292 | | - $data = json_decode(implode('', $output), true); |
293 | | - exec (VESTA_CMD."v-add-letsencrypt-domain ".$user." ".$v_domain." '' 'no'", $output, $return_var); |
| 290 | + // Add Lets Encrypt support |
| 291 | + if ((!empty($_POST['v_ssl'])) && ( $v_letsencrypt == 'no' ) && (!empty($_POST['v_letsencrypt'])) && empty($_SESSION['error_msg'])) { |
| 292 | + $l_aliases = str_replace("\n", ',', $v_aliases); |
| 293 | + exec (VESTA_CMD."v-add-letsencrypt-domain ".$user." ".$v_domain." '".$l_aliases."' 'no'", $output, $return_var); |
294 | 294 | check_return_code($return_var,$output); |
295 | 295 | unset($output); |
296 | 296 | $v_letsencrypt = 'yes'; |
| 297 | + $v_ssl = 'yes'; |
297 | 298 | $restart_web = 'yes'; |
298 | 299 | $restart_proxy = 'yes'; |
299 | 300 | } |
300 | | - else{ |
301 | | - // Change SSL certificate |
302 | | - if (($v_ssl == 'yes') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
303 | | - if (( $v_ssl_crt != str_replace("\r\n", "\n", $_POST['v_ssl_crt'])) || ( $v_ssl_key != str_replace("\r\n", "\n", $_POST['v_ssl_key'])) || ( $v_ssl_ca != str_replace("\r\n", "\n", $_POST['v_ssl_ca']))) { |
304 | | - exec ('mktemp -d', $mktemp_output, $return_var); |
305 | | - $tmpdir = $mktemp_output[0]; |
306 | | - |
307 | | - // Certificate |
308 | | - if (!empty($_POST['v_ssl_crt'])) { |
309 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); |
310 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); |
311 | | - fwrite($fp, "\n"); |
312 | | - fclose($fp); |
313 | | - } |
314 | | - |
315 | | - // Key |
316 | | - if (!empty($_POST['v_ssl_key'])) { |
317 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); |
318 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); |
319 | | - fwrite($fp, "\n"); |
320 | | - fclose($fp); |
321 | | - } |
322 | | - |
323 | | - // CA |
324 | | - if (!empty($_POST['v_ssl_ca'])) { |
325 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); |
326 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); |
327 | | - fwrite($fp, "\n"); |
328 | | - fclose($fp); |
329 | | - } |
330 | 301 |
|
331 | | - exec (VESTA_CMD."v-change-web-domain-sslcert ".$user." ".$v_domain." ".$tmpdir." 'no'", $output, $return_var); |
| 302 | + // Add SSL certificate |
| 303 | + if (( $v_ssl == 'no' ) && (!empty($_POST['v_ssl'])) && (empty($v_letsencrypt_deleted)) && (empty($_SESSION['error_msg']))) { |
| 304 | + if (empty($_POST['v_ssl_crt'])) $errors[] = 'ssl certificate'; |
| 305 | + if (empty($_POST['v_ssl_key'])) $errors[] = 'ssl key'; |
| 306 | + if (empty($_POST['v_ssl_home'])) $errors[] = 'ssl home'; |
| 307 | + $v_ssl_home = escapeshellarg($_POST['v_ssl_home']); |
| 308 | + if (!empty($errors[0])) { |
| 309 | + foreach ($errors as $i => $error) { |
| 310 | + if ( $i == 0 ) { |
| 311 | + $error_msg = $error; |
| 312 | + } else { |
| 313 | + $error_msg = $error_msg.", ".$error; |
| 314 | + } |
| 315 | + } |
| 316 | + $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg); |
| 317 | + } else { |
| 318 | + exec ('mktemp -d', $mktemp_output, $return_var); |
| 319 | + $tmpdir = $mktemp_output[0]; |
| 320 | + |
| 321 | + // Certificate |
| 322 | + if (!empty($_POST['v_ssl_crt'])) { |
| 323 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); |
| 324 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); |
| 325 | + fclose($fp); |
| 326 | + } |
| 327 | + |
| 328 | + // Key |
| 329 | + if (!empty($_POST['v_ssl_key'])) { |
| 330 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); |
| 331 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); |
| 332 | + fclose($fp); |
| 333 | + } |
| 334 | + |
| 335 | + // CA |
| 336 | + if (!empty($_POST['v_ssl_ca'])) { |
| 337 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); |
| 338 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); |
| 339 | + fclose($fp); |
| 340 | + } |
| 341 | + exec (VESTA_CMD."v-add-web-domain-ssl ".$user." ".$v_domain." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var); |
332 | 342 | check_return_code($return_var,$output); |
333 | 343 | unset($output); |
| 344 | + $v_ssl = 'yes'; |
334 | 345 | $restart_web = 'yes'; |
335 | 346 | $restart_proxy = 'yes'; |
336 | 347 |
|
|
348 | 359 | $v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY']; |
349 | 360 | $v_ssl_issuer = $ssl_str[$v_domain]['ISSUER']; |
350 | 361 |
|
351 | | - // Cleanup certificate tempfiles |
352 | | - if (!empty($_POST['v_ssl_crt'])) { |
353 | | - unlink($tmpdir."/".$_POST['v_domain'].".crt"); |
354 | | - } |
355 | | - |
356 | | - if (!empty($_POST['v_ssl_key'])) { |
357 | | - unlink($tmpdir."/".$_POST['v_domain'].".key"); |
358 | | - } |
359 | | - |
360 | | - if (!empty($_POST['v_ssl_ca'])) { |
361 | | - unlink($tmpdir."/".$_POST['v_domain'].".ca"); |
362 | | - } |
363 | | - |
364 | | - rmdir($tmpdir); |
365 | | - } |
366 | | - } |
367 | | - |
368 | | - // Add SSL certificate |
369 | | - if (( $v_ssl == 'no') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
370 | | - if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_crt']))) $errors[] = 'ssl certificate'; |
371 | | - if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_key']))) $errors[] = 'ssl key'; |
372 | | - if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_home']))) $errors[] = 'ssl home'; |
373 | | - $v_ssl_home = escapeshellarg($_POST['v_ssl_home']); |
374 | | - if (!empty($errors[0])) { |
375 | | - foreach ($errors as $i => $error) { |
376 | | - if ( $i == 0 ) { |
377 | | - $error_msg = $error; |
378 | | - } else { |
379 | | - $error_msg = $error_msg.", ".$error; |
380 | | - } |
381 | | - } |
382 | | - $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg); |
383 | | - } else { |
384 | | - exec ('mktemp -d', $mktemp_output, $return_var); |
385 | | - $tmpdir = $mktemp_output[0]; |
386 | | - |
387 | | - // Certificate |
388 | | - if (!empty($_POST['v_ssl_crt'])) { |
389 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); |
390 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); |
391 | | - fclose($fp); |
392 | | - } |
393 | | - |
394 | | - // Key |
395 | | - if (!empty($_POST['v_ssl_key'])) { |
396 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); |
397 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); |
398 | | - fclose($fp); |
399 | | - } |
| 362 | + // Cleanup certificate tempfiles |
| 363 | + if (!empty($_POST['v_ssl_crt'])) unlink($tmpdir."/".$_POST['v_domain'].".crt"); |
| 364 | + if (!empty($_POST['v_ssl_key'])) unlink($tmpdir."/".$_POST['v_domain'].".key"); |
| 365 | + if (!empty($_POST['v_ssl_ca'])) unlink($tmpdir."/".$_POST['v_domain'].".ca"); |
| 366 | + rmdir($tmpdir); |
| 367 | + } |
| 368 | + } |
| 369 | + |
| 370 | + // Change SSL certificate |
| 371 | + if (( $v_letsencrypt == 'no' ) && ( $v_ssl == 'yes' ) && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
| 372 | + if (( $v_ssl_crt != str_replace("\r\n", "\n", $_POST['v_ssl_crt'])) || ( $v_ssl_key != str_replace("\r\n", "\n", $_POST['v_ssl_key'])) || ( $v_ssl_ca != str_replace("\r\n", "\n", $_POST['v_ssl_ca']))) { |
| 373 | + exec ('mktemp -d', $mktemp_output, $return_var); |
| 374 | + $tmpdir = $mktemp_output[0]; |
| 375 | + |
| 376 | + // Certificate |
| 377 | + if (!empty($_POST['v_ssl_crt'])) { |
| 378 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); |
| 379 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); |
| 380 | + fwrite($fp, "\n"); |
| 381 | + fclose($fp); |
| 382 | + } |
| 383 | + |
| 384 | + // Key |
| 385 | + if (!empty($_POST['v_ssl_key'])) { |
| 386 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); |
| 387 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); |
| 388 | + fwrite($fp, "\n"); |
| 389 | + fclose($fp); |
| 390 | + } |
400 | 391 |
|
401 | 392 | // CA |
402 | 393 | if (!empty($_POST['v_ssl_ca'])) { |
403 | 394 | $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); |
404 | 395 | fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); |
| 396 | + fwrite($fp, "\n"); |
405 | 397 | fclose($fp); |
406 | 398 | } |
407 | | - exec (VESTA_CMD."v-add-web-domain-ssl ".$user." ".$v_domain." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var); |
| 399 | + |
| 400 | + exec (VESTA_CMD."v-change-web-domain-sslcert ".$user." ".$v_domain." ".$tmpdir." 'no'", $output, $return_var); |
408 | 401 | check_return_code($return_var,$output); |
409 | 402 | unset($output); |
410 | | - $v_ssl = 'yes'; |
411 | 403 | $restart_web = 'yes'; |
412 | 404 | $restart_proxy = 'yes'; |
413 | 405 |
|
|
425 | 417 | $v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY']; |
426 | 418 | $v_ssl_issuer = $ssl_str[$v_domain]['ISSUER']; |
427 | 419 |
|
428 | | - // Cleanup certificate tempfiles |
429 | | - if (!empty($_POST['v_ssl_crt'])) { |
430 | | - unlink($tmpdir."/".$_POST['v_domain'].".crt"); |
431 | | - } |
432 | | - |
433 | | - if (!empty($_POST['v_ssl_key'])) { |
434 | | - unlink($tmpdir."/".$_POST['v_domain'].".key"); |
435 | | - } |
436 | | - |
437 | | - if (!empty($_POST['v_ssl_ca'])) { |
438 | | - unlink($tmpdir."/".$_POST['v_domain'].".ca"); |
439 | | - } |
| 420 | + // Cleanup certificate tempfiles |
| 421 | + if (!empty($_POST['v_ssl_crt'])) unlink($tmpdir."/".$_POST['v_domain'].".crt"); |
| 422 | + if (!empty($_POST['v_ssl_key'])) unlink($tmpdir."/".$_POST['v_domain'].".key"); |
| 423 | + if (!empty($_POST['v_ssl_ca'])) unlink($tmpdir."/".$_POST['v_domain'].".ca"); |
| 424 | + rmdir($tmpdir); |
| 425 | + } |
| 426 | + } |
440 | 427 |
|
441 | | - rmdir($tmpdir); |
442 | | - } |
443 | | - } |
444 | | - } |
445 | 428 | // Change document root for ssl domain |
446 | 429 | if (( $v_ssl == 'yes') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
447 | 430 | if ( $v_ssl_home != $_POST['v_ssl_home'] ) { |
|
0 commit comments