PluginProbe
ManageWP Worker / 3.9.8
ManageWP Worker v3.9.8
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.8, at init.php

670 lines 18.4 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: http://managewp.com/
5 Description: Manage all your blogs from one dashboard. Visit <a href="http://managewp.com">ManageWP.com</a> to sign up.
6 Author: Prelovac Media
7 Version: 3.9.8
8 Author URI: http://www.prelovac.com
9 */
10
11 /*************************************************************
12 *
13 * init.php
14 *
15 * Initialize the communication with master
16 *
17 *
18 * Copyright (c) 2011 Prelovac Media
19 * www.prelovac.com
20 **************************************************************/
21
22
23 define('MMB_WORKER_VERSION', '3.9.8');
24
25 global $wpdb, $mmb_plugin_dir, $mmb_plugin_url;
26
27 if (version_compare(PHP_VERSION, '5.0.0', '<')) // min version 5 supported
28 exit("<p>ManageWP Worker plugin requires PHP 5 or higher.</p>");
29
30
31
32 global $wp_version;
33
34 $mmb_wp_version = $wp_version;
35 $mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
36 $mmb_plugin_url = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__));
37
38 $mmb_actions = array(
39 'remove_site' => 'mmb_remove_site',
40 'get_stats' => 'mmb_stats_get',
41 'backup_clone' => 'mmb_backup_now',
42 'restore' => 'mmb_restore_now',
43 'optimize_tables' => 'mmb_optimize_tables',
44 'check_wp_version' => 'mmb_wp_checkversion',
45 'create_post' => 'mmb_post_create',
46 'update_worker' => 'mmb_update_worker_plugin',
47 'change_comment_status' => 'mmb_change_comment_status',
48 'change_post_status' => 'mmb_change_post_status',
49 'get_comment_stats' => 'mmb_comment_stats_get',
50 'install_addon' => 'mmb_install_addon',
51 'do_upgrade' => 'mmb_do_upgrade',
52 'add_link' => 'mmb_add_link',
53 'add_user' => 'mmb_add_user',
54 'email_backup' => 'mmb_email_backup',
55 'check_backup_compat' => 'mmb_check_backup_compat',
56 'scheduled_backup' => 'mmb_scheduled_backup',
57 'execute_php_code' => 'mmb_execute_php_code',
58 'delete_backup' => 'mmm_delete_backup',
59 'remote_backup_now' => 'mmb_remote_backup_now',
60 'set_notifications' => 'mmb_set_notifications',
61 'clean_orphan_backups' => 'mmb_clean_orphan_backups'
62 );
63
64 require_once("$mmb_plugin_dir/helper.class.php");
65 require_once("$mmb_plugin_dir/core.class.php");
66 require_once("$mmb_plugin_dir/post.class.php");
67 require_once("$mmb_plugin_dir/comment.class.php");
68 require_once("$mmb_plugin_dir/stats.class.php");
69 require_once("$mmb_plugin_dir/backup.class.php");
70 require_once("$mmb_plugin_dir/installer.class.php");
71 require_once("$mmb_plugin_dir/link.class.php");
72 require_once("$mmb_plugin_dir/user.class.php");
73 require_once("$mmb_plugin_dir/api.php");
74
75 require_once("$mmb_plugin_dir/plugins/search/search.php");
76 require_once("$mmb_plugin_dir/plugins/cleanup/cleanup.php");
77
78 //this is an exmaple plugin for extra_html element
79 //require_once("$mmb_plugin_dir/plugins/extra_html_example/extra_html_example.php");
80
81 $mmb_core = new MMB_Core();
82 if( microtime(true) - (double)get_option('mwp_iframe_options_header') < 3600 ){
83 remove_action( 'admin_init', 'send_frame_options_header');
84 remove_action( 'login_init', 'send_frame_options_header');
85 }
86
87 add_action('init', 'mmb_parse_request');
88
89
90 if (function_exists('register_activation_hook'))
91 register_activation_hook(__FILE__, array(
92 $mmb_core,
93 'install'
94 ));
95
96 if (function_exists('register_deactivation_hook'))
97 register_deactivation_hook(__FILE__, array(
98 $mmb_core,
99 'uninstall'
100 ));
101 do_action('after_db_upgrade');
102 if( !function_exists ( 'mmb_parse_request' )) {
103
104 function mmb_parse_request()
105 {
106
107 if (!isset($HTTP_RAW_POST_DATA)) {
108 $HTTP_RAW_POST_DATA = file_get_contents('php://input');
109 }
110 ob_start();
111
112 global $mmb_core, $mmb_actions, $new_actions, $wp_db_version, $wpmu_version, $_wp_using_ext_object_cache;
113
114 $data = base64_decode($HTTP_RAW_POST_DATA);
115 if ($data)
116 $num = @extract(unserialize($data));
117
118 if ($action) {
119 $_wp_using_ext_object_cache = false;
120 @set_time_limit(600);
121
122 update_option('mwp_iframe_options_header', microtime(true));
123 // mmb_response($mmb_actions, false);
124 if (!$mmb_core->check_if_user_exists($params['username']))
125 mmb_response('Username <b>' . $params['username'] . '</b> does not have administrator capabilities. Enter the correct username in the site options.', false);
126
127 /* in case database upgrade required, do database backup and perform upgrade ( wordpress wp_upgrade() function ) */
128 if( strlen(trim($wp_db_version)) ){
129 if ( get_option('db_version') != $wp_db_version ) {
130 /* in multisite network, please update database manualy */
131 if (empty($wpmu_version) || (function_exists('is_multisite') && !is_multisite())){
132 if( ! function_exists('wp_upgrade'))
133 include_once(ABSPATH.'wp-admin/includes/upgrade.php');
134
135 ob_clean();
136 @wp_upgrade();
137 @do_action('after_db_upgrade');
138 ob_end_clean();
139 }
140 }
141 }
142
143 if ($action == 'add_site') {
144 mmb_add_site($params);
145 mmb_response('You should never see this.', false);
146 }
147 $auth = $mmb_core->authenticate_message($action . $id, $signature, $id);
148 if ($auth === true) {
149 if(isset($params['secure'])){
150 if($decrypted = $mmb_core->_secure_data($params['secure'])){
151 $decrypted = maybe_unserialize($decrypted);
152 if(is_array($decrypted)){
153 foreach($decrypted as $key => $val){
154 if(!is_numeric($key))
155 $params[$key] = $val;
156 }
157 unset($params['secure']);
158 } else $params['secure'] = $decrypted;
159 }
160 }
161
162 if (array_key_exists($action, $mmb_actions) && function_exists($mmb_actions[$action]))
163 call_user_func($mmb_actions[$action], $params);
164 else
165 mmb_response('Action "' . $action . '" does not exist. Please update your Worker plugin.', false);
166 } else {
167 mmb_response($auth['error'], false);
168 }
169 }
170
171
172 ob_end_clean();
173 }
174 }
175 /* Main response function */
176 if( !function_exists ( 'mmb_response' )) {
177
178 function mmb_response($response = false, $success = true)
179 {
180 $return = array();
181
182 if ((is_array($response) && empty($response)) || (!is_array($response) && strlen($response) == 0))
183 $return['error'] = 'Empty response.';
184 else if ($success)
185 $return['success'] = $response;
186 else
187 $return['error'] = $response;
188
189 if( !headers_sent() ){
190 header('HTTP/1.0 200 OK');
191 header('Content-Type: text/plain');
192 }
193 exit("<MWPHEADER>" . base64_encode(serialize($return))."<ENDMWPHEADER>");
194 }
195 }
196
197
198
199 if( !function_exists ( 'mmb_add_site' )) {
200 function mmb_add_site($params)
201 {
202 global $mmb_core;
203
204 $num = extract($params);
205
206
207 if ($num) {
208 if (!get_option('_action_message_id') && !get_option('_worker_public_key')) {
209 $public_key = base64_decode($public_key);
210
211 if (function_exists('openssl_verify')) {
212 $verify = openssl_verify($action . $id, base64_decode($signature), $public_key);
213 if ($verify == 1) {
214 $mmb_core->set_master_public_key($public_key);
215 $mmb_core->set_worker_message_id($id);
216 $mmb_core->get_stats_instance();
217 if(is_array($notifications) && !empty($notifications)){
218 $mmb_core->stats_instance->set_notifications($notifications);
219 }
220 mmb_response($mmb_core->stats_instance->get_initial_stats(), true);
221 } else if ($verify == 0) {
222 mmb_response('Invalid message signature. Please contact us if you see this message often.', false);
223 } else {
224 mmb_response('Command not successful. Please try again.', false);
225 }
226 } else {
227 if (!get_option('_worker_nossl_key')) {
228 srand();
229
230 $random_key = md5(base64_encode($public_key) . rand(0, getrandmax()));
231
232 $mmb_core->set_random_signature($random_key);
233 $mmb_core->set_worker_message_id($id);
234 $mmb_core->set_master_public_key($public_key);
235 $mmb_core->get_stats_instance();
236 $mmb_core->get_stats_instance();
237 if(is_array($notifications) && !empty($notifications)){
238 $mmb_core->stats_instance->set_notifications($notifications);
239 }
240 mmb_response($mmb_core->stats_instance->get_initial_stats(), true);
241 } else
242 mmb_response('Please deactivate & activate ManageWP Worker plugin on your site, then re-add the site to your dashboard.', false);
243 }
244 } else {
245 mmb_response('Please deactivate & activate ManageWP Worker plugin on your site and re-add the site to your dashboard.', false);
246 }
247 } else {
248 mmb_response('Invalid parameters received. Please try again.', false);
249 }
250 }
251 }
252
253 if( !function_exists ( 'mmb_remove_site' )) {
254 function mmb_remove_site($params)
255 {
256 extract($params);
257 global $mmb_core;
258 $mmb_core->uninstall();
259
260 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
261 $plugin_slug = basename(dirname(__FILE__)) . '/' . basename(__FILE__);
262
263 if ($deactivate) {
264 deactivate_plugins($plugin_slug, true);
265 }
266
267 if (!is_plugin_active($plugin_slug))
268 mmb_response(array(
269 'deactivated' => 'Site removed successfully. <br /><br />ManageWP Worker plugin successfully deactivated.'
270 ), true);
271 else
272 mmb_response(array(
273 'removed_data' => 'Site removed successfully. <br /><br /><b>ManageWP Worker plugin was not deactivated.</b>'
274 ), true);
275
276 }
277 }
278 if( !function_exists ( 'mmb_stats_get' )) {
279 function mmb_stats_get($params)
280 {
281 global $mmb_core;
282 $mmb_core->get_stats_instance();
283 mmb_response($mmb_core->stats_instance->get($params), true);
284 }
285 }
286
287 //post
288 if( !function_exists ( 'mmb_post_create' )) {
289 function mmb_post_create($params)
290 {
291 global $mmb_core;
292 $mmb_core->get_post_instance();
293 $return = $mmb_core->post_instance->create($params);
294 if (is_int($return))
295 mmb_response($return, true);
296 else
297 mmb_response($return, false);
298 }
299 }
300
301 if( !function_exists ( 'mmb_change_post_status' )) {
302 function mmb_change_post_status($params)
303 {
304 global $mmb_core;
305 $mmb_core->get_post_instance();
306 $return = $mmb_core->post_instance->change_status($params);
307 //mmb_response($return, true);
308
309 }
310 }
311
312 //comments
313 if( !function_exists ( 'mmb_change_comment_status' )) {
314 function mmb_change_comment_status($params)
315 {
316 global $mmb_core;
317 $mmb_core->get_comment_instance();
318 $return = $mmb_core->comment_instance->change_status($params);
319 //mmb_response($return, true);
320 if ($return){
321 $mmb_core->get_stats_instance();
322 mmb_response($mmb_core->stats_instance->get_comments_stats($params), true);
323 }else
324 mmb_response('Comment not updated', false);
325 }
326
327 }
328 if( !function_exists ( 'mmb_comment_stats_get' )) {
329 function mmb_comment_stats_get($params)
330 {
331 global $mmb_core;
332 $mmb_core->get_stats_instance();
333 mmb_response($mmb_core->stats_instance->get_comments_stats($params), true);
334 }
335 }
336
337 if( !function_exists ( 'mmb_backup_now' )) {
338 //backup
339 function mmb_backup_now($params)
340 {
341 global $mmb_core;
342
343 $mmb_core->get_backup_instance();
344 $return = $mmb_core->backup_instance->backup($params);
345
346 if (is_array($return) && array_key_exists('error', $return))
347 mmb_response($return['error'], false);
348 else {
349 mmb_response($return, true);
350 }
351 }
352 }
353
354 if( !function_exists ( 'mmb_email_backup' )) {
355 function mmb_email_backup($params)
356 {
357 global $mmb_core;
358 $mmb_core->get_backup_instance();
359 $return = $mmb_core->backup_instance->email_backup($params);
360
361 if (is_array($return) && array_key_exists('error', $return))
362 mmb_response($return['error'], false);
363 else {
364 mmb_response($return, true);
365 }
366 }
367 }
368 if( !function_exists ( 'mmb_check_backup_compat' )) {
369 function mmb_check_backup_compat($params)
370 {
371 global $mmb_core;
372 $mmb_core->get_backup_instance();
373 $return = $mmb_core->backup_instance->check_backup_compat($params);
374
375 if (is_array($return) && array_key_exists('error', $return))
376 mmb_response($return['error'], false);
377 else {
378 mmb_response($return, true);
379 }
380 }
381 }
382
383 if( !function_exists ( 'mmb_scheduled_backup' )) {
384 function mmb_scheduled_backup($params)
385 {
386
387 global $mmb_core;
388 $mmb_core->get_backup_instance();
389 $return = $mmb_core->backup_instance->set_backup_task($params);
390 mmb_response($return, $return);
391 }
392 }
393
394 if( !function_exists ( 'mmm_delete_backup' )) {
395 function mmm_delete_backup($params)
396 {
397 global $mmb_core;
398 $mmb_core->get_backup_instance();
399 $return = $mmb_core->backup_instance->delete_backup($params);
400 mmb_response($return, $return);
401 }
402 }
403
404 if( !function_exists ( 'mmb_optimize_tables' )) {
405 function mmb_optimize_tables($params)
406 {
407 global $mmb_core;
408 $mmb_core->get_backup_instance();
409 $return = $mmb_core->backup_instance->optimize_tables();
410 if ($return)
411 mmb_response($return, true);
412 else
413 mmb_response(false, false);
414 }
415 }
416 if( !function_exists ( 'mmb_restore_now' )) {
417 function mmb_restore_now($params)
418 {
419 global $mmb_core;
420 $mmb_core->get_backup_instance();
421 $return = $mmb_core->backup_instance->restore($params);
422 if (is_array($return) && array_key_exists('error', $return))
423 mmb_response($return['error'], false);
424 else
425 mmb_response($return, true);
426
427 }
428 }
429
430 if( !function_exists ( 'mmb_remote_backup_now' )) {
431 function mmb_remote_backup_now($params)
432 {
433 global $mmb_core;
434 $backup_instance = $mmb_core->get_backup_instance();
435 $return = $mmb_core->backup_instance->remote_backup_now($params);
436 if (is_array($return) && array_key_exists('error', $return))
437 mmb_response($return['error'], false);
438 else
439 mmb_response($return, true);
440 }
441 }
442
443
444 if( !function_exists ( 'mmb_clean_orphan_backups' )) {
445 function mmb_clean_orphan_backups()
446 {
447 global $mmb_core;
448 $backup_instance = $mmb_core->get_backup_instance();
449 $return = $mmb_core->backup_instance->cleanup();
450 if(is_array($return))
451 mmb_response($return, true);
452 else
453 mmb_response($return, false);
454 }
455 }
456
457 if( !function_exists ( 'mmb_update_worker_plugin' )) {
458 function mmb_update_worker_plugin($params)
459 {
460 global $mmb_core;
461 mmb_response($mmb_core->update_worker_plugin($params), true);
462 }
463 }
464
465 if( !function_exists ( 'mmb_wp_checkversion' )) {
466 function mmb_wp_checkversion($params)
467 {
468 include_once(ABSPATH . 'wp-includes/version.php');
469 global $mmb_wp_version, $mmb_core;
470 mmb_response($mmb_wp_version, true);
471 }
472 }
473 if( !function_exists ( 'mmb_search_posts_by_term' )) {
474 function mmb_search_posts_by_term($params)
475 {
476 global $mmb_core;
477 $mmb_core->get_search_instance();
478
479 $search_type = trim($params['search_type']);
480 $search_term = strtolower(trim($params['search_term']));
481
482 switch ($search_type){
483 case 'page_post':
484 $return = $mmb_core->search_instance->search_posts_by_term($params);
485 if($return){
486 $return = serialize($return);
487 mmb_response($return, true);
488 }else{
489 mmb_response('No posts found', false);
490 }
491 break;
492
493 case 'plugin':
494 $plugins = get_option('active_plugins');
495
496 $have_plugin = false;
497 foreach ($plugins as $plugin) {
498 if(strpos($plugin, $search_term)>-1){
499 $have_plugin = true;
500 }
501 }
502 if($have_plugin){
503 mmb_response(serialize($plugin), true);
504 }else{
505 mmb_response(false, false);
506 }
507 break;
508 case 'theme':
509 $theme = strtolower(get_option('template'));
510 if(strpos($theme, $search_term)>-1){
511 mmb_response($theme, true);
512 }else{
513 mmb_response(false, false);
514 }
515 break;
516 default: mmb_response(false, false);
517 }
518 $return = $mmb_core->search_instance->search_posts_by_term($params);
519
520
521
522 if ($return_if_true) {
523 mmb_response($return_value, true);
524 } else {
525 mmb_response($return_if_false, false);
526 }
527 }
528 }
529
530 if( !function_exists ( 'mmb_install_addon' )) {
531 function mmb_install_addon($params)
532 {
533 global $mmb_core;
534 $mmb_core->get_installer_instance();
535 $return = $mmb_core->installer_instance->install_remote_file($params);
536 mmb_response($return, true);
537
538 }
539 }
540
541 if( !function_exists ( 'mmb_do_upgrade' )) {
542 function mmb_do_upgrade($params)
543 {
544 global $mmb_core, $mmb_upgrading;
545 $mmb_core->get_installer_instance();
546 $return = $mmb_core->installer_instance->do_upgrade($params);
547 mmb_response($return, true);
548
549 }
550 }
551 if( !function_exists ( 'mmb_add_link' )) {
552 function mmb_add_link($params)
553 {
554 global $mmb_core;
555 $mmb_core->get_link_instance();
556 $return = $mmb_core->link_instance->add_link($params);
557 if (is_array($return) && array_key_exists('error', $return))
558
559 mmb_response($return['error'], false);
560 else {
561 mmb_response($return, true);
562 }
563
564 }
565 }
566
567
568 if( !function_exists ( 'mmb_add_user' )) {
569 function mmb_add_user($params)
570 {
571 global $mmb_core;
572 $mmb_core->get_user_instance();
573 $return = $mmb_core->user_instance->add_user($params);
574 if (is_array($return) && array_key_exists('error', $return))
575
576 mmb_response($return['error'], false);
577 else {
578 mmb_response($return, true);
579 }
580
581 }
582 }
583 add_filter('install_plugin_complete_actions','mmb_iframe_plugins_fix');
584 if( !function_exists ( 'mmb_iframe_plugins_fix' )) {
585 function mmb_iframe_plugins_fix($update_actions)
586 {
587 foreach($update_actions as $key => $action)
588 {
589 $update_actions[$key] = str_replace('target="_parent"','',$action);
590 }
591
592 return $update_actions;
593
594 }
595 }
596 if( !function_exists ( 'mmb_execute_php_code' )) {
597 function mmb_execute_php_code($params)
598 {
599 ob_start();
600 eval($params['code']);
601 $return = ob_get_flush();
602 mmb_response(print_r($return, true), true);
603 }
604 }
605
606 if( !function_exists ( 'mmb_set_notifications' )) {
607 function mmb_set_notifications($params)
608 {
609 global $mmb_core;
610 $mmb_core->get_stats_instance();
611 $return = $mmb_core->stats_instance->set_notifications($params);
612 if (is_array($return) && array_key_exists('error', $return))
613 mmb_response($return['error'], false);
614 else {
615 mmb_response($return, true);
616 }
617
618 }
619 }
620
621 if(!function_exists('mmb_more_reccurences')){
622 //Backup Tasks
623 add_filter('cron_schedules', 'mmb_more_reccurences');
624 function mmb_more_reccurences($schedules) {
625
626 $schedules['minutely'] = array('interval' => 60, 'display' => 'Once in a minute');
627 $schedules['fiveminutes'] = array('interval' => 300, 'display' => 'Once every five minutes');
628 $schedules['tenminutes'] = array('interval' => 600, 'display' => 'Once every ten minutes');
629
630 return $schedules;
631 }
632 }
633
634
635 if (!wp_next_scheduled('mwp_backup_tasks')) {
636 wp_schedule_event( time(), 'tenminutes', 'mwp_backup_tasks' );
637 }
638 add_action('mwp_backup_tasks', 'mwp_check_backup_tasks');
639
640
641
642 if( !function_exists('mwp_check_backup_tasks') ){
643 function mwp_check_backup_tasks() {
644 global $mmb_core, $_wp_using_ext_object_cache;
645 $_wp_using_ext_object_cache = false;
646
647 $mmb_core->get_backup_instance();
648 $mmb_core->backup_instance->check_backup_tasks();
649 }
650 }
651
652 if (!wp_next_scheduled('mwp_notifications')) {
653 wp_schedule_event( time(), 'daily', 'mwp_notifications' );
654 }
655 add_action('mwp_notifications', 'mwp_check_notifications');
656
657
658
659 if( !function_exists('mwp_check_notifications') ){
660 function mwp_check_notifications() {
661 global $mmb_core, $_wp_using_ext_object_cache;
662 $_wp_using_ext_object_cache = false;
663
664 $mmb_core->get_stats_instance();
665 $mmb_core->stats_instance->check_notifications();
666 }
667 }
668
669 ?>
670