Skip to content

Commit df26e5e

Browse files
author
Marius Burkard
committed
- WIP: fixing LE on install / update
1 parent e255b99 commit df26e5e

File tree

3 files changed

+90
-8
lines changed

3 files changed

+90
-8
lines changed

install/lib/installer_base.lib.php

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,6 +2720,42 @@ private function curl_request($url, $use_ipv6 = false) {
27202720
return $response;
27212721
}
27222722

2723+
private function make_acme_vhost($server_name, $server = 'apache') {
2724+
global $conf;
2725+
2726+
$use_template = 'apache_acme.vhost.master';
2727+
if($server === 'nginx') {
2728+
$use_template = 'nginx_acme.vhost.master';
2729+
}
2730+
2731+
$vhost_conf_dir = $conf[$server]['vhost_conf_dir'];
2732+
$vhost_conf_enabled_dir = $conf[$server]['vhost_conf_enabled_dir'];
2733+
2734+
$tpl = new tpl($use_template);
2735+
$tpl->setVar('domain', $server_name);
2736+
2737+
if($server !== 'nginx') {
2738+
$tpl->setVar('apache_version',getapacheversion());
2739+
}
2740+
2741+
wf($vhost_conf_dir.'/acme.vhost', $tpl->grab());
2742+
2743+
if(@is_link($vhost_conf_enabled_dir.'/999-acme.vhost')) {
2744+
unlink($vhost_conf_enabled_dir.'/999-acme.vhost');
2745+
}
2746+
if(!@is_link($vhost_conf_enabled_dir.'/999-acme.vhost')) {
2747+
symlink($vhost_conf_dir.'/acme.vhost', $vhost_conf_enabled_dir.'/999-acme.vhost');
2748+
}
2749+
2750+
if($conf[$server]['installed'] == true && $conf[$server]['init_script'] != '') {
2751+
if($this->is_update) {
2752+
system($this->getinitcommand($conf[$server]['init_script'], 'force-reload').' &> /dev/null || ' . $this->getinitcommand($conf[$server]['init_script'], 'restart').' &> /dev/null');
2753+
} else {
2754+
system($this->getinitcommand($conf[$server]['init_script'], 'restart').' &> /dev/null');
2755+
}
2756+
}
2757+
}
2758+
27232759
public function make_ispconfig_ssl_cert() {
27242760
global $conf, $autoinstall;
27252761

@@ -2802,13 +2838,18 @@ public function make_ispconfig_ssl_cert() {
28022838
$acme = explode("\n", shell_exec('which /usr/local/ispconfig/server/scripts/acme.sh /root/.acme.sh/acme.sh'));
28032839
$acme = reset($acme);
28042840

2841+
// first of all create the acme vhosts if not existing
2842+
if($conf['nginx']['installed'] == true) {
2843+
$this->make_acme_vhost($hostname, 'nginx');
2844+
} elseif($conf['apache']['installed'] == true) {
2845+
$this->make_acme_vhost($hostname, 'apache');
2846+
}
2847+
28052848
// Attempt to use Neilpang acme.sh first, as it is now the preferred LE client
28062849
if (is_executable($acme)) {
28072850

2808-
if($conf['nginx']['installed'] == true) {
2809-
exec("$acme --issue --nginx -d $hostname $renew_hook");
2810-
} elseif($conf['apache']['installed'] == true) {
2811-
exec("$acme --issue --apache -d $hostname $renew_hook");
2851+
if($conf['nginx']['installed'] == true || $conf['apache']['installed'] == true) {
2852+
exec("$acme --issue -w /usr/local/ispconfig/interface/acme -d $hostname $renew_hook");
28122853
}
28132854
// Else, it is not webserver, so we use standalone
28142855
else {
@@ -2840,10 +2881,8 @@ public function make_ispconfig_ssl_cert() {
28402881
$certonly = 'certonly --agree-tos --non-interactive --expand --rsa-key-size 4096';
28412882

28422883
// If this is a webserver
2843-
if($conf['nginx']['installed'] == true)
2844-
exec("$le_client $certonly $acme_version --nginx --email postmaster@$hostname -d $hostname $renew_hook");
2845-
elseif($conf['apache']['installed'] == true)
2846-
exec("$le_client $certonly $acme_version --apache --email postmaster@$hostname -d $hostname $renew_hook");
2884+
if($conf['nginx']['installed'] == true || $conf['apache']['installed'] == true)
2885+
exec("$le_client $certonly $acme_version --authenticator webroot --webroot-path /usr/local/ispconfig/interface/acme --email postmaster@$hostname -d $hostname $renew_hook");
28472886
// Else, it is not webserver, so we use standalone
28482887
else
28492888
exec("$le_client $certonly $acme_version --standalone --email postmaster@$hostname -d $hostname $hook");
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<VirtualHost *:80>
2+
3+
ServerName <tmpl_var name='domain'>
4+
5+
DocumentRoot /usr/local/ispconfig/interface/acme
6+
7+
<Directory /usr/local/ispconfig/interface/acme>
8+
AllowOverride None
9+
<tmpl_if name='apache_version' op='>' value='2.2' format='version'>
10+
Require all granted
11+
<tmpl_else>
12+
Order allow,deny
13+
Allow from all
14+
</tmpl_if>
15+
</Directory>
16+
17+
</VirtualHost>
18+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
server {
2+
listen 80;
3+
listen [::]:80;
4+
5+
server_name <tmpl_var name='domain'>;
6+
7+
root /usr/local/ispconfig/interface/acme;
8+
9+
autoindex off;
10+
index index.html;
11+
12+
## Disable .htaccess and other hidden files
13+
location ~ / {
14+
deny all;
15+
}
16+
17+
## Allow access for .well-known/acme-challenge
18+
location ^~ /.well-known/acme-challenge/ {
19+
access_log off;
20+
log_not_found off;
21+
auth_basic off;
22+
root /usr/local/ispconfig/interface/acme/;
23+
try_files $uri $uri/ =404;
24+
}
25+
}

0 commit comments

Comments
 (0)