Skip to content

Commit 48bced2

Browse files
committed
*Add letsencrypt GUI support
1 parent 50f1db1 commit 48bced2

File tree

6 files changed

+235
-163
lines changed

6 files changed

+235
-163
lines changed

web/add/web/index.php

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
$v_ssl_key = $_POST['v_ssl_key'];
8080
$v_ssl_ca = $_POST['v_ssl_ca'];
8181
$v_ssl_home = $data[$v_domain]['SSL_HOME'];
82+
$v_letsencrypt = $_POST['v_letsencrypt'];
8283
$v_stats = escapeshellarg($_POST['v_stats']);
8384
$v_stats_user = $data[$v_domain]['STATS_USER'];
8485
$v_stats_password = $data[$v_domain]['STATS_PASSWORD'];
@@ -96,6 +97,7 @@
9697
if ((!empty($_POST['v_ssl'])) || (!empty($_POST['v_elog']))) $v_adv = 'yes';
9798
if ((!empty($_POST['v_ssl_crt'])) || (!empty($_POST['v_ssl_key']))) $v_adv = 'yes';
9899
if ((!empty($_POST['v_ssl_ca'])) || ($_POST['v_stats'] != 'none')) $v_adv = 'yes';
100+
if ((!empty($_POST['v_letsencrypt']))) $v_adv = 'yes';
99101

100102
// Check advanced features
101103
if (empty($_POST['v_dns'])) $v_dns = 'off';
@@ -144,42 +146,51 @@
144146
unset($output);
145147
}
146148

