PluginProbe
Patchstack – WordPress & Plugins Security / 2.2.11
Patchstack – WordPress & Plugins Security v2.2.11
2.3.7 trunk 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.17 2.1.18 2.1.19 2.1.2 2.1.20 2.1.21 2.1.22 2.1.23 2.1.24 2.1.25 2.1.3 2.1.4 2.1.5 2.1.6 All 49 releases
← All changes | includes/multisite.php +113 -2 trunk2.2.11 View file →
@@ -8,9 +8,17 @@
8 8 /**
9 9 * This class is used to handle anything multisite related.
10 10 */
11 11 class P_Multisite extends P_Core {
12 +
12 13 /**
14 + * Stores any errors.
15 + *
16 + * @var string
17 + */
18 + public $error = '';
19 +
20 + /**
13 21 * Add the actions required for the multisite functionality.
14 22 *
15 23 * @param Patchstack $core
16 24 * @return void
@@ -20,8 +28,18 @@
20 28 if ( ! is_super_admin() ) {
21 29 return;
22 30 }
23 31
32 + // When settings are saved.
33 + if ( isset( $_POST['option_page'], $_POST['PatchstackNonce'] ) && wp_verify_nonce( $_POST['PatchstackNonce'], 'patchstack-option-page' ) ) {
34 + $this->save_settings();
35 + }
36 +
37 + // When sites are activated.
38 + if ( isset( $_POST['patchstack_do'], $_POST['PatchstackNonce'], $_POST['sites'] ) && $_POST['patchstack_do'] == 'do_licenses' && wp_verify_nonce( $_POST['PatchstackNonce'], 'patchstack-multisite-activation' ) ) {
39 + $this->activate_licenses();
40 + }
41 +
24 42 // When we need to re-run the migration of a specific site.
25 43 if ( isset( $_GET['site'], $_GET['PatchstackNonce'] ) && wp_verify_nonce( $_GET['PatchstackNonce'], 'patchstack-migration' ) ) {
26 44 $this->run_migration();
27 45 }
@@ -27,8 +45,79 @@
27 45 }
28 46 }
29 47
30 48 /**
49 + * When a user selects sites that need to be activated.
50 + *
51 + * @return string
52 + */
53 + private function activate_licenses() {
54 + if ( empty( $_POST['sites'] ) ) {
55 + $this->error = '<span style="color: #ff6262;">Please select at least 1 site to be activated.</span><br /><br />';
56 + return;
57 + }
58 +
59 + // Determine which sites are already activated and skip those.
60 + $activate = [];
61 + $sites = get_sites();
62 + foreach ( $sites as $site ) {
63 + if ( in_array( $site->siteurl, $_POST['sites'] ) && get_blog_option( $site->id, 'patchstack_clientid' ) == '' ) {
64 + array_push( $activate, $site->siteurl );
65 + }
66 + }
67 +
68 + // Make sure there is a site that can be activated.
69 + if ( count( $activate ) == 0 ) {
70 + $this->error = '<span style="color: #ff6262;">None of the selected sites need activation.</span><br /><br />';
71 + return;
72 + }
73 +
74 + // Add the site to the app and retrieve the license for each site.
75 + $licenses = $this->plugin->api->get_site_licenses( [ 'sites' => $activate ] );
76 +
77 + // Did an error happen during the multisite license activation?
78 + if ( isset( $licenses['error'] ) ) {
79 + $this->error = '<span style="color: #ff6262;">' . $licenses['error'] . '</span><br /><br />';
80 + return;
81 + }
82 +
83 + // Activate licenses on given sites
84 + $sites = get_sites();
85 + foreach ( $sites as $site ) {
86 + if ( isset( $licenses[ $site->siteurl ] ) ) {
87 + $this->plugin->activation->activate_multisite_license( $site, $licenses[ $site->siteurl ] );
88 + }
89 + }
90 + }
91 +
92 + /**
93 + * When the individual or global settings are saved.
94 + *
95 + * @return void
96 + */
97 + private function save_settings() {
98 + switch ( $_POST['option_page'] ) {
99 + // Save hardening options
100 + case 'patchstack_hardening_settings_group':
101 + $options = [ 'patchstack_auto_update', 'patchstack_json_is_disabled', 'patchstack_register_email_blacklist', 'patchstack_move_logs', 'patchstack_basicscanblock', 'patchstack_userenum', 'patchstack_hidewpversion', 'patchstack_activity_log_is_enabled', 'patchstack_activity_log_failed_logins', 'patchstack_xmlrpc_is_disabled', 'patchstack_captcha_on_comments', 'patchstack_captcha_login_form', 'patchstack_captcha_registration_form', 'patchstack_captcha_reset_pwd_form', 'patchstack_captcha_type', 'patchstack_captcha_public_key', 'patchstack_captcha_public_key_v3', 'patchstack_captcha_public_key_v3_new', 'patchstack_captcha_private_key', 'patchstack_captcha_private_key_v3', 'patchstack_captcha_private_key_v3_new', 'patchstack_application_passwords_disabled' ];
102 + $this->save_options( $options );
103 + break;
104 +
105 + // Save firewall settings
106 + case 'patchstack_firewall_settings_group':
107 + $options = [ 'patchstack_geo_block_countries', 'patchstack_geo_block_enabled', 'patchstack_geo_block_inverse', 'patchstack_ip_block_list', 'patchstack_basic_firewall', 'patchstack_autoblock_blocktime', 'patchstack_autoblock_attempts', 'patchstack_autoblock_minutes', 'patchstack_basic_firewall_roles', 'patchstack_disable_htaccess', 'patchstack_add_security_headers', 'patchstack_prevent_default_file_access', 'patchstack_block_debug_log_access', 'patchstack_index_views', 'patchstack_proxy_comment_posting', 'patchstack_image_hotlinking', 'patchstack_firewall_custom_rules', 'patchstack_firewall_custom_rules_loc', 'patchstack_blackhole_log', 'patchstack_whitelist' ];
108 + $this->save_options( $options );
109 + break;
110 +
111 + // Save login settings
112 + case 'patchstack_login_settings_group':
113 + $options = [ 'patchstack_mv_wp_login', 'patchstack_rename_wp_login', 'patchstack_block_bruteforce_ips', 'patchstack_anti_bruteforce_blocktime', 'patchstack_anti_bruteforce_attempts', 'patchstack_anti_bruteforce_minutes', 'patchstack_login_time_block', 'patchstack_login_time_start', 'patchstack_login_time_end', 'patchstack_login_2fa', 'patchstack_login_whitelist' ];
114 + $this->save_options( $options );
115 + break;
116 + }
117 + }
118 +
119 + /**
31 120 * This will be called when the network admin clicks on the "Sites" button.
32 121 * It will show all sites.
33 122 *
34 123 * @return void
@@ -37,8 +126,30 @@
37 126 require_once dirname( __FILE__ ) . '/views/pages/multisite-table.php';
38 127 }
39 128
40 129 /**
130 + * Save an array of options on a specific site.
131 + *
132 + * @param array $options
133 + * @return void
134 + */
135 + private function save_options( $options ) {
136 + if ( isset( $_GET['page'] ) && $_GET['page'] == 'patchstack-multisite-settings' ) {
137 + foreach ( $options as $option ) {
138 + $value = isset( $_POST[ $option ] ) ? $_POST[ $option ] : 0;
139 + $value = map_deep( $value, 'wp_filter_nohtml_kses' );
140 + update_site_option( $option, $value );
141 + }
142 + } else {
143 + foreach ( $options as $option ) {
144 + $value = isset( $_POST[ $option ] ) ? $_POST[ $option ] : 0;
145 + $value = map_deep( $value, 'wp_filter_nohtml_kses' );
146 + update_option( $option, $value );
147 + }
148 + }
149 + }
150 +
151 + /**
41 152 * Re-run the migration for a specific multisite site.
42 153 *
43 154 * @return void
44 155 */
@@ -43,14 +154,14 @@
43 154 * @return void
44 155 */
45 156 private function run_migration( ) {
46 157 // Must be a number.
47 - if ( ! isset( $_GET['site'] ) || ! is_scalar( $_GET['site'] ) || ! ctype_digit( (string) $_GET['site'] ) ) {
158 + if ( !ctype_digit( $_GET['site'] ) ) {
48 159 exit;
49 160 }
50 161
51 162 // Site must be valid and exists.
52 - $site = function_exists( 'get_site' ) ? get_site( $_GET['site'] ) : null;
163 + $site = get_site( $_GET['site'] );
53 164 if ( is_null( $site ) ) {
54 165 exit;
55 166 }
56 167