Skip to content

Commit 7df680a

Browse files
author
Serghey Rodin
committed
fix for ssl w/o LE
1 parent 028a7a5 commit 7df680a

File tree

1 file changed

+87
-79
lines changed

1 file changed

+87
-79
lines changed

web/edit/web/index.php

Lines changed: 87 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,85 @@
265265
$restart_proxy = 'yes';
266266
}
267267

268+
// Change document root for ssl domain
269+
if (( $v_ssl == 'yes') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
270+
if ( $v_ssl_home != $_POST['v_ssl_home'] ) {
271+
$v_ssl_home = escapeshellarg($_POST['v_ssl_home']);
272+
exec (VESTA_CMD."v-change-web-domain-sslhome ".$user." ".$v_domain." ".$v_ssl_home." 'no'", $output, $return_var);
273+
check_return_code($return_var,$output);
274+
$v_ssl_home = $_POST['v_ssl_home'];
275+
$restart_web = 'yes';
276+
$restart_proxy = 'yes';
277+
unset($output);
278+
}
279+
}
280+
281+
// Change SSL certificate
282+
if (( $v_letsencrypt == 'no' ) && ( $v_ssl == 'yes' ) && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
283+
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']))) {
284+
exec ('mktemp -d', $mktemp_output, $return_var);
285+
$tmpdir = $mktemp_output[0];
286+
287+
// Certificate
288+
if (!empty($_POST['v_ssl_crt'])) {
289+
$fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w');
290+
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt']));
291+
fwrite($fp, "\n");
292+
fclose($fp);
293+
}
294+
295+
// Key
296+
if (!empty($_POST['v_ssl_key'])) {
297+
$fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w');
298+
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key']));
299+
fwrite($fp, "\n");
300+
fclose($fp);
301+
}
302+
303+
// CA
304+
if (!empty($_POST['v_ssl_ca'])) {
305+
$fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w');
306+
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca']));
307+
fwrite($fp, "\n");
308+
fclose($fp);
309+
}
310+
311+
exec (VESTA_CMD."v-change-web-domain-sslcert ".$user." ".$v_domain." ".$tmpdir." 'no'", $output, $return_var);
312+
check_return_code($return_var,$output);
313+
unset($output);
314+
$restart_web = 'yes';
315+
$restart_proxy = 'yes';
316+
317+
exec (VESTA_CMD."v-list-web-domain-ssl ".$user." '".$v_domain."' json", $output, $return_var);
318+
$ssl_str = json_decode(implode('', $output), true);
319+
unset($output);
320+
$v_ssl_crt = $ssl_str[$v_domain]['CRT'];
321+
$v_ssl_key = $ssl_str[$v_domain]['KEY'];
322+
$v_ssl_ca = $ssl_str[$v_domain]['CA'];
323+
$v_ssl_subject = $ssl_str[$v_domain]['SUBJECT'];
324+
$v_ssl_aliases = $ssl_str[$v_domain]['ALIASES'];
325+
$v_ssl_not_before = $ssl_str[$v_domain]['NOT_BEFORE'];
326+
$v_ssl_not_after = $ssl_str[$v_domain]['NOT_AFTER'];
327+
$v_ssl_signature = $ssl_str[$v_domain]['SIGNATURE'];
328+
$v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY'];
329+
$v_ssl_issuer = $ssl_str[$v_domain]['ISSUER'];
330+
331+
// Cleanup certificate tempfiles
332+
if (!empty($_POST['v_ssl_crt'])) unlink($tmpdir."/".$_POST['v_domain'].".crt");
333+
if (!empty($_POST['v_ssl_key'])) unlink($tmpdir."/".$_POST['v_domain'].".key");
334+
if (!empty($_POST['v_ssl_ca'])) unlink($tmpdir."/".$_POST['v_domain'].".ca");
335+
rmdir($tmpdir);
336+
}
337+
}
338+
268339
// Delete Lets Encrypt support
269340
if (( $v_letsencrypt == 'yes' ) && (empty($_POST['v_letsencrypt'])) && (empty($_SESSION['error_msg']))) {
270341
exec (VESTA_CMD."v-delete-letsencrypt-domain ".$user." ".$v_domain." 'no'", $output, $return_var);
271342
check_return_code($return_var,$output);
272343
unset($output);
344+
$v_ssl_crt = '';
345+
$v_ssl_key = '';
346+
$v_ssl_ca = '';
273347
$v_letsencrypt = 'no';
274348
$v_letsencrypt_deleted = 'yes';
275349
$v_ssl = 'no';
@@ -282,6 +356,9 @@
282356
exec (VESTA_CMD."v-delete-web-domain-ssl ".$v_username." ".$v_domain." 'no'", $output, $return_var);
283357
check_return_code($return_var,$output);
284358
unset($output);
359+
$v_ssl_crt = '';
360+
$v_ssl_key = '';
361+
$v_ssl_ca = '';
285362
$v_ssl = 'no';
286363
$restart_web = 'yes';
287364
$restart_proxy = 'yes';
@@ -348,16 +425,16 @@
348425
exec (VESTA_CMD."v-list-web-domain-ssl ".$user." '".$v_domain."' json", $output, $return_var);
349426
$ssl_str = json_decode(implode('', $output), true);
350427
unset($output);
351-
$v_ssl_crt = $ssl_str[$v_domain]['CRT'];
352-
$v_ssl_key = $ssl_str[$v_domain]['KEY'];
353-
$v_ssl_ca = $ssl_str[$v_domain]['CA'];
354-
$v_ssl_subject = $ssl_str[$v_domain]['SUBJECT'];
355-
$v_ssl_aliases = $ssl_str[$v_domain]['ALIASES'];
356-
$v_ssl_not_before = $ssl_str[$v_domain]['NOT_BEFORE'];
357-
$v_ssl_not_after = $ssl_str[$v_domain]['NOT_AFTER'];
358-
$v_ssl_signature = $ssl_str[$v_domain]['SIGNATURE'];
359-
$v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY'];
360-
$v_ssl_issuer = $ssl_str[$v_domain]['ISSUER'];
428+
$v_ssl_crt = $ssl_str[$_POST['v_domain']]['CRT'];
429+
$v_ssl_key = $ssl_str[$_POST['v_domain']]['KEY'];
430+
$v_ssl_ca = $ssl_str[$_POST['v_domain']]['CA'];
431+
$v_ssl_subject = $ssl_str[$_POST['v_domain']]['SUBJECT'];
432+
$v_ssl_aliases = $ssl_str[$_POST['v_domain']]['ALIASES'];
433+
$v_ssl_not_before = $ssl_str[$_POST['v_domain']]['NOT_BEFORE'];
434+
$v_ssl_not_after = $ssl_str[$_POST['v_domain']]['NOT_AFTER'];
435+
$v_ssl_signature = $ssl_str[$_POST['v_domain']]['SIGNATURE'];
436+
$v_ssl_pub_key = $ssl_str[$_POST['v_domain']]['PUB_KEY'];
437+
$v_ssl_issuer = $ssl_str[$_POST['v_domain']]['ISSUER'];
361438

362439
// Cleanup certificate tempfiles
363440
if (!empty($_POST['v_ssl_crt'])) unlink($tmpdir."/".$_POST['v_domain'].".crt");
@@ -367,76 +444,7 @@
367444
}
368445
}
369446

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-
}
391447

