Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function createStream(array $tables = array())
 {
     if (!mwp_is_shell_available()) {
         throw new MWP_Worker_Exception(MWP_Worker_Exception::SHELL_NOT_AVAILABLE, 'Shell not available.');
     }
     $mysqldump = mwp_container()->getExecutableFinder()->find('mysqldump', 'mysqldump');
     $processBuilder = $this->createProcessBuilder($tables, $mysqldump);
     $process = $processBuilder->getProcess();
     mwp_logger()->info('Database dumping process starting', array('executable_location' => $mysqldump, 'command_line' => $process->getCommandLine()));
     return new MWP_Stream_ProcessOutput($process);
 }
 /**
  * @param string $method
  *
  * @param array  $options
  *
  * @throws MWP_Worker_Exception
  * @return MWP_IncrementalBackup_Database_DumperInterface
  */
 protected function createDumper($method, array $options = array())
 {
     $dumperOptions = MWP_IncrementalBackup_Database_DumpOptions::createFromArray($options);
     switch ($method) {
         case self::METHOD_MYSQLDUMP:
             $configuration = MWP_IncrementalBackup_Database_Configuration::createFromWordPressContext(mwp_context());
             $dumper = new MWP_IncrementalBackup_Database_MysqlDumpDumper($configuration, $dumperOptions);
             return $dumper;
         case self::METHOD_PHPDUMPER:
             $configuration = MWP_IncrementalBackup_Database_Configuration::createFromWordPressContext(mwp_context());
             $dumper = new MWP_IncrementalBackup_Database_PhpDumper($configuration, mwp_container()->getSystemEnvironment(), $dumperOptions);
             return $dumper;
         default:
             throw new MWP_Worker_Exception(MWP_Worker_Exception::BACKUP_DATABASE_METHOD_NOT_AVAILABLE);
             break;
     }
 }
