PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | class/class-mainwp-post-site-handler.php +45 -12 5.1 → 6.2.1 View file →
@@ -6,8 +6,13 @@
6 6 */
7 7
8 8 namespace MainWP\Dashboard;
9 9
10 +// Exit if accessed directly.
11 +if ( ! defined( 'ABSPATH' ) ) {
12 + exit;
13 +}
14 +
10 15 /**
11 16 * Class MainWP_Post_Site_Handler
12 17 *
13 18 * @package MainWP\Dashboard
@@ -49,9 +54,9 @@
49 54 $this->add_action( 'mainwp_addwp', array( &$this, 'mainwp_addwp' ) );
50 55 $this->add_action( 'mainwp_get_site_icon', array( &$this, 'get_site_icon' ) );
51 56 $this->add_action( 'mainwp_check_abandoned', array( &$this, 'check_abandoned' ) );
52 57
53 - if ( mainwp_current_user_have_right( 'dashboard', 'test_connection' ) ) {
58 + if ( \mainwp_current_user_can( 'dashboard', 'test_connection' ) ) {
54 59 $this->add_action( 'mainwp_testwp', array( &$this, 'mainwp_testwp' ) );
55 60 }
56 61
57 62 $this->add_action( 'mainwp_removesite', array( &$this, 'mainwp_removesite' ) );
@@ -68,9 +73,9 @@
68 73
69 74 // Widget: RightNow.
70 75 $this->add_action( 'mainwp_syncsites', array( &$this, 'mainwp_syncsites' ) );
71 76
72 - $this->add_action( 'mainwp_checksites', array( &$this, 'mainwp_checksites' ) );
77 + $this->add_action( 'mainwp_checksites', array( &$this, 'ajax_checksites' ) );
73 78 $this->add_action( 'mainwp_manage_sites_suspend_site', array( &$this, 'manage_suspend_site' ) );
74 79 $this->add_action( 'mainwp_group_sites_add', array( &$this, 'ajax_group_sites_add' ) );
75 80 }
76 81
@@ -134,9 +139,9 @@
134 139 }
135 140 if ( ! $success ) {
136 141 wp_die( wp_json_encode( array( 'error' => esc_html__( 'Unexpected error occurred. Please try again.', 'mainwp' ) ) ) );
137 142 } else {
138 - wp_die( wp_json_encode( array( 'success' => 1 ) ) );
143 + wp_die( wp_json_encode( array( 'success' => $success ) ) );
139 144 }
140 145 }
141 146
142 147
@@ -301,10 +306,12 @@
301 306 $name = $website->name;
302 307 $verifyCertificate = (int) $website->verify_certificate;
303 308 $forceUseIPv4 = $website->force_use_ipv4;
304 309 $sslVersion = $website->ssl_version;
305 - $http_user = $website->http_user;
306 - $http_pass = $website->http_pass;
310 + // MWP-1548: decrypt at the boundary so the reconnect /
311 + // try_visit call below uses plaintext credentials.
312 + $http_user = MainWP_Credential_Storage::decrypt_credential( $website->http_user );
313 + $http_pass = MainWP_Credential_Storage::decrypt_credential( $website->http_pass );
307 314 }
308 315 }
309 316 // phpcs:enable
310 317
@@ -345,18 +352,28 @@
345 352 *
346 353 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::remove_site()
347 354 */
348 355 public function mainwp_removesite() {
349 - if ( ! mainwp_current_user_have_right( 'dashboard', 'delete_sites' ) ) {
350 - die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( esc_html__( 'delete sites', 'mainwp' ), false ) ) ) );
356 + if ( ! \mainwp_current_user_can( 'dashboard', 'delete_sites' ) ) {
357 + die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'delete sites', 'mainwp' ), false ) ) ) );
351 358 }
352 359
353 360 $this->secure_request( 'mainwp_removesite' );
354 361
362 + static::invalidate_warm_cache();
363 +
355 364 MainWP_Manage_Sites_Handler::remove_site();
356 365 }
357 366
367 +
358 368 /**
369 + * Method invalidate_warm_cache()
370 + */
371 + public static function invalidate_warm_cache() {
372 + MainWP_Cache_Warm_Helper::invalidate_manage_pages( array( 'managesites', 'mainwp_tab' ) );
373 + }
374 +
375 + /**
359 376 * Method mainwp_reconnectwp()
360 377 *
361 378 * Reconnect to Child Site.
362 379 *
@@ -420,17 +437,33 @@
420 437 die( wp_json_encode( array( 'error' => esc_html( wp_strip_all_tags( $website->sync_errors ) ) ) ) );
421 438 }
422 439
423 440 /**
424 - * Method mainwp_checksites()
441 + * Method ajax_checksites()
425 442 *
426 443 * Check Child Sites.
427 - *
428 - * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::ajax_check_status_site()
429 444 */
430 - public function mainwp_checksites() {
445 + public function ajax_checksites() {
431 446 $this->secure_request( 'mainwp_checksites' );
432 - MainWP_Monitoring_Handler::ajax_check_status_site();
447 +
448 + $website = null;
449 + if ( isset( $_POST['wp_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
450 + $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['wp_id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
451 + }
452 +
453 + if ( null === $website ) {
454 + die( wp_json_encode( array( 'error' => esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ) ) );
455 + }
456 +
457 + MainWP_Utility::end_session();
458 + $result = MainWP_Monitoring_Handler::handle_check_website( $website );
459 + MainWP_Utility::end_session();
460 +
461 + if ( is_array( $result ) ) {
462 + die( wp_json_encode( array( 'result' => 'success' ) ) );
463 + } else {
464 + die( wp_json_encode( array( 'error' => esc_html__( 'Request failed. Please, try again.', 'mainwp' ) ) ) );
465 + }
433 466 }
434 467
435 468 /**
436 469 * Method mainwp_manage_sites_suspend_site()