Skip to content

Commit 5ce7598

Browse files
committed
Create new stage failed ssl to prevent domain without valid ssl certs from being active
1 parent 2da607b commit 5ce7598

File tree

9 files changed

+72
-37
lines changed

9 files changed

+72
-37
lines changed

inc/apis/schemas/domain-create.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// Exit if accessed directly
1010
defined('ABSPATH') || exit;
1111

12+
use WP_Ultimo\Database\Domains\Domain_Stage;
13+
1214
/**
1315
* Schema for domain@create.
1416
*
@@ -49,11 +51,12 @@
4951
'type' => 'string',
5052
'required' => true,
5153
'enum' => [
52-
'checking-dns',
53-
'checking-ssl-cert',
54-
'done-without-ssl',
55-
'done',
56-
'failed',
54+
Domain_Stage::CHECKING_DNS,
55+
Domain_Stage::CHECKING_SSL,
56+
Domain_Stage::DONE_WITHOUT_SSL,
57+
Domain_Stage::DONE,
58+
Domain_Stage::FAILED,
59+
Domain_Stage::SSL_FAILED,
5760
],
5861
],
5962
'date_created' => [

inc/apis/schemas/domain-update.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// Exit if accessed directly
1010
defined('ABSPATH') || exit;
1111

12+
use WP_Ultimo\Database\Domains\Domain_Stage;
13+
1214
/**
1315
* Schema for domain@update.
1416
*
@@ -49,11 +51,12 @@
4951
'type' => 'string',
5052
'required' => false,
5153
'enum' => [
52-
'checking-dns',
53-
'checking-ssl-cert',
54-
'done-without-ssl',
55-
'done',
56-
'failed',
54+
Domain_Stage::CHECKING_DNS,
55+
Domain_Stage::CHECKING_SSL,
56+
Domain_Stage::DONE_WITHOUT_SSL,
57+
Domain_Stage::DONE,
58+
Domain_Stage::FAILED,
59+
Domain_Stage::SSL_FAILED,
5760
],
5861
],
5962
'date_created' => [

inc/class-faker.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Exception;
1313
use Faker as Lib_Faker;
14+
use WP_Ultimo\Database\Domains\Domain_Stage;
1415
use WP_Ultimo\Models\Membership;
1516
use WP_Ultimo\Models\Product;
1617

@@ -184,6 +185,7 @@ private function get_random_data($model) {
184185
return false;
185186
}
186187
}
188+
return false;
187189
}
188190

189191
/**
@@ -481,9 +483,9 @@ public function generate_fake_domain($number = 1): void {
481483

482484
$faker = $this->get_faker();
483485
$stage_options = [
484-
'checking-dns',
485-
'checking-ssl-cert',
486-
'done',
486+
Domain_Stage::CHECKING_DNS,
487+
Domain_Stage::CHECKING_SSL,
488+
Domain_Stage::DONE,
487489
];
488490

489491
$stage_checking_dns = $stage_options[0];

inc/database/domains/class-domain-stage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Domain_Stage extends Enum {
2828

2929
const FAILED = 'failed';
3030

31+
const SSL_FAILED = 'ssl-failed';
32+
3133
const CHECKING_DNS = 'checking-dns';
3234

3335
const CHECKING_SSL = 'checking-ssl-cert';
@@ -46,6 +48,7 @@ protected function classes() {
4648

4749
return [
4850
static::FAILED => 'wu-bg-red-200 wu-text-red-700',
51+
static::SSL_FAILED => 'wu-bg-red-200 wu-text-red-700',
4952
static::CHECKING_DNS => 'wu-bg-blue-200 wu-text-blue-700',
5053
static::CHECKING_SSL => 'wu-bg-yellow-200 wu-text-yellow-700',
5154
static::DONE => 'wu-bg-green-200 wu-text-green-700',
@@ -63,6 +66,7 @@ protected function labels() {
6366

6467
return [
6568
static::FAILED => __('DNS Failed', 'ultimate-multisite'),
69+
static::SSL_FAILED => __('SSL Failed', 'ultimate-multisite'),
6670
static::CHECKING_DNS => __('Checking DNS', 'ultimate-multisite'),
6771
static::CHECKING_SSL => __('Checking SSL', 'ultimate-multisite'),
6872
static::DONE => __('Ready', 'ultimate-multisite'),

inc/database/domains/class-domains-schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Domains_Schema extends Schema {
9090

9191
[
9292
'name' => 'stage',
93-
'type' => 'enum(\'checking-dns\', \'checking-ssl-cert\', \'done-without-ssl\', \'done\', \'failed\')',
93+
'type' => 'enum(\'' . Domain_Stage::CHECKING_DNS . '\', \'' . Domain_Stage::CHECKING_SSL . '\', \'' . Domain_Stage::DONE_WITHOUT_SSL . '\', \'' . Domain_Stage::DONE . '\', \'' . Domain_Stage::FAILED . '\', \'' . Domain_Stage::SSL_FAILED . '\')',
9494
'default' => 'checking-dns',
9595
'transition' => true,
9696
'sortable' => true,

inc/database/domains/class-domains-table.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,18 @@ final class Domains_Table extends Table {
4343
* @since 2.0.0
4444
* @var string
4545
*/
46-
protected $version = '2.0.1-revision.20230601';
46+
protected $version = '2.0.1-revision.20260109';
4747