147-
// Add SSL certificates
148-
if ((!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
149-
exec ('mktemp -d', $output, $return_var);
150-
$tmpdir = $output[0];
151-
unset($output);
152-
153-
// Save certificate
154-
if (!empty($_POST['v_ssl_crt'])) {
155-
$fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w');
156-
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt']));
157-
fwrite($fp, "\n");
158-
fclose($fp);
159-
}
160-
161-
// Save private key
162-
if (!empty($_POST['v_ssl_key'])) {
163-
$fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w');
164-
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key']));
165-
fwrite($fp, "\n");
166-
fclose($fp);
167-
}
168-
169-
// Save CA bundle
170-
if (!empty($_POST['v_ssl_ca'])) {
171-
$fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w');
172-
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca']));
173-
fwrite($fp, "\n");
174-
fclose($fp);
175-
}
176-
177-
$v_ssl_home = escapeshellarg($_POST['v_ssl_home']);
178-
exec (VESTA_CMD."v-add-web-domain-ssl ".$user." ".$v_domain." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var);
179-
check_return_code($return_var,$output);
180-
unset($output);
181-
}
182-
149+
// Add Lets Encrypt support
150+
151+
if ((!empty($_POST['v_letsencrypt'])) && (empty($_SESSION['error_msg']))) {
152+
exec (VESTA_CMD."v-add-letsencrypt-domain ".$user." ".$v_domain." '' 'no'", $output, $return_var);
153+
check_return_code($return_var,$output);
154+
unset($output);
155+
}
156+
else {
157+
// Add SSL certificates only if Lets Encrypt is off
158+
if ((!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
159+
exec ('mktemp -d', $output, $return_var);
160+
$tmpdir = $output[0];
161+
unset($output);
162+
163+
// Save certificate
164+
if (!empty($_POST['v_ssl_crt'])) {
165+
$fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w');
166+
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt']));
167+
fwrite($fp, "\n");
168+
fclose($fp);
169+
}
170+
171+
// Save private key
172+
if (!empty($_POST['v_ssl_key'])) {
173+
$fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w');
174+
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key']));
175+
fwrite($fp, "\n");
176+
fclose($fp);
177+
}
178+
179+
// Save CA bundle
180+
if (!empty($_POST['v_ssl_ca'])) {
181+
$fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w');
182+
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca']));
183+
fwrite($fp, "\n");
184+
fclose($fp);
185+
}
186+
187+
$v_ssl_home = escapeshellarg($_POST['v_ssl_home']);
188+
exec (VESTA_CMD."v-add-web-domain-ssl ".$user." ".$v_domain." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var);
189+
check_return_code($return_var,$output);
190+
unset($output);
191+
}
192+
193+
}
183194
// Add web stats
184195
if ((!empty($_POST['v_stats'])) && ($_POST['v_stats'] != 'none' ) && (empty($_SESSION['error_msg']))) {
185196
$v_stats = escapeshellarg($_POST['v_stats']);

web/edit/web/index.php

Lines changed: 146 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
$v_cgi = $data[$v_domain]['CGI'];
3636
$v_elog = $data[$v_domain]['ELOG'];
3737
$v_ssl = $data[$v_domain]['SSL'];
38-
if ( $v_ssl == 'yes' ) {
38+
$v_letsencrypt = $data[$v_domain]['LETSENCRYPT'];
39+
if ( $v_ssl == 'yes' && ($v_letsencrypt == 'no' || empty($v_letsencrypt))) {
3940
exec (VESTA_CMD."v-list-web-domain-ssl ".$user." '".$v_domain."' json", $output, $return_var);
4041
$ssl_str = json_decode(implode('', $output), true);
4142
unset($output);
@@ -256,139 +257,159 @@
256257
$restart_proxy = 'yes';
257258
}
258259

259-
// Delete SSL certificate
260-
if (( $v_ssl == 'yes' ) && (empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
261-
exec (VESTA_CMD."v-delete-web-domain-ssl ".$v_username." ".$v_domain." 'no'", $output, $return_var);
260+
// Disable Lets Encrypt support
261+
262+
if (( $v_letsencrypt == 'yes' ) && (empty($_POST['v_letsencrypt'])) && (!empty($_POST['v_letsencrypt'])) && (empty($_SESSION['error_msg']))) {
263+
exec (VESTA_CMD."v-add-letsencrypt-domain ".$user." ".$v_domain." '' 'no'", $output, $return_var);
262264
check_return_code($return_var,$output);
263265
unset($output);
264-
$v_ssl = 'no';
266+
$v_letsencrypt = 'no';
265267
$restart_web = 'yes';
266268
$restart_proxy = 'yes';
267-
}
268-
269-
// Change SSL certificate
270-
if (($v_ssl == 'yes') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
271-
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']))) {
272-
exec ('mktemp -d', $mktemp_output, $return_var);
273-
$tmpdir = $mktemp_output[0];
274-
275-
// Certificate
276-
if (!empty($_POST['v_ssl_crt'])) {
277-
$fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w');
278-
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt']));
279-
fwrite($fp, "\n");
280-
fclose($fp);
281-
}
282-
283-
// Key
284-
if (!empty($_POST['v_ssl_key'])) {
285-
$fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w');
286-
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key']));
287-
fwrite($fp, "\n");
288-
fclose($fp);
289-
}
290-
291-
// CA
292-
if (!empty($_POST['v_ssl_ca'])) {
293-
$fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w');
294-
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca']));
295-
fwrite($fp, "\n");
296-
fclose($fp);
297-
}
298-
299-
exec (VESTA_CMD."v-change-web-domain-sslcert ".$user." ".$v_domain." ".$tmpdir." 'no'", $output, $return_var);
300-
check_return_code($return_var,$output);
301-
unset($output);
302-
$restart_web = 'yes';
303-
$restart_proxy = 'yes';
304-
$v_ssl_crt = $_POST['v_ssl_crt'];
305-
$v_ssl_key = $_POST['v_ssl_key'];
306-
$v_ssl_ca = $_POST['v_ssl_ca'];
307-
308-
// Cleanup certificate tempfiles
309-
if (!empty($_POST['v_ssl_crt'])) {
310-
unlink($tmpdir."/".$_POST['v_domain'].".crt");
311-
}
312-
313-
if (!empty($_POST['v_ssl_key'])) {
314-
unlink($tmpdir."/".$_POST['v_domain'].".key");
315-
}
316-
317-
if (!empty($_POST['v_ssl_ca'])) {
318-
unlink($tmpdir."/".$_POST['v_domain'].".ca");
319-
}
320-
321-
rmdir($tmpdir);
322-
}
323-
}
324-
325-
// Add SSL certificate
326-
if (( $v_ssl == 'no') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
327-
if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_crt']))) $errors[] = 'ssl certificate';
328-
if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_key']))) $errors[] = 'ssl key';
329-
if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_home']))) $errors[] = 'ssl home';
330-
$v_ssl_home = escapeshellarg($_POST['v_ssl_home']);
331-
if (!empty($errors[0])) {
332-
foreach ($errors as $i => $error) {
333-
if ( $i == 0 ) {
334-
$error_msg = $error;
335-
} else {
336-
$error_msg = $error_msg.", ".$error;
337-
}
338-
}
339-
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
340-
} else {
341-
exec ('mktemp -d', $mktemp_output, $return_var);
342-
$tmpdir = $mktemp_output[0];
343-
344-
// Certificate
345-
if (!empty($_POST['v_ssl_crt'])) {
346-
$fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w');
347-
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt']));
348-
fclose($fp);
349-
}
350-
351-
// Key
352-
if (!empty($_POST['v_ssl_key'])) {
353-
$fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w');
354-
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key']));
355-
fclose($fp);
356-
}
357-
358-
// CA
359-
if (!empty($_POST['v_ssl_ca'])) {
360-
$fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w');
361-
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca']));
362-
fclose($fp);
363-
}
364-
exec (VESTA_CMD."v-add-web-domain-ssl ".$user." ".$v_domain." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var);
269+
}
270+
else {
271+
// Delete SSL certificate
272+
if (( $v_ssl == 'yes' ) && (empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
273+
exec (VESTA_CMD."v-delete-web-domain-ssl ".$v_username." ".$v_domain." 'no'", $output, $return_var);
365274
check_return_code($return_var,$output);
366275
unset($output);
367-
$v_ssl = 'yes';
276+
$v_ssl = 'no';
368277
$restart_web = 'yes';
369278
$restart_proxy = 'yes';
370-
$v_ssl_crt = $_POST['v_ssl_crt'];
371-
$v_ssl_key = $_POST['v_ssl_key'];
372-
$v_ssl_ca = $_POST['v_ssl_ca'];
373-
$v_ssl_home = $_POST['v_ssl_home'];
374-
375-
// Cleanup certificate tempfiles
376-
if (!empty($_POST['v_ssl_crt'])) {
377-
unlink($tmpdir."/".$_POST['v_domain'].".crt");
378-
}
379-
380-
if (!empty($_POST['v_ssl_key'])) {
381-
unlink($tmpdir."/".$_POST['v_domain'].".key");
382-
}
383-
384-
if (!empty($_POST['v_ssl_ca'])) {
385-
unlink($tmpdir."/".$_POST['v_domain'].".ca");
386-
}
387-
388-
rmdir($tmpdir);
389279
}
390-
}
391-
280+
}
281+
if (( $v_letsencrypt == 'no' || empty( $v_letsencrypt)) && (!empty($_POST['v_letsencrypt'])) && empty($_SESSION['error_msg'])) {
282+
exec (VESTA_CMD."v-add-letsencrypt-domain ".$user." ".$v_domain." '' 'no'", $output, $return_var);
283+
check_return_code($return_var,$output);
284+
unset($output);
285+
$v_letsencrypt = 'yes';
286+
$restart_web = 'yes';
287+
$restart_proxy = 'yes';
288+
}
289+
else{
290+
// Change SSL certificate
291+
if (($v_ssl == 'yes') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
292+
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']))) {
293+
exec ('mktemp -d', $mktemp_output, $return_var);
294+
$tmpdir = $mktemp_output[0];
295+
296+
// Certificate
297+
if (!empty($_POST['v_ssl_crt'])) {
298+
$fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w');
299+
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt']));
300+
fwrite($fp, "\n");
301+
fclose($fp);
302+
}
303+
304+
// Key
305+
if (!empty($_POST['v_ssl_key'])) {
306+
$fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w');
307+
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key']));
308+
fwrite($fp, "\n");
309+
fclose($fp);
310+
}
311+
312+
// CA
313+
if (!empty($_POST['v_ssl_ca'])) {
314+
$fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w');
315+
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca']));
316+
fwrite($fp, "\n");
317+
fclose($fp);
318+
}
319+
320+
exec (VESTA_CMD."v-change-web-domain-sslcert ".$user." ".$v_domain." ".$tmpdir." 'no'", $output, $return_var);
321+
check_return_code($return_var,$output);
322+
unset($output);
323+
$restart_web = 'yes';
324+
$restart_proxy = 'yes';
325+
$v_ssl_crt = $_POST['v_ssl_crt'];
326+
$v_ssl_key = $_POST['v_ssl_key'];
327+
$v_ssl_ca = $_POST['v_ssl_ca'];
328+
329+
// Cleanup certificate tempfiles
330+
if (!empty($_POST['v_ssl_crt'])) {
331+
unlink($tmpdir."/".$_POST['v_domain'].".crt");
332+
}
333+
334+
if (!empty($_POST['v_ssl_key'])) {
335+
unlink($tmpdir."/".$_POST['v_domain'].".key");
336+
}
337+
338+
if (!empty($_POST['v_ssl_ca'])) {
339+
unlink($tmpdir."/".$_POST['v_domain'].".ca");
340+
}
341+
342+
rmdir($tmpdir);
343+
}
344+
}
345+
346+
// Add SSL certificate
347+
if (( $v_ssl == 'no') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
348+
if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_crt']))) $errors[] = 'ssl certificate';
349+
if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_key']))) $errors[] = 'ssl key';
350+
if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_home']))) $errors[] = 'ssl home';
351+
$v_ssl_home = escapeshellarg($_POST['v_ssl_home']);
352+
if (!empty($errors[0])) {
353+
foreach ($errors as $i => $error) {
354+
if ( $i == 0 ) {
355+
$error_msg = $error;
356+
} else {
357+
$error_msg = $error_msg.", ".$error;
358+
}
359+
}
360+
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
361+
} else {
362+
exec ('mktemp -d', $mktemp_output, $return_var);
363+
$tmpdir = $mktemp_output[0];
364+
365+
// Certificate
366+
if (!empty($_POST['v_ssl_crt'])) {
367+
$fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w');
368+
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt']));
369+
fclose($fp);
370+
}
371+
372+
// Key
373+
if (!empty($_POST['v_ssl_key'])) {
374+
$fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w');
375+
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key']));
376+
fclose($fp);
377+
}
378+
379+
// CA
380+
if (!empty($_POST['v_ssl_ca'])) {
381+
$fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w');
382+
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca']));
383+
fclose($fp);
384+
}
385+
exec (VESTA_CMD."v-add-web-domain-ssl ".$user." ".$v_domain." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var);
386+
check_return_code($return_var,$output);
387+
unset($output);
388+
$v_ssl = 'yes';
389+
$restart_web = 'yes';
390+
$restart_proxy = 'yes';
391+
$v_ssl_crt = $_POST['v_ssl_crt'];
392+
$v_ssl_key = $_POST['v_ssl_key'];
393+
$v_ssl_ca = $_POST['v_ssl_ca'];
394+
$v_ssl_home = $_POST['v_ssl_home'];
395+
396+
// Cleanup certificate tempfiles
397+
if (!empty($_POST['v_ssl_crt'])) {
398+
unlink($tmpdir."/".$_POST['v_domain'].".crt");
399+
}
400+
401+
if (!empty($_POST['v_ssl_key'])) {
402+
unlink($tmpdir."/".$_POST['v_domain'].".key");
403+
}
404+
405+
if (!empty($_POST['v_ssl_ca'])) {
406+
unlink($tmpdir."/".$_POST['v_domain'].".ca");
407+
}
408+
409+
rmdir($tmpdir);
410+
}
411+
}
412+
}
392413
// Change document root for ssl domain
393414
if (( $v_ssl == 'yes') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
394415
if ( $v_ssl_home != $_POST['v_ssl_home'] ) {

0 commit comments

Comments
 (0)