public static function performAllChecks() { $websites = MainWP_DB::Instance()->getOfflineChecks(); foreach ($websites as $website) { if ($website->sync_errors != '') { try { //Add if (function_exists('openssl_pkey_new')) { $conf = array('private_key_bits' => 384); $conf_loc = MainWP_System::get_openssl_conf(); if (!empty($conf_loc)) { $conf['config'] = $conf_loc; } $res = openssl_pkey_new($conf); @openssl_pkey_export($res, $privkey, null, $conf); $pubkey = openssl_pkey_get_details($res); $pubkey = $pubkey['key']; } else { $privkey = '-1'; $pubkey = '-1'; } $information = MainWP_Utility::fetchUrlNotAuthed($website->url, $website->adminname, 'register', array('pubkey' => $pubkey, 'server' => get_admin_url(), 'uniqueId' => $website->uniqueId), false, $website->verify_certificate, $website->http_user, $website->http_pass, $website->ssl_version); if (!isset($information['error']) || $information['error'] == '') { if (isset($information['register']) && $information['register'] == 'OK') { //Update website MainWP_DB::Instance()->updateWebsiteValues($website->id, array('pubkey' => base64_encode($pubkey), 'privkey' => base64_encode($privkey), 'nossl' => $information['nossl'], 'nosslkey' => isset($information['nosslkey']) ? $information['nosslkey'] : '', 'uniqueId' => isset($information['uniqueId']) ? $information['uniqueId'] : '')); $message = 'Site successfully reconnected'; MainWP_Sync::syncInformationArray($website, $information); } } } catch (Exception $e) { } } self::performCheck($website); } }
function mainwp_cronupdatescheck_action() { MainWP_Logger::Instance()->info('CRON :: updates check'); @ignore_user_abort(true); @set_time_limit(0); $mem = '512M'; @ini_set('memory_limit', $mem); @ini_set('max_execution_time', 0); MainWP_Utility::update_option('mainwp_cron_last_updatescheck', time()); $mainwpAutomaticDailyUpdate = get_option('mainwp_automaticDailyUpdate'); $mainwpLastAutomaticUpdate = get_option('mainwp_updatescheck_last'); if ($mainwpLastAutomaticUpdate == date('d/m/Y')) { MainWP_Logger::Instance()->debug('CRON :: updates check :: already updated today'); return; } $websites = MainWP_DB::Instance()->getWebsitesCheckUpdates(4); MainWP_Logger::Instance()->debug('CRON :: updates check :: found ' . count($websites) . ' websites'); $userid = null; foreach ($websites as $website) { $websiteValues = array('dtsAutomaticSyncStart' => time()); if ($userid == null) { $userid = $website->userid; } MainWP_DB::Instance()->updateWebsiteSyncValues($website->id, $websiteValues); } if (count($websites) == 0) { $busyCounter = MainWP_DB::Instance()->getWebsitesCountWhereDtsAutomaticSyncSmallerThenStart(); if ($busyCounter == 0) { MainWP_Logger::Instance()->debug('CRON :: updates check :: got to the mail part'); //Send the email & update all to this time! $mail = ''; $sendMail = false; $sitesCheckCompleted = null; if (get_option('mainwp_backup_before_upgrade') == 1) { $sitesCheckCompleted = get_option('mainwp_automaticUpdate_backupChecks'); if (!is_array($sitesCheckCompleted)) { $sitesCheckCompleted = null; } } $pluginsNewUpdate = get_option('mainwp_updatescheck_mail_update_plugins_new'); if (!is_array($pluginsNewUpdate)) { $pluginsNewUpdate = array(); } $pluginsToUpdate = get_option('mainwp_updatescheck_mail_update_plugins'); if (!is_array($pluginsToUpdate)) { $pluginsToUpdate = array(); } $ignoredPluginsNewUpdate = get_option('mainwp_updatescheck_mail_ignore_plugins_new'); if (!is_array($ignoredPluginsNewUpdate)) { $ignoredPluginsNewUpdate = array(); } $ignoredPluginsToUpdate = get_option('mainwp_updatescheck_mail_ignore_plugins'); if (!is_array($ignoredPluginsToUpdate)) { $ignoredPluginsToUpdate = array(); } if (count($pluginsNewUpdate) != 0 || count($pluginsToUpdate) != 0) { $sendMail = true; $mail .= '<div><strong>WordPress Plugin Updates</strong></div>'; $mail .= '<ul>'; $mail .= $this->print_updates_array_lines($pluginsNewUpdate, null); $mail .= $this->print_updates_array_lines($pluginsToUpdate, $sitesCheckCompleted); // $mail .= $this->print_updates_array_lines( $ignoredPluginsNewUpdate, null ); // $mail .= $this->print_updates_array_lines( $ignoredPluginsToUpdate, null ); $mail .= '</ul>'; } $themesNewUpdate = get_option('mainwp_updatescheck_mail_update_themes_new'); if (!is_array($themesNewUpdate)) { $themesNewUpdate = array(); } $themesToUpdate = get_option('mainwp_updatescheck_mail_update_themes'); if (!is_array($themesToUpdate)) { $themesToUpdate = array(); } $ignoredThemesNewUpdate = get_option('mainwp_updatescheck_mail_ignore_themes_new'); if (!is_array($ignoredThemesNewUpdate)) { $ignoredThemesNewUpdate = array(); } $ignoredThemesToUpdate = get_option('mainwp_updatescheck_mail_ignore_themes'); if (!is_array($ignoredThemesToUpdate)) { $ignoredThemesToUpdate = array(); } if (count($themesNewUpdate) != 0 || count($themesToUpdate) != 0) { $sendMail = true; $mail .= '<div><strong>WordPress Themes Updates</strong></div>'; $mail .= '<ul>'; $mail .= $this->print_updates_array_lines($themesNewUpdate, null); $mail .= $this->print_updates_array_lines($themesToUpdate, $sitesCheckCompleted); // $mail .= $this->print_updates_array_lines( $ignoredThemesNewUpdate, null ); // $mail .= $this->print_updates_array_lines( $ignoredThemesToUpdate, null ); $mail .= '</ul>'; } $coreNewUpdate = get_option('mainwp_updatescheck_mail_update_core_new'); if (!is_array($coreNewUpdate)) { $coreNewUpdate = array(); } $coreToUpdate = get_option('mainwp_updatescheck_mail_update_core'); if (!is_array($coreToUpdate)) { $coreToUpdate = array(); } $ignoredCoreNewUpdate = get_option('mainwp_updatescheck_mail_ignore_core_new'); if (!is_array($ignoredCoreNewUpdate)) { $ignoredCoreNewUpdate = array(); } $ignoredCoreToUpdate = get_option('mainwp_updatescheck_mail_ignore_core'); if (!is_array($ignoredCoreToUpdate)) { $ignoredCoreToUpdate = array(); } if (count($coreNewUpdate) != 0 || count($coreToUpdate) != 0 || count($ignoredCoreNewUpdate) != 0 || count($ignoredCoreToUpdate) != 0) { $sendMail = true; $mail .= '<div><strong>WordPress Core Updates</strong></div>'; $mail .= '<ul>'; $mail .= $this->print_updates_array_lines($coreNewUpdate, null); $mail .= $this->print_updates_array_lines($coreToUpdate, $sitesCheckCompleted); $mail .= $this->print_updates_array_lines($ignoredCoreNewUpdate, null); $mail .= $this->print_updates_array_lines($ignoredCoreToUpdate, null); $mail .= '</ul>'; } $pluginConflicts = get_option('mainwp_updatescheck_mail_pluginconflicts'); if ($pluginConflicts === false) { $pluginConflicts = ''; } if ($pluginConflicts != '') { $sendMail = true; $mail .= '<div><strong>WordPress Plugin Conflicts</strong></div>'; $mail .= '<ul>'; $mail .= $pluginConflicts; $mail .= '</ul>'; } $themeConflicts = get_option('mainwp_updatescheck_mail_themeconflicts'); if ($themeConflicts === false) { $themeConflicts = ''; } if ($themeConflicts != '') { $sendMail = true; $mail .= '<div><strong>WordPress Theme Conflicts</strong></div>'; $mail .= '<ul>'; $mail .= $themeConflicts; $mail .= '</ul>'; } MainWP_Utility::update_option('mainwp_automaticUpdate_backupChecks', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_update_core_new', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_update_plugins_new', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_update_themes_new', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_update_core', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_update_plugins', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_update_themes', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_core', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_plugins', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_themes', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_core_new', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_plugins_new', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_themes_new', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_pluginconflicts', ''); MainWP_Utility::update_option('mainwp_updatescheck_mail_themeconflicts', ''); MainWP_Utility::update_option('mainwp_updatescheck_last', date('d/m/Y')); if (!$sendMail) { MainWP_Logger::Instance()->debug('CRON :: updates check :: sendMail is false'); return; } if ($mainwpAutomaticDailyUpdate !== false && $mainwpAutomaticDailyUpdate != 0) { //Create a nice email to send $email = get_option('mainwp_updatescheck_mail_email'); MainWP_Logger::Instance()->debug('CRON :: updates check :: send mail to ' . $email); if ($email != false && $email != '') { $mail = '<div>We noticed the following updates are available on your MainWP Dashboard. (<a href="' . site_url() . '">' . site_url() . '</a>)</div> <div></div> ' . $mail . ' Update Key: (<strong><span style="color:#008000">Trusted</span></strong>) will be auto updated within 24 hours. (<strong><span style="color:#ff0000">Not Trusted</span></strong>) you will need to log into your Main Dashboard and update <div> </div> <div>If your MainWP is configured to use Auto Updates these upgrades will be installed in the next 24 hours. To find out how to enable automatic updates please see the FAQs below.</div> <div><a href="http://docs.mainwp.com/marking-a-plugin-as-trusted/" style="color:#446200" target="_blank">http://docs.mainwp.com/marking-a-plugin-as-trusted/</a></div> <div><a href="http://docs.mainwp.com/marking-a-theme-as-trusted/" style="color:#446200" target="_blank">http://docs.mainwp.com/marking-a-theme-as-trusted/</a></div> <div><a href="http://docs.mainwp.com/marking-a-sites-wp-core-updates-as-trusted/" style="color:#446200" target="_blank">http://docs.mainwp.com/marking-a-sites-wp-core-updates-as-trusted/</a></div>'; wp_mail($email, 'MainWP - Trusted Updates', MainWP_Utility::formatEmail($email, $mail), array('From: "' . get_option('admin_email') . '" <' . get_option('admin_email') . '>', 'content-type: text/html')); } } } } else { $userExtension = MainWP_DB::Instance()->getUserExtensionByUserId($userid); $decodedIgnoredPlugins = json_decode($userExtension->ignored_plugins, true); if (!is_array($decodedIgnoredPlugins)) { $decodedIgnoredPlugins = array(); } $trustedPlugins = json_decode($userExtension->trusted_plugins, true); if (!is_array($trustedPlugins)) { $trustedPlugins = array(); } $decodedIgnoredThemes = json_decode($userExtension->ignored_themes, true); if (!is_array($decodedIgnoredThemes)) { $decodedIgnoredThemes = array(); } $trustedThemes = json_decode($userExtension->trusted_themes, true); if (!is_array($trustedThemes)) { $trustedThemes = array(); } $coreToUpdateNow = array(); $coreToUpdate = array(); $coreNewUpdate = array(); $ignoredCoreToUpdate = array(); $ignoredCoreNewUpdate = array(); $pluginsToUpdateNow = array(); $pluginsToUpdate = array(); $pluginsNewUpdate = array(); $ignoredPluginsToUpdate = array(); $ignoredPluginsNewUpdate = array(); $themesToUpdateNow = array(); $themesToUpdate = array(); $themesNewUpdate = array(); $ignoredThemesToUpdate = array(); $ignoredThemesNewUpdate = array(); $pluginConflicts = ''; $themeConflicts = ''; $allWebsites = array(); $infoTrustedText = ' (<span style="color:#008000"><strong>Trusted</strong></span>)'; $infoNotTrustedText = ' (<strong><span style="color:#ff0000">Not Trusted</span></strong>)'; foreach ($websites as $website) { $websiteDecodedIgnoredPlugins = json_decode($website->ignored_plugins, true); if (!is_array($websiteDecodedIgnoredPlugins)) { $websiteDecodedIgnoredPlugins = array(); } $websiteDecodedIgnoredThemes = json_decode($website->ignored_themes, true); if (!is_array($websiteDecodedIgnoredThemes)) { $websiteDecodedIgnoredThemes = array(); } //Perform check & update if (!MainWP_Sync::syncSite($website, false, true)) { $websiteValues = array('dtsAutomaticSync' => time()); MainWP_DB::Instance()->updateWebsiteSyncValues($website->id, $websiteValues); continue; } $website = MainWP_DB::Instance()->getWebsiteById($website->id); /** Check core upgrades **/ $websiteLastCoreUpgrades = json_decode(MainWP_DB::Instance()->getWebsiteOption($website, 'last_wp_upgrades'), true); $websiteCoreUpgrades = json_decode(MainWP_DB::Instance()->getWebsiteOption($website, 'wp_upgrades'), true); //Run over every update we had last time.. if (isset($websiteCoreUpgrades['current'])) { $infoTxt = '<a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ' . $websiteCoreUpgrades['current'] . ' to ' . $websiteCoreUpgrades['new']; $infoNewTxt = '*NEW* <a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ' . $websiteCoreUpgrades['current'] . ' to ' . $websiteCoreUpgrades['new']; $newUpdate = !(isset($websiteLastCoreUpgrades['current']) && $websiteLastCoreUpgrades['current'] == $websiteCoreUpgrades['current'] && $websiteLastCoreUpgrades['new'] == $websiteCoreUpgrades['new']); if ($website->automatic_update == 1) { if ($newUpdate) { $coreNewUpdate[] = array($website->id, $infoNewTxt, $infoTrustedText); } else { //Check ignore ? $ignoredCoreToUpdate $coreToUpdateNow[] = $website->id; $allWebsites[$website->id] = $website; $coreToUpdate[] = array($website->id, $infoTxt, $infoTrustedText); } } else { if ($newUpdate) { $ignoredCoreNewUpdate[] = array($website->id, $infoNewTxt, $infoNotTrustedText); } else { $ignoredCoreToUpdate[] = array($website->id, $infoTxt, $infoNotTrustedText); } } } /** Check plugins **/ $websiteLastPlugins = json_decode(MainWP_DB::Instance()->getWebsiteOption($website, 'last_plugin_upgrades'), true); $websitePlugins = json_decode($website->plugin_upgrades, true); /** Check themes **/ $websiteLastThemes = json_decode(MainWP_DB::Instance()->getWebsiteOption($website, 'last_theme_upgrades'), true); $websiteThemes = json_decode($website->theme_upgrades, true); $decodedPremiumUpgrades = json_decode(MainWP_DB::Instance()->getWebsiteOption($website, 'premium_upgrades'), true); if (is_array($decodedPremiumUpgrades)) { foreach ($decodedPremiumUpgrades as $slug => $premiumUpgrade) { if ($premiumUpgrade['type'] == 'plugin') { if (!is_array($websitePlugins)) { $websitePlugins = array(); } $websitePlugins[$slug] = $premiumUpgrade; } else { if ($premiumUpgrade['type'] == 'theme') { if (!is_array($websiteThemes)) { $websiteThemes = array(); } $websiteThemes[$slug] = $premiumUpgrade; } } } } //Run over every update we had last time.. foreach ($websitePlugins as $pluginSlug => $pluginInfo) { if (isset($decodedIgnoredPlugins[$pluginSlug]) || isset($websiteDecodedIgnoredPlugins[$pluginSlug])) { continue; } $infoTxt = '<a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ' . $pluginInfo['Name'] . ' ' . $pluginInfo['Version'] . ' to ' . $pluginInfo['update']['new_version']; $infoNewTxt = '*NEW* <a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ' . $pluginInfo['Name'] . ' ' . $pluginInfo['Version'] . ' to ' . $pluginInfo['update']['new_version']; $newUpdate = !(isset($websiteLastPlugins[$pluginSlug]) && $pluginInfo['Version'] == $websiteLastPlugins[$pluginSlug]['Version'] && $pluginInfo['update']['new_version'] == $websiteLastPlugins[$pluginSlug]['update']['new_version']); //update this.. if (in_array($pluginSlug, $trustedPlugins)) { //Trusted if ($newUpdate) { $pluginsNewUpdate[] = array($website->id, $infoNewTxt, $infoTrustedText); } else { $pluginsToUpdateNow[$website->id][] = $pluginSlug; $allWebsites[$website->id] = $website; $pluginsToUpdate[] = array($website->id, $infoTxt, $infoTrustedText); } } else { //Not trusted if ($newUpdate) { $ignoredPluginsNewUpdate[] = array($website->id, $infoNewTxt, $infoNotTrustedText); } else { $ignoredPluginsToUpdate[] = array($website->id, $infoTxt, $infoNotTrustedText); } } } //Run over every update we had last time.. foreach ($websiteThemes as $themeSlug => $themeInfo) { if (isset($decodedIgnoredThemes[$themeSlug]) || isset($websiteDecodedIgnoredThemes[$themeSlug])) { continue; } $infoTxt = '<a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ' . $themeInfo['Name'] . ' ' . $themeInfo['Version'] . ' to ' . $themeInfo['update']['new_version']; $infoNewTxt = '*NEW* <a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ' . $themeInfo['Name'] . ' ' . $themeInfo['Version'] . ' to ' . $themeInfo['update']['new_version']; $newUpdate = !(isset($websiteLastThemes[$themeSlug]) && $themeInfo['Version'] == $websiteLastThemes[$themeSlug]['Version'] && $themeInfo['update']['new_version'] == $websiteLastThemes[$themeSlug]['update']['new_version']); //update this.. if (in_array($themeSlug, $trustedThemes)) { //Trusted if ($newUpdate) { $themesNewUpdate[] = array($website->id, $infoNewTxt, $infoTrustedText); } else { $themesToUpdateNow[$website->id][] = $themeSlug; $allWebsites[$website->id] = $website; $themesToUpdate[] = array($website->id, $infoTxt, $infoTrustedText); } } else { //Not trusted if ($newUpdate) { $ignoredThemesNewUpdate[] = array($website->id, $infoNewTxt, $infoNotTrustedText); } else { $ignoredThemesToUpdate[] = array($website->id, $infoTxt, $infoNotTrustedText); } } } /** * Show plugin conflicts */ $sitePluginConflicts = json_decode($website->pluginConflicts, true); if (count($sitePluginConflicts) > 0) { $infoTxt = '<a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - '; $pluginConflicts .= '<li>' . $infoTxt; $added = false; foreach ($sitePluginConflicts as $sitePluginConflict) { if ($added) { $pluginConflicts .= ', '; } $pluginConflicts .= $sitePluginConflict; $added = true; } $pluginConflicts .= '</li>' . "\n"; } /** * Show theme conflicts */ $siteThemeConflicts = json_decode($website->themeConflicts, true); if (count($siteThemeConflicts) > 0) { $infoTxt = '<a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - '; $themeConflicts .= '<li>' . $infoTxt; $added = false; foreach ($siteThemeConflicts as $siteThemeConflict) { if ($added) { $themeConflicts .= ', '; } $themeConflicts .= $siteThemeConflict; $added = true; } $themeConflicts .= '</li>' . "\n"; } //Loop over last plugins & current plugins, check if we need to upgrade them.. $user = get_userdata($website->userid); $email = MainWP_Utility::getNotificationEmail($user); MainWP_Utility::update_option('mainwp_updatescheck_mail_email', $email); MainWP_DB::Instance()->updateWebsiteSyncValues($website->id, array('dtsAutomaticSync' => time())); MainWP_DB::Instance()->updateWebsiteOption($website, 'last_wp_upgrades', json_encode($websiteCoreUpgrades)); MainWP_DB::Instance()->updateWebsiteOption($website, 'last_plugin_upgrades', $website->plugin_upgrades); MainWP_DB::Instance()->updateWebsiteOption($website, 'last_theme_upgrades', $website->theme_upgrades); } if (count($coreNewUpdate) != 0) { $coreNewUpdateSaved = get_option('mainwp_updatescheck_mail_update_core_new'); MainWP_Utility::update_option('mainwp_updatescheck_mail_update_core_new', MainWP_Utility::array_merge($coreNewUpdateSaved, $coreNewUpdate)); } if (count($pluginsNewUpdate) != 0) { $pluginsNewUpdateSaved = get_option('mainwp_updatescheck_mail_update_plugins_new'); MainWP_Utility::update_option('mainwp_updatescheck_mail_update_plugins_new', MainWP_Utility::array_merge($pluginsNewUpdateSaved, $pluginsNewUpdate)); } if (count($themesNewUpdate) != 0) { $themesNewUpdateSaved = get_option('mainwp_updatescheck_mail_update_themes_new'); MainWP_Utility::update_option('mainwp_updatescheck_mail_update_themes_new', MainWP_Utility::array_merge($themesNewUpdateSaved, $themesNewUpdate)); } if (count($coreToUpdate) != 0) { $coreToUpdateSaved = get_option('mainwp_updatescheck_mail_update_core'); MainWP_Utility::update_option('mainwp_updatescheck_mail_update_core', MainWP_Utility::array_merge($coreToUpdateSaved, $coreToUpdate)); } if (count($pluginsToUpdate) != 0) { $pluginsToUpdateSaved = get_option('mainwp_updatescheck_mail_update_plugins'); MainWP_Utility::update_option('mainwp_updatescheck_mail_update_plugins', MainWP_Utility::array_merge($pluginsToUpdateSaved, $pluginsToUpdate)); } if (count($themesToUpdate) != 0) { $themesToUpdateSaved = get_option('mainwp_updatescheck_mail_update_themes'); MainWP_Utility::update_option('mainwp_updatescheck_mail_update_themes', MainWP_Utility::array_merge($themesToUpdateSaved, $themesToUpdate)); } if (count($ignoredCoreToUpdate) != 0) { $ignoredCoreToUpdateSaved = get_option('mainwp_updatescheck_mail_ignore_core'); MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_core', MainWP_Utility::array_merge($ignoredCoreToUpdateSaved, $ignoredCoreToUpdate)); } if (count($ignoredCoreNewUpdate) != 0) { $ignoredCoreNewUpdateSaved = get_option('mainwp_updatescheck_mail_ignore_core_new'); MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_core_new', MainWP_Utility::array_merge($ignoredCoreNewUpdateSaved, $ignoredCoreNewUpdate)); } if (count($ignoredPluginsToUpdate) != 0) { $ignoredPluginsToUpdateSaved = get_option('mainwp_updatescheck_mail_ignore_plugins'); MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_plugins', MainWP_Utility::array_merge($ignoredPluginsToUpdateSaved, $ignoredPluginsToUpdate)); } if (count($ignoredPluginsNewUpdate) != 0) { $ignoredPluginsNewUpdateSaved = get_option('mainwp_updatescheck_mail_ignore_plugins_new'); MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_plugins_new', MainWP_Utility::array_merge($ignoredPluginsNewUpdateSaved, $ignoredPluginsNewUpdate)); } if (count($ignoredThemesToUpdate) != 0) { $ignoredThemesToUpdateSaved = get_option('mainwp_updatescheck_mail_ignore_themes'); MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_themes', MainWP_Utility::array_merge($ignoredThemesToUpdateSaved, $ignoredThemesToUpdate)); } if (count($ignoredThemesNewUpdate) != 0) { $ignoredThemesNewUpdateSaved = get_option('mainwp_updatescheck_mail_ignore_themes_new'); MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_themes_new', MainWP_Utility::array_merge($ignoredThemesNewUpdateSaved, $ignoredThemesNewUpdate)); } if ($pluginConflicts != '') { $pluginConflictsSaved = get_option('mainwp_updatescheck_mail_pluginconflicts'); if ($pluginConflictsSaved == false) { $pluginConflictsSaved = ''; } MainWP_Utility::update_option('mainwp_updatescheck_mail_pluginconflicts', $pluginConflictsSaved . $pluginConflicts); } if ($themeConflicts != '') { $themeConflictsSaved = get_option('mainwp_updatescheck_mail_themeconflicts'); if ($themeConflictsSaved == false) { $themeConflictsSaved = ''; } MainWP_Utility::update_option('mainwp_updatescheck_mail_themeconflicts', $themeConflictsSaved . $themeConflicts); } if (count($coreToUpdate) == 0 && count($pluginsToUpdate) == 0 && count($themesToUpdate) == 0 && count($ignoredCoreToUpdate) == 0 && count($ignoredCoreNewUpdate) == 0 && $pluginConflicts == '' && $themeConflicts == '') { return; } if (get_option('mainwp_automaticDailyUpdate') != 1) { return; } //Check if backups are required! if (get_option('mainwp_backup_before_upgrade') == 1) { $sitesCheckCompleted = get_option('mainwp_automaticUpdate_backupChecks'); if (!is_array($sitesCheckCompleted)) { $sitesCheckCompleted = array(); } $websitesToCheck = array(); foreach ($pluginsToUpdateNow as $websiteId => $slugs) { $websitesToCheck[$websiteId] = true; } foreach ($themesToUpdateNow as $websiteId => $slugs) { $websitesToCheck[$websiteId] = true; } foreach ($coreToUpdateNow as $websiteId) { $websitesToCheck[$websiteId] = true; } foreach ($websitesToCheck as $siteId => $bool) { if ($allWebsites[$siteId]->backup_before_upgrade == 0) { $sitesCheckCompleted[$siteId] = true; } if (isset($sitesCheckCompleted[$siteId])) { continue; } $dir = MainWP_Utility::getMainWPSpecificDir($siteId); //Check if backup ok $lastBackup = -1; if (file_exists($dir) && ($dh = opendir($dir))) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { $theFile = $dir . $file; if (MainWP_Utility::isArchive($file) && !MainWP_Utility::isSQLArchive($file) && filemtime($theFile) > $lastBackup) { $lastBackup = filemtime($theFile); } } } closedir($dh); } $backupRequired = $lastBackup < time() - 7 * 24 * 60 * 60 ? true : false; if (!$backupRequired) { $sitesCheckCompleted[$siteId] = true; MainWP_Utility::update_option('mainwp_automaticUpdate_backupChecks', $sitesCheckCompleted); continue; } try { $result = MainWP_Manage_Sites::backup($siteId, 'full', '', '', 0, 0, 0, 0); MainWP_Manage_Sites::backupDownloadFile($siteId, 'full', $result['url'], $result['local']); $sitesCheckCompleted[$siteId] = true; MainWP_Utility::update_option('mainwp_automaticUpdate_backupChecks', $sitesCheckCompleted); } catch (Exception $e) { $sitesCheckCompleted[$siteId] = false; MainWP_Utility::update_option('mainwp_automaticUpdate_backupChecks', $sitesCheckCompleted); } } } else { $sitesCheckCompleted = null; } //Update plugins foreach ($pluginsToUpdateNow as $websiteId => $slugs) { if ($sitesCheckCompleted != null && $sitesCheckCompleted[$websiteId] == false) { continue; } try { MainWP_Utility::fetchUrlAuthed($allWebsites[$websiteId], 'upgradeplugintheme', array('type' => 'plugin', 'list' => urldecode(implode(',', $slugs)))); if (isset($information['sync']) && !empty($information['sync'])) { MainWP_Sync::syncInformationArray($allWebsites[$websiteId], $information['sync']); } } catch (Exception $e) { } } //Update themes foreach ($themesToUpdateNow as $websiteId => $slugs) { if ($sitesCheckCompleted != null && $sitesCheckCompleted[$websiteId] == false) { continue; } try { MainWP_Utility::fetchUrlAuthed($allWebsites[$websiteId], 'upgradeplugintheme', array('type' => 'theme', 'list' => urldecode(implode(',', $slugs)))); if (isset($information['sync']) && !empty($information['sync'])) { MainWP_Sync::syncInformationArray($allWebsites[$websiteId], $information['sync']); } } catch (Exception $e) { } } //Update core foreach ($coreToUpdateNow as $websiteId) { if ($sitesCheckCompleted != null && $sitesCheckCompleted[$websiteId] == false) { continue; } try { MainWP_Utility::fetchUrlAuthed($allWebsites[$websiteId], 'upgrade'); } catch (Exception $e) { } } do_action('mainwp_cronupdatecheck_action', $pluginsNewUpdate, $pluginsToUpdate, $pluginsToUpdateNow, $themesNewUpdate, $themesToUpdate, $themesToUpdateNow, $coreNewUpdate, $coreToUpdate, $coreToUpdateNow); } }
public static function addSite($website) { $error = ''; $message = ''; if ($website) { $error = __('Your site is already added to MainWP', 'mainwp'); } else { try { //Add if (function_exists('openssl_pkey_new')) { $conf = array('private_key_bits' => 384); $conf_loc = MainWP_System::get_openssl_conf(); if (!empty($conf_loc)) { $conf['config'] = $conf_loc; } $res = openssl_pkey_new($conf); @openssl_pkey_export($res, $privkey, null, $conf); $pubkey = openssl_pkey_get_details($res); $pubkey = $pubkey['key']; } else { $privkey = '-1'; $pubkey = '-1'; } $url = $_POST['managesites_add_wpurl']; $pluginConflicts = get_option('mainwp_pluginConflicts'); if ($pluginConflicts !== false) { $pluginConflicts = array_keys($pluginConflicts); } $themeConflicts = get_option('mainwp_themeConflicts'); if ($themeConflicts !== false) { $themeConflicts = array_keys($themeConflicts); } // to fix bug if (is_array($pluginConflicts)) { $pluginConflicts = array_filter($pluginConflicts); } if (is_array($themeConflicts)) { $themeConflicts = array_filter($themeConflicts); } $verifyCertificate = !isset($_POST['verify_certificate']) || empty($_POST['verify_certificate']) ? null : $_POST['verify_certificate']; $sslVersion = MainWP_Utility::getCURLSSLVersion(!isset($_POST['ssl_version']) || empty($_POST['ssl_version']) ? null : $_POST['ssl_version']); $addUniqueId = isset($_POST['managesites_add_uniqueId']) ? $_POST['managesites_add_uniqueId'] : ''; $http_user = isset($_POST['managesites_add_http_user']) ? $_POST['managesites_add_http_user'] : ''; $http_pass = isset($_POST['managesites_add_http_pass']) ? $_POST['managesites_add_http_pass'] : ''; $information = MainWP_Utility::fetchUrlNotAuthed($url, $_POST['managesites_add_wpadmin'], 'register', array('pubkey' => $pubkey, 'server' => get_admin_url(), 'uniqueId' => $addUniqueId, 'pluginConflicts' => json_encode($pluginConflicts), 'themeConflicts' => json_encode($themeConflicts)), false, $verifyCertificate, $http_user, $http_pass, $sslVersion); if (isset($information['error']) && $information['error'] != '') { $error = $information['error']; } else { if (isset($information['register']) && $information['register'] == 'OK') { //Add website to database $groupids = array(); $groupnames = array(); if (isset($_POST['groupids'])) { foreach ($_POST['groupids'] as $group) { $groupids[] = $group; } } if (isset($_POST['groupnames']) && $_POST['groupnames'] != '' || isset($_POST['groupnames_import']) && $_POST['groupnames_import'] != '') { if ($_POST['groupnames']) { $tmpArr = explode(',', $_POST['groupnames']); } else { if ($_POST['groupnames_import']) { $tmpArr = explode(';', $_POST['groupnames_import']); } } foreach ($tmpArr as $tmp) { $group = MainWP_DB::Instance()->getGroupByNameForUser(trim($tmp)); if ($group) { if (!in_array($group->id, $groupids)) { $groupids[] = $group->id; } } else { $groupnames[] = trim($tmp); } } } if (!isset($information['uniqueId']) || empty($information['uniqueId'])) { $addUniqueId = ''; } $http_user = isset($_POST['managesites_add_http_user']) ? $_POST['managesites_add_http_user'] : ''; $http_pass = isset($_POST['managesites_add_http_pass']) ? $_POST['managesites_add_http_pass'] : ''; global $current_user; $id = MainWP_DB::Instance()->addWebsite($current_user->ID, $_POST['managesites_add_wpname'], $_POST['managesites_add_wpurl'], $_POST['managesites_add_wpadmin'], base64_encode($pubkey), base64_encode($privkey), $information['nossl'], isset($information['nosslkey']) ? $information['nosslkey'] : null, $groupids, $groupnames, $verifyCertificate, $addUniqueId, $http_user, $http_pass, $sslVersion); $message = sprintf(__('Site successfully added - Visit the Site\'s %sDashboard%s now.', 'mainwp'), '<a href="admin.php?page=managesites&dashboard=' . $id . '" style="text-decoration: none;" title="' . __('Dashboard', 'mainwp') . '">', '</a>'); $website = MainWP_DB::Instance()->getWebsiteById($id); MainWP_Sync::syncInformationArray($website, $information); } else { $error = __('Undefined error.', 'mainwp'); } } } catch (MainWP_Exception $e) { if ($e->getMessage() == 'HTTPERROR') { $error = 'HTTP error' . ($e->getMessageExtra() != null ? ' - ' . $e->getMessageExtra() : ''); } else { if ($e->getMessage() == 'NOMAINWP') { $error = __('No MainWP Child plugin detected, first install and activate the plugin and add your site to MainWP afterwards. If you continue experiencing this issue please ', 'mainwp'); if ($e->getMessageExtra() != null) { $error .= sprintf(__('test your connection %shere%s or ', 'mainwp'), '<a href="' . admin_url('admin.php?page=managesites&do=test&site=' . urlencode($e->getMessageExtra())) . '">', '</a>'); } $error .= sprintf(__('post as much information as possible on the error in the %ssupport forum%s.', 'mainwp'), '<a href="https://mainwp.com/forum/">', '</a>'); } else { $error = $e->getMessage(); } } } } return array($message, $error); }
static function fetchUrlAuthed(&$website, $what, $params = null, $checkConstraints = false, $pForceFetch = false, $pRetryFailed = true) { if ($params == null) { $params = array(); } if ($what == 'stats' || $what == 'upgradeplugintheme' && isset($params['type']) && 'plugin' == $params['type']) { // to fix bug $try_tounch_plugins_page = get_option('mainwp_request_plugins_page_site_' . $website->id); if ('yes' == $try_tounch_plugins_page) { $page_plugins_url = MainWP_Utility::getGetDataAuthed($website, 'plugins.php'); wp_remote_get($page_plugins_url, array('timeout' => 25, 'httpversion' => '1.1')); } } $params['optimize'] = get_option('mainwp_optimize') == 1 ? 1 : 0; $postdata = MainWP_Utility::getPostDataAuthed($website, $what, $params); $information = MainWP_Utility::fetchUrl($website, $website->url, $postdata, $checkConstraints, $pForceFetch, $website->verify_certificate, $pRetryFailed, $website->http_user, $website->http_pass, $website->ssl_version); if (is_array($information) && isset($information['sync']) && !empty($information['sync'])) { MainWP_Sync::syncInformationArray($website, $information['sync']); unset($information['sync']); } return $information; }
static function fetchUrlAuthed(&$website, $what, $params = null, $checkConstraints = false, $pForceFetch = false, $pRetryFailed = true) { if ($params == null) { $params = array(); } $params['optimize'] = get_option('mainwp_optimize') == 1 ? 1 : 0; $postdata = MainWP_Utility::getPostDataAuthed($website, $what, $params); $information = MainWP_Utility::fetchUrl($website, $website->url, $postdata, $checkConstraints, $pForceFetch, $website->verify_certificate, $pRetryFailed, $website->http_user, $website->http_pass, $website->ssl_version); if (is_array($information) && isset($information['sync']) && !empty($information['sync'])) { MainWP_Sync::syncInformationArray($website, $information['sync']); unset($information['sync']); } return $information; }
public static function unfixSecurityIssue() { if (!isset($_REQUEST['id']) || !MainWP_Utility::ctype_digit($_REQUEST['id'])) { return ''; } $website = MainWP_DB::Instance()->getWebsiteById($_REQUEST['id']); if (!MainWP_Utility::can_edit_website($website)) { return ''; } $information = MainWP_Utility::fetchUrlAuthed($website, 'securityUnFix', array('feature' => $_REQUEST['feature'])); if (isset($information['sync']) && !empty($information['sync'])) { MainWP_Sync::syncInformationArray($website, $information['sync']); unset($information['sync']); } return $information; }