PluginProbe
ManageWP Worker / 3.9.30
ManageWP Worker v3.9.30
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / init.php

init.php in ManageWP Worker 3.9.30, at init.php

2,072 lines 70.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: ManageWP - Worker
4 Plugin URI: https://managewp.com
5 Description: ManageWP Worker plugin allows you to manage your WordPress sites from one dashboard. Visit <a href="https://managewp.com">ManageWP.com</a> for more information.
6 Version: 3.9.30
7 Author: ManageWP
8 Author URI: https://managewp.com
9 License: GPL2
10 */
11
12 /*************************************************************
13 * init.php
14 * Initialize the communication with master
15 * Copyright (c) 2011 Prelovac Media
16 * www.prelovac.com
17 **************************************************************/
18 if (!defined('ABSPATH')) {
19 exit;
20 }
21
22 if (!defined('MMB_WORKER_VERSION')) {
23 define('MMB_WORKER_VERSION', '3.9.30');
24 }
25
26 $GLOBALS['MMB_WORKER_VERSION'] = '3.9.30';
27 $GLOBALS['MMB_WORKER_REVISION'] = '2014-11-24 00:00:00';
28
29 /**
30 * Reserved memory for fatal error handling execution context.
31 */
32 $GLOBALS['mwp_reserved_memory'] = str_repeat(' ', 1024 * 20);
33 /**
34 * If we ever get only partially upgraded due to a server error or misconfiguration,
35 * attempt to disable the plugin and notify the site's administrator via email.
36 */
37 function mwp_fail_safe()
38 {
39 $GLOBALS['mwp_reserved_memory'] = null;
40
41 $lastError = error_get_last();
42
43 if (!$lastError || $lastError['type'] !== E_ERROR) {
44 return;
45 }
46
47 $activePlugins = get_option('active_plugins');
48 $workerIndex = array_search(plugin_basename(__FILE__), $activePlugins);
49 if ($workerIndex === false) {
50 // Plugin is not yet enabled, possibly in activation context.
51 return;
52 }
53
54 $errorSource = realpath($lastError['file']);
55 // We might be in eval() context.
56 if (!$errorSource) {
57 return;
58 }
59
60 // The only fatal error that we would get would be a 'Class 'X' not found in ...', so look out only for those messages.
61 if (!preg_match('/^Class \'[^\']+\' not found$/', $lastError['message'])) {
62 return;
63 }
64
65 // Only look for files that belong to this plugin.
66 $pluginBase = realpath(dirname(__FILE__));
67 if (stripos($errorSource, $pluginBase) !== 0) {
68 return;
69 }
70
71 unset($activePlugins[$workerIndex]);
72 // Reset indexes.
73 $activePlugins = array_values($activePlugins);
74 update_option('active_plugins', $activePlugins);
75
76 // We probably won't have access to the wp_mail function.
77 $mailFn = function_exists('wp_mail') ? 'wp_mail' : 'mail';
78 $siteUrl = get_option('siteurl');
79 $title = sprintf("ManageWP Worker deactivated on %s", $siteUrl);
80 $to = get_option('admin_email');
81 $brand = get_option('mwp_worker_brand');
82 if (!empty($brand['admin_email'])) {
83 $to = $brand['admin_email'];
84 }
85
86 $fullError = print_r($lastError, 1);
87 $workerSettings = get_option('wrksettings');
88 $userID = 0;
89 if (!empty($workerSettings['dataown'])) {
90 $userID = (int) $workerSettings['dataown'];
91 }
92 $body = sprintf('Worker deactivation due to an error. The site that was deactivated - %s. User email - %s (UserID: %s). The error that caused this: %s', $siteUrl, $to, $userID, $fullError);
93 $mailFn('support@managewp.com', $title, $body);
94
95 // If we're inside a cron scope, don't attempt to hide this error.
96 if (defined('DOING_CRON') && DOING_CRON) {
97 return;
98 }
99
100 // If we're inside a normal request scope, we apologize. Retry the request so user doesn't have to see an ugly error page.
101 if (!empty($_SERVER['REQUEST_URI'])) {
102 $siteUrl .= $_SERVER['REQUEST_URI'];
103 }
104 if (headers_sent()) {
105 // The headers are probably sent if the PHP configuration has the 'display_errors' directive enabled. In that case try a meta redirect.
106 echo sprintf('<meta http-equiv="refresh" content="0; url=%s">', htmlspecialchars($siteUrl, ENT_QUOTES));
107 } else {
108 header('Location: '.htmlspecialchars($siteUrl, ENT_QUOTES));
109 }
110 exit;
111 }
112
113 register_shutdown_function('mwp_fail_safe');
114
115 require_once dirname(__FILE__).'/functions.php';
116
117 if (!defined('MMB_XFRAME_COOKIE')) {
118 $siteurl = function_exists('get_site_option') ? get_site_option('siteurl') : get_option('siteurl');
119 define('MMB_XFRAME_COOKIE', $xframe = 'wordpress_'.md5($siteurl).'_xframe');
120 }
121
122 global $wpdb, $mmb_plugin_dir, $mmb_plugin_url, $wp_version, $mmb_filters, $_mmb_item_filter;
123 if (version_compare(PHP_VERSION, '5.2.0', '<')) // min version 5 supported
124 {
125 exit("<p>ManageWP Worker plugin requires PHP 5.2 or higher.</p>");
126 }
127
128 if (version_compare(PHP_VERSION, '5.3', '<')) {
129 spl_autoload_register('mwp_autoload');
130 } else {
131 // The prepend parameter was added in PHP 5.3.0
132 spl_autoload_register('mwp_autoload', true, true);
133 }
134
135 // Will register the logger as the error handler.
136 mwp_logger();
137
138 $mmb_wp_version = $wp_version;
139 $mmb_plugin_dir = WP_PLUGIN_DIR.'/'.basename(dirname(__FILE__));
140 $mmb_plugin_url = WP_PLUGIN_URL.'/'.basename(dirname(__FILE__));
141
142 define('MWP_SHOW_LOG', false);
143 // <stats.class.php>
144 add_filter('mwp_website_add', 'MMB_Stats::readd_alerts');
145 // <backup.class.php>
146 define('MWP_BACKUP_DIR', WP_CONTENT_DIR.'/managewp/backups');
147 define('MWP_DB_DIR', MWP_BACKUP_DIR.'/mwp_db');
148
149 mmb_add_action('search_posts_by_term', 'search_posts_by_term');
150 add_filter('mmb_stats_filter', 'mmb_get_extended_info');
151 mmb_add_action('cleanup_delete', 'cleanup_delete_worker');
152 add_action('plugins_loaded', 'mwp_return_core_reference', 1);
153 // <widget.class.php>
154 $mwp_worker_brand = get_option("mwp_worker_brand");
155 $worker_brand = 0;
156 if (is_array($mwp_worker_brand)) {
157 if ($mwp_worker_brand['name'] || $mwp_worker_brand['desc'] || $mwp_worker_brand['author'] || $mwp_worker_brand['author_url']) {
158 $worker_brand = 1;
159 }
160 }
161 if (!$worker_brand) {
162 add_action('widgets_init', create_function('', 'return register_widget("MMB_Widget");'));
163 }
164
165 if (!function_exists('mmb_parse_data')) {
166 function mmb_parse_data($data = array())
167 {
168 if (empty($data)) {
169 return $data;
170 }
171
172 $data = (array) $data;
173 if (isset($data['params'])) {
174 $data['params'] = mmb_filter_params($data['params']);
175 }
176
177 $postkeys = array('action', 'params', 'id', 'signature', 'setting', 'add_site_signature_id', 'add_site_signature');
178
179 if (!empty($data)) {
180 foreach ($data as $key => $items) {
181 if (!in_array($key, $postkeys)) {
182 unset($data[$key]);
183 }
184 }
185 }
186
187 return $data;
188 }
189 }
190
191 if (!function_exists('mmb_filter_params')) {
192 function mmb_filter_params($array = array())
193 {
194
195 $filter = array('current_user', 'wpdb');
196 $return = array();
197 foreach ($array as $key => $val) {
198 if (!is_int($key) && in_array($key, $filter)) {
199 continue;
200 }
201
202 if (is_array($val)) {
203 $return[$key] = mmb_filter_params($val);
204 } else {
205 $return[$key] = $val;
206 }
207 }
208
209 return $return;
210 }
211 }
212 if (!function_exists('mmb_authenticate')) {
213 function mmb_authenticate()
214 {
215 global $_mwp_data, $_mwp_auth, $mmb_core, $HTTP_RAW_POST_DATA;
216 $compat = false;
217 $compatActive = false;
218 $contentType = empty($_SERVER['CONTENT_TYPE']) ? false : $_SERVER['CONTENT_TYPE'];
219
220 if ($compat && empty($_SERVER['HTTP_MWP_ACTION']) && $contentType === 'application/json') {
221 $compatActive = true;
222 }
223
224 if (empty($_SERVER['HTTP_MWP_ACTION']) && !$compatActive) {
225 return;
226 }
227
228 if (!isset($HTTP_RAW_POST_DATA)) {
229 $HTTP_RAW_POST_DATA = file_get_contents('php://input');
230 }
231 $_mwp_data = json_decode($HTTP_RAW_POST_DATA, true);
232
233 if (!$_mwp_data) {
234 return;
235 }
236 $_mwp_data = mmb_parse_data($_mwp_data);
237
238 if ($compatActive) {
239 if (empty($_mwp_data['action'])) {
240 return;
241 }
242 $_mwp_data['signature'] = base64_decode($_mwp_data['signature']);
243 } else {
244 $_mwp_data['action'] = $_SERVER['HTTP_MWP_ACTION'];
245 $_mwp_data['id'] = isset($_SERVER['HTTP_MWP_MESSAGE_ID']) ? $_SERVER['HTTP_MWP_MESSAGE_ID'] : "";
246 $_mwp_data['signature'] = isset($_SERVER['HTTP_MWP_SIGNATURE']) ? base64_decode($_SERVER['HTTP_MWP_SIGNATURE']) : '';
247 }
248
249 $usernameUsed = array_key_exists('username', $_mwp_data['params']) ? $_mwp_data['params']['username'] : null;
250 if (empty($_mwp_data['params']['username']) || !$mmb_core->check_if_user_exists($_mwp_data['params']['username'])) {
251 $filter = array(
252 'user_roles' => array(
253 'administrator'
254 ),
255 'username' => '',
256 'username_filter' => '',
257 );
258 $users = $mmb_core->get_user_instance()->get_users($filter);
259
260 if (empty($users['users'])) {
261 mmb_response('We could not find an administrator user to use. Please contact support.', false);
262 }
263
264 $_mwp_data['params']['username'] = $users['users'][0]['user_login'];
265 }
266
267 if (isset($_mwp_data['params']['username']) && !is_user_logged_in()) {
268 $user = function_exists('get_user_by') ? get_user_by('login', $_mwp_data['params']['username']) : get_user_by('login', $_mwp_data['params']['username']);
269 }
270
271 if ($_mwp_data['action'] === 'add_site') {
272 $_mwp_auth = mwp_add_site_verify_signature($_mwp_data, $usernameUsed);
273 if (isset($user)) {
274 $GLOBALS['mwp_user_id'] = $user->ID;
275 }
276
277 return;
278 } else {
279 $_mwp_auth = $mmb_core->authenticate_message($_mwp_data['action'].$_mwp_data['id'], $_mwp_data['signature'], $_mwp_data['id']);
280 }
281
282 if ($_mwp_auth !== true) {
283 mmb_response($_mwp_auth['error'], false);
284 }
285
286 if (isset($user)) {
287 wp_set_current_user($user->ID);
288 // Compatibility with All In One Security
289 update_user_meta($user->ID, 'last_login_time', current_time('mysql'));
290 }
291
292 if (defined('ALTERNATE_WP_CRON') && !defined('DOING_AJAX') && ALTERNATE_WP_CRON === true) {
293 define('DOING_AJAX', true);
294 }
295 }
296 }
297
298 if (!function_exists("mwp_add_site_verify_signature")) {
299 function mwp_add_site_verify_signature($_mwp_data, $posted_username = null)
300 {
301 global $mmb_plugin_dir;
302
303 $nonce = new MWP_Security_HashNonce();
304 $nonce->setValue($_mwp_data['id']);
305 if (!$nonce->verify()) {
306 $_mwp_auth = array(
307 'error' => 'Invalid nonce used. Please contact support'
308 );
309 mmb_response($_mwp_auth['error'], false);
310 } else {
311
312 if (!empty($_mwp_data['add_site_signature']) && !empty($_mwp_data['add_site_signature_id'])) {
313 $signature = base64_decode($_mwp_data['add_site_signature']);
314 $signature_id = $_mwp_data['add_site_signature_id'];
315 $plaintext = array();
316 $plaintext['setting'] = $_mwp_data['setting'];
317 $plaintext['params'] = $_mwp_data['params'];
318 if (isset($posted_username)) {
319 $plaintext['params']['username'] = $posted_username;
320 }
321 if (file_exists($mmb_plugin_dir.'/publickeys/'.$signature_id.'.pub')) {
322 $plaintext = json_encode($plaintext);
323 require_once dirname(__FILE__).'/src/PHPSecLib/Crypt/RSA.php';
324 $rsa = new Crypt_RSA();
325 $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
326 $rsa->loadKey(file_get_contents($mmb_plugin_dir.'/publickeys/'.$signature_id.'.pub')); // public key
327 $_mwp_auth = $rsa->verify($plaintext, $signature);
328 } else {
329 $_mwp_auth = false; // we don't have key
330 }
331 } else {
332 $_mwp_auth = false;
333 }
334
335 if ($_mwp_auth !== true) {
336 $_mwp_auth = array(
337 'error' => 'Invalid message signature. Deactivate and activate the ManageWP Worker plugin on this site, then re-add it to your ManageWP account.'
338 );
339 mmb_response($_mwp_auth['error'], false);
340 }
341 }
342
343 return $_mwp_auth;
344 }
345 }
346
347 if (!function_exists('mmb_parse_request')) {
348 function mmb_parse_request()
349 {
350 global $mmb_core, $wp_db_version, $wpmu_version, $_wp_using_ext_object_cache, $_mwp_data, $_mwp_auth;
351 if (empty($_mwp_auth)) {
352 MMB_Stats::set_hit_count();
353
354 return;
355 }
356 ob_start();
357 $_wp_using_ext_object_cache = false;
358 @set_time_limit(1200);
359
360 if (isset($_mwp_data['setting'])) {
361 if (array_key_exists("dataown", $_mwp_data['setting'])) {
362 $oldconfiguration = array("dataown" => $_mwp_data['setting']['dataown']);
363 $mmb_core->save_options($oldconfiguration);
364 unset($_mwp_data['setting']['dataown']);
365 }
366
367 $configurationService = new MWP_Configuration_Service();
368 $configuration = new MWP_Configuration_Conf($_mwp_data['setting']);
369 $configurationService->saveConfiguration($configuration);
370 }
371
372 if ($_mwp_data['action'] === 'add_site') {
373 mmb_add_site($_mwp_data['params']);
374 mmb_response('You should never see this.', false);
375 }
376
377 /* in case database upgrade required, do database backup and perform upgrade ( wordpress wp_upgrade() function ) */
378 if (strlen(trim($wp_db_version)) && !defined('ACX_PLUGIN_DIR')) {
379 if (get_option('db_version') != $wp_db_version) {
380 /* in multisite network, please update database manualy */
381 if (empty($wpmu_version) || (function_exists('is_multisite') && !is_multisite())) {
382 if (!function_exists('wp_upgrade')) {
383 include_once(ABSPATH.'wp-admin/includes/upgrade.php');
384 }
385
386 ob_clean();
387 @wp_upgrade();
388 @do_action('after_db_upgrade');
389 ob_end_clean();
390 }
391 }
392 }
393
394 if (isset($_mwp_data['params']['secure'])) {
395 if (is_array($_mwp_data['params']['secure'])) {
396 $secureParams = $_mwp_data['params']['secure'];
397 foreach ($secureParams as $key => $value) {
398 $secureParams[$key] = base64_decode($value);
399 }
400 $_mwp_data['params']['secure'] = $secureParams;
401 } else {
402 $_mwp_data['params']['secure'] = base64_decode($_mwp_data['params']['secure']);
403 }
404 if ($decrypted = $mmb_core->_secure_data($_mwp_data['params']['secure'])) {
405 $decrypted = maybe_unserialize($decrypted);
406 if (is_array($decrypted)) {
407 foreach ($decrypted as $key => $val) {
408 if (!is_numeric($key)) {
409 $_mwp_data['params'][$key] = $val;
410 }
411 }
412 unset($_mwp_data['params']['secure']);
413 } else {
414 $_mwp_data['params']['secure'] = $decrypted;
415 }
416 }
417
418 if (!$decrypted && $mmb_core->get_random_signature() !== false) {
419 require_once dirname(__FILE__).'/src/PHPSecLib/Crypt/AES.php';
420 $cipher = new Crypt_AES(CRYPT_AES_MODE_ECB);
421 $cipher->setKey($mmb_core->get_random_signature());
422 $decrypted = $cipher->decrypt($_mwp_data['params']['secure']);
423 $_mwp_data['params']['account_info'] = json_decode($decrypted, true);
424 }
425
426 }
427
428 $logData = array(
429 'action' => $_mwp_data['action'],
430 'action_parameters' => $_mwp_data['params'],
431 'action_settings' => $_mwp_data['setting'],
432 );
433
434 if (!empty($_mwp_data['setting'])) {
435 $logData['settings'] = $_mwp_data['setting'];
436 }
437
438 mwp_logger()->debug('Master request: "{action}"', $logData);
439
440 if (!$mmb_core->register_action_params($_mwp_data['action'], $_mwp_data['params'])) {
441 global $_mmb_plugin_actions;
442 $_mmb_plugin_actions[$_mwp_data['action']] = $_mwp_data['params'];
443 }
444
445 ob_end_clean();
446 }
447 }
448 /* Main response function */
449 if (!function_exists('mmb_response')) {
450
451 function mmb_response($response = false, $success = true)
452 {
453 $return = array();
454
455 if ((is_array($response) && empty($response)) || (!is_array($response) && strlen($response) == 0)) {
456 $return['error'] = 'Empty response.';
457 } else {
458 if ($success) {
459 $return['success'] = $response;
460 } else {
461 $return['error'] = $response;
462 }
463 }
464
465 if (!headers_sent()) {
466 header('HTTP/1.0 200 OK');
467 header('Content-Type: text/plain');
468 }
469
470 mwp_logger()->debug('Master response: {action_response_status}', array(
471 'action_response_status' => $success ? 'success' : 'error',
472 'action_response' => $return,
473 'headers_sent' => headers_sent(),
474 ));
475
476 exit("<MWPHEADER>".base64_encode(serialize($return))."<ENDMWPHEADER>");
477 }
478 }
479
480
481 if (!function_exists('mmb_add_site')) {
482 function mmb_add_site($params)
483 {
484 global $mmb_core;
485 $num = extract($params);
486
487 if ($num) {
488 if (!get_option('_worker_public_key')) {
489 $public_key = base64_decode($public_key);
490
491 if (function_exists('openssl_verify')) {
492 $verify = openssl_verify($action.$id, base64_decode($signature), $public_key);
493 if ($verify == 1) {
494 $mmb_core->set_master_public_key($public_key);
495 //$mmb_core->set_worker_message_id($id);
496
497
498 $mmb_core->get_stats_instance();
499 if (isset($notifications) && is_array($notifications) && !empty($notifications)) {
500 $mmb_core->stats_instance->set_notifications($notifications);
501 }
502 if (isset($brand) && is_array($brand) && !empty($brand)) {
503 update_option('mwp_worker_brand', $brand);
504 }
505
506 if (isset($add_settigns) && is_array($add_settigns) && !empty($add_settigns)) {
507 apply_filters('mwp_website_add', $add_settigns);
508 }
509
510 mmb_response($mmb_core->stats_instance->get_initial_stats(), true);
511 } else {
512 if ($verify == 0) {
513
514 //mmb_response('Site could not be added. OpenSSL verification error: "'.openssl_error_string().'". Contact your hosting support to check the OpenSSL configuration.', false);
515
516 } else {
517 mmb_response('Command not successful. Please try again.', false);
518 }
519 }
520 }
521
522 if (!get_option('_worker_nossl_key')) {
523 srand();
524
525 $random_key = md5(base64_encode($public_key).rand(0, getrandmax()));
526
527 $mmb_core->set_random_signature($random_key);
528 //$mmb_core->set_worker_message_id($id);
529 $mmb_core->set_master_public_key($public_key);
530
531
532 $mmb_core->get_stats_instance();
533 if (is_array($notifications) && !empty($notifications)) {
534 $mmb_core->stats_instance->set_notifications($notifications);
535 }
536
537 if (is_array($brand) && !empty($brand)) {
538 update_option('mwp_worker_brand', $brand);
539 }
540
541 mmb_response($mmb_core->stats_instance->get_initial_stats(), true);
542 } else {
543 mmb_response('Sorry, we were unable to communicate with your website. Please deactivate, then activate ManageWP Worker plugin on your website and try again or contact our support.', false);
544 }
545
546 } else {
547 mmb_response('Sorry, we were unable to communicate with your website. Please deactivate, then activate ManageWP Worker plugin on your website and try again or contact our support.', false);
548 }
549 } else {
550 mmb_response('Invalid parameters received. Please try again.', false);
551 }
552 }
553 }
554
555 if (!function_exists('mmb_remove_site')) {
556 function mmb_remove_site($params)
557 {
558 extract($params);
559 global $mmb_core;
560 $mmb_core->uninstall($deactivate);
561
562 include_once(ABSPATH.'wp-admin/includes/plugin.php');
563 $plugin_slug = basename(dirname(__FILE__)).'/'.basename(__FILE__);
564
565 if ($deactivate) {
566 deactivate_plugins($plugin_slug, true);
567 } else {
568 // Prolong the worker deactivation upon site removal.
569 update_option('mmb_worker_activation_time', time());
570 }
571
572 if (!is_plugin_active($plugin_slug)) {
573 mmb_response(
574 array(
575 'deactivated' => 'Site removed successfully. <br /><br />ManageWP Worker plugin successfully deactivated.'
576 ),
577 true
578 );
579 } else {
580 mmb_response(
581 array(
582 'removed_data' => 'Site removed successfully. <br /><br /><b>ManageWP Worker plugin was not deactivated.</b>'
583 ),
584 true
585 );
586 }
587
588 }
589 }
590 if (!function_exists('mmb_stats_get')) {
591 function mmb_stats_get($params)
592 {
593 global $mmb_core;
594 $mmb_core->get_stats_instance();
595 mmb_response($mmb_core->stats_instance->get($params), true);
596 }
597 }
598
599 if (!function_exists('mmb_worker_header')) {
600 function mmb_worker_header()
601 {
602 global $mmb_core, $current_user;
603
604 if (!headers_sent()) {
605 if (isset($current_user->ID)) {
606 $expiration = time() + apply_filters('auth_cookie_expiration', 10800, $current_user->ID, false);
607 } else {
608 $expiration = time() + 10800;
609 }
610
611 setcookie(MMB_XFRAME_COOKIE, md5(MMB_XFRAME_COOKIE), $expiration, COOKIEPATH, COOKIE_DOMAIN, false, true);
612 $_COOKIE[MMB_XFRAME_COOKIE] = md5(MMB_XFRAME_COOKIE);
613 }
614 }
615 }
616
617 if (!function_exists('mmb_pre_init_stats')) {
618 function mmb_pre_init_stats($params)
619 {
620 global $mmb_core;
621 $mmb_core->get_stats_instance();
622
623 return $mmb_core->stats_instance->pre_init_stats($params);
624 }
625 }
626
627 if (!function_exists('mwp_datasend')) {
628 function mwp_datasend($params = array())
629 {
630 global $mmb_core, $_mmb_item_filter, $_mmb_options;
631
632
633 $_mmb_remoteurl = get_option('home');
634 $_mmb_remoteown = isset($_mmb_options['dataown']) && !empty($_mmb_options['dataown']) ? $_mmb_options['dataown'] : false;
635
636 if (empty($_mmb_remoteown)) {
637 return;
638 }
639
640 $_mmb_item_filter['pre_init_stats'] = array('core_update', 'hit_counter', 'comments', 'backups', 'posts', 'drafts', 'scheduled');
641 $_mmb_item_filter['get'] = array('updates', 'errors');
642 $mmb_core->get_stats_instance();
643
644 $filter = array(
645 'refresh' => 'transient',
646 'item_filter' => array(
647 'get_stats' => array(
648 array('updates', array('plugins' => true, 'themes' => true, 'premium' => true)),
649 array('core_update', array('core' => true)),
650 array('posts', array('numberposts' => 5)),
651 array('drafts', array('numberposts' => 5)),
652 array('scheduled', array('numberposts' => 5)),
653 array('hit_counter'),
654 array('comments', array('numberposts' => 5)),
655 array('backups'),
656 'plugins' => array(
657 'cleanup' => array(
658 'overhead' => array(),
659 'revisions' => array('num_to_keep' => 'r_5'),
660 'spam' => array(),
661 )
662 ),
663 ),
664 )
665 );
666
667 $pre_init_data = $mmb_core->stats_instance->pre_init_stats($filter);
668 $init_data = $mmb_core->stats_instance->get($filter);
669
670 $data = array_merge($init_data, $pre_init_data);
671 $data['server_ip'] = $_SERVER['SERVER_ADDR'];
672 $data['uhost'] = php_uname('n');
673 $hash = $mmb_core->get_secure_hash();
674
675 if (mwp_datasend_trigger($data)) { // adds trigger to check if really need to send something
676 $configurationService = new MWP_Configuration_Service();
677 $configuration = $configurationService->getConfiguration();
678
679 set_transient("mwp_cache_notifications", $data);
680 set_transient("mwp_cache_notifications_time", time());
681
682 $datasend['datasend'] = $mmb_core->encrypt_data($data);
683 $datasend['sitehome'] = base64_encode($_mmb_remoteown.'[]'.$_mmb_remoteurl);
684 $datasend['sitehash'] = md5($hash.$_mmb_remoteown.$_mmb_remoteurl);
685 $datasend['setting_checksum_order'] = implode(",", array_keys($configuration->getVariables()));
686 $datasend['setting_checksum'] = md5(json_encode($configuration->toArray()));
687 if (!class_exists('WP_Http')) {
688 include_once(ABSPATH.WPINC.'/class-http.php');
689 }
690
691 $remote = array();
692 $remote['body'] = $datasend;
693 $remote['timeout'] = 20;
694
695 $result = wp_remote_post($configuration->getMasterCronUrl(), $remote);
696 if (!is_wp_error($result)) {
697 if (isset($result['body']) && !empty($result['body'])) {
698 $settings = @unserialize($result['body']);
699 /* rebrand worker or set default */
700 $brand = '';
701 if ($settings['worker_brand']) {
702 $brand = $settings['worker_brand'];
703 }
704 update_option("mwp_worker_brand", $brand);
705 /* change worker version */
706 $w_version = @$settings['worker_updates']['version'];
707 $w_url = @$settings['worker_updates']['url'];
708 if (version_compare($GLOBALS['MMB_WORKER_VERSION'], $w_version, '<')) {
709 //automatic update
710 $mmb_core->update_worker_plugin(array("download_url" => $w_url));
711 }
712
713 if (!empty($settings['mwp_worker_configuration'])) {
714 require_once dirname(__FILE__).'/src/PHPSecLib/Crypt/RSA.php';
715 $rsa = new Crypt_RSA();
716 $keyName = $configuration->getKeyName();
717 $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
718 $rsa->loadKey(file_get_contents(dirname(__FILE__)."/publickeys/$keyName.pub")); // public key
719 $signature = base64_decode($settings['mwp_worker_configuration_signature']);
720 if ($rsa->verify(json_encode($settings['mwp_worker_configuration']), $signature)) {
721 $configuration = new MWP_Configuration_Conf($settings['mwp_worker_configuration']);
722 $configurationService->saveConfiguration($configuration);
723 }
724 }
725 }
726 } else {
727 //$mmb_core->_log($result);
728 }
729
730 }
731
732 }
733
734 }
735
736 if (!function_exists("mwp_datasend_trigger")) {
737 // trigger function, returns true if notifications should be sent
738 function mwp_datasend_trigger($stats)
739 {
740
741 $configurationService = new MWP_Configuration_Service();
742 $configuration = $configurationService->getConfiguration();
743
744 $cachedData = get_transient("mwp_cache_notifications");
745 $cacheTime = (int) get_transient("mwp_cache_notifications_time");
746
747 $returnValue = false;
748 if (false == $cachedData || empty($configuration)) {
749 $returnValue = true;
750 }
751 /**
752 * Cache lifetime check
753 */
754 if (!$returnValue) {
755 $now = time();
756 if ($now - $configuration->getNotiCacheLifeTime() >= $cacheTime) {
757 $returnValue = true;
758 }
759 }
760
761 /**
762 * Themes difference check section
763 * First check if array differ in size. If same size,then check values difference
764 */
765 if (!$returnValue && empty($stats['upgradable_themes']) != empty($cachedData['upgradable_themes'])) {
766 $returnValue = true;
767 }
768 if (!$returnValue && !empty($stats['upgradable_themes'])) {
769 $themesArr = mwp_std_to_array($stats['upgradable_themes']);
770 $cachedThemesArr = mwp_std_to_array($cachedData['upgradable_themes']);
771 if ($themesArr != $cachedThemesArr) {
772 $returnValue = true;
773 }
774 }
775
776 /**
777 * Plugins difference check section
778 * First check if array differ in size. If same size,then check values difference
779 */
780 if (!$returnValue && empty($stats['upgradable_plugins']) != empty($cachedData['upgradable_plugins'])) {
781 $returnValue = true;
782 }
783
784 if (!$returnValue && !empty($stats['upgradable_plugins'])) { //we have hear stdclass
785 $pluginsArr = mwp_std_to_array($stats['upgradable_plugins']);
786 $cachedPluginsArr = mwp_std_to_array($cachedData['upgradable_plugins']);
787 if ($pluginsArr != $cachedPluginsArr) {
788 $returnValue = true;
789 }
790 }
791
792 /**
793 * Premium difference check section
794 * First check if array differ in size. If same size,then check values difference
795 */
796 if (!$returnValue && empty($stats['premium_updates']) != empty($cachedData['premium_updates'])) {
797 $returnValue = true;
798 }
799 if (!$returnValue && !empty($stats['premium_updates'])) {
800 $premiumArr = mwp_std_to_array($stats['premium_updates']);
801 $cachedPremiumArr = mwp_std_to_array($cachedData['premium_updates']);
802 if ($premiumArr != $cachedPremiumArr) {
803 $returnValue = true;
804 }
805 }
806 /**
807 * Comments
808 * Check if we have configs first, then check trasholds
809 */
810 if (!$returnValue && (int) $stats['num_spam_comments'] >= $configuration->getNotiTresholdSpamComments() && $stats['num_spam_comments'] != (int) $cachedData['num_spam_comments']) {
811 $returnValue = true;
812 }
813 if (!$returnValue && (int) $stats['num_spam_comments'] < (int) $cachedData['num_spam_comments']) {
814 $returnValue = true;
815 }
816
817 if (!$returnValue && !empty($stats['comments'])) {
818 if (!empty($stats['comments']['pending']) && count($stats['comments']['pending']) >= $configuration->getNotiTresholdPendingComments()) {
819 $pendingArr = mwp_std_to_array($stats['comments']['pending']);
820 $cachedPendingArr = mwp_std_to_array($cachedData['comments']['pending']);
821 if ($pendingArr != $cachedPendingArr) {
822 $returnValue = true;
823 }
824 }
825
826 if (!empty($stats['comments']['approved']) && count($stats['comments']['approved']) >= $configuration->getNotiTresholdApprovedComments()) {
827 $approvedArr = mwp_std_to_array($stats['comments']['approved']);
828 $cachedApprovedArr = mwp_std_to_array($cachedData['comments']['approved']);
829 if ($approvedArr != $cachedApprovedArr) {
830 $returnValue = true;
831 }
832 }
833 }
834
835 /**
836 * Drafts, posts
837 */
838
839 if (!$returnValue && !empty($stats['drafts']) && count($stats['drafts']) >= $configuration->getNotiTresholdDrafts()) {
840 if (count($stats['drafts']) > $configuration->getNotiTresholdDrafts() && empty($cachedData['drafts'])) {
841 $returnValue = true;
842 } else {
843 $draftsArr = mwp_std_to_array($stats['drafts']);
844 $cachedDraftsArr = mwp_std_to_array($cachedData['drafts']);
845 if ($draftsArr != $cachedDraftsArr) {
846 $returnValue = true;
847 }
848 }
849
850 }
851
852 if (!$returnValue && !empty($stats['posts']) && count($stats['posts']) >= $configuration->getNotiTresholdPosts()) {
853 if (count($stats['posts']) > $configuration->getNotiTresholdPosts() && empty($cachedData['posts'])) {
854 $returnValue = true;
855 } else {
856 $postsArr = mwp_std_to_array($stats['posts']);
857 $cachedPostsArr = mwp_std_to_array($cachedData['posts']);
858 if ($postsArr != $cachedPostsArr) {
859 $returnValue = true;
860 }
861 }
862 }
863
864 /**
865 * Core updates & backups
866 */
867 if (!$returnValue && empty($stats['core_updates']) != empty($cachedData['core_updates'])) {
868 $returnValue = true;
869 }
870 if (!$returnValue && !empty($stats['core_updates'])) {
871 $coreArr = mwp_std_to_array($stats['core_updates']);
872 $cachedCoreArr = mwp_std_to_array($cachedData['core_updates']);
873 if ($coreArr != $cachedCoreArr) {
874 $returnValue = true;
875 }
876 }
877
878 if (!$returnValue && empty($stats['mwp_backups']) != empty($cachedData['mwp_backups'])) {
879 $returnValue = true;
880 }
881 if (!$returnValue && !empty($stats['mwp_backups'])) {
882 $backupArr = mwp_std_to_array($stats['mwp_backups']);
883 $cachedBackupArr = mwp_std_to_array($cachedData['mwp_backups']);
884 if ($backupArr != $cachedBackupArr) {
885 $returnValue = true;
886 }
887 }
888
889 return $returnValue;
890 }
891 }
892
893 if (!function_exists("mwp_std_to_array")) {
894 function mwp_std_to_array($obj)
895 {
896 if (is_object($obj)) {
897 $objArr = clone $obj;
898 } else {
899 $objArr = $obj;
900 }
901 if (!empty($objArr)) {
902 foreach ($objArr as &$element) {
903 if ($element instanceof stdClass || is_array($element)) {
904 $element = mwp_std_to_array($element);
905 }
906 }
907 $objArr = (array) $objArr;
908 }
909
910 return $objArr;
911 }
912 }
913
914
915 //post
916 if (!function_exists('mmb_post_create')) {
917 function mmb_post_create($params)
918 {
919 global $mmb_core;
920 $mmb_core->get_post_instance();
921 $return = $mmb_core->post_instance->create($params);
922 if (is_int($return)) {
923 mmb_response($return, true);
924 } else {
925 if (isset($return['error'])) {
926 mmb_response($return['error'], false);
927 } else {
928 mmb_response($return, false);
929 }
930 }
931 }
932 }
933
934 if (!function_exists('mmb_change_post_status')) {
935 function mmb_change_post_status($params)
936 {
937 global $mmb_core;
938 $mmb_core->get_post_instance();
939 $return = $mmb_core->post_instance->change_status($params);
940 if (is_wp_error($return)) {
941 mmb_response($return->get_error_message(), false);
942 } elseif (empty($return)) {
943 mmb_response("Post status can not be changed", false);
944 } else {
945 mmb_response($return, true);
946 }
947 }
948 }
949
950 //comments
951 if (!function_exists('mmb_change_comment_status')) {
952 function mmb_change_comment_status($params)
953 {
954 global $mmb_core;
955 $mmb_core->get_comment_instance();
956 $return = $mmb_core->comment_instance->change_status($params);
957 //mmb_response($return, true);
958 if ($return) {
959 $mmb_core->get_stats_instance();
960 mmb_response($mmb_core->stats_instance->get_comments_stats($params), true);
961 } else {
962 mmb_response('Comment not updated', false);
963 }
964 }
965
966 }
967 if (!function_exists('mmb_comment_stats_get')) {
968 function mmb_comment_stats_get($params)
969 {
970 global $mmb_core;
971 $mmb_core->get_stats_instance();
972 mmb_response($mmb_core->stats_instance->get_comments_stats($params), true);
973 }
974 }
975
976 if (!function_exists('mmb_backup_now')) {
977 //backup
978 function mmb_backup_now($params)
979 {
980 global $mmb_core;
981
982 $mmb_core->get_backup_instance();
983 $return = $mmb_core->backup_instance->backup($params);
984
985 if (is_array($return) && array_key_exists('error', $return)) {
986 mmb_response($return['error'], false);
987 } else {
988 mmb_response($return, true);
989 }
990 }
991 }
992
993 if (!function_exists('mwp_ping_backup')) {
994 //ping backup
995 function mwp_ping_backup($params)
996 {
997 global $mmb_core;
998
999 $mmb_core->get_backup_instance();
1000 $return = $mmb_core->backup_instance->ping_backup($params);
1001
1002 if (is_array($return) && array_key_exists('error', $return)) {
1003 mmb_response($return['error'], false);
1004 } else {
1005 mmb_response($return, true);
1006 }
1007 }
1008 }
1009
1010 if (!function_exists('mmb_run_task_now')) {
1011 function mmb_run_task_now($params)
1012 {
1013 global $mmb_core;
1014 $mmb_core->get_backup_instance();
1015
1016 $task_name = isset($params['task_name']) ? $params['task_name'] : false;
1017 $google_drive_token = isset($params['google_drive_token']) ? $params['google_drive_token'] : false;
1018
1019 if ($task_name) {
1020 $return = $mmb_core->backup_instance->task_now($task_name, $google_drive_token);
1021 if (is_array($return) && array_key_exists('error', $return)) {
1022 mmb_response($return['error'], false);
1023 } else {
1024 mmb_response($return, true);
1025 }
1026 } else {
1027 mmb_response("Task name is not provided.", false);
1028 }
1029
1030 }
1031 }
1032
1033 if (!function_exists('mmb_email_backup')) {
1034 function mmb_email_backup($params)
1035 {
1036 global $mmb_core;
1037 $mmb_core->get_backup_instance();
1038 $return = $mmb_core->backup_instance->email_backup($params);
1039
1040 if (is_array($return) && array_key_exists('error', $return)) {
1041 mmb_response($return['error'], false);
1042 } else {
1043 mmb_response($return, true);
1044 }
1045 }
1046 }
1047
1048 if (!function_exists('mmb_check_backup_compat')) {
1049 function mmb_check_backup_compat($params)
1050 {
1051 global $mmb_core;
1052 $mmb_core->get_backup_instance();
1053 $return = $mmb_core->backup_instance->check_backup_compat($params);
1054
1055 if (is_array($return) && array_key_exists('error', $return)) {
1056 mmb_response($return['error'], false);
1057 } else {
1058 mmb_response($return, true);
1059 }
1060 }
1061 }
1062
1063 if (!function_exists('mmb_get_backup_req')) {
1064 function mmb_get_backup_req($params)
1065 {
1066 global $mmb_core;
1067 $mmb_core->get_stats_instance();
1068 $return = $mmb_core->stats_instance->get_backup_req($params);
1069
1070 mmb_response($return, true);
1071 }
1072 }
1073
1074 // Fires when Backup Now, or some backup task is saved.
1075 if (!function_exists('mmb_scheduled_backup')) {
1076 function mmb_scheduled_backup($params)
1077 {
1078 global $mmb_core;
1079 $mmb_core->get_backup_instance();
1080 $return = $mmb_core->backup_instance->set_backup_task($params);
1081 mmb_response($return, $return);
1082 }
1083 }
1084
1085 if (!function_exists('mmm_delete_backup')) {
1086 function mmm_delete_backup($params)
1087 {
1088 global $mmb_core;
1089 $mmb_core->get_backup_instance();
1090 $return = $mmb_core->backup_instance->delete_backup($params);
1091 mmb_response($return, $return);
1092 }
1093 }
1094
1095 if (!function_exists('mmb_optimize_tables')) {
1096 function mmb_optimize_tables($params)
1097 {
1098 global $mmb_core;
1099 $mmb_core->get_backup_instance();
1100 $return = $mmb_core->backup_instance->optimize_tables();
1101 if ($return) {
1102 mmb_response($return, true);
1103 } else {
1104 mmb_response(false, false);
1105 }
1106 }
1107 }
1108 if (!function_exists('mmb_restore_now')) {
1109 function mmb_restore_now($params)
1110 {
1111 global $mmb_core;
1112 $mmb_core->get_backup_instance();
1113 $return = $mmb_core->backup_instance->restore($params);
1114 if (is_array($return) && array_key_exists('error', $return)) {
1115 mmb_response($return['error'], false);
1116 } else {
1117 mmb_response($return, true);
1118 }
1119
1120 }
1121 }
1122
1123 if (!function_exists('mmb_remote_backup_now')) {
1124 function mmb_remote_backup_now($params)
1125 {
1126 global $mmb_core;
1127 $backup_instance = $mmb_core->get_backup_instance();
1128 $return = $mmb_core->backup_instance->remote_backup_now($params);
1129 if (is_array($return) && array_key_exists('error', $return)) {
1130 mmb_response($return['error'], false);
1131 } else {
1132 mmb_response($return, true);
1133 }
1134 }
1135 }
1136
1137
1138 if (!function_exists('mmb_clean_orphan_backups')) {
1139 function mmb_clean_orphan_backups()
1140 {
1141 global $mmb_core;
1142 $backup_instance = $mmb_core->get_backup_instance();
1143 $return = $mmb_core->backup_instance->cleanup();
1144 if (is_array($return)) {
1145 mmb_response($return, true);
1146 } else {
1147 mmb_response($return, false);
1148 }
1149 }
1150 }
1151
1152 function mmb_run_forked_action()
1153 {
1154 if (!isset($_POST['mmb_fork_nonce'])) {
1155 return false;
1156 }
1157
1158 $originalUser = wp_get_current_user();
1159 $usernameUsed = array_key_exists('username', $_POST) ? $_POST : null;
1160
1161 if ($usernameUsed && !is_user_logged_in()) {
1162 $user = function_exists('get_user_by') ? get_user_by('login', $_POST['username']) : get_user_by('login', $_POST['username']);
1163 }
1164
1165 if (isset($user) && isset($user->ID)) {
1166 wp_set_current_user($user->ID);
1167 // Compatibility with All In One Security
1168 update_user_meta($user->ID, 'last_login_time', current_time('mysql'));
1169 }
1170
1171 if (!wp_verify_nonce($_POST['mmb_fork_nonce'], 'mmb-fork-nonce')) {
1172 wp_set_current_user($originalUser->ID);
1173
1174 return false;
1175 }
1176
1177 $public_key = get_option('_worker_public_key');
1178 if (!isset($_POST['public_key']) || $public_key !== $_POST['public_key']) {
1179 wp_set_current_user($originalUser->ID);
1180
1181 return false;
1182 }
1183 $args = @json_decode(stripslashes($_POST['args']), true);
1184 $args['forked'] = true;
1185
1186 if (!isset($args)) {
1187 wp_set_current_user($originalUser->ID);
1188
1189 return false;
1190 }
1191 $cron_action = isset($_POST['mwp_forked_action']) ? $_POST['mwp_forked_action'] : false;
1192 if ($cron_action) {
1193 do_action($cron_action, $args);
1194 }
1195 //unset($_POST['public_key']);
1196 unset($_POST['mmb_fork_nonce']);
1197 unset($_POST['args']);
1198 unset($_POST['mwp_forked_action']);
1199
1200 wp_set_current_user($originalUser->ID);
1201
1202 return true;
1203 }
1204
1205 add_filter('mwp_website_add', 'mmb_readd_backup_task');
1206
1207 if (!function_exists('mmb_readd_backup_task')) {
1208 function mmb_readd_backup_task($params = array())
1209 {
1210 global $mmb_core;
1211 $backup_instance = $mmb_core->get_backup_instance();
1212 $settings = $backup_instance->readd_tasks($params);
1213
1214 return $settings;
1215 }
1216 }
1217
1218 if (!function_exists('mmb_update_worker_plugin')) {
1219 function mmb_update_worker_plugin($params)
1220 {
1221 global $mmb_core;
1222 mmb_response($mmb_core->update_worker_plugin($params), true);
1223 }
1224 }
1225
1226 if (!function_exists('mmb_wp_checkversion')) {
1227 function mmb_wp_checkversion($params)
1228 {
1229 include_once(ABSPATH.'wp-includes/version.php');
1230 global $mmb_wp_version, $mmb_core;
1231 mmb_response($mmb_wp_version, true);
1232 }
1233 }
1234 if (!function_exists('mmb_search_posts_by_term')) {
1235 function mmb_search_posts_by_term($params)
1236 {
1237 global $mmb_core;
1238 $mmb_core->get_search_instance();
1239
1240 $search_type = trim($params['search_type']);
1241 $search_term = strtolower(trim($params['search_term']));
1242
1243 switch ($search_type) {
1244 case 'page_post':
1245 $return = $mmb_core->search_instance->search_posts_by_term($params);
1246 if ($return) {
1247 $return = serialize($return);
1248 mmb_response($return, true);
1249 } else {
1250 mmb_response('No posts found', false);
1251 }
1252 break;
1253
1254 case 'plugin':
1255 $plugins = get_option('active_plugins');
1256
1257 $have_plugin = false;
1258 foreach ($plugins as $plugin) {
1259 if (strpos($plugin, $search_term) > -1) {
1260 $have_plugin = true;
1261 }
1262 }
1263 if ($have_plugin) {
1264 mmb_response(serialize($plugin), true);
1265 } else {
1266 mmb_response(false, false);
1267 }
1268 break;
1269 case 'theme':
1270 $theme = strtolower(get_option('template'));
1271 if (strpos($theme, $search_term) > -1) {
1272 mmb_response($theme, true);
1273 } else {
1274 mmb_response(false, false);
1275 }
1276 break;
1277 default:
1278 mmb_response(false, false);
1279 }
1280 $return = $mmb_core->search_instance->search_posts_by_term($params);
1281
1282
1283 if ($return_if_true) {
1284 mmb_response($return_value, true);
1285 } else {
1286 mmb_response($return_if_false, false);
1287 }
1288 }
1289 }
1290
1291 if (!function_exists('mmb_install_addon')) {
1292 function mmb_install_addon($params)
1293 {
1294 global $mmb_core;
1295 $mmb_core->get_installer_instance();
1296 $return = $mmb_core->installer_instance->install_remote_file($params);
1297 mmb_response($return, true);
1298
1299 }
1300 }
1301
1302 if (!function_exists('mmb_install_addons')) {
1303 function mmb_install_addons($params)
1304 {
1305 global $mmb_core;
1306 $mmb_core->get_installer_instance();
1307 $return = $mmb_core->installer_instance->install_remote_files($params);
1308 mmb_response($return, true);
1309
1310 }
1311 }
1312
1313 if (!function_exists('mmb_do_upgrade')) {
1314 function mmb_do_upgrade($params)
1315 {
1316 global $mmb_core, $mmb_upgrading;
1317 $mmb_core->get_installer_instance();
1318 $return = $mmb_core->installer_instance->do_upgrade($params);
1319 mmb_response($return, true);
1320
1321 }
1322 }
1323
1324 if (!function_exists('mmb_get_links')) {
1325 function mmb_get_links($params)
1326 {
1327 global $mmb_core;
1328 $mmb_core->get_link_instance();
1329 $return = $mmb_core->link_instance->get_links($params);
1330 if (is_array($return) && array_key_exists('error', $return)) {
1331 mmb_response($return['error'], false);
1332 } else {
1333 mmb_response($return, true);
1334 }
1335 }
1336 }
1337
1338 if (!function_exists('mmb_add_link')) {
1339 function mmb_add_link($params)
1340 {
1341 global $mmb_core;
1342 $mmb_core->get_link_instance();
1343 $return = $mmb_core->link_instance->add_link($params);
1344 if (is_array($return) && array_key_exists('error', $return)) {
1345 mmb_response($return['error'], false);
1346 } else {
1347 mmb_response($return, true);
1348 }
1349
1350 }
1351 }
1352
1353 if (!function_exists('mmb_delete_link')) {
1354 function mmb_delete_link($params)
1355 {
1356 global $mmb_core;
1357 $mmb_core->get_link_instance();
1358
1359 $return = $mmb_core->link_instance->delete_link($params);
1360 if (is_array($return) && array_key_exists('error', $return)) {
1361 mmb_response($return['error'], false);
1362 } else {
1363 mmb_response($return, true);
1364 }
1365 }
1366 }
1367
1368 if (!function_exists('mmb_delete_links')) {
1369 function mmb_delete_links($params)
1370 {
1371 global $mmb_core;
1372 $mmb_core->get_link_instance();
1373
1374 $return = $mmb_core->link_instance->delete_links($params);
1375 if (is_array($return) && array_key_exists('error', $return)) {
1376 mmb_response($return['error'], false);
1377 } else {
1378 mmb_response($return, true);
1379 }
1380 }
1381 }
1382
1383 if (!function_exists('mmb_get_comments')) {
1384 function mmb_get_comments($params)
1385 {
1386 global $mmb_core;
1387 $mmb_core->get_comment_instance();
1388 $return = $mmb_core->comment_instance->get_comments($params);
1389 if (is_array($return) && array_key_exists('error', $return)) {
1390 mmb_response($return['error'], false);
1391 } else {
1392 mmb_response($return, true);
1393 }
1394 }
1395 }
1396
1397 if (!function_exists('mmb_action_comment')) {
1398 function mmb_action_comment($params)
1399 {
1400 global $mmb_core;
1401 $mmb_core->get_comment_instance();
1402
1403 $return = $mmb_core->comment_instance->action_comment($params);
1404 if (is_array($return) && array_key_exists('error', $return)) {
1405 mmb_response($return['error'], false);
1406 } else {
1407 mmb_response($return, true);
1408 }
1409 }
1410 }
1411
1412 if (!function_exists('mmb_bulk_action_comments')) {
1413 function mmb_bulk_action_comments($params)
1414 {
1415 global $mmb_core;
1416 $mmb_core->get_comment_instance();
1417
1418 $return = $mmb_core->comment_instance->bulk_action_comments($params);
1419 if (is_array($return) && array_key_exists('error', $return)) {
1420 mmb_response($return['error'], false);
1421 } else {
1422 mmb_response($return, true);
1423 }
1424 }
1425 }
1426
1427 if (!function_exists('mmb_reply_comment')) {
1428 function mmb_reply_comment($params)
1429 {
1430 global $mmb_core;
1431 $mmb_core->get_comment_instance();
1432
1433 $return = $mmb_core->comment_instance->reply_comment($params);
1434 if (is_array($return) && array_key_exists('error', $return)) {
1435 mmb_response($return['error'], false);
1436 } else {
1437 mmb_response($return, true);
1438 }
1439 }
1440 }
1441
1442 if (!function_exists('mmb_add_user')) {
1443 function mmb_add_user($params)
1444 {
1445 global $mmb_core;
1446 $mmb_core->get_user_instance();
1447 $return = $mmb_core->user_instance->add_user($params);
1448 if (is_array($return) && array_key_exists('error', $return)) {
1449 mmb_response($return['error'], false);
1450 } else {
1451 mmb_response($return, true);
1452 }
1453
1454 }
1455 }
1456
1457 if (!function_exists('mbb_security_check')) {
1458 function mbb_security_check($params)
1459 {
1460 global $mmb_core;
1461 $mmb_core->get_security_instance();
1462 $return = $mmb_core->security_instance->security_check($params);
1463 if (is_array($return) && array_key_exists('error', $return)) {
1464 mmb_response($return['error'], false);
1465 } else {
1466 mmb_response($return, true);
1467 }
1468
1469 }
1470 }
1471
1472 if (!function_exists('mbb_security_fix_folder_listing')) {
1473 function mbb_security_fix_folder_listing($params)
1474 {
1475 global $mmb_core;
1476 $mmb_core->get_security_instance();
1477 $return = $mmb_core->security_instance->security_fix_dir_listing($params);
1478 if (is_array($return) && array_key_exists('error', $return)) {
1479 mmb_response($return['error'], false);
1480 } else {
1481 mmb_response($return, true);
1482 }
1483
1484 }
1485 }
1486
1487 if (!function_exists('mbb_security_fix_php_reporting')) {
1488 function mbb_security_fix_php_reporting($params)
1489 {
1490 global $mmb_core;
1491 $mmb_core->get_security_instance();
1492 $return = $mmb_core->security_instance->security_fix_php_reporting($params);
1493 if (is_array($return) && array_key_exists('error', $return)) {
1494 mmb_response($return['error'], false);
1495 } else {
1496 mmb_response($return, true);
1497 }
1498
1499 }
1500 }
1501
1502 if (!function_exists('mbb_security_fix_database_reporting')) {
1503 function mbb_security_fix_database_reporting($params)
1504 {
1505 global $mmb_core;
1506 $mmb_core->get_security_instance();
1507 $return = $mmb_core->security_instance->security_fix_database_reporting($params);
1508 if (is_array($return) && array_key_exists('error', $return)) {
1509 mmb_response($return['error'], false);
1510 } else {
1511 mmb_response($return, true);
1512 }
1513
1514 }
1515 }
1516
1517 //security_fix_wp_version
1518
1519 if (!function_exists('mbb_security_fix_wp_version')) {
1520 function mbb_security_fix_wp_version($params)
1521 {
1522 global $mmb_core;
1523 $mmb_core->get_security_instance();
1524 $return = $mmb_core->security_instance->security_fix_wp_version($params);
1525 if (is_array($return) && array_key_exists('error', $return)) {
1526 mmb_response($return['error'], false);
1527 } else {
1528 mmb_response($return, true);
1529 }
1530
1531 }
1532 }
1533
1534 //mbb_security_fix_admin_username
1535
1536 if (!function_exists('mbb_security_fix_admin_username')) {
1537 function mbb_security_fix_admin_username($params)
1538 {
1539 global $mmb_core;
1540 $mmb_core->get_security_instance();
1541 $return = $mmb_core->security_instance->security_fix_admin_username($params);
1542 if (is_array($return) && array_key_exists('error', $return)) {
1543 mmb_response($return['error'], false);
1544 } else {
1545 mmb_response($return, true);
1546 }
1547
1548 }
1549 }
1550
1551 if (!function_exists('mbb_security_fix_scripts_styles')) {
1552 function mbb_security_fix_scripts_styles($params)
1553 {
1554 global $mmb_core;
1555 $mmb_core->get_security_instance();
1556 $return = $mmb_core->security_instance->security_fix_scripts_styles($params);
1557 if (is_array($return) && array_key_exists('error', $return)) {
1558 mmb_response($return['error'], false);
1559 } else {
1560 mmb_response($return, true);
1561 }
1562
1563 }
1564 }
1565
1566 //mbb_security_fix_file_permission
1567 if (!function_exists('mbb_security_fix_file_permission')) {
1568 function mbb_security_fix_file_permission($params)
1569 {
1570 global $mmb_core;
1571 $mmb_core->get_security_instance();
1572 $return = $mmb_core->security_instance->security_fix_permissions($params);
1573 if (is_array($return) && array_key_exists('error', $return)) {
1574 mmb_response($return['error'], false);
1575 } else {
1576 mmb_response($return, true);
1577 }
1578
1579 }
1580 }
1581
1582 //mbb_security_fix_all
1583 if (!function_exists('mbb_security_fix_all')) {
1584 function mbb_security_fix_all($params)
1585 {
1586 global $mmb_core;
1587 $mmb_core->get_security_instance();
1588 $return = $mmb_core->security_instance->security_fix_all($params);
1589 if (is_array($return) && array_key_exists('error', $return)) {
1590 mmb_response($return['error'], false);
1591 } else {
1592 mmb_response($return, true);
1593 }
1594 }
1595 }
1596
1597 //mbb_security_fix_htaccess_permission
1598
1599 if (!function_exists('mbb_security_fix_htaccess_permission')) {
1600 function mbb_security_fix_htaccess_permission($params)
1601 {
1602 global $mmb_core;
1603 $mmb_core->get_security_instance();
1604 $return = $mmb_core->security_instance->security_fix_htaccess_permission($params);
1605 if (is_array($return) && array_key_exists('error', $return)) {
1606 mmb_response($return['error'], false);
1607 } else {
1608 mmb_response($return, true);
1609 }
1610
1611 }
1612 }
1613
1614 if (!function_exists('mmb_get_users')) {
1615 function mmb_get_users($params)
1616 {
1617 global $mmb_core;
1618 $mmb_core->get_user_instance();
1619 $return = $mmb_core->user_instance->get_users($params);
1620 if (is_array($return) && array_key_exists('error', $return)) {
1621 mmb_response($return['error'], false);
1622 } else {
1623 mmb_response($return, true);
1624 }
1625 }
1626 }
1627
1628 if (!function_exists('mmb_edit_users')) {
1629 function mmb_edit_users($params)
1630 {
1631 global $mmb_core;
1632 $mmb_core->get_user_instance();
1633 $users = $mmb_core->user_instance->edit_users($params);
1634 $response = 'User updated.';
1635 $check_error = false;
1636 foreach ($users as $username => $user) {
1637 $check_error = array_key_exists('error', $user);
1638 if ($check_error) {
1639 $response = $username.': '.$user['error'];
1640 }
1641 }
1642 mmb_response($response, !$check_error);
1643 }
1644 }
1645
1646 if (!function_exists('mmb_get_posts')) {
1647 function mmb_get_posts($params)
1648 {
1649 global $mmb_core;
1650 $mmb_core->get_post_instance();
1651
1652 $return = $mmb_core->post_instance->get_posts($params);
1653 if (is_array($return) && array_key_exists('error', $return)) {
1654 mmb_response($return['error'], false);
1655 } else {
1656 mmb_response($return, true);
1657 }
1658 }
1659 }
1660
1661 if (!function_exists('mmb_delete_post')) {
1662 function mmb_delete_post($params)
1663 {
1664 global $mmb_core;
1665 $mmb_core->get_post_instance();
1666
1667 $return = $mmb_core->post_instance->delete_post($params);
1668 if (is_array($return) && array_key_exists('error', $return)) {
1669 mmb_response($return['error'], false);
1670 } else {
1671 mmb_response($return, true);
1672 }
1673 }
1674 }
1675
1676 if (!function_exists('mmb_delete_posts')) {
1677 function mmb_delete_posts($params)
1678 {
1679 global $mmb_core;
1680 $mmb_core->get_post_instance();
1681
1682 $return = $mmb_core->post_instance->delete_posts($params);
1683 if (is_array($return) && array_key_exists('error', $return)) {
1684 mmb_response($return['error'], false);
1685 } else {
1686 mmb_response($return, true);
1687 }
1688 }
1689 }
1690
1691
1692 if (!function_exists('mmb_edit_posts')) {
1693 function mmb_edit_posts($params)
1694 {
1695 global $mmb_core;
1696 $mmb_core->get_posts_instance();
1697 $return = $mmb_core->posts_instance->edit_posts($params);
1698 mmb_response($return, true);
1699 }
1700 }
1701
1702 if (!function_exists('mmb_get_pages')) {
1703 function mmb_get_pages($params)
1704 {
1705 global $mmb_core;
1706 $mmb_core->get_post_instance();
1707
1708 $return = $mmb_core->post_instance->get_pages($params);
1709 if (is_array($return) && array_key_exists('error', $return)) {
1710 mmb_response($return['error'], false);
1711 } else {
1712 mmb_response($return, true);
1713 }
1714 }
1715 }
1716
1717 if (!function_exists('mmb_delete_page')) {
1718 function mmb_delete_page($params)
1719 {
1720 global $mmb_core;
1721 $mmb_core->get_post_instance();
1722
1723 $return = $mmb_core->post_instance->delete_page($params);
1724 if (is_array($return) && array_key_exists('error', $return)) {
1725 mmb_response($return['error'], false);
1726 } else {
1727 mmb_response($return, true);
1728 }
1729 }
1730 }
1731
1732 if (!function_exists('mmb_iframe_plugins_fix')) {
1733 function mmb_iframe_plugins_fix($update_actions)
1734 {
1735 foreach ($update_actions as $key => $action) {
1736 $update_actions[$key] = str_replace('target="_parent"', '', $action);
1737 }
1738
1739 return $update_actions;
1740
1741 }
1742 }
1743 if (!function_exists('mmb_execute_php_code')) {
1744 function mmb_execute_php_code($params)
1745 {
1746 ob_start();
1747 eval($params['code']);
1748 $return = ob_get_flush();
1749 mmb_response(print_r($return, true), true);
1750 }
1751 }
1752
1753 if (!function_exists('mmb_set_notifications')) {
1754 function mmb_set_notifications($params)
1755 {
1756 global $mmb_core;
1757 $mmb_core->get_stats_instance();
1758 $return = $mmb_core->stats_instance->set_notifications($params);
1759 if (is_array($return) && array_key_exists('error', $return)) {
1760 mmb_response($return['error'], false);
1761 } else {
1762 mmb_response($return, true);
1763 }
1764
1765 }
1766 }
1767
1768 if (!function_exists('mmb_get_dbname')) {
1769 function mmb_get_dbname($params)
1770 {
1771 global $mmb_core;
1772 $mmb_core->get_stats_instance();
1773
1774 $return = $mmb_core->stats_instance->get_active_db();
1775 if (is_array($return) && array_key_exists('error', $return)) {
1776 mmb_response($return['error'], false);
1777 } else {
1778 mmb_response($return, true);
1779 }
1780 }
1781 }
1782
1783 if (!function_exists('mmb_more_reccurences')) {
1784 //Backup Tasks
1785 add_filter('cron_schedules', 'mmb_more_reccurences');
1786 function mmb_more_reccurences($schedules)
1787 {
1788 $schedules['halfminute'] = array('interval' => 30, 'display' => 'Once in a half minute');
1789 $schedules['minutely'] = array('interval' => 60, 'display' => 'Once in a minute');
1790 $schedules['fiveminutes'] = array('interval' => 300, 'display' => 'Once every five minutes');
1791 $schedules['tenminutes'] = array('interval' => 600, 'display' => 'Once every ten minutes');
1792 $schedules['sixhours'] = array('interval' => 21600, 'display' => 'Every six hours');
1793 $schedules['fourhours'] = array('interval' => 14400, 'display' => 'Every four hours');
1794 $schedules['threehours'] = array('interval' => 10800, 'display' => 'Every three hours');
1795
1796 return $schedules;
1797 }
1798 }
1799
1800 add_action('mwp_backup_tasks', 'mwp_check_backup_tasks');
1801
1802 if (!function_exists('mwp_check_backup_tasks')) {
1803 function mwp_check_backup_tasks()
1804 {
1805 global $mmb_core, $_wp_using_ext_object_cache;
1806 $_wp_using_ext_object_cache = false;
1807 $mmb_core->get_backup_instance();
1808 $mmb_core->backup_instance->check_backup_tasks();
1809 }
1810 }
1811
1812 // Remote upload in the second request.
1813 // add_action('mmb_scheduled_remote_upload', 'mmb_call_scheduled_remote_upload');
1814 add_action('mmb_remote_upload', 'mmb_call_scheduled_remote_upload');
1815
1816 if (!function_exists('mmb_call_scheduled_remote_upload')) {
1817 function mmb_call_scheduled_remote_upload($args)
1818 {
1819 global $mmb_core, $_wp_using_ext_object_cache;
1820 $_wp_using_ext_object_cache = false;
1821
1822 $mmb_core->get_backup_instance();
1823 if (isset($args['task_name'])) {
1824 $mmb_core->backup_instance->remote_backup_now($args);
1825 }
1826 }
1827 }
1828
1829 // if (!wp_next_scheduled('mwp_notifications')) {
1830 // wp_schedule_event( time(), 'twicedaily', 'mwp_notifications' );
1831 // }
1832 // add_action('mwp_notifications', 'mwp_check_notifications');
1833
1834 if (!wp_next_scheduled('mwp_datasend')) {
1835 wp_schedule_event(time(), 'threehours', 'mwp_datasend');
1836 }
1837
1838 add_action('mwp_datasend', 'mwp_datasend');
1839
1840 if (!function_exists('mwp_check_notifications')) {
1841 function mwp_check_notifications()
1842 {
1843 global $mmb_core, $_wp_using_ext_object_cache;
1844 $_wp_using_ext_object_cache = false;
1845
1846 $mmb_core->get_stats_instance();
1847 $mmb_core->stats_instance->check_notifications();
1848 }
1849 }
1850
1851
1852 if (!function_exists('mmb_get_plugins_themes')) {
1853 function mmb_get_plugins_themes($params)
1854 {
1855 global $mmb_core;
1856 $mmb_core->get_installer_instance();
1857 $return = $mmb_core->installer_instance->get($params);
1858 mmb_response($return, true);
1859 }
1860 }
1861
1862
1863 if (!function_exists('mmb_get_autoupdate_plugins_themes')) {
1864 function mmb_get_autoupdate_plugins_themes($params)
1865 {
1866 $return = MMB_Updater::getSettings($params);
1867 mmb_response($return, true);
1868 }
1869 }
1870
1871 if (!function_exists('mmb_edit_plugins_themes')) {
1872 function mmb_edit_plugins_themes($params)
1873 {
1874 global $mmb_core;
1875 $mmb_core->get_installer_instance();
1876 $return = $mmb_core->installer_instance->edit($params);
1877 mmb_response($return, true);
1878 }
1879 }
1880
1881 if (!function_exists('mmb_edit_autoupdate_plugins_themes')) {
1882 function mmb_edit_autoupdate_plugins_themes($params)
1883 {
1884 $return = MMB_Updater::setSettings($params);
1885 mmb_response($return, true);
1886 }
1887 }
1888
1889 if (!function_exists('mmb_worker_brand')) {
1890 function mmb_worker_brand($params)
1891 {
1892 update_option("mwp_worker_brand", $params['brand']);
1893 mmb_response(true, true);
1894 }
1895 }
1896
1897 if (!function_exists('mmb_maintenance_mode')) {
1898 function mmb_maintenance_mode($params)
1899 {
1900 global $wp_object_cache;
1901
1902 $default = get_option('mwp_maintenace_mode');
1903 $params = empty($default) ? $params : array_merge($default, $params);
1904 update_option("mwp_maintenace_mode", $params);
1905
1906 if (!empty($wp_object_cache)) {
1907 @$wp_object_cache->flush();
1908 }
1909 mmb_response(true, true);
1910 }
1911 }
1912
1913 if (!function_exists('mmb_plugin_actions')) {
1914 function mmb_plugin_actions()
1915 {
1916 global $mmb_actions, $mmb_core;
1917
1918 if (!empty($mmb_actions)) {
1919 global $_mmb_plugin_actions;
1920 if (!empty($_mmb_plugin_actions)) {
1921 $failed = array();
1922 foreach ($_mmb_plugin_actions as $action => $params) {
1923 if (isset($mmb_actions[$action])) {
1924 call_user_func($mmb_actions[$action], $params);
1925 } else {
1926 $failed[] = $action;
1927 }
1928 }
1929 if (!empty($failed)) {
1930 $f = implode(', ', $failed);
1931 $s = count($f) > 1 ? 'Actions "'.$f.'" do' : 'Action "'.$f.'" does';
1932 mmb_response($s.' not exist. Please update your Worker plugin.', false);
1933 }
1934
1935 }
1936 }
1937
1938 global $pagenow, $current_user, $mmode;
1939 if (!is_admin() && !in_array($pagenow, array('wp-login.php'))) {
1940 $mmode = get_option('mwp_maintenace_mode');
1941 if (!empty($mmode)) {
1942 if (isset($mmode['active']) && $mmode['active'] == true) {
1943 if (isset($current_user->data) && !empty($current_user->data) && isset($mmode['hidecaps']) && !empty($mmode['hidecaps'])) {
1944 $usercaps = array();
1945 if (isset($current_user->caps) && !empty($current_user->caps)) {
1946 $usercaps = $current_user->caps;
1947 }
1948 foreach ($mmode['hidecaps'] as $cap => $hide) {
1949 if (!$hide) {
1950 continue;
1951 }
1952
1953 foreach ($usercaps as $ucap => $val) {
1954 if ($ucap == $cap) {
1955 ob_end_clean();
1956 ob_end_flush();
1957 die($mmode['template']);
1958 }
1959 }
1960 }
1961 } else {
1962 die($mmode['template']);
1963 }
1964 }
1965 }
1966 }
1967
1968 if (file_exists(dirname(__FILE__).'/log')) {
1969 unlink(dirname(__FILE__).'/log');
1970 }
1971 }
1972 }
1973
1974 $mmb_core = $mmb_core_backup = new MMB_Core();
1975
1976 if (isset($_GET['auto_login'])) {
1977 $mmb_core->automatic_login();
1978 }
1979
1980 MMB_Updater::register();
1981
1982
1983 if (!function_exists('mwp_return_core_reference')) {
1984 function mwp_return_core_reference()
1985 {
1986 global $mmb_core, $mmb_core_backup;
1987 if (!$mmb_core instanceof MMB_Core) {
1988 $mmb_core = $mmb_core_backup;
1989 }
1990 }
1991 }
1992
1993 if (function_exists('register_activation_hook')) {
1994 register_activation_hook(__FILE__, array($mmb_core, 'install'));
1995 }
1996
1997 if (function_exists('register_deactivation_hook')) {
1998 register_deactivation_hook(__FILE__, array($mmb_core, 'uninstall'));
1999 }
2000
2001 if (function_exists('add_action')) {
2002 add_action('init', 'mmb_plugin_actions', 99999);
2003 }
2004
2005 if (function_exists('add_filter')) {
2006 add_filter('install_plugin_complete_actions', 'mmb_iframe_plugins_fix');
2007 }
2008
2009 if (!function_exists('mwb_edit_redirect_override')) {
2010 function mwb_edit_redirect_override($location = false, $comment_id = false)
2011 {
2012 if (isset($_COOKIE[MMB_XFRAME_COOKIE])) {
2013 $location = get_site_url().'/wp-admin/edit-comments.php';
2014 }
2015
2016 return $location;
2017 }
2018 }
2019 if (function_exists('add_filter')) {
2020 add_filter('comment_edit_redirect', 'mwb_edit_redirect_override');
2021 }
2022
2023 if (isset($_COOKIE[MMB_XFRAME_COOKIE])) {
2024 remove_action('admin_init', 'send_frame_options_header');
2025 remove_action('login_init', 'send_frame_options_header');
2026 }
2027
2028 if (get_option('mwp_remove_php_reporting') == 'T') {
2029 @error_reporting(0);
2030 @ini_set('display_errors', 'off');
2031 @ini_set('display_startup_errors', "off");
2032 }
2033
2034 if (get_option('mwp_remove_wp_version') == 'T') {
2035 remove_action('wp_head', 'wp_generator');
2036 remove_filter('wp_head', 'wp_generator');
2037 }
2038 if (get_option('managewp_remove_styles_version') == 'T') {
2039 global $wp_styles;
2040 if (!is_a($wp_styles, 'WP_Styles')) {
2041 return;
2042 }
2043
2044 foreach ($wp_styles->registered as $handle => $style) {
2045 $wp_styles->registered[$handle]->ver = null;
2046 }
2047 }
2048 if (get_option('managewp_remove_scripts_version') == 'T') {
2049 global $wp_scripts;
2050 if (!is_a($wp_scripts, 'WP_Scripts')) {
2051 return;
2052 }
2053
2054 foreach ($wp_scripts->registered as $handle => $script) {
2055 $wp_scripts->registered[$handle]->ver = null;
2056 }
2057 }
2058
2059 if (wp_next_scheduled('mwp_backup_tasks')) {
2060 wp_clear_scheduled_hook('mwp_backup_tasks');
2061 }
2062
2063 $activePlugins = get_option('active_plugins');
2064 if (reset($activePlugins) !== 'worker/init.php') {
2065 $workerKey = array_search('worker/init.php', $activePlugins);
2066 if ($workerKey !== false) {
2067 unset($activePlugins[$workerKey]);
2068 array_unshift($activePlugins, 'worker/init.php');
2069 update_option('active_plugins', $activePlugins);
2070 }
2071 }
2072