Exemplo n.º 3
0
 protected function notifyMyself($functionName, $args = array())
 {
     if (mwp_container()->getParameter('disable_ping_back')) {
         do_action($functionName, $args);
         return;
     }
     global $current_user;
     $nonce = wp_create_nonce("mmb-fork-nonce");
     $cron_url = site_url('index.php');
     $public_key = get_option('_worker_public_key');
     $args = array('body' => array('mwp_forked_action' => $functionName, 'args' => json_encode($args), 'mmb_fork_nonce' => $nonce, 'public_key' => $public_key, 'username' => $current_user->user_login), 'timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters('https_local_ssl_verify', true));
     wp_remote_post($cron_url, $args);
 }
Exemplo n.º 4
0
 public function upgrade_themes($themes = false)
 {
     if (!$themes || empty($themes)) {
         return array('error' => 'No theme files for upgrade.');
     }
     $current = $this->mmb_get_transient('update_themes');
     $versions = array();
     if (!empty($current)) {
         foreach ($themes as $theme) {
             if (isset($current->checked[$theme])) {
                 $versions[$current->checked[$theme]] = $theme;
             }
         }
     }
     if (class_exists('Theme_Upgrader')) {
         /** @handled class */
         $upgrader = new Theme_Upgrader(mwp_container()->getUpdaterSkin());
         $result = $upgrader->bulk_upgrade($themes);
         if (!function_exists('wp_update_themes')) {
             include_once ABSPATH . 'wp-includes/update.php';
         }
         @wp_update_themes();
         $current = $this->mmb_get_transient('update_themes');
         $return = array();
         if (!empty($result)) {
             foreach ($result as $theme_tmp => $theme_info) {
                 if (is_wp_error($theme_info) || empty($theme_info)) {
                     $return[$theme_tmp] = $this->mmb_get_error($theme_info);
                 } else {
                     if (!empty($result[$theme_tmp]) || isset($current->checked[$theme_tmp]) && version_compare(array_search($theme_tmp, $versions), $current->checked[$theme_tmp], '<') == true) {
                         $return[$theme_tmp] = 1;
                     } else {
                         $return[$theme_tmp] = 'Could not refresh upgrade transients, please reload website data';
                     }
                 }
             }
             return array('upgraded' => $return);
         } else {
             return array('error' => 'Upgrade failed.');
         }
     } else {
         return array('error' => 'WordPress update required first');
     }
 }
Exemplo n.º 5
0
function mwp_is_shell_available()
{
    if (mwp_container()->getParameter('disable_shell')) {
        return false;
    }
    if (mwp_is_safe_mode()) {
        return false;
    }
    if (!function_exists('proc_open') || !function_exists('escapeshellarg')) {
        return false;
    }
    $neededFunction = array('proc_get_status', 'proc_open');
    $disabledFunction = mwp_get_disabled_functions();
    if (count(array_diff($neededFunction, $disabledFunction)) != count($neededFunction)) {
        return false;
    }
    if (!mwp_is_nio_shell_available()) {
        return false;
    }
    return true;
}
Exemplo n.º 6
0
function mwp_is_shell_available()
{
    if (mwp_container()->getParameter('disable_shell')) {
        return false;
    }
    if (mwp_is_safe_mode()) {
        return false;
    }
    if (!function_exists('proc_open') || !function_exists('escapeshellarg')) {
        return false;
    }
    if (extension_loaded('suhosin') && ($suhosin = ini_get('suhosin.executor.func.blacklist'))) {
        $suhosin = explode(',', $suhosin);
        $blacklist = array_map('trim', $suhosin);
        $blacklist = array_map('strtolower', $blacklist);
        if (in_array('proc_open', $blacklist)) {
            return false;
        }
    }
    if (!mwp_is_nio_shell_available()) {
        return false;
    }
    return true;
}
Exemplo n.º 7
0
 function mwp_init()
 {
     // When the plugin deactivates due to a corrupt installation, (de)activation hooks
     // will never get executed, so the 'mwp_recovering' option will never be deleted,
     // making the plugin always force the recovery mode , which may always fail for any
     // reason (eg. the site can't ping itself). Handle that case early.
     register_activation_hook(__FILE__, 'mwp_activation_hook');
     $GLOBALS['MMB_WORKER_VERSION'] = '4.1.28';
     $GLOBALS['MMB_WORKER_REVISION'] = '2016-02-03 00:00:00';
     // Ensure PHP version compatibility.
     if (version_compare(PHP_VERSION, '5.2', '<')) {
         trigger_error("ManageWP Worker plugin requires PHP 5.2 or higher.", E_USER_ERROR);
         exit;
     }
     if ($incrementalUpdateTime = get_option('mwp_incremental_update_active')) {
         if (time() - $incrementalUpdateTime > 3600) {
             delete_option('mwp_incremental_update_active');
         } else {
             return;
         }
     }
     if ($recoveringTime = get_option('mwp_recovering')) {
         $recoveryKey = get_transient('mwp_recovery_key');
         if (!($passedRecoveryKey = filter_input(INPUT_POST, 'mwp_recovery_key'))) {
             $recoveryKey = md5(uniqid('', true));
             set_transient('mwp_recovery_key', $recoveryKey, time() + 604800);
             // 1 week.
             $headers = array();
             if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
                 $headers['AUTHORIZATION'] = $_SERVER['HTTP_AUTHORIZATION'];
             }
             // fork only once, so we do not make too many parallel requests to the website
             $lockTime = get_option('mwp_incremental_recover_lock');
             if ($lockTime && time() - $lockTime < 1200) {
                 // lock for 20 minutes
                 return;
             }
             wp_remote_post(get_bloginfo('wpurl'), array('reject_unsafe_urls' => false, 'headers' => $headers, 'body' => array('mwp_recovery_key' => $recoveryKey), 'timeout' => 0.01));
         } else {
             if ($recoveryKey !== $passedRecoveryKey) {
                 return;
             }
             delete_transient('mwp_recovery_key');
             $recoveryKit = new MwpRecoveryKit();
             try {
                 $recoveredFiles = $recoveryKit->recover($GLOBALS['MMB_WORKER_VERSION']);
                 // Recovery complete.
                 delete_option('mwp_recovering');
                 mail('*****@*****.**', sprintf("ManageWP Worker recovered on %s", get_option('siteurl')), sprintf("%d files successfully recovered in this recovery fork of ManageWP Worker v%s. Filesystem method used was <code>%s</code>.\n\n<pre>%s</pre>", count($recoveredFiles), $GLOBALS['MMB_WORKER_VERSION'], get_filesystem_method(), implode("\n", $recoveredFiles)), 'Content-Type: text/html');
             } catch (Exception $e) {
                 if ($e->getCode() === 1337) {
                     return;
                 }
                 if (time() - $recoveringTime > 3600) {
                     // If the recovery process does not complete after an hour, deactivate the Worker for safety
                     $recoveryKit->selfDeactivate($e->getMessage());
                 }
             }
         }
         return;
     }
     // Register the autoloader that loads everything except the Google namespace.
     if (version_compare(PHP_VERSION, '5.3', '<')) {
         spl_autoload_register('mwp_autoload');
     } else {
         // The prepend parameter was added in PHP 5.3.0
         spl_autoload_register('mwp_autoload', true, true);
     }
     $GLOBALS['mmb_plugin_dir'] = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
     $GLOBALS['_mmb_item_filter'] = array();
     $GLOBALS['mmb_core'] = $core = $GLOBALS['mmb_core_backup'] = new MMB_Core();
     $siteUrl = function_exists('get_site_option') ? get_site_option('siteurl') : get_option('siteurl');
     define('MMB_XFRAME_COOKIE', 'wordpress_' . md5($siteUrl) . '_xframe');
     define('MWP_BACKUP_DIR', WP_CONTENT_DIR . '/managewp/backups');
     define('MWP_DB_DIR', MWP_BACKUP_DIR . '/mwp_db');
     add_filter('mmb_stats_filter', 'mmb_get_extended_info');
     add_action('plugins_loaded', 'mwp_return_core_reference', 1);
     add_filter('cron_schedules', 'mmb_more_reccurences');
     add_action('mmb_remote_upload', 'mmb_call_scheduled_remote_upload');
     add_action('mwp_datasend', 'mwp_datasend');
     add_action('init', 'mmb_plugin_actions', 99999);
     add_filter('install_plugin_complete_actions', 'mmb_iframe_plugins_fix');
     add_filter('comment_edit_redirect', 'mwb_edit_redirect_override');
     add_action('mwp_auto_update', 'MwpRecoveryKit::selfUpdate');
     // Datasend cron.
     if (!wp_next_scheduled('mwp_datasend')) {
         wp_schedule_event(time(), 'threehours', 'mwp_datasend');
     }
     // Register updater hooks.
     MMB_Updater::register();
     register_deactivation_hook(__FILE__, array($core, 'deactivate'));
     register_uninstall_hook(dirname(__FILE__) . '/functions.php', 'mwp_uninstall');
     // Don't send the "X-Frame-Options: SAMEORIGIN" header if we're logging in inside an iframe.
     if (isset($_COOKIE[MMB_XFRAME_COOKIE])) {
         remove_action('admin_init', 'send_frame_options_header');
         remove_action('login_init', 'send_frame_options_header');
     }
     // Remove legacy scheduler.
     if (wp_next_scheduled('mwp_backup_tasks')) {
         wp_clear_scheduled_hook('mwp_backup_tasks');
     }
     mwp_set_plugin_priority();
     $request = MWP_Worker_Request::createFromGlobals();
     $container = mwp_container();
     $responder = new MwpWorkerResponder($container);
     $kernel = new MWP_Worker_Kernel($container);
     $kernel->handleRequest($request, $responder->getCallback(), true);
 }
