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

401 lines 11.6 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
6 Author: Prelovac Media
7 Version: 3.8.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.8.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 global $wp_version;
31
32 $mmb_wp_version = $wp_version;
33 $mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
34 $mmb_plugin_url = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__));
35
36 $mmb_actions = array(
37 'remove_site' => 'mmb_remove_site',
38 'get_stats' => 'mmb_stats_get',
39 'get_stats_notification' => 'mmb_get_stats_notification',
40 'backup' => 'mmb_backup_now',
41 'restore' => 'mmb_restore_now',
42 'optimize_tables' => 'mmb_optimize_tables',
43 'check_wp_version' => 'mmb_wp_checkversion',
44 'create_post' => 'mmb_post_create',
45 'update_worker' => 'mmb_update_worker_plugin',
46 'change_comment_status' => 'mmb_change_comment_status',
47 'change_post_status' => 'mmb_change_post_status',
48 'get_comment_stats' => 'mmb_comment_stats_get',
49 'install_addon' => 'mmb_install_addon',
50 'do_upgrade' => 'mmb_do_upgrade',
51 'add_link' => 'mmb_add_link',
52 'email_backup' => 'mmb_email_backup',
53 'check_backup_compat' => 'mmb_check_backup_compat'
54 );
55
56 require_once("$mmb_plugin_dir/helper.class.php");
57 require_once("$mmb_plugin_dir/core.class.php");
58 require_once("$mmb_plugin_dir/post.class.php");
59 require_once("$mmb_plugin_dir/comment.class.php");
60 require_once("$mmb_plugin_dir/stats.class.php");
61 require_once("$mmb_plugin_dir/backup.class.php");
62 require_once("$mmb_plugin_dir/installer.class.php");
63 require_once("$mmb_plugin_dir/link.class.php");
64 require_once("$mmb_plugin_dir/api.php");
65
66 require_once("$mmb_plugin_dir/plugins/search/search.php");
67 require_once("$mmb_plugin_dir/plugins/cleanup/cleanup.php");
68
69 //this is an exmaple plugin for extra_html element
70 //require_once("$mmb_plugin_dir/plugins/extra_html_example/extra_html_example.php");
71
72 $mmb_core = new MMB_Core();
73 add_action('init', 'mmb_parse_request');
74
75 if (function_exists('register_activation_hook'))
76 register_activation_hook(__FILE__, array(
77 $mmb_core,
78 'install'
79 ));
80
81 if (function_exists('register_deactivation_hook'))
82 register_deactivation_hook(__FILE__, array(
83 $mmb_core,
84 'uninstall'
85 ));
86
87
88
89 function mmb_parse_request()
90 {
91 if (!isset($HTTP_RAW_POST_DATA)) {
92 $HTTP_RAW_POST_DATA = file_get_contents('php://input');
93 }
94 ob_start();
95
96 global $mmb_core, $mmb_actions, $new_actions;
97
98 $data = base64_decode($HTTP_RAW_POST_DATA);
99 if ($data)
100 $num = @extract(unserialize($data));
101
102 if ($action) {
103 // mmb_response($mmb_actions, false);
104 if (!$mmb_core->check_if_user_exists($params['username']))
105 mmb_response('Username <b>' . $params['username'] . '</b> does not have administrator capabilities. Enter the correct username in the site options.', false);
106
107 if ($action == 'add_site') {
108 mmb_add_site($params);
109 mmb_response('You should never see this.', false);
110 }
111
112 $auth = $mmb_core->authenticate_message($action . $id, $signature, $id);
113 if ($auth === true) {
114 if (array_key_exists($action, $mmb_actions) && function_exists($mmb_actions[$action]))
115 call_user_func($mmb_actions[$action], $params);
116 else
117 mmb_response('Action "' . $action . '" does not exist.', false);
118 } else {
119 mmb_response($auth['error'], false);
120 }
121 }
122
123
124 ob_end_clean();
125 }
126
127 /* Main response function */
128
129 function mmb_response($response = false, $success = true)
130 {
131 $return = array();
132
133 if (empty($response))
134 $return['error'] = 'Empty response.';
135 else if ($success)
136 $return['success'] = $response;
137 else
138 $return['error'] = $response;
139
140 header('Content-Type: text/plain');
141 exit(PHP_EOL . base64_encode(serialize($return)));
142 }
143
144 function mmb_add_site($params)
145 {
146 global $mmb_core;
147
148 $num = extract($params);
149
150 if ($num) {
151 if (!get_option('_action_message_id') && !get_option('_worker_public_key')) {
152 $public_key = base64_decode($public_key);
153
154 if (function_exists('openssl_verify')) {
155 $verify = openssl_verify($action . $id, base64_decode($signature), $public_key);
156 if ($verify == 1) {
157 $mmb_core->set_master_public_key($public_key);
158 $mmb_core->set_worker_message_id($id);
159 $mmb_core->get_stats_instance();
160 mmb_response($mmb_core->stats_instance->get_initial_stats(), true);
161 } else if ($verify == 0) {
162 mmb_response('Invalid message signature. Please contact us if you see this message often.', false);
163 } else {
164 mmb_response('Command not successful. Please try again.', false);
165 }
166 } else {
167 if (!get_option('_worker_nossl_key')) {
168 srand();
169 $random_key = md5(base64_encode($public_key) . rand(0, getrandmax()));
170
171 $mmb_core->set_random_signature($random_key);
172 $mmb_core->set_worker_message_id($id);
173 $mmb_core->set_master_public_key($public_key);
174 $mmb_core->get_stats_instance();
175 mmb_response($mmb_core->stats_instance->get_initial_stats(), true);
176 } else
177 mmb_response('Please deactivate & activate ManageWP Worker plugin on your site, then re-add the site to your dashboard.', false);
178 }
179 } else {
180 mmb_response('Please deactivate & activate ManageWP Worker plugin on your site and re-add the site to your dashboard.', false);
181 }
182 } else {
183 mmb_response('Invalid parameters received. Please try again.', false);
184 }
185 }
186
187 function mmb_remove_site($params)
188 {
189 extract($params);
190 global $mmb_core;
191 $mmb_core->uninstall();
192
193 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
194 $plugin_slug = basename(dirname(__FILE__)) . '/' . basename(__FILE__);
195
196 if ($deactivate) {
197 deactivate_plugins($plugin_slug, true);
198 }
199
200 if (!is_plugin_active($plugin_slug))
201 mmb_response(array(
202 'deactivated' => 'Site removed successfully. <br /><br />ManageWP Worker plugin successfully deactivated.'
203 ), true);
204 else
205 mmb_response(array(
206 'removed_data' => 'Site removed successfully. <br /><br /><b>ManageWP Worker plugin was not deactivated.</b>'
207 ), true);
208
209 }
210
211
212 function mmb_stats_get($params)
213 {
214 global $mmb_core;
215 $mmb_core->get_stats_instance();
216 mmb_response($mmb_core->stats_instance->get($params), true);
217 }
218 function mmb_get_stats_notification($params)
219 {
220 global $mmb_core;
221 $mmb_core->get_stats_instance();
222 $stat = $mmb_core->stats_instance->get_stats_notification($params);
223 mmb_response($stat, true);
224 }
225
226 //post
227 function mmb_post_create($params)
228 {
229 global $mmb_core;
230 $mmb_core->get_post_instance();
231 $return = $mmb_core->post_instance->create($params);
232 if (is_int($return))
233 mmb_response($return, true);
234 else
235 mmb_response($return, false);
236 }
237 function mmb_change_post_status($params)
238 {
239 global $mmb_core;
240 $mmb_core->get_post_instance();
241 $return = $mmb_core->post_instance->change_status($params);
242 //mmb_response($return, true);
243
244 }
245 //comments
246 function mmb_change_comment_status($params)
247 {
248
249 global $mmb_core;
250 $mmb_core->get_comment_instance();
251 $return = $mmb_core->comment_instance->change_status($params);
252 //mmb_response($return, true);
253 if ($return){
254 $mmb_core->get_stats_instance();
255 mmb_response($mmb_core->stats_instance->get_comments_stats($params), true);
256 }else
257 mmb_response('Comment not updated', false);
258 }
259 function mmb_comment_stats_get($params)
260 {
261 global $mmb_core;
262 $mmb_core->get_stats_instance();
263 mmb_response($mmb_core->stats_instance->get_comments_stats($params), true);
264 }
265
266 //backup
267 function mmb_backup_now($params)
268 {
269 global $mmb_core;
270 $mmb_core->get_backup_instance();
271 $return = $mmb_core->backup_instance->backup($params);
272
273 if (is_array($return) && array_key_exists('error', $return))
274 mmb_response($return['error'], false);
275 else {
276 mmb_response($return, true);
277 }
278 }
279
280 function mmb_email_backup($params)
281 {
282 global $mmb_core;
283 $mmb_core->get_backup_instance();
284 $return = $mmb_core->backup_instance->email_backup($params);
285
286 if (is_array($return) && array_key_exists('error', $return))
287 mmb_response($return['error'], false);
288 else {
289 mmb_response($return, true);
290 }
291 }
292
293 function mmb_check_backup_compat($params)
294 {
295 global $mmb_core;
296 $mmb_core->get_backup_instance();
297 $return = $mmb_core->backup_instance->check_backup_compat($params);
298
299 if (is_array($return) && array_key_exists('error', $return))
300 mmb_response($return['error'], false);
301 else {
302 mmb_response($return, true);
303 }
304 }
305
306 function mmb_optimize_tables($params)
307 {
308 global $mmb_core;
309 $mmb_core->get_backup_instance();
310 $return = $mmb_core->backup_instance->optimize_tables();
311 if ($return)
312 mmb_response($return, true);
313 else
314 mmb_response(false, false);
315 }
316
317 function mmb_restore_now($params)
318 {
319 global $mmb_core;
320 $mmb_core->get_backup_instance();
321 $return = $mmb_core->backup_instance->restore($params);
322 if (is_array($return) && array_key_exists('error', $return))
323 mmb_response($return['error'], false);
324 else
325 mmb_response($return, true);
326
327 }
328
329 function mmb_update_worker_plugin($params)
330 {
331 global $mmb_core;
332 mmb_response($mmb_core->update_worker_plugin($params), true);
333 }
334
335 function mmb_wp_checkversion($params)
336 {
337 include_once(ABSPATH . 'wp-includes/version.php');
338 global $mmb_wp_version, $mmb_core;
339 mmb_response($mmb_wp_version, true);
340 }
341
342 function mmb_search_posts_by_term($params)
343 {
344 global $mmb_core;
345 $mmb_core->get_search_instance();
346 $return = $mmb_core->search_instance->search_posts_by_term($params);
347
348 if ($return) {
349 mmb_response(serialize($return), true);
350 } else {
351 mmb_response('No posts for term', false);
352 }
353 }
354
355 function mmb_install_addon($params)
356 {
357 global $mmb_core;
358 $mmb_core->get_installer_instance();
359 $return = $mmb_core->installer_instance->install_remote_file($params);
360 mmb_response($return, true);
361
362 }
363 function mmb_do_upgrade($params)
364 {
365 global $mmb_core, $mmb_upgrading;
366 $mmb_core->get_installer_instance();
367 $return = $mmb_core->installer_instance->do_upgrade($params);
368 mmb_response($return, true);
369
370 }
371
372 function mmb_add_link($params)
373 {
374 global $mmb_core;
375 $mmb_core->get_link_instance();
376 $return = $mmb_core->link_instance->add_link($params);
377 if (is_array($return) && array_key_exists('error', $return))
378
379 mmb_response($return['error'], false);
380 else {
381 mmb_response($return, true);
382 }
383
384 }
385
386 function mmb_iframe_plugins_fix($update_actions)
387 {
388 foreach($update_actions as $key => $action)
389 {
390 $update_actions[$key] = str_replace('target="_parent"','',$action);
391 }
392
393 return $update_actions;
394
395 }
396
397 add_filter('install_plugin_complete_actions','mmb_iframe_plugins_fix');
398
399
400 ?>
401