Skip to content

Commit c1b703e

Browse files
committed
Update installer_base.lib.php to use certbot standalone to create SSL certs for ISPConfig server(s).
1 parent 0281760 commit c1b703e

File tree

1 file changed

+53
-12
lines changed

1 file changed

+53
-12
lines changed

install/lib/installer_base.lib.php

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,16 +2398,57 @@ public function configure_apps_vhost() {
23982398
}
23992399

24002400
public function make_ispconfig_ssl_cert() {
2401-
global $conf,$autoinstall;
2402-
2403-
$install_dir = $conf['ispconfig_install_dir'];
2404-
2405-
$ssl_crt_file = $install_dir.'/interface/ssl/ispserver.crt';
2406-
$ssl_csr_file = $install_dir.'/interface/ssl/ispserver.csr';
2407-
$ssl_key_file = $install_dir.'/interface/ssl/ispserver.key';
2408-
2409-
if(!@is_dir($install_dir.'/interface/ssl')) mkdir($install_dir.'/interface/ssl', 0755, true);
2410-
2401+
global $conf, $autoinstall;
2402+
2403+
// This hostname can be taken from user entry too
2404+
// But I don't find a way for it yet so...
2405+
// I use this for now ;D
2406+
$hostname = exec('hostname -f');
2407+
// Check if LE SSL folder for the hostname existed
2408+
$le_live_dir = '/etc/letsencrypt/live/' . $hostname;
2409+
// Check if this is web server
2410+
$check_nginx = exec("dpkg-query -W -f='\${Status}' nginx 2>/dev/null | grep -c 'ok installed'");
2411+
$check_apache = exec("dpkg-query -W -f='\${Status}' apache2 2>/dev/null | grep -c 'ok installed'");
2412+
// We support certbot so create standalone LE SSL certs for this server
2413+
if (!@is_dir($le_live_dir)) {
2414+
// If it is nginx webserver
2415+
if ($check_nginx == 1)
2416+
exec("certbot certonly --authenticator standalone -d $hostname --pre-hook 'service nginx stop' --post-hook 'service nginx start'");
2417+
// If it is apache2 webserver
2418+
elseif ($check_apache2 == 1)
2419+
exec("certbot certonly --authenticator standalone -d $hostname --pre-hook 'service apache2 stop' --post-hook 'service apache2 start'");
2420+
// If it is not webserver
2421+
else
2422+
exec("certbot certonly --authenticator standalone -d $hostname");
2423+
}
2424+
2425+
// If the LE SSL certs for this hostname exists
2426+
if (is_dir($le_live_dir)) {
2427+
2428+
// Define and check ISPConfig SSL folder
2429+
$install_dir = $conf['ispconfig_install_dir'];
2430+
if(!@is_dir($install_dir.'/interface/ssl')) mkdir($install_dir.'/interface/ssl', 0755, true);
2431+
$ssl_crt_file = $install_dir.'/interface/ssl/ispserver.crt';
2432+
$ssl_csr_file = $install_dir.'/interface/ssl/ispserver.csr';
2433+
$ssl_key_file = $install_dir.'/interface/ssl/ispserver.key';
2434+
$ssl_pem_file = $install_dir.'/interface/ssl/ispserver.pem';
2435+
$ssl_bak_file = $install_dir.'/interface/ssl/ispserver.*.bak';
2436+
2437+
// Delete old then backup existing ispserver ssl files
2438+
if (is_file($ssl_bak_file)) exec("rm $ssl_bak_file");
2439+
if (is_file($ssl_crt_file)) exec("mv $ispccrt $ssl_crt_file-$(date +'%y%m%d%H%M%S).bak");
2440+
if (is_file($ssl_key_file)) exec("mv $ispccrt $ssl_key_file-$(date +'%y%m%d%H%M%S).bak");
2441+
if (is_file($ssl_pem_file)) exec("mv $ispccrt $ssl_pem_file-$(date +'%y%m%d%H%M%S).bak");
2442+
2443+
// Create symlink to LE fullchain and key for ISPConfig
2444+
exec("ln -s $le_live_dir/fullchain.pem $ssl_crt_file");
2445+
exec("ln -s $le_live_dir/privkey.pem $ssl_key_file");
2446+
2447+
// Build ispserver.pem file and chmod it
2448+
exec("cat $ssl_key_file $ssl_crt_file > $ssl_pem_file")
2449+
chmod 600 $ssl_pem_file
2450+
}
2451+
/*
24112452
$ssl_pw = substr(md5(mt_rand()), 0, 6);
24122453
exec("openssl genrsa -des3 -passout pass:$ssl_pw -out $ssl_key_file 4096");
24132454
if(AUTOINSTALL){
@@ -2419,8 +2460,8 @@ public function make_ispconfig_ssl_cert() {
24192460
exec("openssl rsa -passin pass:$ssl_pw -in $ssl_key_file -out $ssl_key_file.insecure");
24202461
rename($ssl_key_file, $ssl_key_file.'.secure');
24212462
rename($ssl_key_file.'.insecure', $ssl_key_file);
2422-
2423-
exec('chown -R root:root /usr/local/ispconfig/interface/ssl');
2463+
*/
2464+
exec("chown -R root:root $install_dir/interface/ssl");
24242465

24252466
}
24262467

0 commit comments

Comments
 (0)