@@ -39,9 +39,14 @@ class Site_Command extends EE_Site_Command {
3939 private $ logger ;
4040
4141 /**
42- * @var bool $le Whether the site is letsencrypt or not .
42+ * @var bool $ssl Whether the site is has SSL enabled .
4343 */
44- private $ le ;
44+ private $ ssl ;
45+
46+ /**
47+ * @var bool $ssl_wildcard Whether the site SSL is wildcard.
48+ */
49+ private $ ssl_wildcard ;
4550
4651 /**
4752 * @var bool $skip_chk To skip site status check pre-installation.
@@ -75,9 +80,11 @@ public function __construct() {
7580 * <site-name>
7681 * : Name of website.
7782 *
78- * [--letsencrypt ]
83+ * [--ssl=<value> ]
7984 * : Enables ssl via letsencrypt certificate.
8085 *
86+ * [--wildcard]
87+ * : Gets wildcard SSL .
8188 * [--type=<type>]
8289 * : Type of the site to be created. Values: html,php,wp.
8390 *
@@ -100,8 +107,9 @@ public function create( $args, $assoc_args ) {
100107 EE ::error ( sprintf ( "Site %1 \$s already exists. If you want to re-create it please delete the older one using: \n`ee site delete %1 \$s` " , $ this ->site ['url ' ] ) );
101108 }
102109
103- $ this ->le = EE \Utils \get_flag_value ( $ assoc_args , 'letsencrypt ' );
104- $ this ->skip_chk = EE \Utils \get_flag_value ( $ assoc_args , 'skip-status-check ' );
110+ $ this ->ssl = EE \Utils \get_flag_value ( $ assoc_args , 'ssl ' );
111+ $ this ->ssl_wildcard = EE \Utils \get_flag_value ( $ assoc_args , 'wildcard ' );
112+ $ this ->skip_chk = EE \Utils \get_flag_value ( $ assoc_args , 'skip-status-check ' );
105113
106114 EE \SiteUtils \init_checks ();
107115
@@ -124,14 +132,18 @@ public function info( $args, $assoc_args ) {
124132 $ args = EE \SiteUtils \auto_site_name ( $ args , 'site ' , __FUNCTION__ );
125133 $ this ->populate_site_info ( $ args );
126134 }
127- $ ssl = $ this ->le ? 'Enabled ' : 'Not Enabled ' ;
128- $ prefix = ( $ this ->le ) ? 'https:// ' : 'http:// ' ;
135+ $ ssl = $ this ->ssl ? 'Enabled ' : 'Not Enabled ' ;
136+ $ prefix = ( $ this ->ssl ) ? 'https:// ' : 'http:// ' ;
129137 $ info = [
130138 [ 'Site ' , $ prefix . $ this ->site ['url ' ] ],
131139 [ 'Site Root ' , $ this ->site ['root ' ] ],
132140 [ 'SSL ' , $ ssl ],
133141 ];
134142
143+ if ( $ this ->ssl ) {
144+ $ info [] = [ 'SSL Wildcard ' , $ this ->ssl_wildcard ? 'Yes ' : 'No ' ];
145+ }
146+
135147 EE \Utils \format_table ( $ info );
136148
137149 EE \Utils \delem_log ( 'site info end ' );
@@ -155,7 +167,6 @@ private function configure_site_files() {
155167
156168 $ filter = [];
157169 $ filter [] = $ this ->site ['type ' ];
158- $ filter [] = $ this ->le ;
159170 $ site_docker = new Site_Docker ();
160171 $ docker_compose_content = $ site_docker ->generate_docker_compose_yml ( $ filter );
161172 $ default_conf_content = $ default_conf_content = EE \Utils \mustache_render ( SITE_TEMPLATE_ROOT . '/config/nginx/default.conf.mustache ' , [ 'server_name ' => $ this ->site ['url ' ] ] );
@@ -182,8 +193,6 @@ private function configure_site_files() {
182193 $ this ->fs ->mkdir ( $ site_src_dir );
183194 $ this ->fs ->dumpFile ( $ site_src_dir . '/index.html ' , $ index_html );
184195
185- EE \Siteutils \add_site_redirects ( $ this ->site ['url ' ], $ this ->le );
186-
187196 EE ::success ( 'Configuration files copied. ' );
188197 } catch ( Exception $ e ) {
189198 $ this ->catch_clean ( $ e );
@@ -198,26 +207,42 @@ private function create_site() {
198207 $ this ->site ['root ' ] = WEBROOT . $ this ->site ['url ' ];
199208 $ this ->level = 1 ;
200209 try {
201- EE \Siteutils \create_site_root ( $ this ->site ['root ' ], $ this ->site ['url ' ] );
210+ EE \SiteUtils \create_site_root ( $ this ->site ['root ' ], $ this ->site ['url ' ] );
202211 $ this ->level = 2 ;
203- EE \Siteutils \setup_site_network ( $ this ->site ['url ' ] );
212+ EE \SiteUtils \setup_site_network ( $ this ->site ['url ' ] );
204213 $ this ->level = 3 ;
205214 $ this ->configure_site_files ();
206215
207- EE \Siteutils \start_site_containers ( $ this ->site ['root ' ] );
216+ EE \SiteUtils \start_site_containers ( $ this ->site ['root ' ] );
208217
209- EE \Siteutils \create_etc_hosts_entry ( $ this ->site ['url ' ] );
218+ EE \SiteUtils \create_etc_hosts_entry ( $ this ->site ['url ' ] );
210219 if ( ! $ this ->skip_chk ) {
211220 $ this ->level = 4 ;
212- EE \Siteutils \site_status_check ( $ this ->site ['url ' ] );
221+ EE \SiteUtils \site_status_check ( $ this ->site ['url ' ] );
222+ }
223+
224+ /*
225+ * This adds http www redirection which is needed for issuing cert for a site.
226+ * i.e. when you create example.com site, certs are issued for example.com and www.example.com
227+ *
228+ * We're issuing certs for both domains as it is needed in order to perform redirection of
229+ * https://www.example.com -> https://example.com
230+ *
231+ * We add redirection config two times in case of ssl as we need http redirection
232+ * when certs are being requested and http+https redirection after we have certs.
233+ */
234+ EE \SiteUtils \add_site_redirects ( $ this ->site ['url ' ], false , 'inherit ' === $ this ->ssl );
235+ EE \SiteUtils \reload_proxy_configuration ();
236+
237+ if ( $ this ->ssl ) {
238+ $ this ->init_ssl ( $ this ->site ['url ' ], $ this ->site ['root ' ], $ this ->ssl , $ this ->ssl_wildcard );
239+ EE \SiteUtils \add_site_redirects ( $ this ->site ['url ' ], true , 'inherit ' === $ this ->ssl );
240+ EE \SiteUtils \reload_proxy_configuration ();
213241 }
214242 } catch ( Exception $ e ) {
215243 $ this ->catch_clean ( $ e );
216244 }
217245
218- if ( $ this ->le ) {
219- $ this ->init_le ( $ this ->site ['url ' ], $ this ->site ['root ' ], false );
220- }
221246 $ this ->info ( [ $ this ->site ['url ' ] ], [] );
222247 $ this ->create_site_db_entry ();
223248 }
@@ -227,13 +252,16 @@ private function create_site() {
227252 */
228253 private function create_site_db_entry () {
229254
230- $ ssl = $ this ->le ? 'letsencrypt ' : null ;
255+ $ ssl = $ this ->ssl ? 1 : 0 ;
256+ $ ssl_wildcard = $ this ->ssl_wildcard ? 1 : 0 ;
231257
232258 $ site = Site::create ([
233- 'site_url ' => $ this ->site ['url ' ],
234- 'site_type ' => $ this ->site ['type ' ],
235- 'site_fs_path ' => $ this ->site ['root ' ],
236- 'site_ssl ' => $ ssl ,
259+ 'site_url ' => $ this ->site ['url ' ],
260+ 'site_type ' => $ this ->site ['type ' ],
261+ 'site_fs_path ' => $ this ->site ['root ' ],
262+ 'site_ssl ' => $ ssl ,
263+ 'site_ssl_wildcard ' => $ ssl_wildcard ,
264+ 'created_on ' => date ( 'Y-m-d H:i:s ' , time () ),
237265 ]);
238266
239267 try {
@@ -259,8 +287,8 @@ private function populate_site_info( $args ) {
259287 if ( $ site ) {
260288 $ this ->site ['type ' ] = $ site ->site_type ;
261289 $ this ->site ['root ' ] = $ site ->site_fs_path ;
262- $ this ->le = $ site ->site_ssl ;
263-
290+ $ this ->ssl = $ site ->site_ssl ;
291+ $ this -> ssl_wildcard = $ site -> site_ssl_wildcard ;
264292 } else {
265293 EE ::error ( sprintf ( 'Site %s does not exist. ' , $ this ->site ['url ' ] ) );
266294 }
0 commit comments