PluginProbe ʕ •ᴥ•ʔ
Backup Migration / 1.4.9
Backup Migration v1.4.9
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 / offline.php
backup-backup / includes Last commit date
banner 11 months ago bodies 11 months ago check 11 months ago cli 11 months ago cron 11 months ago dashboard 11 months ago database 11 months ago external 11 months ago extracter 11 months ago htaccess 11 months ago notices 11 months ago progress 11 months ago scanner 11 months ago staging 11 months ago traits 11 months ago uploader 11 months ago zipper 11 months ago .htaccess 11 months ago activation.php 11 months ago ajax.php 11 months ago ajax_offline.php 11 months ago analyst.php 11 months ago backup-process.php 11 months ago class-backup-method-mananger.php 11 months ago cli-handler.php 11 months ago compatibility.php 11 months ago config.php 11 months ago constants.php 11 months ago initializer.php 11 months ago logger.php 11 months ago offline.php 11 months ago
offline.php
141 lines
1 <?php
2
3 // Namespace
4 namespace BMI\Plugin;
5 use BMI\Plugin\Backup_Migration_Plugin as BMP;
6 use BMI\Plugin\BMI_Logger as Logger;
7 // Exit on direct access
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 /**
13 * Offline Methods Manager
14 */
15 class BMI_Offline {
16
17 public $ajaxInserted = false;
18
19 /**
20 * __construct - Initializer (loads offline modules)
21 */
22 function __construct() {
23 add_action('bmi_ajax_offline', function($post=[]){
24 if (BMI_DEBUG)
25 Logger::error("FREE AJAX OFFLINE");
26 require_once BMI_INCLUDES . '/ajax_offline.php';
27 $ajaxoffline = new BMI_Ajax_Offline($post);
28 });
29 add_action('wp_ajax_bmip_keepalive', [&$this, 'initializeOfflineAjax']);
30 add_action('wp_ajax_nopriv_bmip_keepalive', [&$this, 'initializeOfflineAjax']);
31
32 if (is_user_logged_in() && current_user_can('administrator')) {
33 add_action('wp_ajax_backup_migration', [&$this, 'initializeOfflineAjax']);
34 }
35
36 add_filter('allowed_http_origins', function ($origins) {
37 $origins[] = 'https://backupbliss.com';
38 $origins[] = 'https://api.backupbliss.com';
39 return $origins;
40 });
41
42 // $TBU = get_option('bmip_to_be_uploaded', false);
43 // if ($TBU != false && (sizeof($TBU['current_upload']) > 0 || sizeof($TBU['queue']) > 0)) {
44
45 // }
46
47 add_action('wp_head', [&$this, 'keepAliveJS']);
48 add_action('admin_head', [&$this, 'keepAliveJS']);
49 add_action('wp_footer', [&$this, 'keepAliveJS']);
50 add_action('admin_footer', [&$this, 'keepAliveJS']);
51
52 }
53
54 /**
55 * initializeOfflineAjax - Initialized Offline handlers for Ajax
56 *
57 * @return void
58 */
59 public function initializeOfflineAjax() {
60
61 // if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
62
63 // Extend execution time
64 if (BMP::isFunctionEnabled('headers_sent') && BMP::isFunctionEnabled('session_status')) {
65 if (!headers_sent() && session_status() === PHP_SESSION_DISABLED) {
66 if (BMP::isFunctionEnabled('ignore_user_abort')) @ignore_user_abort(true);
67 if (BMP::isFunctionEnabled('set_time_limit')) @set_time_limit(16000);
68 if (BMP::isFunctionEnabled('ini_set')) {
69 @ini_set('max_execution_time', '259200');
70 @ini_set('max_input_time', '259200');
71 }
72 }
73 }
74
75 if ((isset($_GET['token']) && ($_GET['token'] == 'bmip' || $_GET['token'] == 'bmi') && isset($_GET['f']))) {
76
77 if (empty($_GET)) return;
78
79 // Sanitize User Input
80 $post = BMP::sanitize($_GET);
81
82 } else if ((isset($_POST['token']) && ($_POST['token'] == 'bmip' || $_POST['token'] == 'bmi') && isset($_POST['f']))) {
83
84 if (empty($_POST)) return;
85
86 // Sanitize User Input
87 $post = BMP::sanitize($_POST);
88
89 }
90
91 if (!empty($post)) {
92 do_action("bmi_ajax_offline", $post);
93 }
94
95 // Execution error due to time limit
96 // register_shutdown_function([$this, 'execution_shutdown']);
97
98 // }
99
100 }
101
102 public function keepAliveJS() {
103 if ($this->ajaxInserted) return;
104
105 ?>
106 <script defer type="text/javascript" id="bmip-js-inline-remove-js">
107 function objectToQueryString(obj){
108 return Object.keys(obj).map(key => key + '=' + obj[key]).join('&');
109 }
110
111 function globalBMIKeepAlive() {
112 let xhr = new XMLHttpRequest();
113 let data = { action: "bmip_keepalive", token: "bmip", f: "refresh" };
114 let url = '<?php echo admin_url("admin-ajax.php"); ?>' + '?' + objectToQueryString(data);
115 xhr.open('POST', url, true);
116 xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
117 xhr.onreadystatechange = function () {
118 if (xhr.readyState === 4) {
119 let response;
120 if (response = JSON.parse(xhr.responseText)) {
121 if (typeof response.status != 'undefined' && response.status === 'success') {
122 //setTimeout(globalBMIKeepAlive, 3000);
123 } else {
124 //setTimeout(globalBMIKeepAlive, 20000);
125 }
126 }
127 }
128 };
129
130 xhr.send(JSON.stringify(data));
131 }
132
133 document.querySelector('#bmip-js-inline-remove-js').remove();
134 </script>
135 <?php
136
137 $this->ajaxInserted = true;
138 }
139
140 }
141