392-
// CA
393-
if (!empty($_POST['v_ssl_ca'])) {
394-
$fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w');
395-
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca']));
396-
fwrite($fp, "\n");
397-
fclose($fp);
398-
}
399-
400-
exec (VESTA_CMD."v-change-web-domain-sslcert ".$user." ".$v_domain." ".$tmpdir." 'no'", $output, $return_var);
401-
check_return_code($return_var,$output);
402-
unset($output);
403-
$restart_web = 'yes';
404-
$restart_proxy = 'yes';
405-
406-
exec (VESTA_CMD."v-list-web-domain-ssl ".$user." '".$v_domain."' json", $output, $return_var);
407-
$ssl_str = json_decode(implode('', $output), true);
408-
unset($output);
409-
$v_ssl_crt = $ssl_str[$v_domain]['CRT'];
410-
$v_ssl_key = $ssl_str[$v_domain]['KEY'];
411-
$v_ssl_ca = $ssl_str[$v_domain]['CA'];
412-
$v_ssl_subject = $ssl_str[$v_domain]['SUBJECT'];
413-
$v_ssl_aliases = $ssl_str[$v_domain]['ALIASES'];
414-
$v_ssl_not_before = $ssl_str[$v_domain]['NOT_BEFORE'];
415-
$v_ssl_not_after = $ssl_str[$v_domain]['NOT_AFTER'];
416-
$v_ssl_signature = $ssl_str[$v_domain]['SIGNATURE'];
417-
$v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY'];
418-
$v_ssl_issuer = $ssl_str[$v_domain]['ISSUER'];
419-
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-
}
427-
428-
// Change document root for ssl domain
429-
if (( $v_ssl == 'yes') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
430-
if ( $v_ssl_home != $_POST['v_ssl_home'] ) {
431-
$v_ssl_home = escapeshellarg($_POST['v_ssl_home']);
432-
exec (VESTA_CMD."v-change-web-domain-sslhome ".$user." ".$v_domain." ".$v_ssl_home." 'no'", $output, $return_var);
433-
check_return_code($return_var,$output);
434-
$v_ssl_home = $_POST['v_ssl_home'];
435-
$restart_web = 'yes';
436-
$restart_proxy = 'yes';
437-
unset($output);
438-
}
439-
}
440448

441449
// Delete web stats
442450
if ((!empty($v_stats)) && ($_POST['v_stats'] == 'none') && (empty($_SESSION['error_msg']))) {

0 commit comments

Comments
 (0)