PluginProbe ʕ •ᴥ•ʔ
Backup Migration / 1.3.0
Backup Migration v1.3.0
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 / backup-heart.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 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
backup-heart.php
160 lines
1 <?php
2
3 // Namespace
4 namespace BMI\Plugin\Heart;
5
6 // Allow only POST requests
7 if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
8 exit;
9 }
10
11 function isFunctionEnabled($func) {
12 $disabled = explode(',', ini_get('disable_functions'));
13 $isDisabled = in_array($func, $disabled);
14 if (!$isDisabled && function_exists($func)) return true;
15 else return false;
16 }
17
18 // Make sure getallheaders will work
19 if (!function_exists('__getallheaders')) {
20 function __getallheaders() {
21 $headers = [];
22 foreach ($_SERVER as $name => $value) {
23 if (substr($name, 0, 5) == 'HTTP_') {
24 $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
25 }
26 }
27 return $headers;
28 }
29 }
30
31 // Get fields from header
32 if (isFunctionEnabled('getallheaders')) {
33 $fields = getallheaders();
34 }
35
36 // Check headers
37 if (!isset($fields['Content-Content']) && !isset($fields['content-content'])) {
38 $fields = __getallheaders();
39 }
40
41 // Lowercase
42 foreach ($fields as $key => $value) {
43 $buffer = $value;
44 unset($fields[$key]);
45 $fields[strtolower($key)] = $value;
46 }
47
48 // Let other files know that it's CURL request
49 define('BMI_CURL_REQUEST', true);
50 define('BMI_CLI_REQUEST', false);
51
52 // Load some constants
53 define('ABSPATH', $fields['content-abs']);
54 if (substr($fields['content-content'], -1) != '/') {
55 $fields['content-content'] = $fields['content-content'] . '/';
56 }
57 if (!defined('WP_CONTENT_DIR')) {
58 define('WP_CONTENT_DIR', $fields['content-content']);
59 }
60 define('BMI_CONFIG_DIR', $fields['content-configdir']);
61 define('BMI_BACKUPS', $fields['content-backups']);
62 define('BMI_ROOT_DIR', $fields['content-dir']);
63 // define('BMI_SHARE_LOGS_ALLOWED', $fields['content-shareallowed']);
64 define('BMI_INCLUDES', BMI_ROOT_DIR . 'includes');
65 define('BMI_SAFELIMIT', intval($fields['content-safelimit']));
66
67 // Replace error-log file
68 if (isFunctionEnabled('ini_set')) {
69 @ini_set('log_errors', 1);
70 @ini_set('error_log', BMI_CONFIG_DIR . '/background-errors.log');
71 }
72
73 // Increase max execution time
74 if (isFunctionEnabled('set_time_limit')) @set_time_limit(259200);
75 if (isFunctionEnabled('ini_set')) {
76 @ini_set('memory_limit', (BMI_SAFELIMIT * 4 + 16) . 'M');
77 @ini_set('max_input_time', '259200');
78 @ini_set('max_execution_time', '259200');
79 @ini_set('session.gc_maxlifetime', '1200');
80 }
81
82 // Let the server know it's server-side script
83 if (isFunctionEnabled('ignore_user_abort')) {
84 @ignore_user_abort(true);
85 }
86
87 if (!isset($fields['content-browser'])) $fields['content-browser'] = false;
88 if (!($fields['content-browser'] === 'true' || $fields['content-browser'] === true)) {
89
90 // Also return something, so it can close the connection
91 ob_start();
92
93 // The message
94 echo 'This is server side script, you will not get any response here.';
95
96 // Don't block server handler
97 if (isFunctionEnabled('session_write_close')) {
98 @session_write_close();
99 }
100
101 // Set proper headers
102 header('Content-Length: ' . ob_get_length());
103 header('Connection: close');
104
105 // End the output for user
106 ob_end_clean();
107 flush();
108
109 }
110
111 // Start output for server
112 ob_start();
113
114 // Catch anything if possible
115 try {
116
117 // Load bypasser
118 require_once BMI_INCLUDES . '/bypasser.php';
119 $request = new BMI_Backup_Heart(true,
120 $fields['content-configdir'],
121 $fields['content-content'],
122 $fields['content-backups'],
123 $fields['content-abs'],
124 $fields['content-dir'],
125 $fields['content-url'],
126 [
127 'identy' => $fields['content-identy'],
128 'manifest' => $fields['content-manifest'],
129 'safelimit' => $fields['content-safelimit'],
130 'rev' => $fields['content-rev'],
131 'backupname' => $fields['content-name'],
132 'start' => $fields['content-start'],
133 'filessofar' => $fields['content-filessofar'],
134 'total_files' => $fields['content-total'],
135 'browser' => $fields['content-browser']
136 // 'shareallowed' => $fields['content-shareallowed']
137 ],
138 $fields['content-it'],
139 $fields['content-dbit'],
140 $fields['content-dblast']
141 );
142
143 // Handle request
144 $request->handle_batch();
145
146 } catch (\Exception $e) {
147
148 error_log('There was an error with Backup Migration plugin: ' . $e->getMessage());
149 error_log(strval($e));
150
151 } catch (\Throwable $e) {
152
153 error_log('There was an error with Backup Migration plugin: ' . $e->getMessage());
154 error_log(strval($e));
155
156 }
157
158 // End the server task
159 ob_end_clean(); exit;
160