PluginProbe
ManageWP Worker / 3.9.2
ManageWP Worker v3.9.2
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.2, at init.php

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