Exemplo n.º 8
0
 /**
  * Downloads backup file from Amazon S3 to root folder on local server.
  *
  * @param array $args arguments passed to the function
  *                    [as3_bucket_region] -> Amazon S3 bucket region
  *                    [as3_bucket] -> Amazon S3 bucket
  *                    [as3_access_key] -> Amazon S3 access key
  *                    [as3_secure_key] -> Amazon S3 secure key
  *                    [as3_directory] -> folder on user's Amazon S3 account which backup file should be downloaded from
  *                    [as3_site_folder] -> subfolder with site name in as3_directory which backup file should be downloaded from
  *                    [backup_file] -> absolute path of backup file on local server
  *
  * @return bool|array absolute path to downloaded file is successful, array with error message if not
  */
 public function get_amazons3_backup($args)
 {
     if (!mwp_container()->getSystemEnvironment()->isCurlEnabled()) {
         throw new MWP_Worker_Exception(MWP_Worker_Exception::PHP_EXTENSION_REQUIRED_CURL, 'The cURL PHP extension is required for Amazon S3 backup functionality to work. Please, enquire your hosting provider on how to enable that extension.');
     }
     $endpoint = isset($args['as3_bucket_region']) ? $args['as3_bucket_region'] : 's3.amazonaws.com';
     mwp_logger()->info('Downloading the backup file from Amazon S3', array('directory' => $args['as3_directory'], 'bucket' => $args['as3_bucket'], 'endpoint' => $args['endpoint'], 'backup_file' => $args['backup_file']));
     if ($args['as3_site_folder'] == true) {
         $args['as3_directory'] .= '/' . $this->site_name;
     }
     $start = microtime(true);
     try {
         $s3 = new S3_Client($args['as3_access_key'], str_replace(' ', '+', $args['as3_secure_key']), false, $endpoint);
         $s3->setExceptions(true);
         $temp = ABSPATH . 'mwp_temp_backup.zip';
         if (version_compare(PHP_VERSION, '5.3', '>=')) {
             $progress = new MWP_Progress_Download(3, mwp_logger());
             $s3->setProgressCallback($progress->getCallback());
         }
         $s3->getObject($args['as3_bucket'], $args['as3_directory'] . '/' . $args['backup_file'], $temp);
     } catch (Exception $e) {
         mwp_logger()->error('Error while downloading the backup file', array('exception' => $e));
         return array('error' => 'Error while downloading the backup file from Amazon S3: ' . $e->getMessage());
     }
     $fileSize = filesize($temp);
     mwp_logger()->info('Downloading backup file from Amazon S3 completed; file size is {backup_size}; average speed is {speed}', array('backup_size' => mwp_format_bytes($fileSize), 'speed' => mwp_format_bytes($fileSize / (microtime(true) - $start))));
     return $temp;
 }
