Esempio n. 1
0
        function snapshot_admin_show_import_panel()
        {
            //			require( WPMUDEVSnapshot::instance()->get_setting( 'SNAPSHOT_PLUGIN_BASE_DIR' ) . '/lib/snapshot_admin_metaboxes.php' );
            $_snapshot_metaboxes = new Snapshot_View_Metabox_Admin();
            ?>
			<div id="snapshot-settings-metaboxes-general" class="wrap snapshot-wrap">
				<h2><?php 
            _ex("Snapshots Scan / Import", "Snapshot Plugin Page Title", SNAPSHOT_I18N_DOMAIN);
            ?>
</h2>

				<div id="poststuff" class="metabox-holder">
					<div id="post-body" class="">
						<div id="post-body-content" class="snapshot-metabox-holder-main">
							<p><?php 
            _e('The Snapshot import form below is used to import snapshot archives from outside of this environment into view of the snapshot plugin. If you are attempting to restore an archive from a remote server for example you first need to import the archive here. This will then show the archive in the All Snapshots listing. From that page you can then perform the needed restore.', SNAPSHOT_I18N_DOMAIN);
            ?>
</p>

							<form
								action="<?php 
            echo WPMUDEVSnapshot::instance()->get_setting('SNAPSHOT_MENU_URL');
            ?>
snapshots_import_panel"
								method="post">
								<input type="hidden" value="archives-import" name="snapshot-action">
								<?php 
            wp_nonce_field('snapshot-import', 'snapshot-noonce-field');
            ?>

								<?php 
            $_snapshot_metaboxes->snapshot_metaboxes_show_import(__('Import Options', SNAPSHOT_I18N_DOMAIN));
            ?>

								<input id="snapshot-add-button" class="button-primary" type="submit"
								       value="<?php 
            _e('Scan / Import Snapshots', SNAPSHOT_I18N_DOMAIN);
            ?>
"/>
							</form>
						</div>
					</div>
					<?php 
            //echo "_POST<pre>"; print_r($_POST); echo "</pre>";
            //echo "_GET<pre>"; print_r($_GET); echo "</pre>";
            if (isset($_REQUEST['snapshot-action']) && esc_attr($_REQUEST['snapshot-action']) == "archives-import") {
                if (wp_verify_nonce($_POST['snapshot-noonce-field'], 'snapshot-import')) {
                    if (isset($_POST['snapshot-import-archive-remote-url']) && !empty($_POST['snapshot-import-archive-remote-url'])) {
                        //echo "remote url[". $_POST['snapshot-import-archive-remote-url'] ."]<br />";
                        if (substr($_POST['snapshot-import-archive-remote-url'], 0, 4) == 'http') {
                            if (function_exists('curl_version')) {
                                $remoteFile = esc_url_raw($_POST['snapshot-import-archive-remote-url']);
                                @set_time_limit(900);
                                // 15 minutes Technically, server to server should be quick for large files.
                                ?>
<p><?php 
                                _e("PHP max_execution_time", SNAPSHOT_I18N_DOMAIN);
                                ?>
										: <?php 
                                echo ini_get('max_execution_time');
                                ?>
s</p><?php 
                                ?>
<p><?php 
                                _e("Attempting to download remote file", SNAPSHOT_I18N_DOMAIN);
                                ?>
										: <?php 
                                echo $remoteFile;
                                ?>
</p><?php 
                                flush();
                                $restoreFile = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupBaseFolderFull')) . basename($remoteFile);
                                //echo "remoteFile=[". $remoteFile ."]<br />";
                                //echo "restoreFile=[". $restoreFile ."]<br />";
                                Snapshot_Helper_Utility::remote_url_to_local_file($remoteFile, $restoreFile);
                                if (file_exists($restoreFile)) {
                                    $restoreFolder = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupRestoreFolderFull')) . "_imports";
                                    echo "<ol>";
                                    echo "<li><strong>" . __('Processing archive', SNAPSHOT_I18N_DOMAIN) . ": ", basename($restoreFile) . "</strong> (" . Snapshot_Helper_Utility::size_format(filesize($restoreFile)) . ")<ul><li>";
                                    flush();
                                    $error_status = Snapshot_Helper_Utility::archives_import_proc($restoreFile, $restoreFolder);
                                    //echo "error_status<pre>"; print_r($error_status); echo "</pre>";
                                    if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === true) {
                                        if (isset($error_status['errorText']) && strlen($error_status['errorText'])) {
                                            echo '<span class="snapshot-error">Error: ' . $error_status['errorText'] . '</span></br />';
                                        }
                                    } else {
                                        if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === false) {
                                            if (isset($error_status['responseText']) && strlen($error_status['responseText'])) {
                                                echo '<span class="snapshot-success">Success: ' . $error_status['responseText'] . '</span></br />';
                                            } else {
                                            }
                                        }
                                    }
                                    echo "</li></ul></li>";
                                    echo "</ol>";
                                } else {
                                    echo '<p>' . __('Error: Your server does not have lib_curl installed. So the import process cannot retrieve remote file.', SNAPSHOT_I18N_DOMAIN) . '</p>';
                                }
                            } else {
                                echo "<p>" . __('local import file not found. This could mean either the entered URL was not valid or the file was not publicly accessible.', SNAPSHOT_I18N_DOMAIN) . "</p>";
                            }
                        } else {
                            // Then a local directory
                            // Are we dealing with a absolote path...
                            if (substr($_POST['snapshot-import-archive-remote-url'], 0, 1) == "/") {
                                $dir = trailingslashit(esc_attr($_POST['snapshot-import-archive-remote-url']));
                            } else {
                                $dir = trailingslashit(trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupBaseFolderFull')) . esc_attr($_POST['snapshot-import-archive-remote-url']));
                            }
                            //echo "dir[". $dir ."]<br />";
                            if (is_dir($dir)) {
                                echo "<p>" . __('Importing archives from', SNAPSHOT_I18N_DOMAIN) . ": " . $dir . "</p>";
                                if ($dh = opendir($dir)) {
                                    $restoreFolder = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupRestoreFolderFull')) . "_imports";
                                    echo "<ol>";
                                    while (($file = readdir($dh)) !== false) {
                                        if ($file == '.' || $file == '..' || $file == 'index.php' || $file[0] == '.') {
                                            continue;
                                        }
                                        if (pathinfo($file, PATHINFO_EXTENSION) != "zip") {
                                            continue;
                                        }
                                        $restoreFile = $dir . $file;
                                        if (is_dir($restoreFile)) {
                                            continue;
                                        }
                                        echo "<li><strong>" . __('Processing archive', SNAPSHOT_I18N_DOMAIN) . ": ", basename($restoreFile) . "</strong> (" . Snapshot_Helper_Utility::size_format(filesize($restoreFile)) . ")<ul><li>";
                                        flush();
                                        $error_status = Snapshot_Helper_Utility::archives_import_proc($restoreFile, $restoreFolder);
                                        //echo "error_status<pre>"; print_r($error_status); echo "</pre>";
                                        if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === true) {
                                            if (isset($error_status['errorText']) && strlen($error_status['errorText'])) {
                                                echo '<span class="snapshot-error">Error: ' . $error_status['errorText'] . '</span></br />';
                                            }
                                        } else {
                                            if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === false) {
                                                if (isset($error_status['responseText']) && strlen($error_status['responseText'])) {
                                                    echo '<span class="snapshot-success">Success: ' . $error_status['responseText'] . '</span></br />';
                                                } else {
                                                }
                                            }
                                        }
                                        echo "</li></ul></li>";
                                    }
                                    echo "</ol>";
                                    closedir($dh);
                                }
                            } else {
                                echo "<p>" . sprintf(__('local import file not found %s. This could mean either the entered path was not valid or accessible.', SNAPSHOT_I18N_DOMAIN), $dir) . "</p>";
                            }
                        }
                    } else {
                        $dir = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupBaseFolderFull'));
                        echo "<p>" . __('Importing archives from', SNAPSHOT_I18N_DOMAIN) . ": " . $dir . "</p>";
                        if ($dh = opendir($dir)) {
                            $restoreFolder = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupRestoreFolderFull')) . "_imports";
                            echo "<ol>";
                            while (($file = readdir($dh)) !== false) {
                                if ($file == '.' || $file == '..' || $file == 'index.php' || $file[0] == '.') {
                                    continue;
                                }
                                if (pathinfo($file, PATHINFO_EXTENSION) != "zip") {
                                    continue;
                                }
                                $restoreFile = $dir . $file;
                                if (is_dir($restoreFile)) {
                                    continue;
                                }
                                echo "<li><strong>" . __('Processing archive', SNAPSHOT_I18N_DOMAIN) . ": ", basename($restoreFile) . "</strong> (" . Snapshot_Helper_Utility::size_format(filesize($restoreFile)) . ")<ul><li>";
                                flush();
                                $error_status = Snapshot_Helper_Utility::archives_import_proc($restoreFile, $restoreFolder);
                                //echo "error_status<pre>"; print_r($error_status); echo "</pre>";
                                if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === true) {
                                    if (isset($error_status['errorText']) && strlen($error_status['errorText'])) {
                                        echo '<span class="snapshot-error">Error: ' . $error_status['errorText'] . '</span></br />';
                                    }
                                } else {
                                    if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === false) {
                                        if (isset($error_status['responseText']) && strlen($error_status['responseText'])) {
                                            echo '<span class="snapshot-success">Success: ' . $error_status['responseText'] . '</span></br />';
                                        } else {
                                        }
                                    }
                                }
                                echo "</li></ul></li>";
                            }
                            echo "</ol>";
                            closedir($dh);
                        }
                    }
                }
                echo "<p>" . __('Snapshot import complete', SNAPSHOT_I18N_DOMAIN) . "</p>";
            }
            ?>
				</div>
			</div>
		<?php 
        }
