' . esc_html__( 'Sites', 'mainwp' ) . '', 'read', 'managesites', array( MainWP_Manage_Sites::get_class_name(), 'render_manage_sites' ) ); } /** * Method init_subpages_menu() * * @param array $subPages Sub pages array. * * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item() */ public static function init_subpages_menu( &$subPages ) { // phpcs:ignore -- NOSONAR - complex. ?> esc_html__( 'Sites', 'mainwp' ), 'parent_key' => 'mainwp_tab', 'slug' => 'managesites', 'href' => 'admin.php?page=managesites', 'icon' => '', ), 0 ); $items_menu = array( array( 'title' => esc_html__( 'Manage Sites', 'mainwp' ), 'parent_key' => 'managesites', 'slug' => 'managesites', 'href' => 'admin.php?page=managesites', 'right' => '', 'leftsub_order_level2' => 1, ), array( 'title' => esc_html__( 'Add New', 'mainwp' ), 'parent_key' => 'managesites', 'href' => 'admin.php?page=managesites&do=new', 'slug' => 'managesites', 'right' => 'add_sites', 'item_slug' => 'managesites_add_new', 'id' => 'managesites-addnew', 'leftsub_order_level2' => 2, ), array( 'title' => esc_html__( 'Import Sites', 'mainwp' ), 'parent_key' => 'managesites', 'href' => 'admin.php?page=managesites&do=bulknew', 'slug' => 'managesites', 'right' => 'add_sites', 'item_slug' => 'managesites_import', 'id' => 'managesites-bulknew', 'leftsub_order_level2' => 3, ), ); MainWP_Menu::init_subpages_left_menu( $subPages, $items_menu, 'managesites', 'ManageSites' ); foreach ( $items_menu as $item ) { if ( isset( $item['item_slug'] ) ) { if ( MainWP_Menu::is_disable_menu_item( 3, $item['item_slug'] ) ) { continue; } } elseif ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) { continue; } MainWP_Menu::add_left_menu( $item, 2 ); } } /** * Method render_header() * * Build Sites page header. * * @param string $shownPage Current Page. * @param array $subPages Sites subpages. * * @uses \MainWP\Dashboard\MainWP_Connect::get_favico_url() * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() * @uses \MainWP\Dashboard\MainWP_UI::render_top_header() * @uses \MainWP\Dashboard\MainWP_UI::render_second_top_header() */ public static function render_header( $shownPage = '', $subPages = array() ) { // phpcs:ignore -- NOSONAR - complex. if ( '' === $shownPage || 'managesites' === $shownPage ) { $shownPage = 'ManageSites'; } $site_id = 0; // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized if ( isset( $_GET['id'] ) && ! empty( $_GET['id'] ) ) { $site_id = intval( $_GET['id'] ); } elseif ( isset( $_GET['backupid'] ) && ! empty( $_GET['backupid'] ) ) { $site_id = intval( $_GET['backupid'] ); } elseif ( isset( $_GET['updateid'] ) && ! empty( $_GET['updateid'] ) ) { $site_id = intval( $_GET['updateid'] ); } elseif ( isset( $_GET['dashboard'] ) && ! empty( $_GET['dashboard'] ) ) { $site_id = intval( $_GET['dashboard'] ); } elseif ( isset( $_GET['scanid'] ) && ! empty( $_GET['scanid'] ) ) { $site_id = intval( $_GET['scanid'] ); } elseif ( isset( $_GET['emailsettingsid'] ) && ! empty( $_GET['emailsettingsid'] ) ) { $site_id = intval( $_GET['emailsettingsid'] ); } elseif ( isset( $_GET['cacheControlId'] ) && ! empty( $_GET['cacheControlId'] ) ) { $site_id = intval( $_GET['cacheControlId'] ); } elseif ( ! empty( $_GET['monitor_wpid'] ) ) { $site_id = intval( $_GET['monitor_wpid'] ); } // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $managesites_pages = array( 'ManageSites' => array( 'href' => 'admin.php?page=managesites', 'title' => esc_html__( 'Manage Sites', 'mainwp' ), 'access' => true, ), 'AddNew' => array( 'href' => 'admin.php?page=managesites&do=new', 'title' => esc_html__( 'Add New', 'mainwp' ), 'access' => \mainwp_current_user_can( 'dashboard', 'add_sites' ), ), 'BulkAddNew' => array( 'href' => 'admin.php?page=managesites&do=bulknew', 'title' => esc_html__( 'Import Sites', 'mainwp' ), 'access' => \mainwp_current_user_can( 'dashboard', 'add_sites' ), ), 'MonitoringSites' => array( 'href' => 'admin.php?page=MonitoringSites', 'title' => esc_html__( 'Monitoring', 'mainwp' ), 'access' => true, ), ); $total_info = MainWP_Manage_Sites_Update_View::get_total_info( $site_id ); $total_updates = $total_info['total_upgrades']; $after_title = empty( $total_updates ) ? '' : '
'; $site_pages = array( 'ManageSitesDashboard' => array( 'href' => 'admin.php?page=managesites&dashboard=' . $site_id, 'title' => esc_html__( 'Overview', 'mainwp' ), 'access' => \mainwp_current_user_can( 'dashboard', 'access_individual_dashboard' ), ), 'ManageSitesEdit' => array( 'href' => 'admin.php?page=managesites&id=' . $site_id, 'title' => esc_html__( 'Settings', 'mainwp' ), 'access' => \mainwp_current_user_can( 'dashboard', 'edit_sites' ), ), 'ManageSitesUpdates' => array( 'href' => 'admin.php?page=managesites&updateid=' . $site_id, 'title' => esc_html__( 'Updates', 'mainwp' ), 'access' => \mainwp_current_user_can( 'dashboard', 'access_individual_dashboard' ), 'after_title' => $after_title, ), 'ManageSitesBackups' => array( 'href' => 'admin.php?page=managesites&backupid=' . $site_id, 'title' => esc_html__( 'Backups', 'mainwp' ), 'access' => \mainwp_current_user_can( 'dashboard', 'execute_backups' ), ), 'SecurityScan' => array( 'href' => 'admin.php?page=managesites&scanid=' . $site_id, 'title' => esc_html__( 'Site Hardening', 'mainwp' ), 'access' => true, ), ); /** * MainWP Use External Primary backup Method global. * * @global string */ global $mainwpUseExternalPrimaryBackupsMethod; if ( ! empty( $mainwpUseExternalPrimaryBackupsMethod ) ) { unset( $site_pages['ManageSitesBackups'] ); } elseif ( ! get_option( 'mainwp_enableLegacyBackupFeature' ) ) { if ( isset( $site_pages['ManageSitesBackups'] ) ) { unset( $site_pages['ManageSitesBackups'] ); } } $pagetitle = esc_html__( 'Sites', 'mainwp' ); if ( ! empty( $site_id ) ) { $website = MainWP_DB::instance()->get_website_by_id( $site_id ); if ( $website ) { $reconnect = ''; if ( $site_id && $website && '' !== $website->sync_errors ) { $reconnect = ' Reconnect'; } $wp_admin_href = MainWP_Site_Open::get_open_site_url( $site_id, false, false ); $dropdown = $reconnect . ' Remove Site Go to WP Admin '; $site_icon = ''; if ( 1 === (int) get_option( 'mainwp_use_favicon', 1 ) ) { $favi_url = MainWP_Connect::get_favico_url( $website ); $site_icon = MainWP_Manage_Sites::get_instance()->get_site_icon_display( $website->cust_site_icon_info, $favi_url ); } $pagetitle = $site_icon . '
' . MainWP_Utility::get_nice_url( $website->url ) . '
'; } } $params = array( 'title' => $pagetitle, ); MainWP_UI::render_top_header( $params ); $manage_sites = false; if ( 'ManageSites' === $shownPage || 'MonitoringSites' === $shownPage ) { $manage_sites = true; } static::render_managesites_header( $site_pages, $managesites_pages, $subPages, $site_id, $shownPage ); if ( $manage_sites ) { $which = strtolower( $shownPage ); MainWP_UI::render_second_top_header( $which ); } if ( ! empty( $site_id ) ) { MainWP_UI::render_modal_reconnect(); } } /** * Method render_footer() * * Close the page container. */ public static function render_footer() { echo ''; } /** * Method render_managesites_header() * * Render manage sites header. * * @param array $site_pages site pages. * @param array $managesites_pages manage site pages. * @param array $subPages sub pages. * @param int $site_id Site id. * @param string $shownPage Current Page. * * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item() * @uses \MainWP\Dashboard\MainWP_UI::render_page_navigation() */ private static function render_managesites_header( $site_pages, $managesites_pages, $subPages, $site_id, $shownPage ) { //phpcs:ignore -- NOSONAR - complex method. $renderItems = array(); if ( isset( $managesites_pages[ $shownPage ] ) ) { foreach ( $managesites_pages as $page => $value ) { if ( MainWP_Menu::is_disable_menu_item( 3, $page ) ) { continue; } $item = $value; $item['active'] = ( $page === $shownPage ) ? true : false; $renderItems[] = $item; } } elseif ( $site_id ) { foreach ( $site_pages as $page => $value ) { if ( MainWP_Menu::is_disable_menu_item( 3, $page ) ) { continue; } $item = $value; $item['active'] = ( $page === $shownPage ) ? true : false; $renderItems[] = $item; } } if ( isset( $subPages ) && is_array( $subPages ) ) { foreach ( $subPages as $subPage ) { if ( MainWP_Menu::is_disable_menu_item( 3, 'ManageSites' . $subPage['slug'] ) ) { continue; } if ( isset( $subPage['sitetab'] ) && true === $subPage['sitetab'] && empty( $site_id ) ) { continue; } $item = array(); $item['title'] = $subPage['title']; if ( ! empty( $subPage['href'] ) ) { $item['href'] = $subPage['href']; } else { $item['href'] = 'admin.php?page=ManageSites' . $subPage['slug'] . ( $site_id ? '&id=' . esc_attr( $site_id ) : '' ); } $item['active'] = isset( $subPage['slug'] ) && ( $subPage['slug'] === $shownPage ) ? true : false; $renderItems[] = $item; } } $renderItems = apply_filters( 'mainwp_manage_sites_navigation_items', $renderItems, $site_id, $shownPage ); MainWP_UI::render_page_navigation( $renderItems ); } /** * Method render_import_sites() * * Render import sites dialog. * * @uses \MainWP\Dashboard\MainWP_System_Utility::get_wp_file_system() * @uses \MainWP\Dashboard\MainWP_Utility::starts_with() */ public static function render_import_sites() { // phpcs:ignore -- NOSONAR - complex. ?>
' . esc_html__( 'Importing...', 'mainwp' ); ?>
get_contents( $tmp_path ); // to compatible with EOL on OSs. $content = str_replace( "\r\n", "\r", $content ); $content = str_replace( "\n", "\r", $content ); $lines = explode( "\r", $content ); $default_values = array( 'name' => '', 'url' => '', 'adminname' => '', 'adminpwd' => '', 'wpgroups' => '', 'uniqueId' => '', 'http_user' => '', 'http_pass' => '', 'verify_certificate' => 1, 'ssl_version' => 'auto', ); if ( is_array( $lines ) && ( ! empty( $lines ) ) ) { $row = 0; $header_line = null; foreach ( $lines as $originalLine ) { $line = trim( $originalLine ); if ( MainWP_Utility::starts_with( $line, '#' ) ) { continue; } $items = str_getcsv( $line, ',' ); if ( ( null === $header_line ) && ! empty( $_POST['mainwp_managesites_chk_header_first'] ) ) { $header_line = sanitize_text_field( $line ) . "\r"; continue; } if ( 3 > count( $items ) ) { continue; } $x = 0; foreach ( $default_values as $field => $val ) { $value = isset( $items[ $x ] ) ? $items[ $x ] : $val; if ( 'verify_certificate' === $field ) { if ( 'T' === $value ) { $value = '1'; } elseif ( 'Y' === $value ) { $value = '0'; } } $import_data[ $field ] = sanitize_text_field( wp_unslash( $value ) ); ++$x; } $encoded = wp_json_encode( $import_data ); ?>
'; ?>
'; } } else { $errors[] = esc_html__( 'Upload failed. Please, try again.', 'mainwp' ) . '
'; } } elseif ( ! empty( $_POST['mainwp_managesites_import'] ) && check_admin_referer( 'mainwp-admin-nonce' ) ) { // Set site data by POST value. $sites_data = ! empty( $_POST['mainwp_managesites_import'] ) ? wp_unslash( $_POST['mainwp_managesites_import'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized if ( ! empty( $sites_data ) ) { $import_data = array(); // Create default import data. // Map data sites data to import_data. foreach ( $sites_data as $site ) { // Break site if site_url and admin_name empty. if ( empty( $site['site_url'] ) && empty( $site['admin_name'] ) ) { continue; } // Map POST data to import data. $import_data[] = array( 'name' => ! empty( $site['site_name'] ) ? sanitize_text_field( wp_unslash( $site['site_name'] ) ) : '', 'url' => ! empty( $site['site_url'] ) ? sanitize_text_field( wp_unslash( $site['site_url'] ) ) : '', 'adminname' => ! empty( $site['admin_name'] ) ? sanitize_text_field( wp_unslash( $site['admin_name'] ) ) : '', 'adminpwd' => ! empty( $site['admin_password'] ) ? wp_unslash( $site['admin_password'] ) : '', 'wpgroups' => ! empty( $site['tag'] ) ? sanitize_text_field( wp_unslash( $site['tag'] ) ) : '', 'uniqueId' => ! empty( $site['security_id'] ) ? sanitize_text_field( wp_unslash( $site['security_id'] ) ) : '', 'http_user' => ! empty( $site['http_username'] ) ? sanitize_text_field( wp_unslash( $site['http_username'] ) ) : '', 'http_pass' => ! empty( $site['http_password'] ) ? wp_unslash( $site['http_password'] ) : '', 'verify_certificate' => isset( $site['verify_certificate'] ) ? intval( $site['verify_certificate'] ) : 1, 'ssl_version' => ! empty( $site['ssl_version'] ) ? sanitize_text_field( wp_unslash( $site['ssl_version'] ) ) : 'auto', ); } // Import website if import data is not empty. if ( ! empty( $import_data ) ) { $header_line = trim( 'Site Name, Url, Admin Name, Tag,Security ID,HTTP Username,HTTP Password,Verify Certificate,SSL Version' ); // Set Header Line. // Map import data to input html. foreach ( $import_data as $key_import => $val_import ) { $line = trim( implode( ',', $val_import ) ) ?>
'; ?>
'; } } else { $errors[] = esc_html__( 'Import failed. Please, try again.', 'mainwp' ) . '
'; } } else { $errors[] = esc_html__( 'Import failed. Please, try again.', 'mainwp' ) . '
'; } if ( ! empty( $errors ) ) { ?>

