PluginProbe
ManageWP Worker / 3.9.5
ManageWP Worker v3.9.5
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.5, at init.php

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