· 5 years ago · Feb 25, 2020, 12:26 PM
1<?php
2/*
3Plugin Name: InfiniteWP - Client
4Plugin URI: http://infinitewp.com/
5Description: This is the client plugin of InfiniteWP that communicates with the InfiniteWP Admin panel.
6Author: Revmakx
7Version: 1.9.4.5
8Author URI: http://www.revmakx.com
9Network: true
10*/
11/************************************************************
12 * This plugin was modified by Revmakx *
13 * Copyright (c) 2012 Revmakx *
14 * www.revmakx.com *
15 * *
16 ************************************************************/
17
18/*************************************************************
19 *
20 * init.php
21 *
22 * Initialize the communication with master
23 *
24 *
25 * Copyright (c) 2011 Prelovac Media
26 * www.prelovac.com
27 **************************************************************/
28if(basename($_SERVER['SCRIPT_FILENAME']) == "init.php"):
29 exit;
30endif;
31if(!defined('IWP_MMB_CLIENT_VERSION'))
32 define('IWP_MMB_CLIENT_VERSION', '1.9.4.5');
33
34
35
36if ( !defined('IWP_MMB_XFRAME_COOKIE')){
37 $siteurl = function_exists('get_site_option') ? get_site_option( 'siteurl' ) : get_option('siteurl');
38 define('IWP_MMB_XFRAME_COOKIE', $xframe = 'wordpress_'.md5($siteurl).'_xframe');
39}
40global $wpdb, $iwp_mmb_plugin_dir, $iwp_mmb_plugin_url, $wp_version, $iwp_mmb_filters, $_iwp_mmb_item_filter;
41if (version_compare(PHP_VERSION, '5.0.0', '<')) // min version 5 supported
42 exit("<p>InfiniteWP Client plugin requires PHP 5 or higher.</p>");
43
44
45$iwp_mmb_wp_version = $wp_version;
46$iwp_mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
47$iwp_mmb_plugin_url = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__));
48
49if(!defined('IWP_BACKUP_DIR')){
50define('IWP_BACKUP_DIR', WP_CONTENT_DIR . '/infinitewp/backups');
51}
52
53if(!defined('IWP_DB_DIR')){
54define('IWP_DB_DIR', IWP_BACKUP_DIR . '/iwp_db');
55}
56
57if(!defined('IWP_PCLZIP_TEMPORARY_DIR')){
58define('IWP_PCLZIP_TEMPORARY_DIR', WP_CONTENT_DIR . '/infinitewp/temp/');
59}
60
61require_once("$iwp_mmb_plugin_dir/helper.class.php");
62require_once("$iwp_mmb_plugin_dir/backup/backup.options.php");
63require_once("$iwp_mmb_plugin_dir/backup/functions.php");
64require_once("$iwp_mmb_plugin_dir/backup/databaseencrypt.php");
65require_once("$iwp_mmb_plugin_dir/backup/encrypt.php");
66require_once("$iwp_mmb_plugin_dir/core.class.php");
67require_once("$iwp_mmb_plugin_dir/activities_log.class.php");
68require_once("$iwp_mmb_plugin_dir/stats.class.php");
69//require_once("$iwp_mmb_plugin_dir/backup.class.php");
70//require_once("$iwp_mmb_plugin_dir/backup.class.singlecall.php");
71//require_once("$iwp_mmb_plugin_dir/backup.class.multicall.php");
72require_once("$iwp_mmb_plugin_dir/installer.class.php");
73
74require_once("$iwp_mmb_plugin_dir/addons/manage_users/user.class.php");
75//require_once("$iwp_mmb_plugin_dir/addons/backup_repository/backup_repository.class.php");
76require_once("$iwp_mmb_plugin_dir/addons/comments/comments.class.php");
77
78require_once("$iwp_mmb_plugin_dir/addons/post_links/link.class.php");
79require_once("$iwp_mmb_plugin_dir/addons/post_links/post.class.php");
80
81require_once("$iwp_mmb_plugin_dir/addons/wp_optimize/optimize.class.php");
82
83require_once("$iwp_mmb_plugin_dir/addons.api.php");
84require_once("$iwp_mmb_plugin_dir/plugin.compatibility.class.php");
85require_once("$iwp_mmb_plugin_dir/plugins/search/search.php");
86require_once("$iwp_mmb_plugin_dir/plugins/cleanup/cleanup.php");
87
88
89if( !function_exists ( 'iwp_mmb_filter_params' )) {
90 function iwp_mmb_filter_params( $array = array() ){
91
92 $filter = array( 'current_user', 'wpdb' );
93 $return = array();
94 foreach ($array as $key => $val) {
95 if( !is_int($key) && in_array($key, $filter) )
96 continue;
97
98 if( is_array( $val ) ) {
99 $return[$key] = iwp_mmb_filter_params( $val );
100 } else {
101 $return[$key] = $val;
102 }
103 }
104
105 return $return;
106 }
107}
108
109if( !function_exists ('iwp_mmb_parse_request')) {
110 function iwp_mmb_parse_request()
111 {
112 global $HTTP_RAW_POST_DATA, $iwp_mmb_activities_log;
113 $HTTP_RAW_POST_DATA_LOCAL = NULL;
114 $HTTP_RAW_POST_DATA_LOCAL = file_get_contents('php://input');
115 if(empty($HTTP_RAW_POST_DATA_LOCAL)){
116 if (isset($HTTP_RAW_POST_DATA)) {
117 $HTTP_RAW_POST_DATA_LOCAL = $HTTP_RAW_POST_DATA;
118 }
119 }
120
121
122
123 global $current_user, $iwp_mmb_core, $new_actions, $wp_db_version, $wpmu_version, $_wp_using_ext_object_cache;
124 if (strrpos($HTTP_RAW_POST_DATA_LOCAL, '_IWP_JSON_PREFIX_') !== false) {
125 $request_data_array = explode('_IWP_JSON_PREFIX_', $HTTP_RAW_POST_DATA_LOCAL);
126 $request_raw_data = $request_data_array[1];
127 $data = trim(base64_decode($request_raw_data));
128 $GLOBALS['IWP_JSON_COMMUNICATION'] = 1;
129 }else{
130 $data = false;
131 $request_raw_data = $HTTP_RAW_POST_DATA_LOCAL;
132 $serialized_data = trim(base64_decode($request_raw_data));
133 if (is_serialized($serialized_data)) {
134 iwp_mmb_response(array('error' => 'Please update your IWP Admin Panel to latest version', 'error_code' => 'update_panel'), false, true);
135 }
136 }
137
138 if ($data){
139
140 //$num = @extract(unserialize($data));
141 $request_data = json_decode($data, true);
142
143 if(isset($request_data['params'])){
144 $request_data['params'] = iwp_mmb_filter_params($request_data['params']);
145 }
146 if (isset($GLOBALS['IWP_JSON_COMMUNICATION']) && $GLOBALS['IWP_JSON_COMMUNICATION']) {
147 $signature = base64_decode($request_data['signature']);
148 }else{
149 $signature = $request_data['signature'];
150 }
151
152 $iwp_action = $request_data['iwp_action'];
153 $params = $request_data['params'];
154 $id = $request_data['id'];
155 if(isset($request_data['is_save_activity_log'])) {
156 $is_save_activity_log = $request_data['is_save_activity_log'];
157 }
158 $GLOBALS['activities_log_datetime'] = $request_data['activities_log_datetime'];
159 }
160 if (isset($iwp_action) && $iwp_action != 'restoreNew') {
161 if(!defined('IWP_AUTHORISED_CALL')) define('IWP_AUTHORISED_CALL', 1);
162 if(function_exists('register_shutdown_function')){ register_shutdown_function("iwp_mmb_shutdown"); }
163 $GLOBALS['IWP_MMB_PROFILING']['ACTION_START'] = microtime(1);
164
165 error_reporting(0);
166 @ini_set("display_errors", 0);
167
168
169 run_hash_change_process();
170 iwp_plugin_compatibility_fix();
171 $action = $iwp_action;
172 $_wp_using_ext_object_cache = false;
173 @set_time_limit(600);
174
175 if (!$iwp_mmb_core->check_if_user_exists($params['username']))
176 iwp_mmb_response(array('error' => 'Username <b>' . $params['username'] . '</b> does not have administrative access. Enter the correct username in the site options.', 'error_code' => 'username_does_not_have_administrative_access'), false);
177
178 if ($action == 'add_site') {
179 $params['iwp_action'] = $action;
180 $iwp_mmb_core->request_params = $params;
181 return;
182 }elseif ($action == 'readd_site') {
183 $params['id'] = $id;
184 $params['iwp_action'] = $action;
185 $params['signature'] = $signature;
186 $iwp_mmb_core->request_params = $params;
187 return;
188 }
189
190 $auth = $iwp_mmb_core->authenticate_message($action . $id, $signature, $id);
191 if ($auth === true) {
192 if (!defined('WP_ADMIN') && $action == 'get_stats' || $action == 'do_upgrade' || $action == 'install_addon' || $action == 'edit_plugins_themes' || $action == 'bulk_actions_processor' || $action == 'update_broken_link' || $action == 'undismiss_broken_link') {
193 define('WP_ADMIN', true);
194 }
195 if ($action == 'get_stats') {
196 iwp_mu_plugin_loader();
197 }
198 if (is_multisite()) {
199 define('WP_NETWORK_ADMIN', true);
200 }else{
201 define('WP_NETWORK_ADMIN', false);
202 }
203 $params['id'] = $id;
204 $params['iwp_action'] = $action;
205 $params['is_save_activity_log'] = $is_save_activity_log;
206 $iwp_mmb_core->request_params = $params;
207 } else {
208 iwp_mmb_response($auth, false);
209 }
210 } else {
211 //IWP_MMB_Stats::set_hit_count();
212 // $GLOBALS['HTTP_RAW_POST_DATA'] = $HTTP_RAW_POST_DATA_LOCAL;
213 $HTTP_RAW_POST_DATA = $HTTP_RAW_POST_DATA_LOCAL;
214 }
215
216 }
217}
218if (!function_exists ('iwp_mmb_add_readd_request')) {
219 function iwp_mmb_add_readd_request(){
220 global $current_user, $iwp_mmb_core, $new_actions, $wp_db_version, $wpmu_version, $_wp_using_ext_object_cache, $iwp_mmb_activities_log;
221 if (empty($iwp_mmb_core->request_params)) {
222 return false;
223 }
224 $params = $iwp_mmb_core->request_params;
225 $action = $iwp_mmb_core->request_params['iwp_action'];
226
227 if ($action == 'add_site') {
228 $params['is_save_activity_log'] = $is_save_activity_log;
229 iwp_mmb_add_site($params);
230 iwp_mmb_response(array('error' => 'You should never see this.', 'error_code' => 'you_should_never_see_this'), false);
231 }
232 if ($action == 'readd_site') {
233 $params['id'] = $params['id'];
234 $params['signature'] = $params['signature'];
235 $params['is_save_activity_log'] = $is_save_activity_log;
236 iwp_mmb_readd_site($params);
237 iwp_mmb_response(array('error' => 'You should never see this.', 'error_code' => 'you_should_never_see_this'), false);
238 }
239 }
240}
241if (!function_exists ('iwp_mmb_set_request')) {
242 function iwp_mmb_set_request(){
243 global $current_user, $iwp_mmb_core, $new_actions, $wp_db_version, $wpmu_version, $_wp_using_ext_object_cache, $iwp_mmb_activities_log;
244 if (is_user_logged_in()) {
245 iwp_plugin_compatibility_fix();
246 }
247 if (empty($iwp_mmb_core->request_params)) {
248 return false;
249 }
250 $params = $iwp_mmb_core->request_params;
251 $action = $iwp_mmb_core->request_params['iwp_action'];
252 $is_save_activity_log = $iwp_mmb_core->request_params['is_save_activity_log'];
253 if ($action == 'add_site' || $action == 'readd_site') {
254 return false;
255 }
256 if ($action == 'maintain_site') {
257 iwp_mmb_maintain_site($params);
258 iwp_mmb_response(array('error' => 'You should never see this.', 'error_code' => 'you_should_never_see_this'), false);
259 }
260 @ignore_user_abort(true);
261 $GLOBALS['IWP_CLIENT_HISTORY_ID'] = $iwp_mmb_core->request_params['id'];
262 iwp_mmb_backup_db_changes();
263 if(isset($params['username']) && !is_user_logged_in()){
264 $user = function_exists('get_user_by') ? get_user_by('login', $params['username']) : iwp_mmb_get_user_by( 'login', $params['username'] );
265 if (isset($user) && isset($user->ID)) {
266 wp_set_current_user($user->ID);
267 // Compatibility with All In One Security
268 update_user_meta($user->ID, 'last_login_time', current_time('mysql'));
269 }
270 $isHTTPS = (bool)is_ssl();
271 if($isHTTPS){
272 wp_set_auth_cookie($user->ID);
273 }else{
274 wp_set_auth_cookie($user->ID, false, false);
275 wp_set_auth_cookie($user->ID, false, true);
276 }
277 }
278 if ($action == 'get_cookie') {
279 iwp_mmb_response(true, true);
280 }
281 /* in case database upgrade required, do database backup and perform upgrade ( wordpress wp_upgrade() function ) */
282 if( strlen(trim($wp_db_version)) && !defined('ACX_PLUGIN_DIR') ){
283 if ( get_option('db_version') != $wp_db_version ) {
284 /* in multisite network, please update database manualy */
285 if (empty($wpmu_version) || (function_exists('is_multisite') && !is_multisite())){
286 if( ! function_exists('wp_upgrade'))
287 include_once(ABSPATH.'wp-admin/includes/upgrade.php');
288
289 ob_clean();
290 @wp_upgrade();
291 @do_action('after_db_upgrade');
292 ob_end_clean();
293 }
294 }
295 }
296
297 if(isset($params['secure'])){
298 if (isset($GLOBALS['IWP_JSON_COMMUNICATION']) && $GLOBALS['IWP_JSON_COMMUNICATION']) {
299 $params['secure'] = iwp_mmb_safe_unserialize(base64_decode($params['secure']));
300 }
301 if($decrypted = $iwp_mmb_core->_secure_data($params['secure'])){
302 if (is_serialized($decrypted)) {
303 $decrypted = iwp_mmb_safe_unserialize($decrypted);
304 }
305 if(is_array($decrypted)){
306
307 foreach($decrypted as $key => $val){
308 if(!is_numeric($key))
309 $params[$key] = $val;
310
311 }
312 unset($params['secure']);
313 } else $params['secure'] = $decrypted;
314 }
315 elseif(isset($params['secure']['account_info'])){
316 $params['account_info'] = $params['secure']['account_info'];
317 }
318 }
319
320 if( !$iwp_mmb_core->register_action_params( $action, $params ) ){
321 global $_iwp_mmb_plugin_actions;
322 $_iwp_mmb_plugin_actions[$action] = $params;
323 }
324 $iwp_mmb_activities_log->iwp_mmb_update_is_save_activity_log($is_save_activity_log);
325 $iwp_mmb_activities_log->iwp_mmb_save_options_for_activity_log('parse_request');
326 }
327}
328
329if( !function_exists('iwp_mmb_convert_wperror_obj_to_arr')){
330 function iwp_mmb_convert_wperror_obj_to_arr($obj,$state="initial"){
331 $result = array();
332 if( is_array($obj) ){
333 foreach ($obj as $key => $value) {
334 $result[$key] = iwp_mmb_convert_wperror_obj_to_arr($value,"intermediate");
335 }
336 }elseif(is_object($obj) && is_wp_error($obj)){
337 $result['error_codes'] = $obj->get_error_codes();
338 $result['errors'] = $obj->get_error_messages();
339 $result['error_data'] = $obj->get_error_data();
340 }else{
341 return $obj;
342 }
343 if($state == 'initial' ){
344 if(isset($obj['error']) && is_wp_error($obj['error'])){
345 $errMsgTemp = $result['error']['errors'];
346 $errCodesTemp = $result['error']['error_codes'];
347 if(!empty($result['error']['error_data']) ){
348 $errData = ":::".$result['error']['error_data'];
349 }else{
350 $errData = '';
351 }
352
353 $errMsg ='';
354 $errCode = '';
355
356 if(count($errMsgTemp) > 1 ){$errMsg = implode("|&|",$errMsgTemp);}elseif(count($errMsgTemp) == 1){$errMsg = $errMsgTemp[0];}
357 if(count($errCodesTemp) > 1 ){$errCode = implode("|&|",$errCodesTemp);}elseif(count($errCodesTemp) == 1){$errCode = $errCodesTemp[0];}
358
359 $wpErr = array('error'=>$errMsg.$errData,'error_code'=>$errCode,'error_data'=>$errData);
360 return $wpErr;
361 }
362 }
363 return $result;
364 }
365}
366
367/* Main response function */
368if( !function_exists ( 'iwp_mmb_response' )) {
369
370 function iwp_mmb_response($response = false, $success = true, $send_serialize_response=false)
371 {
372 $return = array();
373
374 $response = iwp_mmb_convert_wperror_obj_to_arr($response,'initial');
375
376 if ((is_array($response) && empty($response)) || (!is_array($response) && strlen($response) == 0)){
377 $return['error'] = 'Empty response.';
378 $return['error_code'] = 'empty_response';
379 }
380 else if ($success){
381 $return['success'] = $response;
382 }
383 else{
384 $return['error'] = $response['error'];
385 $return['error_code'] = $response['error_code'];
386 }
387
388 if( !headers_sent() ){
389 $protocol = 'HTTP/1.1';
390 if (isset($_SERVER['SERVER_PROTOCOL']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.0') {
391 $protocol = 'HTTP/1.0';
392 }
393 header($protocol.' 200 OK');
394 header('Content-Type: text/plain');
395 }
396 if (!$send_serialize_response) {
397 $GLOBALS['IWP_RESPONSE_SENT'] = true;
398 $response_data = '_IWP_JSON_PREFIX_'.base64_encode(iwp_mmb_json_encode($return));
399 }else{
400 $GLOBALS['IWP_RESPONSE_SENT'] = true;
401 $response_data = base64_encode(serialize($return));
402 }
403 $txt= "<IWPHEADER>" .$response_data."<ENDIWPHEADER>";
404 if (defined('IWP_RESPONSE_HEADER_CLOSE') && IWP_RESPONSE_HEADER_CLOSE) {
405 ignore_user_abort(true);
406 ob_end_clean();
407 ob_start();
408 echo ($txt);
409 $size = ob_get_length();
410 header("Connection: close\r\n");
411 header("Content-Encoding: none\r\n");
412 header("Content-Length: $size");
413 @ob_flush();
414 flush();
415 ob_end_flush();
416 exit(1);
417 }else{
418 exit($txt);
419 }
420 }
421}
422
423
424
425if( !function_exists ( 'iwp_mmb_add_site' )) {
426 function iwp_mmb_add_site($params)
427 {
428 global $iwp_mmb_core, $iwp_mmb_activities_log;
429 $num = extract($params);
430
431 if ($num) {
432 if (!$iwp_mmb_core->get_option('iwp_client_action_message_id') && !$iwp_mmb_core->get_option('iwp_client_public_key')) {
433 $public_key = base64_decode($public_key);
434
435
436 if(trim($activation_key) != get_option('iwp_client_activate_key')){ //iwp
437 iwp_mmb_response(array('error' => 'Invalid activation key', 'error_code' => 'iwp_mmb_add_site_invalid_activation_key'), false);
438 return;
439 }
440
441 if (checkOpenSSL() && !$user_random_key_signing) {
442 $verify = openssl_verify($action . $id, base64_decode($signature), $public_key);
443 if ($verify == 1) {
444 $iwp_mmb_core->set_admin_panel_public_key($public_key);
445 $iwp_mmb_core->set_client_message_id($id);
446 $iwp_mmb_core->get_stats_instance();
447 if(isset($notifications) && is_array($notifications) && !empty($notifications)){
448 $iwp_mmb_core->stats_instance->set_notifications($notifications);
449 }
450 if(isset($brand) && is_array($brand) && !empty($brand)){
451 update_option('iwp_client_brand',$brand);
452 }
453
454 iwp_mmb_response($iwp_mmb_core->stats_instance->get_initial_stats(), true);
455 $iwp_mmb_activities_log->iwp_mmb_update_is_save_activity_log($params['is_save_activity_log']);
456 $iwp_mmb_activities_log->iwp_mmb_save_options_for_activity_log('add_site');
457 delete_option('iwp_client_activate_key');//iwp
458 } else if ($verify == 0) {
459 iwp_mmb_response(array('error' => 'Invalid message signature. Please contact us if you see this message often.', 'error_code' => 'iwp_mmb_add_site_invalid_message_signature'), false);
460 } else {
461 iwp_mmb_response(array('error' => 'Command not successful. Please try again.', 'error_code' => 'iwp_mmb_add_site_command_not_successful'), false);
462 }
463 } else {
464 if (!get_option('iwp_client_nossl_key')) {
465 srand();
466
467 $random_key = md5(base64_encode($public_key) . rand(0, getrandmax()));
468
469 $iwp_mmb_core->set_random_signature($random_key);
470 $iwp_mmb_core->set_client_message_id($id);
471 $iwp_mmb_core->set_admin_panel_public_key($public_key);
472 $iwp_mmb_core->get_stats_instance();
473 if(is_array($notifications) && !empty($notifications)){
474 $iwp_mmb_core->stats_instance->set_notifications($notifications);
475 }
476
477 if(is_array($brand) && !empty($brand)){
478 update_option('iwp_client_brand',$brand);
479 }
480 $iwp_mmb_activities_log->iwp_mmb_update_is_save_activity_log($params['is_save_activity_log']);
481 $iwp_mmb_activities_log->iwp_mmb_save_options_for_activity_log('add_site');
482 iwp_mmb_response($iwp_mmb_core->stats_instance->get_initial_stats(), true);
483 delete_option('iwp_client_activate_key');//IWP
484 } else
485 iwp_mmb_response(array('error' => 'Please deactivate & activate InfiniteWP Client plugin on your site, then add the site again.', 'error_code' => 'deactivate_ctivate_InfiniteWP_Client_plugin_add_site_again_not_iwp_client_nossl_key'), false);
486 }
487 } else {
488 iwp_mmb_response(array('error' => 'Please deactivate & activate InfiniteWP Client plugin on your site, then add the site again.', 'error_code' => 'deactivate_ctivate_InfiniteWP_Client_plugin_add_site_again_not_iwp_client_nossl_key'), false);
489 }
490 } else {
491 iwp_mmb_response(array('error' => 'Invalid parameters received. Please try again.', 'error_code' => 'iwp_mmb_add_site_invalid_parameters_received'), false);
492 }
493 }
494}
495
496if( !function_exists ( 'iwp_mmb_readd_site' )) {
497 function iwp_mmb_readd_site($params){
498 global $iwp_mmb_core,$iwp_mmb_activities_log;
499 $num = extract($params);
500 if ($num) {
501 if (!get_option('iwp_client_action_message_id') && !get_option('iwp_client_public_key')) {
502 $public_key = base64_decode($public_key);
503 if(trim($activation_key) != get_option('iwp_client_activate_key')){ //iwp
504 iwp_mmb_response(array('error' => 'Invalid activation key', 'error_code' => 'iwp_mmb_readd_site_invalid_activation_key'), false);
505 return;
506 }
507 if (checkOpenSSL() && !$user_random_key_signing) {
508
509 $verify = openssl_verify($action . $id, $signature, $public_key);
510 if ($verify == 1) {
511 $iwp_mmb_core->set_admin_panel_public_key($public_key);
512 $iwp_mmb_core->set_client_message_id($id);
513 $iwp_mmb_core->get_stats_instance();
514 if(isset($notifications) && is_array($notifications) && !empty($notifications)){
515 $iwp_mmb_core->stats_instance->set_notifications($notifications);
516 }
517 if(isset($brand) && is_array($brand) && !empty($brand)){
518 update_option('iwp_client_brand',$brand);
519 }
520 $iwp_mmb_activities_log->iwp_mmb_update_is_save_activity_log($params['is_save_activity_log']);
521 $iwp_mmb_activities_log->iwp_mmb_save_options_for_activity_log('readd_site');
522 iwp_mmb_response($iwp_mmb_core->stats_instance->get_initial_stats(), true);
523 delete_option('iwp_client_activate_key');//iwp
524 } else if ($verify == 0) {
525 iwp_mmb_response(array('error' => 'Invalid message signature. Please contact us if you see this message often.', 'error_code' => 'iwp_mmb_readd_site_invalid_message_signature'), false);
526 } else {
527 iwp_mmb_response(array('error' => 'Command not successful. Please try again.', 'error_code' => 'iwp_mmb_readd_site_command_not_successful'), false);
528 }
529 } else {
530 if (!get_option('iwp_client_nossl_key')) {
531 srand();
532
533 $random_key = md5(base64_encode($public_key) . rand(0, getrandmax()));
534
535 $iwp_mmb_core->set_random_signature($random_key);
536 $iwp_mmb_core->set_client_message_id($id);
537 $iwp_mmb_core->set_admin_panel_public_key($public_key);
538 $iwp_mmb_core->get_stats_instance();
539 if(is_array($notifications) && !empty($notifications)){
540 $iwp_mmb_core->stats_instance->set_notifications($notifications);
541 }
542
543 if(is_array($brand) && !empty($brand)){
544 update_option('iwp_client_brand',$brand);
545 }
546 $iwp_mmb_activities_log->iwp_mmb_update_is_save_activity_log($params['is_save_activity_log']);
547 $iwp_mmb_activities_log->iwp_mmb_save_options_for_activity_log('readd_site');
548 iwp_mmb_response($iwp_mmb_core->stats_instance->get_initial_stats(), true);
549 delete_option('iwp_client_activate_key');//IWP
550 } else
551 iwp_mmb_response(array('error' => 'Please deactivate & activate InfiniteWP Client plugin on your site, then add the site again.', 'error_code' => 'deactivate_ctivate_InfiniteWP_Client_plugin_add_site_again_not_iwp_client_nossl_key'), false);
552 }
553 } else {
554 iwp_mmb_response(array('error' => 'Please deactivate & activate InfiniteWP Client plugin on your site, then add the site again.', 'error_code' => 'deactivate_ctivate_InfiniteWP_Client_plugin_add_site_again_not_iwp_client_nossl_key'), false);
555 }
556 } else {
557 iwp_mmb_response(array('error' => 'Invalid parameters received. Please try again.', 'error_code' => 'iwp_mmb_add_site_invalid_parameters_received'), false);
558 }
559 }
560}
561
562if(!function_exists('iwp_mmb_maintain_site')){
563 function iwp_mmb_maintain_site($params){
564 $check = 1;
565 if(get_option('iwp_mmb_maintenance_mode') != $params['maintenance_mode'])
566 if(update_option('iwp_mmb_maintenance_mode',$params['maintenance_mode']) ){ $check = 1;}else{$check = 0;}
567 if(get_option('iwp_mmb_maintenance_html') != $params['maintenance_html'])
568 if(update_option('iwp_mmb_maintenance_html',$params['maintenance_html']) ){ $check = 1;}else{$check = 0;}
569 if($check == 1){
570 iwp_mmb_response($params, true);
571 }else{
572 iwp_mmb_response(array('error' => 'Some error with database connection in client site', 'error_code' => 'database_connection_in_client_site'), false);
573 }
574 }
575}
576
577
578if( !function_exists ( 'iwp_mmb_remove_site' )) {
579 function iwp_mmb_remove_site($params)
580 {
581 extract($params);
582 global $iwp_mmb_core;
583 $iwp_mmb_core->uninstall( $deactivate );
584
585 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
586 $plugin_slug = basename(dirname(__FILE__)) . '/' . basename(__FILE__);
587
588 if ($deactivate) {
589 deactivate_plugins($plugin_slug, true);
590 }
591
592 if (!is_plugin_active($plugin_slug))
593 iwp_mmb_response(array(
594 'deactivated' => 'Site removed successfully. <br /><br />InfiniteWP Client plugin successfully deactivated.'
595 ), true);
596 else
597 iwp_mmb_response(array(
598 'removed_data' => 'Site removed successfully. <br /><br /><b>InfiniteWP Client plugin was not deactivated.</b>'
599 ), true);
600
601 }
602}
603if( !function_exists ( 'iwp_mmb_stats_get' )) {
604 function iwp_mmb_stats_get($params)
605 {
606 global $iwp_mmb_core;
607 $iwp_mmb_core->get_stats_instance();
608 iwp_mmb_response($iwp_mmb_core->stats_instance->get($params), true);
609 }
610}
611
612if( !function_exists ( 'iwp_mmb_client_header' )) {
613 function iwp_mmb_client_header()
614 { global $iwp_mmb_core, $current_user;
615
616 if(!headers_sent()){
617 if(isset($current_user->ID))
618 $expiration = time() + apply_filters('auth_cookie_expiration', 10800, $current_user->ID, false);
619 else
620 $expiration = time() + 10800;
621
622 setcookie(IWP_MMB_XFRAME_COOKIE, md5(IWP_MMB_XFRAME_COOKIE), $expiration, COOKIEPATH, COOKIE_DOMAIN, false, true);
623 $_COOKIE[IWP_MMB_XFRAME_COOKIE] = md5(IWP_MMB_XFRAME_COOKIE);
624 }
625 }
626}
627
628if( !function_exists ( 'iwp_mmb_pre_init_stats' )) {
629 function iwp_mmb_pre_init_stats( $params )
630 {
631 global $iwp_mmb_core;
632 $iwp_mmb_core->get_stats_instance();
633 return $iwp_mmb_core->stats_instance->pre_init_stats($params);
634 }
635}
636
637if( !function_exists ( 'iwp_mmb_trigger_check_new' )) {
638//backup multi call trigger and status check.
639 function iwp_mmb_trigger_check_new($params)
640 {
641 global $iwp_backup_core;
642 $return = $iwp_backup_core->getRunningBackupStatus($params);
643
644 if (is_array($return) && array_key_exists('error', $return))
645 iwp_mmb_response($return, false);
646 else {
647 iwp_mmb_response($return, true);
648 }
649 }
650}
651
652if( !function_exists ( 'iwp_pheonix_backup_cron_do_action' )) {
653//backup multi call trigger and status check.
654 function iwp_pheonix_backup_cron_do_action($params)
655 {
656 global $iwp_backup_core;
657 $return = $iwp_backup_core->iwp_pheonix_backup_cron_do_action($params);
658
659 if (is_array($return) && array_key_exists('error', $return))
660 iwp_mmb_response($return, false);
661 else {
662 iwp_mmb_response($return, true);
663 }
664 }
665}
666
667if( !function_exists ( 'iwp_mmb_trigger_check' )) {
668//backup multi call trigger and status check.
669 function iwp_mmb_trigger_check($params)
670 {
671 global $iwp_mmb_core;
672 $iwp_mmb_core->get_backup_instance($params['mechanism']);
673 $return = $iwp_mmb_core->backup_instance->trigger_check($params);
674
675 if (is_array($return) && array_key_exists('error', $return))
676 iwp_mmb_response($return, false);
677 else {
678 iwp_mmb_response($return, true);
679 }
680 }
681}
682
683
684if( !function_exists ( 'iwp_mmb_backup_now' )) {
685//backup
686 function iwp_mmb_backup_now($params)
687 {
688 global $iwp_mmb_core;
689
690 $iwp_mmb_core->get_backup_instance();
691 $return = $iwp_mmb_core->backup_instance->backup($params);
692
693 if (is_array($return) && array_key_exists('error', $return))
694 iwp_mmb_response($return, false);
695 else {
696 iwp_mmb_response($return, true);
697 }
698 }
699}
700
701if( !function_exists ( 'iwp_get_additional_stats' )) {
702//backup
703 function iwp_get_additional_stats($params)
704 {
705 global $iwp_mmb_core, $iwp_mmb_plugin_dir;
706 $response = array();
707 if (!empty($params['requiredActions']) && isset($params['requiredActions']['get_all_links'])) {
708 $iwp_mmb_core->wp_blc_get_blinks();
709 $brokenlinks = $iwp_mmb_core->blc_get_blinks->blc_get_all_links();
710 if (is_array($brokenlinks) && !array_key_exists('error', $brokenlinks))
711 $response['get_all_links'] = $brokenlinks;
712 }
713 if (!empty($params['requiredActions']) && isset($params['requiredActions']['ithemes_security_check'])) {
714 if (iwp_mmb_ithemes_security_check()) {
715 $ithemessec_instance = $iwp_mmb_core->get_ithemessec_instance();
716 $return = $ithemessec_instance->securityCheck();
717 if (isset($return['security_check'])) {
718 $response['ithemes_security_check'] = $return['security_check'];
719 }
720 }
721 }
722 if (!empty($params['requiredActions']) && isset($params['requiredActions']['sucuri_fetch_result'])) {
723 require_once("$iwp_mmb_plugin_dir/addons/malware_scanner_sucuri/malware_scanner_sucuri.class.php");
724 $iwp_mmb_core->get_sucuri_instance();
725
726 $return = $iwp_mmb_core->sucuri_instance->getScannedCacheResult();
727 if (is_array($return) && !array_key_exists('error', $return))
728 $response['sucuri_fetch_result'] = $return;
729 }
730
731 if (!empty($params['requiredActions']) && isset($params['requiredActions']['get_comments'])) {
732 require_once("$iwp_mmb_plugin_dir/addons/malware_scanner_sucuri/malware_scanner_sucuri.class.php");
733 $iwp_mmb_core->get_comment_instance();
734
735 $return = $iwp_mmb_core->comment_instance->get_comments($params['requiredActions']['get_comments']);
736 if (is_array($return) && !array_key_exists('error', $return))
737 $response['get_comments'] = $return;
738 }
739
740 if (!empty($params['requiredActions']) && isset($params['requiredActions']['get_users'])) {
741 $iwp_mmb_core->get_user_instance();
742
743 $return = $iwp_mmb_core->user_instance->get_users($params['requiredActions']['get_users']);
744 if (is_array($return) && !array_key_exists('error', $return))
745 $response['get_users'] = $return;
746 }
747
748 if (!empty($params['requiredActions']) && isset($params['requiredActions']['wordfence_load'])) {
749 global $iwp_mmb_core,$iwp_mmb_plugin_dir;
750 require_once("$iwp_mmb_plugin_dir/addons/wordfence/wordfence.class.php");
751 $iwp_mmb_core->get_wordfence_instance();
752
753 $return = $iwp_mmb_core->wordfence_instance->load($params);
754 if (is_array($return) && !array_key_exists('error', $return))
755 $response['wordfence_load'] = $return;
756 }
757 // bulk publish
758 if (!empty($params['requiredActions']) && isset($params['requiredActions']['get_bulkposts'])) {
759 $iwp_mmb_core->get_post_instance();
760 $return = $iwp_mmb_core->post_instance->get_posts($params['requiredActions']['get_bulkposts']);
761 if (is_array($return) && !array_key_exists('error', $return))
762 $response['get_bulkposts'] = $return;
763 }
764
765 if (!empty($params['requiredActions']) && isset($params['requiredActions']['get_bulkpages'])) {
766 $iwp_mmb_core->get_post_instance();
767 $return = $iwp_mmb_core->post_instance->get_pages($params['requiredActions']['get_bulkpages']);
768 if (is_array($return) && !array_key_exists('error', $return))
769 $response['get_bulkpages'] = $return;
770 }
771
772 if (!empty($params['requiredActions']) && isset($params['requiredActions']['get_bulklinks'])) {
773 $iwp_mmb_core->get_link_instance();
774 $return = $iwp_mmb_core->link_instance->get_links($params['requiredActions']['get_bulklinks']);
775 if (is_array($return) && !array_key_exists('error', $return))
776 $response['get_bulklinks'] = $return;
777 }
778
779 if (is_array($response) && array_key_exists('error', $response))
780 iwp_mmb_response($response, false);
781 else {
782 iwp_mmb_response($response, true);
783 }
784 }
785}
786
787if( !function_exists ( 'iwp_mmb_new_scheduled_backup' )) {
788 function iwp_mmb_new_scheduled_backup($params)
789 {
790 require_once($GLOBALS['iwp_mmb_plugin_dir']."/backup/backup-repo-test.php");
791 global $iwp_backup_core;
792
793 if (!empty($params['backup_nounce'])) {
794 $backupId = $params['backup_nounce'];
795 }else{
796 $backupId = $iwp_backup_core->backup_time_nonce();
797 }
798
799 $msg = array(
800 'backup_id' => $backupId,
801 'parentHID' => $params['args']['parentHID'],
802 'success' => 'Backup started',
803 'wp_content_url' => content_url(),
804 );
805 $iwp_backup_dir = $iwp_backup_core->backups_dir_location();
806 if (is_array($iwp_backup_dir) && array_key_exists('error', $iwp_backup_dir)){
807 iwp_closeBrowserConnection($iwp_backup_dir, false);
808 }
809 // Close browser connection not working for some servers so we suggest IWP_PHOENIX_BACKUP_CRON
810 // iwp_closeBrowserConnection( $msg );
811 if ((!defined('DISABLE_IWP_CLOUD_VERIFICATION')) && (empty($params['args']['disable_iwp_cloud_verification']))) {
812 require_once($GLOBALS['iwp_mmb_plugin_dir']."/backup.class.multicall.php");
813 $backup_repo_test_obj = new IWP_BACKUP_REPO_TEST();
814 $backup_repo_test_result = $backup_repo_test_obj->repositoryTestConnection($params['account_info']);
815 if (!empty($backup_repo_test_result['error']) && $backup_repo_test_result['status'] != 'success') {
816 $return = array('error' => $backup_repo_test_result['error'], 'error_code' => $backup_repo_test_result['error_code']);
817 iwp_mmb_response($return, false);
818 }
819 }
820 if (is_array($msg) && array_key_exists('error', $msg))
821 iwp_closeBrowserConnection($msg, false);
822 else {
823 iwp_closeBrowserConnection($msg, true);
824 }
825 $iwp_backup_core->set_backup_task_option($params);
826 if (!empty($params['args']['exclude'])) {
827 $params['restrict_files_to_override']= explode(',', $params['args']['exclude']);
828 }
829 // return true;
830 if (defined('IWP_PHOENIX_BACKUP_CRON_START') && IWP_PHOENIX_BACKUP_CRON_START) {
831 $params['cron_start'] = 1;
832 }
833 $params['use_nonce'] = $backupId;
834 $params['label'] = $params['task_name'];
835 $params['backup_name'] = $params['args']['backup_name'];
836 if ($params['args']['what'] == 'db') {
837 // $return = $iwp_mmb_core->backup_new_instance->backupnow_database($params);
838 do_action( 'IWP_backupnow_backup_database', $params );
839 } elseif ($params['args']['what'] == 'files') {
840 // $return = $iwp_mmb_core->backup_new_instance->backupnow_files($params);
841 do_action( 'IWP_backupnow_backup', $params );
842 } else {
843 // $return = $iwp_mmb_core->backup_new_instance->backup_all($params);
844 do_action( 'IWP_backupnow_backup_all', $params );
845 }
846
847 }
848}
849
850if( !function_exists ( 'iwp_mmb_run_task_now' )) {
851 function iwp_mmb_run_task_now($params)
852 {
853 global $iwp_mmb_core;
854 $iwp_mmb_core->get_backup_instance($params['mechanism']);
855 //$return = $iwp_mmb_core->backup_instance->task_now(); //set_backup_task($params)
856 $return = $iwp_mmb_core->backup_instance->set_backup_task($params);
857 if (is_array($return) && array_key_exists('error', $return))
858 iwp_mmb_response($return, false);
859 else {
860 iwp_mmb_response($return, true);
861 }
862 }
863}
864
865if( !function_exists ( 'iwp_mmb_delete_task_now' )) {
866 function iwp_mmb_delete_task_now($params)
867 {
868 global $iwp_mmb_core;
869 $iwp_mmb_core->get_backup_instance();
870 $return = $iwp_mmb_core->backup_instance->delete_task_now($params['task_name']);
871 if (is_array($return) && array_key_exists('error', $return))
872 iwp_mmb_response($return, false);
873 else {
874 iwp_mmb_response($return, true);
875 }
876 }
877}
878if( !function_exists ( 'iwp_mmb_check_backup_compat' )) {
879 function iwp_mmb_check_backup_compat($params)
880 {
881 global $iwp_mmb_core;
882 $iwp_mmb_core->get_backup_instance();
883 $return = $iwp_mmb_core->backup_instance->check_backup_compat($params);
884
885 if (is_array($return) && array_key_exists('error', $return))
886 iwp_mmb_response($return, false);
887 else {
888 iwp_mmb_response($return, true);
889 }
890 }
891}
892
893if( !function_exists ( 'iwp_mmb_get_backup_req' )) {
894 function iwp_mmb_get_backup_req( $params )
895 {
896 global $iwp_mmb_core;
897 $iwp_mmb_core->get_stats_instance();
898 $return = $iwp_mmb_core->stats_instance->get_backup_req($params);
899
900 if (is_array($return) && array_key_exists('error', $return))
901 iwp_mmb_response($return, false);
902 else {
903 iwp_mmb_response($return, true);
904 }
905 }
906}
907
908
909if( !function_exists ( 'iwp_mmb_scheduled_backup' )) {
910 function iwp_mmb_scheduled_backup($params)
911 {
912 global $iwp_mmb_core;
913 $iwp_mmb_core->get_backup_instance($params['mechanism']);
914 $return = $iwp_mmb_core->backup_instance->set_backup_task($params);
915 iwp_mmb_response($return, $return);
916 }
917}
918
919if( !function_exists ( 'iwp_get_db_details' )) {
920 function iwp_get_db_details($params)
921 {
922 global $iwp_mmb_core;
923 $return = $iwp_mmb_core->get_db_details($params);
924 iwp_mmb_response($return, $return);
925 }
926}
927
928if( !function_exists ( 'iwp_mmb_new_run_task_now' )) {
929 function iwp_mmb_new_run_task_now($params)
930 {
931 require_once($GLOBALS['iwp_mmb_plugin_dir']."/backup/backup-repo-test.php");
932 global $iwp_backup_core;
933
934 if (!empty($params['backup_nounce'])) {
935 $backupId = $params['backup_nounce'];
936 }else{
937 $backupId = $iwp_backup_core->backup_time_nonce();
938 }
939
940 $msg = array(
941 'backup_id' => $backupId,
942 'parentHID' => $params['args']['parentHID'],
943 'success' => 'Backup started',
944 'wp_content_url' => content_url(),
945 );
946 $iwp_backup_dir = $iwp_backup_core->backups_dir_location();
947 if (is_array($iwp_backup_dir) && array_key_exists('error', $iwp_backup_dir)){
948 iwp_closeBrowserConnection($iwp_backup_dir, false);
949 }
950 // Close browser connection not working for some servers so we suggest IWP_PHOENIX_BACKUP_CRON
951 // iwp_closeBrowserConnection( $msg );
952 if ((!defined('DISABLE_IWP_CLOUD_VERIFICATION')) && (empty($params['args']['disable_iwp_cloud_verification']))) {
953 require_once($GLOBALS['iwp_mmb_plugin_dir']."/backup.class.multicall.php");
954 $backup_repo_test_obj = new IWP_BACKUP_REPO_TEST();
955 $backup_repo_test_result = $backup_repo_test_obj->repositoryTestConnection($params['account_info']);
956 if (!empty($backup_repo_test_result['error']) && $backup_repo_test_result['status'] != 'success') {
957 $return = array('error' => $backup_repo_test_result['error'], 'error_code' => $backup_repo_test_result['error_code']);
958 iwp_mmb_response($return, false);
959 }
960 }
961 if (is_array($msg) && array_key_exists('error', $msg))
962 iwp_closeBrowserConnection($msg, false);
963 else {
964 iwp_closeBrowserConnection($msg, true);
965 }
966 $iwp_backup_core->set_backup_task_option($params);
967 if (!empty($params['args']['exclude'])) {
968 $params['restrict_files_to_override']= explode(',', $params['args']['exclude']);
969 }
970 // return true;
971 if (defined('IWP_PHOENIX_BACKUP_CRON_START') && IWP_PHOENIX_BACKUP_CRON_START) {
972 $params['cron_start'] = 1;
973 }
974 $params['use_nonce'] = $backupId;
975 $params['label'] = $params['task_name'];
976 $params['backup_name'] = $params['args']['backup_name'];
977 if ($params['args']['what'] == 'db') {
978 // $return = $iwp_mmb_core->backup_new_instance->backupnow_database($params);
979 do_action( 'IWP_backupnow_backup_database', $params );
980 } elseif ($params['args']['what'] == 'files') {
981 // $return = $iwp_mmb_core->backup_new_instance->backupnow_files($params);
982 do_action( 'IWP_backupnow_backup', $params );
983 } else {
984 // $return = $iwp_mmb_core->backup_new_instance->backup_all($params);
985 do_action( 'IWP_backupnow_backup_all', $params );
986 }
987
988 }
989}
990
991if( !function_exists ( 'iwp_mmb_delete_backup_new' )) {
992 function iwp_mmb_delete_backup_new($params)
993 {
994 global $iwp_mmb_core;
995 $iwp_mmb_core->get_new_backup_instance($params);
996 $return = $iwp_mmb_core->backup_new_instance->delete_backup($params);
997 iwp_mmb_response($return, $return);
998 }
999}
1000
1001if( !function_exists ( 'iwp_mmb_kill_new_backup' )) {
1002 function iwp_mmb_kill_new_backup($params)
1003 {
1004 global $iwp_mmb_core;
1005 $iwp_mmb_core->get_new_backup_instance($params);
1006 $return = $iwp_mmb_core->backup_new_instance->kill_new_backup($params);
1007 iwp_mmb_response($return, $return);
1008 }
1009}
1010
1011if( !function_exists ( 'iwp_mmb_delete_backup' )) {
1012 function iwp_mmb_delete_backup($params)
1013 {
1014 global $iwp_mmb_core;
1015 $iwp_mmb_core->get_backup_instance();
1016 $return = $iwp_mmb_core->backup_instance->delete_backup($params);
1017 iwp_mmb_response($return, $return);
1018 }
1019}
1020
1021if( !function_exists ( 'iwp_mmb_backup_downlaod' )) {
1022 function iwp_mmb_backup_downlaod($params)
1023 {
1024 global $iwp_mmb_core;
1025 $iwp_mmb_core->get_new_backup_instance();
1026 //$return = $iwp_mmb_core->backup_instance->task_now(); //set_backup_task($params)
1027 $return = $iwp_mmb_core->backup_new_instance->do_iwp_download_backup($params);
1028 if (is_array($return) && array_key_exists('error', $return))
1029 iwp_mmb_response($return, false);
1030 else {
1031 iwp_mmb_response($return, true);
1032 }
1033 }
1034}
1035
1036if( !function_exists ( 'iwp_mmb_optimize_tables' )) {
1037 function iwp_mmb_optimize_tables($params)
1038 {
1039 global $iwp_mmb_core;
1040 $iwp_mmb_core->get_backup_instance();
1041 $return = $iwp_mmb_core->backup_instance->optimize_tables();
1042 if ($return)
1043 iwp_mmb_response($return, true);
1044 else
1045 iwp_mmb_response(false, false);
1046 }
1047}
1048if( !function_exists ( 'iwp_mmb_restore_now' )) {
1049 function iwp_mmb_restore_now($params)
1050 {
1051 global $iwp_mmb_core;
1052 $iwp_mmb_core->get_backup_instance('multiCall');
1053 $return = $iwp_mmb_core->backup_instance->restore($params);
1054
1055 if (is_array($return) && array_key_exists('error', $return))
1056 iwp_mmb_response($return, false);
1057 else
1058 iwp_mmb_response($return, true);
1059
1060 }
1061}
1062
1063
1064if( !function_exists ( 'iwp_mmb_backup_repository' )) {
1065 function iwp_mmb_backup_repository($params)
1066 {
1067 global $iwp_mmb_core;
1068 $iwp_mmb_core->get_backup_repository_instance();
1069 $return = $iwp_mmb_core->backup_repository_instance->backup_repository($params);
1070 if (is_array($return) && array_key_exists('error', $return))
1071 iwp_mmb_response($return, false);
1072 else
1073 iwp_mmb_response($return, true);
1074 }
1075}
1076
1077
1078if( !function_exists ( 'iwp_mmb_clean_orphan_backups' )) {
1079 function iwp_mmb_clean_orphan_backups()
1080 {
1081 global $iwp_mmb_core;
1082 $backup_instance = $iwp_mmb_core->get_backup_instance();
1083 $return = $iwp_mmb_core->backup_instance->cleanup();
1084 if(is_array($return))
1085 iwp_mmb_response($return, true);
1086 else
1087 iwp_mmb_response($return, false);
1088 }
1089}
1090
1091
1092
1093add_filter( 'iwp_website_add', 'iwp_mmb_readd_backup_task' );
1094
1095if (!function_exists('iwp_mmb_readd_backup_task')) {
1096 function iwp_mmb_readd_backup_task($params = array()) {
1097 global $iwp_mmb_core;
1098 $backup_instance = $iwp_mmb_core->get_backup_instance();
1099 $settings = $backup_instance->readd_tasks($params);
1100 return $settings;
1101 }
1102}
1103
1104if( !function_exists ( 'iwp_mmb_update_client_plugin' )) {
1105 function iwp_mmb_update_client_plugin($params)
1106 {
1107 global $iwp_mmb_core;
1108 iwp_mmb_response($iwp_mmb_core->update_client_plugin($params), true);
1109 }
1110}
1111
1112if( !function_exists ( 'iwp_mmb_wp_checkversion' )) {
1113 function iwp_mmb_wp_checkversion($params)
1114 {
1115 include_once(ABSPATH . 'wp-includes/version.php');
1116 global $iwp_mmb_wp_version, $iwp_mmb_core;
1117 iwp_mmb_response($iwp_mmb_wp_version, true);
1118 }
1119}
1120if( !function_exists ( 'iwp_mmb_search_posts_by_term' )) {
1121 function iwp_mmb_search_posts_by_term($params)
1122 {
1123 global $iwp_mmb_core;
1124 $iwp_mmb_core->get_search_instance();
1125
1126 $search_type = trim($params['search_type']);
1127 $search_term = strtolower(trim($params['search_term']));
1128
1129 switch ($search_type){
1130 case 'plugin':
1131 $plugins = get_option('active_plugins');
1132
1133 $have_plugin = false;
1134 foreach ($plugins as $plugin) {
1135 if(strpos($plugin, $search_term)>-1){
1136 $have_plugin = true;
1137 }
1138 }
1139 if($have_plugin){
1140 iwp_mmb_response(serialize($plugin), true);
1141 }else{
1142 iwp_mmb_response(false, false);
1143 }
1144 break;
1145 case 'theme':
1146 $theme = strtolower(get_option('template'));
1147 if(strpos($theme, $search_term)>-1){
1148 iwp_mmb_response($theme, true);
1149 }else{
1150 iwp_mmb_response(false, false);
1151 }
1152 break;
1153 default: iwp_mmb_response(false, false);
1154 }
1155 $return = $iwp_mmb_core->search_instance->iwp_mmb_search_posts_by_term($params);
1156
1157
1158
1159 if ($return_if_true) {
1160 iwp_mmb_response($return_value, true);
1161 } else {
1162 iwp_mmb_response($return_if_false, false);
1163 }
1164 }
1165}
1166
1167if( !function_exists ( 'iwp_mmb_install_addon' )) {
1168 function iwp_mmb_install_addon($params)
1169 {
1170 global $iwp_mmb_core;
1171 $iwp_mmb_core->get_installer_instance();
1172 $return = $iwp_mmb_core->installer_instance->install_remote_file($params);
1173 iwp_mmb_response($return, true);
1174
1175 }
1176}
1177
1178if( !function_exists ( 'iwp_mmb_do_upgrade' )) {
1179 function iwp_mmb_do_upgrade($params)
1180 {
1181 global $iwp_mmb_core, $iwp_mmb_upgrading;
1182 $iwp_mmb_core->get_installer_instance();
1183 $return = $iwp_mmb_core->installer_instance->do_upgrade($params);
1184 iwp_mmb_response($return, true);
1185
1186 }
1187}
1188
1189if( !function_exists ( 'iwp_mmb_add_user' )) {
1190 function iwp_mmb_add_user($params)
1191 {
1192 global $iwp_mmb_core;
1193 $iwp_mmb_core->get_user_instance();
1194 if(!empty($params['additional_params'])){
1195 $return['action_response'] = $iwp_mmb_core->user_instance->add_user($params['action_params']);
1196 $return['additional_response'] = $iwp_mmb_core->user_instance->get_users($params['additional_params']);
1197 }else{
1198 $return = $iwp_mmb_core->user_instance->add_user($params);
1199 }
1200
1201 if (is_array($return) && array_key_exists('error', $return)){
1202 iwp_mmb_response($return, false);
1203 }
1204 else {
1205 iwp_mmb_response($return, true);
1206 }
1207
1208 }
1209}
1210
1211if( !function_exists ('iwp_mmb_get_users')) {
1212 function iwp_mmb_get_users($params)
1213 {
1214 global $iwp_mmb_core;
1215 $iwp_mmb_core->get_user_instance();
1216 $return = $iwp_mmb_core->user_instance->get_users($params);
1217 if (is_array($return) && array_key_exists('error', $return))
1218 iwp_mmb_response($return, false);
1219 else {
1220 iwp_mmb_response($return, true);
1221 }
1222 }
1223}
1224
1225if( !function_exists ('iwp_mmb_edit_users')) {
1226 function iwp_mmb_edit_users($params)
1227 {
1228 global $iwp_mmb_core;
1229 $iwp_mmb_core->get_user_instance();
1230 if(!empty($params['additional_params'])){
1231 $params['action_params']['username'] = $params['username'];
1232 $return['action_response'] = $iwp_mmb_core->user_instance->edit_users($params['action_params']);
1233 $return['additional_response'] = $iwp_mmb_core->user_instance->get_users($params['additional_params']);
1234 }else{
1235 $return = $iwp_mmb_core->user_instance->edit_users($params);
1236 }
1237
1238 iwp_mmb_response($return, true);
1239 }
1240}
1241
1242if( !function_exists ( 'iwp_mmb_iframe_plugins_fix' )) {
1243 function iwp_mmb_iframe_plugins_fix($update_actions)
1244 {
1245 foreach($update_actions as $key => $action)
1246 {
1247 $update_actions[$key] = str_replace('target="_parent"','',$action);
1248 }
1249
1250 return $update_actions;
1251
1252 }
1253}
1254
1255if( !function_exists ( 'iwp_mmb_set_notifications' )) {
1256 function iwp_mmb_set_notifications($params)
1257 {
1258 global $iwp_mmb_core;
1259 $iwp_mmb_core->get_stats_instance();
1260 $return = $iwp_mmb_core->stats_instance->set_notifications($params);
1261 if (is_array($return) && array_key_exists('error', $return))
1262 iwp_mmb_response($return, false);
1263 else {
1264 iwp_mmb_response($return, true);
1265 }
1266
1267 }
1268}
1269
1270if( !function_exists ( 'iwp_mmb_set_alerts' )) {
1271 function iwp_mmb_set_alerts($params)
1272 {
1273 global $iwp_mmb_core;
1274 $iwp_mmb_core->get_stats_instance();
1275 $return = $iwp_mmb_core->stats_instance->set_alerts($params);
1276 iwp_mmb_response(true, true);
1277 }
1278}
1279
1280/*
1281if(!function_exists('iwp_mmb_more_reccurences')){
1282 //Backup Tasks
1283 add_filter('cron_schedules', 'iwp_mmb_more_reccurences');
1284 function iwp_mmb_more_reccurences($schedules) {
1285 $schedules['halfminute'] = array('interval' => 30, 'display' => 'Once in a half minute');
1286 $schedules['minutely'] = array('interval' => 60, 'display' => 'Once in a minute');
1287 $schedules['fiveminutes'] = array('interval' => 300, 'display' => 'Once every five minutes');
1288 $schedules['tenminutes'] = array('interval' => 600, 'display' => 'Once every ten minutes');
1289
1290 return $schedules;
1291 }
1292}
1293
1294 add_action('iwp_client_backup_tasks', 'iwp_client_check_backup_tasks');
1295
1296if( !function_exists('iwp_client_check_backup_tasks') ){
1297 function iwp_client_check_backup_tasks() {
1298 global $iwp_mmb_core, $_wp_using_ext_object_cache;
1299 $_wp_using_ext_object_cache = false;
1300
1301 $iwp_mmb_core->get_backup_instance();
1302 $iwp_mmb_core->backup_instance->check_backup_tasks();
1303 }
1304}
1305*/
1306
1307if( !function_exists('iwp_check_notifications') ){
1308 function iwp_check_notifications() {
1309 global $iwp_mmb_core, $_wp_using_ext_object_cache;
1310 $_wp_using_ext_object_cache = false;
1311
1312 $iwp_mmb_core->get_stats_instance();
1313 $iwp_mmb_core->stats_instance->check_notifications();
1314 }
1315}
1316
1317
1318if( !function_exists('iwp_mmb_get_plugins_themes') ){
1319 function iwp_mmb_get_plugins_themes($params) {
1320 global $iwp_mmb_core;
1321 $iwp_mmb_core->get_installer_instance();
1322 $return = $iwp_mmb_core->installer_instance->get($params);
1323 iwp_mmb_response($return, true);
1324 }
1325}
1326
1327if( !function_exists('iwp_mmb_edit_plugins_themes') ){
1328 function iwp_mmb_edit_plugins_themes($params) {
1329 global $iwp_mmb_core;
1330 $iwp_mmb_core->get_installer_instance();
1331 $return = $iwp_mmb_core->installer_instance->edit($params);
1332 iwp_mmb_response($return, true);
1333 }
1334}
1335
1336//post
1337if( !function_exists ( 'iwp_mmb_post_create' )) {
1338 function iwp_mmb_post_create($params)
1339 {
1340 global $iwp_mmb_core;
1341 $iwp_mmb_core->get_post_instance();
1342 if(!empty($params['action_params'])){
1343 // v3
1344 $return['action_response'] = $iwp_mmb_core->post_instance->create($params['action_params']);
1345 $return['additional_response']['additional_posts'] = $iwp_mmb_core->post_instance->get_posts($params['additional_params']);
1346 $return['additional_response']['additional_pages'] = $iwp_mmb_core->post_instance->get_pages($params['additional_params']);
1347 if (is_int($return['action_response']))
1348 iwp_mmb_response($return, true);
1349 else{
1350 if(isset($return['action_response']['error'])){
1351 iwp_mmb_response($return['action_response'], false);
1352 } else {
1353 iwp_mmb_response($return['action_response'], false);
1354 }
1355 }
1356
1357 }else{
1358 // V2
1359 $return = $iwp_mmb_core->post_instance->create($params);
1360 if (is_int($return))
1361 iwp_mmb_response($return, true);
1362 else{
1363 if(isset($return['error'])){
1364 iwp_mmb_response($return, false);
1365 } else {
1366 iwp_mmb_response($return, false);
1367 }
1368 }
1369 }
1370
1371 }
1372}
1373
1374if( !function_exists ( 'iwp_mmb_change_post_status' )) {
1375 function iwp_mmb_change_post_status($params)
1376 {
1377 global $iwp_mmb_core;
1378 $iwp_mmb_core->get_post_instance();
1379 $return = $iwp_mmb_core->post_instance->change_status($params);
1380 //mmb_response($return, true);
1381
1382 }
1383}
1384
1385if( !function_exists ('iwp_mmb_get_posts')) {
1386 function iwp_mmb_get_posts($params)
1387 {
1388 global $iwp_mmb_core;
1389 $iwp_mmb_core->get_post_instance();
1390
1391 $return = $iwp_mmb_core->post_instance->get_posts($params);
1392 if (is_array($return) && array_key_exists('error', $return))
1393 iwp_mmb_response($return, false);
1394 else {
1395 iwp_mmb_response($return, true);
1396 }
1397 }
1398}
1399
1400if( !function_exists ('iwp_mmb_delete_post')) {
1401 function iwp_mmb_delete_post($params)
1402 {
1403 global $iwp_mmb_core;
1404 $iwp_mmb_core->get_post_instance();
1405 if(!empty($params['additional_params'])){
1406 $return['action_response'] = $iwp_mmb_core->post_instance->delete_post($params['action_params']);
1407 $return['additional_response'] = $iwp_mmb_core->post_instance->get_posts($params['additional_params']);
1408 }else{
1409 $return = $iwp_mmb_core->post_instance->delete_post($params);
1410 }
1411 if (is_array($return) && array_key_exists('error', $return))
1412 iwp_mmb_response($return, false);
1413 else {
1414 iwp_mmb_response($return, true);
1415 }
1416 }
1417}
1418
1419if( !function_exists ('iwp_mmb_delete_posts')) {
1420 function iwp_mmb_delete_posts($params)
1421 {
1422 global $iwp_mmb_core;
1423 $iwp_mmb_core->get_post_instance();
1424 if(!empty($params['action_params'])){
1425 $return['action_response'] = $iwp_mmb_core->post_instance->delete_posts($params['action_params']);
1426 $return['additional_response']['additional_posts'] = $iwp_mmb_core->post_instance->get_posts($params['additional_params']);
1427 $return['additional_response']['additional_pages'] = $iwp_mmb_core->post_instance->get_pages($params['additional_params']);
1428 }else{
1429 $return = $iwp_mmb_core->post_instance->delete_posts($params);
1430 }
1431 if (is_array($return) && array_key_exists('error', $return))
1432 iwp_mmb_response($return, false);
1433 else {
1434 iwp_mmb_response($return, true);
1435 }
1436 }
1437}
1438
1439if( !function_exists ('iwp_mmb_edit_posts')) {
1440 function iwp_mmb_edit_posts($params)
1441 {
1442 global $iwp_mmb_core;
1443 $iwp_mmb_core->get_posts_instance();
1444 $return = $iwp_mmb_core->posts_instance->edit_posts($params);
1445 iwp_mmb_response($return, true);
1446 }
1447}
1448
1449if( !function_exists ('iwp_mmb_get_pages')) {
1450 function iwp_mmb_get_pages($params)
1451 {
1452 global $iwp_mmb_core;
1453 $iwp_mmb_core->get_post_instance();
1454
1455 $return = $iwp_mmb_core->post_instance->get_pages($params);
1456 if (is_array($return) && array_key_exists('error', $return))
1457 iwp_mmb_response($return, false);
1458 else {
1459 iwp_mmb_response($return, true);
1460 }
1461 }
1462}
1463
1464if( !function_exists ('iwp_mmb_delete_page')) {
1465 function iwp_mmb_delete_page($params)
1466 {
1467 global $iwp_mmb_core;
1468 $iwp_mmb_core->get_post_instance();
1469 if(!empty($params['action_params'])){
1470 $return['action_response'] = $iwp_mmb_core->post_instance->delete_page($params['action_params']);
1471 $return['additional_response'] = $iwp_mmb_core->post_instance->get_pages($params['additional_params']);
1472 }else{
1473 $return = $iwp_mmb_core->post_instance->delete_page($params);
1474 }
1475 if (is_array($return) && array_key_exists('error', $return))
1476 iwp_mmb_response($return, false);
1477 else {
1478 iwp_mmb_response($return, true);
1479 }
1480 }
1481}
1482
1483
1484//links
1485if( !function_exists ('iwp_mmb_get_links')) {
1486 function iwp_mmb_get_links($params)
1487 {
1488 global $iwp_mmb_core;
1489 $iwp_mmb_core->get_link_instance();
1490 $return = $iwp_mmb_core->link_instance->get_links($params);
1491 if (is_array($return) && array_key_exists('error', $return))
1492 iwp_mmb_response($return, false);
1493 else {
1494 iwp_mmb_response($return, true);
1495 }
1496 }
1497}
1498
1499if( !function_exists ( 'iwp_mmb_add_link' )) {
1500 function iwp_mmb_add_link($params)
1501 {
1502 global $iwp_mmb_core;
1503 $iwp_mmb_core->get_link_instance();
1504 if(!empty($params['action_params'])){
1505 $return['action_response'] = $iwp_mmb_core->link_instance->add_link($params['action_params']);
1506 $return['additional_response'] = $iwp_mmb_core->link_instance->get_links($params['additional_params']);
1507 }else{
1508 $return = $iwp_mmb_core->link_instance->add_link($params);
1509 }
1510 if (is_array($return) && array_key_exists('error', $return)){
1511 iwp_mmb_response($return, false);
1512 }
1513 else {
1514 iwp_mmb_response($return, true);
1515 }
1516
1517 }
1518}
1519
1520if( !function_exists ('iwp_mmb_delete_link')) {
1521 function iwp_mmb_delete_link($params)
1522 {
1523 global $iwp_mmb_core;
1524 $iwp_mmb_core->get_link_instance();
1525 if(!empty($params['action_params'])){
1526 $return['action_response'] = $iwp_mmb_core->link_instance->delete_link($params['action_params']);
1527 $return['additional_response'] = $iwp_mmb_core->link_instance->get_links($params['additional_params']);
1528 }else{
1529 $return = $iwp_mmb_core->link_instance->delete_link($params);
1530 }
1531 if (is_array($return) && array_key_exists('error', $return)){
1532 iwp_mmb_response($return, false);
1533 }
1534 else {
1535 iwp_mmb_response($return, true);
1536 }
1537 }
1538}
1539
1540if( !function_exists ('iwp_mmb_delete_links')) {
1541 function iwp_mmb_delete_links($params)
1542 {
1543 global $iwp_mmb_core;
1544 $iwp_mmb_core->get_link_instance();
1545 if(!empty($params['action_params'])){
1546 $return['action_response'] = $iwp_mmb_core->link_instance->delete_links($params['action_params']);
1547 $return['additional_response'] = $iwp_mmb_core->link_instance->get_links($params['additional_params']);
1548 }else{
1549 $return = $iwp_mmb_core->link_instance->delete_links($params);
1550 }
1551 if (is_array($return) && array_key_exists('error', $return)){
1552 iwp_mmb_response($return, false);
1553 }
1554 else {
1555 iwp_mmb_response($return, true);
1556 }
1557 }
1558}
1559
1560
1561//comments
1562if( !function_exists ( 'iwp_mmb_change_comment_status' )) {
1563 function iwp_mmb_change_comment_status($params)
1564 {
1565 global $iwp_mmb_core;
1566 $iwp_mmb_core->get_comment_instance();
1567 $return = $iwp_mmb_core->comment_instance->change_status($params);
1568 //mmb_response($return, true);
1569 if ($return){
1570 $iwp_mmb_core->get_stats_instance();
1571 iwp_mmb_response($iwp_mmb_core->stats_instance->get_comments_stats($params), true);
1572 }else
1573 iwp_mmb_response(array('error' => 'Comment not updated', 'error_code' => 'comment_not_updated'), false);
1574 }
1575
1576}
1577if( !function_exists ( 'iwp_mmb_comment_stats_get' )) {
1578 function iwp_mmb_comment_stats_get($params)
1579 {
1580 global $iwp_mmb_core;
1581 $iwp_mmb_core->get_stats_instance();
1582 iwp_mmb_response($iwp_mmb_core->stats_instance->get_comments_stats($params), true);
1583 }
1584}
1585
1586if( !function_exists ('iwp_mmb_get_comments')) {
1587 function iwp_mmb_get_comments($params)
1588 {
1589 global $iwp_mmb_core;
1590 $iwp_mmb_core->get_comment_instance();
1591 $return = $iwp_mmb_core->comment_instance->get_comments($params);
1592 if (is_array($return) && array_key_exists('error', $return))
1593 iwp_mmb_response($return, false);
1594 else {
1595 iwp_mmb_response($return, true);
1596 }
1597 }
1598}
1599
1600if( !function_exists ('iwp_mmb_action_comment')) {
1601 function iwp_mmb_action_comment($params)
1602 {
1603 global $iwp_mmb_core;
1604 $iwp_mmb_core->get_comment_instance();
1605 if(!empty($params['additional_params'])){
1606 $return['action_response'] = $iwp_mmb_core->comment_instance->action_comment($params['action_params']);
1607 $return['additional_response'] = $iwp_mmb_core->comment_instance->get_comments($params['additional_params']);
1608 }else{
1609 $return = $iwp_mmb_core->comment_instance->action_comment($params);
1610 }
1611 if (is_array($return) && array_key_exists('error', $return))
1612 iwp_mmb_response($return, false);
1613 else {
1614 iwp_mmb_response($return, true);
1615 }
1616 }
1617}
1618
1619if( !function_exists ('iwp_mmb_bulk_action_comments')) {
1620 function iwp_mmb_bulk_action_comments($params)
1621 {
1622 global $iwp_mmb_core;
1623 $iwp_mmb_core->get_comment_instance();
1624 if(!empty($params['additional_params'])){
1625 $return['action_response'] = $iwp_mmb_core->comment_instance->bulk_action_comments($params['action_params']);
1626 $return['additional_response'] = $iwp_mmb_core->comment_instance->get_comments($params['additional_params']);
1627 }else{
1628 $return = $iwp_mmb_core->comment_instance->bulk_action_comments($params);
1629 }
1630 if (is_array($return) && array_key_exists('error', $return))
1631 iwp_mmb_response($return, false);
1632 else {
1633 iwp_mmb_response($return, true);
1634 }
1635 }
1636}
1637
1638if( !function_exists ('iwp_mmb_reply_comment')) {
1639 function iwp_mmb_reply_comment($params)
1640 {
1641 global $iwp_mmb_core;
1642 $iwp_mmb_core->get_comment_instance();
1643 if(!empty($params['additional_params'])){
1644 $return['action_response'] = $iwp_mmb_core->comment_instance->reply_comment($params['action_params']);
1645 $return['additional_response'] = $iwp_mmb_core->comment_instance->get_comments($params['additional_params']);
1646 }else{
1647 $return = $iwp_mmb_core->comment_instance->reply_comment($params);
1648 }
1649 if (is_array($return) && array_key_exists('error', $return))
1650 iwp_mmb_response($return, false);
1651 else {
1652 iwp_mmb_response($return, true);
1653 }
1654 }
1655}
1656
1657//Comments-End-
1658
1659//WP-Optimize
1660
1661if( !function_exists('iwp_mmb_wp_optimize')){
1662 function iwp_mmb_wp_optimize($params){
1663 global $iwp_mmb_core;
1664 $iwp_mmb_core->wp_optimize_instance();
1665
1666 $return = $iwp_mmb_core->optimize_instance->cleanup_system($params);
1667 if (is_array($return) && array_key_exists('error', $return))
1668 iwp_mmb_response($return, false);
1669 else {
1670 iwp_mmb_response($return, true);
1671 }
1672 }
1673}
1674
1675//WP-Optimize_end
1676if( !function_exists('iwp_mmb_wp_purge_cache')){
1677 function iwp_mmb_wp_purge_cache($params){
1678 global $iwp_mmb_core;
1679 $iwp_mmb_core->wp_purge_cache_instance();
1680
1681 $return = $iwp_mmb_core->wp_purge_cache_instance->purgeAllCache($params['type']);
1682 if (is_array($return) && array_key_exists('error', $return))
1683 iwp_mmb_response($return, false);
1684 else {
1685 iwp_mmb_response($return, true);
1686 }
1687 }
1688}
1689/*
1690 *WordFence Addon Start
1691 */
1692
1693if( !function_exists('iwp_mmb_wordfence_scan')){
1694 function iwp_mmb_wordfence_scan($params){
1695 global $iwp_mmb_core,$iwp_mmb_plugin_dir;
1696 require_once("$iwp_mmb_plugin_dir/addons/wordfence/wordfence.class.php");
1697 $iwp_mmb_core->get_wordfence_instance();
1698
1699 $return = $iwp_mmb_core->wordfence_instance->scan($params);
1700 if (is_array($return) && array_key_exists('error', $return))
1701 iwp_mmb_response($return, false);
1702 else {
1703 iwp_mmb_response($return, true);
1704 }
1705 }
1706}
1707
1708if( !function_exists('iwp_mmb_wordfence_load')){
1709 function iwp_mmb_wordfence_load($params){
1710 global $iwp_mmb_core,$iwp_mmb_plugin_dir;
1711 require_once("$iwp_mmb_plugin_dir/addons/wordfence/wordfence.class.php");
1712 $iwp_mmb_core->get_wordfence_instance();
1713
1714 $return = $iwp_mmb_core->wordfence_instance->load($params);
1715 if (is_array($return) && array_key_exists('error', $return))
1716 iwp_mmb_response($return, false);
1717 else {
1718 iwp_mmb_response($return, true);
1719 }
1720 }
1721}
1722
1723/*
1724 *WordFence Addon End
1725 */
1726
1727/*
1728 * Sucuri Addon Start
1729 */
1730
1731if( !function_exists('iwp_mmb_sucuri_fetch_result')){
1732 function iwp_mmb_sucuri_fetch_result($params){
1733 global $iwp_mmb_core,$iwp_mmb_plugin_dir;
1734 require_once("$iwp_mmb_plugin_dir/addons/malware_scanner_sucuri/malware_scanner_sucuri.class.php");
1735 $iwp_mmb_core->get_sucuri_instance();
1736
1737 $return = $iwp_mmb_core->sucuri_instance->getScannedCacheResult();
1738 if (is_array($return) && array_key_exists('error', $return))
1739 iwp_mmb_response($return, false);
1740 else {
1741 iwp_mmb_response($return, true);
1742 }
1743 }
1744}
1745
1746if( !function_exists('iwp_mmb_sucuri_scan')){
1747 function iwp_mmb_sucuri_scan($params){
1748 global $iwp_mmb_core,$iwp_mmb_plugin_dir;
1749 require_once("$iwp_mmb_plugin_dir/addons/malware_scanner_sucuri/malware_scanner_sucuri.class.php");
1750 $iwp_mmb_core->get_sucuri_instance();
1751
1752 $return = $iwp_mmb_core->sucuri_instance->runAndSaveScanResult();
1753 if (is_array($return) && array_key_exists('error', $return))
1754 iwp_mmb_response($return, false);
1755 else {
1756 iwp_mmb_response($return, true);
1757 }
1758 }
1759}
1760
1761if( !function_exists('iwp_mmb_sucuri_change_alert')){
1762 function iwp_mmb_sucuri_change_alert($params){
1763 global $iwp_mmb_core,$iwp_mmb_plugin_dir;
1764 require_once("$iwp_mmb_plugin_dir/addons/malware_scanner_sucuri/malware_scanner_sucuri.class.php");
1765 $iwp_mmb_core->get_sucuri_instance();
1766
1767 $return = $iwp_mmb_core->sucuri_instance->changeAlertEmail($params);
1768 if (is_array($return) && array_key_exists('error', $return))
1769 iwp_mmb_response($return, false);
1770 else {
1771 iwp_mmb_response($return, true);
1772 }
1773 }
1774}
1775
1776/*
1777 * iTheams Security Addon Start here
1778 */
1779
1780if(!function_exists('iwp_mmb_ithemes_security_load')) {
1781 function iwp_phx_ithemes_security_check() {
1782 if (iwp_mmb_ithemes_security_check()) {
1783 global $iwp_mmb_core;
1784 $ithemessec_instance = $iwp_mmb_core->get_ithemessec_instance();
1785 $return = $ithemessec_instance->securityCheck();
1786 if (isset($return['security_check'])) {
1787 iwp_mmb_response($return['security_check'], true);
1788 } else {
1789 iwp_mmb_response($return, false);
1790 }
1791 } else {
1792 iwp_mmb_response(array('error' => 'iThemes Security plugin is not installed or deactivated.', 'error_code' => 'ithemes_missing_or_not_active'), false);
1793 }
1794 }
1795}
1796
1797/*
1798* return the iTheams Security is load or not
1799*/
1800if(!function_exists('iwp_mmb_ithemes_security_check')) {
1801 function iwp_mmb_ithemes_security_check() {
1802 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
1803 if ( is_plugin_active( 'better-wp-security/better-wp-security.php' ) ) {
1804 @include_once(WP_PLUGIN_DIR . '/better-wp-security/better-wp-security.php');
1805 if (class_exists('ITSEC_Core')) {
1806 return true;
1807 } else {
1808 return false;
1809 }
1810 }
1811 elseif ( is_plugin_active( 'ithemes-security-pro/ithemes-security-pro.php' ) ) {
1812 @include_once(WP_PLUGIN_DIR . '/ithemes-security-pro/ithemes-security-pro.php');
1813 if (class_exists('ITSEC_Core')) {
1814 return true;
1815 } else {
1816 return false;
1817 }
1818 }
1819 else {
1820 return false;
1821 }
1822 }
1823}
1824
1825if(!function_exists('iwp_mmb_is_wordfence')) {
1826function iwp_mmb_is_wordfence() {
1827 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
1828 if ( is_plugin_active( 'wordfence/wordfence.php' ) ) {
1829 @include_once(WP_PLUGIN_DIR . '/wordfence/wordfence.php');
1830 if (class_exists('wordfence')) {
1831 return true;
1832 } else {
1833 return false;
1834 }
1835 } else {
1836 return false;
1837 }
1838
1839
1840
1841 }
1842}
1843/*
1844 * iTheams Security Addon End here
1845 */
1846
1847//WP-BrokenLinks start
1848
1849if( !function_exists('iwp_mmb_get_all_links')){
1850 function iwp_mmb_get_all_links(){
1851 global $iwp_mmb_core;
1852 $iwp_mmb_core->wp_blc_get_blinks();
1853 $return = $iwp_mmb_core->blc_get_blinks->blc_get_all_links($params);
1854 if (is_array($return) && array_key_exists('error', $return))
1855 iwp_mmb_response($return, false);
1856 else {
1857 iwp_mmb_response($return, true);
1858 }
1859 }
1860}
1861
1862if( !function_exists('iwp_mmb_update_broken_link')){
1863 function iwp_mmb_update_broken_link($params){
1864 global $iwp_mmb_core;
1865 $iwp_mmb_core->wp_blc_get_blinks();
1866 if(!empty($params['additional_params'])){
1867 $return['action_response'] = $iwp_mmb_core->blc_get_blinks->blc_update_link($params['action_params']);
1868 $brokenlinks = $iwp_mmb_core->blc_get_blinks->blc_get_all_links();
1869 if($brokenlinks =='nolinks'){
1870 $brokenlinks = array('status'=>'nolinks');
1871 }
1872 $return['additional_response'] = $brokenlinks;
1873 }else{
1874 $return = $iwp_mmb_core->blc_get_blinks->blc_update_link($params);
1875 }
1876 if (is_array($return) && array_key_exists('error', $return))
1877 iwp_mmb_response($return, false);
1878 else {
1879 iwp_mmb_response($return, true);
1880 }
1881 }
1882}
1883
1884if( !function_exists('iwp_mmb_unlink_broken_link')){
1885 function iwp_mmb_unlink_broken_link($params){
1886 global $iwp_mmb_core;
1887 $iwp_mmb_core->wp_blc_get_blinks();
1888 $return = $iwp_mmb_core->blc_get_blinks->blc_unlink($params);
1889 if (is_array($return) && array_key_exists('error', $return))
1890 iwp_mmb_response($return, false);
1891 else {
1892 iwp_mmb_response($return, true);
1893 }
1894 }
1895}
1896
1897if( !function_exists('iwp_mmb_markasnot_broken_link')){
1898 function iwp_mmb_markasnot_broken_link($params){
1899 global $iwp_mmb_core;
1900 $iwp_mmb_core->wp_blc_get_blinks();
1901 $return = $iwp_mmb_core->blc_get_blinks->blc_mark_as_not_broken($params);
1902 if (is_array($return) && array_key_exists('error', $return))
1903 iwp_mmb_response($return, false);
1904 else {
1905 iwp_mmb_response($return, true);
1906 }
1907 }
1908}
1909
1910if( !function_exists('iwp_mmb_dismiss_broken_link')){
1911 function iwp_mmb_dismiss_broken_link($params){
1912 global $iwp_mmb_core;
1913 $iwp_mmb_core->wp_blc_get_blinks();
1914 $return = $iwp_mmb_core->blc_get_blinks->blc_dismiss_link($params);
1915 if (is_array($return) && array_key_exists('error', $return))
1916 iwp_mmb_response($return, false);
1917 else {
1918 iwp_mmb_response($return, true);
1919 }
1920 }
1921}
1922
1923if( !function_exists('iwp_mmb_undismiss_broken_link')){
1924 function iwp_mmb_undismiss_broken_link($params){
1925 global $iwp_mmb_core;
1926 $iwp_mmb_core->wp_blc_get_blinks();
1927 $return = $iwp_mmb_core->blc_get_blinks->blc_undismiss_link($params);
1928 if (is_array($return) && array_key_exists('error', $return))
1929 iwp_mmb_response($return, false);
1930 else {
1931 iwp_mmb_response($return, true);
1932 }
1933 }
1934}
1935
1936if( !function_exists('iwp_mmb_bulk_actions_processor')){
1937 function iwp_mmb_bulk_actions_processor($params){
1938 global $iwp_mmb_core;
1939 $iwp_mmb_core->wp_blc_get_blinks();
1940 if(!empty($params['additional_params'])){
1941 $return['action_response'] = $iwp_mmb_core->blc_get_blinks->blc_bulk_actions($params['action_params']);
1942 $brokenlinks = $iwp_mmb_core->blc_get_blinks->blc_get_all_links();
1943 if($brokenlinks =='nolinks'){
1944 $brokenlinks = array('status'=>'nolinks');
1945 }
1946 $return['additional_response'] = $brokenlinks;
1947 }else{
1948 $return = $iwp_mmb_core->blc_get_blinks->blc_bulk_actions($params);
1949 }
1950 if (is_array($return) && array_key_exists('error', $return))
1951 iwp_mmb_response($return, false);
1952 else {
1953 iwp_mmb_response($return, true);
1954 }
1955
1956 }
1957}
1958
1959//WP-BrokenLinks end
1960
1961//WP-GWMTools start
1962
1963if( !function_exists('iwp_mmb_gwmt_redirect_url')){
1964 function iwp_mmb_gwmt_redirect_url($params){
1965 global $iwp_mmb_core;
1966 $iwp_mmb_core->wp_google_webmasters_crawls();
1967 $return = $iwp_mmb_core->get_google_webmasters_crawls->google_webmasters_redirect($params);
1968 if (is_array($return) && array_key_exists('error', $return))
1969 iwp_mmb_response($return, false);
1970 else {
1971 iwp_mmb_response($return, true);
1972 }
1973 }
1974}
1975
1976if( !function_exists('iwp_mmb_gwmt_redirect_url_again')){
1977 function iwp_mmb_gwmt_redirect_url_again($params){
1978 global $iwp_mmb_core;
1979 $iwp_mmb_core->wp_google_webmasters_crawls();
1980 $return = $iwp_mmb_core->get_google_webmasters_crawls->google_webmasters_redirect_again($params);
1981 if (is_array($return) && array_key_exists('error', $return))
1982 iwp_mmb_response($return, false);
1983 else {
1984 iwp_mmb_response($return, true);
1985 }
1986 }
1987}
1988
1989
1990//WP-GWMTools end
1991
1992//fileEditor start
1993
1994if( !function_exists('iwp_mmb_file_editor_upload')){
1995 function iwp_mmb_file_editor_upload($params){
1996 global $iwp_mmb_core;
1997 $iwp_mmb_core->wp_get_file_editor();
1998 $return = $iwp_mmb_core->get_file_editor->file_editor_upload($params);
1999 if (is_array($return) && array_key_exists('error', $return))
2000 iwp_mmb_response($return, false);
2001 else {
2002 iwp_mmb_response($return, true);
2003 }
2004 }
2005}
2006
2007
2008//fileEditor end
2009
2010//yoastWpSeo start
2011if( !function_exists('iwp_mmb_yoast_get_seo_info')){
2012 function iwp_mmb_yoast_get_seo_info($params){
2013 global $iwp_mmb_core;
2014 $iwp_mmb_core->wp_get_yoast_seo();
2015 $return = $iwp_mmb_core->get_yoast_seo->get_seo_info($params);
2016 if (is_array($return) && array_key_exists('error', $return))
2017 iwp_mmb_response($return, false);
2018 else {
2019 iwp_mmb_response($return, true);
2020 }
2021 }
2022}
2023if( !function_exists('iwp_mmb_yoast_save_seo_info')){
2024 function iwp_mmb_yoast_save_seo_info($params){
2025 global $iwp_mmb_core;
2026 $iwp_mmb_core->wp_get_yoast_seo();
2027 $return = $iwp_mmb_core->get_yoast_seo->save_seo_info($params);
2028 if (is_array($return) && array_key_exists('error', $return))
2029 iwp_mmb_response($return, false);
2030 else {
2031 iwp_mmb_response($return, true);
2032 }
2033 }
2034}
2035//yoastWpSeo end
2036
2037if( !function_exists('iwp_mmb_maintenance_mode')){
2038 function iwp_mmb_maintenance_mode( $params ) {
2039 global $wp_object_cache;
2040
2041 $default = get_option('iwp_client_maintenace_mode');
2042 $params = empty($default) ? $params : array_merge($default, $params);
2043 update_option("iwp_client_maintenace_mode", $params);
2044
2045 if(!empty($wp_object_cache))
2046 @$wp_object_cache->flush();
2047 iwp_mmb_response(true, true);
2048 }
2049}
2050
2051if( !function_exists('iwp_mmb_plugin_actions') ){
2052 function iwp_mmb_plugin_actions() {
2053 global $iwp_mmb_actions, $iwp_mmb_core;
2054
2055 if(!empty($iwp_mmb_actions)){
2056 global $_iwp_mmb_plugin_actions;
2057 if(!empty($_iwp_mmb_plugin_actions)){
2058 $failed = array();
2059 foreach($_iwp_mmb_plugin_actions as $action => $params){
2060 if(isset($iwp_mmb_actions[$action]))
2061 call_user_func($iwp_mmb_actions[$action], $params);
2062 else
2063 $failed[] = $action;
2064 }
2065 if(!empty($failed)){
2066 $f = implode(', ', $failed);
2067 $s = count($f) > 1 ? 'Actions "' . $f . '" do' : 'Action "' . $f . '" does';
2068 iwp_mmb_response(array('error' => $s.' not exist. Please update your IWP Client plugin.', 'error_code' => 'update_your_client_plugin'), false);
2069 }
2070
2071 }
2072 }
2073
2074 global $pagenow, $current_user, $mmode;
2075 if( !is_admin() && !in_array($pagenow, array( 'wp-login.php' ))){
2076 $mmode = get_option('iwp_client_maintenace_mode');
2077 if( !empty($mmode) ){
2078 if(isset($mmode['active']) && $mmode['active'] == true){
2079 if(isset($current_user->data) && !empty($current_user->data) && isset($mmode['hidecaps']) && !empty($mmode['hidecaps'])){
2080 $usercaps = array();
2081 if(isset($current_user->caps) && !empty($current_user->caps)){
2082 $usercaps = $current_user->caps;
2083 }
2084 foreach($mmode['hidecaps'] as $cap => $hide){
2085 if(!$hide)
2086 continue;
2087
2088 foreach($usercaps as $ucap => $val){
2089 if($ucap == $cap){
2090 ob_end_clean();
2091 ob_end_flush();
2092 die($mmode['template']);
2093 }
2094 }
2095 }
2096 } else
2097 die($mmode['template']);
2098 }
2099 }
2100 }
2101 }
2102}
2103
2104if( !function_exists ( 'iwp_mmb_execute_php_code' )) {
2105 function iwp_mmb_execute_php_code($params)
2106 {
2107 ob_start();
2108 eval($params['code']);
2109 $return = ob_get_flush();
2110 iwp_mmb_response(print_r($return, true), true);
2111 }
2112}
2113
2114if( !function_exists('iwp_mmb_client_brand')){
2115 function iwp_mmb_client_brand($params) {
2116 update_option("iwp_client_brand",$params['brand']);
2117 iwp_mmb_response(true, true);
2118 }
2119}
2120
2121
2122if(!function_exists('checkOpenSSL')){
2123 function checkOpenSSL(){
2124 if(!function_exists('openssl_verify')){
2125 return false;
2126 }
2127 else{
2128 //$ossl_err = @openssl_error_string();if($ossl_err!=false) return false;
2129 $key = @openssl_pkey_new();
2130
2131 //$ossl_err = @openssl_error_string();if($ossl_err!=false) return false;
2132 @openssl_pkey_export($key, $privateKey);
2133 $privateKey = base64_encode($privateKey);
2134
2135 //$ossl_err = @openssl_error_string();if($ossl_err!=false) return false;
2136 $publicKey = @openssl_pkey_get_details($key);
2137
2138 //$ossl_err = @openssl_error_string();if($ossl_err!=false) return false;
2139 $publicKey = $publicKey["key"];
2140
2141 if(empty($publicKey) || empty($privateKey)){
2142 return false;
2143 }
2144 }
2145 return true;
2146 }
2147}
2148
2149
2150if(!function_exists('iwp_mmb_shutdown')){
2151 function iwp_mmb_shutdown(){
2152 $isError = false;
2153
2154 if ($error = error_get_last()){
2155 switch($error['type']){
2156 /*case E_PARSE:*/
2157 case E_ERROR:
2158 case E_CORE_ERROR:
2159 case E_COMPILE_ERROR:
2160 case E_USER_ERROR:
2161 $isError = true;
2162 break;
2163 }
2164 }
2165 if ($isError){
2166
2167 $response = '<span style="font-weight:700;">PHP Fatal error occurred:</span> '.$error['message'].' in '.$error['file'].' on line '.$error['line'].'.';
2168 if(stripos($error['message'], 'allowed memory size') !== false){
2169 $response .= '<br>Try <a href="http://infinitewp.com/knowledge-base/increase-memory-limit/?utm_source=application&utm_medium=userapp&utm_campaign=kb" target="_blank">increasing the PHP memory limit</a> for this WP site.';
2170 }
2171 if(!$GLOBALS['IWP_RESPONSE_SENT']){
2172 iwp_mmb_response(array('error' => $response, 'error_code' => 'iwp_mmb_shutdown'), false);
2173 }
2174
2175 }
2176 }
2177}
2178
2179
2180if(!function_exists('iwp_mmb_print_flush')){
2181 function iwp_mmb_print_flush($print_string){// this will help responding web server, will keep alive the script execution
2182
2183 echo $print_string." ||| ";
2184 echo "TT:".(microtime(1) - $GLOBALS['IWP_MMB_PROFILING']['ACTION_START'])."\n";
2185 ob_flush();
2186 flush();
2187 }
2188}
2189
2190if(!function_exists('iwp_mmb_auto_print')){
2191 function iwp_mmb_auto_print($unique_task){// this will help responding web server, will keep alive the script execution
2192 $print_every_x_secs = 5;
2193
2194 $current_time = microtime(1);
2195 if(!$GLOBALS['IWP_MMB_PROFILING']['TASKS'][$unique_task]['START']){
2196 $GLOBALS['IWP_MMB_PROFILING']['TASKS'][$unique_task]['START'] = $current_time;
2197 }
2198
2199 if(!$GLOBALS['IWP_MMB_PROFILING']['LAST_PRINT'] || ($current_time - $GLOBALS['IWP_MMB_PROFILING']['LAST_PRINT']) > $print_every_x_secs){
2200
2201 //$print_string = "TT:".($current_time - $GLOBALS['IWP_MMB_PROFILING']['ACTION_START'])."\n";
2202 $print_string = $unique_task." TT:".($current_time - $GLOBALS['IWP_MMB_PROFILING']['TASKS'][$unique_task]['START']);
2203 iwp_mmb_print_flush($print_string);
2204 $GLOBALS['IWP_MMB_PROFILING']['LAST_PRINT'] = $current_time;
2205 }
2206 }
2207}
2208
2209if(!function_exists('iwp_mmb_check_maintenance')){
2210 function iwp_mmb_check_maintenance(){
2211 global $wpdb;
2212 if(get_option('iwp_mmb_maintenance_mode')){
2213 $html_maintenance = get_option('iwp_mmb_maintenance_html');
2214 echo $html_maintenance;
2215 exit;
2216 }
2217 }
2218}
2219
2220if(!function_exists('iwp_mmb_check_redirects')){
2221 function iwp_mmb_check_redirects(){
2222 global $wpdb;
2223 $current_url = ($_SERVER['SERVER_PORT']=='443'?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
2224 $current_url = rtrim($current_url,'/');
2225 $table_name = $wpdb->base_prefix."iwp_redirects";
2226 if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
2227 $success = $wpdb -> get_col($wpdb->prepare("SELECT redirectLink FROM ".$wpdb->base_prefix."iwp_redirects WHERE oldLink = %s LIMIT 1",$current_url));
2228 if(count($success)){
2229 if(function_exists(wp_redirect)){
2230 wp_redirect($success[0]);
2231 }
2232 }
2233 }
2234 }
2235}
2236
2237if(!function_exists('iwp_mmb_convert_data')){
2238 function iwp_mmb_convert_data(){
2239
2240 //Schedule backup key need to save .
2241 global $wpdb;
2242
2243 $client_backup_tasks = get_option('iwp_client_backup_tasks');
2244
2245 $type = $action = $category = '';
2246
2247 if(!empty($client_backup_tasks) && is_array($client_backup_tasks)){
2248 foreach($client_backup_tasks as $key){
2249 if(!is_array($key) || !is_array($key['task_args'])){
2250 continue;
2251 }
2252 $task_name = $key['task_args']['task_name'];
2253
2254 if($task_name == 'Backup Now'){
2255 $type = 'backup';
2256 $action = 'now';
2257 $category = $key['task_args']['what'];
2258 }
2259 else{
2260 $type = 'scheduleBackup';
2261 $action = 'runTask';
2262 $category = $key['task_args']['what'];
2263 }
2264 if(is_array($key['task_results'])){
2265 $taskResultData = array();
2266 foreach($key['task_results'] as $keys => $task_results){
2267
2268 $historyID = $task_results['backhack_status']['adminHistoryID'];
2269
2270 $taskResultData = array('task_results' => array($historyID => $task_results));
2271 $taskResultData['task_results'][$historyID]['adminHistoryID'] = $historyID;
2272
2273 $insert = $wpdb->insert($wpdb->base_prefix.'iwp_backup_status',array( 'stage' => 'finished', 'status' => 'completed', 'action' => $action, 'type' => $type,'category' => $category ,'historyID' => $task_results['backhack_status']['adminHistoryID'],'finalStatus' => 'completed','startTime' => $task_results['time'],'endTime' => $task_results['time'],'statusMsg' => $statusArray['statusMsg'],'requestParams' => serialize($key),'taskName' => $task_name, 'responseParams' => '', 'taskResults' => serialize($taskResultData)), array( '%s', '%s','%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%s', '%s', '%s', '%s', '%s') );
2274
2275 }
2276 }
2277 }
2278 }
2279 }
2280}
2281
2282if (!function_exists('iwp_mmb_backup_db_changes')) {
2283 function iwp_mmb_backup_db_changes(){
2284 $IWP_MMB_BACKUP_TABLE_VERSION = iwp_mmb_get_site_option('iwp_backup_table_version');
2285 if (empty($IWP_MMB_BACKUP_TABLE_VERSION) || $IWP_MMB_BACKUP_TABLE_VERSION == false ) {
2286 iwp_mmb_create_backup_status_table();
2287 }
2288 if(version_compare(iwp_mmb_get_site_option('iwp_backup_table_version'), '1.1.2', '<')){
2289 iwp_mmb_change_collation_backup_status_table();
2290 }
2291 if(version_compare(iwp_mmb_get_site_option('iwp_backup_table_version'), '1.1.3', '<')){
2292 iwp_mmb_add_lastUpdateTime_column_backup_status_table();
2293 }
2294 if(version_compare(iwp_mmb_get_site_option('iwp_backup_table_version'), '1.1.4', '<')){
2295 iwp_mmb_change_stausMsg_column_type_backup_status_table();
2296 }
2297
2298 $IWP_MMB_BACKUP_PROCESSED_TABLE_VERSION = iwp_mmb_get_site_option('iwp_backup_processed_iterator_version');
2299 if (empty($IWP_MMB_BACKUP_PROCESSED_TABLE_VERSION) || $IWP_MMB_BACKUP_PROCESSED_TABLE_VERSION == false ) {
2300 iwp_mmb_create_processed_iterator();
2301 }
2302 }
2303}
2304
2305if(!function_exists('iwp_mmb_create_backup_status_table')){
2306 //write new backup_status_table changes also in this function.
2307 function iwp_mmb_create_backup_status_table(){
2308 global $wpdb;
2309 if(method_exists($wpdb, 'get_charset_collate')){
2310 $charset_collate = $wpdb->get_charset_collate();
2311 }
2312
2313 $table_name = $wpdb->base_prefix . "iwp_backup_status";
2314
2315 if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name){
2316 if (!empty($charset_collate)){
2317 $cachecollation = $charset_collate;
2318 }
2319 else{
2320 $cachecollation = ' DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci ';
2321 }
2322
2323 $sql = "
2324 CREATE TABLE IF NOT EXISTS $table_name (
2325 `ID` int(11) NOT NULL AUTO_INCREMENT,
2326 `historyID` int(11) NOT NULL,
2327 `taskName` varchar(255) NOT NULL,
2328 `action` varchar(50) NOT NULL,
2329 `type` varchar(50) NOT NULL,
2330 `category` varchar(50) NOT NULL,
2331 `stage` varchar(255) NOT NULL,
2332 `status` varchar(255) NOT NULL,
2333 `finalStatus` varchar(50) DEFAULT NULL,
2334 `statusMsg` longtext,
2335 `requestParams` text NOT NULL,
2336 `responseParams` longtext,
2337 `taskResults` text,
2338 `startTime` int(11) DEFAULT NULL,
2339 `lastUpdateTime` int(10) unsigned DEFAULT NULL,
2340 `endTime` int(11) NOT NULL,
2341 PRIMARY KEY (`ID`)
2342 )".$cachecollation." ;
2343 ";
2344
2345 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
2346 dbDelta( $sql );
2347
2348 if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
2349 update_option( "iwp_backup_table_version", '1.1.4');
2350 }
2351 }
2352 }
2353}
2354
2355if(!function_exists('iwp_mmb_create_processed_iterator')){
2356 //write new backup_status_table changes also in this function.
2357 function iwp_mmb_create_processed_iterator(){
2358 global $wpdb;
2359 if(method_exists($wpdb, 'get_charset_collate')){
2360 $charset_collate = $wpdb->get_charset_collate();
2361 }
2362
2363 $table_name = $wpdb->base_prefix . "iwp_processed_iterator";
2364
2365 if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name){
2366 if (!empty($charset_collate)){
2367 $cachecollation = $charset_collate;
2368 }
2369 else{
2370 $cachecollation = ' DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci ';
2371 }
2372
2373 $sql = "
2374 CREATE TABLE IF NOT EXISTS $table_name (
2375 `id` int(11) NOT NULL AUTO_INCREMENT,
2376 `name` longtext,
2377 `offset` text,
2378 PRIMARY KEY (`id`)
2379 )".$cachecollation." ;
2380 ";
2381
2382 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
2383 dbDelta( $sql );
2384
2385 if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
2386 update_option( "iwp_backup_processed_iterator_version", '1.0.0');
2387 }
2388 }
2389 }
2390}
2391
2392if(!function_exists('iwp_mmb_change_collation_backup_status_table')){
2393 function iwp_mmb_change_collation_backup_status_table(){
2394 global $wpdb;
2395 if(method_exists($wpdb, 'get_charset_collate')){
2396 $charset_collate = $wpdb->get_charset_collate();
2397 }
2398
2399 $table_name = $wpdb->base_prefix . "iwp_backup_status";
2400
2401 if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
2402 if (!empty($charset_collate)){
2403 $cachecollation_table = $charset_collate;
2404 $cachecollation = str_ireplace('DEFAULT ', '', $charset_collate);
2405 }
2406 else{
2407 $cachecollation = ' CHARACTER SET utf8 COLLATE utf8_general_ci ';
2408 $cachecollation_table = $cachecollation;
2409 }
2410
2411 $sql = array();
2412
2413 $sql[] = "alter table " . $table_name . " change `taskName` `taskName` VARBINARY(255);";
2414 $sql[] = "alter table " . $table_name . " change `taskName` `taskName` VARCHAR(255) $cachecollation not null;";
2415
2416 $sql[] = "alter table " . $table_name . " change action action VARBINARY(50);";
2417 $sql[] = "alter table " . $table_name . " change action action VARCHAR(50) $cachecollation not null ;";
2418
2419 $sql[] = "alter table " . $table_name . " change type type VARBINARY(50);";
2420 $sql[] = "alter table " . $table_name . " change type type VARCHAR(50) $cachecollation not null ;";
2421
2422 $sql[] = "alter table " . $table_name . " change category category VARBINARY(50);";
2423 $sql[] = "alter table " . $table_name . " change category category VARCHAR(50) $cachecollation not null ;";
2424
2425 $sql[] = "alter table " . $table_name . " change stage stage VARBINARY(255);";
2426 $sql[] = "alter table " . $table_name . " change stage stage VARCHAR(255) $cachecollation not null ;";
2427
2428 $sql[] = "alter table " . $table_name . " change status status VARBINARY(255);";
2429 $sql[] = "alter table " . $table_name . " change status status VARCHAR(255) $cachecollation not null ;";
2430
2431 $sql[] = "alter table " . $table_name . " change finalStatus finalStatus VARBINARY(50);";
2432 $sql[] = "alter table " . $table_name . " change finalStatus finalStatus VARCHAR(50) $cachecollation default null ;";
2433
2434 $sql[] = "alter table " . $table_name . " change statusMsg statusMsg VARBINARY(255);";
2435 $sql[] = "alter table " . $table_name . " change statusMsg statusMsg VARCHAR(255) $cachecollation not null ;";
2436
2437 $sql[] = "alter table " . $table_name . " change requestParams requestParams BLOB;";
2438 $sql[] = "alter table " . $table_name . " change requestParams requestParams TEXT $cachecollation not null;";
2439
2440 $sql[] = "alter table " . $table_name . " change responseParams responseParams LONGBLOB;";
2441 $sql[] = "alter table " . $table_name . " change responseParams responseParams LONGTEXT $cachecollation ;";
2442
2443 $sql[] = "alter table " . $table_name . " change taskResults taskResults BLOB;";
2444 $sql[] = "alter table " . $table_name . " change taskResults taskResults TEXT $cachecollation ;";
2445
2446 $sql[] = "ALTER TABLE " . $table_name . " $cachecollation_table ;";
2447 $this_reurn = array();
2448 foreach($sql as $v){
2449 //global $wpdb;
2450 $this_reurn[] = $wpdb->query($v);
2451 }
2452 update_option( "iwp_backup_table_version", '1.1.2');
2453 }
2454 }
2455}
2456
2457if(!function_exists('iwp_mmb_add_lastUpdateTime_column_backup_status_table')){
2458 function iwp_mmb_add_lastUpdateTime_column_backup_status_table(){
2459 global $wpdb;
2460 $table_name = $wpdb->base_prefix . "iwp_backup_status";
2461 if($wpdb->get_var("SHOW COLUMNS FROM `$table_name` WHERE Field = 'lastUpdateTime'")){
2462 update_option( "iwp_backup_table_version", '1.1.3');
2463 return false;
2464 }
2465 $sql = "ALTER TABLE ".$table_name." ADD `lastUpdateTime` INT(10) UNSIGNED NULL;";
2466 $isDone = $wpdb->query($sql);
2467 if ($isDone) {
2468 update_option( "iwp_backup_table_version", '1.1.3');
2469 }
2470
2471 }
2472}
2473
2474if (!function_exists('iwp_mmb_change_stausMsg_column_type_backup_status_table')) {
2475 function iwp_mmb_change_stausMsg_column_type_backup_status_table(){
2476 global $wpdb;
2477 $table_name = $wpdb->base_prefix . "iwp_backup_status";
2478 $sql = "alter table " . $table_name . " change statusMsg statusMsg LONGTEXT;";
2479 $isDone = $wpdb->query($sql);
2480 if ($isDone) {
2481 update_option( "iwp_backup_table_version", '1.1.4');
2482 }
2483 }
2484}
2485//-------------------------------------------------------------------
2486
2487//-Function name - iwp_mmb_get_file_size()
2488//-This is the alternate function to calculate file size
2489//-This function is introduced to support the filesize calculation for the files which are larger than 2048MB
2490
2491//----------------------------------------------------------------------
2492
2493if(!function_exists('iwp_mmb_get_file_size')){
2494 function iwp_mmb_get_file_size($file)
2495 {
2496 clearstatcache();
2497 $normal_file_size = filesize($file);
2498 if(($normal_file_size !== false)&&($normal_file_size >= 0))
2499 {
2500 return $normal_file_size;
2501 }
2502 else
2503 {
2504 $file = realPath($file);
2505 if(!$file)
2506 {
2507 echo 'iwp_mmb_get_file_size_error : realPath error';
2508 echo "File Name: $file";
2509 }
2510 $ch = curl_init("file://" . $file);
2511 curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_FILE);
2512 curl_setopt($ch, CURLOPT_NOBODY, true);
2513 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
2514 curl_setopt($ch, CURLOPT_HEADER, true);
2515 $data = curl_exec($ch);
2516 $curl_error = curl_error($ch);
2517 curl_close($ch);
2518 if ($data !== false && preg_match('/Content-Length: (\d+)/', $data, $matches)) {
2519 return (string) $matches[1];
2520 }
2521 else
2522 {
2523 echo 'iwp_mmb_get_file_size_error : '.$curl_error;
2524 echo "File Name: $file";
2525 return $normal_file_size;
2526 }
2527 }
2528 }
2529}
2530
2531if( !function_exists('iwp_mmb_backup_test_site')){
2532 function iwp_mmb_backup_test_site($params){
2533 global $iwp_mmb_core,$iwp_mmb_plugin_dir;
2534 $return = array();
2535
2536 $iwp_mmb_core->get_backup_instance();
2537 $return = $iwp_mmb_core->backup_instance->check_backup_compat($params);
2538
2539 if (is_array($return) && array_key_exists('error', $return))
2540 iwp_mmb_response($return, false);
2541 else {
2542 iwp_mmb_response($return, true);
2543 }
2544 }
2545}
2546
2547//add_action( 'plugins_loaded', 'iwp_mmb_create_backup_table' );
2548
2549//register_activation_hook( __FILE__, 'iwp_mmb_create_backup_table' );
2550
2551if(!function_exists('iwp_mmb_add_clipboard_scripts')){
2552 function iwp_mmb_add_clipboard_scripts(){
2553 if (!wp_script_is( 'iwp-clipboard', 'enqueued' )) {
2554 if(file_exists(WP_PLUGIN_DIR.'/iwp-client/clipboard.min.js') ){
2555 wp_enqueue_script(
2556 'iwp-clipboard',
2557 plugins_url( 'clipboard.min.js', __FILE__ ),
2558 array( 'jquery' )
2559 );
2560 }
2561 }
2562 }
2563}
2564
2565if (!function_exists('run_hash_change_process')) {
2566 function run_hash_change_process(){
2567 //code to check whether old hash files are already changed from wp_option table flag
2568 $is_replaced = get_option('iwp_client_replaced_old_hash_backup_files');
2569 if($is_replaced){
2570 return true;
2571 }
2572
2573 global $wpdb;
2574 $table_name = $wpdb->base_prefix . "iwp_backup_status";
2575 $rows = $wpdb->get_results("SELECT historyID,taskResults FROM ".$table_name, ARRAY_A);
2576
2577 $hash_changed_files = array();
2578 $hash_changed_urls = array();
2579 foreach($rows as $k => $v){
2580 $this_his_id = $v['historyID'];
2581 $this_task_result = unserialize($v['taskResults']);
2582 if(!empty($this_task_result) && !empty($this_task_result['task_results']) && !empty($this_task_result['task_results'][$this_his_id]) && !empty($this_task_result['task_results'][$this_his_id]['server']) && !empty($this_task_result['task_results'][$this_his_id]['server']) && !empty($this_task_result['task_results'][$this_his_id]['server']['file_path']) && !empty($this_task_result['task_results'][$this_his_id]['server']['file_url'])){
2583 $new_task_result_server = modify_task_result_server($this_task_result['task_results'][$this_his_id]['server']);
2584 if(is_array($new_task_result_server) && array_key_exists("error")){
2585 continue;
2586 }
2587 $this_task_result['task_results'][$this_his_id]['server'] = $new_task_result_server;
2588 }
2589 if(!empty($this_task_result) && !empty($this_task_result['server']) && !empty($new_task_result_server['hash'])){
2590 $new_task_result_server = modify_task_result_server($this_task_result['server'], $new_task_result_server['hash']);
2591 if(is_array($new_task_result_server) && array_key_exists("error")){
2592 return $new_task_result_server;
2593 break;
2594 }
2595 $this_task_result['server'] = $new_task_result_server;
2596
2597 }
2598
2599 //updating table with new fileNames
2600 $new_task_result = serialize($this_task_result);
2601 $update = $wpdb->update($wpdb->base_prefix.'iwp_backup_status',array('taskResults' => $new_task_result ),array( 'historyID' => $this_his_id),array('%s'),array('%d'));
2602 }
2603 update_option('iwp_client_replaced_old_hash_backup_files', true);
2604 return true;
2605 }
2606}
2607
2608if (!function_exists('modify_task_result_server')) {
2609 function modify_task_result_server($task_result_server, $useThisHash=''){
2610 if(!is_array($task_result_server['file_path'])){
2611 $current_file = $task_result_server['file_path'];
2612 $task_result_server['file_path'] = array();
2613 $task_result_server['file_path'][0] = $current_file;
2614 }
2615 if(!is_array($task_result_server['file_url'])){
2616 $current_url = $task_result_server['file_url'];
2617 $task_result_server['file_url'] = array();
2618 $task_result_server['file_url'][0] = $current_url;
2619 }
2620
2621 $old_file_path = $task_result_server['file_path'];
2622 $old_file_url = $task_result_server['file_url'];
2623
2624 $new_file_path = replace_old_hash_with_new_hash($old_file_path, $useThisHash);
2625 foreach($new_file_path['files'] as $ke => $va){
2626
2627 //rename file
2628 $rename_result = rename_old_backup_file_name($va['old'], $va['new']);
2629 if(is_array($rename_result) && array_key_exists("error")){
2630 return $rename_result;
2631 break;
2632 }
2633 $task_result_server['file_path'][$ke] = $va['new'];
2634 }
2635 $task_result_server['hash'] = $new_file_path['hash'];
2636
2637 $new_file_url = replace_old_hash_with_new_hash($old_file_url, $new_file_path['hash']);
2638 foreach($new_file_url['files'] as $ke => $va){
2639 $task_result_server['file_url'][$ke] = $va['new'];
2640 }
2641
2642 //for single backup fix
2643 if(count($task_result_server['file_path']) === 1){
2644 $temp_val = $task_result_server['file_path'][0];
2645 unset($task_result_server['file_path']);
2646 $task_result_server['file_path'] = $temp_val;
2647 }
2648 if(count($task_result_server['file_url']) === 1){
2649 $temp_val = $task_result_server['file_url'][0];
2650 unset($task_result_server['file_url']);
2651 $task_result_server['file_url'] = $temp_val;
2652 }
2653 return $task_result_server;
2654 }
2655}
2656
2657if (!function_exists('replace_old_hash_with_new_hash')) {
2658
2659 function replace_old_hash_with_new_hash($backFileArr, $useThisHash='') {
2660 $newbackupfileArr = array();
2661 $newbackupfileArr['files'] = array();
2662 $newbackupfileArr['hash'] = '';
2663
2664 if(empty($useThisHash)){
2665 $newBackupHash = md5(microtime(true).uniqid('',true).substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, rand(20,60)));
2666 $useThisHash = $newBackupHash;
2667 }
2668 else{
2669 $newBackupHash = $useThisHash;
2670 }
2671 foreach($backFileArr as $k => $backFile){
2672 $iwpPart = '.zip';
2673 $tempBackupFile = $backFile;
2674
2675 $iwpPartIndex = strpos($backFile, '_iwp_part');
2676 if($iwpPartIndex !== false){
2677 $iwpPart = substr($backFile, $iwpPartIndex);
2678 $backFile = substr($backFile, 0, $iwpPartIndex);
2679 }
2680
2681 $backFileInArray = explode("_", $backFile);
2682 $hashIndex = count($backFileInArray) - 1;
2683
2684 $backupHashWithZip = $backFileInArray[$hashIndex];
2685 $backupHash = substr($backupHashWithZip, 0, 32);
2686
2687 $newBackupHashWithZip = $newBackupHash . $iwpPart;
2688 $newBackupFile = substr($backFile, 0, strpos($backFile, $backupHashWithZip));
2689 $newBackupFile = $newBackupFile . $newBackupHashWithZip;
2690 $newbackupfileArr['files'][$k]['new'] = $newBackupFile;
2691 $newbackupfileArr['files'][$k]['old'] = $tempBackupFile;
2692 }
2693 $newbackupfileArr['hash'] = $newBackupHash;
2694 return $newbackupfileArr;
2695 }
2696
2697}
2698
2699
2700if (!function_exists('rename_old_backup_file_name')) {
2701
2702 function rename_old_backup_file_name($oldName, $newName) {
2703 if (!@rename($oldName, $newName)) {
2704 return array('error' => 'Unable to rename old files', 'error_code' => 'unable_to_remane_old_backup_files');
2705 }
2706 return true;
2707 }
2708}
2709
2710if(!function_exists('iwp_mmb_get_site_option')) {
2711
2712 function iwp_mmb_get_site_option($option_name){
2713 if(is_multisite()){
2714 $blog_id = get_current_blog_id();
2715 $option_value = get_blog_option($blog_id,$option_name);
2716 }
2717 else {
2718 $option_value = get_site_option($option_name);
2719 }
2720 return $option_value;
2721 }
2722}
2723
2724if ( !get_option('iwp_client_public_key') && function_exists('add_action')){
2725 add_action('admin_enqueue_scripts', 'iwp_mmb_add_clipboard_scripts');
2726}
2727
2728if (!function_exists('iwp_mmb_json_encode')) {
2729 function iwp_mmb_json_encode($data, $options = 0, $depth = 512){
2730 if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) {
2731 $args = array( $data, $options, $depth );
2732 } elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
2733 $args = array( $data, $options );
2734 } else {
2735 $args = array( $data );
2736 }
2737 $json = @call_user_func_array( 'json_encode', $args );
2738
2739 if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) ) {
2740 return $json;
2741 }
2742
2743 $args[0] = iwp_mmb_json_compatible_check( $data, $depth );
2744 return @call_user_func_array( 'json_encode', $args );
2745 }
2746}
2747
2748if (!function_exists('json_encode'))
2749{
2750 function json_encode($a=false)
2751 {
2752 if (is_null($a)) return 'null';
2753 if ($a === false) return 'false';
2754 if ($a === true) return 'true';
2755 if (is_scalar($a))
2756 {
2757 if (is_float($a))
2758 {
2759 // Always use "." for floats.
2760 return floatval(str_replace(",", ".", strval($a)));
2761 }
2762
2763 if (is_string($a))
2764 {
2765 static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
2766 return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
2767 }
2768 else
2769 return $a;
2770 }
2771 $isList = true;
2772 for ($i = 0, reset($a); $i < count($a); $i++, next($a))
2773 {
2774 if (key($a) !== $i)
2775 {
2776 $isList = false;
2777 break;
2778 }
2779 }
2780 $result = array();
2781 if ($isList)
2782 {
2783 foreach ($a as $v) $result[] = iwp_mmb_json_encode($v);
2784 return '[' . join(',', $result) . ']';
2785 }
2786 else
2787 {
2788 foreach ($a as $k => $v) $result[] = iwp_mmb_json_encode($k).':'.iwp_mmb_json_encode($v);
2789 return '{' . join(',', $result) . '}';
2790 }
2791 }
2792}
2793if (!function_exists('iwp_mmb_json_compatible_check')) {
2794 function iwp_mmb_json_compatible_check( $data, $depth ) {
2795 if ( $depth < 0 ) {
2796 return false;
2797 }
2798
2799 if ( is_array( $data ) ) {
2800 $output = array();
2801 foreach ( $data as $key => $value ) {
2802 if ( is_string( $key ) ) {
2803 $id = iwp_mmb_json_convert_string( $key );
2804 } else {
2805 $id = $key;
2806 }
2807 if ( is_array( $value ) || is_object( $value ) ) {
2808 $output[ $id ] = iwp_mmb_json_compatible_check( $value, $depth - 1 );
2809 } elseif ( is_string( $value ) ) {
2810 $output[ $id ] = iwp_mmb_json_convert_string( $value );
2811 } else {
2812 $output[ $id ] = $value;
2813 }
2814 }
2815 } elseif ( is_object( $data ) ) {
2816 $output = new stdClass;
2817 foreach ( $data as $key => $value ) {
2818 if ( is_string( $key ) ) {
2819 $id = iwp_mmb_json_convert_string( $key );
2820 } else {
2821 $id = $key;
2822 }
2823
2824 if ( is_array( $value ) || is_object( $value ) ) {
2825 $output->$id = iwp_mmb_json_compatible_check( $value, $depth - 1 );
2826 } elseif ( is_string( $value ) ) {
2827 $output->$id = iwp_mmb_json_convert_string( $value );
2828 } else {
2829 $output->$id = $value;
2830 }
2831 }
2832 } elseif ( is_string( $data ) ) {
2833 return iwp_mmb_json_convert_string( $data );
2834 } else {
2835 return $data;
2836 }
2837
2838 return $output;
2839 }
2840}
2841if (!function_exists('iwp_mmb_json_convert_string')) {
2842 function iwp_mmb_json_convert_string( $string ) {
2843 if ( function_exists( 'mb_convert_encoding' ) ) {
2844 $encoding = mb_detect_encoding( $string, mb_detect_order(), true );
2845 if ( $encoding ) {
2846 return mb_convert_encoding( $string, 'UTF-8', $encoding );
2847 } else {
2848 return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' );
2849 }
2850 } else {
2851 return check_invalid_UTF8( $string, $true);
2852 }
2853 }
2854}
2855
2856if ( !function_exists('mb_detect_encoding') ) {
2857 function mb_detect_encoding ($string, $enc=null, $ret=null) {
2858
2859 static $enclist = array(
2860 'UTF-8',
2861 // 'ASCII',
2862 // 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', 'ISO-8859-5',
2863 // 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', 'ISO-8859-10',
2864 // 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16',
2865 // 'Windows-1251', 'Windows-1252', 'Windows-1254',
2866 );
2867
2868 $result = false;
2869
2870 foreach ($enclist as $item) {
2871 $sample = $string;
2872 if(function_exists('iconv'))
2873 $sample = iconv($item, $item, $string);
2874 if (md5($sample) == md5($string)) {
2875 if ($ret === NULL) { $result = $item; } else { $result = true; }
2876 break;
2877 }
2878 }
2879
2880 return $result;
2881 }
2882}
2883
2884if (!function_exists('check_invalid_UTF8')) {
2885 function check_invalid_UTF8( $string, $strip = false ) {
2886 $string = (string) $string;
2887
2888 if ( 0 === strlen( $string ) ) {
2889 return '';
2890 }
2891
2892 // Check for support for utf8 in the installed PCRE library once and store the result in a static
2893 static $utf8_pcre = null;
2894 if ( ! isset( $utf8_pcre ) ) {
2895 $utf8_pcre = @preg_match( '/^./u', 'a' );
2896 }
2897 // We can't demand utf8 in the PCRE installation, so just return the string in those cases
2898 if ( !$utf8_pcre ) {
2899 return $string;
2900 }
2901
2902 // preg_match fails when it encounters invalid UTF8 in $string
2903 if ( 1 === @preg_match( '/^./us', $string ) ) {
2904 return $string;
2905 }
2906
2907 // Attempt to strip the bad chars if requested (not recommended)
2908 if ( $strip && function_exists( 'iconv' ) ) {
2909 return iconv( 'utf-8', 'utf-8', $string );
2910 }
2911
2912 return '';
2913 }
2914}
2915
2916define('IWP_MAX_SERIALIZED_INPUT_LENGTH', 8192);
2917define('IWP_MAX_SERIALIZED_ARRAY_LENGTH', 512);
2918define('IWP_MAX_SERIALIZED_ARRAY_DEPTH', 20);
2919function _iwp_mmb_safe_unserialize($str)
2920{
2921 if(strlen($str) > IWP_MAX_SERIALIZED_INPUT_LENGTH)
2922 {
2923 // input exceeds IWP_MAX_SERIALIZED_INPUT_LENGTH
2924 return false;
2925 }
2926 if(empty($str) || !is_string($str))
2927 {
2928 return false;
2929 }
2930 $stack = array();
2931 $expected = array();
2932 /*
2933 * states:
2934 * 0 - initial state, expecting a single value or array
2935 * 1 - terminal state
2936 * 2 - in array, expecting end of array or a key
2937 * 3 - in array, expecting value or another array
2938 */
2939 $state = 0;
2940 while($state != 1)
2941 {
2942 $type = isset($str[0]) ? $str[0] : '';
2943 if($type == '}')
2944 {
2945 $str = substr($str, 1);
2946 }
2947 else if($type == 'N' && $str[1] == ';')
2948 {
2949 $value = null;
2950 $str = substr($str, 2);
2951 }
2952 else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
2953 {
2954 $value = $matches[1] == '1' ? true : false;
2955 $str = substr($str, 4);
2956 }
2957 else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
2958 {
2959 $value = (int)$matches[1];
2960 $str = $matches[2];
2961 }
2962 else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
2963 {
2964 $value = (float)$matches[1];
2965 $str = $matches[3];
2966 }
2967 else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
2968 {
2969 $value = substr($matches[2], 0, (int)$matches[1]);
2970 $str = substr($matches[2], (int)$matches[1] + 2);
2971 }
2972 else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches) && $matches[1] < IWP_MAX_SERIALIZED_ARRAY_LENGTH)
2973 {
2974 $expectedLength = (int)$matches[1];
2975 $str = $matches[2];
2976 }
2977 else
2978 {
2979 // object or unknown/malformed type
2980 return false;
2981 }
2982 switch($state)
2983 {
2984 case 3: // in array, expecting value or another array
2985 if($type == 'a')
2986 {
2987 if(count($stack) >= IWP_MAX_SERIALIZED_ARRAY_DEPTH)
2988 {
2989 // array nesting exceeds IWP_MAX_SERIALIZED_ARRAY_DEPTH
2990 return false;
2991 }
2992 $stack[] = &$list;
2993 $list[$key] = array();
2994 $list = &$list[$key];
2995 $expected[] = $expectedLength;
2996 $state = 2;
2997 break;
2998 }
2999 if($type != '}')
3000 {
3001 $list[$key] = $value;
3002 $state = 2;
3003 break;
3004 }
3005 // missing array value
3006 return false;
3007 case 2: // in array, expecting end of array or a key
3008 if($type == '}')
3009 {
3010 if(count($list) < end($expected))
3011 {
3012 // array size less than expected
3013 return false;
3014 }
3015 unset($list);
3016 $list = &$stack[count($stack)-1];
3017 array_pop($stack);
3018 // go to terminal state if we're at the end of the root array
3019 array_pop($expected);
3020 if(count($expected) == 0) {
3021 $state = 1;
3022 }
3023 break;
3024 }
3025 if($type == 'i' || $type == 's')
3026 {
3027 if(count($list) >= IWP_MAX_SERIALIZED_ARRAY_LENGTH)
3028 {
3029 // array size exceeds IWP_MAX_SERIALIZED_ARRAY_LENGTH
3030 return false;
3031 }
3032 if(count($list) >= end($expected))
3033 {
3034 // array size exceeds expected length
3035 return false;
3036 }
3037 $key = $value;
3038 $state = 3;
3039 break;
3040 }
3041 // illegal array index type
3042 return false;
3043 case 0: // expecting array or value
3044 if($type == 'a')
3045 {
3046 if(count($stack) >= IWP_MAX_SERIALIZED_ARRAY_DEPTH)
3047 {
3048 // array nesting exceeds IWP_MAX_SERIALIZED_ARRAY_DEPTH
3049 return false;
3050 }
3051 $data = array();
3052 $list = &$data;
3053 $expected[] = $expectedLength;
3054 $state = 2;
3055 break;
3056 }
3057 if($type != '}')
3058 {
3059 $data = $value;
3060 $state = 1;
3061 break;
3062 }
3063 // not in array
3064 return false;
3065 }
3066 }
3067 if(!empty($str))
3068 {
3069 // trailing data in input
3070 return false;
3071 }
3072 return $data;
3073}
3074/**
3075 * Wrapper for _safe_unserialize() that handles exceptions and multibyte encoding issue
3076 *
3077 * @param string $str
3078 * @return mixed
3079 */
3080function iwp_mmb_safe_unserialize( $str )
3081{
3082 // ensure we use the byte count for strings even when strlen() is overloaded by mb_strlen()
3083 if (function_exists('mb_internal_encoding') &&
3084 (((int) ini_get('mbstring.func_overload')) & 2))
3085 {
3086 $mbIntEnc = mb_internal_encoding();
3087 mb_internal_encoding('ASCII');
3088 }
3089 $out = _iwp_mmb_safe_unserialize($str);
3090 if (isset($mbIntEnc))
3091 {
3092 mb_internal_encoding($mbIntEnc);
3093 }
3094 return $out;
3095}
3096
3097function iwp_mmb_get_hosting_disk_quota_free() {
3098 if (!@is_dir('/usr/local/cpanel') || !function_exists('popen') || (!@is_executable('/usr/local/bin/perl') && !@is_executable('/usr/local/cpanel/3rdparty/bin/perl')) ) return false;
3099
3100 $perl = (@is_executable('/usr/local/cpanel/3rdparty/bin/perl')) ? '/usr/local/cpanel/3rdparty/bin/perl' : '/usr/local/bin/perl';
3101
3102 $exec = "IWPKEY=IWP $perl ".WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__))."/lib/cpanel-quota-usage.pl";
3103 $handle = popen($exec, 'r');
3104 if (!is_resource($handle)) return false;
3105
3106 $found = false;
3107 $lines = 0;
3108 while (false === $found && !feof($handle) && $lines<100) {
3109 $lines++;
3110 $w = fgets($handle);
3111 # Used, limit, remain
3112 if (preg_match('/RESULT: (\d+) (\d+) (\d+) /', $w, $matches)) { $found = true; }
3113 }
3114 $ret = pclose($handle);
3115 if (false === $found ||$ret != 0) return false;
3116
3117 if ((int)$matches[2]<100 || ($matches[1] + $matches[3] != $matches[2])) return false;
3118
3119 return $matches;
3120 }
3121
3122 function iwp_mmb_check_disk_space(){
3123 $hosting_bytes_free = iwp_mmb_get_hosting_disk_quota_free();
3124 if (is_array($hosting_bytes_free)) {
3125 $perc = round(100*$hosting_bytes_free[1]/(max($hosting_bytes_free[2], 1)), 1);
3126 $quota_free = round($hosting_bytes_free[3]/1048576, 1);
3127 if ($hosting_bytes_free[3] < 1048576*50) {
3128 $quota_free_mb = round($hosting_bytes_free[3]/1048576, 1);
3129 return $quota_free_mb;
3130 }
3131 }
3132
3133 $disk_free_space = @disk_free_space(dirname(__FILE__));
3134 # == rather than === here is deliberate; support experience shows that a result of (int)0 is not reliable. i.e. 0 can be returned when the real result should be false.
3135 if ($disk_free_space == false) {
3136 return false;
3137 } else {
3138
3139 $disk_free_mb = round($disk_free_space/1048576, 1);
3140 if ($disk_free_space < 50*1048576) return $disk_free_mb;
3141 }
3142 return false;
3143 }
3144
3145 function iwp_closeBrowserConnection($response = false, $success = true){
3146 $response = iwp_mmb_convert_wperror_obj_to_arr($response,'initial');
3147
3148 if ((is_array($response) && empty($response)) || (!is_array($response) && strlen($response) == 0)){
3149 $return['error'] = 'Empty response.';
3150 $return['error_code'] = 'empty_response';
3151 }
3152 elseif ($success){
3153 $return['success'] = $response;
3154 }
3155 else{
3156 $return['error'] = $response['error'];
3157 $return['error_code'] = $response['error_code'];
3158 }
3159
3160 $txt = '<IWPHEADER>_IWP_JSON_PREFIX_' . base64_encode( iwp_mmb_json_encode( $return ) ) . '<ENDIWPHEADER>';
3161 ignore_user_abort(true);
3162 ob_end_clean();
3163 ob_start();
3164 echo ($txt);
3165 $size = ob_get_length();
3166 header("Connection: close\r\n");
3167 header("Content-Encoding: none\r\n");
3168 header("Content-Length: $size");
3169 @ob_flush();
3170 flush();
3171 ob_end_flush();
3172 }
3173
3174function iwp_mmb_set_plugin_priority()
3175{
3176 $activePlugins = get_option('active_plugins');
3177 $pluginBasename = 'iwp-client/init.php';
3178 $wptcPluginBasename = 'wp-time-capsule/wp-time-capsule.php';
3179 $array_slice = array_slice($activePlugins, 1, true);
3180 if (!is_array($activePlugins) || (reset($activePlugins) == $wptcPluginBasename && (reset($array_slice) == $pluginBasename))) {
3181 return;
3182 }
3183
3184 $iwpKey = array_search($pluginBasename, $activePlugins);
3185 $wptcKey = array_search($wptcPluginBasename, $activePlugins);
3186 if ($iwpKey == false && $wptcKey == false) {
3187 return;
3188 }elseif ($iwpKey == false) {
3189 return;
3190 }elseif ($iwpKey == true && $wptcKey == false) {
3191 unset($activePlugins[$iwpKey]);
3192 array_unshift($activePlugins, $pluginBasename);
3193 update_option('active_plugins', array_values($activePlugins));
3194 return;
3195 }
3196 unset($activePlugins[$iwpKey]);
3197 unset($activePlugins[$wptcKey]);
3198 array_unshift($activePlugins, $pluginBasename);
3199 array_unshift($activePlugins, $wptcPluginBasename);
3200
3201 update_option('active_plugins', array_values($activePlugins));
3202}
3203
3204function iwp_mmb_get_user_by( $field, $value ) {
3205 $userdata = WP_User::get_data_by( $field, $value );
3206
3207 if ( !$userdata )
3208 return false;
3209
3210 $user = new WP_User;
3211 $user->init( $userdata );
3212
3213 return $user;
3214}
3215
3216function iwp_plugin_compatibility_fix(){
3217 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
3218 $iwp_plugin_fix = new IWP_MMB_FixCompatibility();
3219 $iwp_plugin_fix->fixAllInOneSecurity();
3220 $iwp_plugin_fix->fixWpSimpleFirewall();
3221 $iwp_plugin_fix->fixDuoFactor();
3222 $iwp_plugin_fix->fixShieldUserManagementICWP();
3223 $iwp_plugin_fix->fixSidekickPlugin();
3224 $iwp_plugin_fix->fixSpamShield();
3225 $iwp_plugin_fix->fixWpSpamShieldBan();
3226 $iwp_plugin_fix->fixPantheonGlobals();
3227
3228}
3229
3230function iwp_mu_plugin_loader(){
3231 global $iwp_mmb_core;
3232 $loaderName = 'mu-iwp-client.php';
3233 $mustUsePluginDir = rtrim(WPMU_PLUGIN_DIR, '/');
3234 $loaderPath = $mustUsePluginDir.'/'.$loaderName;
3235
3236 if (file_exists($loaderPath)) {
3237 return;
3238 }
3239 try {
3240 $iwp_mmb_core->registerMustUse($loaderName, $iwp_mmb_core->buildLoaderContent('iwp-client/init.php'));
3241 } catch (Exception $e) {
3242 iwp_mmb_response(array('error' => 'Unable to write InfiniteWP Client loader:'.$e->getMessage(), 'error_code' => 'iwp_mu_plugin_loader_failed'), false);
3243 }
3244}
3245if(!function_exists('iwp_mmb_is_WPTC')) {
3246function iwp_mmb_is_WPTC() {
3247 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
3248 if ( is_plugin_active( 'wp-time-capsule/wp-time-capsule.php' ) ) {
3249 return true;
3250 } else {
3251 return false;
3252 }
3253 }
3254}
3255
3256iwp_mmb_set_plugin_priority();
3257$iwp_mmb_core = new IWP_MMB_Core();
3258$GLOBALS['iwp_mmb_activities_log'] = new IWP_MMB_Activities_log();
3259$mmb_core = 1;
3260$GLOBALS['iwp_activities_log_post_type'] = 'iwp_log';
3261
3262if(isset($_GET['auto_login'])){
3263 $GLOBALS['__itsec_core_is_rest_api_request'] = true;
3264 $iwp_mmb_core->add_login_action();
3265}
3266if (function_exists('register_activation_hook'))
3267 register_activation_hook( __FILE__ , array( $iwp_mmb_core, 'install' ));
3268
3269if (function_exists('register_deactivation_hook'))
3270 register_deactivation_hook(__FILE__, array( $iwp_mmb_core, 'uninstall' ));
3271
3272if (function_exists('add_action'))
3273 add_action('init', 'iwp_mmb_plugin_actions', 99999);
3274
3275if (function_exists('add_action'))
3276 add_action('template_redirect', 'iwp_mmb_check_maintenance', 99999);
3277
3278if (function_exists('add_action'))
3279 add_action('template_redirect', 'iwp_mmb_check_redirects', 99999);
3280
3281if (function_exists('add_filter'))
3282 add_filter('install_plugin_complete_actions','iwp_mmb_iframe_plugins_fix');
3283
3284if( isset($_COOKIE[IWP_MMB_XFRAME_COOKIE]) ){
3285 remove_action( 'admin_init', 'send_frame_options_header');
3286 remove_action( 'login_init', 'send_frame_options_header');
3287}
3288
3289//added for jQuery compatibility
3290if(!function_exists('iwp_mmb_register_ext_scripts')){
3291 function iwp_mmb_register_ext_scripts(){
3292 wp_register_script( 'iwp-clipboard', plugins_url( 'clipboard.min.js', __FILE__ ) );
3293 }
3294}
3295
3296add_action( 'admin_init', 'iwp_mmb_register_ext_scripts' );
3297$iwp_mmb_core->get_new_backup_instance();
3298iwp_mmb_parse_request();
3299
3300?>