:

'; foreach ( $working_extensions as $slug => $data ) { $dir_slug = dirname( $slug ); if ( ! isset( $sync_extensions_options[ $dir_slug ] ) ) { continue; } $sync_info = isset( $sync_extensions_options[ $dir_slug ] ) ? $sync_extensions_options[ $dir_slug ] : array(); $ext_name = MainWP_Extensions_Handler::polish_string_name( $data['name'] ); $ext_name = esc_html( $ext_name ); $html = '
'; $html .= '
'; $html .= '

' . $ext_name . '

'; if ( isset( $sync_info['plugin_slug'] ) && ! empty( $sync_info['plugin_slug'] ) ) { $html .= '
'; $html .= '
'; $html .= $loader; $html .= '
'; if ( ! isset( $sync_info['no_setting'] ) || empty( $sync_info['no_setting'] ) ) { $html .= '
'; $html .= '
'; $html .= '
'; $html .= $loader; $html .= '
'; } if ( ! empty( $sync_info['action_after_install'] ) ) { $html .= '
'; $html .= '
'; $html .= '
'; $html .= $loader; $html .= '
'; } } else { $html .= '
'; $html .= '
'; $html .= ' '; $html .= '
'; } $html .= '
'; $html .= '
'; echo $html; // phpcs:ignore WordPress.Security.EscapeOutput } } } /** * Method render_dashboard() * * Render individual Child Site Overview page. * * @param mixed $website Child Site. * * @return string Sites Overview Page. * * @uses \MainWP\Dashboard\MainWP_Overview::render_dashboard_body() */ public static function render_dashboard( &$website ) { if ( ! \mainwp_current_user_can( 'dashboard', 'access_individual_dashboard' ) ) { \mainwp_do_not_have_permissions( esc_html__( 'individual dashboard', 'mainwp' ) ); return; } ?>
mainwpdir ) { echo '
Configuration issue detected: MainWP has no write privileges to the uploads directory. Because of this some of the functionality might not work.
'; } /** * Screen layout columns global. * * @global string */ global $screen_layout_columns; MainWP_Overview::render_dashboard_body( array( $website ) ); ?>
' . esc_html__( 'Update Selected', 'mainwp' ) . ''; ?> ' . esc_html__( 'Update Selected', 'mainwp' ) . ''; ?>
get_website_by_id( $websiteid ); if ( empty( $website ) ) { return; } if ( \mainwp_current_user_can( 'dashboard', 'manage_security_issues' ) ) { do_action_deprecated( 'mainwp-securityissues-sites', array( $website ), '4.0.7.2', 'mainwp_securityissues_sites' ); // @deprecated Use 'mainwp_securityissues_sites' instead. NOSONAR - not IP. /** * Action: mainwp_securityissues_sites * * Fires on a child site Hardening page at top. * * @hooked MainWP basic hardening features. * * @param object $website Object containing child site info. * * @since Unknown */ do_action( 'mainwp_securityissues_sites', $website ); } ?>
get_website_by_id( $websiteid, false, array( 'monitoring_notification_emails', 'settings_notification_emails' ) ); if ( ! MainWP_System_Utility::can_edit_website( $website ) ) { $website = null; } if ( empty( $website ) ) { return; } $groups = MainWP_DB_Common::instance()->get_groups_for_current_user(); if ( ! is_array( $groups ) ) { $groups = array(); } $website_url = MainWP_Utility::remove_http_www_prefix( $website->url, true ); $text_use_global = esc_html__( 'Use global setting', 'mainwp' ); $style_checked = 'checked="true"'; ?>
name ) ), '' . esc_url( $website->url ) . '', '', ' ' ); // phpcs:ignore WordPress.Security.EscapeOutput -- NOSONAR - noopener - open safe. ?>