Esempio n. 2
0
 public static function validate_step_1($restore_form)
 {
     $form_errors = array();
     $form_errors['form'] = array();
     $form_errors['message-error'] = array();
     $form_errors['message-success'] = array();
     // Do the form validation first before the heavy processing
     if (!isset($restore_form['snapshot']['archive-file']) || !strlen($restore_form['snapshot']['archive-file'])) {
         $form_errors['form']['snapshot']['archive-file'] = "Snapshot Archive file cannot be empty.";
     } else {
         $_SESSION['restore_form']['snapshot']['archive-file'] = $restore_form['snapshot']['archive-file'];
     }
     if (!isset($restore_form['wordpress']['reload']) || !strlen($restore_form['wordpress']['reload'])) {
         $form_errors['form']['wordpress']['reload'] = "WordPress Reload cannot be empty.";
     } else {
         if ($restore_form['wordpress']['reload'] != "yes" && $restore_form['wordpress']['reload'] != "no") {
             $form_errors['form']['wordpress']['reload'] = "WordPress Reload invalid value given.";
             return $form_errors;
         } else {
             $_SESSION['restore_form']['wordpress']['reload'] = $restore_form['wordpress']['reload'];
         }
     }
     if (!isset($restore_form['wordpress']['install-path']) || !strlen($restore_form['wordpress']['install-path'])) {
         $form_errors['form']['wordpress']['install-path'] = "WordPress Install Path file cannot be empty.";
     } else {
         $_SESSION['restore_form']['wordpress']['install-path'] = self::untrailingslashit_snapshot($restore_form['wordpress']['install-path']);
         if (!file_exists($_SESSION['restore_form']['wordpress']['install-path'])) {
             mkdir($_SESSION['restore_form']['wordpress']['install-path'], 0777, true);
         }
         $_SESSION['restore_form']['wordpress']['install-path'] = self::trailingslashit_snapshot($_SESSION['restore_form']['wordpress']['install-path']);
     }
     if (count($form_errors['form'])) {
         return $form_errors;
     }
     // If here then the form is valid. Now get into the heavy processing
     if (!isset($_SESSION['restore_form']['snapshot']['archive-file'])) {
         $_SESSION['restore_form']['snapshot']['archive-file'] = '';
     }
     unset($_SESSION['restore_form']['snapshot']['archive-file-local']);
     unset($_SESSION['restore_form']['snapshot']['archive-file-remote']);
     if (substr($_SESSION['restore_form']['snapshot']['archive-file'], 0, strlen('http')) == "http") {
         $_SESSION['restore_form']['snapshot']['archive-file-remote'] = $_SESSION['restore_form']['snapshot']['archive-file'];
         $_SESSION['restore_form']['snapshot']['archive-file-local'] = dirname(__FILE__) . "/_snapshot/file/" . basename($_SESSION['restore_form']['snapshot']['archive-file']);
         if (file_exists($_SESSION['restore_form']['snapshot']['archive-file-local'])) {
             $unlink_ret = unlink($_SESSION['restore_form']['snapshot']['archive-file-local']);
             if ($unlink_ret !== true) {
                 $form_errors['message-error'][] = "Unable to delete previous local file [" . $_SESSION['restore_form']['snapshot']['archive-file-local'] . "]. Manually delete the file. Check parent folder permissions and reload the page.";
                 return $form_errors;
             }
         }
         $func_ret = Snapshot_Helper_Utility::remote_url_to_local_file($_SESSION['restore_form']['snapshot']['archive-file-remote'], $_SESSION['restore_form']['snapshot']['archive-file-local']);
         if (!file_exists($_SESSION['restore_form']['snapshot']['archive-file-local']) || !filesize($_SESSION['restore_form']['snapshot']['archive-file-local'])) {
             $form_errors['message-error'][] = "Attempted to download remote Snapshot file to local [" . $_SESSION['restore_form']['snapshot']['archive-file-local'] . "]<br />";
             ". File not found or is empty. Check parent folder permissions and reload the page.";
             return $form_errors;
         } else {
             $form_errors['message-success'][] = "Remote Snapshot Archive [" . $_SESSION['restore_form']['snapshot']['archive-file-remote'] . "] downloaded and extracted successfully.";
         }
     } else {
         $local_file = '';
         if (substr($_SESSION['restore_form']['snapshot']['archive-file'], 0, 1) == "/") {
             $local_file = $_SESSION['restore_form']['snapshot']['archive-file'];
         } else {
             $local_file = self::trailingslashit_snapshot($_SERVER['DOCUMENT_ROOT']) . $_SESSION['restore_form']['snapshot']['archive-file'];
         }
         if (file_exists($local_file)) {
             $_SESSION['restore_form']['snapshot']['archive-file-local'] = $local_file;
             $form_errors['message-success'][] = "Local Snapshot Archive located [" . basename($local_file) . "] successfully.";
         }
     }
     if (isset($_SESSION['restore_form']['snapshot']['archive-file-local']) && strlen($_SESSION['restore_form']['snapshot']['archive-file-local'])) {
         /**
          * THIS IS WHERE THE RECOVERY BEGINS.
          */
         $_SESSION['restore_form']['snapshot']['extract-path'] = WP_CONTENT_DIR . "/_snapshot_recovery/extract/";
         self::unzip_archive($_SESSION['restore_form']['snapshot']['archive-file-local'], $_SESSION['restore_form']['snapshot']['extract-path']);
         // Locate and consume the Snapshot manifest file
         $_SESSION['restore_form']['snapshot']['manifest-file'] = self::trailingslashit_snapshot($_SESSION['restore_form']['snapshot']['extract-path']) . "snapshot_manifest.txt";
         if (!file_exists($_SESSION['restore_form']['snapshot']['manifest-file'])) {
             $form_errors['message-error'][] = "Snapshot archive Manifest file missing. Cannot restore/migrate via Snapshot.";
             return $form_errors;
         }
         $manifest_data = Snapshot_Helper_Utility::consume_archive_manifest($_SESSION['restore_form']['snapshot']['manifest-file']);
         if (is_array($manifest_data)) {
             $_SESSION['restore_form']['snapshot']['manifest-data'] = $manifest_data;
             $form_errors['message-success'][] = "Snapshot archive Manifest located and loaded successfully.";
         }
     }
     if ($_SESSION['restore_form']['wordpress']['reload'] == "yes" && isset($_SESSION['restore_form']['snapshot']['manifest-data']['WP_VERSION'])) {
         $_SESSION['restore_form']['wordpress']['archive-file-remote'] = 'http://wordpress.org/wordpress-' . $_SESSION['restore_form']['snapshot']['manifest-data']['WP_VERSION'] . '.zip';
         $_SESSION['restore_form']['wordpress']['archive-file-local'] = dirname(__FILE__) . "/_wordpress/file/" . basename($_SESSION['restore_form']['wordpress']['archive-file-remote']);
         $func_ret = Snapshot_Helper_Utility::remote_url_to_local_file($_SESSION['restore_form']['wordpress']['archive-file-remote'], $_SESSION['restore_form']['wordpress']['archive-file-local']);
         if (!file_exists($_SESSION['restore_form']['wordpress']['archive-file-local']) || !filesize($_SESSION['restore_form']['wordpress']['archive-file-local'])) {
             $form_errors['message-error'][] = "Attempted to download WordPress file to local [" . $_SESSION['restore_form']['wordpress']['archive-file-local'] . "]. File not found or is empty. Check parent folder permissions and reload the page.";
             return $form_errors;
         } else {
             $form_errors['message-success'][] = "Remote WordPress  Archive [" . basename($_SESSION['restore_form']['wordpress']['archive-file-local']) . "] downloaded successfully.";
             // Extract WordPress files into place
             $_SESSION['restore_form']['wordpress']['extract-path'] = dirname(__FILE__) . "/_wordpress/extract/";
             $unzip_ret = unzip_archive($_SESSION['restore_form']['wordpress']['archive-file-local'], $_SESSION['restore_form']['wordpress']['extract-path']);
             if (file_exists($_SESSION['restore_form']['wordpress']['extract-path'] . "/wordpress")) {
                 $_SESSION['restore_form']['wordpress']['extract-path'] = $_SESSION['restore_form']['wordpress']['extract-path'] . "/wordpress";
                 $form_errors['message-success'][] = "WordPress Archive extracted successfully.";
             }
             self::move_tree($_SESSION['restore_form']['wordpress']['extract-path'], $_SESSION['restore_form']['wordpress']['install-path']);
         }
     }
     return $form_errors;
 }