PluginProbe ʕ •ᴥ•ʔ
Backup Migration / 1.3.5
Backup Migration v1.3.5
2.1.7 2.1.6 2.1.5.2 trunk 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.6.1 1.4.7 1.4.8 1.4.9 1.4.9.1 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.5.1
backup-backup / includes / restore-batching.php
backup-backup / includes Last commit date
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-cli.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
221 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 . '/class-wp-user-request.php',
97 ABSPATH . WPINC . '/user.php',
98 ABSPATH . WPINC . '/class-wp-user-query.php',
99 ABSPATH . WPINC . '/class-wp-session-tokens.php',
100 ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php',
101 ABSPATH . WPINC . '/rest-api.php',
102 ABSPATH . WPINC . '/kses.php',
103 ABSPATH . WPINC . '/theme.php',
104 ABSPATH . WPINC . '/rewrite.php',
105 ABSPATH . WPINC . '/class-wp-block-editor-context.php',
106 ABSPATH . WPINC . '/class-wp-block-type.php',
107 ABSPATH . WPINC . '/class-wp-block-pattern-categories-registry.php',
108 ABSPATH . WPINC . '/class-wp-block-patterns-registry.php',
109 ABSPATH . WPINC . '/class-wp-block-styles-registry.php',
110 ABSPATH . WPINC . '/class-wp-block-type-registry.php',
111 ABSPATH . WPINC . '/class-wp-block.php',
112 ABSPATH . WPINC . '/class-wp-block-list.php',
113 ABSPATH . WPINC . '/class-wp-block-parser-block.php',
114 ABSPATH . WPINC . '/class-wp-block-parser-frame.php',
115 ABSPATH . WPINC . '/class-wp-block-parser.php',
116 ABSPATH . WPINC . '/blocks.php',
117 ABSPATH . WPINC . '/blocks/index.php',
118 ];
119
120 for ($i = 0; $i < sizeof($dependencies); ++$i) {
121 $dependency = $dependencies[$i];
122 if (strpos($dependency, 'class-http.php') && version_compare($wp_version, '5.9.0', '>=')) {
123 continue;
124 }
125 if (strpos($dependency, 'session.php') && version_compare($wp_version, '4.7.0', '>=')) {
126 continue;
127 }
128 if (file_exists($dependency)) require_once $dependency;
129 }
130
131 // Load Cookie Constants
132 wp_cookie_constants();
133
134 // Load SSL Constants for DB export
135 wp_ssl_constants();
136
137 // Register Translation
138 if (class_exists('WP_Textdomain_Registry')) {
139 $GLOBALS['wp_textdomain_registry'] = new \WP_Textdomain_Registry();
140 }
141
142 if (is_readable($bmiPluginPathToLoadPro)) {
143 wp_register_plugin_realpath($bmiPluginPathToLoadPro);
144 include_once $bmiPluginPathToLoadPro;
145
146 require_once BMI_PRO_ROOT_DIR . '/classes/core' . ((BMI_PRO_DEBUG) ? '.to-enc' : '') . '.php';
147 $bmi_pro_instance = new BMI_Pro_Core();
148 $bmi_pro_instance->initialize();
149 }
150
151 // Register our backup plugin and load its contents
152 wp_register_plugin_realpath($bmiPluginPathToLoad);
153 include_once $bmiPluginPathToLoad;
154
155 // Enable our plugin WITHOUT calling plugins_loaded hook – it's important
156 require_once BMI_ROOT_DIR . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'constants.php';
157
158 // Initialize backup-migration
159 if (!class_exists('Backup_Migration_Plugin')) {
160
161 // Require initializator
162 require_once BMI_ROOT_DIR . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'initializer.php';
163
164 // Initialize entire plugin
165 $bmi_instance = new BMI\Backup_Migration_Plugin();
166 $bmi_instance->initialize();
167
168 }
169
170 }
171
172 // Find WordPress Path
173 function bmi_find_wordpress_base_path() {
174
175 $dir = dirname(__FILE__);
176 $previous = null;
177
178 do {
179
180 if (file_exists($dir . '/wp-load.php') && file_exists($dir . '/wp-config.php')) return $dir;
181 if ($previous == $dir) break;
182 $previous = $dir;
183
184 } while ($dir = dirname($dir));
185
186 return null;
187
188 }
189
190 // Validate the secret
191 if (gettype($_POST['bmi_restore_secret']) == 'string' && strlen($_POST['bmi_restore_secret']) == '64') {
192
193 // For now we don't trust the user
194 $bmi_continue_module = false;
195
196 // Check the secret
197 $bmi_secret_storage = __DIR__ . '/htaccess/.restore_secret';
198 if (file_exists($bmi_secret_storage)) {
199 $bmi_saved_secret = file_get_contents($bmi_secret_storage);
200 if ($bmi_saved_secret === $_POST['bmi_restore_secret']) {
201 $bmi_continue_module = true;
202 } else exit;
203 } else exit;
204
205 // Set definition for handler
206 define('BMI_RESTORE_SECRET', $_POST['bmi_restore_secret']);
207 define('BMI_POST_CONTINUE_RESTORE', true);
208
209 // Tell WP to not use Themes and set Base Path
210 define('BASE_PATH', bmi_find_wordpress_base_path() . '/');
211
212 // Third time just for sure
213 if ($bmi_continue_module === true) {
214
215 // Use WP Globals and load WordPress
216 bmiLoadWordPressAndBackupPlugin();
217
218 }
219
220 }
221