adminname; ?>
get_cust_site_icon( $website->cust_site_icon_info, 'uploaded' ); $selected_site_icon = MainWP_Manage_Sites::get_instance()->get_cust_site_icon( $website->cust_site_icon_info, 'selected' ); $selected_site_color = MainWP_Manage_Sites::get_instance()->get_cust_site_icon( $website->cust_site_icon_info, 'color' ); $uploaded_icon_src = ''; // default. if ( empty( $selected_site_color ) ) { $selected_site_color = '#34424D'; } if ( empty( $selected_site_icon ) ) { $selected_site_icon = 'wordpress'; //phpcs:ignore -- WP icon default. } if ( ! empty( $uploaded_site_icon ) ) { $dirs = MainWP_System_Utility::get_mainwp_dir( 'site-icons', true ); $icon_base = $dirs[1]; $cust_prod_icon_file = $uploaded_site_icon; $uploaded_icon_src = $icon_base . $cust_prod_icon_file; } $default_icons = MainWP_UI::get_default_icons(); $delnonce = MainWP_System_Utility::get_custom_nonce( 'site', esc_attr( $uploaded_site_icon ) ); ?>
get_cust_site_icon( $website->cust_site_icon_info, 'display_edit' ); //phpcs:ignore --ok. ?>
get_groups_by_website_id( $website->id ); $init_groups = ''; if ( is_array( $groupsSite ) ) { foreach ( $groupsSite as $gpsSite ) { $init_groups .= ( isset( $groups[ $gpsSite->id ] ) && $groups[ $gpsSite->id ] ) ? ',' . $gpsSite->id : ''; } } $init_groups = ltrim( $init_groups, ',' ); ?>
get_wp_client_by( 'all' ); ?>
suspended ? $style_checked : ''; //phpcs:ignore -- ok. ?>>
automatic_update ? $style_checked : ''; //phpcs:ignore -- ok. ?>>
is_ignoreCoreUpdates ? $style_checked : ''; //phpcs:ignore -- ok. ?>>
is_ignorePluginUpdates ? $style_checked : ''; //phpcs:ignore -- ok. ?>>
is_ignoreThemeUpdates ? $style_checked : ''; //phpcs:ignore -- ok. ?>>

