Skip to content

Commit 5bf8371

Browse files
author
Marius Burkard
committed
Merge branch 'ahrasis/ispconfig3-patch-1'
2 parents ae7f217 + d74f0ad commit 5bf8371

File tree

3 files changed

+134
-13
lines changed

3 files changed

+134
-13
lines changed

install/install.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,12 @@
552552
$inst->install_ispconfig_interface = false;
553553
}
554554

555+
// Create SSL certs for non-webserver(s)?
556+
if(!file_exists(/usr/local/ispconfig/interface/ssl/ispserver.crt)) {
557+
if(strtolower($inst->simple_query('Do you want to create SSL certs for your server?', array('y', 'n'), 'y')) == 'y')
558+
$inst->make_ispconfig_ssl_cert();
559+
}
560+
555561
$inst->raiseEvent('install_ispconfig::before');
556562
$inst->install_ispconfig();
557563
$inst->raiseEvent('install_ispconfig::after');

install/lib/installer_base.lib.php

Lines changed: 122 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*
4-
Copyright (c) 2007-2010, Till Brehm, projektfarm Gmbh
4+
Copyright (c) 2007-2018, Till Brehm, projektfarm Gmbh, Hj Ahmad Rasyid Hj Ismail
55
All rights reserved.
66
77
Redistribution and use in source and binary forms, with or without modification,
@@ -938,6 +938,9 @@ public function configure_postfix($options = '') {
938938
caselog($command." &> /dev/null", __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
939939
}
940940

941+
//** We have to change the permissions of the courier authdaemon directory to make it accessible for maildrop.
942+
$command = 'chmod 755 /var/run/courier/authdaemon/';
943+
if(is_file('/var/run/courier/authdaemon/')) caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
941944
if(!stristr($options, 'dont-create-certs')) {
942945
//* Create the SSL certificate
943946
if(AUTOINSTALL){
@@ -2048,29 +2051,135 @@ public function configure_apps_vhost() {
20482051
}
20492052

20502053
public function make_ispconfig_ssl_cert() {
2051-
global $conf,$autoinstall;
2054+
global $conf, $autoinstall;
2055+
2056+
//* Get hostname from user entry or shell command */
2057+
if($conf['hostname'] !== ('localhost' || '')) $hostname = $conf['hostname'];
2058+
else $hostname = exec('hostname -f');
2059+
2060+
// Check dns a record exist and its ip equal to server public ip
2061+
$svr_ip = file_get_contents('http://dynamicdns.park-your-domain.com/getip');
2062+
if (checkdnsrr(idn_to_ascii($hostname, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46), 'A')) {
2063+
$dnsa=dns_get_record($hostname, DNS_A);
2064+
$dns_ips = array();
2065+
foreach ($dnsa as $rec) {
2066+
$dns_ips[] = $rec['ip'];
2067+
}
2068+
}
2069+
2070+
// Request for certs if no LE SSL folder for server fqdn exist
2071+
$le_live_dir = '/etc/letsencrypt/live/' . $hostname;
2072+
if (!@is_dir($le_live_dir) && in_array($svr_ip, $dns_ips)) {
20522073

2074+
// Get the default LE client name and version
2075+
$le_client = explode("\n", shell_exec('which letsencrypt certbot /root/.local/share/letsencrypt/bin/letsencrypt /opt/eff.org/certbot/venv/bin/certbot'));
2076+
$le_client = reset($le_client);
2077+
$le_info = exec($le_client . ' --version 2>&1', $ret, $val);
2078+
if(preg_match('/^(\S+|\w+)\s+(\d+(\.\d+)+)$/', $le_info, $matches)) { $le_name = $matches[1]; $le_version = $matches[2]; }
2079+
2080+
// Define certbot commands
2081+
$acme_version = '--server https://acme-v0' . (($le_version >=0.22) ? '2' : '1') . '.api.letsencrypt.org/directory';
2082+
$certonly = 'certonly --agree-tos --non-interactive --expand --rsa-key-size 4096';
2083+
$webroot = '--authenticator webroot --webroot-path /var/www/html';
2084+
$standalone = '--authenticator standalone';
2085+
2086+
// Only certbot is supported to prevent unknown failures
2087+
if($le_name == 'certbot' && is_executable($le_client)) {
2088+
// If this is a webserver, we use webroot
2089+
if(($conf['nginx']['installed'] || $conf['apache']['installed']) == true) {
2090+
$well_known = '/var/www/html/.well-known';
2091+
$challenge = "$well_known/acme_challenge";
2092+
$acme_challenge = '/usr/local/ispconfig/interface/acme/.well-known/acme-challenge';
2093+
if (!is_dir($well_known)) mkdir($well_known, 0755, true);
2094+
if (!is_dir($challenge)) exec("ln -sf $acme_challenge $challenge");
2095+
exec("$le_client $certonly $acme_version $webroot --email postmaster@$hostname -d $hostname");
2096+
}
2097+
// Else, it is not webserver, so we use standalone
2098+
else
2099+
exec("$le_client $certonly $acme_version $standalone --email postmaster@$hostname -d $hostname");
2100+
}
2101+
}
2102+
2103+
//* Define and check ISPConfig SSL folder */
20532104
$install_dir = $conf['ispconfig_install_dir'];
20542105

20552106
$ssl_crt_file = $install_dir.'/interface/ssl/ispserver.crt';
20562107
$ssl_csr_file = $install_dir.'/interface/ssl/ispserver.csr';
20572108
$ssl_key_file = $install_dir.'/interface/ssl/ispserver.key';
2109+
$ssl_pem_file = $install_dir.'/interface/ssl/ispserver.pem';
20582110

20592111
if(!@is_dir($install_dir.'/interface/ssl')) mkdir($install_dir.'/interface/ssl', 0755, true);
20602112

2061-
$ssl_pw = substr(md5(mt_rand()), 0, 6);
2062-
exec("openssl genrsa -des3 -passout pass:$ssl_pw -out $ssl_key_file 4096");
2063-
if(AUTOINSTALL){
2064-
exec("openssl req -new -passin pass:$ssl_pw -passout pass:$ssl_pw -subj '/C=".escapeshellcmd($autoinstall['ssl_cert_country'])."/ST=".escapeshellcmd($autoinstall['ssl_cert_state'])."/L=".escapeshellcmd($autoinstall['ssl_cert_locality'])."/O=".escapeshellcmd($autoinstall['ssl_cert_organisation'])."/OU=".escapeshellcmd($autoinstall['ssl_cert_organisation_unit'])."/CN=".escapeshellcmd($autoinstall['ssl_cert_common_name'])."' -key $ssl_key_file -out $ssl_csr_file");
2113+
$date = new DateTime();
2114+
2115+
// If the LE SSL certs for this hostname exists
2116+
if (is_dir($le_live_dir) && in_array($svr_ip, $dns_ips)) {
2117+
2118+
// Backup existing ispserver ssl files
2119+
if (file_exists($ssl_crt_file)) rename($ssl_crt_file, $ssl_crt_file . '-' .$date->format('YmdHis') . '.bak');
2120+
if (file_exists($ssl_crt_file)) rename($ssl_key_file, $ssl_key_file . '-' .$date->format('YmdHis') . '.bak');
2121+
if (file_exists($ssl_crt_file)) rename($ssl_pem_file, $ssl_pem_file . '-' .$date->format('YmdHis') . '.bak');
2122+
2123+
// Create symlink to LE fullchain and key for ISPConfig
2124+
symlink($le_live_dir.'/fullchain.pem', $ssl_crt_file);
2125+
symlink($le_live_dir.'/privkey.pem', $ssl_key_file);
2126+
20652127
} else {
2066-
exec("openssl req -new -passin pass:$ssl_pw -passout pass:$ssl_pw -key $ssl_key_file -out $ssl_csr_file");
2067-
}
2068-
exec("openssl req -x509 -passin pass:$ssl_pw -passout pass:$ssl_pw -key $ssl_key_file -in $ssl_csr_file -out $ssl_crt_file -days 3650");
2069-
exec("openssl rsa -passin pass:$ssl_pw -in $ssl_key_file -out $ssl_key_file.insecure");
2070-
rename($ssl_key_file, $ssl_key_file.'.secure');
2071-
rename($ssl_key_file.'.insecure', $ssl_key_file);
20722128

2073-
exec('chown -R root:root /usr/local/ispconfig/interface/ssl');
2129+
// We can still use the old self-signed method
2130+
$ssl_pw = substr(md5(mt_rand()), 0, 6);
2131+
exec("openssl genrsa -des3 -passout pass:$ssl_pw -out $ssl_key_file 4096");
2132+
if(AUTOINSTALL){
2133+
exec("openssl req -new -passin pass:$ssl_pw -passout pass:$ssl_pw -subj '/C=".escapeshellcmd($autoinstall['ssl_cert_country'])."/ST=".escapeshellcmd($autoinstall['ssl_cert_state'])."/L=".escapeshellcmd($autoinstall['ssl_cert_locality'])."/O=".escapeshellcmd($autoinstall['ssl_cert_organisation'])."/OU=".escapeshellcmd($autoinstall['ssl_cert_organisation_unit'])."/CN=".escapeshellcmd($autoinstall['ssl_cert_common_name'])."' -key $ssl_key_file -out $ssl_csr_file");
2134+
} else {
2135+
exec("openssl req -new -passin pass:$ssl_pw -passout pass:$ssl_pw -key $ssl_key_file -out $ssl_csr_file");
2136+
}
2137+
exec("openssl req -x509 -passin pass:$ssl_pw -passout pass:$ssl_pw -key $ssl_key_file -in $ssl_csr_file -out $ssl_crt_file -days 3650");
2138+
exec("openssl rsa -passin pass:$ssl_pw -in $ssl_key_file -out $ssl_key_file.insecure");
2139+
rename($ssl_key_file, $ssl_key_file.'.secure');
2140+
rename($ssl_key_file.'.insecure', $ssl_key_file);
2141+
}
2142+
2143+
// Build ispserver.pem file and chmod it
2144+
exec("cat $ssl_key_file $ssl_crt_file > $ssl_pem_file; chmod 600 $ssl_pem_file");
2145+
2146+
// Extend LE SSL certs to postfix
2147+
if ($conf['postfix']['installed'] == true && strtolower($this->simple_query('Symlink ISPConfig LE SSL certs to postfix?', array('y', 'n'), 'y')) == 'y') {
2148+
2149+
// Define folder, file(s)
2150+
$cf = $conf['postfix'];
2151+
$postfix_dir = $cf['config_dir'];
2152+
if(!is_dir($postfix_dir)) $this->error("The postfix configuration directory '$postfix_dir' does not exist.");
2153+
$smtpd_crt = $postfix_dir.'/smtpd.cert';
2154+
$smtpd_key = $postfix_dir.'/smtpd.key';
2155+
2156+
// Backup existing postfix ssl files
2157+
if (file_exists($smtpd_crt)) rename($smtpd_crt, $smtpd_crt . '-' .$date->format('YmdHis') . '.bak');
2158+
if (file_exists($smtpd_key)) rename($smtpd_key, $smtpd_key . '-' .$date->format('YmdHis') . '.bak');
2159+
2160+
// Create symlink to ISPConfig SSL files
2161+
symlink($ssl_crt_file, $smtpd_crt);
2162+
symlink($ssl_key_file, $smtpd_key);
2163+
}
2164+
2165+
// Extend LE SSL certs to pureftpd
2166+
if ($conf['pureftpd']['installed'] == true && strtolower($this->simple_query('Symlink ISPConfig LE SSL certs to pureftpd? Creating dhparam file takes some times.', array('y', 'n'), 'y')) == 'y') {
2167+
2168+
// Define folder, file(s)
2169+
$pureftpd_dir = '/etc/ssl/private';
2170+
if(!is_dir($pureftpd_dir)) mkdir($pureftpd_dir, 0755, true);
2171+
$pureftpd_pem = $pureftpd_dir.'/pure-ftpd.pem';
2172+
2173+
// Backup existing pureftpd ssl files
2174+
if (file_exists($pureftpd_pem)) rename($pureftpd_pem, $pureftpd_pem . '-' .$date->format('YmdHis') . '.bak');
2175+
2176+
// Create symlink to ISPConfig SSL files
2177+
symlink($ssl_pem_file, $pureftpd_pem);
2178+
if (!file_exists("$pureftpd_dir/pure-ftpd-dhparams.pem"))
2179+
exec("cd $pureftpd_dir; openssl dhparam -out dhparam4096.pem 4096; ln -sf dhparam4096.pem pure-ftpd-dhparams.pem");
2180+
}
2181+
2182+
exec("chown -R root:root $install_dir/interface/ssl");
20742183

20752184
}
20762185

install/update.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,12 @@
503503
}
504504
}
505505

506+
// Create SSL certs for non-webserver(s)?
507+
if(!file_exists(/usr/local/ispconfig/interface/ssl/ispserver.crt)) {
508+
if(strtolower($inst->simple_query('Do you want to create SSL certs for your server?', array('y', 'n'), 'y')) == 'y')
509+
$inst->make_ispconfig_ssl_cert();
510+
}
511+
506512
$inst->raiseEvent('install_ispconfig::before');
507513
$inst->install_ispconfig();
508514
$inst->raiseEvent('install_ispconfig::after');

0 commit comments

Comments
 (0)