PluginProbe
ManageWP Worker / 3.8.7
ManageWP Worker v3.8.7
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.7, at init.php

316 lines 9.3 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.7
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.7');
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 'backup' => 'mmb_backup_now',
40 'restore' => 'mmb_restore_now',
41 'optimize_tables' => 'mmb_optimize_tables',
42 'check_wp_version' => 'mmb_wp_checkversion',
43 'create_post' => 'mmb_post_create',
44 'update_worker' => 'mmb_update_worker_plugin',
45 'change_comment_status' => 'mmb_change_comment_status',
46 'get_comment_stats' => 'mmb_comment_stats_get',
47 'install_addon' => 'mmb_install_addon',
48 'do_upgrade' => 'mmb_do_upgrade'
49 );
50
51 require_once("$mmb_plugin_dir/helper.class.php");
52 require_once("$mmb_plugin_dir/core.class.php");
53 require_once("$mmb_plugin_dir/post.class.php");
54 require_once("$mmb_plugin_dir/comment.class.php");
55 require_once("$mmb_plugin_dir/stats.class.php");
56 require_once("$mmb_plugin_dir/backup.class.php");
57 require_once("$mmb_plugin_dir/installer.class.php");
58 require_once("$mmb_plugin_dir/api.php");
59
60
61 require_once("$mmb_plugin_dir/plugins/search/search.php");
62 require_once("$mmb_plugin_dir/plugins/cleanup/cleanup.php");
63
64 //this is an exmaple plugin for extra_html element
65 //require_once("$mmb_plugin_dir/plugins/extra_html_example/extra_html_example.php");
66
67 $mmb_core = new MMB_Core();
68 add_action('init', 'mmb_parse_request');
69
70 if (function_exists('register_activation_hook'))
71 register_activation_hook(__FILE__, array(
72 $mmb_core,
73 'install'
74 ));
75
76 if (function_exists('register_deactivation_hook'))
77 register_deactivation_hook(__FILE__, array(
78 $mmb_core,
79 'uninstall'
80 ));
81
82
83
84 function mmb_parse_request()
85 {
86 if (!isset($HTTP_RAW_POST_DATA)) {
87 $HTTP_RAW_POST_DATA = file_get_contents('php://input');
88 }
89 ob_start();
90
91 global $mmb_core, $mmb_actions, $new_actions;
92
93 $data = base64_decode($HTTP_RAW_POST_DATA);
94 if ($data)
95 $num = @extract(unserialize($data));
96
97 if ($action) {
98 // mmb_response($mmb_actions, false);
99 if (!$mmb_core->check_if_user_exists($params['username']))
100 mmb_response('Username <b>' . $params['username'] . '</b> does not have administrator capabilities. Enter the correct username in the site options.', false);
101
102 if ($action == 'add_site') {
103 mmb_add_site($params);
104 mmb_response('You should never see this.', false);
105 }
106
107 $auth = $mmb_core->authenticate_message($action . $id, $signature, $id);
108 if ($auth === true) {
109 if (array_key_exists($action, $mmb_actions) && function_exists($mmb_actions[$action]))
110 call_user_func($mmb_actions[$action], $params);
111 else
112 mmb_response('Action "' . $action . '" does not exist.', false);
113 } else {
114 mmb_response($auth['error'], false);
115 }
116 }
117
118
119 ob_end_clean();
120 }
121
122 /* Main response function */
123
124 function mmb_response($response = false, $success = true)
125 {
126 $return = array();
127
128 if (empty($response))
129 $return['error'] = 'Empty response.';
130 else if ($success)
131 $return['success'] = $response;
132 else
133 $return['error'] = $response;
134
135 header('Content-Type: text/plain');
136 exit(PHP_EOL . base64_encode(serialize($return)));
137 }
138
139 function mmb_add_site($params)
140 {
141 global $mmb_core;
142
143 $num = extract($params);
144
145 if ($num) {
146 if (!get_option('_action_message_id') && !get_option('_worker_public_key')) {
147 $public_key = base64_decode($public_key);
148
149 if (function_exists('openssl_verify')) {
150 $verify = openssl_verify($action . $id, base64_decode($signature), $public_key);
151 if ($verify == 1) {
152 $mmb_core->set_master_public_key($public_key);
153 $mmb_core->set_worker_message_id($id);
154
155 mmb_response($mmb_core->get_stats_instance()->get_initial_stats(), true);
156 } else if ($verify == 0) {
157 mmb_response('Invalid message signature. Please contact us if you see this message often.', false);
158 } else {
159 mmb_response('Command not successful. Please try again.', false);
160 }
161 } else {
162 if (!get_option('_worker_nossl_key')) {
163 srand();
164 $random_key = md5(base64_encode($public_key) . rand(0, getrandmax()));
165
166 $mmb_core->set_random_signature($random_key);
167 $mmb_core->set_worker_message_id($id);
168 $mmb_core->set_master_public_key($public_key);
169 mmb_response($mmb_core->get_stats_instance()->get_initial_stats(), true);
170 } else
171 mmb_response('Please deactivate & activate ManageWP Worker plugin on your site, then re-add the site to your dashboard.', false);
172 }
173 } else {
174 mmb_response('Please deactivate & activate ManageWP Worker plugin on your site and re-add the site to your dashboard.', false);
175 }
176 } else {
177 mmb_response('Invalid parameters received. Please try again.', false);
178 }
179 }
180
181 function mmb_remove_site($params)
182 {
183 extract($params);
184 global $mmb_core;
185 $mmb_core->uninstall();
186
187 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
188 $plugin_slug = basename(dirname(__FILE__)) . '/' . basename(__FILE__);
189
190 if ($deactivate) {
191 deactivate_plugins($plugin_slug, true);
192 }
193
194 if (!is_plugin_active($plugin_slug))
195 mmb_response(array(
196 'deactivated' => 'Site removed successfully. <br /><br />ManageWP Worker plugin successfully deactivated.'
197 ), true);
198 else
199 mmb_response(array(
200 'removed_data' => 'Site removed successfully. <br /><br /><b>ManageWP Worker plugin was not deactivated.</b>'
201 ), true);
202
203 }
204
205
206 function mmb_stats_get($params)
207 {
208 global $mmb_core;
209 mmb_response($mmb_core->get_stats_instance()->get($params), true);
210 }
211
212 //post
213 function mmb_post_create($params)
214 {
215 global $mmb_core;
216 $return = $mmb_core->get_post_instance()->create($params);
217 if (is_int($return))
218 mmb_response($return, true);
219 else
220 mmb_response($return, false);
221 }
222
223 //comments
224 function mmb_change_comment_status($params)
225 {
226
227 global $mmb_core;
228 $return = $mmb_core->get_comment_instance()->change_status($params);
229 //mmb_response($return, true);
230 if ($return)
231 mmb_response($mmb_core->get_stats_instance()->get_comments_stats($params), true);
232 else
233 mmb_response('Comment not updated', false);
234 }
235 function mmb_comment_stats_get($params)
236 {
237 global $mmb_core;
238 mmb_response($mmb_core->get_stats_instance()->get_comments_stats($params), true);
239 }
240
241 //backup
242 function mmb_backup_now($params)
243 {
244 global $mmb_core;
245
246 $return = $mmb_core->get_backup_instance()->backup($params);
247
248 if (is_array($return) && array_key_exists('error', $return))
249 mmb_response($return['error'], false);
250 else {
251 mmb_response($return, true);
252 }
253 }
254
255 function mmb_optimize_tables($params)
256 {
257 global $mmb_core;
258 $return = $mmb_core->get_backup_instance()->optimize_tables();
259 if ($return)
260 mmb_response($return, true);
261 else
262 mmb_response(false, false);
263 }
264
265 function mmb_restore_now($params)
266 {
267 global $mmb_core;
268 $return = $mmb_core->get_backup_instance()->restore($params);
269 if (is_array($return) && array_key_exists('error', $return))
270 mmb_response($return['error'], false);
271 else
272 mmb_response($return, true);
273
274 }
275
276 function mmb_update_worker_plugin($params)
277 {
278 global $mmb_core;
279 mmb_response($mmb_core->update_worker_plugin($params), true);
280 }
281
282 function mmb_wp_checkversion($params)
283 {
284 include_once(ABSPATH . 'wp-includes/version.php');
285 global $mmb_wp_version, $mmb_core;
286 mmb_response($mmb_wp_version, true);
287 }
288
289 function mmb_search_posts_by_term($params)
290 {
291 global $mmb_core;
292 $return = $mmb_core->get_search_instance()->search_posts_by_term($params);
293
294 if ($return) {
295 mmb_response(serialize($return), true);
296 } else {
297 mmb_response('No posts for term', false);
298 }
299 }
300
301 function mmb_install_addon($params)
302 {
303 global $mmb_core;
304 $return = $mmb_core->get_installer_instance()->install_remote_file($params);
305 mmb_response($return, true);
306
307 }
308 function mmb_do_upgrade($params)
309 {
310 global $mmb_core, $mmb_upgrading;
311 $return = $mmb_core->get_installer_instance()->do_upgrade($params);
312 mmb_response($return, true);
313
314 }
315 ?>
316