Skip to content

Commit 9bf86ea

Browse files
author
Serghey Rodin
committed
LE installation
1 parent 5096b36 commit 9bf86ea

File tree

2 files changed

+115
-137
lines changed

2 files changed

+115
-137
lines changed

web/edit/web/index.php

Lines changed: 108 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
$v_cgi = $data[$v_domain]['CGI'];
3636
$v_elog = $data[$v_domain]['ELOG'];
3737
$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)) {
4039
exec (VESTA_CMD."v-list-web-domain-ssl ".$user." '".$v_domain."' json", $output, $return_var);
4140
$ssl_str = json_decode(implode('', $output), true);
4241
unset($output);
@@ -51,6 +50,8 @@
5150
$v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY'];
5251
$v_ssl_issuer = $ssl_str[$v_domain]['ISSUER'];
5352
}
53+
$v_letsencrypt = $data[$v_domain]['LETSENCRYPT'];
54+
if (empty($v_letsencrypt)) $v_letsencrypt = 'no';
5455
$v_ssl_home = $data[$v_domain]['SSL_HOME'];
5556
$v_backend_template = $data[$v_domain]['BACKEND'];
5657
$v_proxy = $data[$v_domain]['PROXY'];
@@ -214,10 +215,10 @@
214215

215216
// Change backend template
216217
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);
221222
}
222223

223224
// Delete proxy support
@@ -264,73 +265,83 @@
264265
$restart_proxy = 'yes';
265266
}
266267

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);
271271
check_return_code($return_var,$output);
272272
unset($output);
273273
$v_letsencrypt = 'no';
274+
$v_letsencrypt_deleted = 'yes';
275+
$v_ssl = 'no';
274276
$restart_web = 'yes';
275277
$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+
}
288289

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);
294294
check_return_code($return_var,$output);
295295
unset($output);
296296
$v_letsencrypt = 'yes';
297+
$v_ssl = 'yes';
297298
$restart_web = 'yes';
298299
$restart_proxy = 'yes';
299300
}
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-
}
330301

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);
332342
check_return_code($return_var,$output);
333343
unset($output);
344+
$v_ssl = 'yes';
334345
$restart_web = 'yes';
335346
$restart_proxy = 'yes';
336347

@@ -348,66 +359,47 @@
348359
$v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY'];
349360
$v_ssl_issuer = $ssl_str[$v_domain]['ISSUER'];
350361

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+
}
400391

401392
// CA
402393
if (!empty($_POST['v_ssl_ca'])) {
403394
$fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w');
404395
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca']));
396+
fwrite($fp, "\n");
405397
fclose($fp);
406398
}
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);
408401
check_return_code($return_var,$output);
409402
unset($output);
410-
$v_ssl = 'yes';
411403
$restart_web = 'yes';
412404
$restart_proxy = 'yes';
413405

@@ -425,23 +417,14 @@
425417
$v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY'];
426418
$v_ssl_issuer = $ssl_str[$v_domain]['ISSUER'];
427419

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+
}
440427

441-
rmdir($tmpdir);
442-
}
443-
}
444-
}
445428
// Change document root for ssl domain
446429
if (( $v_ssl == 'yes') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
447430
if ( $v_ssl_home != $_POST['v_ssl_home'] ) {

web/templates/admin/edit_web.html

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,9 @@
186186
<tr>
187187
<td class="step-left">
188188
<table style="display:<?php if ($v_ssl == 'no' ) { echo 'none';} else {echo 'block';}?> ;" id="ssltable">
189-
<tr>
190-
<td class="input-label vst-text">
191-
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_letsencrypt" <?php if($v_letencrypt == 'yes' || $v_letencrypt == 'on') echo "checked=yes" ?> onclick="App.Actions.WEB.toggle_letsencrypt(this)"> <?php print __('Lets Encrypt Support');?></label>
192-
</td>
193-
</tr>
194-
<tr>
195-
<td class="vst-text input-label lets-encrypt-note <? if($v_letencrypt == 'yes' || $v_letencrypt == 'on') echo ' enabled';?>" >
196-
<?= __('Your certificate will be automatically issued in 5 minutes')?>
189+
<tr>
190+
<td class="input-label vst-text">
191+
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_letsencrypt" <?php if($v_letsencrypt == 'yes' || $v_letencrypt == 'on') echo "checked=yes" ?> onclick="App.Actions.WEB.toggle_letsencrypt(this)"> <?php print __('Lets Encrypt Support');?></label>
197192
</td>
198193
</tr>
199194
<tr>
@@ -217,7 +212,7 @@
217212
<tr>
218213
<td class="vst-text input-label">
219214
<?php print __('SSL Certificate');?>
220-
<span id="generate-csr"> / <a class="generate" target="_blank" href="/generate/ssl/?domain=<?php echo $v_domain ?>"><?php print __('Generate CSR') ?></a></span>
215+
<span id="generate-csr"> / <a class="generate" target="_blank" href="/generate/ssl/?domain=<?php echo $v_domain ?>"><?php print __('Generate CSR') ?></a></span>
221216
</td>
222217
</tr>
223218
<tr>
@@ -246,7 +241,7 @@
246241
</td>
247242
</tr>
248243
<?
249-
if ($v_ssl != 'no' ) { ?>
244+
if ($v_ssl != 'no' ) { ?>
250245
<tr>
251246
<td>
252247
<table class="additional-info">
@@ -311,7 +306,7 @@
311306
</table>
312307
</td>
313308
</tr>
314-
<? } // if ssl is enabled ?>
309+
<? } // if ssl is enabled ?>
315310
</table>
316311
</td>
317312
</tr>
@@ -337,7 +332,7 @@
337332
</select>
338333
</td>
339334
</tr>
340-
<tr class="stats-auth" style="<? if ($v_stats == 'none') { ?>display:none"<? } ?>>
335+
<tr class="stats-auth" style="<? if ($v_stats == 'none') { ?>display:none<? } ?>">
341336
<td class="vst-text input-label step-left">
342337
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_stats_auth" <?php if (!empty($v_stats_user)) echo "checked=yes" ?> onclick="javascript:elementHideShow('statstable');"><?php print __('Statistics Authorization');?></label>
343338
</td>

0 commit comments

Comments
 (0)