From 98aef725ac2933a4ac1f65733efdfad32dd31518 Mon Sep 17 00:00:00 2001 From: sagarnasit Date: Mon, 17 Dec 2018 19:41:00 +0530 Subject: [PATCH 1/2] Add parent site ssl certificate check before site creation --- src/helper/class-ee-site.php | 9 +++------ src/site-type/html.php | 4 ++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/helper/class-ee-site.php b/src/helper/class-ee-site.php index 16a76848..a514b392 100644 --- a/src/helper/class-ee-site.php +++ b/src/helper/class-ee-site.php @@ -727,7 +727,7 @@ protected function www_ssl_wrapper( $containers_to_start = [], $site_enable = fa * * @throws \Exception */ - protected function inherit_certs( $site_url ) { + protected function check_parent_site_certs( $site_url ) { $parent_site_name = implode( '.', array_slice( explode( '.', $site_url ), 1 ) ); $parent_site = Site::find( $parent_site_name, [ 'site_ssl', 'site_ssl_wildcard' ] ); @@ -743,9 +743,6 @@ protected function inherit_certs( $site_url ) { if ( ! $parent_site->site_ssl_wildcard ) { throw new \Exception( "Cannot inherit from $parent_site_name as site does not have wildcard SSL cert" ); } - - // We don't have to do anything now as nginx-proxy handles everything for us. - \EE::success( 'Inherited certs from parent' ); } /** @@ -770,8 +767,8 @@ protected function init_ssl( $site_url, $site_fs_path, $ssl_type, $wildcard = fa if ( $wildcard ) { throw new \Exception( 'Cannot use --wildcard with --ssl=inherit', false ); } - \EE::debug( 'Inheriting certs' ); - $this->inherit_certs( $site_url ); + // We don't have to do anything now as nginx-proxy handles everything for us. + \EE::success( 'Inherited certs from parent' ); } elseif ( 'self' === $ssl_type ) { $client = new Site_Self_signed(); $client->create_certificate( $site_url ); diff --git a/src/site-type/html.php b/src/site-type/html.php index 815684cf..6a694c37 100644 --- a/src/site-type/html.php +++ b/src/site-type/html.php @@ -262,6 +262,10 @@ private function create_site() { $this->site_data['site_fs_path'] = WEBROOT . $this->site_data['site_url']; $this->level = 1; try { + if ( 'inherit' === $this->site_data['site_ssl'] ) { + $this->check_parent_site_certs( $this->site_data['site_url'] ); + } + \EE\Site\Utils\create_site_root( $this->site_data['site_fs_path'], $this->site_data['site_url'] ); $this->level = 3; $this->configure_site_files(); From 92e1f322df44bc98659ad04f8312244f08a46d72 Mon Sep 17 00:00:00 2001 From: sagarnasit Date: Mon, 24 Dec 2018 11:26:26 +0530 Subject: [PATCH 2/2] Fix EE namespace use --- src/helper/class-ee-site.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helper/class-ee-site.php b/src/helper/class-ee-site.php index 2d3e6855..591604d9 100644 --- a/src/helper/class-ee-site.php +++ b/src/helper/class-ee-site.php @@ -769,7 +769,7 @@ protected function init_ssl( $site_url, $site_fs_path, $ssl_type, $wildcard = fa throw new \Exception( 'Cannot use --wildcard with --ssl=inherit', false ); } // We don't have to do anything now as nginx-proxy handles everything for us. - \EE::success( 'Inherited certs from parent' ); + EE::success( 'Inherited certs from parent' ); } elseif ( 'self' === $ssl_type ) { $client = new Site_Self_signed(); $client->create_certificate( $site_url );