Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/helper/class-ee-site.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ protected function delete_site( $level, $site_url, $site_fs_path, $db_data = []
* [--wildcard]
* : Enable wildcard SSL on site.
*
* [--ssl-key=<ssl-key-path>]
* : Path to the SSL key file. Required with --ssl=custom.
*
* [--ssl-crt=<ssl-crt-path>]
* : Path to the SSL crt file. Required with --ssl=custom.
*
* [--php=<php-version>]
* : PHP version for site. Currently only supports PHP 5.6, 7.0, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, and 8.5.
* ---
Expand Down Expand Up @@ -471,6 +477,9 @@ protected function delete_site( $level, $site_url, $site_fs_path, $db_data = []
* # Add self-signed SSL to non-ssl site
* $ ee site update example.com --ssl=self
*
* # Add custom SSL to non-ssl site
* $ ee site update example.com --ssl=custom --ssl-key=/path/to/site.key --ssl-crt=/path/to/site.crt
*
* # Update PHP version of site.
* $ ee site update example.com --php=8.0
*
Expand Down Expand Up @@ -937,6 +946,11 @@ protected function update_ssl( $assoc_args ) {
$this->site_data['site_ssl'] = $ssl;

if ( $ssl ) {
// www_ssl_wrapper() skips cert work for custom SSL, so validate and copy the provided pair first.
if ( 'custom' === $ssl ) {
$this->validate_site_custom_ssl( get_flag_value( $assoc_args, 'ssl-key' ), get_flag_value( $assoc_args, 'ssl-crt' ) );
$this->custom_site_ssl();
}
$this->www_ssl_wrapper( [ 'nginx' ] );
} else {
$this->disable_ssl();
Expand Down Expand Up @@ -2265,8 +2279,13 @@ protected function custom_site_ssl() {
$ssl_key_dest = sprintf( '%1$s/nginx-proxy/certs/%2$s.key', remove_trailing_slash( EE_SERVICE_DIR ), $this->site_data['site_url'] );
$ssl_crt_dest = sprintf( '%1$s/nginx-proxy/certs/%2$s.crt', remove_trailing_slash( EE_SERVICE_DIR ), $this->site_data['site_url'] );

$this->fs->copy( $this->site_data['ssl_key'], $ssl_key_dest, true );
$this->fs->copy( $this->site_data['ssl_crt'], $ssl_crt_dest, true );
// Copying a file onto itself truncates it, e.g. when re-enabling SSL with the files already in the certs dir.
if ( realpath( $ssl_key_dest ) !== $this->site_data['ssl_key'] ) {
$this->fs->copy( $this->site_data['ssl_key'], $ssl_key_dest, true );
}
if ( realpath( $ssl_crt_dest ) !== $this->site_data['ssl_crt'] ) {
$this->fs->copy( $this->site_data['ssl_crt'], $ssl_crt_dest, true );
}
}

/**
Expand Down
Loading