banner
2 years ago
check
2 years ago
cli
2 years ago
cron
2 years ago
dashboard
2 years ago
database
2 years ago
extracter
2 years ago
htaccess
2 years ago
progress
2 years ago
scanner
2 years ago
staging
2 years ago
uploader
2 years ago
zipper
2 years ago
.htaccess
2 years ago
activation.php
2 years ago
ajax.php
2 years ago
analyst.php
2 years ago
backup-heart.php
2 years ago
bypasser.php
2 years ago
cli-handler.php
2 years ago
compatibility.php
2 years ago
config.php
2 years ago
constants.php
2 years ago
initializer.php
2 years ago
logger.php
2 years ago
restore-batching.php
2 years ago
restore-batching.php
207 lines
| 1 | <?php |
| 2 | |
| 3 | // Namespace |
| 4 | namespace BMI\Plugin; |
| 5 | |
| 6 | use BMI\Plugin AS BMI; |
| 7 | |
| 8 | // Exit on GET access |
| 9 | if (!(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest' && isset($_POST['bmi_restore_secret']))) { |
| 10 | echo 'Access denied!'; |
| 11 | exit; |
| 12 | } |
| 13 | |
| 14 | // Double check because why not |
| 15 | if (empty($_POST)) exit; |
| 16 | if (!isset($_POST['bmi_restore_secret'])) exit; |
| 17 | |
| 18 | function fixSlashes($str, $slash = false) { |
| 19 | // Old version |
| 20 | // $str = str_replace('\\\\', DIRECTORY_SEPARATOR, $str); |
| 21 | // $str = str_replace('\\', DIRECTORY_SEPARATOR, $str); |
| 22 | // $str = str_replace('\/', DIRECTORY_SEPARATOR, $str); |
| 23 | // $str = str_replace('/', DIRECTORY_SEPARATOR, $str); |
| 24 | |
| 25 | // if ($str[strlen($str) - 1] == DIRECTORY_SEPARATOR) { |
| 26 | // $str = substr($str, 0, -1); |
| 27 | // } |
| 28 | |
| 29 | // Since 1.3.2 |
| 30 | $protocol = ''; |
| 31 | if ($slash == false) $slash = DIRECTORY_SEPARATOR; |
| 32 | if (substr($str, 0, 7) == 'http://') $protocol = 'http://'; |
| 33 | else if (substr($str, 0, 8) == 'https://') $protocol = 'https://'; |
| 34 | |
| 35 | $str = substr($str, strlen($protocol)); |
| 36 | $str = preg_replace('/[\\\\\/]+/', $slash, $str); |
| 37 | $str = rtrim($str, '/\\' ); |
| 38 | |
| 39 | return $protocol . $str; |
| 40 | } |
| 41 | |
| 42 | // WP Loader |
| 43 | function bmiLoadWordPressAndBackupPlugin() { |
| 44 | |
| 45 | // Define how WP should load |
| 46 | define('WP_USE_THEMES', false); |
| 47 | define('SHORTINIT', true); |
| 48 | |
| 49 | // Set path to our plugin's main file |
| 50 | $bmiPluginPathToLoad = fixSlashes(dirname(__DIR__) . '/backup-backup.php'); |
| 51 | $bmiPluginPathToLoadPro = fixSlashes(dirname(dirname(__DIR__)) . '/backup-backup-pro/backup-backup-pro.php'); |
| 52 | |
| 53 | // Use WP Globals and load WordPress |
| 54 | global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header; |
| 55 | require_once bmi_find_wordpress_base_path() . DIRECTORY_SEPARATOR . 'wp-load.php'; |
| 56 | global $wp_version; |
| 57 | |
| 58 | // Load directory WordPress constants |
| 59 | require_once ABSPATH . WPINC . '/formatting.php'; |
| 60 | require_once ABSPATH . WPINC . '/meta.php'; |
| 61 | wp_plugin_directory_constants(); |
| 62 | |
| 63 | // Allow to register activation hook and realpath |
| 64 | $GLOBALS['wp_plugin_paths'] = array(); |
| 65 | $GLOBALS['shortcode_tags'] = array(); |
| 66 | |
| 67 | // Load all dependencies of WordPress for Backup plugin |
| 68 | $dependencies = [ |
| 69 | ABSPATH . WPINC . '/l10n.php', |
| 70 | ABSPATH . WPINC . '/plugin.php', |
| 71 | ABSPATH . WPINC . '/link-template.php', |
| 72 | ABSPATH . WPINC . '/class-wp-textdomain-registry.php', |
| 73 | ABSPATH . WPINC . '/class-wp-locale.php', |
| 74 | ABSPATH . WPINC . '/class-wp-locale-switcher.php', |
| 75 | ABSPATH . WPINC . '/session.php', |
| 76 | ABSPATH . WPINC . '/pluggable.php', |
| 77 | ABSPATH . WPINC . '/class-wp-ajax-response.php', |
| 78 | ABSPATH . WPINC . '/capabilities.php', |
| 79 | ABSPATH . WPINC . '/class-wp-roles.php', |
| 80 | ABSPATH . WPINC . '/class-wp-role.php', |
| 81 | ABSPATH . WPINC . '/class-wp-user.php', |
| 82 | ABSPATH . WPINC . '/class-wp-query.php', |
| 83 | ABSPATH . WPINC . '/query.php', |
| 84 | ABSPATH . WPINC . '/general-template.php', |
| 85 | ABSPATH . WPINC . '/http.php', |
| 86 | ABSPATH . WPINC . '/class-http.php', |
| 87 | ABSPATH . WPINC . '/class-wp-http.php', |
| 88 | ABSPATH . WPINC . '/class-wp-http-streams.php', |
| 89 | ABSPATH . WPINC . '/class-wp-http-curl.php', |
| 90 | ABSPATH . WPINC . '/class-wp-http-proxy.php', |
| 91 | ABSPATH . WPINC . '/class-wp-http-cookie.php', |
| 92 | ABSPATH . WPINC . '/class-wp-http-encoding.php', |
| 93 | ABSPATH . WPINC . '/class-wp-http-response.php', |
| 94 | ABSPATH . WPINC . '/class-wp-http-requests-response.php', |
| 95 | ABSPATH . WPINC . '/class-wp-http-requests-hooks.php', |
| 96 | ABSPATH . WPINC . '/widgets.php', |
| 97 | ABSPATH . WPINC . '/class-wp-widget.php', |
| 98 | ABSPATH . WPINC . '/class-wp-widget-factory.php', |
| 99 | ABSPATH . WPINC . '/class-wp-user-request.php', |
| 100 | ABSPATH . WPINC . '/user.php', |
| 101 | ABSPATH . WPINC . '/class-wp-user-query.php', |
| 102 | ABSPATH . WPINC . '/class-wp-session-tokens.php', |
| 103 | ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php', |
| 104 | ABSPATH . WPINC . '/rest-api.php', |
| 105 | ABSPATH . WPINC . '/kses.php', |
| 106 | ABSPATH . WPINC . '/theme.php', |
| 107 | ABSPATH . WPINC . '/rewrite.php', |
| 108 | ABSPATH . WPINC . '/class-wp-block-editor-context.php', |
| 109 | ABSPATH . WPINC . '/class-wp-block-type.php', |
| 110 | ABSPATH . WPINC . '/class-wp-block-pattern-categories-registry.php', |
| 111 | ABSPATH . WPINC . '/class-wp-block-patterns-registry.php', |
| 112 | ABSPATH . WPINC . '/class-wp-block-styles-registry.php', |
| 113 | ABSPATH . WPINC . '/class-wp-block-type-registry.php', |
| 114 | ABSPATH . WPINC . '/class-wp-block.php', |
| 115 | ABSPATH . WPINC . '/class-wp-block-list.php', |
| 116 | ABSPATH . WPINC . '/class-wp-block-parser-block.php', |
| 117 | ABSPATH . WPINC . '/class-wp-block-parser-frame.php', |
| 118 | ABSPATH . WPINC . '/class-wp-block-parser.php', |
| 119 | ABSPATH . WPINC . '/blocks.php', |
| 120 | ABSPATH . WPINC . '/blocks/index.php', |
| 121 | ]; |
| 122 | |
| 123 | for ($i = 0; $i < sizeof($dependencies); ++$i) { |
| 124 | $dependency = $dependencies[$i]; |
| 125 | if (strpos($dependency, 'class-http.php') && version_compare($wp_version, '5.9.0', '>=')) { |
| 126 | continue; |
| 127 | } |
| 128 | if (strpos($dependency, 'session.php') && version_compare($wp_version, '4.7.0', '>=')) { |
| 129 | continue; |
| 130 | } |
| 131 | if (file_exists($dependency)) require_once $dependency; |
| 132 | } |
| 133 | |
| 134 | // Load Cookie Constants |
| 135 | wp_cookie_constants(); |
| 136 | |
| 137 | // Load SSL Constants for DB export |
| 138 | wp_ssl_constants(); |
| 139 | |
| 140 | // Register Translation |
| 141 | if (class_exists('WP_Textdomain_Registry')) { |
| 142 | $GLOBALS['wp_textdomain_registry'] = new \WP_Textdomain_Registry(); |
| 143 | } |
| 144 | |
| 145 | if (is_readable($bmiPluginPathToLoadPro)) { |
| 146 | wp_register_plugin_realpath($bmiPluginPathToLoadPro); |
| 147 | include_once $bmiPluginPathToLoadPro; |
| 148 | |
| 149 | require_once BMI_PRO_ROOT_DIR . '/classes/core' . ((BMI_PRO_DEBUG) ? '.to-enc' : '') . '.php'; |
| 150 | $bmi_pro_instance = new BMI_Pro_Core(); |
| 151 | $bmi_pro_instance->initialize(); |
| 152 | } |
| 153 | |
| 154 | // Register our backup plugin and load its contents |
| 155 | wp_register_plugin_realpath($bmiPluginPathToLoad); |
| 156 | include_once $bmiPluginPathToLoad; |
| 157 | |
| 158 | // Enable our plugin WITHOUT calling plugins_loaded hook – it's important |
| 159 | require_once BMI_ROOT_DIR . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'constants.php'; |
| 160 | |
| 161 | // Initialize backup-migration |
| 162 | if (!class_exists('Backup_Migration_Plugin')) { |
| 163 | |
| 164 | // Require initializator |
| 165 | require_once BMI_ROOT_DIR . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'initializer.php'; |
| 166 | |
| 167 | // Initialize entire plugin |
| 168 | $bmi_instance = new BMI\Backup_Migration_Plugin(); |
| 169 | $bmi_instance->initialize(); |
| 170 | |
| 171 | } |
| 172 | |
| 173 | } |
| 174 | |
| 175 | // Find WordPress Path |
| 176 | function bmi_find_wordpress_base_path() { |
| 177 | |
| 178 | $dir = dirname(__FILE__); |
| 179 | $previous = null; |
| 180 | |
| 181 | do { |
| 182 | |
| 183 | if (file_exists($dir . '/wp-load.php') && file_exists($dir . '/wp-config.php')) return $dir; |
| 184 | if ($previous == $dir) break; |
| 185 | $previous = $dir; |
| 186 | |
| 187 | } while ($dir = dirname($dir)); |
| 188 | |
| 189 | return null; |
| 190 | |
| 191 | } |
| 192 | |
| 193 | // Validate the secret |
| 194 | if (gettype($_POST['bmi_restore_secret']) == 'string' && strlen($_POST['bmi_restore_secret']) == '64') { |
| 195 | |
| 196 | // Set definition for handler |
| 197 | define('BMI_RESTORE_SECRET', $_POST['bmi_restore_secret']); |
| 198 | define('BMI_POST_CONTINUE_RESTORE', true); |
| 199 | |
| 200 | // Tell WP to not use Themes and set Base Path |
| 201 | define('BASE_PATH', bmi_find_wordpress_base_path() . '/'); |
| 202 | |
| 203 | // Use WP Globals and load WordPress |
| 204 | bmiLoadWordPressAndBackupPlugin(); |
| 205 | |
| 206 | } |
| 207 |