From 7179b7b817aa461d9598d6c6c5726f7609c585b6 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Mon, 23 Oct 2023 13:15:56 -0500 Subject: [PATCH 1/4] A2CP-422 added wpcli method to expose is_active --- core/A2_Optimized_CLI.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/core/A2_Optimized_CLI.php b/core/A2_Optimized_CLI.php index c3a077e..82905b8 100644 --- a/core/A2_Optimized_CLI.php +++ b/core/A2_Optimized_CLI.php @@ -329,6 +329,34 @@ public function site_health($args, $assoc_args) { } } + /** + * Returns status of specified security options + */ + public function is_active($args, $assoc_args) { + $optimizations = new A2_Optimized_Optimizations; + $return = array(); + + $specialMapping = array( + 'lock_plugins' => 'lock_editing', + 'bcrypt' => 'a2_bcrypt_passwords', + ); + + if (count($args) > 0) { + $slugs = explode(',', $args[0]); + + foreach ($slugs as $slug) { + $name = $slug; + if (array_key_exists($slug, $specialMapping)) { + $name = $specialMapping[$slug]; + } + $stat = $optimizations->is_active($name, TRUE); + $return[$slug] = $stat; + } + } + + return WP_CLI::line(json_encode($return)); + } + /** * Returns a site health report for the current site */ From 76a7732eac858d06914e656b96d9df8c94c7963a Mon Sep 17 00:00:00 2001 From: James Taylor Date: Tue, 24 Oct 2023 09:34:16 -0500 Subject: [PATCH 2/4] A2OPT-724 and A2OPT-724 add cli regenerate_salts remove_conf_backups --- core/A2_Optimized_CLI.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core/A2_Optimized_CLI.php b/core/A2_Optimized_CLI.php index 82905b8..be2421a 100644 --- a/core/A2_Optimized_CLI.php +++ b/core/A2_Optimized_CLI.php @@ -192,6 +192,17 @@ public function enable($args, $assoc_args) { } break; + case 'regenerate_salts': + $optimizations->regenerate_wpconfig_salts(); + + return WP_CLI::success(esc_html__( $site_type . ' salts have been regenerated.', 'a2-optimized-wp' )); + + break; + case 'remove_conf_backups': + $optimizations->enable_wpconfig_cleanup(); + + return WP_CLI::success(esc_html__( $site_type . ' config backups are scheduled to be removed.', 'a2-optimized-wp' )); + break; } } @@ -284,6 +295,12 @@ public function disable($args, $assoc_args) { return WP_CLI::success(esc_html__( $site_type . ' Bcrypt passwords disabled.', 'a2-optimized-wp' )); + break; + case 'remove_conf_backups': + $optimizations->disable_wpcon; + + return WP_CLI::success(esc_html__( $site_type . ' No longer removing config backups.', 'a2-optimized-wp' )); + break; } } @@ -339,6 +356,7 @@ public function is_active($args, $assoc_args) { $specialMapping = array( 'lock_plugins' => 'lock_editing', 'bcrypt' => 'a2_bcrypt_passwords', + 'remove_conf_backups' => 'a2_wpconfig_cleanup', ); if (count($args) > 0) { @@ -349,7 +367,7 @@ public function is_active($args, $assoc_args) { if (array_key_exists($slug, $specialMapping)) { $name = $specialMapping[$slug]; } - $stat = $optimizations->is_active($name, TRUE); + $stat = $optimizations->is_active($name, FALSE); $return[$slug] = $stat; } } From a3d26848f63a9b79f5347744ceae5326d9007137 Mon Sep 17 00:00:00 2001 From: charlie pauch Date: Tue, 24 Oct 2023 11:35:00 -0400 Subject: [PATCH 3/4] Update core/A2_Optimized_CLI.php fix typo Co-authored-by: Paulo Manrique <4464977+paulomanrique@users.noreply.github.com> --- core/A2_Optimized_CLI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/A2_Optimized_CLI.php b/core/A2_Optimized_CLI.php index be2421a..04f9b88 100644 --- a/core/A2_Optimized_CLI.php +++ b/core/A2_Optimized_CLI.php @@ -297,7 +297,7 @@ public function disable($args, $assoc_args) { break; case 'remove_conf_backups': - $optimizations->disable_wpcon; + $optimizations->disable_wpconfig_cleanup(); return WP_CLI::success(esc_html__( $site_type . ' No longer removing config backups.', 'a2-optimized-wp' )); From 4c583b890b1964617ca73a96bad10b4a80c3d016 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Tue, 24 Oct 2023 14:10:29 -0500 Subject: [PATCH 4/4] Updated is_active method to return string by default and support json output --- core/A2_Optimized_CLI.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/A2_Optimized_CLI.php b/core/A2_Optimized_CLI.php index 04f9b88..1a9328d 100644 --- a/core/A2_Optimized_CLI.php +++ b/core/A2_Optimized_CLI.php @@ -357,7 +357,10 @@ public function is_active($args, $assoc_args) { 'lock_plugins' => 'lock_editing', 'bcrypt' => 'a2_bcrypt_passwords', 'remove_conf_backups' => 'a2_wpconfig_cleanup', + 'xmlrpc' => 'xmlrpc_requests', ); + + $output_json = (array_key_exists('format', $assoc_args) && $assoc_args['format'] == 'json'); if (count($args) > 0) { $slugs = explode(',', $args[0]); @@ -367,12 +370,21 @@ public function is_active($args, $assoc_args) { if (array_key_exists($slug, $specialMapping)) { $name = $specialMapping[$slug]; } - $stat = $optimizations->is_active($name, FALSE); + $stat = $optimizations->is_active($name, !$output_json); $return[$slug] = $stat; } } - return WP_CLI::line(json_encode($return)); + if ($output_json) { + return WP_CLI::line(json_encode($return)); + } else { + foreach ($return as $slug => $v) { + echo "$slug is " . ($v === true ? 'Active' : 'Inactive') . "\n\r"; + } + + return; + } + } /**