Fix to respect option to copy new key and certificate to Webmin

https://forum.virtualmin.com/t/letsencrypt-automatic-certificate-advice/132891/3?u=ilia
This commit is contained in:
Ilia Ross
2025-04-03 16:51:45 +03:00
parent e5beb7f022
commit f2cba6af00
3 changed files with 22 additions and 18 deletions

View File

@@ -326,7 +326,7 @@ else {
# Install in Webmin now?
print &ui_table_row($text{'ssl_usewebmin'},
&ui_yesno_radio("use", 1));
&ui_yesno_radio("use", !!($config{'letsencrypt_use'} // 1)));
# SSL key size
print &ui_table_row($text{'ssl_size'},

View File

@@ -88,7 +88,8 @@ else {
if ($in{'save'}) {
# Just update renewal
&save_renewal_only(\@doms, $webroot, $mode, $size, $in{'subset'});
&save_renewal_only(\@doms, $webroot, $mode, $size,
$in{'subset'}, $in{'use'});
&redirect("edit_ssl.cgi");
}
else {
@@ -110,8 +111,12 @@ else {
# Worked, now copy to Webmin
print $text{'letsencrypt_done'},"<p>\n";
# Save the renewal schedule
&save_renewal_only(\@doms, $webroot, $mode,
$size, $in{'subset'}, $in{'use'});
# Copy cert, key and chain to Webmin
if ($in{'use'}) {
# Copy cert, key and chain to Webmin
print $text{'letsencrypt_webmin'},"<br>\n";
&lock_file($ENV{'MINISERV_CONFIG'});
&get_miniserv_config(\%miniserv);
@@ -141,38 +146,33 @@ else {
&put_miniserv_config(\%miniserv);
&unlock_file($ENV{'MINISERV_CONFIG'});
&save_renewal_only(\@doms, $webroot, $mode,
$size, $in{'subset'});
&webmin_log("letsencrypt");
&restart_miniserv(1);
print $text{'letsencrypt_wdone'},"<p>\n";
}
else {
# Just tell the user
print $text{'letsencrypt_show'},"<p>\n";
my @grid = ( $text{'letsencrypt_cert'}, $cert,
$text{'letsencrypt_key'}, $key );
if ($chain) {
push(@grid, $text{'letsencrypt_chain'}, $chain);
}
print &ui_grid_table(\@grid, 2);
}
# Tell the user what was done
print $text{'letsencrypt_show'},"<p>\n";
my @grid = ( $text{'letsencrypt_cert'}, $cert,
$text{'letsencrypt_key'}, $key );
push(@grid, $text{'letsencrypt_chain'}, $chain) if ($chain);
print &ui_grid_table(\@grid, 2);
}
&ui_print_footer("", $text{'index_return'});
}
# save_renewal_only(&doms, webroot, mode, size, subset-mode)
# save_renewal_only(&doms, webroot, mode, size, subset-mode, used-by-webmin)
# Save for future renewals
sub save_renewal_only
{
my ($doms, $webroot, $mode, $size, $subset) = @_;
my ($doms, $webroot, $mode, $size, $subset, $usewebmin) = @_;
$config{'letsencrypt_doms'} = join(" ", @$doms);
$config{'letsencrypt_webroot'} = $webroot;
$config{'letsencrypt_mode'} = $mode;
$config{'letsencrypt_size'} = $size;
$config{'letsencrypt_subset'} = $subset;
$config{'letsencrypt_use'} = $usewebmin;
&save_module_config();
if (&foreign_check("webmincron")) {
my $job = &find_letsencrypt_cron_job();

View File

@@ -2697,6 +2697,7 @@ my @doms = split(/\s+/, $config{'letsencrypt_doms'});
my $webroot = $config{'letsencrypt_webroot'};
my $mode = $config{'letsencrypt_mode'} || "web";
my $size = $config{'letsencrypt_size'};
my $usewebmin = !!($config{'letsencrypt_use'} // 1);
if (!@doms) {
print "No domains saved to renew cert for!\n";
return;
@@ -2716,6 +2717,9 @@ if (!$ok) {
return;
}
# If we don't want to update the Webmin SSL certificate, then just return
return if (!$usewebmin);
# Copy into place
my %miniserv;
&lock_file($ENV{'MINISERV_CONFIG'});