4848
/**
49-
* List of table upgrades.
50-
*
51-
* @var array
49+
* Use real callbacks.
5250
*/
53-
protected $upgrades = [
54-
'2.0.1-revision.20230601' => 20_230_601,
55-
];
56-
51+
public function __construct() {
52+
$this->upgrades = [
53+
'2.0.1-revision.20230601' => [$this, 'allow_nulls'],
54+
'2.0.1-revision.20260109' => [$this, 'update_enum'],
55+
];
56+
parent::__construct();
57+
}
5758

5859
/**
5960
* Set up the database schema
@@ -70,7 +71,7 @@ protected function set_schema(): void {
7071
active tinyint(4) default 1,
7172
primary_domain tinyint(4) default 0,
7273
secure tinyint(4) default 0,
73-
stage enum('checking-dns', 'checking-ssl-cert', 'done', 'failed', 'done-without-ssl') DEFAULT 'checking-dns',
74+
stage enum('" . Domain_Stage::CHECKING_DNS . "', '" . Domain_Stage::CHECKING_SSL . "', '" . Domain_Stage::DONE_WITHOUT_SSL . "', '" . Domain_Stage::DONE . "', '" . Domain_Stage::FAILED . "', '" . Domain_Stage::SSL_FAILED . "')) DEFAULT '" . Domain_Stage::CHECKING_DNS . "',
7475
date_created datetime NULL,
7576
date_modified datetime NULL,
7677
PRIMARY KEY (id),
@@ -83,7 +84,7 @@ protected function set_schema(): void {
8384
*
8485
* @since 2.1.2
8586
*/
86-
protected function __20230601(): bool { // phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore
87+
protected function allow_nulls(): bool {
8788

8889
$null_columns = [
8990
'date_created',
@@ -102,4 +103,22 @@ protected function __20230601(): bool { // phpcs:ignore PHPCompatibility.Functio
102103

103104
return true;
104105
}
106+
107+
/**
108+
* Adds the ssl-failed stage
109+
*
110+
* @since 2.4.10
111+
*/
112+
protected function update_enum(): bool { // phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore
113+
114+
$query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `stage` enum('" . Domain_Stage::CHECKING_DNS . "', '" . Domain_Stage::CHECKING_SSL . "', '" . Domain_Stage::DONE_WITHOUT_SSL . "', '" . Domain_Stage::DONE . "', '" . Domain_Stage::FAILED . "', '" . Domain_Stage::SSL_FAILED . "') DEFAULT '" . Domain_Stage::CHECKING_DNS . "';";
115+
116+
$result = $this->get_db()->query($query);
117+
118+
if ( ! $this->is_success($result)) {
119+
return false;
120+
}
121+
122+
return true;
123+
}
105124
}

inc/integrations/host-providers/class-wpmudev-host-provider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace WP_Ultimo\Integrations\Host_Providers;
1111

1212
use Psr\Log\LogLevel;
13+
use WP_Ultimo\Database\Domains\Domain_Stage;
1314
use WP_Ultimo\Integrations\Host_Providers\Base_Host_Provider;
1415

1516
// Exit if accessed directly
@@ -99,7 +100,7 @@ public function ssl_tries($max_tries, $domain) {
99100
return $max_tries;
100101
}
101102

102-
if ('checking-ssl-cert' === $domain->get_stage()) {
103+
if (Domain_Stage::CHECKING_SSL === $domain->get_stage()) {
103104
$max_tries = 10;
104105
}
105106

inc/managers/class-domain-manager.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace WP_Ultimo\Managers;
1414

1515
use Psr\Log\LogLevel;
16+
use WP_Ultimo\Database\Domains\Domain_Stage;
1617
use WP_Ultimo\Domain_Mapping\Helper;
1718
use WP_Ultimo\Models\Domain;
1819

@@ -664,9 +665,9 @@ public function async_process_domain_stage($domain_id, $tries = 0): void {
664665
// translators: %s is the domain name
665666
wu_log_add("domain-{$domain_url}", sprintf(__('Starting Check for %s', 'ultimate-multisite'), $domain_url));
666667

667-
if ('checking-dns' === $stage) {
668+
if (Domain_Stage::CHECKING_DNS === $stage) {
668669
if ($domain->has_correct_dns()) {
669-
$domain->set_stage('checking-ssl-cert');
670+
$domain->set_stage(Domain_Stage::CHECKING_SSL);
670671

671672
$domain->save();
672673

@@ -692,7 +693,7 @@ public function async_process_domain_stage($domain_id, $tries = 0): void {
692693
* Max attempts
693694
*/
694695
if ($tries > $max_tries) {
695-
$domain->set_stage('failed');
696+
$domain->set_stage(Domain_Stage::FAILED);
696697

697698
$domain->save();
698699

@@ -723,9 +724,9 @@ public function async_process_domain_stage($domain_id, $tries = 0): void {
723724

724725
return;
725726
}
726-
} elseif ('checking-ssl-cert' === $stage) {
727+
} elseif (Domain_Stage::CHECKING_SSL === $stage) {
727728
if ($domain->has_valid_ssl_certificate()) {
728-
$domain->set_stage('done');
729+
$domain->set_stage(Domain_Stage::DONE);
729730

730731
$domain->set_secure(true);
731732

@@ -742,10 +743,11 @@ public function async_process_domain_stage($domain_id, $tries = 0): void {
742743
* Max attempts
743744
*/
744745
if ($tries > $max_tries) {
745-
$domain->set_stage('done-without-ssl');
746+
// We use SSL FAILED instead of done-without-ssl since ssl is pretty much required
747+
// and we don't want to redirect to a domain with certificate errors.
748+
$domain->set_stage(Domain_Stage::SSL_FAILED);
746749

747750
$domain->save();
748-
749751
wu_log_add(
750752
"domain-{$domain_url}",
751753
// translators: %d is the number of minutes to try again.

inc/models/class-domain.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Domain extends Base_Model {
7373
* @since 2.0.0
7474
* @var string
7575
*/
76-
protected $stage = 'checking-dns';
76+
protected $stage = Domain_Stage::CHECKING_DNS;
7777

7878
/**
7979
* Date when this was created.
@@ -90,9 +90,10 @@ class Domain extends Base_Model {
9090
* @var array
9191
*/
9292
const INACTIVE_STAGES = [
93-
'checking-dns',
94-
'checking-ssl-cert',
95-
'failed',
93+
Domain_Stage::CHECKING_DNS,
94+
Domain_Stage::CHECKING_SSL,
95+
Domain_Stage::FAILED,
96+
Domain_Stage::SSL_FAILED,
9697
];
9798

9899
/**
@@ -127,7 +128,7 @@ public function validation_rules() {
127128
return [
128129
'blog_id' => 'required|integer',
129130
'domain' => "required|domain|unique:\WP_Ultimo\Models\Domain,domain,{$id}",
130-
'stage' => 'required|in:checking-dns,checking-ssl-cert,done-without-ssl,done,failed|default:checking-dns',
131+
'stage' => 'required|in:checking-dns,checking-ssl-cert,done-without-ssl,done,failed,ssl-failed|default:checking-dns',
131132
'active' => 'default:1',
132133
'secure' => 'default:0',
133134
'primary_domain' => 'default:0',

0 commit comments

Comments
 (0)