@@ -33,7 +33,6 @@ class installer_base {
3333 var $ wb = array ();
3434 var $ language = 'en ' ;
3535 var $ db ;
36- public $ conf ;
3736 public $ install_ispconfig_interface = true ;
3837 public $ is_update = false ; // true if it is an update, falsi if it is a new install
3938 public $ min_php = '5.3.3 ' ; // minimal php-version for update / install
@@ -42,7 +41,6 @@ class installer_base {
4241
4342 public function __construct () {
4443 global $ conf ; //TODO: maybe $conf should be passed to constructor
45- //$this->conf = $conf;
4644 }
4745
4846 //: TODO Implement the translation function and language files for the installer.
@@ -2720,7 +2718,7 @@ private function curl_request($url, $use_ipv6 = false) {
27202718 return $ response ;
27212719 }
27222720
2723- private function make_acme_vhost ($ server_name , $ server = 'apache ' ) {
2721+ private function make_acme_vhost ($ server_name , $ server = 'apache ' , $ restart = true ) {
27242722 global $ conf ;
27252723
27262724 $ use_template = 'apache_acme.conf.master ' ;
@@ -2758,12 +2756,13 @@ private function make_acme_vhost($server_name, $server = 'apache') {
27582756 if (!@is_link ($ vhost_conf_enabled_dir .'' . $ use_symlink )) {
27592757 symlink ($ vhost_conf_dir .'/ ' . $ use_name , $ vhost_conf_enabled_dir .'/ ' . $ use_symlink );
27602758 }
2761-
2762- if ($ conf [$ server ]['installed ' ] == true && $ conf [$ server ]['init_script ' ] != '' ) {
2763- if ($ this ->is_update ) {
2764- system ($ this ->getinitcommand ($ conf [$ server ]['init_script ' ], 'force-reload ' ).' &> /dev/null || ' . $ this ->getinitcommand ($ conf [$ server ]['init_script ' ], 'restart ' ).' &> /dev/null ' );
2765- } else {
2766- system ($ this ->getinitcommand ($ conf [$ server ]['init_script ' ], 'restart ' ).' &> /dev/null ' );
2759+ if ($ restart === true ) {
2760+ if ($ conf [$ server ]['installed ' ] == true && $ conf [$ server ]['init_script ' ] != '' ) {
2761+ if ($ this ->is_update ) {
2762+ system ($ this ->getinitcommand ($ conf [$ server ]['init_script ' ], 'force-reload ' ).' &> /dev/null || ' . $ this ->getinitcommand ($ conf [$ server ]['init_script ' ], 'restart ' ).' &> /dev/null ' );
2763+ } else {
2764+ system ($ this ->getinitcommand ($ conf [$ server ]['init_script ' ], 'restart ' ).' &> /dev/null ' );
2765+ }
27672766 }
27682767 }
27692768 }
@@ -2822,6 +2821,8 @@ public function make_ispconfig_ssl_cert() {
28222821
28232822 // Request for certs if no LE SSL folder for server fqdn exist
28242823
2824+ swriteln ('Checking / creating certificate for ' . $ hostname );
2825+
28252826 $ acme_cert_dir = '/usr/local/ispconfig/server/scripts/ ' . $ hostname ;
28262827 $ check_acme_file = $ acme_cert_dir . '/ ' . $ hostname . '.cer ' ;
28272828 if (!@is_dir ($ acme_cert_dir )) {
@@ -2832,6 +2833,13 @@ public function make_ispconfig_ssl_cert() {
28322833 $ check_acme_file = $ acme_cert_dir . '/cert.pem ' ;
28332834 }
28342835 }
2836+
2837+ swriteln ('Using certificate path ' . $ acme_cert_dir );
2838+ if (!(($ svr_ip4 && in_array ($ svr_ip4 , $ dns_ips )) || ($ svr_ip6 && in_array ($ svr_ip6 , $ dns_ips )))) {
2839+ swriteln ('Server \'s public ip(s) ( ' . $ svr_ip4 . ($ svr_ip6 ? ', ' . $ svr_ip6 : '' ) . ') not found in A/AAAA records for ' . $ hostname . ': ' . implode (', ' , $ dns_ips ));
2840+ }
2841+
2842+
28352843 if ((!@is_dir ($ acme_cert_dir ) || !@file_exists ($ check_acme_file ) || !@file_exists ($ ssl_crt_file ) || md5_file ($ check_acme_file ) != md5_file ($ ssl_crt_file )) && (($ svr_ip4 && in_array ($ svr_ip4 , $ dns_ips )) || ($ svr_ip6 && in_array ($ svr_ip6 , $ dns_ips )))) {
28362844
28372845 // This script is needed earlier to check and open http port 80 or standalone might fail
@@ -2881,8 +2889,10 @@ public function make_ispconfig_ssl_cert() {
28812889
28822890 // first of all create the acme vhosts if not existing
28832891 if ($ conf ['nginx ' ]['installed ' ] == true ) {
2892+ swriteln ('Using nginx for certificate validation ' );
28842893 $ this ->make_acme_vhost ($ hostname , 'nginx ' );
28852894 } elseif ($ conf ['apache ' ]['installed ' ] == true ) {
2895+ swriteln ('Using apache for certificate validation ' );
28862896 if ($ this ->is_update == false && @is_link ($ vhost_conf_enabled_dir .'/000-ispconfig.conf ' )) {
28872897 $ restore_conf_symlink = true ;
28882898 unlink ($ vhost_conf_enabled_dir .'/000-ispconfig.conf ' );
@@ -2899,7 +2909,7 @@ public function make_ispconfig_ssl_cert() {
28992909 $ out = null ;
29002910 $ ret = null ;
29012911 if ($ conf ['nginx ' ]['installed ' ] == true || $ conf ['apache ' ]['installed ' ] == true ) {
2902- exec ("$ acme --issue -w /usr/local/ispconfig/interface/acme -d $ hostname $ renew_hook " , $ out , $ ret );
2912+ exec ("$ acme --issue -w /usr/local/ispconfig/interface/acme -d " . escapeshellarg ( $ hostname) . " $ renew_hook " , $ out , $ ret );
29032913 }
29042914 // Else, it is not webserver, so we use standalone
29052915 else {
@@ -2909,6 +2919,7 @@ public function make_ispconfig_ssl_cert() {
29092919 if ($ ret == 0 || ($ ret == 2 && file_exists ($ check_acme_file ))) {
29102920 // acme.sh returns with 2 on issue for already existing certificate
29112921
2922+
29122923 // Backup existing ispserver ssl files
29132924 if (file_exists ($ ssl_crt_file ) || is_link ($ ssl_crt_file )) {
29142925 rename ($ ssl_crt_file , $ ssl_crt_file . '- ' . $ date ->format ('YmdHis ' ) . '.bak ' );
@@ -2924,8 +2935,10 @@ public function make_ispconfig_ssl_cert() {
29242935 //$acme_cert = "--cert-file $acme_cert_dir/cert.pem";
29252936 $ acme_key = "--key-file " . escapeshellarg ($ ssl_key_file );
29262937 $ acme_chain = "--fullchain-file " . escapeshellarg ($ ssl_crt_file );
2927- exec ("$ acme --install-cert -d $ hostname $ acme_key $ acme_chain " );
2938+ exec ("$ acme --install-cert -d " . escapeshellarg ( $ hostname) . " $ acme_key $ acme_chain " );
29282939 $ issued_successfully = true ;
2940+ } else {
2941+ swriteln ('Issuing certificate via acme.sh failed. Please check that your hostname can be verified by letsencrypt ' );
29292942 }
29302943 // Else, we attempt to use the official LE certbot client certbot
29312944 } else {
@@ -2947,11 +2960,11 @@ public function make_ispconfig_ssl_cert() {
29472960
29482961 // If this is a webserver
29492962 if ($ conf ['nginx ' ]['installed ' ] == true || $ conf ['apache ' ]['installed ' ] == true ) {
2950- exec ("$ le_client $ certonly $ acme_version --authenticator webroot --webroot-path /usr/local/ispconfig/interface/acme --email " . escapeshellarg ('postmaster@$hostname ' ) . " -d " . escapeshellarg ($ hostname ) . " $ renew_hook " , $ out , $ ret );
2963+ exec ("$ le_client $ certonly $ acme_version --authenticator webroot --webroot-path /usr/local/ispconfig/interface/acme --email " . escapeshellarg ('postmaster@ ' . $ hostname ) . " -d " . escapeshellarg ($ hostname ) . " $ renew_hook " , $ out , $ ret );
29512964 }
29522965 // Else, it is not webserver, so we use standalone
29532966 else {
2954- exec ("$ le_client $ certonly $ acme_version --standalone --email " . escapeshellarg ('postmaster@$hostname ' ) . " -d " . escapeshellarg ($ hostname ) . " $ hook " , $ out , $ ret );
2967+ exec ("$ le_client $ certonly $ acme_version --standalone --email " . escapeshellarg ('postmaster@ ' . $ hostname ) . " -d " . escapeshellarg ($ hostname ) . " $ hook " , $ out , $ ret );
29552968 }
29562969
29572970 if ($ ret == 0 ) {
@@ -2969,7 +2982,11 @@ public function make_ispconfig_ssl_cert() {
29692982 }
29702983
29712984 $ issued_successfully = true ;
2985+ } else {
2986+ swriteln ('Issuing certificate via certbot failed. Please check log files and make sure that your hostname can be verified by letsencrypt ' );
29722987 }
2988+ } else {
2989+ swriteln ('Did not find any valid acme client (acme.sh or certbot) ' );
29732990 }
29742991 }
29752992
@@ -2978,13 +2995,24 @@ public function make_ispconfig_ssl_cert() {
29782995 symlink ($ vhost_conf_dir .'/ispconfig.conf ' , $ vhost_conf_enabled_dir .'/000-ispconfig.conf ' );
29792996 }
29802997 }
2981- } elseif (($ svr_ip4 && in_array ($ svr_ip4 , $ dns_ips )) || ($ svr_ip6 && in_array ($ svr_ip6 , $ dns_ips ))) {
2982- // the directory already exists so we have to assume that it was created previously
2983- $ issued_successfully = true ;
2998+ } else {
2999+ if ($ conf ['apache ' ]['installed ' ] == true ) {
3000+ $ this ->make_acme_vhost ($ hostname , 'apache ' , false ); // we need this config file but we don't want apache to be restarted at this point
3001+ }
3002+ if (($ svr_ip4 && in_array ($ svr_ip4 , $ dns_ips )) || ($ svr_ip6 && in_array ($ svr_ip6 , $ dns_ips ))) {
3003+ // the directory already exists so we have to assume that it was created previously
3004+ $ issued_successfully = true ;
3005+ }
29843006 }
29853007
29863008 // If the LE SSL certs for this hostname exists
29873009 if (!is_dir ($ acme_cert_dir ) || !file_exists ($ check_acme_file ) || !$ issued_successfully ) {
3010+ if (!$ issued_successfully ) {
3011+ swriteln ('Could not issue letsencrypt certificate, falling back to self-signed. ' );
3012+ } else {
3013+ swriteln ('Issuing certificate seems to have succeeded but ' . $ check_acme_file . ' seems to be missing. Falling back to self-signed. ' );
3014+ }
3015+
29883016 // We can still use the old self-signed method
29893017 $ ssl_pw = substr (md5 (mt_rand ()), 0 , 6 );
29903018 exec ("openssl genrsa -des3 -passout pass: $ ssl_pw -out $ ssl_key_file 4096 " );
0 commit comments