disable_health_check ? $style_checked : ''; //phpcs:ignore -- ok. ?>>
health_threshold; $indi_val = 0 !== (int) $healthThreshold ? 1 : 0; ?>
disable_health_check ? $hide_style : ''; //phpcs:ignore -- ok.?> hide-element="health-monitoring">

" data-inverted="" data-position="top left">
verify_method ) ) { $verify_conn_method = 3; } else { $verify_conn_method = (int) $website->verify_method; } ?>
" data-inverted="" data-position="top left">
signature_algo ) ) { $site_sign_algo = 9999; } else { $site_sign_algo = (int) $website->signature_algo; } ?>
>
" data-inverted="" data-position="top left">
>
render_monitor_settings( $website->id, true ); MainWP_Manage_Sites::render_email_settings( $website ); do_action_deprecated( 'mainwp-manage-sites-edit', array( $website ), '4.0.7.2', 'mainwp_manage_sites_edit' ); // @deprecated Use 'mainwp_manage_sites_edit' instead. NOSONAR - not IP. do_action_deprecated( 'mainwp-extension-sites-edit', array( $website ), '4.0.7.2', 'mainwp_manage_sites_edit' ); // @deprecated Use 'mainwp_manage_sites_edit' instead. NOSONAR - not IP. /** This action is documented in ../pages/page-mainwp-manage-sites.php */ do_action( 'mainwp_manage_sites_edit', $website ); do_action( 'mainwp_extension_sites_edit_tablerow', $website ); ?>
settings_notification_emails ) ) { $emails_settings = json_decode( $website->settings_notification_emails, true ); } if ( ! is_array( $emails_settings ) ) { $emails_settings = array(); } $default = MainWP_Notification_Settings::get_default_emails_fields( $type ); $options = isset( $emails_settings[ $type ] ) ? $emails_settings[ $type ] : array(); $options = array_merge( $default, $options ); $title = MainWP_Notification_Settings::get_notification_types( $type ); $siteid = $website->id; $email_description = MainWP_Notification_Settings::get_settings_desc( $type ); $text_recipients = esc_html__( 'Recipient(s)', 'mainwp' ); $style_checked = 'checked="true"'; ?>
Boilerplate and Reports extensions tokens are supported in the email settings and templates if Extensions are in use.'; // NOSONAR - noopener - open safe. ?>