Exemplo n.º 9
0
 /**
  * Worker update
  */
 public function update_worker_plugin($params)
 {
     if ($params['download_url']) {
         @(include_once ABSPATH . 'wp-admin/includes/file.php');
         @(include_once ABSPATH . 'wp-admin/includes/misc.php');
         @(include_once ABSPATH . 'wp-admin/includes/template.php');
         @(include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
         @(include_once ABSPATH . 'wp-admin/includes/screen.php');
         @(include_once ABSPATH . 'wp-admin/includes/plugin.php');
         if (!$this->is_server_writable()) {
             return array('error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide/faq/my-pluginsthemes-fail-to-update-or-i-receive-a-yellow-ftp-warning">add FTP details for automatic upgrades.</a>');
         }
         mwp_load_required_components();
         ob_start();
         @unlink(dirname(__FILE__));
         /** @handled class */
         $upgrader = new Plugin_Upgrader(mwp_container()->getUpdaterSkin());
         $result = $upgrader->run(array('package' => $params['download_url'], 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('plugin' => 'worker/init.php')));
         ob_end_clean();
         if (is_wp_error($result) || !$result) {
             return array('error' => 'ManageWP Worker plugin could not be updated.');
         } else {
             return array('success' => 'ManageWP Worker plugin successfully updated.');
         }
     }
     return array('error' => 'Bad download path for worker installation file.');
 }