/>
wp-content/uploads/mainwp/templates/' . esc_html( $templ ) . '' : esc_html__( 'To override and edit this email template copy:', 'mainwp' ) . ' mainwp/templates/' . esc_html( $templ ) . ' ' . esc_html__( 'to the folder:', 'mainwp' ) . ' wp-content/uploads/mainwp/templates/' . esc_html( $templ ) . ''; ?>
get_default_templates_dir(); $custom_dir = MainWP_Notification_Template::instance()->get_custom_templates_dir(); $custom_file = $custom_dir . $template; $default_file = $default_dir . $template; $template_file = apply_filters( 'mainwp_default_template_locate', $default_file, $template, $default_dir, $type, $siteid ); if ( $siteid ) { $localion = 'admin.php?page=managesites&id=' . (int) $siteid . '&emailsettingsid=' . $siteid . '&edit-email=' . $type; } else { $localion = 'admin.php?page=SettingsEmail&edit-email=' . $type; } $editable = false; ?> settings_notification_emails ) ) { $emails_settings = json_decode( $website->settings_notification_emails, true ); } if ( ! is_array( $emails_settings ) ) { $emails_settings = array(); } $email_description = ''; $notification_emails = MainWP_Notification_Settings::get_notification_types(); $text_recipients = esc_html__( 'Recipient(s)', 'mainwp' ); ?>

$name ) { ?>
 
' : ''; ?>
 
signature_algo ) ? $website->signature_algo : false; if ( empty( $alg ) && is_object( $website ) ) { MainWP_DB::instance()->update_website_option( $website, 'signature_algo', 9999 ); // use global. $website = MainWP_DB::instance()->get_website_by_id( $website->id ); $success = MainWP_Sync::sync_site( $website, true ); } } } if ( ! $success ) { if ( MainWP_Connect_Lib::is_use_fallback_sec_lib( $website ) ) { $details = MainWP_Connect_Lib::instance()->create_connect_keys(); if ( is_array( $details ) ) { $pubkey = $details['pub']; $privkey = $details['priv']; } else { $privkey = '-1'; $pubkey = '-1'; } } elseif ( function_exists( 'openssl_pkey_new' ) ) { $conf = array( 'private_key_bits' => 2048 ); $conf_loc = MainWP_System_Utility::get_openssl_conf(); if ( ! empty( $conf_loc ) ) { $conf['config'] = $conf_loc; } $res = openssl_pkey_new( $conf ); @openssl_pkey_export( $res, $privkey, null, $conf ); // phpcs:ignore -- prevent warning. $details = openssl_pkey_get_details( $res ); $pubkey = $details['key']; } else { $privkey = '-1'; $pubkey = '-1'; } $verify_reg = MainWP_DB::instance()->get_website_option( $website, 'register_verify_key', '' ); $register_data = array( 'pubkey' => $pubkey, 'server' => get_admin_url(), 'uniqueId' => $website->uniqueId, 'regverify' => $verify_reg, ); $recon_user = ''; $recon_userpwd = ''; if ( is_array( $params ) && ! empty( $params['wpadmin'] ) && ! empty( $params['adminpwd'] ) ) { $recon_user = ! empty( $params['wpadmin'] ) ? $params['wpadmin'] : ''; $recon_userpwd = ! empty( $params['adminpwd'] ) ? $params['adminpwd'] : ''; } if ( ! empty( $recon_user ) && ! empty( $recon_userpwd ) ) { $register_data['user'] = $recon_user; $register_data['userpwd'] = $recon_userpwd; } $information = MainWP_Connect::fetch_url_not_authed( $website->url, $website->adminname, 'register', $register_data, true, $website->verify_certificate, $website->http_user, $website->http_pass, $website->ssl_version ); if ( isset( $information['error'] ) && '' !== $information['error'] ) { $err = urldecode( $information['error'] ); $_error = MainWP_Utility::esc_content( $err ); $error_code = isset( $information['error_code'] ) ? sanitize_text_field( wp_unslash( $information['error_code'] ) ) : ''; } elseif ( isset( $information['register'] ) && 'OK' === $information['register'] ) { $en_pk_data = MainWP_Encrypt_Data_Lib::instance()->encrypt_privkey( $privkey, $website->id, true ); $en_privkey = isset( $en_pk_data['en_data'] ) ? $en_pk_data['en_data'] : ''; $site_values = array( 'pubkey' => base64_encode( $pubkey ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode() used for backwards compatibility. 'privkey' => base64_encode( $en_privkey ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode() used for backwards compatibility. 'uniqueId' => ( isset( $information['uniqueId'] ) ? $information['uniqueId'] : '' ), ); if ( ! empty( $recon_user ) && ! empty( $recon_userpwd ) && ( $website->adminname !== $recon_user ) ) { $site_values['adminname'] = $recon_user; } MainWP_DB::instance()->update_website_values( $website->id, $site_values ); if ( ! empty( $information['regverify'] ) ) { MainWP_DB::instance()->update_website_option( $website, 'register_verify_key', $information['regverify'] ); } MainWP_Sync::sync_information_array( $website, $information ); $success = true; } else { $_error = esc_html__( 'Undefined error!', 'mainwp' ); } } } catch ( MainWP_Exception $e ) { if ( 'HTTPERROR' === $e->getMessage() ) { $_error = 'HTTP error' . ( null !== $e->get_message_extra() ? ' - ' . $e->get_message_extra() : '' ); } elseif ( 'NOMAINWP' === $e->getMessage() ) { $_error = MainWP_Error_Helper::get_error_not_detected_connect(); // phpcs:ignore WordPress.Security.EscapeOutput } } /** * Fires immediately after reconnect website. * * @since 4.5.1.1 * * @param object $website website data. */ do_action( 'mainwp_site_reconnected', $website, $success, $_error ); if ( $success ) { return true; } if ( ! empty( $_error ) ) { throw new MainWP_Exception( $_error, '', $error_code ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped } } else { throw new MainWP_Exception( esc_html__( 'This operation is not allowed!', 'mainwp' ) ); } return false; } /** * Method add_site() * * Add Child Site. * * @param mixed $website Child Site. * @param array $output Output values. * * @return self add_wp_site() */ public static function add_site( $website = false, &$output = array() ) { //phpcs:ignore -- NOSONAR - complexity. //phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $params['url'] = isset( $_POST['managesites_add_wpurl'] ) ? sanitize_text_field( wp_unslash( $_POST['managesites_add_wpurl'] ) ) : ''; $params['name'] = isset( $_POST['managesites_add_wpname'] ) ? sanitize_text_field( wp_unslash( $_POST['managesites_add_wpname'] ) ) : ''; $params['wpadmin'] = isset( $_POST['managesites_add_wpadmin'] ) ? sanitize_text_field( wp_unslash( $_POST['managesites_add_wpadmin'] ) ) : ''; $params['adminpwd'] = isset( $_POST['managesites_add_adminpwd'] ) ? wp_unslash( $_POST['managesites_add_adminpwd'] ) : ''; //phpcs:ignore -- NOSONAR - requires urlencoded passwd, do not sanitize for specical chars. $params['unique_id'] = isset( $_POST['managesites_add_uniqueId'] ) ? sanitize_text_field( wp_unslash( $_POST['managesites_add_uniqueId'] ) ) : ''; $params['ssl_verify'] = empty( $_POST['verify_certificate'] ) ? false : intval( $_POST['verify_certificate'] ); $params['ssl_version'] = empty( $_POST['ssl_version'] ) ? false : intval( $_POST['ssl_version'] ); $params['force_use_ipv4'] = apply_filters( 'mainwp_manage_sites_force_use_ipv4', null, $params['url'] ); $params['http_user'] = isset( $_POST['managesites_add_http_user'] ) ? sanitize_text_field( wp_unslash( $_POST['managesites_add_http_user'] ) ) : ''; $params['http_pass'] = isset( $_POST['managesites_add_http_pass'] ) ? wp_unslash( $_POST['managesites_add_http_pass'] ) : ''; $params['groupids'] = isset( $_POST['groupids'] ) && ! empty( $_POST['groupids'] ) ? explode( ',', sanitize_text_field( wp_unslash( $_POST['groupids'] ) ) ) : array(); $params['groupnames_import'] = isset( $_POST['groupnames_import'] ) ? sanitize_text_field( wp_unslash( $_POST['groupnames_import'] ) ) : ''; $params['clientid'] = isset( $_POST['clientid'] ) && ! empty( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0; $params['uploaded_site_icon'] = isset( $_POST['uploaded_icon'] ) && ! empty( $_POST['uploaded_icon'] ) ? sanitize_text_field( wp_unslash( $_POST['uploaded_icon'] ) ) : ''; $params['selected_site_icon'] = isset( $_POST['selected_icon'] ) && ! empty( $_POST['selected_icon'] ) ? sanitize_text_field( wp_unslash( $_POST['selected_icon'] ) ) : ''; $params['cust_icon_color'] = isset( $_POST['cust_color'] ) && ! empty( $_POST['cust_color'] ) ? sanitize_hex_color( wp_unslash( $_POST['cust_color'] ) ) : ''; if ( isset( $_POST['qsw_page'] ) ) { $params['qsw_page'] = sanitize_text_field( wp_unslash( $_POST['qsw_page'] ) ); } //phpcs:enable return static::add_wp_site( $website, $params, $output ); } /** * Medthod add_wp_site() * * Add new Child Site. * * @param mixed $website Child Site. * @param array $params Array of new Child Site to add. * @param array $output Output values. * * @return array $message, $error, $id * * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() * @uses \MainWP\Dashboard\MainWP_DB_Common::get_group_by_name() * @uses \MainWP\Dashboard\MainWP_DB::add_website() * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() * @uses \MainWP\Dashboard\MainWP_Exception * @uses \MainWP\Dashboard\MainWP_Sync::sync_information_array() * @uses \MainWP\Dashboard\MainWP_System_Utility::get_openssl_conf() * @uses \MainWP\Dashboard\MainWP_Utility::esc_content() */ public static function add_wp_site( $website, $params = array(), &$output = array() ) { //phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated. $error = ''; $message = ''; $id = 0; $existed_id = 0; if ( $website ) { $error = esc_html__( 'The site is already connected to your MainWP Dashboard', 'mainwp' ); if ( is_array( $website ) && ! empty( $website[0] ) && is_object( $website[0] ) ) { $existed_id = $website[0]->id; } elseif ( is_object( $website ) && property_exists( $website, 'id' ) ) { $existed_id = $website->id; } } else { try { if ( MainWP_Connect_Lib::is_use_fallback_sec_lib( $website ) ) { $details = MainWP_Connect_Lib::instance()->create_connect_keys(); if ( is_array( $details ) ) { $pubkey = $details['pub']; $privkey = $details['priv']; } else { $privkey = '-1'; $pubkey = '-1'; } } elseif ( function_exists( 'openssl_pkey_new' ) ) { $conf = array( 'private_key_bits' => 2048 ); $conf_loc = MainWP_System_Utility::get_openssl_conf(); if ( ! empty( $conf_loc ) ) { $conf['config'] = $conf_loc; } $res = openssl_pkey_new( $conf ); @openssl_pkey_export( $res, $privkey, null, $conf ); // phpcs:ignore -- prevent warning. $pubkey = openssl_pkey_get_details( $res ); $pubkey = $pubkey['key']; } else { $privkey = '-1'; $pubkey = '-1'; } $url = $params['url']; $verifyCertificate = ( ! isset( $params['ssl_verify'] ) || empty( $params['ssl_verify'] ) ) ? false : true; $sslVersion = ! isset( $params['ssl_version'] ) || empty( $params['ssl_version'] ) ? 0 : $params['ssl_version']; $addUniqueId = isset( $params['unique_id'] ) ? $params['unique_id'] : ''; $http_user = isset( $params['http_user'] ) ? $params['http_user'] : ''; $http_pass = isset( $params['http_pass'] ) ? $params['http_pass'] : ''; $force_use_ipv4 = isset( $params['force_use_ipv4'] ) ? $params['force_use_ipv4'] : null; MainWP_Logger::instance()->debug( ' :: register site :: ' . $url ); $information = MainWP_Connect::fetch_url_not_authed( $url, $params['wpadmin'], 'register', array( 'pubkey' => $pubkey, 'server' => get_admin_url(), 'uniqueId' => $addUniqueId, 'userpwd' => isset( $params['adminpwd'] ) ? $params['adminpwd'] : '', // require urlencoded. ), false, $verifyCertificate, $http_user, $http_pass, $sslVersion, array( 'force_use_ipv4' => $force_use_ipv4 ), $output ); if ( isset( $information['error'] ) && '' !== $information['error'] ) { $error = MainWP_Utility::esc_content( $information['error'] ); } elseif ( isset( $information['register'] ) && 'OK' === $information['register'] ) { $groupids = array(); $groupnames = array(); $tmpArr = array(); if ( isset( $params['groupids'] ) && is_array( $params['groupids'] ) ) { foreach ( $params['groupids'] as $group ) { if ( is_numeric( $group ) ) { $groupids[] = $group; } else { $group = trim( $group ); if ( ! empty( $group ) ) { $tmpArr[] = $group; } } } foreach ( $tmpArr as $tmp ) { $getgroup = MainWP_DB_Common::instance()->get_group_by_name( trim( $tmp ) ); if ( $getgroup ) { if ( ! in_array( $getgroup->id, $groupids, true ) ) { $groupids[] = $getgroup->id; } } else { $groupnames[] = trim( $tmp ); } } } if ( isset( $params['groupnames_import'] ) && '' !== $params['groupnames_import'] ) { $tmpArr = preg_split( '/[;,]/', $params['groupnames_import'] ); foreach ( $tmpArr as $tmp ) { $group = MainWP_DB_Common::instance()->get_group_by_name( trim( $tmp ) ); if ( $group ) { if ( ! in_array( $group->id, $groupids, true ) ) { $groupids[] = $group->id; } } else { $groupnames[] = trim( $tmp ); } } } if ( ! isset( $information['uniqueId'] ) || empty( $information['uniqueId'] ) ) { $addUniqueId = ''; } $http_user = isset( $params['http_user'] ) ? $params['http_user'] : ''; $http_pass = isset( $params['http_pass'] ) ? $params['http_pass'] : ''; /** * Current user global. * * @global string */ global $current_user; $others = array( 'groupids' => $groupids, 'groupnames' => $groupnames, 'verifyCertificate' => $verifyCertificate || false === $verifyCertificate ? 2 : 0, // 2 use global. 'addUniqueId' => $addUniqueId, 'http_user' => $http_user, 'http_pass' => $http_pass, 'sslVersion' => $sslVersion, ); $id = MainWP_DB::instance()->add_website( $current_user->ID, $params['name'], $params['url'], $params['wpadmin'], base64_encode( $pubkey ), base64_encode( $privkey ), $others ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode() used for http encoding compatible. if ( $id && isset( $params['clientid'] ) ) { MainWP_DB::instance()->update_website_values( $id, array( 'client_id' => intval( $params['clientid'] ) ) ); } if ( $id ) { $obj_site = (object) array( 'id' => $id ); MainWP_DB::instance()->update_website_option( $obj_site, 'added_timestamp', time() ); MainWP_DB::instance()->update_website_option( $obj_site, 'signature_algo', 9999 ); // use global. $icon_info = 'uploaded:' . $params['uploaded_site_icon'] . ';selected:' . $params['selected_site_icon'] . ';color:' . $params['cust_icon_color']; MainWP_DB::instance()->update_website_option( $obj_site, 'cust_site_icon_info', $icon_info ); } if ( isset( $params['qsw_page'] ) && $params['qsw_page'] ) { set_transient( 'mainwp_transient_just_connected_site_id', $id, HOUR_IN_SECONDS ); $message = sprintf( esc_html__( '%1$sCongratulations you have connected %2$s.%3$s After finishing the Quick Setup Wizard, you can add additional sites from the Add New Sites page.', 'mainwp' ), '
', '' . esc_html( $params['name'] ) . '', '
' ); } else { $message = sprintf( esc_html__( 'Site successfully added - Visit the Site\'s %1$sDashboard%2$s now.%3$s', 'mainwp' ), '', '', '
' ); } $website = MainWP_DB::instance()->get_website_by_id( $id ); if ( $website ) { // to fix. if ( ! empty( $information['regverify'] ) ) { MainWP_DB::instance()->update_website_option( $website, 'register_verify_key', $information['regverify'] ); } $glo_settings = MainWP_Uptime_Monitoring_Handle::get_global_monitoring_settings(); $monitoring_glo_active = is_array( $glo_settings ) && isset( $glo_settings['active'] ) ? (int) $glo_settings['active'] : 1; if ( $monitoring_glo_active ) { MainWP_DB_Uptime_Monitoring::instance()->update_wp_monitor( array( 'wpid' => $id, 'active' => -1, 'interval' => -1, // -1 - use global setting. 'timeout' => -1, 'method' => 'useglobal', 'type' => 'useglobal', 'up_status_codes' => 'useglobal', 'issub' => 0, // primary monitor. ) ); } /** * Fires immediately after a new website is added. * * @since 4.5.1.1 * * @param object $website website data. * @param array $information The array of information data . */ do_action( 'mainwp_site_added', $website, $information ); /** * New site added * * Fires after adding a website to MainWP Dashboard. * * @param int $id Child site ID. * * @since 3.4 */ do_action( 'mainwp_added_new_site', $id, $website ); MainWP_Sync::sync_init_empty_values( $website ); MainWP_Sync::sync_information_array( $website, $information ); } } else { $error = sprintf( esc_html__( 'Undefined error occurred. Please try again. For additional help, contact the MainWP Support.', 'mainwp' ), '', ' ' ); // NOSONAR - noopener - open safe. } } catch ( MainWP_Exception $e ) { if ( 'HTTPERROR' === $e->getMessage() ) { $error = 'HTTP error' . ( null !== $e->get_message_extra() ? ' - ' . $e->get_message_extra() : '' ); } elseif ( 'NOMAINWP' === $e->getMessage() ) { $error = MainWP_Error_Helper::get_error_not_detected_connect(); } else { $error = $e->getMessage(); } } } return array( $message, $error, $id, $existed_id ); } /** * Method update_wp_site() * * Update Child Site. * * @param mixed $params Udate parameters. * * @return int Child Site ID on success and return 0 on failure. * @throws \MainWP_Exception Error message. * * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() */ public static function update_wp_site( $params ) { if ( ! isset( $params['websiteid'] ) || ! MainWP_Utility::ctype_digit( $params['websiteid'] ) ) { return 0; } if ( isset( $params['is_staging'] ) ) { unset( $params['is_staging'] ); } $website = MainWP_DB::instance()->get_website_by_id( $params['websiteid'] ); if ( null === $website ) { return 0; } if ( ! MainWP_System_Utility::can_edit_website( $website ) ) { return 0; } $data = array(); $uniqueId = null; if ( isset( $params['name'] ) && ! empty( $params['name'] ) ) { $data['name'] = htmlentities( $params['name'] ); } if ( isset( $params['wpadmin'] ) && ! empty( $params['wpadmin'] ) ) { $data['adminname'] = $params['wpadmin']; } if ( isset( $params['unique_id'] ) ) { $data['uniqueId'] = $params['unique_id']; $uniqueId = $params['unique_id']; } if ( empty( $data ) ) { return 0; } MainWP_DB::instance()->update_website_values( $website->id, $data ); if ( null !== $uniqueId ) { try { MainWP_Connect::fetch_url_authed( $website, 'update_values', array( 'uniqueId' => $uniqueId ) ); } catch ( MainWP_Exception $e ) { // error update unique id. } } /** * Action: mainwp_updated_site * * Fires after updatig the child site options. * * @param int $website->id Child site ID. * @param array $data Child site data. * * @since 3.5.1 */ do_action( 'mainwp_updated_site', $website->id, $data ); return $website->id; } }